Question

I'm developing an application which will generate an audio stream (PCM) based on a input sequence. This sound (audio stream) will be played from start to end. What I want is to have some notifications about the position in the input sequence when the generated sound is played.

Example:

I have the input as "ABC" and the generated sound corresponds to 3 seconds for letter A, 2 seconds for letter B and 2 seconds for letter C ---> a total of 7 seconds (3+2+2). The notification means that after 3 seconds an event about 'A transmitted' is sent, 2 seconds after that an event about 'B transmitted' is sent and after 2 more seconds the 'C transmitted' event is sent.

Is there a classic way of doing this, or this is particular to each problem? (I'm using C/C++ with portaudio framework)

Right now the only way I would do this is by generating on the fly the audio data for each letter as the player advances into the stream.

NOTE: I know about how to send asynchronous events between threads and inter threading communication. I'm just interested if there's a classic way of doing this.

Thanks

Was it helpful?

Solution

Portaudio does not have a mechanism to notify you when a particular event is played through the audio device, or when a specific time has passed. If you need to know when a specific amount of data has passed through the device, you'll need to poll the device using Pa_GetStreamTime.

Often, especially with low-latency settings, it is sufficient to know that the data is written and will be played. In this case, standard (lock-free) inter-thread communication will do.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top