DIY looper/sampler chronicles

Started by cloudscapes, March 15, 2012, 12:39:15 AM

Previous topic - Next topic

cloudscapes

I thought I'd try something. For years I've wanted to build my dream looper. When I first started DIY stompboxes and noise-generators 6-ish years ago, I never in my right mind would I have guessed I'd be doing projects at the complexity I am now! And original ones at that! But still, these last few years, I've been gearing up (mentally) to tackle something huge (to my eyes). Looping is not only an important part of my music, but the ability to manipulate loops on the fly as well. I've tried many loopers. While many were excellent, they all lacked something another had that I thought was fantastic! So here I am now, thinking about how to combine those very best features and add a few of my own.

And I thought I'd start a thread about it, and log it as I make progress. :) Complete with a pretentious thread title!

I've only just started, and there will be many firsts for me in this project as well, so I'll try and keep it informative. How I made certain decisions and not others.There isn't a whole lot of information out there when it comes to non-ISD based loopers. Maybe this thread will contribute in some tiny bit. A reference of things that come up for such a project, to others. A mixture of technical and laypersons theory, and I will try and keep the theory to a maximum! But mostly, it will be a curiosity! It will also be a learning experience. I don't claim to be an expert, and I will make mistakes and errors in judgment. I'm learning as I go along with this ambitious project.

So really, what do I want?

- Hi-fi. 16bit 44khz is my goal.
- Variable fidelity/sampling rate for stepless time/pitch effects.
- Overdub with variable feedback. No question.
- Resonant LP / HP filter, and an automatic antialiasing filter
- Complete mixer to be able to mix from selectable inputs
- Same-pitch time stretching
- Automatic & manual "scrubbing"
- Ping-pong scrubbing, or "freeze" effects
- Reverse
- Loop cropping / trimming. Defining start-end loop points in realtime.
- Modulation
- Clickless seams


Will not do / not smart enough to do:

- Undo
- SD card storage
- Multitrack or stereo
- BPM or time-sensitive quantization


What have I done so far:

A simple breadboarded setup that can pass 12bit audio at around 100khz!  ;D It doesn't do anything but pass audio, no recording or feature whatsoever. Just raw analog-to-digital conversion and back again. I'm concentrating on getting simple audio right before I do any sort of recording, playback, logic or feature.

What I'm using so far:

I've started using MikroC, which is a C compiler for various microcontrollers. This is a very big step for me. Up 'till now, I had been using 8-bit AVRs and Bascom. While great for LFOs, presets and automation, they simply don't have the horsepower to do anything but telephone-quality audio. I've experimented quite a bit with audio on them, but I don't know assembly, so wasn't hitting good samplerates. What I made were fun little glitchy noise boxes that sample and loop, but in no way were they going to satisfy my looping needs. Bascom (basic) only supports AVRs, so I need to learn a new environment, and while I'm at it, language. A common language like C opens up future possibilities for other platforms as well, unlike Basic. So now, I learn. I'm still very much at the beginning of the language fundamentals of C.

Another new thing for me will be heavy use of surfacemount packages. I've done a few before, but with AVRs and most pedal builds, it wasn't really needed. With high-speed audio and data, it will be needed, and often in tiny pitch (0.5mm). I'm considering buying a cheap stereo microscope to aid me in this and other projects.



CPU:

A PIC32 board from Mikroelectronica. A little expensive but it's in an easy to use footprint on a DIP40 stamp and packs a punch! The chip on it is 32bit and clocks at 80MHz.

Digital-to-analog:

A PT8211 16bit DAC. Same company who make our beloved 2399 delay ic! Easily found for cheap (2 bucks a chip on ebay) and in an easy to use package (DIP8 or SOIC8), and specced to deliver better than CD-quality sound. I've tested it, it sounds good, it's cheap, it's fast, it works, I'm set!

Analog-to-digital:

