Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
|
This sketch produces a sine tone, the frequency and amplitude of which are modulated by data received on the analog input pins. Before looping through each audio frame, we declare a value for the frequency
and amplitude
of our sine tone; we adjust these values by taking in data from analog sensors (for example potentiometers) with analogRead()
.
The important thing to notice is that audio is sampled twice as often as analog data. The audio sampling rate is 44.1kHz (44100 frames per second) and the analog sampling rate is 22.05kHz (22050 frames per second). Notice that we are processing the analog data and updating frequency and amplitude only on every second audio sample, since the analog sampling rate is half that of the audio.
```` if(!(n % gAudioFramesPerAnalogFrame)) { Even audio samples: update frequency and amplitude from the analog inputs frequency = map(analogRead(context, n/gAudioFramesPerAnalogFrame, gSensorInputFrequency), 0, 1, 100, 1000); amplitude = analogRead(context, n/gAudioFramesPerAnalogFrame, gSensorInputAmplitude); } ````