MOD/S3M player for the MD
Moderator: BigEvilCorporation
-
- Very interested
- Posts: 256
- Joined: Tue Sep 11, 2007 9:10 pm
MOD/S3M player for the MD
I'm in the process if writing a mod player for another console and was wondering if anyone has written one for the MD?
I was think about how you'd go about writing the main PCM driver that all the channels would be mixed into. Can you generate an HINT for every scanline or are you just limited to active display?
Also, if the z80 is running in its own work ram instead of mapped memory from the 68k address range, you could have it stream from a 256 sample buffer so the PSG unit using PWM method for a single frame, with the main CPU or DMA stalling the z80 - right?
If so, the S3M format would be a great option for the MD. It had up to 16 sampled channels and 14 FM channels for the format (not that you could use that many channels for a MD setup). MOD+FM would be a killer combo.
I was think about how you'd go about writing the main PCM driver that all the channels would be mixed into. Can you generate an HINT for every scanline or are you just limited to active display?
Also, if the z80 is running in its own work ram instead of mapped memory from the 68k address range, you could have it stream from a 256 sample buffer so the PSG unit using PWM method for a single frame, with the main CPU or DMA stalling the z80 - right?
If so, the S3M format would be a great option for the MD. It had up to 16 sampled channels and 14 FM channels for the format (not that you could use that many channels for a MD setup). MOD+FM would be a killer combo.
It would be great option to waste all MD resources to get very crappy digital sound. If you'll use DAC mode of YM2612 for output, you'll get 16 4-bit sampled channels and no FM channels because S3M FM part designed for OPL2, not OPN.
Btw, I'd say it's very bad idea to use general-use formats for projects on retro systems, because it's just waste of resources. You always can rearrange data on project compilation stage for more effective use.
It's easily understandable why you must use general-use formats for things like editors or players, but there is absolutely no reason to use it for games etc (where user can't change this data).
Btw, I'd say it's very bad idea to use general-use formats for projects on retro systems, because it's just waste of resources. You always can rearrange data on project compilation stage for more effective use.
It's easily understandable why you must use general-use formats for things like editors or players, but there is absolutely no reason to use it for games etc (where user can't change this data).
-
- Very interested
- Posts: 256
- Joined: Tue Sep 11, 2007 9:10 pm
How do you figure? 15khz 8bit MOD player is hardly crappy digital sound. FM is limiting in that in it's repetitive use of the same sounds/instruments gets "old". It's great if you *want* that classic sound, and not so great if you don't or want something new. Wave table synth offers that freedom.Shiru wrote:It would be great option to waste all MD resources to get very crappy digital sound.
My approach is to use 4 channels for digital sampling/instruments mixed into a single 8bit mono stream. I don't think you really need more than that if you have FM channels for instruments as well, assuming you want to go that route.
The Z80 can output an 8bit streamed sample at atleast 15khz via PWM, with no interruption from the from the VDP DMA or tight loops stalls on the 68k side. The tricky side would synchronizing the z80 to copy 256bytes into work ram (during active display to avoid DVP DMA halts), while still continuing to play samples from the previous frame buffer.
If you were to use the z80 to output to the YM2612 DAC instead, then you'd loose 68k to VDP DMA and resort to slower loop write method. But it's still an option.
Either way, having the z80 feed a DAC is like having a free self feeding DAC. All sample mixing would have to be down on the 68k side, of course.
When I say MOD, I mean more as in a generic term. You'd want better then the original MOD format had. Support for ADSR, frequency envelopes, LFO, ping-pong and other looping for an instruments.
At the very least you want a two channel setup for things the MD was weak in - drums, snare, hi-hat, distorted electric guitar, etc. Though a 4 channel would lend it self for some nice string instruments like the SNES FF series did.
I wrote simple 4-ch sample player for SMD; I listen many (almost all which exists) digital players for ZX Spectrum (~10-20 Khz, 3-4ch, 8-10bit); I listen HardWareMan's try of implementation of MOD player on SMD. I prefer FM rather than digital with such quality.tomaitheous wrote:How do you figure? 15khz 8bit MOD player is hardly crappy digital sound.
Anyway, if you want, you can try to implement player which you describe. Who knows, maybe you'll get better results.
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
The DAC on the ym2612 is 8 bits. If you add channels so that they don't clip, that reduces the resolution by log2(# channels added together). As you mentioned, S3M uses 16 digital channels, so that means each channel can only be 4 bits to avoid saturation when you add then together.
That's the conventional way to mix audio. I mentioned another a while back. If you have all the channels running at the same sample rate, you can interleave the channels. While that avoids loss of resolution, it requires you to play the samples at N times the sample rate, where N is the number of interleaved channels. There's always some kind of trade off when mixing audio. It's best if you have multiple channels so you don't have to mix.
That's the conventional way to mix audio. I mentioned another a while back. If you have all the channels running at the same sample rate, you can interleave the channels. While that avoids loss of resolution, it requires you to play the samples at N times the sample rate, where N is the number of interleaved channels. There's always some kind of trade off when mixing audio. It's best if you have multiple channels so you don't have to mix.
-
- Very interested
- Posts: 2440
- Joined: Tue Dec 05, 2006 1:37 pm
- Location: Estonia, Rapla City
- Contact:
Getting 4ch mixed together gives you rather quiet sound, and 6-bit samples don't sound very good anymore. I would have gladly added 4ch to my MD sound engine, but things I mentioned kept me form doing them.
Mida sa loed ? Nagunii aru ei saa
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
-
- Very interested
- Posts: 256
- Joined: Tue Sep 11, 2007 9:10 pm
Oh, but I wasn't suggesting using all 16 sample channels - just four. Also, why would you limit to 4bit per channel for 16 channels? If all 16 channels hit max amplitude (all the same postive or negative amplitude), you'd be able to use 5bit channels without clipping. I'd use 6bit anyway. It's not like you're going to constantly run into max signed amplitude on all channels.Chilly Willy wrote:The DAC on the ym2612 is 8 bits. If you add channels so that they don't clip, that reduces the resolution by log2(# channels added together). As you mentioned, S3M uses 16 digital channels, so that means each channel can only be 4 bits to avoid saturation when you add then together."
Yeah, that's a pretty cool trick.That's the conventional way to mix audio. I mentioned another a while back. If you have all the channels running at the same sample rate, you can interleave the channels. While that avoids loss of resolution, it requires you to play the samples at N times the sample rate, where N is the number of interleaved channels. There's always some kind of trade off when mixing audio. It's best if you have multiple channels so you don't have to mix.
What about using the amplitude add method? Since the z80 can drive both the DAC and the PWM channel. You'd have to be able to output the one of the channels at half the volume of the other, increasing the total sample stream output.
BTW, I have no idea how much resource it takes to use the PWM method for the z80 method, but if you did use the combined amplitude method you could probably lessen up the sample rate on the PWM side.
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
Four bits gives a value of 0 to 15. The maximum value for 8 bits is 255, so you could add (255/15) 17 channels of 4 bits without clipping. Five bits gives values of 0 to 31, and therefore you can only add (255/31) 8 channels of 5 bits without clipping. It's true that most of the time, the samples will not be a maximum all at the same time, but they COULD. You could probably add 16 five bit channels together with no noticeable clipping. Decreasing the number of channels you add together would allow you to increase the resolution.
I'm not sure I'd try using the PWM trick to increase the resolution. I'd instead use it for other channels - in particular, the drum track, as percussion instruments don't need to be as high a resolution to sound right. If I remember correctly, the PWM trick doesn't give a very good resolution (it's equivalent to only 4 or 5 bits from one source I read).
I'm not sure I'd try using the PWM trick to increase the resolution. I'd instead use it for other channels - in particular, the drum track, as percussion instruments don't need to be as high a resolution to sound right. If I remember correctly, the PWM trick doesn't give a very good resolution (it's equivalent to only 4 or 5 bits from one source I read).
-
- Very interested
- Posts: 256
- Joined: Tue Sep 11, 2007 9:10 pm
Opps. I was mixing my unsigned and signed targets there. I was measuring samples in signed notation for amplitude and DAC output in unsigned, thinking 255 was the signed ceiling instead of 127.Chilly Willy wrote:Four bits gives a value of 0 to 15. The maximum value for 8 bits is 255, so you could add (255/15) 17 channels of 4 bits without clipping. Five bits gives values of 0 to 31, and therefore you can only add (255/31) 8 channels of 5 bits without clipping. It's true that most of the time, the samples will not be a maximum all at the same time, but they COULD. You could probably add 16 five bit channels together with no noticeable clipping. Decreasing the number of channels you add together would allow you to increase the resolution.
5bit PWM would good enough to combine the channels. 10bit audio is decent for 4 channel waveform and maybe the occasional digitized sound effect mixed into the final stream.If I remember correctly, the PWM trick doesn't give a very good resolution (it's equivalent to only 4 or 5 bits from one source I read).
Clipping is always noticeable if not handled, because in that case output volume jumps from ~max to ~min (or vice versa). To make it not very noticeable it must be handled, i.e. if there was overflow after addition, output value must be corrected (>255 = 255; <0 = 0). But it can helps only if clipping occurs rarely and by short 'peaks' only. That correction takes time, so I think it's better to prevent any clipping at all.Chilly Willy wrote:with no noticeable clipping
-
- Very interested
- Posts: 256
- Joined: Tue Sep 11, 2007 9:10 pm
Yeah, but clipping on a single sample of the total output stream is not noticable unless you're running some seriously low sample rates. Newer professionally mastered CD's even have clipping. Few samples are prone to cause ceiling or clipping like loud low hz bass samples. But if that was/is the case, you can always move that ghetto bass over to the FM sideShiru wrote:Clipping is always noticeable if not handled, because in that case output volume jumps from ~max to ~min (or vice versa). To make it not very noticeable it must be handled, i.e. if there was overflow after addition, output value must be corrected (>255 = 255; <0 = 0). But it can helps only if clipping occurs rarely and by short 'peaks' only. That correction takes time, so I think it's better to prevent any clipping at all.Chilly Willy wrote:with no noticeable clipping
-
- Very interested
- Posts: 256
- Joined: Tue Sep 11, 2007 9:10 pm
Maybe you misunderstand. When I said a single sample clipping, I mean one 8bit sample of the total mixed output stream, not an a whole instrument clipping. If you had 3 sample bytes randomly clip per frame (1/60 or every 262 bytes), at 15.7khz that would be less than 1%. You think you're going to hear that? I don't have statistics, but my gut assumption is that up 5% clipping per second(not sequential clipped bytes) is more than likely unnoticeable. But I guess we'll see.Shiru wrote:Did you tested how much it's 'not noticeable' in any audio editor (especially for looped part of instrument), or just assumes that?
Hmm, maybe I'll add support for keeping track of clipping occurrence and have it display in realtime on the screen - the number of samples bytes clipped per frame, per second, and the largest sequential clipping run per second.
I'm pretty sure that I can hear one wrong sample (yes, just one byte or word) of mixed stream, if it broke waveform, i.e. if it's actual clipping (not limiting). If you'll do limiting, i.e. handle clipping as I said above - yes, it will be not so easy to hear. But it can't be measured in % of clipped (limited) samples per second, because it very depends from depth of clipping, big depth broke waveform too.
To clarify that I'm talking about: clipping itself is 254+4=2. Clipping with limiting is 254+4=255.
To clarify that I'm talking about: clipping itself is 254+4=2. Clipping with limiting is 254+4=255.
-
- Very interested
- Posts: 256
- Joined: Tue Sep 11, 2007 9:10 pm
Ohhh. I guess we're using different terms. Yes, I'm referring to clipping as you are to "limiting". Yeah, a if the sample value were to roll over without correction, it would be noticeable.Shiru wrote:I'm pretty sure that I can hear one wrong sample (yes, just one byte or word) of mixed stream, if it broke waveform, i.e. if it's actual clipping (not limiting). If you'll do limiting, i.e. handle clipping as I said above - yes, it will be not so easy to hear. But it can't be measured in % of clipped (limited) samples per second, because it very depends from depth of clipping, big depth broke waveform too.
To clarify that I'm talking about: clipping itself is 254+4=2. Clipping with limiting is 254+4=255.