|
78 | 78 |
|
79 | 79 | _array_fmts = None, 'b', 'h', None, 'l' |
80 | 80 |
|
| 81 | +# Determine endian-ness |
| 82 | +import struct |
| 83 | +if struct.pack("h", 1) == "\000\001": |
| 84 | + big_endian = 1 |
| 85 | +else: |
| 86 | + big_endian = 0 |
| 87 | + |
81 | 88 | def _read_long(file): |
82 | 89 | x = 0L |
83 | 90 | for i in range(4): |
@@ -309,7 +316,8 @@ def readframes(self, nframes): |
309 | 316 | nitems = (self._data_chunk.chunksize - self._data_chunk.size_read) / self._sampwidth |
310 | 317 | data.fromfile(self._data_chunk.file, nitems) |
311 | 318 | self._data_chunk.size_read = self._data_chunk.size_read + nitems * self._sampwidth |
312 | | - data.byteswap() |
| 319 | + if big_endian: |
| 320 | + data.byteswap() |
313 | 321 | data = data.tostring() |
314 | 322 | else: |
315 | 323 | data = self._data_chunk.read(nframes * self._framesize) |
@@ -482,7 +490,8 @@ def writeframesraw(self, data): |
482 | 490 | if self._sampwidth > 1: |
483 | 491 | import array |
484 | 492 | data = array.array(_array_fmts[self._sampwidth], data) |
485 | | - data.byteswap() |
| 493 | + if big_endian: |
| 494 | + data.byteswap() |
486 | 495 | data.tofile(self._file) |
487 | 496 | self._datawritten = self._datawritten + len(data) * self._sampwidth |
488 | 497 | else: |
@@ -542,7 +551,7 @@ def _patchheader(self): |
542 | 551 | return |
543 | 552 | curpos = self._file.tell() |
544 | 553 | self._file.seek(self._form_length_pos, 0) |
545 | | - _write_long(36 + self._datawritten) |
| 554 | + _write_long(self._file, 36 + self._datawritten) |
546 | 555 | self._file.seek(self._data_length_pos, 0) |
547 | 556 | _write_long(self._file, self._datawritten) |
548 | 557 | self._file.seek(curpos, 0) |
|
0 commit comments