Possible to use AudioEffectEnvelope with analogWrite()?

Status
Not open for further replies.

skiff

New member
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!
 
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);
}
 
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.
 
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.
IMG_1393.png
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.
 
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?
 
A follow-up to this thread. This morning I was able to initialize the code used above in a Teensy LC to make my LC a dedicated envelope chip. For now I am using a Cat Skull TeensyBoy board as a quick way to have a breakout for a MIDI-triggered board capable of supporting N number of ADSR envelope generators outputting to PWM pins.
In comparison to other "adsr-on-a-chip" solutions this kills it. This would let me make a an analog percussion synth module (with multiple analog voices) where only the audio signal path circuits would be needed; the triggers and envelopes and other modulation would be in the LC.
Finally a use for the LC on my bench!
 
(What always happens is, I start out with the Teensy LC on a project, and it works decently! But then I want a few more IO pins, and then I want an SD reader to save presets... Slippery slope of Teensy consumption.)
 
Another note. When I use the Teensy LC with Teensy Audio Library, I must use the Teensy LC 1-channel DAC.
This DAC gets clobbered when I change PWM frequency. When that happens, the Teensy Audio Library goes dead (update methods short circuit because there is no output device). So this is a limiting factor for using the AudioEffectEnvelope to drive several PWM pins. I assume I can find which set of PWM pins shares the timer with the DAC and avoid changing PWM frequency on them. But have not looked it up yet.
 
Status
Not open for further replies.
Back
Top