Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c47d723e
Commit
c47d723e
authored
Nov 09, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #1575020: Fixed support of 24-bit wave files on big-endian platforms.
parent
f87854e7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
11 deletions
+15
-11
Lib/test/test_wave.py
Lib/test/test_wave.py
+0
-3
Lib/wave.py
Lib/wave.py
+13
-8
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/test/test_wave.py
View file @
c47d723e
...
...
@@ -49,9 +49,6 @@ class WavePCM16Test(audiotests.AudioWriteTests,
frames
=
audiotests
.
byteswap2
(
frames
)
@
unittest
.
skipIf
(
sys
.
byteorder
==
'big'
,
'24-bit wave files are supported only on little-endian '
'platforms'
)
class
WavePCM24Test
(
audiotests
.
AudioWriteTests
,
audiotests
.
AudioTestsWithSourceFile
,
unittest
.
TestCase
):
...
...
Lib/wave.py
View file @
c47d723e
...
...
@@ -82,15 +82,16 @@ WAVE_FORMAT_PCM = 0x0001
_array_fmts
=
None
,
'b'
,
'h'
,
None
,
'i'
# Determine endian-ness
import
struct
if
struct
.
pack
(
"h"
,
1
)
==
"
\
000
\
001
"
:
big_endian
=
1
else
:
big_endian
=
0
import
sys
from
chunk
import
Chunk
def
_byteswap3
(
data
):
ba
=
bytearray
(
data
)
ba
[::
3
]
=
data
[
2
::
3
]
ba
[
2
::
3
]
=
data
[::
3
]
return
bytes
(
ba
)
class
Wave_read
:
"""Variables used in this class:
...
...
@@ -231,7 +232,7 @@ class Wave_read:
self
.
_data_seek_needed
=
0
if
nframes
==
0
:
return
''
if
self
.
_sampwidth
>
1
and
big_endian
:
if
self
.
_sampwidth
in
(
2
,
4
)
and
sys
.
byteorder
==
'big'
:
# unfortunately the fromfile() method does not take
# something that only looks like a file object, so
# we have to reach into the innards of the chunk object
...
...
@@ -252,6 +253,8 @@ class Wave_read:
data
=
data
.
tostring
()
else
:
data
=
self
.
_data_chunk
.
read
(
nframes
*
self
.
_framesize
)
if
self
.
_sampwidth
==
3
and
sys
.
byteorder
==
'big'
:
data
=
_byteswap3
(
data
)
if
self
.
_convert
and
data
:
data
=
self
.
_convert
(
data
)
self
.
_soundpos
=
self
.
_soundpos
+
len
(
data
)
//
(
self
.
_nchannels
*
self
.
_sampwidth
)
...
...
@@ -419,7 +422,7 @@ class Wave_write:
nframes
=
len
(
data
)
//
(
self
.
_sampwidth
*
self
.
_nchannels
)
if
self
.
_convert
:
data
=
self
.
_convert
(
data
)
if
self
.
_sampwidth
>
1
and
big_endian
:
if
self
.
_sampwidth
in
(
2
,
4
)
and
sys
.
byteorder
==
'big'
:
import
array
data
=
array
.
array
(
_array_fmts
[
self
.
_sampwidth
],
data
)
assert
data
.
itemsize
==
self
.
_sampwidth
...
...
@@ -427,6 +430,8 @@ class Wave_write:
data
.
tofile
(
self
.
_file
)
self
.
_datawritten
=
self
.
_datawritten
+
len
(
data
)
*
self
.
_sampwidth
else
:
if
self
.
_sampwidth
==
3
and
sys
.
byteorder
==
'big'
:
data
=
_byteswap3
(
data
)
self
.
_file
.
write
(
data
)
self
.
_datawritten
=
self
.
_datawritten
+
len
(
data
)
self
.
_nframeswritten
=
self
.
_nframeswritten
+
nframes
...
...
Misc/NEWS
View file @
c47d723e
...
...
@@ -12,6 +12,8 @@ Core and Builtins
Library
-------
- Issue #1575020: Fixed support of 24-bit wave files on big-endian platforms.
- Issue #19480: HTMLParser now accepts all valid start-tag names as defined
by the HTML5 standard.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment