fs, "channels=", channels, ) numblocks = pickle.load(codedfile) numblocks -= 4 #last encoded samples might be missing from rounding to bytes print("numblocks=", numblocks) for chan in range(channels): #loop over channels: print("channel ", chan) ricecoeffcomp = pickle.load(codedfile) ricecoeff = struct.unpack('B' * len(ricecoeffcomp), ricecoeffcomp) #print("ricecoeff=", ricecoeff) ychandec = np.zeros((N, numblocks)) for k in range(N): #loop across subbands: if (k % 100 == 0): print("Subband:", k) ys = pickle.load(codedfile) #Rice coded subband samples #m=2**b signedrice = rice(b=ricecoeff[k], signed=True) yricedec = BitStream() yricedec.write(ys) ychandec[k, :] = yricedec.read(signedrice, numblocks) if chan == 0: y0 = ychandec if chan == 1: y1 = ychandec print("Inverse IntMDCT:") xrek = IntMDCTsynfb(y0, y1, fb) xrek = np.clip(xrek, -2**15, 2**15 - 1) print("Write decoded signal to wav file ", decfile) wav.write(decfile, fs, np.int16(xrek))
#Demo of a rice endoder #Gerald Schuller, Aug. 2018 #for installation: sudo pip install audio.coders from audio.coders import rice from bitstream import BitStream import numpy as np origs = np.arange(-2, 6) print("Original= ", origs) #b: exponent of 2 ricecode = rice(b=1, signed=True) riceencoded = BitStream(origs.astype(np.int32), ricecode) print("rice encoded=", riceencoded) for index in origs: print("Index: ", index, "Rice code: ", BitStream(index, ricecode)) ricedecoded = riceencoded.read(ricecode, 8) print("rice decoded=", ricedecoded)