Iron Maiden chiptune musicdisc + 26 kHz mod/ahx player
Moderator: Mask of Destiny
Iron Maiden chiptune musicdisc + 26 kHz mod/ahx player
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).
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).
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
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 !
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 !
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.
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.
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Oh ok so maybe Gens is just not enough accurate on the Z80 timings.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.
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 ?
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
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 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 ?
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
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.Chilly Willy wrote: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 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 ?
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).
-
- Very interested
- Posts: 211
- Joined: Sat Apr 19, 2008 10:58 am
- Location: Frankfurt, Germany
- Contact:
Well, if it's so easy, why don't you 1-up us?Chilly Willy wrote: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 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 ?
(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: 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.
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.
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
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 :-/
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 :-/
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).
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).
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
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.