ATTiny85 as envelope detector + controller for compressor or filter

Started by Fancy Lime, October 18, 2020, 02:32:12 PM

Previous topic - Next topic

Fancy Lime

Has anyone here tried this? I'm thinking: one of the analog pins as signal input, the two others as parameter inputs via control voltage from pots. One or both of the PWM pins can be used to control an analog circuit. From what I read on the chip that should be possible, I think, but I have zero practice experience with DSP.

Thanks,
Andy
My dry, sweaty foot had become the source of one of the most disturbing cases of chemical-based crime within my home country.

A cider a day keeps the lobster away, bucko!

ElectricDruid

Yeah, I've tried it. Not on AVR, on PIC, but same deal.

I've got a bit of code I called "FOLLOW" which is a firmware implementation of Harry Bissel's "three peak detectors" envelope follower.

The tricky bits were reading the analog inputs fast enough to get a decent sample rate and still be able to read the pots. My code reads the ADC at something like 48KHz (if I remember now) and every other read is a pot read, so the audio sample rate is 24KHz - not fantastic, but plenty good enough just to get an idea of the amplitude. Then it does a ton of processing before spitting out the output.

Because I decided that I needed output samples at the audio sample rate (that's not *necessary*, just desirable) I finished up having to use some of the time after a pot is dealt with to complete the envelope follower processing. Basically, time got short, partly/mostly because running even simple IIR filters on a chip with no multiply instruction is a bit of an ask!!

So yeah, it can definitely be done. Avoid feature creep, keep it as simple as you can. Because you're processing audio, time gets tight fast.

Tom



anotherjim

I agree with Tom. Note that the ADC clock can be as fast as 1Mhz with decent accuracy while the datasheet tells us to go slower.
If I guess your aim correctly, there's probably no need to be especially fast, regular or synchronous and the program could be pretty much inline and not worry about interrupts. That is assuming your envelope detector is all external and the ADC only has to take it's turn reading a buffered DC envelope voltage and it could easily do that in turn with checking the parameter pots.

Fancy Lime

Thanks guys!

Hmm, avoid feature creep, you say, Tom. But feature creep is what drive me from analog envelope detectors to DSP in the first place. Maybe I'm gonna need a bigger boat ship chip. In the end at least few features will suffice for getting my feet wet and see where this thing goes.

The idea was indeed to feed the chip with straight up audio but if sample rate is a problem, I could put an analog envelope detector with the fastest possible response up front and only use the DSP chip to slow the attack or decay or alter the curve profile. For what I have in mind, quick response is not critical. Neither fast transients nor high frequencies need to be followed. Sampling the analog envelope at 1kHz would be overkill. 100Hz should suffice. If on the other hand I want to avoid the analog envelope detector, I would probably need something like 2-3kHz and a steep low pass filter before the input to avoid aliasing.

Do you need to check all inputs on each pass with these things? Otherwise, check the pots should probably be done at a much lower rate than the audio/envelope in. More like 1-10Hz.

Cheers,
Andy
My dry, sweaty foot had become the source of one of the most disturbing cases of chemical-based crime within my home country.

A cider a day keeps the lobster away, bucko!

ElectricDruid

Quote from: Fancy Lime on October 18, 2020, 05:23:09 PM
Hmm, avoid feature creep, you say, Tom. But feature creep is what drive me from analog envelope detectors to DSP in the first place. Maybe I'm gonna need a bigger boat ship chip. In the end at least few features will suffice for getting my feet wet and see where this thing goes.
All I meant by "avoid feature creep" is that you'll start thinking that it'd be a good idea to have an LFO on there too, so you could mix the envelope output with the LFO output. Or you could use the envelope to control the LFO rate. Or the LFO depth. See what I mean?! All of those are good ideas, but (at least on a simple chip) there won't be time. Either use a chip that can do all of that, or do it on separate chips. I've already got the StompLFO for most of the other stuff, so if I had a 0-5V output from an envelope follower chip, I could use it to control any/all of the StompLFO's parameters.

Quote
The idea was indeed to feed the chip with straight up audio but if sample rate is a problem, I could put an analog envelope detector with the fastest possible response up front and only use the DSP chip to slow the attack or decay or alter the curve profile.
No, no, definitely do the envelope detection on the chip! Otherwise where's the fun or benefit?!

Quote
For what I have in mind, quick response is not critical. Neither fast transients nor high frequencies need to be followed. Sampling the analog envelope at 1kHz would be overkill. 100Hz should suffice. If on the other hand I want to avoid the analog envelope detector, I would probably need something like 2-3kHz and a steep low pass filter before the input to avoid aliasing.
I don't agree. I don't think this is fast enough. I might be wrong. Not unlikely, in fact. But we're trying to follow the overall amplitude of the audio signal. While we can filter that and remove some harmonics and hash, that will mean that we tend to miss the initial peak where those elements probably dominate. If you're sampling at only 3KHz, you're going to need very harsh filters. And if you're going to all that trouble with lots of analog filtering to filter the signal so your processor can cope, you might as well do the envelope follower in the analog domino too, no?

The supposed advantage of a digital solution that we're going for here is simplicity, right? You stick some audio in, you get a nice envelope out. Ideally with a couple of adjustments too. Bingo!

Quote
Do you need to check all inputs on each pass with these things? Otherwise, check the pots should probably be done at a much lower rate than the audio/envelope in. More like 1-10Hz.
No, you don't need to check everything every time. But you need to check the audio regularly, or you're going to introduce weird variable-sample-rate effects into the signal you're trying to process. It's possible that doesn't matter but that's more than I can get my head around right now. It certainly sounds like it matters. Interested to hear views on that one.

So...if you're sampling the audio regularly, and you need enough time to get something else in between the audio samples, you choose the best ADC rate you can get (let's say 50KHz, for the sake of argument). So you sample Audio, then some pot or other, then audio again, then you can sample another pot or you can ignore it, then Audio again, etc etc.
So you finish up with half the samples being audio (so 25KHz), and the others being available for pots. You might as well cycle through the pots on the alternate samples: Audio, Pot1, Audio, Pot2, Audio, Pot3, Audio, Pot4, Audio, Pot1, etc etc. Yes, its much faster than you need for pots really (especially with only a few pots), but there's no real benefit to slowing it down. It's a side-effect of the *audio* rate.

