from numpy import *
from pylab import *
%matplotlib inline
from bitstream import BitStream
from audio.coders import rice
import audio.wave as wave
import audio.io
BitStream(42, uint16)
frame = [0,0,1,1,7,255,301,16,78, 100, 0,0,0, 6]
r = rice.from_frame(frame, signed=False)
print r.b
BitStream(0,r)
BitStream(1,r)
BitStream(255, r)
BitStream(frame, r)
BitStream(1,rice(b=5,signed=True))
for b in range(0,9):
print b, len(BitStream(frame, rice(signed=False, b=b)))
df = 44100.0; dt = 1.0 / df
f = 440.0
#t = r_[0:0.1:dt] # 0.1 sec of data
#data = sin(2*pi*f*t)
data = audio.io.record(1.0, df=df)[0]
plot(data)
data2 = wave.read(wave.write(data))
data3 = wave.read(wave.write(data), scale=False)
print data3.dtype
data = data3[0]
print len(data)
r = rice.from_frame(data, signed=True) # near 15 ?
print r.b
stream = BitStream(data, r)
print len(data) * 16
print len(stream)
close()
hist(abs(data.astype(int32)))
# negative values of abs(data) ? WTF!!!
print abs(int16(-2**15)) # overflow: abs output is a int16!
df = 44100.0; dt = 1.0 / df
f = 440.0
t = r_[0:0.1:dt] # 0.1 sec of data
data = 0.1*sin(2*pi*f*t)
data = wave.read(wave.write(data), scale=False)[0]
print len(BitStream(data, rice.from_frame(data, signed=True)))
hist(abs(data))
df = 44100.0; dt = 1.0 / df
f = 440.0
t = r_[0:0.1:dt] # 0.1 sec of data
#data = sin(2*pi*f*t)
#data = wave.read(wave.write(data), scale=False)[0]
ddata = diff(data)
print len(data), len(ddata)
ddata = diff(r_[0,data]) # coding of the first value
print len(data), len(ddata)
hist(abs(ddata))
r = rice.from_frame(ddata, signed=True)
print r.b
print len(BitStream(ddata, r))
idata = cumsum(ddata)
all(data == idata)
dddata = diff(r_[0, diff(r_[0, data])])
r = rice.from_frame(dddata, signed=True)
print r.b
print len(BitStream(dddata, r))
iidata = cumsum(cumsum(dddata))
all(data == iidata)