grame-cncm / faust

Functional programming language for signal processing and sound synthesis
http://faust.grame.fr
Other
2.58k stars 322 forks source link

Oboe code assumes INPUT and OUTPUT rates match #382

Closed philburk closed 4 years ago

philburk commented 4 years ago

If I interpret this code correctly:

https://github.com/grame-cncm/faust/blob/master-dev/architecture/faust/audio/oboe-dsp.h

if the sample rate is not specified then it will use the default rate for INPUT and OUTPUT. Surprisingly, on Android, those may not be the same! When visiting China, I was surprised to learn that there are some devices that use 44100 for input and 48000 for output! You may want to open the output first and then request that same sample rate for input so they match.

sletz commented 4 years ago

Thanks for detecting the issue !

"and then request that same sample rate for input so they match" => does this mean the input will then do resampling ? Or is there a way to setup native sampling rate ?

philburk commented 4 years ago

Good question. If you request a sample rate that does not match the native sample rate then you will not get a low latency stream UNLESS you use the new Oboe resampler. This was added in Oboe 1.3.0.

https://google.github.io/oboe/reference/classoboe_1_1_audio_stream_builder.html#af7d24a9ec975d430732151e5ee0d1027

If the native rate matches then it will skip the resampler so no overhead.

sletz commented 4 years ago

I tried to swap the two blocks, so that opening the output stream is done first. Then opening the input stream works (openManagedStream(fInputStream) != oboe::Result::OK is fine) but reading it in the callback fails here oboe::ResultWithValue<int32_t> res = fInputStream->read(inbuffer, framesWrite, 0);

Any idea?

sletz commented 4 years ago

New version https://github.com/grame-cncm/faust/blob/master-dev/architecture/faust/audio/oboe-dsp.h, can you possibly check ?

philburk commented 4 years ago

I do not see any obvious errors in the way the streams are setup.

What is the error returned from the read()? Maybe print it at Line 125.

convertToText(res.error())

It is possible that the Input stream may not be ready for some reason the first time you call it. Does the error happen at the beginning, at the end or always?

Another issue is in the stop(). You close the input stream but it is still being used by the output stream callback. There is a race condition. Better to close the output stream before closing the input stream.

sletz commented 4 years ago

Thanks.

"Better to close the output stream before closing the input stream." => is it documented somewhere ?

philburk commented 4 years ago

Not specifically. We are planning to add a Tech Note on full duplex operation.