Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 11 of 11

Thread: MI Braids into an audio object

  1. #1
    Junior Member
    Join Date
    Jun 2019
    Location
    Rennes, France
    Posts
    9

    MI Braids into an audio object

    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:
    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 by xtreemechill; 06-07-2020 at 11:55 PM.

  2. #2
    Junior Member
    Join Date
    Jun 2019
    Location
    Rennes, France
    Posts
    9

  3. #3
    Junior Member
    Join Date
    Jun 2019
    Location
    Rennes, France
    Posts
    9
    I saw several clones on my github, please share your work

  4. #4
    Junior Member
    Join Date
    Jun 2020
    Posts
    4
    I was thinking about doing exactly this same conversion, good thing I googled first! I'm not a C++ developer really either, but I'll try it out and see if I could at least reproduce the problems

  5. #5
    Junior Member
    Join Date
    Jun 2019
    Location
    Rennes, France
    Posts
    9
    Quote Originally Posted by laamaa View Post
    I was thinking about doing exactly this same conversion, good thing I googled first! I'm not a C++ developer really either, but I'll try it out and see if I could at least reproduce the problems
    In my opinion it is just about the frequency and the sample rate (maybe the block size either). I try to change them in the AudioLibrary but it is not a good choice as all other audio objects will not work ...

  6. #6
    Junior Member
    Join Date
    Oct 2015
    Posts
    7
    Modify the waveforms.py and lookup_tables.py python scripts included with braids to run at 44.1khz and rerun the script to generate the waveforms and lookup table for "resources.cc"

  7. #7
    Junior Member
    Join Date
    Jun 2019
    Location
    Rennes, France
    Posts
    9
    Quote Originally Posted by trash80 View Post
    Modify the waveforms.py and lookup_tables.py python scripts included with braids to run at 44.1khz and rerun the script to generate the waveforms and lookup table for "resources.cc"
    Niiiice ! I will try this, thanks !

  8. #8
    Junior Member
    Join Date
    Jun 2019
    Location
    Rennes, France
    Posts
    9

    Unhappy

    Quote Originally Posted by xtreemechill View Post
    Niiiice ! I will try this, thanks !

    I think that resources were already compiled with sample rate set to 44100, I try to re-compile them with the AUDIO_SAMPLE_RATE_EXACT 44117.64706 but same sound ...

  9. #9
    Junior Member
    Join Date
    Jun 2020
    Posts
    4
    Quote Originally Posted by xtreemechill View Post
    I think that resources were already compiled with sample rate set to 44100, I try to re-compile them with the AUDIO_SAMPLE_RATE_EXACT 44117.64706 but same sound ...
    I had unfortunately the same results with my audio shield (even at 96khz). Strange that the sound's pitch seems to change correctly when played with midi but otherwise the sound is wrong, I wonder if the rendering doesn't work properly for some reason...

  10. #10
    Junior Member
    Join Date
    Jun 2020
    Posts
    4
    Ok, now I got it working with my audio shield.. mostly Some things seem to crash my Teensy 3.2 and Teensy 4.0 completely, like trying to use triple saw shape. But at least a lot of the modes are working correctly I also switched to Braids Reneissance.

    The forked code can be found from https://github.com/laamaa/AudioSynthBraids/tree/test

  11. #11
    Junior Member
    Join Date
    Jun 2019
    Location
    Rennes, France
    Posts
    9
    Quote Originally Posted by laamaa View Post
    Ok, now I got it working with my audio shield.. mostly Some things seem to crash my Teensy 3.2 and Teensy 4.0 completely, like trying to use triple saw shape. But at least a lot of the modes are working correctly I also switched to Braids Reneissance.

    The forked code can be found from https://github.com/laamaa/AudioSynthBraids/tree/test
    Good news !!! Yeah some of the mode just make teensy crash ...

    Much more simple I may have complicated the thing ^^

    Nice work, thanks ! I will try it tomorrow !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •