Iron Maiden chiptune musicdisc + 26 kHz mod/ahx player

Announce (tech) demos or games releases

Moderator: Mask of Destiny

Kabuto
Interested
Posts: 27
Joined: Sun Aug 25, 2013 6:56 pm

Iron Maiden chiptune musicdisc + 26 kHz mod/ahx player

Post by Kabuto » Mon Dec 01, 2014 12:48 am

Grab it here: http://www.pouet.net/prod.php?which=64438

This was just released this weekend, a music disc (or rather: cartridge) full of iron maiden chiptune covers with some nice gfx too.

This features a mod+ahx player, made for this project, which mixes 4 PCM channels with individual volume and playback speeds each at a sample rate of 26 kHz. The little (about 10%) CPU time left is used for a GUI as fancy as possible under these circumstances.

I'm thinking about releasing the player as an open source project as it might be handy for other projects too (e.g. game title screens, or even games if they don't need much CPU time).

Beware that emulators have their bugs; both exodus and regen show bugs at the left edge of the logos (they don't emulate the LCB flag), logo colours are slightly off in regen (S/H implemented incorrectly), and regen's default settings sound horrible too (just enable Sound->SuperHQ, but the music disc warns you about that too if it detects that).

Stef
Very interested
Posts: 2988
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Mon Dec 01, 2014 9:35 am

Hey,

Nice piece ! I tested on Fusion and seems like it does not output anything except noises when playing mod file X'D
Also, how are you actually detecting the sound issue ? I tested on Gens and it always shows the sound warning whatever are the sound settings.

I'm impatient to test that on a real MD though :) Well done !

Kabuto
Interested
Posts: 27
Joined: Sun Aug 25, 2013 6:56 pm

Post by Kabuto » Mon Dec 01, 2014 10:26 am

Thanks :)

I'm detecting it by silently playing a number of samples on the z80 and running a busy loop on the 68k, and then, when the 68k finishes, checking how many samples the z80 could play. Had to add this because it sounded horrible in some emulators (regen with default settings, gens). I have no idea why fusion doesn't have any sound, though, it's like the Z80 just hangs there.

Stef
Very interested
Posts: 2988
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Mon Dec 01, 2014 12:58 pm

Kabuto wrote:Thanks :)

I'm detecting it by silently playing a number of samples on the z80 and running a busy loop on the 68k, and then, when the 68k finishes, checking how many samples the z80 could play. Had to add this because it sounded horrible in some emulators (regen with default settings, gens). I have no idea why fusion doesn't have any sound, though, it's like the Z80 just hangs there.
Oh ok so maybe Gens is just not enough accurate on the Z80 timings.
Still i am surprised as general it gets quite close in sample from what i got on real hardware... Anyway if it works on real hardware then that is the important point, it's just showing emulator flaws ;)

Oh and by the way, 26 Khz for 4 PCM channels with envelop and pitch support is awesome ! Congrats ! Indeed it would be cool to have the sources as it can be really useful for high quality music on intro screen or stuff like that. One more question, is there any limit on sample or mod file ?

Stef
Very interested
Posts: 2988
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Mon Dec 01, 2014 7:07 pm

Just tested on my MD1, sounds perfect :D

Chilly Willy
Very interested
Posts: 2791
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Mon Dec 01, 2014 8:44 pm

Stef wrote:Oh and by the way, 26 Khz for 4 PCM channels with envelop and pitch support is awesome ! Congrats ! Indeed it would be cool to have the sources as it can be really useful for high quality music on intro screen or stuff like that. One more question, is there any limit on sample or mod file ?
Correct me if I'm wrong, but it sounds like the 68000 adds the channels together into one sample stream the Z80 then plays at 26kHz - which is easy for the Z80 to do with a single channel at a set rate. Note how the explanation says that about 90% of the 68000 is used for the player, and 10% for the UI. Doing it that way is not that hard.

Stef
Very interested
Posts: 2988
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Mon Dec 01, 2014 9:44 pm

Chilly Willy wrote:
Stef wrote:Oh and by the way, 26 Khz for 4 PCM channels with envelop and pitch support is awesome ! Congrats ! Indeed it would be cool to have the sources as it can be really useful for high quality music on intro screen or stuff like that. One more question, is there any limit on sample or mod file ?
Correct me if I'm wrong, but it sounds like the 68000 adds the channels together into one sample stream the Z80 then plays at 26kHz - which is easy for the Z80 to do with a single channel at a set rate. Note how the explanation says that about 90% of the 68000 is used for the player, and 10% for the UI. Doing it that way is not that hard.
Yeah i was thinking about it but then, you require to write the buffer in the Z80 memory at some time ? and so you need to interrupt it for a bunch of cycles. Doing that should affect the playback quality from Z80 (or he has to split the transfer in very small portions) and when i tested on my MD the quality was pretty clear.
Also that would require some Z80 / 68000 synchronization to know when Z80 is ready to accept new sample data (but this part is not a big deal).

Oerg866
Very interested
Posts: 211
Joined: Sat Apr 19, 2008 10:58 am
Location: Frankfurt, Germany
Contact:

Post by Oerg866 » Mon Dec 01, 2014 10:26 pm

