Hello all,
So, I want to load my sound data directly from memory, and I'm using
load_from_array function for that. However, Libaudioverse expects float
data, while Python's wave module returns wave data as byte string. After
some searching, I found the way on stackoverflow to do proper conversion,
but unfortunately this solution doesn't work for 24-bit or higher wave
data.
So:
def load_sound_data(filename):
waveIO = BytesIO(data[filename])
w = wave.open(waveIO)
sr = w.getframerate()
channels = w.getnchannels()
frames = w.getnframes()
bitrate = w.getsampwidth() * 8
wdata = w.readframes(frames)
fdata = struct.unpack("%ih" % (w.getnframes() * w.getnchannels()), wdata)
fdata = [float(val) / pow(2, 15) for val in fdata]
return (sr, channels, frames, fdata)
And then I say:
sound = load_sound_data('splash.wav')
filenode = libaudioverse.BufferNode(server)
buffer = libaudioverse.Buffer(server)
buffer.load_from_array(sound[0], sound[1], sound[2], sound[3])
filenode.buffer = buffer
filenode.connect(0, filenode.server)
As I expected, it played 16-bit wave data properly, but failed at 24-bit
wave data. Do you have any suggestions on how I can implement better to-float
conversion.
The reason why I want wave data loaded directly into memory is because
I stored all the sounds inside an encrypted zip file, and
decryption/extraction is all done inside memory. This is to prevent
users from accessing sound data and modifying sound files. But as I said,
a proper conversion is required, because wave module has no way of
returning sound data as floats, as far as I know.
Thanks for any help,
Hrvoje
LP,
Hrvoje
Web:
www.hrvojekatic.com