Hello,
I'm trying to add a sync input to the waveforms of the audio library but am having issues adding a second input.
I've succeeded in making my own effects with two inputs but there's still something I'm not getting about the objects.
Here is my test where the second input does nothing. It's just read if it exists and released.
sketch:
In "synth_sine.h" I changed this line :
And here's what I added in "synth_sine.cpp" :
When uncommented "Serial.println("a");" will show up once, then it crashes.
Thanks!
I'm trying to add a sync input to the waveforms of the audio library but am having issues adding a second input.
I've succeeded in making my own effects with two inputs but there's still something I'm not getting about the objects.
Here is my test where the second input does nothing. It's just read if it exists and released.
sketch:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioSynthWaveform waveform1; //xy=240,329
AudioSynthWaveform waveform2; //xy=244,396
AudioSynthWaveformSineModulated sine_fm1; //xy=444,318
AudioMixer4 mixer1; //xy=496,461
AudioOutputI2S i2s1; //xy=653,304
AudioConnection patchCord1(waveform1, 0, sine_fm1, 0);
AudioConnection patchCord4(waveform2, 0, sine_fm1, 1);
AudioConnection patchCord2(sine_fm1, 0, i2s1, 0);
AudioConnection patchCord3(sine_fm1, 0, i2s1, 1);
// GUItool: end automatically generated code
AudioControlSGTL5000 sgtl5000_1; //xy=615.7142857142857,619.9999999999999
uint32_t prev3;
void setup() {
AudioNoInterrupts();
Serial.begin(9600);
delay(500);
Serial.println("start");
sgtl5000_1.enable();
sgtl5000_1.volume(.75);
AudioMemory(50);
waveform1.begin(1, .5, WAVEFORM_TRIANGLE);
waveform2.begin(1, 2, WAVEFORM_TRIANGLE);
sine_fm1.amplitude(1);
sine_fm1.frequency(220);
AudioInterrupts();
}
void loop() {
if (millis() - prev3 > 100 && 1 == 1) {
prev3 = millis();
Serial.print(AudioProcessorUsageMax());
Serial.print(" ");
Serial.println(AudioMemoryUsageMax());
AudioProcessorUsageMaxReset();
AudioMemoryUsageMaxReset();
}
}
In "synth_sine.h" I changed this line :
Code:
class AudioSynthWaveformSineModulated : public AudioStream
{
public:
AudioSynthWaveformSineModulated() : AudioStream(2, inputQueueArray), magnitude(16384) {}
And here's what I added in "synth_sine.cpp" :
Code:
void AudioSynthWaveformSineModulated::update(void)
{
audio_block_t *block, *modinput, *syncinput;
uint32_t i, ph, inc, index, scale;
int32_t val1, val2;
int16_t mod, sync;
modinput = receiveReadOnly(0);
syncinput = receiveReadOnly(1);
// Serial.println("a"); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ph = phase_accumulator;
inc = phase_increment;
block = allocate();
if (!block) {
// unable to allocate memory, so we'll send nothing
if (modinput) {
// but if we got modulation data, update the phase
for (i = 0; i < AUDIO_BLOCK_SAMPLES; i++) {
mod = modinput->data[i];
ph += inc + (multiply_32x32_rshift32(inc, mod << 16) << 1);
}
release(modinput);
}
else {
ph += phase_increment * AUDIO_BLOCK_SAMPLES;
}
phase_accumulator = ph;
return;
}
if (modinput) {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (syncinput) {
for (i = 0; i < AUDIO_BLOCK_SAMPLES; i++) {
sync = syncinput->data[i];
}
release(syncinput);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
for (i = 0; i < AUDIO_BLOCK_SAMPLES; i++) {
index = ph >> 24;
val1 = AudioWaveformSine[index];
val2 = AudioWaveformSine[index + 1];
scale = (ph >> 8) & 0xFFFF;
val2 *= scale;
val1 *= 0x10000 - scale;
//block->data[i] = (((val1 + val2) >> 16) * magnitude) >> 16;
block->data[i] = multiply_32x32_rshift32(val1 + val2, magnitude);
// -32768 = no phase increment
// 32767 = double phase increment
mod = modinput->data[i];
ph += inc + (multiply_32x32_rshift32(inc, mod << 16) << 1);
//ph += inc + (((int64_t)inc * (mod << 16)) >> 31);
}
release(modinput);
}
else {
ph = phase_accumulator;
inc = phase_increment;
for (i = 0; i < AUDIO_BLOCK_SAMPLES; i++) {
index = ph >> 24;
val1 = AudioWaveformSine[index];
val2 = AudioWaveformSine[index + 1];
scale = (ph >> 8) & 0xFFFF;
val2 *= scale;
val1 *= 0x10000 - scale;
block->data[i] = (val1 + val2) >> 16;
ph += inc;
}
}
phase_accumulator = ph;
transmit(block);
release(block);
}
When uncommented "Serial.println("a");" will show up once, then it crashes.
Thanks!