HTH,
Tom

garcho

NE571 can do double rectified ED with very few external components, maybe not anything at all what you're looking for but maybe it is, no DSP coding required, and less parts needed than having an op amp ED before the ATTiny.
  • SUPPORTER
"...and weird on top!"

ElectricDruid

I remain to be convinced that double rectification offers any actual benefits over simple full-wave rectification. I can't see how it can, tbh.

571 can do pretty typical analog envelope detection, with the usual trade-offs between response time and smoothness. I rather hoped we might improve a bit on that, with less parts. That's not setting the bar *that* high.

garcho

QuoteI remain to be convinced that double rectification offers any actual benefits over simple full-wave rectification. I can't see how it can, tbh.

I'm just quoting Thomas Henry because he knows way more than I do (as do you!).

Quote571 can do pretty typical analog envelope detection, with the usual trade-offs between response time and smoothness. I rather hoped we might improve a bit on that, with less parts. That's not setting the bar *that* high.

I wasn't responding to your thoughts on how to improve on anything, just responding to the first post "zero practice in DSP". No setting of any bar intended.
  • SUPPORTER
"...and weird on top!"

garcho

I think the idea behind double rectification for an ED is that the first go at it doubles the frequency without the need for a filtering cap, and the second go at it quadruples the frequency so the cap can be smaller and the response time is more sensitive but with little ripple. Not trying to change the subject though.
  • SUPPORTER
"...and weird on top!"

ElectricDruid

Quote from: garcho on October 19, 2020, 05:49:49 PM
Quote571 can do pretty typical analog envelope detection, with the usual trade-offs between response time and smoothness. I rather hoped we might improve a bit on that, with less parts. That's not setting the bar *that* high.

I wasn't responding to your thoughts on how to improve on anything, just responding to the first post "zero practice in DSP". No setting of any bar intended.

Fair enough. If you're going for an analogue solution, it's a decent chip for the job.  I suppose I'm just keen that someone else as a go at this digitally to see what I can learn from their efforts!

Quote from: garcho on October 19, 2020, 05:54:12 PM
I think the idea behind double rectification for an ED is that the first go at it doubles the frequency without the need for a filtering cap, and the second go at it quadruples the frequency so the cap can be smaller and the response time is more sensitive but with little ripple. Not trying to change the subject though.
Yeah, that's the theory, isn't it? And if you're doing an envelope follower, then a full wave rectifier is always going to give you less ripple than a half-wave rectifier, so I can go along with the first stage. I don't agree that that's because it "doubles the frequency" though. As we know, FWR's aren't exactly perfect for octave up, although with a bit of help they can do a useful job of it. I'd say the ripple is reduced because you turn a bipolar waveform into a unipolar one without just chopping off every other half-cycle. The flipped lower peaks "fill in the gaps" in the upper waveform. That's of clear benefit when trying to do the smoothing.
But then we get to the bit that makes no sense to me - *another* FWR. Why? We flip the points that used to be at the virtual ground up so they stick up instead, around some arbitrary new "midpoint" level that used to be half-way up the upper range of our waveform? It just makes no sense to me. It certainly won't double the frequency again, since it's pretty much impossible that the waveform you're feeding it is the same at the bottom as at the top (if it was, we just messed that up when we FWR'd it the first time).


Fancy Lime

Garcho, Tom,

One of my objectives for thin endeavor is to learn me some DSP. Simply out of interest in seeing what I can do with it. I suspect it's going to be fun since I rather like programming, although I usually only do that for data analysis, not for audio stuff. I also suspect that my designs may benefit from DSP integration where appropriate, since I am much better at programming than I am at soldering.

After some more research I decided to try a simple tremolo first to get a handle on things before moving on to envelope controlled effects. Ultimately, I think a fully parametric studio compressor should be much easier to do with analog signal path and a DSP envelope detection system than fully analog, but this will be a little down the road and probably require a faster chip or something like a Teensy.

Cheers,
Andy
My dry, sweaty foot had become the source of one of the most disturbing cases of chemical-based crime within my home country.

A cider a day keeps the lobster away, bucko!

garcho

I've been noodling around with Teensy audio, since I'm familiar with arduino's IDE it was really fun and easy! Have you seen this:

https://www.pjrc.com/teensy/gui/index.html
  • SUPPORTER
"...and weird on top!"

Mr. Lime

Sorry for digging up that old thread but the topic has always interested me.

I got myself a Drolo Moon Rabbit Envelope Phaser to get an idea how a StompLFO could be fed from an envelope detector.
Unfortunately the tracking isn't that great. I would love to try the Bissell detector but it's too much circuit effort to me just for the envelope part.

@Tom is there any plan in offering PICs with that envelope detector programmed or at least a released code to program it?


Thanks for help