We have now received the new Bela I mentioned previously, which came with the latest software already installed (I did another install to be sure). It seems that the old Bela we had been using was just being stubborn about updating, I will continue to investigate the issue.
I now seem to be having other issues. Currently I'm simply trying to load a mono audio file from disk, play it from the audio output and write it to disk using AudioWriter. However, using the script below, the resulting recording is a series of buzzing noises rather than the intended sine sweep.
/*
____ _____ _ _
| __ )| ____| | / \
| _ \| _| | | / _ \
| |_) | |___| |___ / ___ \
|____/|_____|_____/_/ \_\
http://bela.io
*/
#include <Bela.h>
#include <cmath>
#include <libraries/AudioFile/AudioFile.h>
#include "MonoFilePlayer.h"
#include <libraries/Pipe/Pipe.h>
#include <libraries/sndfile/sndfile.h>
AudioFileWriter writer;
// Name of the sound file (in project folder)
std::string gFilename = "sine_sweep_10.wav";
// Object that handles playing sound from a buffer
MonoFilePlayer gPlayer;
int gAudioFramesPerAnalogFrame = 0;
const char* outPath = "./recording.wav";
unsigned int gAudioFrames;
unsigned int gAudioInChannels;
float gAudioSampleRate;
std::vector<float> outBuffer(512);
AuxiliaryTask writeTask;
void writeAudio(void *)
{
writer.setSamples(outBuffer);
}
bool setup(BelaContext *context, void *userData)
{
// check audio and digital have same no. frames
if(context->audioFrames != context->digitalFrames) {
rt_fprintf(stderr, "This example needs audio and digital running at the same rate.\n");
return false;
}
// Load the audio file
if(!gPlayer.setup(gFilename)) {
rt_printf("Error loading audio file '%s'\n", gFilename.c_str());
return false;
}
// Print some useful info
rt_printf("Loaded the audio file '%s' with %d frames (%.1f seconds)\n",
gFilename.c_str(), gPlayer.size(),
gPlayer.size() / context->audioSampleRate);
// calculate no. audio frames per analog frame
if(context->analogFrames)
gAudioFramesPerAnalogFrame = context->audioFrames / context->analogFrames;
gAudioSampleRate = context->audioSampleRate;
gAudioFrames = context->audioFrames;
gAudioInChannels = context->audioInChannels;
writer.setup(outPath, 441000, gAudioInChannels, gAudioSampleRate);
writeTask = Bela_createAuxiliaryTask(writeAudio, 50, "bela-write-audio");
return true;
}
void render(BelaContext *context, void *userData)
{
for(unsigned int n = 0; n < context->audioFrames; n++) {
float out = 0.5*gPlayer.process();
for(unsigned int i = 0; i < outBuffer.size(); i++){
outBuffer[i] = out;
}
// Write sweep to speaker
audioWrite(context, n, 0, 0.02*out);
//audioRead(context, n, 0);
//audioRead(context, n, 1);
//writer.setSamples(outBuffer);
Bela_scheduleAuxiliaryTask(writeTask);
}
}
void cleanup(BelaContext *context, void *userData)
{
}