Multiple playback of large wav files
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 // NUMBER OF CHANNELS IN THE FILE
#define BUFFER_LEN 44100 // BUFFER LENGTH
#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];
}
}