AudioNet / node-core-audio

Bindings for PortAudio giving JavaScript access to sound card samples (mostly unmaintained)
MIT License
330 stars 67 forks source link

sampleFormat confusion #37

Open SAERobinReumers opened 9 years ago

SAERobinReumers commented 9 years ago

Hi, first of all thank you very much for this very useful module.

I have been reading the docs but I'm a bit confused. SampleFormat in the documentation says:

sampleFormat [default sampleFormatFloat32] Bit depth - Number of bits used to represent sample values formats are sampleFormatFloat32, sampleFormatInt32, sampleFormatInt24, sampleFormatInt16, sampleFormatInt8, sampleFormatUInt8.

However, when I try: engine.setOptions({ sampleFormat: "sampleFormatInt16", }); it doesn't change anything. I did see that I can change it between 1 and 2. 1 seems be the floating value and 2 seems to be integer based, however I don't know if it's 20bit or something similar? The highest value seems to go to 95.000.000 which is higher than 16-bit but a lot lower than 24-bit. Any input on this would be much appreciated.

madsci77 commented 6 years ago

I realize it's been a few years, but I'll chime in with what I've found for anyone else looking at this.

I'm new to Node and I'm not sure how those enumerations are supposed to work - I can't find them anywhere. But I did find the code where they're defined:

target->Set( Nan::New<String>("sampleFormatFloat32").ToLocalChecked(), Nan::New<Number>(1)); target->Set( Nan::New<String>("sampleFormatInt32").ToLocalChecked(), Nan::New<Number>(2) ); target->Set( Nan::New<String>("sampleFormatInt24").ToLocalChecked(), Nan::New<Number>(4) ); target->Set( Nan::New<String>("sampleFormatInt16").ToLocalChecked(), Nan::New<Number>(8) ); target->Set( Nan::New<String>("sampleFormatInt8").ToLocalChecked(), Nan::New<Number>(10) ); target->Set( Nan::New<String>("sampleFormatUInt8").ToLocalChecked(), Nan::New<Number>(20) );

That at least gives you the numbers to use - Int16 is 8, and it gives me the expected numeric range.