This sketch shows how to use the mathneon library which provides optimized implementation of many simple math functions. The code is based on the sinetone/render.cpp project, with the following differences:
 
#include <libraries/math_neon/math_neon.h>
#include <stdlib.h>
#include <time.h>
 
 
#define NUM_OSCS 40
 
float gPhaseIncrement;
 
float gFrequencies[NUM_OSCS];
float gPhases[NUM_OSCS];
 
float gFrequenciesLFO[NUM_OSCS];
float gPhasesLFO[NUM_OSCS];
 
float gScale;
 
{
        gScale = 1 / (float)NUM_OSCS * 0.5;
 
        srand (time(NULL));
 
        for(int k = 0; k < NUM_OSCS; ++k){
                        
                        gFrequencies[k] = rand() / (float)RAND_MAX * 2400 + 300;
                        
                        gFrequenciesLFO[k] = rand() / (float)RAND_MAX * 0.05 + 0.001;
                        gPhasesLFO[k] = 0;
                }
 
        return true;
}
 
{
        for(
unsigned int n = 0; n < context->
audioFrames; n++) {
 
                float out[2] = {0};
 
                for(int k = 0; k < NUM_OSCS; ++k){
 
                        
                        float LFO = sinf_neon(gPhasesLFO[k]);
                        gPhasesLFO[k] += gFrequenciesLFO[k] * gPhaseIncrement;
                        if(gPhasesLFO[k] > M_PI)
                                gPhasesLFO[k] -= 2.0f * (float)M_PI;
 
                        
                        
                        
                        
                        
                        out[k&1] += sinf_neon(gPhases[k]) * gScale * (LFO*LFO);
                        gPhases[k] += gFrequencies[k] * gPhaseIncrement;
                        if(gPhases[k] > M_PI)
                                gPhases[k] -= 2.0f * (float)M_PI;
 
                }
        }
}
 
{
 
}
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 audioFrames
The number of audio frames per block.
Definition Bela.h:322
const float audioSampleRate
The audio sample rate in Hz (currently always 44100.0).
Definition Bela.h:328