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
1f057546
Commit
1f057546
authored
Sep 06, 1994
by
Sjoerd Mullender
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for ADPCM compression.
parent
03a90962
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
6 deletions
+47
-6
Lib/aifc.py
Lib/aifc.py
+47
-6
No files found.
Lib/aifc.py
View file @
1f057546
...
...
@@ -514,6 +514,15 @@ class Aifc_read:
import
audioop
return
audioop
.
ulaw2lin
(
data
,
2
)
def
_adpcm2lin
(
self
,
data
):
import
audioop
if
not
hasattr
(
self
,
'_adpcmstate'
):
# first time
self
.
_adpcmstate
=
None
data
,
self
.
_adpcmstate
=
audioop
.
adpcm2lin
(
data
,
2
,
self
.
_adpcmstate
)
return
data
def
_read_comm_chunk
(
self
,
chunk
):
self
.
_nchannels
=
_read_short
(
chunk
)
self
.
_nframes
=
_read_long
(
chunk
)
...
...
@@ -539,6 +548,16 @@ class Aifc_read:
#DEBUG end
self
.
_compname
=
_read_string
(
chunk
)
if
self
.
_comptype
!=
'NONE'
:
if
self
.
_comptype
==
'G722'
:
try
:
import
audioop
except
ImportError
:
pass
else
:
self
.
_convert
=
self
.
_adpcm2lin
self
.
_framesize
=
self
.
_framesize
/
4
return
# for ULAW and ALAW try Compression Library
try
:
import
cl
,
CL
except
ImportError
:
...
...
@@ -711,7 +730,7 @@ class Aifc_write:
def
setcomptype
(
self
,
comptype
,
compname
):
if
self
.
_nframeswritten
:
raise
Error
,
'cannot change parameters after starting to write'
if
comptype
not
in
(
'NONE'
,
'ULAW'
,
'ALAW'
):
if
comptype
not
in
(
'NONE'
,
'ULAW'
,
'ALAW'
,
'G722'
):
raise
Error
,
'unsupported compression type'
self
.
_comptype
=
comptype
self
.
_compname
=
compname
...
...
@@ -730,7 +749,7 @@ class Aifc_write:
def
setparams
(
self
,
(
nchannels
,
sampwidth
,
framerate
,
nframes
,
comptype
,
compname
)):
if
self
.
_nframeswritten
:
raise
Error
,
'cannot change parameters after starting to write'
if
comptype
not
in
(
'NONE'
,
'ULAW'
,
'ALAW'
):
if
comptype
not
in
(
'NONE'
,
'ULAW'
,
'ALAW'
,
'G722'
):
raise
Error
,
'unsupported compression type'
self
.
setnchannels
(
nchannels
)
self
.
setsampwidth
(
sampwidth
)
...
...
@@ -817,6 +836,14 @@ class Aifc_write:
import
audioop
return
audioop
.
lin2ulaw
(
data
,
2
)
def
_lin2adpcm
(
self
,
data
):
import
audioop
if
not
hasattr
(
self
,
'_adpcmstate'
):
self
.
_adpcmstate
=
None
data
,
self
.
_adpcmstate
=
audioop
.
lin2adpcm
(
data
,
2
,
self
.
_adpcmstate
)
return
data
def
_ensure_header_written
(
self
,
datasize
):
if
not
self
.
_nframeswritten
:
if
self
.
_comptype
in
(
'ULAW'
,
'ALAW'
):
...
...
@@ -824,6 +851,11 @@ class Aifc_write:
self
.
_sampwidth
=
2
if
self
.
_sampwidth
!=
2
:
raise
Error
,
'sample width must be 2 when compressing with ULAW or ALAW'
if
self
.
_comptype
==
'G722'
:
if
not
self
.
_sampwidth
:
self
.
_sampwidth
=
2
if
self
.
_sampwidth
!=
2
:
raise
Error
,
'sample width must be 2 when compressing with G7.22 (ADPCM)'
if
not
self
.
_nchannels
:
raise
Error
,
'# channels not specified'
if
not
self
.
_sampwidth
:
...
...
@@ -833,6 +865,10 @@ class Aifc_write:
self
.
_write_header
(
datasize
)
def
_init_compression
(
self
):
if
self
.
_comptype
==
'G722'
:
import
audioop
self
.
_convert
=
self
.
_lin2adpcm
return
try
:
import
cl
,
CL
except
ImportError
:
...
...
@@ -876,10 +912,15 @@ class Aifc_write:
self
.
_datalength
=
self
.
_nframes
*
self
.
_nchannels
*
self
.
_sampwidth
if
self
.
_datalength
&
1
:
self
.
_datalength
=
self
.
_datalength
+
1
if
self
.
_aifc
and
self
.
_comptype
in
(
'ULAW'
,
'ALAW'
):
self
.
_datalength
=
self
.
_datalength
/
2
if
self
.
_datalength
&
1
:
self
.
_datalength
=
self
.
_datalength
+
1
if
self
.
_aifc
:
if
self
.
_comptype
in
(
'ULAW'
,
'ALAW'
):
self
.
_datalength
=
self
.
_datalength
/
2
if
self
.
_datalength
&
1
:
self
.
_datalength
=
self
.
_datalength
+
1
elif
self
.
_comptype
==
'G722'
:
self
.
_datalength
=
(
self
.
_datalength
+
3
)
/
4
if
self
.
_datalength
&
1
:
self
.
_datalength
=
self
.
_datalength
+
1
self
.
_form_length_pos
=
self
.
_file
.
tell
()
commlength
=
self
.
_write_form_length
(
self
.
_datalength
)
if
self
.
_aifc
:
...
...
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