This example loads a specified range of samples from a file into a buffer using a helper function provided in libraries/AudioFile/AudioFile.h. This should be used when working with small wav files. See sampleStreamer and sampleStreamerMulti for more elaborate ways of loading and playing back larger files.
 
#include <libraries/AudioFile/AudioFile.h>
#include <vector>
 
std::string gFilename = "waves.wav";
int gStartFrame = 44100;
int gEndFrame = 88200;
 
std::vector<std::vector<float> > gSampleData;
 
unsigned int gReadPtr; 
 
{
        return true;
}
 
{
    for(
unsigned int n = 0; n < context->
audioFrames; n++) {
 
 
        
        if(++gReadPtr > gSampleData[0].size())
            gReadPtr = 0;
 
            
                float out = gSampleData[channel%gSampleData.size()][gReadPtr];
        }
    }
}
 
 
{
}
static void audioWrite(BelaContext *context, int frame, int channel, float value)
Write an audio output, specifying the frame number (when to write) and the channel.
Definition Bela.h:1469
void render(BelaContext *context, void *userData)
User-defined callback function to process audio and sensor data.
Definition render.cpp:68
bool setup(BelaContext *context, void *userData)
User-defined initialisation function which runs before audio rendering begins.
Definition render.cpp:51
void cleanup(BelaContext *context, void *userData)
User-defined cleanup function which runs when the program finishes.
Definition render.cpp:96
std::vector< std::vector< float > > load(const std::string &filename, int maxCount=-1, unsigned int start=0)
Definition AudioFileUtilities.cpp:135
Structure holding audio and sensor settings and pointers to I/O data buffers.
Definition Bela.h:231
const uint32_t audioOutChannels
The number of audio output channels.
Definition Bela.h:326
const uint32_t audioFrames
The number of audio frames per block.
Definition Bela.h:322