A Spectrum PCM player...

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
TMD2003
Rick Dangerous
Posts: 2045
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

A Spectrum PCM player...

Post by TMD2003 »

...is there such a thing?

To achieve something that I have planned for the CSSCGC (though maybe for next year - don't get too excited, @Jbizzel...), I may need to be able to play back a PCM sample, either through the beeper or via the AY chip - thus also giving me the option to do it on the Next as well, and avoid using a dot command that CSpect can't handle, and a lot of extra strife besides. With the Next also in my thoughts, the only restriction is that both the sound sample and the player need to fit into 16K, i.e. a single Next bank.

It must be possible, if @PROSM can fit a sample about a second long of Rick Gervais' laugh and a through-the-MIC playback routine and a very rudimentary game into a single K and do so on a ZX80. Recording the PCM sample and compressing it to the required size shouldn't be a problem, I can do that with Audacity; mono, 8-bit unsigned, probably 11 kHz sampling rate at most, job (should be) done.

Although I can already see a problem with having to convert it into a pure square wave first... again, if that's possible.
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
User avatar
PROSM
Manic Miner
Posts: 476
Joined: Fri Nov 17, 2017 7:18 pm
Location: Sunderland, England
Contact:

Re: A Spectrum PCM player...

Post by PROSM »

Yes, there are several tools to do it on both the beeper and the AY, though I am only familiar with a couple of the beeper tools, namely BeepFX and pcm2pwm. There's more information on both in this thread: viewtopic.php?p=74184
All software to-date
Working on something, as always.
User avatar
TMD2003
Rick Dangerous
Posts: 2045
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: A Spectrum PCM player...

Post by TMD2003 »

Well, BeepFX is certainly getting there... and the sample is "only" 8K even if I'm using a 44 kHz sample rate. Down-converted to 1-bit, it doesn't sound like a complete trainwreck so I'm considering that a win.
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: A Spectrum PCM player...

Post by Jbizzel »

I used beep FX for Speccy and spell my speak and spell simulator.

Very good tool!
User avatar
TMD2003
Rick Dangerous
Posts: 2045
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: A Spectrum PCM player...

Post by TMD2003 »

As per alternative tools, I don't suppose there's anyone who knows what Odin Computer Graphics used for the speech in Robin Of The Wood? I can also see the advantages of a sound sample that's recorded directly by the Spectrum, and I'd assume they did it that way.
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
User avatar
Guesser
Manic Miner
Posts: 641
Joined: Wed Nov 15, 2017 2:35 pm
Contact:

Re: A Spectrum PCM player...

Post by Guesser »

Gasman released one many years ago (used for speech samples in his game Celebrity Arses iirc) that I think he called "samplepack". Later someone else made a windows exe (wav2ay?) to do the conversion instead of using Matt's original perl script.

It generates correctly weighted 4-bit samples for the AY at around 11000 kHz I think.
I (ab)used it for my streaming jukebox on Spectranet :)

C.Born
Manic Miner
Posts: 232
Joined: Sat Dec 09, 2017 4:09 pm

Re: A Spectrum PCM player...

Post by C.Born »

User avatar
Seven.FFF
Manic Miner
Posts: 744
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: A Spectrum PCM player...

Post by Seven.FFF »

Dot commands work just fine in CSpect. In fact I use CSpect to write and debug them. I suppose you mean that you don't want to use dot commands because you want to package your program as a single file .TAP or .NEX that can be passed on the CSpect command line - emulator-first coding rather than machine-first.

The Next has four 8bit PCM channels, which you can play in a stereo or mono configuration. Sample rates can be anything you like, at least up to 48KHz stereo, and I'm sure beyond too. The simplest program (and one quite suitable for a crap games competition) would be:

Code: Select all

10 .playway MyFile.wav
If you don't want to use the dot command for above reasons, you can incorporate the .playwav code directly. https://github.com/em00k/zxnext-playwavdma. It's opensource with MIT license.

Note that playwav only supports a small number of sample rates. You can get more creative with your own code, of course.

For custom code I usually use sox to generate raw 8bit samples at my chosen samplerate, without needing to deal with WAV file headers.

Samples are typically played back on the Next in one of three ways. I mention them here briefly just to give you ideas, or for other people reading the topic.

DMA: The Next has a DMA chip based on the official Zilog one, and can very easily OUT a large block of data to the mono DACport. Burst mode is designed specifcally for PCM audio, as it can output one sample every n milliseconds.

Copper: The next has an Amiga-style copper which can run programs timed to particular screen pixels or lines. Output is always to nextregs, and the DACs have a full set of nextregs mapped. Sample rate can be pretty much arbitrary, depending on which how many pixels you wait for before outputting the next sample.

CTC: The Next has a CTC chip based on the official Zilog one, and can run timers with arbitrary absolute periods. Timers can generate interrupts when they fire, and the Next can have multiple interrupt service routines, each one specific to a particular interrupt source.

And of course you can also use standard Speccy techniques for sample playback using AY or beeper, as answered already in this thread.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
TMD2003
Rick Dangerous
Posts: 2045
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: A Spectrum PCM player...

Post by TMD2003 »

Seven.FFF wrote: Mon Aug 07, 2023 4:26 pm Dot commands work just fine in CSpect. In fact I use CSpect to write and debug them. I suppose you mean that you don't want to use dot commands because you want to package your program as a single file .TAP or .NEX that can be passed on the CSpect command line - emulator-first coding rather than machine-first.
.playwav didn't work for me, and that was what I'd been basing my original idea on. Others like .txt2bas, .bas2txt and .mem are fine. But if I find one that's a problem on CSpect, I will avoid it. I've yet to try packaging .NEX files - though I can see why they're useful, as the last Next entry I put to the CSSCGC was a whole package of BASIC, machine code, layer 2 screens and a handful of character arrays - all of which would have been contained as a single tape or disc file on the Spectrum.

WAV2AY is going to be my next conversion effort. I could live with the output of BeepFX, but this sounds like it could and should be better. Or at least less eardrum-scrape-o-phonic...
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
User avatar
Seven.FFF
Manic Miner
Posts: 744
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: A Spectrum PCM player...

Post by Seven.FFF »

TMD2003 wrote: Mon Aug 07, 2023 6:39 pm .playwav didn't work for me, and that was what I'd been basing my original idea on.
Right, CSpect has some known DMA bugs. It's also possible you generated your WAV with some bad parameters. Audacity export is not the best. I exported a sample 11.025KHz mono file as 8bit unsigned WAV, and it actually outputted 44.1KHz. Sox is much more controllable.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
Post Reply