SpecDrum programming information

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

Re: SpecDrum programming information

Post by pianomatt » Tue May 14, 2019 8:39 am

djnzx48 wrote:
Tue May 14, 2019 5: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.
0 x

uglifruit
Berk
Posts: 13
Joined: Thu Jan 17, 2019 12:41 pm
Location: Leicester
Contact:

Re: SpecDrum programming information

Post by uglifruit » Wed May 15, 2019 12:29 pm

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.
1 x
CLEAR 23855

User avatar
djnzx48
Manic Miner
Posts: 398
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: SpecDrum programming information

Post by djnzx48 » Thu May 16, 2019 12:32 am

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

pianomatt
Berk
Posts: 15
Joined: Sun May 12, 2019 9:38 pm

Re: SpecDrum programming information

Post by pianomatt » Thu May 16, 2019 5:35 pm

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

User avatar
djnzx48
Manic Miner
Posts: 398
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: SpecDrum programming information

Post by djnzx48 » Thu May 16, 2019 9:43 pm

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

uglifruit
Berk
Posts: 13
Joined: Thu Jan 17, 2019 12:41 pm
Location: Leicester
Contact:

Re: SpecDrum programming information

Post by uglifruit » Thu May 16, 2019 10:14 pm

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).
0 x
CLEAR 23855

User avatar
djnzx48
Manic Miner
Posts: 398
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: SpecDrum programming information

Post by djnzx48 » Thu May 16, 2019 11:51 pm

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

pianomatt
Berk
Posts: 15
Joined: Sun May 12, 2019 9:38 pm

Re: SpecDrum programming information

Post by pianomatt » Fri May 17, 2019 10:44 pm

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?
0 x

pianomatt
Berk
Posts: 15
Joined: Sun May 12, 2019 9:38 pm

Re: SpecDrum programming information

Post by pianomatt » Sat May 18, 2019 12:41 am

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
1 x

User avatar
djnzx48
Manic Miner
Posts: 398
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: SpecDrum programming information

Post by djnzx48 » Sat May 18, 2019 3:24 am

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

Post Reply