How to play a float* buffer


#1

Hi everyone,
It’s been like 5 hours that i’m searching the smartest way to play a float* buffer, i’ve read a lot of topic, all the documentation.

Let me explain:
I’ve got a api which fill my buffer, that i call in a MyAudioIODeviceCallback.
I’ve got a AudioDeviceManager, a AudioTransportSource, and i think i need a AudioSampleBuffer, but now i’ve got that, i’m blocked…

Can you please give me some helps?


#2

It depends on how you want to play it e.g. just once from the start, seek-able, in a loop, in an audio chain etc.

Put simply you just need to add the float samples to the outputChannelData buffer that you receive in your AudioIODeviceCallback::audioIODeviceCallback method. You will have to deal with all the positioning yourself though.

I did recently create an AudioSampleBufferAudioFormat however which may ease things slightly and makes playing a float* buffer interchangeable with any other kind of audio file. See the documentation here.

To use this you will have to create an AudioSampleBuffer and using the “dataToReferTo” constructor then create an InputStream to the getArrayOfChannels method which you can use to create the reader.

It may seem complex but is really only a few lines of code and saves a lot of time in the end.


#3

[quote=“dave96”]It depends on how you want to play it e.g. just once from the start, seek-able, in a loop, in an audio chain etc.

Put simply you just need to add the float samples to the outputChannelData buffer that you receive in your AudioIODeviceCallback::audioIODeviceCallback method. You will have to deal with all the positioning yourself though.

I did recently create an AudioSampleBufferAudioFormat however which may ease things slightly and makes playing a float* buffer interchangeable with any other kind of audio file. See the documentation here.

To use this you will have to create an AudioSampleBuffer and using the “dataToReferTo” constructor then create an InputStream to the getArrayOfChannels method which you can use to create the reader.

It may seem complex but is really only a few lines of code and saves a lot of time in the end.[/quote]

Hi dave, and thanks for your reply!
I need to play my buffer in differents ways: just once from the start, in a loop, or in freeze mode.
I’m gonna check your solution right now, but can you explain me how to use my AudioDeviceManager, my AudioTransportSource and my AudioSampleBuffer please?
Salutations,
Nox

[EDIT] Here is some of my code

      ///
      /// @brief SoundManager constructor
      ///
      /// @param sound_data[in] t_sound_data structure which contains all the needed stuff
      ///
      SoundManager::SoundManager(t_sound_data *sound_data) {
        this->_sound_data = sound_data;
        this->_audio_device_manager.initialise(1, 2, 0, true);
      	AudioFormatManager format_manager;
      	format_manager.registerBasicFormats();
        this->_audio_device_manager.addAudioCallback(this);
      } 

      ///
      /// @brief data initialisation
      ///
      void SoundManager::Initialisation() {
        this->_audio_buffer = new AudioSampleBuffer(&(this->_sound_data->samples), 1,this->_sound_data->sample_frame_number);
      }

      ///
      /// @brief Processes a block of incoming and outgoing audio data.
      ///
      /// @param inputChannelData	a set of arrays containing the audio data for each incoming channel
      /// @param numInputChannels	the number of pointers to channel data in the inputChannelData array
      /// @param outputChannelData	a set of arrays which need to be filled with the data that should be sent to each outgoing channel of the device
      /// @param numOutputChannels	the number of pointers to channel data in the outputChannelData array
      /// @param numSamples	the number of samples in each channel of the input and output arrays
      ///
      void SoundManager::audioDeviceIOCallback(const float **inputChannelData, int totalNumInputChannels, float **outputChannelData, int totalNumOutputChannels, int numSamples) {
        _analyzer_process_(this->_sound_data->handle, this->_sound_data->samples, numSamples);
        outputChannelData = &(this->_sound_data->samples);
      }