Currently an MCP3201. It's easy to find and cheap, but is "only" 12bit and is quite slow. I can get decent samplerates with it, but data/SPI transfer isn't fast at all, so it doesn't leave the CPU much free time to do logic. I'm using it at the moment because I know it and I had some at hand. Must find something else. I've orded a couple LTC1864 which is, according to the datasheet, an extremely fast 16bit ADC in a nice SOIC8 package! Pretty expensive though, at $14 each. According to how hard my PIC32 is currently chugging, and if my math is right, I will be able to get 200khz sampling speeds at 16bit, just raw audio pass-through! That should leave my PIC32 with tons of time to perform logic and whatnot if I'm aiming for 44khz!

RAM:

This was the hard one. I've made some calculations. How much looping time do I want? Well, 10 seconds is a nice round number! Lessee..

- 1 sample at 16bit uses up two bytes.
- At 44khz, 44000-ish samples per second, one second uses up 88000 bytes, or 88KB.
- 10 seconds needs 880KB, or 1MB if we're rounding up for easy findability.


I've used Microchips 23k256 RAM ics a few times. They are in nice DIP8 packages, use fast and easy SPI communication, but they are only 32KB. Forget it. So I hop onto Mouser and Digikey to see what my RAM options are. This takes several days of reading datasheets and measuring options, actually. I have to filter out anythign that comes in BGA. So, a few kinds of RAM:

- FRAM. SPI communication, fast, easy package, but still small storage quantity
at 128KB and costs a leg at $28 for that little amount. Scratch that.

- Parallel RAM. Cheap-ish, common, easy to understand, VERY fast as its parallel
instead of serial com, but uses a ton of pins. 8 data pins + 20 address pins + 2-3
extra. I need over 30 free pins on my CPU! If I was using a large PIC32, I could do that,
but I'm not. I'm using a 64-pin micro on a 40-pin stamp, and not all of those 40 pins are
the right "kind". Also, I don't want the headache of routing the PCB for all those traces.
Still... parallel RAM is the de facto standard when it comes to consumer audio looping
and sampling at high-speed. Better order a couple, in case.

- Flash memory. Cheap, easy to use, nice packages, but a little slow, and limited write
cycles. 100,000 or so. If I'd be using this as a traditional looper, that might be enough,
but I have to plan for the time where I set the loop-trimming to 5 milliseconds and hit
record. There, I just burnt through 10% of the chips available rewrites in a second! ;D
Scratch that.

- MRAM. Specifically MR25H40. Hmm... doesn't seem to be a common type of memory.
But oooOOOHH! Look at these specs! Lightning-fast SPI com, zero read/write time, infinite
rewrites, and available as a 512KB! $14 is a bit pricey, but I'm willing to spend that much
if I only have to use one or two of them in the project! But... wait.... ohhhh
effffffffffffffffffffffffffffffff..................................

DFN package. That's nearly as bad as BGA.It's like... THERE ARE NO PINS! The pins are tiny little exposed metal UNDER the 8-pin square. Anyways, I order a couple, ball a bit of solder directly on the "pads", tin a SOIC-to-DIP adapter's pads (same footprint), and melt the balled-DFN onto the tinned adapter. It seems to have worked. Okay, I can do this. The specs make it worth it! Oooohh, data retention under no power even!

Speed test:

I have the digital oscilloscope (a cheap 25mhz Owon) hooked up to the circuit. The red lines represent the SPI clock hooked up to the slow 12bit ADC. The yellow lines are the clock on the fast DAC and MRAM. The green line I added represents a single sample. It represents an elapsed time of almost 30us. That's 30 millionths of a second! That's a short amount of time to us humans, but to a 32bit 80MHz microcontroller, a lot can be done in that amount of time. Here is how many millionths of a second my PIC32 hs to work with for each sample:

- 44khz = 23us per sample
- 33khz = 30us per sample
- 22khz = 45us per sample


Considering that, at the time I took this picture, I guess it was sampling at about 35khz, which in all honesty to my ears, sounds mostly fine.



The two large red blocks represent 8 clock pulses (for a total of 16, which is what the ADC needs to sample a single 12bits). They're just tight together which is why they look like one single huge pulse. The yellow represent the SPI clock hooked up to the much much faster 16bit DAC and MRAM ic! All 8 of the yellow lines have 8 little clock pulses of their own. Just so much more tightly together they appear as a single line! The first two of those blocks (16 pulses) are for the fast 16bit DAC, and the other 6 (48 pulses) for the MRAM.Once I get my new fast ADC, those two large red blocks will shrink to the size of the tiny yellow ones, and the PIC32 will have much more free time for logic/features, and/or will be able to achieve even higher samplerates!

