• Audio
  • Reading real-time audio frame-by-frame instead of sample-by-sample

Hi, I need to buffer a frame 128 audio samples for processing. I use a for loop to buffer the audio frame from the Utilities routine audioRead(), reading in one sample at a time. When I writing the audio frame to the output, I use audioWrite() in another for loop, writing out one sample at a time.

Is there a more efficient way to collect a frame of audio samples? I wish to have a audioReadFrame() and a audioReadFrame() routine, passing the audio frame to me and back out without needing the for loop.

Thanks for your help.

    You can use the BelaContext structure's "audioIn" and "audioOut" members to access the data directly as stereo float arrays.

    But I seem to remember those functions just being inlines or macros anyway so it's probably not that bad.

      Rej But I seem to remember those functions just being inlines or macros anyway so it's probably not that bad.

      correct.

      kwan Is there a more efficient way to collect a frame of audio samples? I wish to have a audioReadFrame() and a audioReadFrame() routine, passing the audio frame to me and back out without needing the for loop.

      Can you explain a bit more what you are trying to achieve here?

      • kwan replied to this.

        giuliomoro I am a new owner of the Bela system. I have a DSP algorithm processing the audio in 128-sample frame captured from a live microphone and then play back the 128-sample frame to a loudspeaker.

        I am only now starting to look at the source code. Thanks to Rej's response, looking at Bela.h, I think I just need to set audioFrames to 128 and read/write from/to audioIn and audioOut arrays directly. You both are right that audioRead() is an inline routine. Thank so much for your quick response!

        No problem. You will notice that those arrays are by default interleaved. There is an option to have the non-interleaved if that is more convenient for your application.