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 »

I've had a pretty productive day and I've managed to bodge something together.

First, the samples are stored as 8-bit signed, as pointed out by a couple of people on here. The sample rate seems to be 20 kHz, not the 16 kHz as I first thought.

There are two fixed lengths for the drums - 3072 and 2048 samples. Both the Afro kit and the stock kit use the following scheme:

Code: Select all

21504 SAMPLES

SAMPLES START AT 33792

START(DEC)	LENGTH (DEC)

0		3072	
3072		3072	
6144		3072	
9216		2048	
11264		2048	
13312		3072	
16384		3072	
19456		2048	
Using the "Import Binary Data" function in FUSE I was able to import a block of data that I'd prepared in Audacity and get it to play those samples. Now all I need to do is find out how the tape loader works so I can make custom kits and save them in a TZX.

It would be really neat if I could release a new SpecDrum kit for the first time in 30 odd years.
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 »

Nice work!

The time period between OUTs is about 173 T-states, which corresponds to a sample rate of approximately 20.231 kHz. Not that bad actually.
pianomatt
Drutt
Posts: 21
Joined: Sun May 12, 2019 10:38 pm

Re: SpecDrum programming information

Post by pianomatt »

Here it is in action

From one bland set of samples to another. If I can get the TZX thing figured out I'll definitely put more effort into picking the sounds.
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2641
Joined: Mon Nov 13, 2017 3:16 pm

Re: SpecDrum programming information

Post by Ast A. Moore »

pianomatt wrote: Mon May 13, 2019 3:00 pm Here it is in action

From one bland set of samples to another.
Some are pretty good, actually. I’d play around with adding more samples of the same drum hit with a different force. You’ll have fewer individual instruments to work with but will avoid the machine-gun effect (somewhat).
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
pianomatt
Drutt
Posts: 21
Joined: Sun May 12, 2019 10:38 pm

Re: SpecDrum programming information

Post by pianomatt »

I've done it!

I managed to get onto a Windows PC and I downloaded ZX-Blockeditor. I loaded up the Afro Kit tzx and it's just two blocks - one with some text and the other with the raw sample data.

The first block must begin with a lower case c and then each drum needs a 7 character name.

I don't think I can attach on this forum, but if anyone wants a copy of what I'm calling the first EVER third party release for the SpecDrum then PM me. It uses samples from my Yamaha VSS-200 and Casio VL-1 toy keyboards.

Image
pianomatt
Drutt
Posts: 21
Joined: Sun May 12, 2019 10:38 pm

Re: SpecDrum programming information

Post by pianomatt »

Found out something else when I tried loading up my custom kit - the order the samples are stored in memory isn't the order they're presented on screen. For some reason they're all offset by one, with the last sample actually being the first on screen. So with the standard kit the kick drum is drum number 1 in software, but it's the 8th sample in memory.
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 »

That looks pretty good. Have you tried recreating Rock-1 yet?
pianomatt
Drutt
Posts: 21
Joined: Sun May 12, 2019 10:38 pm

Re: SpecDrum programming information

Post by pianomatt »

User avatar
zxbruno
Manic Miner
Posts: 214
Joined: Sun Mar 04, 2018 6:13 am

Re: SpecDrum programming information

Post by zxbruno »

At first I thought this topic would be about "exploiting" the SpecDrum to do something it wasn't meant to do (people have used it to play WAV files, for example) but this is quite interesting! For many years I played music on Yamaha Clavinovas and always wondered if the Spectrum (with the proper add-on) could be used to as a drum machine with different styles to choose from. I'm going to keep an eye on this one for sure.

I can't remember if the SpecDrum sofware allows for a rhythm to play on a loop (it's been a while). If it does, it would be wonderful if it had options such as Main A/B, fill-in, fill-in to jump from main A to main B (just like a standard keyboard), and vice-versa. Maybe I'm just hoping for too much.

Meanwhile, I found a link that someone posted years ago but I don't know if it's relevant to this topic. It has the SpecDrum samples available for download:

https://samples.kb6.de/downloads.php
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 »

Heh, I like how they call it the 'Spectrum ZX81' on that page.

Yes, looping rhythms would be cool. It would mainly depend on how many spare T-states can be squeezed out of the player routine. 1K DJ has basic rhythm selection, but no fills. Something more advanced could be done though.

I believe the SpecDrum can also be used as a replacement for the 'Covox' output device, used in a few sample players. It would probably just require a change of port address.

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.
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