I can measure how long it takes to read or write to the MRAM, about 4us, how long it takes to output to the DAC, 2us, and how long it currently takes to sample from the ADC, 8us.

It's half past midnight so I'll stop now. In a day or three, I'll write about why I chose to use a seperate ADC and DAC rather than use an audio codec chip, which is what's comonly used. Also, what I've learned about antialias filtering! Also, I'll fill in some links to stuff.
~~~~~~~~~~~~~~~~~~~~~~
{DIY blog}
{www.dronecloud.org}

Taylor

Subscribed. Put me down on the pre-order list...  ;)

cloudscapes

Testing new parts:

As I've said, this project has a lot of new things for me! New kinds of fast parts, a new language and environment, a brand new type of microcontroller. I didn't just plug new parts together and hoped I could get it working!  ;)

I know AVRs (8bit micros) fairly well, so when I purchased the new MRAM and 16bit DAC, I hooked those up to the AVR instead to see if I knew how to use them, figure out the routines, data order, control bits, etc. It made debugging and discovering a new part FAR easier. There were issues, but I could remove the AVR from the equation because I knew how to use these. Once I had a set of rules on how to use my new ics, I could move on to the new language and PIC32 and "translate" those rules. The AVR is far far too slow for decent audio.
~~~~~~~~~~~~~~~~~~~~~~
{DIY blog}
{www.dronecloud.org}

imbuedblue


wavley

New and exciting innovations in current technology!

Bone is in the fingers.

EccoHollow Art & Sound

eccohollow.bandcamp.com

slacker

This is possibly the start of the greatest thread in diystompbox history, look forward to seeing where it goes.

wavley

Quote from: slacker on March 15, 2012, 01:57:26 PM
This is possibly the start of the greatest thread in diystompbox history, look forward to seeing where it goes.

Apparently you have forgotten about this thread http://www.diystompboxes.com/smfforum/index.php?topic=76932.0  :D

Seriously, I've been wanting a looper diy for a while, but my programming skills are rudimentary at best.
New and exciting innovations in current technology!

Bone is in the fingers.

EccoHollow Art & Sound

eccohollow.bandcamp.com

cloudscapes

#7
That thread is gold.  :icon_biggrin:
~~~~~~~~~~~~~~~~~~~~~~
{DIY blog}
{www.dronecloud.org}

cloudscapes

Inspiration:

Looping is my main part of my solo sets. I use loopers as instruments if at all possible, and not just as stomp-and-forget boxes. I've used so many, and sold them after a while. I did keep four of them, though! And they're kind of my main inspiration for this project, feature-wise.

- Timefactor. Awesome looper! Has loop cropping/trimming and is pretty flexible! Wish they would of gone the extra mile with the crazy features, though!

- Stereo Memory Man / Hazarai. My simple workhorse looper when I don't need something complex. I like the filter on it and how fast one can lay down a loop.

- 2880. Not too many crazy features, but the UI design is something I admire! I think I prefer the tabletop format. I wish I could make mine multitrack, but for the moment, best focus on a single track.

- PDS-8000. Just love it!


Separate ADC / DAC vs codec IC:

I think a standard for these types of applications is a dedacated codec IC which incorporates ADC/DAC as well as audio-optimized filtering and stuff. I know my 2880 uses one of the Texas Instrument ones, maybe the PCM3001 (from memory), and I've seen them in a lot of other products where audio quality was important. They're an "all-in-one" audio solution to be connected to a microcontroller or CPU, which only handles the thinking. They're generally not too expensive, and have a lot of built-in audio features that normally I'd need a lot of external components for, but I chose not to go this route for one reason. They also all require a secondary clock that's hundreds of times higher frequency than the SPI/data transfer clock.

