mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Two important fixes:
(1) on a little-endian platform, don't byteswap; (2) in _patchheader(), there was a missing self._file argument to a _write_long() call.
This commit is contained in:
parent
2aaeb52665
commit
ebb9c922cb
1 changed files with 12 additions and 3 deletions
15
Lib/wave.py
15
Lib/wave.py
|
@ -78,6 +78,13 @@ WAVE_FORMAT_PCM = 0x0001
|
||||||
|
|
||||||
_array_fmts = None, 'b', 'h', None, 'l'
|
_array_fmts = None, 'b', 'h', None, 'l'
|
||||||
|
|
||||||
|
# Determine endian-ness
|
||||||
|
import struct
|
||||||
|
if struct.pack("h", 1) == "\000\001":
|
||||||
|
big_endian = 1
|
||||||
|
else:
|
||||||
|
big_endian = 0
|
||||||
|
|
||||||
def _read_long(file):
|
def _read_long(file):
|
||||||
x = 0L
|
x = 0L
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
|
@ -309,7 +316,8 @@ class Wave_read:
|
||||||
nitems = (self._data_chunk.chunksize - self._data_chunk.size_read) / self._sampwidth
|
nitems = (self._data_chunk.chunksize - self._data_chunk.size_read) / self._sampwidth
|
||||||
data.fromfile(self._data_chunk.file, nitems)
|
data.fromfile(self._data_chunk.file, nitems)
|
||||||
self._data_chunk.size_read = self._data_chunk.size_read + nitems * self._sampwidth
|
self._data_chunk.size_read = self._data_chunk.size_read + nitems * self._sampwidth
|
||||||
data.byteswap()
|
if big_endian:
|
||||||
|
data.byteswap()
|
||||||
data = data.tostring()
|
data = data.tostring()
|
||||||
else:
|
else:
|
||||||
data = self._data_chunk.read(nframes * self._framesize)
|
data = self._data_chunk.read(nframes * self._framesize)
|
||||||
|
@ -482,7 +490,8 @@ class Wave_write:
|
||||||
if self._sampwidth > 1:
|
if self._sampwidth > 1:
|
||||||
import array
|
import array
|
||||||
data = array.array(_array_fmts[self._sampwidth], data)
|
data = array.array(_array_fmts[self._sampwidth], data)
|
||||||
data.byteswap()
|
if big_endian:
|
||||||
|
data.byteswap()
|
||||||
data.tofile(self._file)
|
data.tofile(self._file)
|
||||||
self._datawritten = self._datawritten + len(data) * self._sampwidth
|
self._datawritten = self._datawritten + len(data) * self._sampwidth
|
||||||
else:
|
else:
|
||||||
|
@ -542,7 +551,7 @@ class Wave_write:
|
||||||
return
|
return
|
||||||
curpos = self._file.tell()
|
curpos = self._file.tell()
|
||||||
self._file.seek(self._form_length_pos, 0)
|
self._file.seek(self._form_length_pos, 0)
|
||||||
_write_long(36 + self._datawritten)
|
_write_long(self._file, 36 + self._datawritten)
|
||||||
self._file.seek(self._data_length_pos, 0)
|
self._file.seek(self._data_length_pos, 0)
|
||||||
_write_long(self._file, self._datawritten)
|
_write_long(self._file, self._datawritten)
|
||||||
self._file.seek(curpos, 0)
|
self._file.seek(curpos, 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue