JuliaAudio / PortAudio.jl

PortAudio wrapper for the Julia programming language, compatible with the JuliaAudio family of packages
Other
115 stars 20 forks source link

Get number of samples available to be read? #119

Open arnief3 opened 2 years ago

arnief3 commented 2 years ago

Is Pa_GetStreamReadAvailable the correct way to get the number of samples available to be read? Or can PortAudioSource be queried for that information? What is the recommended approach? Does it make sense to add this to the official API?

bramtayl commented 2 years ago

Hello! I'm not sure I understand the port audio documentation for that function. But, you can read as many samples as you want from the microphone, as long as you wait for them to occur. Do you want the size of the read buffer? You could do stream.sink_messenger.buffer.frames_per_buffer; we could definitely make an official function for that.

arnief3 commented 2 years ago

My goal is to be able to determine the number of frames that are sitting in the read buffer and that can be read without waiting for additional data to be acquired by the audio input device. In other words, what is the max number of frames I can read without the read function blocking and waiting for more data. I think that is what Pa_GetStreamReadAvailable will give me.

My question about PortAudioSource may stem from a lack of understanding of how the intermediate buffers operate. Are frames pulled from the low level buffers and stored independent of my calls to read or is PortAudioSource essentially a pass through?

PortAudio.jl is working well for my application but this function would help me when I am trying to do real time audio processing. I will continue to study the code to try to better understand the low level details.