An SPI clock is a clock signal that drives the "engine" of a part to deliver or recieve data in that specific timing. This can be a variable speed, but is usually multiples of two. Some parts can send/recieve data to and from the PIC32  very quickly, while others require a slower clock running parallel to the data stream. Codecs are a bit more difficult, as they require a secondary clock that's exactly 256 or 512 times the samplerate (well into the MHz), and it has to be in sync with the SPI clock at all times! The SPI clock has to scale along with the samplerate, and that I simply can't do. I've read about it, and it's way way over my head. There are strict rules in place when it comes to codec timing and control. Maybe someday I will get familiar enough with this language and environment that I'll be able to use a codec, but at the moment, I'd rather find another way. Separate ADC and DAC it is. They are much "looser" in terms of these kinds of things, and are operated simply by SPI which I know pretty well. No additional clock required. No strict scaling of the SPI clock relative to the samplerate.

Using an ADC/DAC combo over a codec however brigns on another challenge. Antialias filtering. A codec IC wwhen properly controlled will filter the sample "stepping" in digital audio and will adjust the filter according to your samplerate. This is very helpful to have in a single chip! But since I'm going to be using an ADC/DAC combo, I'll have to devise external fitlering to get rid of the jaggies, and I'll need to sweep the filter when I tune the loop down to a slower speed. I'll probably end up using a MAX7404 ic which is a filter-on-a-chip controllable by either capacitor or clock input. If I use a clock, it won't have to be scaled perfectly with the SPI clock or samplerate. I can just wing it, use my ear. Much easier! More on that AA filter some other time.

Using an ADC/DAC combo vs a codec is moves much of the work involved from programming in the new environment (not my strength), over to external components and "winging it". Fine with me!

Display:

I'm gonna need some sort of visual feedback, though I haven't figured out what I want yet. An LCD would be nice, but I don't yet know how to cut squares in metal.
~~~~~~~~~~~~~~~~~~~~~~
{DIY blog}
{www.dronecloud.org}

wavley

I think that we are on the same page as far as loopers go, as a matter of fact last night I did a looping based song for a compilation of music recorded on cell phones.

My favorites are:

Boomerang+ (the III is nicer, but I have a wife, therefore I can no longer buy expensive things) because it is just laid out so well for live looping.
EHX 16 Second Delay because of the sweet glitch stuff you can do with it
Digitech RDS-900, my first looper, I love it most likely for all the same reasons you love your PDS
New and exciting innovations in current technology!

Bone is in the fingers.

EccoHollow Art & Sound

eccohollow.bandcamp.com

cloudscapes

This is pretty relevant:

http://www.youtube.com/watch?v=TRflDaVqfuQ

It's a looper I built a year and some months ago, but it is very very lo-fi and unreliable. It could use some extra features too. I guess what I want to build now is what this should have been, but couldn't be.
~~~~~~~~~~~~~~~~~~~~~~
{DIY blog}
{www.dronecloud.org}

cloudscapes

#11
I still haven't recieved my new 16bit ADCs yet, but I may still work on this on the weekend. maybe try and get a timer running on the PIC32 for a variable samplerate. at the moment I set the samplerate just with a wait state. maybe try and get a (samplerate*100) clock output going at the same time, which is what those filter chips described earlier need to clean up the sound.

Quote from: wavley on March 16, 2012, 09:19:51 AM
I think that we are on the same page as far as loopers go, as a matter of fact last night I did a looping based song for a compilation of music recorded on cell phones.

My favorites are:

Boomerang+ (the III is nicer, but I have a wife, therefore I can no longer buy expensive things) because it is just laid out so well for live looping.
EHX 16 Second Delay because of the sweet glitch stuff you can do with it
Digitech RDS-900, my first looper, I love it most likely for all the same reasons you love your PDS

I actually have the rang III ! I'll probably sell it though. it's mostly great, but a couple things keep me from using it. 1. I don't like the interface. I like to have buttons for each feature if possible, not have to assign buttons with the dial. and 2. you can't change the speed of the loop except by half. it has some other great features going for it, though! the free play mode, for instance!

I have never had the pleasure of using the 16 sec delay! one day, maybe, one day.....
~~~~~~~~~~~~~~~~~~~~~~
{DIY blog}
{www.dronecloud.org}

g_u_e_s_t

i would encourage another look at codec chips
there are some that are easy to work with
i have used the wolfson wm8731 a fair bit
and made a sampler out of it
http://www.openmusiclabs.com/projects/microdec/

mikroelektronika uses it as well in their codec breakout board
http://www.mikroe.com/eng/products/view/484/audio-codec-board-proto/

the antialiasing filters that are built in are way better than anything i could make
and it frees up a fair bit of data passing time for more processing time

i see your point about wanting to simply modify the codec clock to get different playback speeds
but this could also be done with interpolation
although that has a completely different sound

i havent tried this
but i think you can vary the codec clock pretty easily
even though it is up 16MHz or whatever
and the wm8731 doesnt require the spi transfer
to be a submultiple of the codec clock

cloudscapes

Quote from: g_u_e_s_t on March 17, 2012, 04:12:37 AM
i would encourage another look at codec chips
there are some that are easy to work with
i have used the wolfson wm8731 a fair bit
and made a sampler out of it
http://www.openmusiclabs.com/projects/microdec/

mikroelektronika uses it as well in their codec breakout board
http://www.mikroe.com/eng/products/view/484/audio-codec-board-proto/

the antialiasing filters that are built in are way better than anything i could make
and it frees up a fair bit of data passing time for more processing time

i see your point about wanting to simply modify the codec clock to get different playback speeds
but this could also be done with interpolation
although that has a completely different sound

i havent tried this
but i think you can vary the codec clock pretty easily
even though it is up 16MHz or whatever
and the wm8731 doesnt require the spi transfer
to be a submultiple of the codec clock

I don't know, I've read the datasheet and it's one of the more complex codec chips I've come accross. there are a whole bunch of registers to set. a little overwhelming. and I avoided that ic specifically as well because mikroelectronica have been promising samples for their WM8731 board since summer of 2010. it's kind of a joke on their forums now. "soon" they'd keep saying, and occasionally the "writing a library turned out to be more complicated than we thought" kind of says to me that if mikroelectronica are having trouble doing it after a year and a half, then there's no way I'd be able. I'm just learning this platform, as well as this language, and if I can get an ADC and DAC to sound good, then it's good enough to me. I appreciate the advice, though!

the filter ic I have in mind is the MAX7404, which is built for exactly such purposes.

I'll not outright dismiss the possibility just yet, but I've already poured through my compiler's help. I don't know yet how to output a multi-MHz clock using their compiler, and I didn't get any answer on their forum.
~~~~~~~~~~~~~~~~~~~~~~
{DIY blog}
{www.dronecloud.org}

g_u_e_s_t

yes there are a lot of registers to set
but i have documented them and have stuff written for it
so that could make it easier

i didnt know about the problems with mikroelecktronika
i saw that mouser says they have them in stock
http://www.mouser.com/ProductDetail/mikroElektronika/MIKROE-506/?qs=sGAEpiMZZMuNcqZxhMNT33vXtqfzWVVK

i also made a wm8731 breakout
http://www.openmusiclabs.com/projects/codec-shield/
its more of an arduino shield
but can be used as a breakout

but it looks like you have a good path chosen

im not certain the best method of sending a different clock to the codec
if the clock is generated from a microcontroller
then it will not have a fine granularity
unless there is a PLL onboard or something
so maybe an external analog oscillator would work
it isnt digitally settable but is easy to make

im getting quite curious about externally clocking this chip now
perhaps a 4046 PLL would do the trick
if i prototype something up i will report back

cloudscapes

Lets say I get my PIC32 to supply an external codec clock.

The max frequencies I can get with a timer on the mikro is 1.6MHz (tested it this morning). And without a timer, just a pin toggle in a loop, about double that. It's still not enough for a codec, they needs several MHz at least.

I'll look up the 4046 datasheet. I haven't done much discreet logic (just the odd schmitt trig or binary counter).
~~~~~~~~~~~~~~~~~~~~~~
{DIY blog}
{www.dronecloud.org}

g_u_e_s_t

what sort of frequency range were you thinking of using with your current setup
if the fastest the mikroc can go is 1.6MHz
then there might be a granularity issue already at 100khz sample rate

