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

Thread: Tutorial On Writing Directly to Audio Shield Output?

  1. #1

    Tutorial On Writing Directly to Audio Shield Output?

    The Project:
    I've got a Teensy 3.6 and an audio shield, and I'd like to write my own additive synth from scratch... I want to have just one array of points for a sine wave, and then every time I want to generate a new sample I do the following:


    Code:
    while (there are more partials) { 
        Select a sample for the current partial from the array based on the desired frequency and phase for oscillator and the sample from the last cycle for that partial
        Multiply by current value of EG for this partial
        Add the resulting sample value to the output accumulator
    }
    Multiply by compression factor to compress the resulting waveform so that clipping doesn't occur (map max value during the past 1s to 1.0 volume) 
    Multiply by current value of overall instrument EG
    Write the resulting sample to the audio buffer
    Update the previous values for all all partials and EGs
    Check to see if any new MIDI messages have come in over USB. If so, adjust desired frequencies accordingly
    // See how many sines can fit in this and still get real time audio out of a Teensy 3.6
    And then each patch could have as many or as few sine waves as it needs up to the amount that I can reliably add in and still get real time functionality out of the thing.

    Does this sound doable? And are there any tutorials on how to write directly to the output buffer of the audio shield so I could start writing this synth?

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,941
    Quote Originally Posted by IWorkInPixels View Post
    And are there any tutorials on how to write directly to the output buffer of the audio shield so I could start writing this synth?
    Maybe this can help?

    https://www.pjrc.com/teensy/td_libs_...ewObjects.html

    The basic idea is you write to a buffer of 128 sample each time your update() function is called. The output code uses the samples from that buffer, if you've made a connection from your object to the output object.

Posting Permissions

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