Monthly Archives: January 2014

Constructing a sampler, pt. 1

Starting way at the bottom, a digital sampler is basically a computer system with a few basic features:

  • Memory for storing sounds
  • An analogue-to-digital converter for getting sounds from the real world into memory
  • A digital-to-analogue converter for getting sounds from the memory into the real world
  • A method of playing back sound from the memory at will in a musically useful way (ie., triggers, MIDI notes)

(You can of course bypass the ADC and just pre-load the memory with sounds, in which case you get a sample-based synth or ROMpler)

This is very similar to a digital delay or looper such as Clueles, of course, which also stores sounds in memory and plays them back again, only such a system dispenses with the ‘at will’ part and just plays back everything in the order it came in.

If we modify the basic algorithm described in the Clueless document, instead of the simple three-step sequence, we need some state to know if we’re recording, playing back, or not doing anything. Ie.,

repeat: {
  if(RUNNING) {
    if(RECORDING) {
      write(buffer[addr++]);
    }
    else {
      read(buffer[addr++]);
    }
  }
}

This obviously doesn’t have a user interface to change the state so it’s not much fun if you run it on a PC, but if we make an implementation with digital logic, we can implement the state by reading from e.g. a pair of flip-flops controlled by simple buttons. By ANDing the sample clock with the flip-flop which represents the RUNNING variable in the code above, the counters are only incremented when the flip-flop is on, We probably only want to fill or play the buffer once on every trigger, so we connect the overflow from the address counters to the reset of the flipflops, meaning that when we reach the end of the buffer, playback or recording stops. In code, this would mean resetting addr to 0 once it reaches the end of the buffer.


repeat: {
  if(RUNNING) {
    if(RECORDING) {
      write(buffer[addr++]);
    }
    else {
      read(buffer[addr++]);
    }
    if (addr >= LENGTH) {
       addr = 0;
       RUNNING = false;
    }
  }
} 

This sampler has some serious limitations, of course: It can only store one sample and it can only play it back from the very beginning to the very end. A variable clock would allow for simple repitching, much like varying the playback speed on a delay or tape recorder.

The addition of a trigger circuit so you could enable recording but only start it after the input reaches a certain threshold would arguably make it useful for sampling percussive noises. A use case for this is making drums with monophonic synths without using a whole synth for a single drum sound; it’s also possible (and easy) to add battery-backup to SRAM, meaning that you could have non-volatile sample storage.

I’ve attached a schematic sketching the above design, minus this trigger circuit. Note that it is untested not all signals are properly connected and that buttons, clock, analogue circuitry, etc., are not shown. The Clueless schematic is more complete if you want to try to build this, but most things should be obvious.

I’ve used a 112 dual J/K flip-flop for the state, push buttons could obvious be attached more or less directly to this. The ‘112 has two outputs per flip-flop: one that’s high when the flip-flop is on, and one that’s high when it’s off. Since the DAC write strobe is derived from the high-when-on output, we can use the other output for the chip select of the DAC, and conversely for the ADC.

It seems that the sequencing parts of Clueless can be entirely foregone since the DAC and ADC aren’t sharing the memory bus, By NAND’ing the clock with the output from the flip-flops, we offset the sample counting pulse (triggered on a rising edge) and the R/W pulses (falling edge). Once again, this is untested, no fitness implied, etc., etc. Do let me know if you try it, though.

bang02

Advertisements

Clueless delay

Over the past few months, I’ve been improving my non-existent knowledge of electronics through a project I call Clueless. It’s basically a very simple digital delay.

DIY delays seem to fall into two groups: those based on analogue bucket brigade chips, and those based on the PT2399 IC, which was originally meant for karaoke applications but has also found use in a number of guitar pedals and eurorack modules. These both have limitations in terms of delay length and (for the PT2399) the sample rate.

The present design is based on a few chips of 74xx-series logic and an SRAM IC and can scale to ludicrous delay lengths, since simple cascadable counters are used for addressing. The quality is (probably) hampered by the fact that it uses 8-bit DACs and ADCs, but when run at high sample rates it doesn’t seem to exhibit much of the crunchiness normally associated with older designs.

The design is described in further detail at my hackerspace Labitat’s wiki, because that’s where I’ve been working on it. In fact, it’s fair to say that none of what I do with electronics would be possible without Labitat. It’s such a great environment for being creative with technology, and there are so many helpful people. I basically showed up a little over a year ago with the parts for a MIDIBox sequencer and someone there taught me to solder and helped me debug it. If you’re in the Copenhagen area, come down on a tuesday night. Similar places exist all over the world, check out hackerspaces.org to see if there’s one near you. Or support a movement and start one.

I’m already in the process of augmenting the design to make it a one-voice sampler. A digital delay is a sampler that continously records and plays back as it steps through a buffer. Or conversely, a sampler is a delay that steps through a buffer once while recording and then steps through it playing back at request.

The hard part of a sampler implemented in digital logic (well, one of them) is address generation. If you’ve only got one sample at a time and all you want to do is play it back from start to finish, this can be done with counters as in the delay. More features requires more logic, but fortunately there are a few examples in the service manuals of old samplers of how to do this — the earliest Emus, in particular, have very good, thorough service manuals with clear schematics, block diagrammes and sections describing the operation of this part of the circuit. I hope to do more in-depth posts on the SP12(00) and Emulator 1 and 2 in the near future. The ones after those, unfortunately, sealed all this off in custom ICs that also do DSP.

Modern µcs are fast enough to do address generation by bit-banging if they don’t have a proper memory interface. Unfortunately, the through-hole versions generally don’t have enough pins to actually output them in a timely fashion. The Where’s The Party At uses an AVR and some latches to do it. I’ve studied the design more closely, and one thing that struck me is that it runs at a fairly low sampling rate (a maximum of 20khz) and does no filtering of either inputs or outputs. This is why it’s sound is so rough, but is something that could be easily cleaned up. I don’t particularly like the thought of working with somebody else’s 8 bit assembly, but if one used parallel-input DACs and ADCs and never let the data touch the AVR, the latter could be reduced to a pure address generator, which might lead to significant reductions in code complexity (and also free up the data pins, meaning less latches). This deserves to be explored. The ARM-based LPC1114 is also interesting, although the through-hole variant has too few pins.