python - Converting 16 bit audio sample to char -


i using matrix creator board , trying make python wrapper mic array c++ code.

the library has read function returns uint16_t array of 128 samples.

i'm trying compare alsa readi function writes buffer char array user passes argument function.

the question how alsa write 16-bit samples char array when single char 8 bit wide? , how same uint16_t array , pass python i'll same result alsa readi function?

a uint16 can passed 2 bytes (uint8), c++ code uses union data can saved uint16 while usb code can pass data bytes.

as python code, function use convert 8-bit bytes uint16

def convert_int8_int16(self, byte_array):     new_array = [0]*(len(byte_array)/2)     in range(len(byte_array)/2):         new_array[i] = byte_array.pop(0)*256 + byte_array.pop(0)      return new_array 

this go through byte array , add values new uint16 array.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -