pyspeex-0.2/ 0000755 0001750 0001750 00000000000 10176705223 013013 5 ustar thom thom 0000000 0000000 pyspeex-0.2/INSTALL 0000644 0001750 0001750 00000000330 07631310504 014034 0 ustar thom thom 0000000 0000000 To build the Python Bindings for Speex:
1) Ensure that this directory is sitting at the top level of
the Speex source tree
2) Type 'python setup.py build'
3) Log in as root, and type 'python setup.py install'
pyspeex-0.2/README 0000644 0001750 0001750 00000000706 07631310555 013700 0 ustar thom thom 0000000 0000000 This directory contains Python bindings to the Speex speech codec.
Python module implementing these bindings was implemented by
David McNab
For info on Speex, refer the Speex website - www.speex.org
To install these bindings, place this directory at the top level of
your Speex build directory.
To build the extension, refer to the file INSTALL
To use the python interface, refer to the documentation
in the doc directory.
pyspeex-0.2/doc/ 0000755 0001750 0001750 00000000000 07631311367 013564 5 ustar thom thom 0000000 0000000 pyspeex-0.2/doc/private/ 0000755 0001750 0001750 00000000000 07631311367 015236 5 ustar thom thom 0000000 0000000 pyspeex-0.2/doc/private/speex-module.html 0000644 0001750 0001750 00000012217 07631311066 020532 0 ustar thom thom 0000000 0000000
speex
Module speex
Module: speex
by David McNab <david@rebirthing.co.nz>
This Python module implements a Python wrapper to the Speex speech
codec, (http://www.speex.org), providing a class called 'speex' which can
be used to encode and decode streams of audio speech data
Function Summary
new
(... )
new(): Create a new speex speech stream object
new (... )
new(): Create a new speex speech stream object
Arguments:
quality - 0 (lowest) to 10 (highest), default 8
The created speex stream object has two methods:
Notes:
Both of these methods use internal buffering, which means that you can
feed in data piecemeal. This helps a lot when sending and receiving
data over the net.
pyspeex-0.2/doc/private/trees.html 0000644 0001750 0001750 00000005206 07631311066 017245 0 ustar thom thom 0000000 0000000
Module and Class Hierarchies
Module Hierarchy
pyspeex-0.2/doc/private/indices.html 0000644 0001750 0001750 00000006002 07631311066 017534 0 ustar thom thom 0000000 0000000
Index
pyspeex-0.2/doc/private/help.html 0000644 0001750 0001750 00000023005 07631311066 017050 0 ustar thom thom 0000000 0000000
Help
API Documentation
This document contains the API (Application Programming Interface)
documentation for PySpeex - Python Bindings for Speex speech codec. Documentation for the Python
objects defined by the project is divided into separate pages for each
package, module, and class. The API documentation also includes two
pages containing information about the project as a whole: a trees
page, and an index page.
Object Documentation
Each Package Documentation page contains:
A description of the package.
A list of the modules and sub-packages contained by the
package.
A summary of the classes defined by the package.
A summary of the functions defined by the package.
A summary of the variables defined by the package.
A detailed description of each function defined by the
package.
A detailed description of each variable defined by the
package.
Each Module Documentation page contains:
A description of the module.
A summary of the classes defined by the module.
A summary of the functions defined by the module.
A summary of the variables defined by the module.
A detailed description of each function defined by the
module.
A detailed description of each variable defined by the
module.
Each Class Documentation page contains:
A class inheritance diagram.
A list of known subclasses.
A description of the class.
A summary of the methods defined by the class.
A summary of the instance variables defined by the class.
A summary of the class (static) variables defined by the
class.
A detailed description of each method defined by the
class.
A detailed description of each instance variable defined by the
class.
A detailed description of each class (static) variable defined
by the class.
Project Documentation
The Trees page contains the module and class hierarchies:
The module hierarchy lists every package and module, with
modules grouped into packages. At the top level, and within each
package, modules and sub-packages are listed alphabetically.
The class hierarchy lists every class, grouped by base
class. If a class has more than one base class, then it will be
listed under each base class. At the top level, and under each base
class, classes are listed alphabetically.
The Index page contains indices of terms and
identifiers:
The term index lists every term indexed by any object's
documentation. For each term, the index provides links to each
place where the term is indexed.
The identifier index lists the (short) name of every package,
module, class, method, function, variable, and parameter. For each
identifier, the index provides a short description, and a link to
its documentation.
The Table of Contents
The table of contents occupies the two frames on the left side of
the window. The upper-left frame displays the project
contents , and the lower-left frame displays the module
contents :
Project Contents ...
API Documentation Frame
Module Contents ...
The project contents frame contains a list of all packages
and modules that are defined by the project. Clicking on an entry
will display its contents in the module contents frame. Clicking on a
special entry, labeled "Everything," will display the contents of
the entire project.
The module contents frame contains a list of every
submodule, class, type, exception, function, and variable defined by a
module or package. Clicking on an entry will display its
documentation in the API documentation frame. Clicking on the name of
the module, at the top of the frame, will display the documentation
for the module itself.
The "frames " and "no frames " buttons below the top
navigation bar can be used to control whether the table of contents is
displayed or not.
The Navigation Bar
A navigation bar is located at the top and bottom of every page.
It indicates what type of page you are currently viewing, and allows
you to go to related pages. The following table describes the labels
on the navigation bar. Note that not some labels (such as
[Parent]) are not displayed on all pages.
Label
Highlighted when...
Links to...
[Parent]
(never highlighted)
the parent of the current package
[Package]
viewing a package
the package containing the current object
[Module]
viewing a module
the module containing the current object
[Class]
viewing a class
the class containing the current object
[Trees]
viewing the trees page
the trees page
[Index]
viewing the index page
the index page
[Help]
viewing the help page
the help page
The "show private " and "hide private " buttons below
the top navigation bar can be used to control whether documentation
for private objects is displayed. Private objects are usually defined
as objects whose (short) names begin with a single underscore, but do
not end with an underscore. For example, "_x
",
"__pprint
", and "epydoc.epytext._tokenize
"
are private objects; but "re.sub
",
"__init__
", and "type_
" are not. However,
if a module defines the "__all__
" variable, then its
contents are used to decide which objects are private.
A timestamp below the bottom navigation bar indicates when each
page was last updated.
pyspeex-0.2/doc/private/frames.html 0000644 0001750 0001750 00000000614 07631311066 017376 0 ustar thom thom 0000000 0000000
PySpeex - Python Bindings for Speex speech codec
pyspeex-0.2/doc/private/toc.html 0000644 0001750 0001750 00000001722 07631311066 016707 0 ustar thom thom 0000000 0000000
Table of Contents
Table of Contents
Everything
Packages
Modules
speex
[show private | hide private ]
pyspeex-0.2/doc/private/toc-everything.html 0000644 0001750 0001750 00000002006 07631311066 021065 0 ustar thom thom 0000000 0000000
Everything
Everything
All Functions
new
[show private | hide private ]
pyspeex-0.2/doc/private/toc-speex-module.html 0000644 0001750 0001750 00000001474 07631311066 021320 0 ustar thom thom 0000000 0000000
speex
speex
Functions
new
[show private | hide private ]
pyspeex-0.2/doc/private/index.html 0000644 0001750 0001750 00000000614 07631311066 017230 0 ustar thom thom 0000000 0000000
PySpeex - Python Bindings for Speex speech codec
pyspeex-0.2/doc/private/epydoc.css 0000644 0001750 0001750 00000010154 07631311066 017230 0 ustar thom thom 0000000 0000000
/* Body color */
body { background: #ffffff; color: #000000; }
/* Tables */
table.summary, table.details, table.index
{ background: #e8f0f8; color: #000000; }
tr.summary, tr.details, tr.index
{ background: #70b0f0; color: #000000;
text-align: left; font-size: 120%; }
/* Documentation page titles */
h2.module { margin-top: 0.2em; }
h2.class { margin-top: 0.2em; }
/* Headings */
h1.heading { font-size: +140%; font-style: italic;
font-weight: bold; }
h2.heading { font-size: +125%; font-style: italic;
font-weight: bold; }
h3.heading { font-size: +110%; font-style: italic;
font-weight: normal; }
/* Base tree */
pre.base-tree { font-size: 80%; margin: 0; }
/* Details Sections */
table.func-details { background: #e8f0f8; color: #000000;
border: 2px groove #c0d0d0;
padding: 0 1em 0 1em; margin: 0.4em 0 0 0; }
h3.func-detail { background: transparent; color: #000000;
margin: 0 0 1em 0; }
table.var-details { background: #e8f0f8; color: #000000;
border: 2px groove #c0d0d0;
padding: 0 1em 0 1em; margin: 0.4em 0 0 0; }
h3.var-details { background: transparent; color: #000000;
margin: 0 0 1em 0; }
/* Function signatures */
.sig { background: transparent; color: #000000;
font-weight: bold; }
.sig-name { background: transparent; color: #006080; }
.sig-arg, .sig-kwarg, .sig-vararg
{ background: transparent; color: #008060; }
.sig-default { background: transparent; color: #602000; }
.summary-sig { background: transparent; color: #000000; }
.summary-sig-name { background: transparent; color: #0000ff; }
.summary-sig-arg, .summary-sig-kwarg, .summary-sig-vararg
{ background: transparent; color: #008060; }
/* Doctest blocks */
.py-src { background: transparent; color: #000000; }
.py-prompt { background: transparent; color: #005050;
font-weight: bold;}
.py-string { background: transparent; color: #006030; }
.py-comment { background: transparent; color: #003060; }
.py-keyword { background: transparent; color: #600000; }
.py-output { background: transparent; color: #404040; }
pre.doctestblock { background: #f4faff; color: #000000;
padding: .5em; margin: 1em;
border: 1px solid #708890; }
table pre.doctestblock
{ background: #dce4ec; color: #000000;
padding: .5em; margin: 1em;
border: 1px solid #708890; }
/* Variable values */
pre.variable { background: #dce4ec; color: #000000;
padding: .5em; margin: 0;
border: 1px solid #708890; }
.variable-linewrap { background: transparent; color: #604000; }
.variable-ellipsis { background: transparent; color: #604000; }
.variable-quote { background: transparent; color: #604000; }
.re { background: transparent; color: #000000; }
.re-char { background: transparent; color: #006030; }
.re-op { background: transparent; color: #600000; }
.re-group { background: transparent; color: #003060; }
.re-ref { background: transparent; color: #404040; }
/* Navigation bar */
table.navbar { background: #a0c0ff; color: #000000;
border: 2px groove #c0d0d0; }
th.navbar { background: #a0c0ff; color: #6090d0; font-size: 110% }
th.navselect { background: #70b0ff; color: #000000; font-size: 110% }
/* Links */
a:link { background: transparent; color: #0000ff; }
a:visited { background: transparent; color: #204080; }
a.navbar:link { background: transparent; color: #0000ff;
text-decoration: none; }
a.navbar:visited { background: transparent; color: #204080;
text-decoration: none; }
pyspeex-0.2/doc/public/ 0000755 0001750 0001750 00000000000 07631311367 015042 5 ustar thom thom 0000000 0000000 pyspeex-0.2/doc/public/speex-module.html 0000644 0001750 0001750 00000012220 07631311066 020330 0 ustar thom thom 0000000 0000000
speex
Module speex
Module: speex
by David McNab <david@rebirthing.co.nz>
This Python module implements a Python wrapper to the Speex speech
codec, (http://www.speex.org), providing a class called 'speex' which can
be used to encode and decode streams of audio speech data
Function Summary
new
(... )
new(): Create a new speex speech stream object
new (... )
new(): Create a new speex speech stream object
Arguments:
quality - 0 (lowest) to 10 (highest), default 8
The created speex stream object has two methods:
Notes:
Both of these methods use internal buffering, which means that you can
feed in data piecemeal. This helps a lot when sending and receiving
data over the net.
pyspeex-0.2/doc/public/trees.html 0000644 0001750 0001750 00000005207 07631311066 017052 0 ustar thom thom 0000000 0000000
Module and Class Hierarchies
Module Hierarchy
pyspeex-0.2/doc/public/indices.html 0000644 0001750 0001750 00000006003 07631311066 017341 0 ustar thom thom 0000000 0000000
Index
pyspeex-0.2/doc/public/help.html 0000644 0001750 0001750 00000023006 07631311066 016655 0 ustar thom thom 0000000 0000000
Help
API Documentation
This document contains the API (Application Programming Interface)
documentation for PySpeex - Python Bindings for Speex speech codec. Documentation for the Python
objects defined by the project is divided into separate pages for each
package, module, and class. The API documentation also includes two
pages containing information about the project as a whole: a trees
page, and an index page.
Object Documentation
Each Package Documentation page contains:
A description of the package.
A list of the modules and sub-packages contained by the
package.
A summary of the classes defined by the package.
A summary of the functions defined by the package.
A summary of the variables defined by the package.
A detailed description of each function defined by the
package.
A detailed description of each variable defined by the
package.
Each Module Documentation page contains:
A description of the module.
A summary of the classes defined by the module.
A summary of the functions defined by the module.
A summary of the variables defined by the module.
A detailed description of each function defined by the
module.
A detailed description of each variable defined by the
module.
Each Class Documentation page contains:
A class inheritance diagram.
A list of known subclasses.
A description of the class.
A summary of the methods defined by the class.
A summary of the instance variables defined by the class.
A summary of the class (static) variables defined by the
class.
A detailed description of each method defined by the
class.
A detailed description of each instance variable defined by the
class.
A detailed description of each class (static) variable defined
by the class.
Project Documentation
The Trees page contains the module and class hierarchies:
The module hierarchy lists every package and module, with
modules grouped into packages. At the top level, and within each
package, modules and sub-packages are listed alphabetically.
The class hierarchy lists every class, grouped by base
class. If a class has more than one base class, then it will be
listed under each base class. At the top level, and under each base
class, classes are listed alphabetically.
The Index page contains indices of terms and
identifiers:
The term index lists every term indexed by any object's
documentation. For each term, the index provides links to each
place where the term is indexed.
The identifier index lists the (short) name of every package,
module, class, method, function, variable, and parameter. For each
identifier, the index provides a short description, and a link to
its documentation.
The Table of Contents
The table of contents occupies the two frames on the left side of
the window. The upper-left frame displays the project
contents , and the lower-left frame displays the module
contents :
Project Contents ...
API Documentation Frame
Module Contents ...
The project contents frame contains a list of all packages
and modules that are defined by the project. Clicking on an entry
will display its contents in the module contents frame. Clicking on a
special entry, labeled "Everything," will display the contents of
the entire project.
The module contents frame contains a list of every
submodule, class, type, exception, function, and variable defined by a
module or package. Clicking on an entry will display its
documentation in the API documentation frame. Clicking on the name of
the module, at the top of the frame, will display the documentation
for the module itself.
The "frames " and "no frames " buttons below the top
navigation bar can be used to control whether the table of contents is
displayed or not.
The Navigation Bar
A navigation bar is located at the top and bottom of every page.
It indicates what type of page you are currently viewing, and allows
you to go to related pages. The following table describes the labels
on the navigation bar. Note that not some labels (such as
[Parent]) are not displayed on all pages.
Label
Highlighted when...
Links to...
[Parent]
(never highlighted)
the parent of the current package
[Package]
viewing a package
the package containing the current object
[Module]
viewing a module
the module containing the current object
[Class]
viewing a class
the class containing the current object
[Trees]
viewing the trees page
the trees page
[Index]
viewing the index page
the index page
[Help]
viewing the help page
the help page
The "show private " and "hide private " buttons below
the top navigation bar can be used to control whether documentation
for private objects is displayed. Private objects are usually defined
as objects whose (short) names begin with a single underscore, but do
not end with an underscore. For example, "_x
",
"__pprint
", and "epydoc.epytext._tokenize
"
are private objects; but "re.sub
",
"__init__
", and "type_
" are not. However,
if a module defines the "__all__
" variable, then its
contents are used to decide which objects are private.
A timestamp below the bottom navigation bar indicates when each
page was last updated.
pyspeex-0.2/doc/public/frames.html 0000644 0001750 0001750 00000000614 07631311066 017202 0 ustar thom thom 0000000 0000000
PySpeex - Python Bindings for Speex speech codec
pyspeex-0.2/doc/public/toc.html 0000644 0001750 0001750 00000001723 07631311066 016514 0 ustar thom thom 0000000 0000000
Table of Contents
Table of Contents
Everything
Packages
Modules
speex
[show private | hide private]
pyspeex-0.2/doc/public/toc-everything.html 0000644 0001750 0001750 00000002007 07631311066 020672 0 ustar thom thom 0000000 0000000
Everything
Everything
All Functions
new
[show private | hide private]
pyspeex-0.2/doc/public/toc-speex-module.html 0000644 0001750 0001750 00000001475 07631311066 021125 0 ustar thom thom 0000000 0000000
speex
speex
Functions
new
[show private | hide private]
pyspeex-0.2/doc/public/index.html 0000644 0001750 0001750 00000000614 07631311066 017034 0 ustar thom thom 0000000 0000000
PySpeex - Python Bindings for Speex speech codec
pyspeex-0.2/doc/public/epydoc.css 0000644 0001750 0001750 00000010154 07631311066 017034 0 ustar thom thom 0000000 0000000
/* Body color */
body { background: #ffffff; color: #000000; }
/* Tables */
table.summary, table.details, table.index
{ background: #e8f0f8; color: #000000; }
tr.summary, tr.details, tr.index
{ background: #70b0f0; color: #000000;
text-align: left; font-size: 120%; }
/* Documentation page titles */
h2.module { margin-top: 0.2em; }
h2.class { margin-top: 0.2em; }
/* Headings */
h1.heading { font-size: +140%; font-style: italic;
font-weight: bold; }
h2.heading { font-size: +125%; font-style: italic;
font-weight: bold; }
h3.heading { font-size: +110%; font-style: italic;
font-weight: normal; }
/* Base tree */
pre.base-tree { font-size: 80%; margin: 0; }
/* Details Sections */
table.func-details { background: #e8f0f8; color: #000000;
border: 2px groove #c0d0d0;
padding: 0 1em 0 1em; margin: 0.4em 0 0 0; }
h3.func-detail { background: transparent; color: #000000;
margin: 0 0 1em 0; }
table.var-details { background: #e8f0f8; color: #000000;
border: 2px groove #c0d0d0;
padding: 0 1em 0 1em; margin: 0.4em 0 0 0; }
h3.var-details { background: transparent; color: #000000;
margin: 0 0 1em 0; }
/* Function signatures */
.sig { background: transparent; color: #000000;
font-weight: bold; }
.sig-name { background: transparent; color: #006080; }
.sig-arg, .sig-kwarg, .sig-vararg
{ background: transparent; color: #008060; }
.sig-default { background: transparent; color: #602000; }
.summary-sig { background: transparent; color: #000000; }
.summary-sig-name { background: transparent; color: #0000ff; }
.summary-sig-arg, .summary-sig-kwarg, .summary-sig-vararg
{ background: transparent; color: #008060; }
/* Doctest blocks */
.py-src { background: transparent; color: #000000; }
.py-prompt { background: transparent; color: #005050;
font-weight: bold;}
.py-string { background: transparent; color: #006030; }
.py-comment { background: transparent; color: #003060; }
.py-keyword { background: transparent; color: #600000; }
.py-output { background: transparent; color: #404040; }
pre.doctestblock { background: #f4faff; color: #000000;
padding: .5em; margin: 1em;
border: 1px solid #708890; }
table pre.doctestblock
{ background: #dce4ec; color: #000000;
padding: .5em; margin: 1em;
border: 1px solid #708890; }
/* Variable values */
pre.variable { background: #dce4ec; color: #000000;
padding: .5em; margin: 0;
border: 1px solid #708890; }
.variable-linewrap { background: transparent; color: #604000; }
.variable-ellipsis { background: transparent; color: #604000; }
.variable-quote { background: transparent; color: #604000; }
.re { background: transparent; color: #000000; }
.re-char { background: transparent; color: #006030; }
.re-op { background: transparent; color: #600000; }
.re-group { background: transparent; color: #003060; }
.re-ref { background: transparent; color: #404040; }
/* Navigation bar */
table.navbar { background: #a0c0ff; color: #000000;
border: 2px groove #c0d0d0; }
th.navbar { background: #a0c0ff; color: #6090d0; font-size: 110% }
th.navselect { background: #70b0ff; color: #000000; font-size: 110% }
/* Links */
a:link { background: transparent; color: #0000ff; }
a:visited { background: transparent; color: #204080; }
a.navbar:link { background: transparent; color: #0000ff;
text-decoration: none; }
a.navbar:visited { background: transparent; color: #204080;
text-decoration: none; }
pyspeex-0.2/doc/index.html 0000644 0001750 0001750 00000000641 07631311066 015556 0 ustar thom thom 0000000 0000000
PySpeex - Python Bindings for Speex speech codec
pyspeex-0.2/doc/epydoc.css 0000644 0001750 0001750 00000010154 07631311066 015556 0 ustar thom thom 0000000 0000000
/* Body color */
body { background: #ffffff; color: #000000; }
/* Tables */
table.summary, table.details, table.index
{ background: #e8f0f8; color: #000000; }
tr.summary, tr.details, tr.index
{ background: #70b0f0; color: #000000;
text-align: left; font-size: 120%; }
/* Documentation page titles */
h2.module { margin-top: 0.2em; }
h2.class { margin-top: 0.2em; }
/* Headings */
h1.heading { font-size: +140%; font-style: italic;
font-weight: bold; }
h2.heading { font-size: +125%; font-style: italic;
font-weight: bold; }
h3.heading { font-size: +110%; font-style: italic;
font-weight: normal; }
/* Base tree */
pre.base-tree { font-size: 80%; margin: 0; }
/* Details Sections */
table.func-details { background: #e8f0f8; color: #000000;
border: 2px groove #c0d0d0;
padding: 0 1em 0 1em; margin: 0.4em 0 0 0; }
h3.func-detail { background: transparent; color: #000000;
margin: 0 0 1em 0; }
table.var-details { background: #e8f0f8; color: #000000;
border: 2px groove #c0d0d0;
padding: 0 1em 0 1em; margin: 0.4em 0 0 0; }
h3.var-details { background: transparent; color: #000000;
margin: 0 0 1em 0; }
/* Function signatures */
.sig { background: transparent; color: #000000;
font-weight: bold; }
.sig-name { background: transparent; color: #006080; }
.sig-arg, .sig-kwarg, .sig-vararg
{ background: transparent; color: #008060; }
.sig-default { background: transparent; color: #602000; }
.summary-sig { background: transparent; color: #000000; }
.summary-sig-name { background: transparent; color: #0000ff; }
.summary-sig-arg, .summary-sig-kwarg, .summary-sig-vararg
{ background: transparent; color: #008060; }
/* Doctest blocks */
.py-src { background: transparent; color: #000000; }
.py-prompt { background: transparent; color: #005050;
font-weight: bold;}
.py-string { background: transparent; color: #006030; }
.py-comment { background: transparent; color: #003060; }
.py-keyword { background: transparent; color: #600000; }
.py-output { background: transparent; color: #404040; }
pre.doctestblock { background: #f4faff; color: #000000;
padding: .5em; margin: 1em;
border: 1px solid #708890; }
table pre.doctestblock
{ background: #dce4ec; color: #000000;
padding: .5em; margin: 1em;
border: 1px solid #708890; }
/* Variable values */
pre.variable { background: #dce4ec; color: #000000;
padding: .5em; margin: 0;
border: 1px solid #708890; }
.variable-linewrap { background: transparent; color: #604000; }
.variable-ellipsis { background: transparent; color: #604000; }
.variable-quote { background: transparent; color: #604000; }
.re { background: transparent; color: #000000; }
.re-char { background: transparent; color: #006030; }
.re-op { background: transparent; color: #600000; }
.re-group { background: transparent; color: #003060; }
.re-ref { background: transparent; color: #404040; }
/* Navigation bar */
table.navbar { background: #a0c0ff; color: #000000;
border: 2px groove #c0d0d0; }
th.navbar { background: #a0c0ff; color: #6090d0; font-size: 110% }
th.navselect { background: #70b0ff; color: #000000; font-size: 110% }
/* Links */
a:link { background: transparent; color: #0000ff; }
a:visited { background: transparent; color: #204080; }
a.navbar:link { background: transparent; color: #0000ff;
text-decoration: none; }
a.navbar:visited { background: transparent; color: #204080;
text-decoration: none; }
pyspeex-0.2/speex.pyx 0000644 0001750 0001750 00000044546 07760313475 014727 0 ustar thom thom 0000000 0000000 #@+leo-ver=4
#@+node:@file speex.pyx
#@@language python
"""
speex.pyx
Python wrapper for Speex speech codec (www.speex.org)
Defines a 'speex' object through which encoding and
decoding of audio data can be performed.
"""
version = "0.2"
try:
x = True
except:
True = 1
False = 0
#@+others
#@+node:cdef externs
# basic system and python facilities
#@+others
#@+node:string.h
cdef extern from "string.h":
cdef void *memset(void *s, int c, int n)
cdef void *memcpy(void *dest, void *src, int n)
#@-node:string.h
#@+node:stdio.h
cdef extern from "stdio.h":
int printf(char *format,...)
#@-node:stdio.h
#@+node:stdlib.h
cdef extern from "stdlib.h":
void *malloc(int size)
void *realloc(void *ptr, int size)
void free(void *ptr)
#@-node:stdlib.h
#@+node:math.h
cdef extern from "math.h":
double fabs(double x)
#@-node:math.h
#@+node:Python.h
# Python-specifics
cdef extern from "Python.h":
object PyString_FromStringAndSize(char *, int)
#@-node:Python.h
#@+node:speex.h
# Speex-specifics
cdef extern from "speex.h":
ctypedef struct SpeexBits:
char *bytes # "raw" data
int nbBits # Total number of bits stored in the stream
int bytePtr # Position of the byte "cursor"
int bitPtr # Position of the bit "cursor" within the current byte
int owner # Does the struct "own" the "raw" buffer (member "bytes")
int overflow # Set to one if we try to read past the valid data
int buf_size # Allocated size for buffer
ctypedef struct SpeexMode:
void *mode
cdef enum SPEEX_SYMBOLS:
SPEEX_SET_QUALITY
SPEEX_GET_FRAME_SIZE
SPEEX_SET_ENH
SPEEX_GET_ENH
cdef SpeexMode speex_nb_mode
cdef void speex_bits_init(SpeexBits *bits)
cdef void speex_bits_read_from(SpeexBits *bits, char *bytes, int len)
cdef int speex_bits_write(SpeexBits *bits, char *bytes, int max_len)
cdef void speex_bits_reset(SpeexBits *bits)
cdef void speex_bits_destroy(SpeexBits *bits)
cdef void *speex_encoder_init(SpeexMode *mode)
cdef int speex_encoder_ctl(void *state,
int request,
void *ptr)
cdef int speex_encode(void *state, float *inbuf, SpeexBits *bits)
cdef void speex_encoder_destroy(void *state)
cdef void *speex_decoder_init(SpeexMode *mode)
int speex_decoder_ctl(void *state, int request, void *ptr)
cdef int speex_decode(void *state,
SpeexBits *bits,
float *out)
cdef void speex_decoder_destroy(void *state)
#@-node:speex.h
#@-others
#@-node:cdef externs
#@+node:cdef class new
cdef class new:
#@ @+others
#@+node:c attribs
cdef void *encState
cdef int encQuality
cdef int encFramesPerBlock
cdef float *encBuf
cdef float *encPtr
cdef int encNumFrames
cdef SpeexBits encBits
cdef int raw
# Data for decoding
cdef void *decState
cdef int decQuality
cdef unsigned char *decBuf
cdef unsigned char *decPtr
cdef unsigned short decBlkSize
cdef int decNumBytes
cdef int decPhase
cdef int decEnhanceOn
cdef SpeexBits decBits
cdef public object debug
cdef public object endianness
#@-node:c attribs
#@+node:__init__
def __init__(self, quality=8, raw=0, **kw):
"""
Create a new speex speech stream object
Arguments:
- quality - 0 (lowest) to 10 (highest), default 8
- raw - set to 1 for encoding from and decoding to string, default 0
Keywords:
- debug - set to 1 to issue debug messages, default 0
The created speex stream object has two methods:
- encode - encode a block of speech audio data
Arguments:
- block of audio data, as sequence of frames, where
each frame is an int
Returns:
- raw string containing encoded data, or
empty string if there is not yet any encoded
data available
- decode - decodes a block of speech audio data
Arguments:
- block of encoded data, as raw string,
Returns:
- block of audio data, as sequence of ints, or
an empty sequence if there is no decoded data
available yet
Notes:
- Both of these methods use internal buffering, which means that
you can feed in data piecemeal. This helps a lot when sending and
receiving data over the net.
"""
cdef int is_raw
#cdef SpeexMode speex_nb_mode
# Set up encoder
self.encState = speex_encoder_init(&speex_nb_mode)
self.encQuality = quality
is_raw = raw
self.raw = is_raw
self.debug = int(kw.get('debug', 0))
speex_encoder_ctl(self.encState, SPEEX_SET_QUALITY, &self.encQuality)
#printf("speex1: using new pyrex wrapper, quality=%d\n", self.encQuality)
speex_encoder_ctl(self.encState, SPEEX_GET_FRAME_SIZE, &self.encFramesPerBlock)
#printf("encoder frame size=%d\n", self.encFramesPerBlock)
self.encBuf = malloc(self.encFramesPerBlock * sizeof(float))
if not self.encBuf:
raise Exception("Out of memory")
memset(self.encBuf, 0, self.encFramesPerBlock * sizeof(float))
self.encNumFrames = 0
self.encPtr = self.encBuf
speex_bits_init(&self.encBits)
# Set up decoder
self.decState = speex_decoder_init(&speex_nb_mode)
self.decEnhanceOn = 1
speex_decoder_ctl(self.decState, SPEEX_SET_ENH, &self.decEnhanceOn)
self.decBuf = malloc(2) # just big enough for leading length field
self.decPhase = 0
if not self.decBuf:
raise Exception("Out of memory")
self.decPtr = self.decBuf
self.decNumBytes = 0
speex_bits_init(&self.decBits)
#@-node:__init__
#@+node:__dealloc__
def __dealloc__(self):
# Destroy the encoder state and data
speex_encoder_destroy(self.encState)
if self.encBuf:
free(self.encBuf)
# Destroy the decoder state
speex_decoder_destroy(self.decState)
if self.decBuf:
free(self.decBuf)
# Destroy the bit-packing structs
speex_bits_destroy(&self.encBits)
speex_bits_destroy(&self.decBits)
#@-node:__dealloc__
#@+node:encode
def encode(self, input, raw=None):
"""
Encode some audio data
Arguments:
- data - sequence of audio frames to encode, OR string of 16-bit frames
- raw - true if data being passed in is a string of 16-bit frames
defaults to whatever raw arg was passed to constructor
Returns:
- raw string with encoded data
"""
cdef int numInputFrames
cdef float *framesBuf, *framesPtr
# cdef float thisframe
cdef int i
cdef int totFrames
# cdef SpeexBits bits;
cdef int cbitsSiz
# cdef int cbitsSiz = 2048
# cdef char cbits[cbitsSiz]
cdef char cbits[2048]
cdef int nBlocks
cdef int nBytes
cdef char *bufOut
cdef int bufOutSiz
cdef int remainder
cdef char *rawbuf
cdef short *frameptr
cbitsSiz = self.encFramesPerBlock * 5 / 4
bufOut = malloc(0)
bufOutSiz = 0
inputFramesList = []
#printf("encode: ok1\n")
# override raw flag if user has passed in a string
if raw is None:
raw = self.raw
if type(input) is type(""):
raw = 1
# Determine number of frames
if raw:
numInputFrames = len(input) / 2 # hardwired 16-bit frames
else:
numInputFrames = len(input)
#printf("encode: ok2\n")
# printf("enc - numInputFrames = %d\n", numInputFrames)
if numInputFrames == 0:
return ''
#printf("encode: ok3\n")
# Encode what we have, block by block
totFrames = numInputFrames + self.encNumFrames
#printf("totFrames=%d, input data size=%d\n",
# totFrames, totFrames * sizeof(short))
framesBuf = malloc(totFrames * sizeof(float))
framesPtr = framesBuf
if not framesBuf:
raise Exception("Out of memory")
#printf("encode: ok4\n")
# Copy in the fragments we have in buffer
# printf("copying in buf of %d frames\n", self.encNumFrames)
for i from 0 <= i < self.encNumFrames:
framesPtr[i] = self.encBuf[i]
#printf("encode: ok4a = i=%d, self.encNumFrames=%d\n",
# i, self.encNumFrames)
framesPtr = framesPtr + i
#printf("encode: ok5\n")
# Extract the rest from input sequence, depending on whether input is str or list
# printf("copying extra %d frames from input\n", numInputFrames);
if raw:
rawbuf = input
frameptr = rawbuf
for i from 0 <= i < numInputFrames:
# assume little-endian - sorry, mac hackers
# frame = rawptr[0] + 256 * rawptr[1]
# rawptr += 2
# *framesPtr++ = (float)frame
framesPtr[i] = frameptr[i]
framesPtr = framesPtr + i
frameptr = frameptr + i
# thisframe = *frameptr++
# if (i < 10)
# {
# printf("encode: thisframe=%f\n", thisframe)
# }
# *framesPtr++ = thisframe
else:
for i from 0 <= i < numInputFrames:
framesPtr[i] = input[i]
framesPtr = framesPtr + i
# thisframe = PyInt_AsLong(PyList_GetItem(input, i))
# if (i < 10)
# {
# printf("encode: thisframe=%f\n", thisframe)
# }
# *framesPtr++ = thisframe
#printf("written %d frames to buf\n", framesPtr - framesBuf)
#printf("encode: ok6\n")
# Encode these frames
nBlocks = totFrames / self.encFramesPerBlock
framesPtr = framesBuf
for i from 0 <= i < nBlocks:
# printf("seeking to encode a block, nBlocks=%d\n", nBlocks)
speex_bits_reset(&self.encBits)
# printf("ok1 - state=0x%lx, buf=0x%lx, bits=0x%lx\n",
# self.encState, framesBuf, &self.encBits)
speex_encode(self.encState, framesPtr, &self.encBits)
# printf("ok2\n")
nBytes = speex_bits_write(&self.encBits, cbits, cbitsSiz)
#printf("nBytes=%d\n", nBytes)
bufOut = realloc(bufOut, bufOutSiz+nBytes+2)
# printf("ok4\n")
# write out 2 length bytes
bufOut[bufOutSiz] = nBytes % 256
bufOut[bufOutSiz+1] = nBytes / 256
bufOutSiz = bufOutSiz + 2
memcpy(bufOut+bufOutSiz, cbits, nBytes)
# printf("ok5\n")
bufOutSiz = bufOutSiz + nBytes
# printf("ok6\n")
framesPtr = framesPtr + self.encFramesPerBlock
#printf("encode: ok7\n")
# stick remainder, if any, into buffer
self.encNumFrames = totFrames - (nBlocks * self.encFramesPerBlock)
remainder = self.encNumFrames * sizeof(float)
memcpy(self.encBuf, framesPtr, remainder)
# memset(self.encBuf, 0, self.encFramesPerBlock * sizeof(float))
# printf("encNumFrames=%d\n", self.encNumFrames)
# printf("remainder=%d\n", remainder)
#printf("encode: ok8\n")
# ditch temp buffer
free(framesBuf)
#printf("encode: ok9\n")
# pass back encoded buffer as raw string
#printf("bufOutSize=%d\n", bufOutSiz)
return PyString_FromStringAndSize(bufOut, bufOutSiz)
#@-node:encode
#@+node:decode
def decode(self, input, raw=None):
"""
Decode an encoded block, return as sequence of frame tuples
Arguments:
- encoded - raw string, containing encoded data
- raw - True if data is to be returned as string of 16-bit frames, defaults to
whatever raw value was passed to constructor
Returns:
- decoded blocks, as sequence of frames, where each frame
or a string of these 16-bit frames if raw is True
is an int
"""
cdef unsigned char *encBuf
cdef unsigned char *encBufEnd
cdef unsigned char *encPtr
cdef int encBufLen
cdef int numDecFrames # number of decoded frames
# cdef int cbitsSiz
# cdef char cbits[cbitsSiz]
cdef float *decFloats
cdef float *decFloats1
cdef short *decShorts
cdef short *decShorts1
cdef int decBlocks
cdef int i
cdef int is_raw
cdef int needed
cdef int newNumFrames
cdef char *tmp
#printf("decode: ok1\n")
tmp = input
encBuf = tmp
encBufEnd = NULL
encPtr = NULL
encBufLen = 0
decFloats = malloc(0)
decShorts = malloc(0)
decBlocks = 0
if raw is None:
raw = self.raw
is_raw = raw
#printf("decode: ok2, raw=%d\n", is_raw)
# We get an earlymark if caller provided no data
encBufLen = len(input)
if encBufLen == 0:
if is_raw:
return ''
else:
return []
#printf("decode: ok3\n")
# decode the sucker
encPtr = encBuf
encBufEnd = encBuf + encBufLen
#printf("decode: ok4, len=%d\n", encBufLen)
while encPtr < encBufEnd:
# state depends on whether we've received the block header count bytes
if self.decPhase == 0:
# Grab LSB of block size
self.decBuf[0] = encPtr[0]
#printf("decode: ok4a - LSB=%02x\n", encPtr[0])
self.decPhase = 1
encPtr = encPtr + 1
encBufLen = encBufLen - 1
continue
elif self.decPhase == 1:
# Grab MSB of block size and determine total block size
self.decBuf[1] = encPtr[0]
#printf("decode: ok4b - LSB=%02x\n", encPtr[0])
self.decBlkSize = self.decBuf[0] + 256 * self.decBuf[1]
# resize dec buffer to suit
# todo - find better way to sanity check the size
self.decBuf = realloc(
self.decBuf,
self.decBlkSize)
self.decPtr = self.decBuf
self.decNumBytes = 0
self.decPhase = 2
encPtr = encPtr + 1
encBufLen = encBufLen - 1
continue
else:
#printf("decode: ok4c siz=%d decnumbytes=%d\n",
# self.decBlkSize, self.decNumBytes)
needed = self.decBlkSize - self.decNumBytes
#printf("decode: ok4d encBufLen=%d needed=%d\n",
# encBufLen, needed)
# do we have enough input data to complete a frame?
if encBufLen >= needed:
newNumFrames = (decBlocks + 1) * self.encFramesPerBlock
# great - decode frame and add to our array of shorts
memcpy(self.decPtr,
encPtr,
self.decBlkSize - self.decNumBytes)
encPtr = encPtr + needed
encBufLen = encBufLen - needed
# do the decoding
# expand shorts and floats buffers
decShorts = realloc(decShorts, newNumFrames * sizeof(short))
decShorts1 = decShorts + decBlocks * self.encFramesPerBlock
decFloats = realloc(decFloats, newNumFrames * sizeof(float))
decFloats1 = decFloats + decBlocks * self.encFramesPerBlock
# Copy the data into the bit-stream struct
speex_bits_read_from(&self.decBits, self.decPtr, self.decBlkSize)
# Decode the data
speex_decode(self.decState, &self.decBits, decFloats1)
# Copy from float to short (16 bits) for output
for i from 0 <= i < self.encFramesPerBlock:
decShorts1[i] = decFloats1[i]
self.decPhase = 0 # back to awaiting LSB of count header
self.decNumBytes = 0
if self.debug:
printf("self.decBuf=%lx\n", self.decBuf)
self.decBuf = realloc(self.decBuf, 2)
decBlocks = decBlocks + 1
continue
else:
#printf("decode: ok4e\n")
# not enough to decode another speex frame - just stick into buffer
if self.debug:
printf("decPtr=%lx, encPtr=%lx, encBufLen=%d\n",
self.decPtr, encPtr, encBufLen)
memcpy(self.decPtr, encPtr, encBufLen)
self.decPtr = self.decPtr + encBufLen
encBufLen = 0
break
#printf("decode: ok5\n")
# did we get anything?
if decBlocks > 0:
numDecFrames = decBlocks * self.encFramesPerBlock
if is_raw:
ret = PyString_FromStringAndSize(decShorts, numDecFrames * 2)
else:
# build up a sequence of tuples
ret = []
for i in range(numDecFrames):
ret.append(decShorts[i])
else:
if is_raw:
ret = ""
else:
ret = []
#printf("decode: ok6\n")
free(decShorts)
free(decFloats)
return ret
# return Py_BuildValue("s#", decBuf, decBufLen)
#@-node:decode
#@-others
#@-node:cdef class new
#@-others
#@-node:@file speex.pyx
#@-leo
pyspeex-0.2/speex.c 0000644 0001750 0001750 00000165153 07760313542 014322 0 ustar thom thom 0000000 0000000 /* Generated by Pyrex 0.9 on Mon Nov 24 18:30:10 2003 */
#include "Python.h"
#include "structmember.h"
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
#include "math.h"
#include "speex.h"
static PyObject *__Pyx_UnpackItem(PyObject *, int); /*proto*/
static int __Pyx_EndUnpack(PyObject *, int); /*proto*/
static int __Pyx_PrintItem(PyObject *); /*proto*/
static int __Pyx_PrintNewline(void); /*proto*/
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static void __Pyx_ReRaise(void); /*proto*/
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
static PyObject *__Pyx_GetExcValue(void); /*proto*/
static PyObject *__Pyx_GetName(PyObject *dict, char *name); /*proto*/
static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name); /*proto*/
static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char *kwd_list[], int nargs, PyObject **args2, PyObject **kwds2); /*proto*/
static void __Pyx_WriteUnraisable(char *name); /*proto*/
static void __Pyx_AddTraceback(char *funcname); /*proto*/
static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size); /*proto*/
static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
static int __Pyx_GetVtable(PyObject *dict, void **vtabptr); /*proto*/
static PyObject *__pyx_m;
static PyObject *__pyx_b;
static int __pyx_lineno;
static char *__pyx_filename;
staticforward char **__pyx_f;
static char __pyx_mdoc[] = "\nspeex.pyx\n\nPython wrapper for Speex speech codec (www.speex.org)\nDefines a \'speex\' object through which encoding and\ndecoding of audio data can be performed.\n";
/* Declarations from speex */
staticforward PyTypeObject __pyx_type_5speex_new;
struct __pyx_obj_5speex_new {
PyObject_HEAD
void (*encState);
int encQuality;
int encFramesPerBlock;
float (*encBuf);
float (*encPtr);
int encNumFrames;
SpeexBits encBits;
int raw;
void (*decState);
int decQuality;
unsigned char (*decBuf);
unsigned char (*decPtr);
unsigned short decBlkSize;
int decNumBytes;
int decPhase;
int decEnhanceOn;
SpeexBits decBits;
PyObject *debug;
PyObject *endianness;
};
static PyTypeObject *__pyx_ptype_5speex_new = 0;
static PyObject *__pyx_k2;
static PyObject *__pyx_k3;
static PyObject *__pyx_k4;
static PyObject *__pyx_k5;
/* Implementation of speex */
static char (__pyx_k1[]) = "0.2";
static char (__pyx_k6[]) = "debug";
static char (__pyx_k7[]) = "Out of memory";
static char (__pyx_k8[]) = "Out of memory";
static int __pyx_f_5speex_3new___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5speex_3new___init__[] = "\n Create a new speex speech stream object\n \n Arguments:\n - quality - 0 (lowest) to 10 (highest), default 8\n \n - raw - set to 1 for encoding from and decoding to string, default 0\n \n Keywords:\n - debug - set to 1 to issue debug messages, default 0\n \n The created speex stream object has two methods:\n - encode - encode a block of speech audio data\n \n Arguments:\n - block of audio data, as sequence of frames, where\n each frame is an int\n \n Returns:\n - raw string containing encoded data, or\n empty string if there is not yet any encoded\n data available\n \n - decode - decodes a block of speech audio data\n \n Arguments:\n - block of encoded data, as raw string,\n \n Returns:\n - block of audio data, as sequence of ints, or\n an empty sequence if there is no decoded data\n available yet\n \n Notes:\n - Both of these methods use internal buffering, which means that\n you can feed in data piecemeal. This helps a lot when sending and\n receiving data over the net.\n ";
static int __pyx_f_5speex_3new___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_quality = 0;
PyObject *__pyx_v_raw = 0;
PyObject *__pyx_v_kw = 0;
int __pyx_v_is_raw;
int __pyx_r;
int __pyx_1;
PyObject *__pyx_2 = 0;
PyObject *__pyx_3 = 0;
PyObject *__pyx_4 = 0;
PyObject *__pyx_5 = 0;
PyObject *__pyx_6 = 0;
static char *__pyx_argnames[] = {"quality","raw",0};
__pyx_v_quality = __pyx_k2;
__pyx_v_raw = __pyx_k3;
if (__Pyx_GetStarArgs(&__pyx_args, &__pyx_kwds, __pyx_argnames, 2, 0, &__pyx_v_kw) < 0) return -1;
if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "|OO", __pyx_argnames, &__pyx_v_quality, &__pyx_v_raw)) {
Py_XDECREF(__pyx_args);
Py_XDECREF(__pyx_kwds);
Py_XDECREF(__pyx_v_kw);
return -1;
}
Py_INCREF(__pyx_v_self);
Py_INCREF(__pyx_v_quality);
Py_INCREF(__pyx_v_raw);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":176 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->encState = speex_encoder_init((&speex_nb_mode));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":178 */
__pyx_1 = PyInt_AsLong(__pyx_v_quality); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; goto __pyx_L1;}
((struct __pyx_obj_5speex_new *)__pyx_v_self)->encQuality = __pyx_1;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":179 */
__pyx_1 = PyInt_AsLong(__pyx_v_raw); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; goto __pyx_L1;}
__pyx_v_is_raw = __pyx_1;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":180 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->raw = __pyx_v_is_raw;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":181 */
__pyx_2 = __Pyx_GetName(__pyx_b, "int"); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; goto __pyx_L1;}
__pyx_3 = PyObject_GetAttrString(__pyx_v_kw, "get"); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; goto __pyx_L1;}
__pyx_4 = PyString_FromString(__pyx_k6); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; goto __pyx_L1;}
__pyx_5 = PyInt_FromLong(0); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; goto __pyx_L1;}
__pyx_6 = PyTuple_New(2); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; goto __pyx_L1;}
PyTuple_SET_ITEM(__pyx_6, 0, __pyx_4);
PyTuple_SET_ITEM(__pyx_6, 1, __pyx_5);
__pyx_4 = 0;
__pyx_5 = 0;
__pyx_4 = PyObject_CallObject(__pyx_3, __pyx_6); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; goto __pyx_L1;}
Py_DECREF(__pyx_3); __pyx_3 = 0;
Py_DECREF(__pyx_6); __pyx_6 = 0;
__pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; goto __pyx_L1;}
PyTuple_SET_ITEM(__pyx_5, 0, __pyx_4);
__pyx_4 = 0;
__pyx_3 = PyObject_CallObject(__pyx_2, __pyx_5); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; goto __pyx_L1;}
Py_DECREF(__pyx_2); __pyx_2 = 0;
Py_DECREF(__pyx_5); __pyx_5 = 0;
Py_DECREF(((struct __pyx_obj_5speex_new *)__pyx_v_self)->debug);
((struct __pyx_obj_5speex_new *)__pyx_v_self)->debug = __pyx_3;
__pyx_3 = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":183 */
speex_encoder_ctl(((struct __pyx_obj_5speex_new *)__pyx_v_self)->encState,SPEEX_SET_QUALITY,(&((struct __pyx_obj_5speex_new *)__pyx_v_self)->encQuality));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":187 */
speex_encoder_ctl(((struct __pyx_obj_5speex_new *)__pyx_v_self)->encState,SPEEX_GET_FRAME_SIZE,(&((struct __pyx_obj_5speex_new *)__pyx_v_self)->encFramesPerBlock));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":189 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->encBuf = ((float (*))malloc((((struct __pyx_obj_5speex_new *)__pyx_v_self)->encFramesPerBlock * (sizeof(float )))));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":190 */
__pyx_1 = (!(((struct __pyx_obj_5speex_new *)__pyx_v_self)->encBuf != 0));
if (__pyx_1) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":191 */
__pyx_6 = __Pyx_GetName(__pyx_b, "Exception"); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; goto __pyx_L1;}
__pyx_4 = PyString_FromString(__pyx_k7); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; goto __pyx_L1;}
__pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; goto __pyx_L1;}
PyTuple_SET_ITEM(__pyx_2, 0, __pyx_4);
__pyx_4 = 0;
__pyx_5 = PyObject_CallObject(__pyx_6, __pyx_2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; goto __pyx_L1;}
Py_DECREF(__pyx_6); __pyx_6 = 0;
Py_DECREF(__pyx_2); __pyx_2 = 0;
__Pyx_Raise(__pyx_5, 0, 0);
Py_DECREF(__pyx_5); __pyx_5 = 0;
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; goto __pyx_L1;}
goto __pyx_L2;
}
__pyx_L2:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":192 */
memset(((struct __pyx_obj_5speex_new *)__pyx_v_self)->encBuf,0,(((struct __pyx_obj_5speex_new *)__pyx_v_self)->encFramesPerBlock * (sizeof(float ))));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":193 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->encNumFrames = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":194 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->encPtr = ((struct __pyx_obj_5speex_new *)__pyx_v_self)->encBuf;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":195 */
speex_bits_init((&((struct __pyx_obj_5speex_new *)__pyx_v_self)->encBits));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":198 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->decState = speex_decoder_init((&speex_nb_mode));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":199 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->decEnhanceOn = 1;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":200 */
speex_decoder_ctl(((struct __pyx_obj_5speex_new *)__pyx_v_self)->decState,SPEEX_SET_ENH,(&((struct __pyx_obj_5speex_new *)__pyx_v_self)->decEnhanceOn));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":201 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBuf = ((unsigned char (*))malloc(2));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":202 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->decPhase = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":203 */
__pyx_1 = (!(((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBuf != 0));
if (__pyx_1) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":204 */
__pyx_3 = __Pyx_GetName(__pyx_b, "Exception"); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; goto __pyx_L1;}
__pyx_4 = PyString_FromString(__pyx_k8); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; goto __pyx_L1;}
__pyx_6 = PyTuple_New(1); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; goto __pyx_L1;}
PyTuple_SET_ITEM(__pyx_6, 0, __pyx_4);
__pyx_4 = 0;
__pyx_2 = PyObject_CallObject(__pyx_3, __pyx_6); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; goto __pyx_L1;}
Py_DECREF(__pyx_3); __pyx_3 = 0;
Py_DECREF(__pyx_6); __pyx_6 = 0;
__Pyx_Raise(__pyx_2, 0, 0);
Py_DECREF(__pyx_2); __pyx_2 = 0;
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; goto __pyx_L1;}
goto __pyx_L3;
}
__pyx_L3:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":205 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->decPtr = ((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBuf;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":206 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->decNumBytes = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":207 */
speex_bits_init((&((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBits));
__pyx_r = 0;
goto __pyx_L0;
__pyx_L1:;
Py_XDECREF(__pyx_2);
Py_XDECREF(__pyx_3);
Py_XDECREF(__pyx_4);
Py_XDECREF(__pyx_5);
Py_XDECREF(__pyx_6);
__Pyx_AddTraceback("speex.new.__init__");
__pyx_r = -1;
__pyx_L0:;
Py_XDECREF(__pyx_v_kw);
Py_DECREF(__pyx_v_self);
Py_DECREF(__pyx_v_quality);
Py_DECREF(__pyx_v_raw);
Py_XDECREF(__pyx_args);
Py_XDECREF(__pyx_kwds);
return __pyx_r;
}
static void __pyx_f_5speex_3new___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_f_5speex_3new___dealloc__(PyObject *__pyx_v_self) {
int __pyx_1;
Py_INCREF(__pyx_v_self);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":212 */
speex_encoder_destroy(((struct __pyx_obj_5speex_new *)__pyx_v_self)->encState);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":213 */
__pyx_1 = (((struct __pyx_obj_5speex_new *)__pyx_v_self)->encBuf != 0);
if (__pyx_1) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":214 */
free(((struct __pyx_obj_5speex_new *)__pyx_v_self)->encBuf);
goto __pyx_L2;
}
__pyx_L2:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":217 */
speex_decoder_destroy(((struct __pyx_obj_5speex_new *)__pyx_v_self)->decState);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":218 */
__pyx_1 = (((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBuf != 0);
if (__pyx_1) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":219 */
free(((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBuf);
goto __pyx_L3;
}
__pyx_L3:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":222 */
speex_bits_destroy((&((struct __pyx_obj_5speex_new *)__pyx_v_self)->encBits));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":223 */
speex_bits_destroy((&((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBits));
goto __pyx_L0;
__pyx_L1:;
__Pyx_AddTraceback("speex.new.__dealloc__");
__pyx_L0:;
Py_DECREF(__pyx_v_self);
}
static char (__pyx_k9[]) = "";
static char (__pyx_k10[]) = "";
static char (__pyx_k11[]) = "Out of memory";
static PyObject *__pyx_f_5speex_3new_encode(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5speex_3new_encode[] = "\n Encode some audio data\n \n Arguments:\n - data - sequence of audio frames to encode, OR string of 16-bit frames\n \n - raw - true if data being passed in is a string of 16-bit frames\n defaults to whatever raw arg was passed to constructor\n \n Returns:\n - raw string with encoded data\n ";
static PyObject *__pyx_f_5speex_3new_encode(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_input = 0;
PyObject *__pyx_v_raw = 0;
int __pyx_v_numInputFrames;
float (*__pyx_v_framesBuf);
float (*__pyx_v_framesPtr);
int __pyx_v_i;
int __pyx_v_totFrames;
int __pyx_v_cbitsSiz;
char (__pyx_v_cbits[2048]);
int __pyx_v_nBlocks;
int __pyx_v_nBytes;
char (*__pyx_v_bufOut);
int __pyx_v_bufOutSiz;
int __pyx_v_remainder;
char (*__pyx_v_rawbuf);
short (*__pyx_v_frameptr);
PyObject *__pyx_v_inputFramesList;
PyObject *__pyx_r;
PyObject *__pyx_1 = 0;
int __pyx_2;
PyObject *__pyx_3 = 0;
PyObject *__pyx_4 = 0;
PyObject *__pyx_5 = 0;
char (*__pyx_6);
float __pyx_7;
static char *__pyx_argnames[] = {"input","raw",0};
__pyx_v_raw = __pyx_k4;
if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O|O", __pyx_argnames, &__pyx_v_input, &__pyx_v_raw)) return 0;
Py_INCREF(__pyx_v_self);
Py_INCREF(__pyx_v_input);
Py_INCREF(__pyx_v_raw);
__pyx_v_inputFramesList = Py_None; Py_INCREF(__pyx_v_inputFramesList);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":260 */
__pyx_v_cbitsSiz = ((((struct __pyx_obj_5speex_new *)__pyx_v_self)->encFramesPerBlock * 5) / 4);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":261 */
__pyx_v_bufOut = ((char (*))malloc(0));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":262 */
__pyx_v_bufOutSiz = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":264 */
__pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 264; goto __pyx_L1;}
Py_DECREF(__pyx_v_inputFramesList);
__pyx_v_inputFramesList = __pyx_1;
__pyx_1 = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":269 */
__pyx_2 = __pyx_v_raw == Py_None;
if (__pyx_2) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":270 */
__pyx_1 = PyInt_FromLong(((struct __pyx_obj_5speex_new *)__pyx_v_self)->raw); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 270; goto __pyx_L1;}
Py_DECREF(__pyx_v_raw);
__pyx_v_raw = __pyx_1;
__pyx_1 = 0;
goto __pyx_L2;
}
__pyx_L2:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":271 */
__pyx_1 = __Pyx_GetName(__pyx_b, "type"); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; goto __pyx_L1;}
__pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; goto __pyx_L1;}
Py_INCREF(__pyx_v_input);
PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_input);
__pyx_4 = PyObject_CallObject(__pyx_1, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; goto __pyx_L1;}
Py_DECREF(__pyx_1); __pyx_1 = 0;
Py_DECREF(__pyx_3); __pyx_3 = 0;
__pyx_1 = __Pyx_GetName(__pyx_b, "type"); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; goto __pyx_L1;}
__pyx_3 = PyString_FromString(__pyx_k9); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; goto __pyx_L1;}
__pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; goto __pyx_L1;}
PyTuple_SET_ITEM(__pyx_5, 0, __pyx_3);
__pyx_3 = 0;
__pyx_3 = PyObject_CallObject(__pyx_1, __pyx_5); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; goto __pyx_L1;}
Py_DECREF(__pyx_1); __pyx_1 = 0;
Py_DECREF(__pyx_5); __pyx_5 = 0;
__pyx_2 = __pyx_4 == __pyx_3;
Py_DECREF(__pyx_4); __pyx_4 = 0;
Py_DECREF(__pyx_3); __pyx_3 = 0;
if (__pyx_2) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":272 */
__pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 272; goto __pyx_L1;}
Py_DECREF(__pyx_v_raw);
__pyx_v_raw = __pyx_1;
__pyx_1 = 0;
goto __pyx_L3;
}
__pyx_L3:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":275 */
__pyx_2 = PyObject_IsTrue(__pyx_v_raw); if (__pyx_2 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; goto __pyx_L1;}
if (__pyx_2) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":276 */
__pyx_5 = __Pyx_GetName(__pyx_b, "len"); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
__pyx_4 = PyTuple_New(1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
Py_INCREF(__pyx_v_input);
PyTuple_SET_ITEM(__pyx_4, 0, __pyx_v_input);
__pyx_3 = PyObject_CallObject(__pyx_5, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
Py_DECREF(__pyx_5); __pyx_5 = 0;
Py_DECREF(__pyx_4); __pyx_4 = 0;
__pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
__pyx_5 = PyNumber_Divide(__pyx_3, __pyx_1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
Py_DECREF(__pyx_3); __pyx_3 = 0;
Py_DECREF(__pyx_1); __pyx_1 = 0;
__pyx_2 = PyInt_AsLong(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; goto __pyx_L1;}
Py_DECREF(__pyx_5); __pyx_5 = 0;
__pyx_v_numInputFrames = __pyx_2;
goto __pyx_L4;
}
/*else*/ {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":278 */
__pyx_4 = __Pyx_GetName(__pyx_b, "len"); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; goto __pyx_L1;}
__pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; goto __pyx_L1;}
Py_INCREF(__pyx_v_input);
PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_input);
__pyx_1 = PyObject_CallObject(__pyx_4, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; goto __pyx_L1;}
Py_DECREF(__pyx_4); __pyx_4 = 0;
Py_DECREF(__pyx_3); __pyx_3 = 0;
__pyx_2 = PyInt_AsLong(__pyx_1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; goto __pyx_L1;}
Py_DECREF(__pyx_1); __pyx_1 = 0;
__pyx_v_numInputFrames = __pyx_2;
}
__pyx_L4:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":284 */
__pyx_2 = (__pyx_v_numInputFrames == 0);
if (__pyx_2) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":285 */
__pyx_5 = PyString_FromString(__pyx_k10); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; goto __pyx_L1;}
__pyx_r = __pyx_5;
__pyx_5 = 0;
goto __pyx_L0;
goto __pyx_L5;
}
__pyx_L5:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":290 */
__pyx_v_totFrames = (__pyx_v_numInputFrames + ((struct __pyx_obj_5speex_new *)__pyx_v_self)->encNumFrames);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":295 */
__pyx_v_framesBuf = ((float (*))malloc((__pyx_v_totFrames * (sizeof(float )))));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":296 */
__pyx_v_framesPtr = __pyx_v_framesBuf;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":297 */
__pyx_2 = (!(__pyx_v_framesBuf != 0));
if (__pyx_2) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":298 */
__pyx_4 = __Pyx_GetName(__pyx_b, "Exception"); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; goto __pyx_L1;}
__pyx_3 = PyString_FromString(__pyx_k11); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; goto __pyx_L1;}
__pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; goto __pyx_L1;}
PyTuple_SET_ITEM(__pyx_1, 0, __pyx_3);
__pyx_3 = 0;
__pyx_5 = PyObject_CallObject(__pyx_4, __pyx_1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; goto __pyx_L1;}
Py_DECREF(__pyx_4); __pyx_4 = 0;
Py_DECREF(__pyx_1); __pyx_1 = 0;
__Pyx_Raise(__pyx_5, 0, 0);
Py_DECREF(__pyx_5); __pyx_5 = 0;
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; goto __pyx_L1;}
goto __pyx_L6;
}
__pyx_L6:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":304 */
__pyx_2 = ((struct __pyx_obj_5speex_new *)__pyx_v_self)->encNumFrames;
for (__pyx_v_i = 0; __pyx_v_i < __pyx_2; ++__pyx_v_i) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":305 */
(__pyx_v_framesPtr[__pyx_v_i]) = (((struct __pyx_obj_5speex_new *)__pyx_v_self)->encBuf[__pyx_v_i]);
__pyx_L7:;
}
__pyx_L8:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":310 */
__pyx_v_framesPtr = (__pyx_v_framesPtr + __pyx_v_i);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":316 */
__pyx_2 = PyObject_IsTrue(__pyx_v_raw); if (__pyx_2 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 316; goto __pyx_L1;}
if (__pyx_2) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":317 */
__pyx_6 = PyString_AsString(__pyx_v_input); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; goto __pyx_L1;}
__pyx_v_rawbuf = __pyx_6;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":318 */
__pyx_v_frameptr = ((short (*))__pyx_v_rawbuf);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":319 */
for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_numInputFrames; ++__pyx_v_i) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":325 */
(__pyx_v_framesPtr[__pyx_v_i]) = (__pyx_v_frameptr[__pyx_v_i]);
__pyx_L10:;
}
__pyx_L11:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":326 */
__pyx_v_framesPtr = (__pyx_v_framesPtr + __pyx_v_i);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":327 */
__pyx_v_frameptr = (__pyx_v_frameptr + __pyx_v_i);
goto __pyx_L9;
}
/*else*/ {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":336 */
for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_numInputFrames; ++__pyx_v_i) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":337 */
__pyx_3 = PyInt_FromLong(__pyx_v_i); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 337; goto __pyx_L1;}
__pyx_4 = PyObject_GetItem(__pyx_v_input, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 337; goto __pyx_L1;}
Py_DECREF(__pyx_3); __pyx_3 = 0;
__pyx_7 = PyFloat_AsDouble(__pyx_4); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 337; goto __pyx_L1;}
Py_DECREF(__pyx_4); __pyx_4 = 0;
(__pyx_v_framesPtr[__pyx_v_i]) = __pyx_7;
__pyx_L12:;
}
__pyx_L13:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":338 */
__pyx_v_framesPtr = (__pyx_v_framesPtr + __pyx_v_i);
}
__pyx_L9:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":351 */
__pyx_v_nBlocks = (__pyx_v_totFrames / ((struct __pyx_obj_5speex_new *)__pyx_v_self)->encFramesPerBlock);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":352 */
__pyx_v_framesPtr = __pyx_v_framesBuf;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":353 */
for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_nBlocks; ++__pyx_v_i) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":355 */
speex_bits_reset((&((struct __pyx_obj_5speex_new *)__pyx_v_self)->encBits));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":358 */
speex_encode(((struct __pyx_obj_5speex_new *)__pyx_v_self)->encState,__pyx_v_framesPtr,(&((struct __pyx_obj_5speex_new *)__pyx_v_self)->encBits));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":360 */
__pyx_v_nBytes = speex_bits_write((&((struct __pyx_obj_5speex_new *)__pyx_v_self)->encBits),__pyx_v_cbits,__pyx_v_cbitsSiz);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":362 */
__pyx_v_bufOut = ((char (*))realloc(__pyx_v_bufOut,((__pyx_v_bufOutSiz + __pyx_v_nBytes) + 2)));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":365 */
(__pyx_v_bufOut[__pyx_v_bufOutSiz]) = (__pyx_v_nBytes % 256);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":366 */
(__pyx_v_bufOut[(__pyx_v_bufOutSiz + 1)]) = (__pyx_v_nBytes / 256);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":367 */
__pyx_v_bufOutSiz = (__pyx_v_bufOutSiz + 2);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":368 */
memcpy((__pyx_v_bufOut + __pyx_v_bufOutSiz),__pyx_v_cbits,__pyx_v_nBytes);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":370 */
__pyx_v_bufOutSiz = (__pyx_v_bufOutSiz + __pyx_v_nBytes);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":373 */
__pyx_v_framesPtr = (__pyx_v_framesPtr + ((struct __pyx_obj_5speex_new *)__pyx_v_self)->encFramesPerBlock);
__pyx_L14:;
}
__pyx_L15:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":378 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->encNumFrames = (__pyx_v_totFrames - (__pyx_v_nBlocks * ((struct __pyx_obj_5speex_new *)__pyx_v_self)->encFramesPerBlock));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":379 */
__pyx_v_remainder = (((struct __pyx_obj_5speex_new *)__pyx_v_self)->encNumFrames * (sizeof(float )));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":380 */
memcpy(((struct __pyx_obj_5speex_new *)__pyx_v_self)->encBuf,__pyx_v_framesPtr,__pyx_v_remainder);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":388 */
free(__pyx_v_framesBuf);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":394 */
__pyx_1 = PyString_FromStringAndSize(__pyx_v_bufOut,__pyx_v_bufOutSiz); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 394; goto __pyx_L1;}
__pyx_r = __pyx_1;
__pyx_1 = 0;
goto __pyx_L0;
__pyx_r = Py_None; Py_INCREF(__pyx_r);
goto __pyx_L0;
__pyx_L1:;
Py_XDECREF(__pyx_1);
Py_XDECREF(__pyx_3);
Py_XDECREF(__pyx_4);
Py_XDECREF(__pyx_5);
__Pyx_AddTraceback("speex.new.encode");
__pyx_r = 0;
__pyx_L0:;
Py_DECREF(__pyx_v_inputFramesList);
Py_DECREF(__pyx_v_self);
Py_DECREF(__pyx_v_input);
Py_DECREF(__pyx_v_raw);
return __pyx_r;
}
static char (__pyx_k12[]) = "";
static char (__pyx_k13[]) = "self.decBuf=%lx\n";
static char (__pyx_k14[]) = "decPtr=%lx, encPtr=%lx, encBufLen=%d\n";
static char (__pyx_k15[]) = "";
static PyObject *__pyx_f_5speex_3new_decode(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5speex_3new_decode[] = "\n Decode an encoded block, return as sequence of frame tuples\n \n Arguments:\n - encoded - raw string, containing encoded data\n - raw - True if data is to be returned as string of 16-bit frames, defaults to\n whatever raw value was passed to constructor\n \n Returns:\n - decoded blocks, as sequence of frames, where each frame\n or a string of these 16-bit frames if raw is True\n is an int\n ";
static PyObject *__pyx_f_5speex_3new_decode(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_input = 0;
PyObject *__pyx_v_raw = 0;
unsigned char (*__pyx_v_encBuf);
unsigned char (*__pyx_v_encBufEnd);
unsigned char (*__pyx_v_encPtr);
int __pyx_v_encBufLen;
int __pyx_v_numDecFrames;
float (*__pyx_v_decFloats);
float (*__pyx_v_decFloats1);
short (*__pyx_v_decShorts);
short (*__pyx_v_decShorts1);
int __pyx_v_decBlocks;
int __pyx_v_i;
int __pyx_v_is_raw;
int __pyx_v_needed;
int __pyx_v_newNumFrames;
char (*__pyx_v_tmp);
PyObject *__pyx_v_ret;
PyObject *__pyx_r;
char (*__pyx_1);
int __pyx_2;
PyObject *__pyx_3 = 0;
PyObject *__pyx_4 = 0;
PyObject *__pyx_5 = 0;
PyObject *__pyx_6 = 0;
static char *__pyx_argnames[] = {"input","raw",0};
__pyx_v_raw = __pyx_k5;
if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O|O", __pyx_argnames, &__pyx_v_input, &__pyx_v_raw)) return 0;
Py_INCREF(__pyx_v_self);
Py_INCREF(__pyx_v_input);
Py_INCREF(__pyx_v_raw);
__pyx_v_ret = Py_None; Py_INCREF(__pyx_v_ret);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":434 */
__pyx_1 = PyString_AsString(__pyx_v_input); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; goto __pyx_L1;}
__pyx_v_tmp = __pyx_1;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":435 */
__pyx_v_encBuf = ((unsigned char (*))__pyx_v_tmp);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":436 */
__pyx_v_encBufEnd = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":437 */
__pyx_v_encPtr = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":438 */
__pyx_v_encBufLen = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":439 */
__pyx_v_decFloats = ((float (*))malloc(0));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":440 */
__pyx_v_decShorts = ((short (*))malloc(0));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":441 */
__pyx_v_decBlocks = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":443 */
__pyx_2 = __pyx_v_raw == Py_None;
if (__pyx_2) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":444 */
__pyx_3 = PyInt_FromLong(((struct __pyx_obj_5speex_new *)__pyx_v_self)->raw); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 444; goto __pyx_L1;}
Py_DECREF(__pyx_v_raw);
__pyx_v_raw = __pyx_3;
__pyx_3 = 0;
goto __pyx_L2;
}
__pyx_L2:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":445 */
__pyx_2 = PyInt_AsLong(__pyx_v_raw); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 445; goto __pyx_L1;}
__pyx_v_is_raw = __pyx_2;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":450 */
__pyx_3 = __Pyx_GetName(__pyx_b, "len"); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; goto __pyx_L1;}
__pyx_4 = PyTuple_New(1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; goto __pyx_L1;}
Py_INCREF(__pyx_v_input);
PyTuple_SET_ITEM(__pyx_4, 0, __pyx_v_input);
__pyx_5 = PyObject_CallObject(__pyx_3, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; goto __pyx_L1;}
Py_DECREF(__pyx_3); __pyx_3 = 0;
Py_DECREF(__pyx_4); __pyx_4 = 0;
__pyx_2 = PyInt_AsLong(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; goto __pyx_L1;}
Py_DECREF(__pyx_5); __pyx_5 = 0;
__pyx_v_encBufLen = __pyx_2;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":451 */
__pyx_2 = (__pyx_v_encBufLen == 0);
if (__pyx_2) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":452 */
__pyx_2 = __pyx_v_is_raw;
if (__pyx_2) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":453 */
__pyx_3 = PyString_FromString(__pyx_k12); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 453; goto __pyx_L1;}
__pyx_r = __pyx_3;
__pyx_3 = 0;
goto __pyx_L0;
goto __pyx_L4;
}
/*else*/ {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":455 */
__pyx_4 = PyList_New(0); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; goto __pyx_L1;}
__pyx_r = __pyx_4;
__pyx_4 = 0;
goto __pyx_L0;
}
__pyx_L4:;
goto __pyx_L3;
}
__pyx_L3:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":460 */
__pyx_v_encPtr = __pyx_v_encBuf;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":461 */
__pyx_v_encBufEnd = (__pyx_v_encBuf + __pyx_v_encBufLen);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":465 */
while (1) {
__pyx_L5:;
__pyx_2 = (__pyx_v_encPtr < __pyx_v_encBufEnd);
if (!__pyx_2) break;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":467 */
__pyx_2 = (((struct __pyx_obj_5speex_new *)__pyx_v_self)->decPhase == 0);
if (__pyx_2) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":469 */
(((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBuf[0]) = (__pyx_v_encPtr[0]);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":471 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->decPhase = 1;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":472 */
__pyx_v_encPtr = (__pyx_v_encPtr + 1);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":473 */
__pyx_v_encBufLen = (__pyx_v_encBufLen - 1);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":474 */
goto __pyx_L5;
goto __pyx_L7;
}
__pyx_2 = (((struct __pyx_obj_5speex_new *)__pyx_v_self)->decPhase == 1);
if (__pyx_2) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":477 */
(((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBuf[1]) = (__pyx_v_encPtr[0]);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":479 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBlkSize = ((((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBuf[0]) + (256 * (((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBuf[1])));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":483 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBuf = ((unsigned char (*))realloc(((void (*))((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBuf),((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBlkSize));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":486 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->decPtr = ((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBuf;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":487 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->decNumBytes = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":488 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->decPhase = 2;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":489 */
__pyx_v_encPtr = (__pyx_v_encPtr + 1);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":490 */
__pyx_v_encBufLen = (__pyx_v_encBufLen - 1);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":491 */
goto __pyx_L5;
goto __pyx_L7;
}
/*else*/ {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":495 */
__pyx_v_needed = (((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBlkSize - ((struct __pyx_obj_5speex_new *)__pyx_v_self)->decNumBytes);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":500 */
__pyx_2 = (__pyx_v_encBufLen >= __pyx_v_needed);
if (__pyx_2) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":501 */
__pyx_v_newNumFrames = ((__pyx_v_decBlocks + 1) * ((struct __pyx_obj_5speex_new *)__pyx_v_self)->encFramesPerBlock);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":504 */
memcpy(((struct __pyx_obj_5speex_new *)__pyx_v_self)->decPtr,__pyx_v_encPtr,(((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBlkSize - ((struct __pyx_obj_5speex_new *)__pyx_v_self)->decNumBytes));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":507 */
__pyx_v_encPtr = (__pyx_v_encPtr + __pyx_v_needed);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":508 */
__pyx_v_encBufLen = (__pyx_v_encBufLen - __pyx_v_needed);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":512 */
__pyx_v_decShorts = ((short (*))realloc(__pyx_v_decShorts,(__pyx_v_newNumFrames * (sizeof(short )))));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":513 */
__pyx_v_decShorts1 = (__pyx_v_decShorts + (__pyx_v_decBlocks * ((struct __pyx_obj_5speex_new *)__pyx_v_self)->encFramesPerBlock));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":514 */
__pyx_v_decFloats = ((float (*))realloc(__pyx_v_decFloats,(__pyx_v_newNumFrames * (sizeof(float )))));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":515 */
__pyx_v_decFloats1 = (__pyx_v_decFloats + (__pyx_v_decBlocks * ((struct __pyx_obj_5speex_new *)__pyx_v_self)->encFramesPerBlock));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":518 */
speex_bits_read_from((&((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBits),((char (*))((struct __pyx_obj_5speex_new *)__pyx_v_self)->decPtr),((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBlkSize);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":521 */
speex_decode(((struct __pyx_obj_5speex_new *)__pyx_v_self)->decState,(&((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBits),__pyx_v_decFloats1);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":524 */
__pyx_2 = ((struct __pyx_obj_5speex_new *)__pyx_v_self)->encFramesPerBlock;
for (__pyx_v_i = 0; __pyx_v_i < __pyx_2; ++__pyx_v_i) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":525 */
(__pyx_v_decShorts1[__pyx_v_i]) = (__pyx_v_decFloats1[__pyx_v_i]);
__pyx_L9:;
}
__pyx_L10:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":527 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->decPhase = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":528 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->decNumBytes = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":529 */
__pyx_2 = PyObject_IsTrue(((struct __pyx_obj_5speex_new *)__pyx_v_self)->debug); if (__pyx_2 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 529; goto __pyx_L1;}
if (__pyx_2) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":530 */
printf(__pyx_k13,((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBuf);
goto __pyx_L11;
}
__pyx_L11:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":531 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBuf = ((unsigned char (*))realloc(((struct __pyx_obj_5speex_new *)__pyx_v_self)->decBuf,2));
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":532 */
__pyx_v_decBlocks = (__pyx_v_decBlocks + 1);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":533 */
goto __pyx_L5;
goto __pyx_L8;
}
/*else*/ {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":538 */
__pyx_2 = PyObject_IsTrue(((struct __pyx_obj_5speex_new *)__pyx_v_self)->debug); if (__pyx_2 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; goto __pyx_L1;}
if (__pyx_2) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":539 */
printf(__pyx_k14,((struct __pyx_obj_5speex_new *)__pyx_v_self)->decPtr,__pyx_v_encPtr,__pyx_v_encBufLen);
goto __pyx_L12;
}
__pyx_L12:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":541 */
memcpy(((struct __pyx_obj_5speex_new *)__pyx_v_self)->decPtr,__pyx_v_encPtr,__pyx_v_encBufLen);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":542 */
((struct __pyx_obj_5speex_new *)__pyx_v_self)->decPtr = (((struct __pyx_obj_5speex_new *)__pyx_v_self)->decPtr + __pyx_v_encBufLen);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":543 */
__pyx_v_encBufLen = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":544 */
goto __pyx_L6;
}
__pyx_L8:;
}
__pyx_L7:;
}
__pyx_L6:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":549 */
__pyx_2 = (__pyx_v_decBlocks > 0);
if (__pyx_2) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":550 */
__pyx_v_numDecFrames = (__pyx_v_decBlocks * ((struct __pyx_obj_5speex_new *)__pyx_v_self)->encFramesPerBlock);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":552 */
__pyx_2 = __pyx_v_is_raw;
if (__pyx_2) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":553 */
__pyx_5 = PyString_FromStringAndSize(((char (*))__pyx_v_decShorts),(__pyx_v_numDecFrames * 2)); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 553; goto __pyx_L1;}
Py_DECREF(__pyx_v_ret);
__pyx_v_ret = __pyx_5;
__pyx_5 = 0;
goto __pyx_L14;
}
/*else*/ {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":556 */
__pyx_3 = PyList_New(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; goto __pyx_L1;}
Py_DECREF(__pyx_v_ret);
__pyx_v_ret = __pyx_3;
__pyx_3 = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":557 */
__pyx_4 = __Pyx_GetName(__pyx_b, "range"); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 557; goto __pyx_L1;}
__pyx_5 = PyInt_FromLong(__pyx_v_numDecFrames); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 557; goto __pyx_L1;}
__pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 557; goto __pyx_L1;}
PyTuple_SET_ITEM(__pyx_3, 0, __pyx_5);
__pyx_5 = 0;
__pyx_5 = PyObject_CallObject(__pyx_4, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 557; goto __pyx_L1;}
Py_DECREF(__pyx_4); __pyx_4 = 0;
Py_DECREF(__pyx_3); __pyx_3 = 0;
__pyx_4 = PyObject_GetIter(__pyx_5); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 557; goto __pyx_L1;}
Py_DECREF(__pyx_5); __pyx_5 = 0;
for (;;) {
__pyx_L15:;
__pyx_3 = PyIter_Next(__pyx_4);
if (!__pyx_3) {
if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 557; goto __pyx_L1;}
break;
}
__pyx_2 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 557; goto __pyx_L1;}
Py_DECREF(__pyx_3); __pyx_3 = 0;
__pyx_v_i = __pyx_2;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":558 */
__pyx_5 = PyObject_GetAttrString(__pyx_v_ret, "append"); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; goto __pyx_L1;}
__pyx_3 = PyInt_FromLong((__pyx_v_decShorts[__pyx_v_i])); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; goto __pyx_L1;}
__pyx_6 = PyTuple_New(1); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; goto __pyx_L1;}
PyTuple_SET_ITEM(__pyx_6, 0, __pyx_3);
__pyx_3 = 0;
__pyx_3 = PyObject_CallObject(__pyx_5, __pyx_6); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; goto __pyx_L1;}
Py_DECREF(__pyx_5); __pyx_5 = 0;
Py_DECREF(__pyx_6); __pyx_6 = 0;
Py_DECREF(__pyx_3); __pyx_3 = 0;
}
__pyx_L16:;
Py_DECREF(__pyx_4); __pyx_4 = 0;
}
__pyx_L14:;
goto __pyx_L13;
}
/*else*/ {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":560 */
__pyx_2 = __pyx_v_is_raw;
if (__pyx_2) {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":561 */
__pyx_5 = PyString_FromString(__pyx_k15); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; goto __pyx_L1;}
Py_DECREF(__pyx_v_ret);
__pyx_v_ret = __pyx_5;
__pyx_5 = 0;
goto __pyx_L17;
}
/*else*/ {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":563 */
__pyx_6 = PyList_New(0); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 563; goto __pyx_L1;}
Py_DECREF(__pyx_v_ret);
__pyx_v_ret = __pyx_6;
__pyx_6 = 0;
}
__pyx_L17:;
}
__pyx_L13:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":567 */
free(__pyx_v_decShorts);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":568 */
free(__pyx_v_decFloats);
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":569 */
Py_INCREF(__pyx_v_ret);
__pyx_r = __pyx_v_ret;
goto __pyx_L0;
__pyx_r = Py_None; Py_INCREF(__pyx_r);
goto __pyx_L0;
__pyx_L1:;
Py_XDECREF(__pyx_3);
Py_XDECREF(__pyx_4);
Py_XDECREF(__pyx_5);
Py_XDECREF(__pyx_6);
__Pyx_AddTraceback("speex.new.decode");
__pyx_r = 0;
__pyx_L0:;
Py_DECREF(__pyx_v_ret);
Py_DECREF(__pyx_v_self);
Py_DECREF(__pyx_v_input);
Py_DECREF(__pyx_v_raw);
return __pyx_r;
}
static PyObject *__pyx_tp_new_5speex_new(struct _typeobject *t, PyObject *a, PyObject *k) {
PyObject *o = (*t->tp_alloc)(t, 0);
struct __pyx_obj_5speex_new *p = (struct __pyx_obj_5speex_new *)o;
p->debug = Py_None; Py_INCREF(p->debug);
p->endianness = Py_None; Py_INCREF(p->endianness);
return o;
}
static void __pyx_tp_dealloc_5speex_new(PyObject *o) {
struct __pyx_obj_5speex_new *p = (struct __pyx_obj_5speex_new *)o;
{
PyObject *etype, *eval, *etb;
PyErr_Fetch(&etype, &eval, &etb);
++o->ob_refcnt;
__pyx_f_5speex_3new___dealloc__(o);
if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
--o->ob_refcnt;
PyErr_Restore(etype, eval, etb);
}
Py_XDECREF(p->debug);
Py_XDECREF(p->endianness);
(*o->ob_type->tp_free)(o);
}
static int __pyx_tp_traverse_5speex_new(PyObject *o, visitproc v, void *a) {
int e;
struct __pyx_obj_5speex_new *p = (struct __pyx_obj_5speex_new *)o;
e = (*v)(p->debug, a); if (e) return e;
e = (*v)(p->endianness, a); if (e) return e;
return 0;
}
static int __pyx_tp_clear_5speex_new(PyObject *o) {
struct __pyx_obj_5speex_new *p = (struct __pyx_obj_5speex_new *)o;
Py_XDECREF(p->debug);
p->debug = Py_None; Py_INCREF(p->debug);
Py_XDECREF(p->endianness);
p->endianness = Py_None; Py_INCREF(p->endianness);
return 0;
}
static struct PyMethodDef __pyx_methods_5speex_new[] = {
{"encode", (PyCFunction)__pyx_f_5speex_3new_encode, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5speex_3new_encode},
{"decode", (PyCFunction)__pyx_f_5speex_3new_decode, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5speex_3new_decode},
{0, 0, 0, 0}
};
static struct PyMemberDef __pyx_members_5speex_new[] = {
{"debug", T_OBJECT, offsetof(struct __pyx_obj_5speex_new, debug), 0, 0},
{"endianness", T_OBJECT, offsetof(struct __pyx_obj_5speex_new, endianness), 0, 0},
{0, 0, 0, 0, 0}
};
static PyNumberMethods __pyx_tp_as_number_new = {
0, /*nb_add*/
0, /*nb_subtract*/
0, /*nb_multiply*/
0, /*nb_divide*/
0, /*nb_remainder*/
0, /*nb_divmod*/
0, /*nb_power*/
0, /*nb_negative*/
0, /*nb_positive*/
0, /*nb_absolute*/
0, /*nb_nonzero*/
0, /*nb_invert*/
0, /*nb_lshift*/
0, /*nb_rshift*/
0, /*nb_and*/
0, /*nb_xor*/
0, /*nb_or*/
0, /*nb_coerce*/
0, /*nb_int*/
0, /*nb_long*/
0, /*nb_float*/
0, /*nb_oct*/
0, /*nb_hex*/
0, /*nb_inplace_add*/
0, /*nb_inplace_subtract*/
0, /*nb_inplace_multiply*/
0, /*nb_inplace_divide*/
0, /*nb_inplace_remainder*/
0, /*nb_inplace_power*/
0, /*nb_inplace_lshift*/
0, /*nb_inplace_rshift*/
0, /*nb_inplace_and*/
0, /*nb_inplace_xor*/
0, /*nb_inplace_or*/
0, /*nb_floor_divide*/
0, /*nb_true_divide*/
0, /*nb_inplace_floor_divide*/
0, /*nb_inplace_true_divide*/
};
static PySequenceMethods __pyx_tp_as_sequence_new = {
0, /*sq_length*/
0, /*sq_concat*/
0, /*sq_repeat*/
0, /*sq_item*/
0, /*sq_slice*/
0, /*sq_ass_item*/
0, /*sq_ass_slice*/
0, /*sq_contains*/
0, /*sq_inplace_concat*/
0, /*sq_inplace_repeat*/
};
static PyMappingMethods __pyx_tp_as_mapping_new = {
0, /*mp_length*/
0, /*mp_subscript*/
0, /*mp_ass_subscript*/
};
static PyBufferProcs __pyx_tp_as_buffer_new = {
0, /*bf_getreadbuffer*/
0, /*bf_getwritebuffer*/
0, /*bf_getsegcount*/
0, /*bf_getcharbuffer*/
};
statichere PyTypeObject __pyx_type_5speex_new = {
PyObject_HEAD_INIT(0)
0, /*ob_size*/
"speex.new", /*tp_name*/
sizeof(struct __pyx_obj_5speex_new), /*tp_basicsize*/
0, /*tp_itemsize*/
__pyx_tp_dealloc_5speex_new, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
&__pyx_tp_as_number_new, /*tp_as_number*/
&__pyx_tp_as_sequence_new, /*tp_as_sequence*/
&__pyx_tp_as_mapping_new, /*tp_as_mapping*/
0, /*tp_hash*/
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
&__pyx_tp_as_buffer_new, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
0, /*tp_doc*/
__pyx_tp_traverse_5speex_new, /*tp_traverse*/
__pyx_tp_clear_5speex_new, /*tp_clear*/
0, /*tp_richcompare*/
0, /*tp_weaklistoffset*/
0, /*tp_iter*/
0, /*tp_iternext*/
__pyx_methods_5speex_new, /*tp_methods*/
__pyx_members_5speex_new, /*tp_members*/
0, /*tp_getset*/
0, /*tp_base*/
0, /*tp_dict*/
0, /*tp_descr_get*/
0, /*tp_descr_set*/
0, /*tp_dictoffset*/
__pyx_f_5speex_3new___init__, /*tp_init*/
0, /*tp_alloc*/
__pyx_tp_new_5speex_new, /*tp_new*/
0, /*tp_free*/
0, /*tp_is_gc*/
0, /*tp_bases*/
0, /*tp_mro*/
0, /*tp_cache*/
0, /*tp_subclasses*/
0, /*tp_weaklist*/
};
static struct PyMethodDef __pyx_methods[] = {
{0, 0, 0, 0}
};
DL_EXPORT(void) initspeex(void); /*proto*/
DL_EXPORT(void) initspeex(void) {
PyObject *__pyx_1 = 0;
PyObject *__pyx_2 = 0;
__pyx_m = Py_InitModule4("speex", __pyx_methods, __pyx_mdoc, 0, PYTHON_API_VERSION);
__pyx_b = PyImport_AddModule("__builtin__");
PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b);
if (PyType_Ready(&__pyx_type_5speex_new) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; goto __pyx_L1;}
if (PyObject_SetAttrString(__pyx_m, "new", (PyObject *)&__pyx_type_5speex_new) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; goto __pyx_L1;}
__pyx_ptype_5speex_new = &__pyx_type_5speex_new;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":12 */
__pyx_1 = PyString_FromString(__pyx_k1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; goto __pyx_L1;}
if (PyObject_SetAttrString(__pyx_m, "version", __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; goto __pyx_L1;}
Py_DECREF(__pyx_1); __pyx_1 = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":14 */
/*try:*/ {
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":15 */
__pyx_1 = __Pyx_GetName(__pyx_m, "True"); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; goto __pyx_L18;}
if (PyObject_SetAttrString(__pyx_m, "x", __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; goto __pyx_L18;}
Py_DECREF(__pyx_1); __pyx_1 = 0;
}
goto __pyx_L19;
__pyx_L18:;
Py_XDECREF(__pyx_1); __pyx_1 = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":16 */
/*except:*/ {
__Pyx_AddTraceback("speex");
__pyx_1 = __Pyx_GetExcValue(); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;}
Py_DECREF(__pyx_1); __pyx_1 = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":17 */
__pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;}
if (PyObject_SetAttrString(__pyx_m, "True", __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;}
Py_DECREF(__pyx_1); __pyx_1 = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":18 */
__pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;}
if (PyObject_SetAttrString(__pyx_m, "False", __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;}
Py_DECREF(__pyx_1); __pyx_1 = 0;
goto __pyx_L19;
}
__pyx_L19:;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":132 */
__pyx_1 = PyInt_FromLong(8); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; goto __pyx_L1;}
__pyx_k2 = __pyx_1;
__pyx_1 = 0;
__pyx_2 = PyInt_FromLong(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; goto __pyx_L1;}
__pyx_k3 = __pyx_2;
__pyx_2 = 0;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":227 */
Py_INCREF(Py_None);
__pyx_k4 = Py_None;
/* "/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx":399 */
Py_INCREF(Py_None);
__pyx_k5 = Py_None;
return;
__pyx_L1:;
Py_XDECREF(__pyx_1);
Py_XDECREF(__pyx_2);
__Pyx_AddTraceback("speex");
}
static char *__pyx_filenames[] = {
"/main/pywindows/speex/speex-1.0rc3/pySpeex/speex.pyx",
};
statichere char **__pyx_f = __pyx_filenames;
/* Runtime support code */
static int __Pyx_GetStarArgs(
PyObject **args,
PyObject **kwds,
char *kwd_list[],
int nargs,
PyObject **args2,
PyObject **kwds2)
{
PyObject *x = 0, *args1 = 0, *kwds1 = 0;
if (args2)
*args2 = 0;
if (kwds2)
*kwds2 = 0;
if (args2) {
args1 = PyTuple_GetSlice(*args, 0, nargs);
if (!args1)
goto bad;
*args2 = PyTuple_GetSlice(*args, nargs, PyTuple_Size(*args));
if (!*args2)
goto bad;
}
else {
args1 = *args;
Py_INCREF(args1);
}
if (kwds2) {
if (*kwds) {
char **p;
kwds1 = PyDict_New();
if (!kwds)
goto bad;
*kwds2 = PyDict_Copy(*kwds);
if (!*kwds2)
goto bad;
for (p = kwd_list; *p; p++) {
x = PyDict_GetItemString(*kwds, *p);
if (x) {
if (PyDict_SetItemString(kwds1, *p, x) < 0)
goto bad;
if (PyDict_DelItemString(*kwds2, *p) < 0)
goto bad;
}
}
}
else {
*kwds2 = PyDict_New();
if (!*kwds2)
goto bad;
}
}
else {
kwds1 = *kwds;
Py_XINCREF(kwds1);
}
*args = args1;
*kwds = kwds1;
return 0;
bad:
Py_XDECREF(args1);
Py_XDECREF(kwds1);
if (*args2)
Py_XDECREF(*args2);
if (*kwds2)
Py_XDECREF(*kwds2);
return -1;
}
static PyObject *__Pyx_GetName(PyObject *dict, char *name) {
PyObject *result;
result = PyObject_GetAttrString(dict, name);
if (!result)
PyErr_SetString(PyExc_NameError, name);
return result;
}
static PyObject *__Pyx_GetExcValue(void) {
PyObject *type = 0, *value = 0, *tb = 0;
PyObject *result = 0;
PyThreadState *tstate = PyThreadState_Get();
PyErr_Fetch(&type, &value, &tb);
PyErr_NormalizeException(&type, &value, &tb);
if (PyErr_Occurred())
goto bad;
if (!value) {
value = Py_None;
Py_INCREF(value);
}
Py_XDECREF(tstate->exc_type);
Py_XDECREF(tstate->exc_value);
Py_XDECREF(tstate->exc_traceback);
tstate->exc_type = type;
tstate->exc_value = value;
tstate->exc_traceback = tb;
result = value;
Py_XINCREF(result);
type = 0;
value = 0;
tb = 0;
bad:
Py_XDECREF(type);
Py_XDECREF(value);
Py_XDECREF(tb);
return result;
}
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
Py_XINCREF(type);
Py_XINCREF(value);
Py_XINCREF(tb);
/* First, check the traceback argument, replacing None with NULL. */
if (tb == Py_None) {
Py_DECREF(tb);
tb = 0;
}
else if (tb != NULL && !PyTraceBack_Check(tb)) {
PyErr_SetString(PyExc_TypeError,
"raise: arg 3 must be a traceback or None");
goto raise_error;
}
/* Next, replace a missing value with None */
if (value == NULL) {
value = Py_None;
Py_INCREF(value);
}
/* Next, repeatedly, replace a tuple exception with its first item */
while (PyTuple_Check(type) && PyTuple_Size(type) > 0) {
PyObject *tmp = type;
type = PyTuple_GET_ITEM(type, 0);
Py_INCREF(type);
Py_DECREF(tmp);
}
if (PyString_Check(type))
;
else if (PyClass_Check(type))
; /*PyErr_NormalizeException(&type, &value, &tb);*/
else if (PyInstance_Check(type)) {
/* Raising an instance. The value should be a dummy. */
if (value != Py_None) {
PyErr_SetString(PyExc_TypeError,
"instance exception may not have a separate value");
goto raise_error;
}
else {
/* Normalize to raise , */
Py_DECREF(value);
value = type;
type = (PyObject*) ((PyInstanceObject*)type)->in_class;
Py_INCREF(type);
}
}
else {
/* Not something you can raise. You get an exception
anyway, just not what you specified :-) */
PyErr_Format(PyExc_TypeError,
"exceptions must be strings, classes, or "
"instances, not %s", type->ob_type->tp_name);
goto raise_error;
}
PyErr_Restore(type, value, tb);
return;
raise_error:
Py_XDECREF(value);
Py_XDECREF(type);
Py_XDECREF(tb);
return;
}
#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
static void __Pyx_AddTraceback(char *funcname) {
PyObject *py_srcfile = 0;
PyObject *py_funcname = 0;
PyObject *py_globals = 0;
PyObject *empty_tuple = 0;
PyObject *empty_string = 0;
PyCodeObject *py_code = 0;
PyFrameObject *py_frame = 0;
py_srcfile = PyString_FromString(__pyx_filename);
if (!py_srcfile) goto bad;
py_funcname = PyString_FromString(funcname);
if (!py_funcname) goto bad;
py_globals = PyModule_GetDict(__pyx_m);
if (!py_globals) goto bad;
empty_tuple = PyTuple_New(0);
if (!empty_tuple) goto bad;
empty_string = PyString_FromString("");
if (!empty_string) goto bad;
py_code = PyCode_New(
0, /*int argcount,*/
0, /*int nlocals,*/
0, /*int stacksize,*/
0, /*int flags,*/
empty_string, /*PyObject *code,*/
empty_tuple, /*PyObject *consts,*/
empty_tuple, /*PyObject *names,*/
empty_tuple, /*PyObject *varnames,*/
empty_tuple, /*PyObject *freevars,*/
empty_tuple, /*PyObject *cellvars,*/
py_srcfile, /*PyObject *filename,*/
py_funcname, /*PyObject *name,*/
__pyx_lineno, /*int firstlineno,*/
empty_string /*PyObject *lnotab*/
);
if (!py_code) goto bad;
py_frame = PyFrame_New(
PyThreadState_Get(), /*PyThreadState *tstate,*/
py_code, /*PyCodeObject *code,*/
py_globals, /*PyObject *globals,*/
0 /*PyObject *locals*/
);
if (!py_frame) goto bad;
py_frame->f_lineno = __pyx_lineno;
PyTraceBack_Here(py_frame);
bad:
Py_XDECREF(py_srcfile);
Py_XDECREF(py_funcname);
Py_XDECREF(empty_tuple);
Py_XDECREF(empty_string);
Py_XDECREF(py_code);
Py_XDECREF(py_frame);
}
pyspeex-0.2/setup.py 0000644 0001750 0001750 00000002156 07760301404 014527 0 ustar thom thom 0000000 0000000 #@+leo-ver=4
#@+node:@file setup.py
import sys
from distutils.core import setup, Extension
from Pyrex.Distutils import build_ext
incDirs = ['../libspeex']
libs = []
libDirs = []
runtimeLibDirs = []
cMacros = []
#extraLinkArgs = ['-g', '/usr/lib/libspeex.a'] # static
extraLinkArgs = ['-g', '-lspeex'] # shared
if sys.platform == 'win32':
libDirs.append('..\\win32\\Release')
libs = []
extraLinkArgs = ['..\\win32\\libspeex\\Release\\libspeex.lib']
speexmodule = Extension('speex',
['speex.pyx'],
define_macros=cMacros,
include_dirs=incDirs,
libraries=libs,
library_dirs=libDirs,
runtime_library_dirs=runtimeLibDirs,
extra_compile_args=['-g'],
extra_link_args=extraLinkArgs
)
setup(name = 'speex',
version = '1.0',
description = 'Python interface to the Speex audio codec',
ext_modules = [speexmodule],
cmdclass = {'build_ext': build_ext},
)
#@-node:@file setup.py
#@-leo
pyspeex-0.2/code.leo 0000644 0001750 0001750 00000045124 07760313475 014445 0 ustar thom thom 0000000 0000000
NewHeadline
@file setup.py
@file speex.pyx
cdef externs
string.h
stdio.h
stdlib.h
math.h
Python.h
speex.h
cdef class new
c attribs
__init__
__dealloc__
encode
decode
import sys
from distutils.core import setup, Extension
from Pyrex.Distutils import build_ext
incDirs = ['../libspeex']
libs = []
libDirs = []
runtimeLibDirs = []
cMacros = []
#extraLinkArgs = ['-g', '/usr/lib/libspeex.a'] # static
extraLinkArgs = ['-g', '-lspeex'] # shared
if sys.platform == 'win32':
libDirs.append('..\\win32\\Release')
libs = []
extraLinkArgs = ['..\\win32\\libspeex\\Release\\libspeex.lib']
speexmodule = Extension('speex',
['speex.pyx'],
define_macros=cMacros,
include_dirs=incDirs,
libraries=libs,
library_dirs=libDirs,
runtime_library_dirs=runtimeLibDirs,
extra_compile_args=['-g'],
extra_link_args=extraLinkArgs
)
setup(name = 'speex',
version = '1.0',
description = 'Python interface to the Speex audio codec',
ext_modules = [speexmodule],
cmdclass = {'build_ext': build_ext},
)
@language python
"""
speex.pyx
Python wrapper for Speex speech codec (www.speex.org)
Defines a 'speex' object through which encoding and
decoding of audio data can be performed.
"""
version = "0.2"
try:
x = True
except:
True = 1
False = 0
@others
# basic system and python facilities
@others
cdef extern from "string.h":
cdef void *memset(void *s, int c, int n)
cdef void *memcpy(void *dest, void *src, int n)
cdef extern from "stdio.h":
int printf(char *format,...)
cdef extern from "stdlib.h":
void *malloc(int size)
void *realloc(void *ptr, int size)
void free(void *ptr)
cdef extern from "math.h":
double fabs(double x)
# Python-specifics
cdef extern from "Python.h":
object PyString_FromStringAndSize(char *, int)
# Speex-specifics
cdef extern from "speex.h":
ctypedef struct SpeexBits:
char *bytes # "raw" data
int nbBits # Total number of bits stored in the stream
int bytePtr # Position of the byte "cursor"
int bitPtr # Position of the bit "cursor" within the current byte
int owner # Does the struct "own" the "raw" buffer (member "bytes")
int overflow # Set to one if we try to read past the valid data
int buf_size # Allocated size for buffer
ctypedef struct SpeexMode:
void *mode
cdef enum SPEEX_SYMBOLS:
SPEEX_SET_QUALITY
SPEEX_GET_FRAME_SIZE
SPEEX_SET_ENH
SPEEX_GET_ENH
cdef SpeexMode speex_nb_mode
cdef void speex_bits_init(SpeexBits *bits)
cdef void speex_bits_read_from(SpeexBits *bits, char *bytes, int len)
cdef int speex_bits_write(SpeexBits *bits, char *bytes, int max_len)
cdef void speex_bits_reset(SpeexBits *bits)
cdef void speex_bits_destroy(SpeexBits *bits)
cdef void *speex_encoder_init(SpeexMode *mode)
cdef int speex_encoder_ctl(void *state,
int request,
void *ptr)
cdef int speex_encode(void *state, float *inbuf, SpeexBits *bits)
cdef void speex_encoder_destroy(void *state)
cdef void *speex_decoder_init(SpeexMode *mode)
int speex_decoder_ctl(void *state, int request, void *ptr)
cdef int speex_decode(void *state,
SpeexBits *bits,
float *out)
cdef void speex_decoder_destroy(void *state)
cdef class new:
@others
cdef void *encState
cdef int encQuality
cdef int encFramesPerBlock
cdef float *encBuf
cdef float *encPtr
cdef int encNumFrames
cdef SpeexBits encBits
cdef int raw
# Data for decoding
cdef void *decState
cdef int decQuality
cdef unsigned char *decBuf
cdef unsigned char *decPtr
cdef unsigned short decBlkSize
cdef int decNumBytes
cdef int decPhase
cdef int decEnhanceOn
cdef SpeexBits decBits
cdef public object debug
cdef public object endianness
def __init__(self, quality=8, raw=0, **kw):
"""
Create a new speex speech stream object
Arguments:
- quality - 0 (lowest) to 10 (highest), default 8
- raw - set to 1 for encoding from and decoding to string, default 0
Keywords:
- debug - set to 1 to issue debug messages, default 0
The created speex stream object has two methods:
- encode - encode a block of speech audio data
Arguments:
- block of audio data, as sequence of frames, where
each frame is an int
Returns:
- raw string containing encoded data, or
empty string if there is not yet any encoded
data available
- decode - decodes a block of speech audio data
Arguments:
- block of encoded data, as raw string,
Returns:
- block of audio data, as sequence of ints, or
an empty sequence if there is no decoded data
available yet
Notes:
- Both of these methods use internal buffering, which means that
you can feed in data piecemeal. This helps a lot when sending and
receiving data over the net.
"""
cdef int is_raw
#cdef SpeexMode speex_nb_mode
# Set up encoder
self.encState = speex_encoder_init(&speex_nb_mode)
self.encQuality = quality
is_raw = raw
self.raw = is_raw
self.debug = int(kw.get('debug', 0))
speex_encoder_ctl(self.encState, SPEEX_SET_QUALITY, &self.encQuality)
#printf("speex1: using new pyrex wrapper, quality=%d\n", self.encQuality)
speex_encoder_ctl(self.encState, SPEEX_GET_FRAME_SIZE, &self.encFramesPerBlock)
#printf("encoder frame size=%d\n", self.encFramesPerBlock)
self.encBuf = <float *>malloc(self.encFramesPerBlock * sizeof(float))
if not self.encBuf:
raise Exception("Out of memory")
memset(self.encBuf, 0, self.encFramesPerBlock * sizeof(float))
self.encNumFrames = 0
self.encPtr = self.encBuf
speex_bits_init(&self.encBits)
# Set up decoder
self.decState = speex_decoder_init(&speex_nb_mode)
self.decEnhanceOn = 1
speex_decoder_ctl(self.decState, SPEEX_SET_ENH, &self.decEnhanceOn)
self.decBuf = <unsigned char *>malloc(2) # just big enough for leading length field
self.decPhase = 0
if not self.decBuf:
raise Exception("Out of memory")
self.decPtr = self.decBuf
self.decNumBytes = 0
speex_bits_init(&self.decBits)
def __dealloc__(self):
# Destroy the encoder state and data
speex_encoder_destroy(self.encState)
if self.encBuf:
free(self.encBuf)
# Destroy the decoder state
speex_decoder_destroy(self.decState)
if self.decBuf:
free(self.decBuf)
# Destroy the bit-packing structs
speex_bits_destroy(&self.encBits)
speex_bits_destroy(&self.decBits)
def encode(self, input, raw=None):
"""
Encode some audio data
Arguments:
- data - sequence of audio frames to encode, OR string of 16-bit frames
- raw - true if data being passed in is a string of 16-bit frames
defaults to whatever raw arg was passed to constructor
Returns:
- raw string with encoded data
"""
cdef int numInputFrames
cdef float *framesBuf, *framesPtr
# cdef float thisframe
cdef int i
cdef int totFrames
# cdef SpeexBits bits;
cdef int cbitsSiz
# cdef int cbitsSiz = 2048
# cdef char cbits[cbitsSiz]
cdef char cbits[2048]
cdef int nBlocks
cdef int nBytes
cdef char *bufOut
cdef int bufOutSiz
cdef int remainder
cdef char *rawbuf
cdef short *frameptr
cbitsSiz = self.encFramesPerBlock * 5 / 4
bufOut = <char *>malloc(0)
bufOutSiz = 0
inputFramesList = []
#printf("encode: ok1\n")
# override raw flag if user has passed in a string
if raw is None:
raw = self.raw
if type(input) is type(""):
raw = 1
# Determine number of frames
if raw:
numInputFrames = len(input) / 2 # hardwired 16-bit frames
else:
numInputFrames = len(input)
#printf("encode: ok2\n")
# printf("enc - numInputFrames = %d\n", numInputFrames)
if numInputFrames == 0:
return ''
#printf("encode: ok3\n")
# Encode what we have, block by block
totFrames = numInputFrames + self.encNumFrames
#printf("totFrames=%d, input data size=%d\n",
# totFrames, totFrames * sizeof(short))
framesBuf = <float *>malloc(totFrames * sizeof(float))
framesPtr = framesBuf
if not framesBuf:
raise Exception("Out of memory")
#printf("encode: ok4\n")
# Copy in the fragments we have in buffer
# printf("copying in buf of %d frames\n", self.encNumFrames)
for i from 0 <= i < self.encNumFrames:
framesPtr[i] = self.encBuf[i]
#printf("encode: ok4a = i=%d, self.encNumFrames=%d\n",
# i, self.encNumFrames)
framesPtr = framesPtr + i
#printf("encode: ok5\n")
# Extract the rest from input sequence, depending on whether input is str or list
# printf("copying extra %d frames from input\n", numInputFrames);
if raw:
rawbuf = input
frameptr = <short *>rawbuf
for i from 0 <= i < numInputFrames:
# assume little-endian - sorry, mac hackers
# frame = rawptr[0] + 256 * rawptr[1]
# rawptr += 2
# *framesPtr++ = (float)frame
framesPtr[i] = frameptr[i]
framesPtr = framesPtr + i
frameptr = frameptr + i
# thisframe = *frameptr++
# if (i < 10)
# {
# printf("encode: thisframe=%f\n", thisframe)
# }
# *framesPtr++ = thisframe
else:
for i from 0 <= i < numInputFrames:
framesPtr[i] = input[i]
framesPtr = framesPtr + i
# thisframe = PyInt_AsLong(PyList_GetItem(input, i))
# if (i < 10)
# {
# printf("encode: thisframe=%f\n", thisframe)
# }
# *framesPtr++ = thisframe
#printf("written %d frames to buf\n", framesPtr - framesBuf)
#printf("encode: ok6\n")
# Encode these frames
nBlocks = totFrames / self.encFramesPerBlock
framesPtr = framesBuf
for i from 0 <= i < nBlocks:
# printf("seeking to encode a block, nBlocks=%d\n", nBlocks)
speex_bits_reset(&self.encBits)
# printf("ok1 - state=0x%lx, buf=0x%lx, bits=0x%lx\n",
# self.encState, framesBuf, &self.encBits)
speex_encode(self.encState, framesPtr, &self.encBits)
# printf("ok2\n")
nBytes = speex_bits_write(&self.encBits, cbits, cbitsSiz)
#printf("nBytes=%d\n", nBytes)
bufOut = <char *>realloc(bufOut, bufOutSiz+nBytes+2)
# printf("ok4\n")
# write out 2 length bytes
bufOut[bufOutSiz] = nBytes % 256
bufOut[bufOutSiz+1] = nBytes / 256
bufOutSiz = bufOutSiz + 2
memcpy(bufOut+bufOutSiz, cbits, nBytes)
# printf("ok5\n")
bufOutSiz = bufOutSiz + nBytes
# printf("ok6\n")
framesPtr = framesPtr + self.encFramesPerBlock
#printf("encode: ok7\n")
# stick remainder, if any, into buffer
self.encNumFrames = totFrames - (nBlocks * self.encFramesPerBlock)
remainder = self.encNumFrames * sizeof(float)
memcpy(self.encBuf, framesPtr, remainder)
# memset(self.encBuf, 0, self.encFramesPerBlock * sizeof(float))
# printf("encNumFrames=%d\n", self.encNumFrames)
# printf("remainder=%d\n", remainder)
#printf("encode: ok8\n")
# ditch temp buffer
free(framesBuf)
#printf("encode: ok9\n")
# pass back encoded buffer as raw string
#printf("bufOutSize=%d\n", bufOutSiz)
return PyString_FromStringAndSize(bufOut, bufOutSiz)
def decode(self, input, raw=None):
"""
Decode an encoded block, return as sequence of frame tuples
Arguments:
- encoded - raw string, containing encoded data
- raw - True if data is to be returned as string of 16-bit frames, defaults to
whatever raw value was passed to constructor
Returns:
- decoded blocks, as sequence of frames, where each frame
or a string of these 16-bit frames if raw is True
is an int
"""
cdef unsigned char *encBuf
cdef unsigned char *encBufEnd
cdef unsigned char *encPtr
cdef int encBufLen
cdef int numDecFrames # number of decoded frames
# cdef int cbitsSiz
# cdef char cbits[cbitsSiz]
cdef float *decFloats
cdef float *decFloats1
cdef short *decShorts
cdef short *decShorts1
cdef int decBlocks
cdef int i
cdef int is_raw
cdef int needed
cdef int newNumFrames
cdef char *tmp
#printf("decode: ok1\n")
tmp = input
encBuf = <unsigned char *>tmp
encBufEnd = NULL
encPtr = NULL
encBufLen = 0
decFloats = <float *>malloc(0)
decShorts = <short *>malloc(0)
decBlocks = 0
if raw is None:
raw = self.raw
is_raw = raw
#printf("decode: ok2, raw=%d\n", is_raw)
# We get an earlymark if caller provided no data
encBufLen = len(input)
if encBufLen == 0:
if is_raw:
return ''
else:
return []
#printf("decode: ok3\n")
# decode the sucker
encPtr = encBuf
encBufEnd = encBuf + encBufLen
#printf("decode: ok4, len=%d\n", encBufLen)
while encPtr < encBufEnd:
# state depends on whether we've received the block header count bytes
if self.decPhase == 0:
# Grab LSB of block size
self.decBuf[0] = encPtr[0]
#printf("decode: ok4a - LSB=%02x\n", encPtr[0])
self.decPhase = 1
encPtr = encPtr + 1
encBufLen = encBufLen - 1
continue
elif self.decPhase == 1:
# Grab MSB of block size and determine total block size
self.decBuf[1] = encPtr[0]
#printf("decode: ok4b - LSB=%02x\n", encPtr[0])
self.decBlkSize = self.decBuf[0] + 256 * self.decBuf[1]
# resize dec buffer to suit
# todo - find better way to sanity check the size
self.decBuf = <unsigned char *>realloc(
<void *>self.decBuf,
self.decBlkSize)
self.decPtr = self.decBuf
self.decNumBytes = 0
self.decPhase = 2
encPtr = encPtr + 1
encBufLen = encBufLen - 1
continue
else:
#printf("decode: ok4c siz=%d decnumbytes=%d\n",
# self.decBlkSize, self.decNumBytes)
needed = self.decBlkSize - self.decNumBytes
#printf("decode: ok4d encBufLen=%d needed=%d\n",
# encBufLen, needed)
# do we have enough input data to complete a frame?
if encBufLen >= needed:
newNumFrames = (decBlocks + 1) * self.encFramesPerBlock
# great - decode frame and add to our array of shorts
memcpy(self.decPtr,
encPtr,
self.decBlkSize - self.decNumBytes)
encPtr = encPtr + needed
encBufLen = encBufLen - needed
# do the decoding
# expand shorts and floats buffers
decShorts = <short *>realloc(decShorts, newNumFrames * sizeof(short))
decShorts1 = decShorts + decBlocks * self.encFramesPerBlock
decFloats = <float *>realloc(decFloats, newNumFrames * sizeof(float))
decFloats1 = decFloats + decBlocks * self.encFramesPerBlock
# Copy the data into the bit-stream struct
speex_bits_read_from(&self.decBits, <char *>self.decPtr, self.decBlkSize)
# Decode the data
speex_decode(self.decState, &self.decBits, decFloats1)
# Copy from float to short (16 bits) for output
for i from 0 <= i < self.encFramesPerBlock:
decShorts1[i] = decFloats1[i]
self.decPhase = 0 # back to awaiting LSB of count header
self.decNumBytes = 0
if self.debug:
printf("self.decBuf=%lx\n", self.decBuf)
self.decBuf = <unsigned char *>realloc(self.decBuf, 2)
decBlocks = decBlocks + 1
continue
else:
#printf("decode: ok4e\n")
# not enough to decode another speex frame - just stick into buffer
if self.debug:
printf("decPtr=%lx, encPtr=%lx, encBufLen=%d\n",
self.decPtr, encPtr, encBufLen)
memcpy(self.decPtr, encPtr, encBufLen)
self.decPtr = self.decPtr + encBufLen
encBufLen = 0
break
#printf("decode: ok5\n")
# did we get anything?
if decBlocks > 0:
numDecFrames = decBlocks * self.encFramesPerBlock
if is_raw:
ret = PyString_FromStringAndSize(<char *>decShorts, numDecFrames * 2)
else:
# build up a sequence of tuples
ret = []
for i in range(numDecFrames):
ret.append(decShorts[i])
else:
if is_raw:
ret = ""
else:
ret = []
#printf("decode: ok6\n")
free(decShorts)
free(decFloats)
return ret
# return Py_BuildValue("s#", decBuf, decBufLen)
pyspeex-0.2/Makefile 0000644 0001750 0001750 00000000107 07760303522 014452 0 ustar thom thom 0000000 0000000 install: clean
python setup.py install
clean:
rm -rf build pyrex.c