rochars / wavefile

Create, read and write wav files according to the specs. :star: :notes: :heart:
MIT License
226 stars 48 forks source link

waveFile.toBuffer as 16 bit array? #33

Closed marksyzm closed 1 year ago

marksyzm commented 1 year ago

I'm just working on something that generates peaks for wave files which I read the data from via base64, and to match what I have I'd prefer the buffer to output in 16 bit, possibly signed format?

Is there a way to do this with what

This would be my ideal:

const waveFile = new WaveFile();      
waveFile.fromDataURI(waveFileBase64);
const audioFileBuffer = waveFile.toBuffer('16');

Or can I just convert this to 16 bit?

Many thanks

kookster commented 1 year ago

Maybe use toBitDepth(16), then output using toBuffer?

marksyzm commented 1 year ago

But according to the code, toBuffer only outputs 8-bit?

marksyzm commented 1 year ago

Being able to set the buffer size would be ideal, especially to 8, 16, 24, or 32-bit.

kookster commented 1 year ago

Yeah toBuffer maybe not; try getSamples(false, Int16Array); ?

marksyzm commented 1 year ago

Aha! That sounds like it

marksyzm commented 1 year ago

Yes, how did I miss that?? Thank you!

marksyzm commented 1 year ago

Also, thank you so much for such amazing work on this. There was barely anything else out there that did all this and you saved me having to work out something from scratch for all this. Brilliant job, thank you!