This is an extension of the sampleStreamer example. Functionality of opening files, managing buffers, retrieving samples etc. is built into the sampleStream class, making it easier to have multiple playback streams at the same time. Streams can be paused/unpaused with the option of fading in/out the playback.
 
#include <cmath>
#include <SampleStream.h>
 
#define NUM_CHANNELS 2    
#define BUFFER_LEN 44100   
#define NUM_STREAMS 20
 
int gStopThreads = 0;
int gTaskStopped = 0;
int gCount = 0;
 
void fillBuffers(void*) {
    for(int i=0;i<NUM_STREAMS;i++) {
        if(sampleStream[i]->bufferNeedsFilled())
            sampleStream[i]->fillBuffer();
    }
}
 
{
 
    for(int i=0;i<NUM_STREAMS;i++) {
        sampleStream[i] = 
new SampleStream(
"waves.wav",NUM_CHANNELS,BUFFER_LEN);
    }
 
    
                return false;
 
        return true;
}
 
{
 
    
 
    
    
    for(int i=0;i<NUM_STREAMS;i++) {
        
        if((rand() / (float)RAND_MAX)>0.9999)
            sampleStream[i]->togglePlaybackWithFade(0.1);
            
            
            
        
        
        
        
        
        
    }
    
 
    for(
unsigned int n = 0; n < context->
audioFrames; n++) {
 
 
        for(int i=0;i<NUM_STREAMS;i++) {
            
            sampleStream[i]->processFrame();
        }
 
 
            float out = 0;
            for(int i=0;i<NUM_STREAMS;i++) {
                
                out += sampleStream[i]->getSample(channel);
            }
            
 
        }
 
    }
}
 
 
{
    for(int i=0;i<NUM_STREAMS;i++) {
        delete sampleStream[i];
    }
}
Definition SampleStream.h:16
void * AuxiliaryTask
Definition Bela.h:561
int Bela_scheduleAuxiliaryTask(AuxiliaryTask task)
Run an auxiliary task which has previously been created.
AuxiliaryTask Bela_createAuxiliaryTask(void(*callback)(void *), int priority, const char *name, void *arg=NULL)
Create a new auxiliary task.
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
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