aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2014-01-06 22:25:21 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2014-01-06 22:25:21 -0800
commit064d0782af002914e6fece13512a6215e96ffcf2 (patch)
treeb2c5c01088803c1ed071e33c1ff08027a1fe9c05 /lib_pypy/audioop.py
parentfix numpy int coerce cases (diff)
downloadpypy-064d0782af002914e6fece13512a6215e96ffcf2.tar.gz
pypy-064d0782af002914e6fece13512a6215e96ffcf2.tar.bz2
pypy-064d0782af002914e6fece13512a6215e96ffcf2.zip
Started on audioop module.
Diffstat (limited to 'lib_pypy/audioop.py')
-rw-r--r--lib_pypy/audioop.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib_pypy/audioop.py b/lib_pypy/audioop.py
new file mode 100644
index 0000000000..d30c8e1fae
--- /dev/null
+++ b/lib_pypy/audioop.py
@@ -0,0 +1,29 @@
+
+import struct
+
+
+class error(Exception):
+ pass
+
+
+def _check_size(size):
+ if size != 1 and size != 2 and size != 4:
+ raise error("Size should be 1, 2 or 4")
+
+
+def _check_params(length, size):
+ _check_size(size)
+ if length % size != 0:
+ raise error("not a whole number of frames")
+
+
+def getsample(cp, size, i):
+ _check_params(len(cp), size)
+ if not (0 <= i < len(cp) / size):
+ raise error("Index out of range")
+ if size == 1:
+ return struct.unpack_from("B", buffer(cp)[i:])[0]
+ elif size == 2:
+ return struct.unpack_from("H", buffer(cp)[i * 2:])[0]
+ elif size == 4:
+ return struct.unpack_from("I", buffer(cp)[i * 4:])[0]