SpecDrum programming information

The place for codemasters or beginners to talk about programming any language for the Spectrum.
pianomatt
Drutt
Posts: 21
Joined: Sun May 12, 2019 10:38 pm

Re: SpecDrum programming information

Post by pianomatt »

djnzx48 wrote: Tue May 14, 2019 6:58 am
Great sounding samples too. The only thing I noticed was, when certain samples are used together, the resulting volume is too high and there's a bit of wraparound (causing a pop). The workaround would be to lower the volume to a third of the total range, or just avoid having those samples played together.
I noticed that when I played with it last night. The samples need to be compressed ideally, because at the moment they're just normalised to -3dB.

The samples are all quite noisy too because I haven't filtered the high end or dithered them. I'm inclined to just leave them rough because it's hardly a hi-fi device.
User avatar
uglifruit
Manic Miner
Posts: 703
Joined: Thu Jan 17, 2019 12:41 pm
Location: Leicester
Contact:

Re: SpecDrum programming information

Post by uglifruit »

From Simon Goodwin's "Beep To Boom" (excellent) textbook on digital audio.
Might be of some use, and appears to be consistent with what you've found.
The SpecDrum ZX Spectrum add-on was little more than an 8-bit DAC in a box but capable of playing three short percussion samples at a time from a 20K PCM sample buffer with remarkable quality for the time (1985) and price (under £30). It did this by mixing them on the fly in tightly written Z80 machine code and constraining the stored drum sample levels.

Seven bits were reserved for the bass drum and six for the other drums and hi-hat. The 8-bit DAC allowed levels in the range −128 to +127. The 7-bit bass drum used the range −64..+63, and the others were limited to the 6-bit range −32 to +31. This meant that one bass drum and two other samples could be mixed by simple addition and written without distortion to a single 8-bit output. Unsigned samples are harder to mix, as the offset varies with their count, but obsolete PC sound cards tried it.

The seventh bit lets the bass drum be 6 dB louder than the others; this was necessary because of the relative insensitivity of the ear to low frequencies and the importance of the bass beat as a reference for other parts of the rhythm. In theory four 6-bit samples—or even 16 4-bit ones—could be packed the same way if they could all make do with the same dynamic range.

In practice that would have overtaxed the Spectrum’s 8-bit processor, capable of sustaining only about 0.5 8-bit MIPS with luck and a following wind. Mixing three voices in a tight hand-tuned loop took 50 microseconds. Any more and the 3.55-MHz processor would’ve been incapable of maintaining a 20-kHz output rate. Contrast this with the 25,600 MIPS throughput, in 32-bit floating-point format, of a single obsolescent PlayStation 3 (PS3) vector co-processor.
CLEAR 23855
User avatar
djnzx48
Manic Miner
Posts: 730
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: SpecDrum programming information

Post by djnzx48 »

Ah, so that explains why the bass drum gets a channel to itself. Unsigned sample mixing isn't that much harder to do - if you store the samples as full range (0 - 255) you can use RRA after each addition to halve the resulting volume and get back the normal DC offset. This does mean that if there's no sample playing, you should have a $80 value on that channel or you'll get pops.

IIRC the main performance impact for the SpecDrum routine is having to constantly switch registers with EXX and EX DE, HL to deal with sample addresses. If there were only two channels this would be a lot faster - something like:

Code: Select all

ld a, (de)
add a, (hl)
inc de
inc hl
add a, $80
out ($df), a
Only 40 T-states per sample (not counting all the extra loop management stuff). And it could be made even faster by changing the increments to 8-bit incs, only using 16-bit ones when necessary. Of course, increasing the sample rate also implies larger samples, but using a 128+bank switching would make this less of an issue.
pianomatt
Drutt
Posts: 21
Joined: Sun May 12, 2019 10:38 pm

Re: SpecDrum programming information

Post by pianomatt »

I'll have to have a look, but by "6-bit" I think they mean that the samples are limited to the lower 6 bits but are stored as bytes. Otherwise the samples wouldn't be so easily interpreted when importing them into audacity.
User avatar
djnzx48
Manic Miner
Posts: 730
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: SpecDrum programming information

Post by djnzx48 »

Yeah, that's what I took it to mean. The 6 and 7 bit samples are only conventions from the program, not an actual restriction imposed by the hardware.
User avatar
uglifruit
Manic Miner
Posts: 703
Joined: Thu Jan 17, 2019 12:41 pm
Location: Leicester
Contact:

Re: SpecDrum programming information

Post by uglifruit »

That'd make sense (lower 6 bits of a byte, but being stored as bytes). So the ideal workflow would be making new samples for encoding, then dithering to 6bits (or 7bits in the case of kick drum), then padding to 8bits. (I'm not sure what audio software can dither to arbritrary bit depths, but presumably it's possible with something).
CLEAR 23855
User avatar
djnzx48
Manic Miner
Posts: 730
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: SpecDrum programming information

Post by djnzx48 »

There are a few bitcrusher plugins that support arbitrary bit depths with dithering. But it wouldn't be necessary here - the samples are still 8-bit, they just have their volume levels reduced. All it would require is normalising the sample to -6dB or -12dB before exporting to 8-bit.
pianomatt
Drutt
Posts: 21
Joined: Sun May 12, 2019 10:38 pm

Re: SpecDrum programming information

Post by pianomatt »

So looking at the samples in a hex editor it doesn't look like the samples are limited to a 6 bit or 7 bit range. The highest peak I could see in the clap sample was -49, but the kick peaks at -51. 7 bit unsigned is -64 to 63, so while the kick is in range the clap is not - and the snare isn't far off either by the looks of things. I wonder where the author got his information?
pianomatt
Drutt
Posts: 21
Joined: Sun May 12, 2019 10:38 pm

Re: SpecDrum programming information

Post by pianomatt »

I've done a bit of a write-up on my blog of what I did and how I did it, and there are links at the bottom to the TZX and the raw blocks it contains in case anyone wants to use them as a template to make their own.

Loading your own samples into the Cheetah SpecDrum
User avatar
djnzx48
Manic Miner
Posts: 730
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: SpecDrum programming information

Post by djnzx48 »

Hmm, very interesting! You're right, I can't find any other sources mentioning the samples being only 6 bit. I'll have another look at those samples.
pianomatt
Drutt
Posts: 21
Joined: Sun May 12, 2019 10:38 pm

Re: SpecDrum programming information

Post by pianomatt »

I've emailed the author to ask how he got those numbers. If he replies I'll follow up here.
User avatar
uglifruit
Manic Miner
Posts: 703
Joined: Thu Jan 17, 2019 12:41 pm
Location: Leicester
Contact:

Re: SpecDrum programming information

Post by uglifruit »

I've checked his book, but that chapter doesn't seem to have any obvious references to say where that info came from.
CLEAR 23855
pianomatt
Drutt
Posts: 21
Joined: Sun May 12, 2019 10:38 pm

Re: SpecDrum programming information

Post by pianomatt »

It might be from a magazine at the time, maybe misremembered? Then again he might mean something completely different. Either way I'm interested to hear from him because on his website he talks about using the SpecDrum in the early 90s for some demos.
pianomatt
Drutt
Posts: 21
Joined: Sun May 12, 2019 10:38 pm

Re: SpecDrum programming information

Post by pianomatt »

I got a reply from Simon Goodwin, and I'll post more details once I get a chance to reply to him.

Long story short - the 7 bit kick and 6 bit samples isn't entirely accurate, but it is an ideal way of handling the samples because if you keep the volume lower on the other two groups it means you can have a nice loud kick that will cut through the mix without clipping or rolling over.

Also, I made another kit - this time it's an 808.

Demo
Kit TZX
Song TZX
matalog
Drutt
Posts: 4
Joined: Wed Jan 15, 2020 7:21 pm

Re: SpecDrum programming information

Post by matalog »

I took an interest in the Specdrum a few years ago and made my own beatboxing Specdrum kit. I got all of the information I needed from Crash magazines, written by Simon back in the day. I got in touch with him and he sent me some related software to backup.

Out of interest, have you seen the Specdrum System II tape software? It allows proper live playing of all drums at one time, with 8 keys. It adds a slightly different twist to the Specdrum.

Yeah, the drums are basically suitable volumes to be played in their allowed combinations. Looking at the figures in the original samples hex, the range goes from around -50 to +50, with the bass not being much louder than the rest of them to be honest.

Are you still using your Specdrum?

Have you seen this http://www.thesadsongco.com/blog.php?blog_id=18 Search for Specdrum in the blog page.
Post Reply