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

SpecDrum programming information

Post by pianomatt »

Hi Everyone

I have a Cheetah SpecDrum for my Speccy - basically an 8-bit DAC that works with some software to turn the humble Speccy into a drum machine. I've had a thorough search online and nobody seems to have any information on how these things work or what format the samples are in, so I'm interested to try to find out myself. The ultimate goal is to somehow inject my own samples via the program's ability to load additional kits.

What would be the best way to locate the sample data in memory? The FUSE emulator supports the SpecDrum, so I can emulate it easily.

Any info would be greatly appreciated.
User avatar
djnzx48
Manic Miner
Posts: 729
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: SpecDrum programming information

Post by djnzx48 »

I too would be interested in finding out about this. I'm not familiar with the SpecDrum software, but a first likely step would be to set a breakpoint in the debugger whenever an OUT instruction occurs, and then see if it's loading sample data from somewhere. SpecEmu can do this pretty easily, and Fuse probably can too, but the syntax there is a bit cryptic.
User avatar
djnzx48
Manic Miner
Posts: 729
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: SpecDrum programming information

Post by djnzx48 »

Just found this: the Amdrum. It's apparently a version of the SpecDrum designed for the Amstrad, and they've handily included part of the playback routine. That could help in getting the samples.
User avatar
zxbruno
Manic Miner
Posts: 213
Joined: Sun Mar 04, 2018 6:13 am

Re: SpecDrum programming information

Post by zxbruno »

It may be worth mentioning a very old Speccy.org (translated) topic:

http://tinyurl.com/Specdrum-topic-translated
Alcoholics Anonymous
Microbot
Posts: 194
Joined: Mon Oct 08, 2018 3:36 am

Re: SpecDrum programming information

Post by Alcoholics Anonymous »

It's just 8-bit unsigned samples to port 0xdf.
User avatar
djnzx48
Manic Miner
Posts: 729
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: SpecDrum programming information

Post by djnzx48 »

But the samples themselves are stored as signed. From the playback routine, conversion to unsigned only happens just prior to the output, otherwise the DC offsets would add up and clipping/wraparound would occur.
pianomatt
Drutt
Posts: 21
Joined: Sun May 12, 2019 10:38 pm

Re: SpecDrum programming information

Post by pianomatt »

I've made some slight progress by using the debugger tool in FUSE. By pure chance I found a line of assembly loading something from 0x8400, so I dumped the memory from that location and loaded it as raw sample data into Audacity. The sample rate seems to be around 16kHz, because at that sample rate the drums sound more or less the same as they do coming out of the SpecDrum.

Image

The sample order is Snare, High Tom, Low Tom, Cowbell (more required), Closed Hat, Open Hat, Clap then Kick.

I'm going to assume that the software has a list somewhere of where each sample starts, because the samples aren't of uniform length.
pianomatt
Drutt
Posts: 21
Joined: Sun May 12, 2019 10:38 pm

Re: SpecDrum programming information

Post by pianomatt »

I've found another TZX online with a different kit, and loading that in also saves the samples at 0x8400. The sample boundaries also line up, so maybe they're hard coded?

Image

Are there any tools out there designed to dissect TZX files to see what is going on? I might be able to learn more by looking in the Afro tape, and use it as a blueprint for making my own.
User avatar
djnzx48
Manic Miner
Posts: 729
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: SpecDrum programming information

Post by djnzx48 »

Not sure if it's what you're looking for, but you could try this.

Edit - never mind, I thought you were using Windows. It probably works in Wine anyway.
User avatar
djnzx48
Manic Miner
Posts: 729
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: SpecDrum programming information

Post by djnzx48 »

I tried to have a closer look at the code, but it's just too crazy for me. There's self-modifying code all over the place and it's impossible to tell what's going on. Anyway, I think the main loop starts at $fa00 and it's decrementing some sort of counter, which may be useful to find the sample lengths.
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: 729
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: 2640
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: 729
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: 213
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: 729
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: 700
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: 729
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: 729
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.
Post Reply