Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a4e3703

Browse files
committed
MERGE: Closes #16461: Wave library should be able to deal with 4GB wav files, and sample rate of 44100 Hz.
2 parents 9d2e7e0 + fc1a636 commit a4e3703

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

Lib/wave.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@ def readframes(self, nframes):
261261
#
262262

263263
def _read_fmt_chunk(self, chunk):
264-
wFormatTag, self._nchannels, self._framerate, dwAvgBytesPerSec, wBlockAlign = struct.unpack_from('<hhllh', chunk.read(14))
264+
wFormatTag, self._nchannels, self._framerate, dwAvgBytesPerSec, wBlockAlign = struct.unpack_from('<HHLLH', chunk.read(14))
265265
if wFormatTag == WAVE_FORMAT_PCM:
266-
sampwidth = struct.unpack_from('<h', chunk.read(2))[0]
266+
sampwidth = struct.unpack_from('<H', chunk.read(2))[0]
267267
self._sampwidth = (sampwidth + 7) // 8
268268
else:
269269
raise Error('unknown format: %r' % (wFormatTag,))
@@ -466,14 +466,14 @@ def _write_header(self, initlength):
466466
self._nframes = initlength // (self._nchannels * self._sampwidth)
467467
self._datalength = self._nframes * self._nchannels * self._sampwidth
468468
self._form_length_pos = self._file.tell()
469-
self._file.write(struct.pack('<l4s4slhhllhh4s',
469+
self._file.write(struct.pack('<L4s4sLHHLLHH4s',
470470
36 + self._datalength, b'WAVE', b'fmt ', 16,
471471
WAVE_FORMAT_PCM, self._nchannels, self._framerate,
472472
self._nchannels * self._framerate * self._sampwidth,
473473
self._nchannels * self._sampwidth,
474474
self._sampwidth * 8, b'data'))
475475
self._data_length_pos = self._file.tell()
476-
self._file.write(struct.pack('<l', self._datalength))
476+
self._file.write(struct.pack('<L', self._datalength))
477477
self._headerwritten = True
478478

479479
def _patchheader(self):
@@ -482,9 +482,9 @@ def _patchheader(self):
482482
return
483483
curpos = self._file.tell()
484484
self._file.seek(self._form_length_pos, 0)
485-
self._file.write(struct.pack('<l', 36 + self._datawritten))
485+
self._file.write(struct.pack('<L', 36 + self._datawritten))
486486
self._file.seek(self._data_length_pos, 0)
487-
self._file.write(struct.pack('<l', self._datawritten))
487+
self._file.write(struct.pack('<L', self._datawritten))
488488
self._file.seek(curpos, 0)
489489
self._datalength = self._datawritten
490490

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ Library
240240
- Issue #16270: urllib may hang when used for retrieving files via FTP by using
241241
a context manager. Patch by Giampaolo Rodola'.
242242

243+
- Issue #16461: Wave library should be able to deal with 4GB wav files,
244+
and sample rate of 44100 Hz.
245+
243246
- Issue #16176: Properly identify Windows 8 via platform.platform()
244247

245248
- Issue #16088: BaseHTTPRequestHandler's send_error method includes a

0 commit comments

Comments
 (0)