also
are you planning on having your anti aliasing filter change with sample rate
i noticed the top speed of the MAX7404 is only 10kHz
it can be overclocked but then it gets noisey

cloudscapes

#17
Quote from: g_u_e_s_t on March 17, 2012, 04:28:00 PM
what sort of frequency range were you thinking of using with your current setup
if the fastest the mikroc can go is 1.6MHz
then there might be a granularity issue already at 100khz sample rate

also
are you planning on having your anti aliasing filter change with sample rate
i noticed the top speed of the MAX7404 is only 10kHz
it can be overclocked but then it gets noisey

yeah I may eventually get a different MAX ic with a higher freq cuttoff.

basically, I want the filter to change with the samplerate. lets say I find a MAX ic with a higher cuttoff. if I'm sampling at 44khz tops, then the MAX ic requires a clock input of (frequency*100), so a clock input of 4.4MHz.

as for the lower frequency, I want well below 6khz.

I've used the MAX6404 before, but with an input cap and a pot to ground. I had an AVR drive a vactrol between the timing cap and ground for control of the MAX chip. even specced at 10KHz tops, I still got a filter sweep that was adequate for me. I'll have to experiment further. if not the MAX ic, then some other PWM-controlled filter.

say I use a codec ic. they require a clock that's 256 or 512 that of the sameplrate. and since I want a continuously variable samplerate, it must be supplied by the mikro. 44khz * 250 is 11.264MHz, which is impossible for my PIC32. unless I use a PLL (havent played around with those yet) or an external clock generator.

I have options. right now I'm leaning towards voltage controlling a MAX filter or some other kind of filter. the filter sweep doesn't have to be totally accurate or linear. just "good to the ear".
~~~~~~~~~~~~~~~~~~~~~~
{DIY blog}
{www.dronecloud.org}

free electron

Quote from: cloudscapes on March 17, 2012, 02:46:56 PM
The max frequencies I can get with a timer on the mikro is 1.6MHz (tested it this morning). And without a timer, just a pin toggle in a loop, about double that. It's still not enough for a codec, they needs several MHz at least.
http://ww1.microchip.com/downloads/en/DeviceDoc/61106G.pdf
page 6
23.1.3 Audio Protocol Interface Mode
PIC 32 family has already a codec interface built in, it's the SPI working in I2S mode. Since, according to the Table 1:
http://ww1.microchip.com/downloads/en/devicedoc/61168b.pdf  -page 2
all the PIC32 family chips have 2 SPI/I2S modules, you can use one to interface the memory and the 2nd one to communicate with codec.

cloudscapes

Quote from: free electron on March 18, 2012, 04:11:45 AM
http://ww1.microchip.com/downloads/en/DeviceDoc/61106G.pdf
page 6
23.1.3 Audio Protocol Interface Mode
PIC 32 family has already a codec interface built in, it's the SPI working in I2S mode. Since, according to the Table 1:
http://ww1.microchip.com/downloads/en/devicedoc/61168b.pdf  -page 2
all the PIC32 family chips have 2 SPI/I2S modules, you can use one to interface the memory and the 2nd one to communicate with codec.

Yeah I have a couple of those MX2's. Unfortunatelly they'e half the speed of the one I'm currently using, which doesn't have an I2S protocol.  :( I don't have anything to program them with anyway. The one I'm using is a stamp with a USB bootloader already integrated. I'm currently using it because I didn't have to buy an expensive programmer.

Thanks, though!

Ran into another snag. My compiler's on-chip ADC libraries (for pot input) are really slow. I mean really slow. A single 10bit conversion eats up almost half a millisecond. Even the 10bit ADCs on AVRs are 100 times faster (no exaggeration). According to the mikroelectroncia forums, I will have to write my own library for quickness.  My options for pot input are:

1. An external SPI 4-channel ADC. I'd lose a lot of clock cycles.
2. Writing my own custom ADC library in mikroC. Reading about that now.
3. Switch compilers entirely. Wouldnt be the first time I was frusterated by a design decision in this one, but that would mean I wouldnt be able to use these DIP boards anymore.
~~~~~~~~~~~~~~~~~~~~~~
{DIY blog}
{www.dronecloud.org}