Chilly Willy wrote:
Stef wrote:Oh and by the way, 26 Khz for 4 PCM channels with envelop and pitch support is awesome ! Congrats ! Indeed it would be cool to have the sources as it can be really useful for high quality music on intro screen or stuff like that. One more question, is there any limit on sample or mod file ?
Correct me if I'm wrong, but it sounds like the 68000 adds the channels together into one sample stream the Z80 then plays at 26kHz - which is easy for the Z80 to do with a single channel at a set rate. Note how the explanation says that about 90% of the 68000 is used for the player, and 10% for the UI. Doing it that way is not that hard.
Well, if it's so easy, why don't you 1-up us? ;)

(friendly reminder that the only other attempt ever to do it was Toy Story's title screen, and the result was rather disastrous)

Also, you're missing the actual decoding of the sound/sample formats in your list there...
Last edited by Oerg866 on Mon Dec 01, 2014 10:31 pm, edited 1 time in total.

Stef
Very interested
Posts: 2988
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Mon Dec 01, 2014 10:30 pm

Indeed the quality in Toy Story is really a level down (16 Khz with very low quality samples).

Kabuto
Interested
Posts: 27
Joined: Sun Aug 25, 2013 6:56 pm

Post by Kabuto » Mon Dec 01, 2014 10:30 pm

Stef: any mod file that plays on amiga should play on MD as well. The mod file format has a limit of 128 KB for samples and 31 samples total.

Chilly Willy: true, that's how it's done, the z80 could never do that on its own... though just start counting cycles, and it won't look that easy any more ;)

Also, the sample buffer holds just 128 samples so very easily underflows at 26 kHz, needs some careful scheduling for all the GUI tasks that are going on (e.g. nearly all animations are done through DMAing since no VRAM is left either). Not to mention the interrupt trouble - interrupts are blocked while a buffer full of samples is being mixed since interrupts happening during any data transfer to Z80 would cause audible glitches. And blocking interrupts just for the length of a transfer was beyond question too, due to the additional cycles that would have eaten. So e.g. the number of samples to be mixed in one go must be carefully chosen to let interrupts happen in time, and there are 2 interrupts every frame (precious vblank time + one mid-frame for scrolling).

Initially I had dithering in my sample player too (can do so with barely any overhead), but then listening tests revealed that the added noise was more annoying than distortion caused by 8 bit downmix, so I removed it again.

Maybe the sample player can use the newly discovered YM register for kind of changing the master volume and lowering the noise level in silent parts that way - the Z80-side code already supports that. Might also play FM instruments but that doesn't really fit well into MOD files ;) (yeah, there was some time left on the Z80 so it's just being used for fetching YM register writes, just there are none right now, as the 68k never writes any).

Anyway, right now I'm going to make this play back mod/ahx files directly - currently they need to be converted to a custom format first.

Stef
Very interested
Posts: 2988
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Mon Dec 01, 2014 10:48 pm

Thanks for the technical informations. So you used a single buffer of 128 samples ? how are you writing to the Z80 buffer ? I guess you write several samples at once (8 ? 16 ?), at least that explain why you can maintain a such good playback quality.
About the volume master trick, it does not work on all MD system, at least i know it produces horrible distorted sounds on my japanese model 1 :-/

Kabuto
Interested
Posts: 27
Joined: Sun Aug 25, 2013 6:56 pm

Post by Kabuto » Mon Dec 01, 2014 10:58 pm

I'm writing 2 samples at once. I mix one sample (-> 16 bits), then use "swap" to shift the word to the upper half of its register, then mix another sample, and then write both at once to z80. I only hog the z80 bus for this short time frame so the z80 code does not get halted for too long which would degrade audio quality (jitter).

Writing this 32 bit value makes the 68k do 2 16 bit writes, but as the z80 bus is only 8 bits wide (and due to the way Sega implemented the bus) each of these 16 bit writes ends up writing just the upper half of the 16 bit value to the z80's RAM. This behaviour is very handy as I basically get a shr #8 for free this way. Though this has the side effect of leaving every 2nd buffer empty in the z80's memory (where register writes can be interleaved into if desired).

Stef
Very interested
Posts: 2988
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Mon Dec 01, 2014 11:15 pm

Oh ok i see ! Yeah the word write in Z80 memory can be handy for that specific operation ;) so basically you just write 2 samples at once, that explain the 'jitter free' playback. One of an old idea i got was to use SRAM inside rom cart (used for game save normally) to communicate with the Z80. It should work as both CPU are able to read and write to this area.

Kabuto
Interested
Posts: 27
Joined: Sun Aug 25, 2013 6:56 pm

Post by Kabuto » Mon Dec 01, 2014 11:28 pm

Haha, this SRAM trick is nice :)

Though there's one caveat: accesses to this area have to use the 68k bus too, and that would halt the Z80 as well during DMA transfers

Stef
Very interested
Posts: 2988
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Mon Dec 01, 2014 11:38 pm

Yeah it does not protect you against DMA but you could eventually recopy the buffer in Z80 memory in your case ;) Initially i wanted to use this area just for communication between Z80 and 68k without interrupting Z80.
Now what i try to do is just minimize communication :p

Post Reply