xtreemechill
Member
Hi,
I would like to port the Mutable Instruments Braids into an audio object but I'm facing some issues:
- when I run Braids without audio object I use a timer like that:
- with the audio object I can't find out what is the right way to do it, it outputs something but it is not very clean, maybe it is the rate, or the data format
Any help will be appreciated
PS: I'm not a C++ developer (as you can see ^^)
I would like to port the Mutable Instruments Braids into an audio object but I'm facing some issues:
- when I run Braids without audio object I use a timer like that:
Code:
void putSample(void){
unsigned int val;
if(buffer_sel){
val = ((uint16_t)(bufferB[buffer_index]+0x7FFF))>>4;
}else{
val = ((uint16_t)(bufferA[buffer_index]+0x7FFF))>>4;
}
// // FOR teensy 3.5
analogWrite(A21, val);
// analogWrite(A22, val);
// FOR teensy 3.2
// analogWrite(A14, val);
buffer_index++;
if(buffer_index>=kAudioBlockSize) {
wait = 0;
buffer_index = 0;
buffer_sel = ~buffer_sel;
}
}
void init_braids(){
// Initalizes the buffers to zero
memset(bufferA, 0, kAudioBlockSize);
memset(bufferB, 0, kAudioBlockSize);
// Global used to trigger the next buffer to render
wait = 0;
// Initializes the objects
osc.Init();
osc.set_shape(MACRO_OSC_SHAPE_GRANULAR_CLOUD);
osc.set_parameters(0, 0);
myTimer.begin(putSample,1e6/96000.0);
//pinMode(13, OUTPUT);
//pinMode(23, OUTPUT);
// Defines the handlers of midi events
//usbMIDI.setHandleControlChange(OnControlChange);
// usbMIDI.setHandleNoteOn(OnNoteOn);
pitch = 32 << 7;
}
void main_braids(){
memset(sync_buffer, 0, sizeof(sync_buffer));
// Set the pin to 1 to mark the begining of the render cycle
digitalWriteFast(13,HIGH);
// If the pitch changes update it
if(pre_pitch!=pitch){
osc.set_pitch(pitch);
pre_pitch = pitch;
}
// Get the timbre and color parameters from the ui and set them
osc.set_parameters(timbre,color);
// Trims the shape to the valid values
shape = shape >= MACRO_OSC_SHAPE_LAST ? MACRO_OSC_SHAPE_LAST : shape<0 ? 0 : shape;
// Sets the shape
MacroOscillatorShape osc_shape = static_cast<MacroOscillatorShape>(shape);//
osc.set_shape(osc_shape);
if(buffer_sel){
osc.Render(sync_buffer, bufferA, kAudioBlockSize);
}
else{
osc.Render(sync_buffer, bufferB, kAudioBlockSize);
}
// Reads the midi data
// usbMIDI.read();
// Set the pin low to mark the end of rendering and processing
digitalWriteFast(13,LOW);
// Waits until the buffer is ready to render again
wait = 1;
while(wait);
}
- with the audio object I can't find out what is the right way to do it, it outputs something but it is not very clean, maybe it is the rate, or the data format
Code:
void AudioSynthBraids::update(void)
{
audio_block_t *block;
uint32_t i, scale;
int32_t val1, val2;
const uint8_t sync_buffer[AUDIO_BLOCK_SAMPLES] = { 0 };
uint8_t buffer_index = 0;
if (magnitude) {
block = allocate();
if (block) {
osc.Render(sync_buffer, buffer, AUDIO_BLOCK_SAMPLES);
for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
val1 = buffer[buffer_index];
if(buffer_index+1 > AUDIO_BLOCK_SAMPLES){
val2 = 0;
}else{
val2 = buffer[buffer_index+1];
}
Serial.print(val1);
Serial.print(",");
if(i%8 == 0)
Serial.print("\n");
scale = (buffer_index >>16) & 0x7FFF;
val2 *= scale;
val1 *= 0x10000 - scale;
#if defined(__ARM_ARCH_7EM__)
block->data[i] = multiply_32x32_rshift32(val1+val2, magnitude);
#elif defined(KINETISL)
block->data[i] = (((val1+val2) >> 16) * magnitude) >> 16;
#endif
buffer_index++;
}
Serial.print("\n");
Serial.print("\n");
transmit(block, 0);
release(block);
// wait = 0;
return;
}
}
}
Any help will be appreciated
PS: I'm not a C++ developer (as you can see ^^)
Last edited: