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

Thread: Possible to use AudioEffectEnvelope with analogWrite()?

  1. #1
    Junior Member
    Join Date
    Oct 2020
    Posts
    3

    Possible to use AudioEffectEnvelope with analogWrite()?

    I'm using PWM with analogWriteFrequency() to drive MOSFETs connected to magnets which vibrate tuned strings. Works great.

    The analogWrite() function increases and decreases the duty cycle and acts a bit like a volume control in this context. I've been able to control that effectively via MIDI CC, but I'd much rather handle this on the teensy side using an ADSR envelope generator.

    I've looked a bit at AudioEffectEnvelope in the Audio library, but can't see how to use it with analogWrite().

    Any advice or examples of how to use AudioEffectEnvelope to control a simple argument in this way?

    Thanks!

  2. #2
    Member
    Join Date
    Sep 2020
    Location
    Massachusetts
    Posts
    61
    I have had some success with this by forking AudioEffect envelope and adding a callback after update() completes its audio memory work.

    ...end of update()

    transmit(block);
    release(block);
    if (functionPointer > 0x00) {
    functionPointer((mult_hires >> 14) / 16);
    }
    //Serial.println("check observer notify");
    if (observer > 0x00) {
    // Serial.println("observer notify");
    observer->notify((mult_hires >> 14) / 16);
    }

  3. #3
    Junior Member garcho's Avatar
    Join Date
    May 2020
    Location
    Richmond, VA
    Posts
    12
    I'm a noob, and I haven't tried it myself, so this is just a random suggestion, but perhaps in the audio system design tool, you could do something like:

    DC => ENVELOPE => PWM


    One encoder could do ADSR (or even DAHDSR), cycle through with the built in push button. On the thing i'm working on now, i use the encoder button to switch between adding value by 1s or 100s and have a separate button for cycling through ADSR.

  4. #4
    Member
    Join Date
    Sep 2020
    Location
    Massachusetts
    Posts
    61
    Yes, that's the right way to do it!
    I am routing the digital value of the envelope to "physical PWM" pin on the Teensy so I can generate a "DAC-like" voltage to control an external analog circuit.
    Click image for larger version. 

Name:	IMG_1393.png 
Views:	2 
Size:	498.3 KB 
ID:	22515
    I am able to generate digital waveforms, use a digital ADSR envelope generator (the 3rd row of knobs) and control an analog VCF->VCA with a really low parts count.

  5. #5
    Member
    Join Date
    Sep 2020
    Location
    Massachusetts
    Posts
    61
    The Synthesizer above is two identical monophonic synths sharing the same set of controls.
    It uses the L and R MQS outputs for the waveform generators.
    I use a PWM pin for VCA, a PWM pin for VCF cutoff, and a PWM pin for VCF resonance. The summed cutoff voltage also drives an LED, for fun.
    Top row: Waveform/Oscillator 2 transpose/detune
    Second row: 24dB/oct analog lowpass filter (with poor man's keyboard tracking)
    Third row:ADSR
    Fourth row: Modulation options.
    Left/rigtht yellow buttons: Voice A or Voice B toggle (each can be on a different midi channel). Pushing both buttons puts Synth B in Mirror Mode of Synth A (awesome unison)
    The weird dial on the right is for program load/save and MIDI channel select.

    I could make a dedicated Teensy Audio Library module to convert "dc" values to some DAC.
    I would prefer this to trying to overload a DAC intended for audio signal. If I have an audio-grade DAC, it seems a waste to borrow a channel to drive some outboard voltage controlled device.
    I want as many good-quality audio channels as I can get. (in practice that's 2)
    I would prefer a new/different class of output device for DC signals. It's super-convenient to generate control signals this way and be able to use them outside of the Teensy. Otherwise you end up needing an interrupt-driven function generator library that plays nicely with the Teensy Audio Library. Why do that?

Posting Permissions

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