Street Fighter 2 - new Z80 PCM sound driver project

For anything related to sound (YM2612, PSG, Z80, PCM...)

Moderator: BigEvilCorporation

User avatar
TmEE co.(TM)
Very interested
Posts: 2296
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Tue Jul 22, 2014 9:05 am

Filter is only useful if you have really high sample rate (beyond 20KHz). You'll only have different noise with low sample rate, and the quantisation noise of 8 bits will overhadow most noise anyway.
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

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

Post by Stef » Wed Jul 23, 2014 8:18 am

gasega68k wrote:This is an interesting project. :)

You think it would be possible to use ADPCM, and also with a simple filter? Because with ADPCM can produce a bit of noise and I think adding a simple filter can remove the noise.
I was thinking about ADPCM but i believe using it at a such low rate (4.77Khz * 2) won't be efficient and the loss will be too important.
As i plan to use the initial rom space with exact same sample location, i believe that using 4 bits PCM (not packed then) would be a better solution than using 4 bits ADPCM...

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

Post by Stef » Mon Aug 11, 2014 3:32 pm

Some news about my project :)
I made the rom modifications to remove "Z80 disable instruction" on DMA and also included the new driver.

Here is a first version which only include the modification to remove the "Z80 disable instruction" on DMA :

https://dl.dropboxusercontent.com/u/933 ... mod_v1.bin

If you try this rom in an emulator (except very accurate ones) you will notice how voices are better now (well as much than 4.8 Khz allow). This is because almost emulator does not emulate the BUS interaction with Z80. On real hardware however it still sounds crappy (maybe a bit less than initially, but still really crap).

Now here is the second modified version :

https://dl.dropboxusercontent.com/u/933 ... mod_v2.bin

This version includes my new sound driver but right now the result is still far from perfect. There are several issues about it :
- The first one, and it is a big one, is the latency issue. Because i'm using 4x256 bytes circular buffer length, everything is timed on this and while it does work quite well for 16 Khz playback, it does not work well for low rate as 4.77 Khz. This comes from the fact that 1 buffer length (16000 Hz / 256) is just below a NTSC frame in term of time (which is perfect), so new command are handled at each frame and usual sound latency is 4 frames which is small enough and not really noticeable. But 4770 Hz / 256 is a bit above 3 frames ! So the latency can be as big as ~14 frames (which is really noticeable).
- Even worse, because of this important latency we can now miss some SFX commands when they are too close (separated by 1, 2 or 3 frames) and it's exactly what happen :-/ Some voices or drums are missing...
- Another problem is that DMA is probably starting a bit too soon and so voices are still not perfect (definitely better but not as good they could be), hopefully i believe only one small DMA retains the bus, the others ones happen in vblank and the driver is protected against them.
- There is also a 'pop' at initialization but hey i don't mind too much about this one right now ;)

I plan to fix the lag issue by shortening buffer (that requires some modifications in the sound driver). Ideally i would have preferred to use higher sample rate but i really want to start with originals samples and having them sounding right ;)
Last edited by Stef on Tue Aug 12, 2014 12:11 am, edited 1 time in total.

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

Post by Chilly Willy » Mon Aug 11, 2014 5:36 pm

How about oversampling? Put each sample in your circular buffer 3X. Not only will that boost the frequency and reduce latency, but will also push the noise beyond the filter cutoff. It should sound better for almost no extra work.

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

Post by Stef » Mon Aug 11, 2014 5:39 pm

What do you mean O_o ? putting each sample 3x will only reduce the latency but not change the output rate at all as i will output 3x the same sample.

TheMole
Newbie
Posts: 3
Joined: Sun May 18, 2014 8:59 pm
Location: Belgium

Post by TheMole » Mon Aug 11, 2014 8:55 pm

Chilly Willy wrote:How about oversampling? Put each sample in your circular buffer 3X. Not only will that boost the frequency and reduce latency, but will also push the noise beyond the filter cutoff. It should sound better for almost no extra work.
I think you mean upsampling instead of oversampling. Oversampling is done at sample creation time, and refers to the process of recording at sample rates that are higher than the Nyquist sample rate for the source material, or in other words higher than 2 times the highest frequency in the audio clip.

Upsampling, on the other hand, is the process of taking a piece of low sample rate source material and "filling in the gaps" by interpolating between the available samples. Software upsampling might give better results than letting the DAC do the upsampling, provided you can implement an algorithm that outperforms the hardware. I don't know the internal details of the Genesis' DAC, but I'm guessing you'd at least need to do linear or even bilinear interpolation between the samples to have something that sounds better instead of the same or worse.

Having said that, it is realistic to assume that doubling or tripling the sample rate by means of (bi-)linear interpolation would indeed improve the perceived playback quality. Anything the hardware does will be generic for a bunch of frequencies, while doubling or tripling is a specific case in which interpolation can be done more efficiently.

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

Post by Chilly Willy » Mon Aug 11, 2014 9:14 pm

Oversampling - it's been used on CD players since 1982 (I bought a CD player in 1982 that used 4X oversampling). The term itself can refer to a few different things, but when used in regards to playing back digital samples, it means playing the same exact sample X number of times in the same period. For example, instead of playing a pair of stereo samples at 44100 Hz, you play the same sample four times in the same period, or an effective sample rate of 176400 Hz. The primary reason to do so is this also pushes the quantization noise up in frequency by the same multiplier. This allows you to use a simpler low-pass filter on the output to remove the noise. Given the same filter on an output (say, the DAC of the FM chip), using a higher sample rate gives more filtering at the same frequency on the output. So using 3X the sample rate should make the noise 3X quieter.

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

Post by Stef » Mon Aug 11, 2014 10:56 pm

I don't know much about the internal DAC filter on YM but given how the YM internally works, writing 3x the same value (let say at 15 Khz for 3x5 Khz) in the DAC register or writing it once at 5 Khz won't make any difference in the final result as the YM will still multiplex the DAC register value for final mixing with other YM channels...
I remember i already tried to "overwrite" the DAC register with same value several time and i could not heard any difference in the output.
Maybe that is not what you are speaking about :?

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

Post by Stef » Mon Aug 11, 2014 11:39 pm

New version :

https://dl.dropboxusercontent.com/u/933 ... mod_v3.bin

I used shorter buffer (64 bytes) and so there is less latency but unfortunately even 3/4 frames is noticeable depending the music (Ruy stage for instance, we immediately heard there is something wrong as beat should be synchronized on FM instruments)... ideally the music should be modified for the driver. Also there is still some missing PCM sfx, when they happen too close to each other, i believe i have something a bit wrong in my driver about priorities, have to check that...

tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

Post by tomaitheous » Mon Aug 11, 2014 11:42 pm

TheMole wrote: Upsampling, on the other hand, is the process of taking a piece of low sample rate source material and "filling in the gaps" by interpolating between the available samples.
From the descriptions I've read of over-sampling, this is exactly what it is. N number of times the output of the source input frequency, interpolation between points.

Though linear interpolation shouldn't have any benefit above 2x, if I'm thinking about this correctly.

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

Post by Chilly Willy » Tue Aug 12, 2014 5:26 am

Stef wrote:I don't know much about the internal DAC filter on YM but given how the YM internally works, writing 3x the same value (let say at 15 Khz for 3x5 Khz) in the DAC register or writing it once at 5 Khz won't make any difference in the final result as the YM will still multiplex the DAC register value for final mixing with other YM channels...
I remember i already tried to "overwrite" the DAC register with same value several time and i could not heard any difference in the output.
Maybe that is not what you are speaking about :?
It is, but you're right - the way the DAC on the YM2612 works, it doesn't change the sample rate on the output. The DAC is always output at the same (fairly high) rate regardless of how often it's updated. So that won't work here. :(

r57shell
Very interested
Posts: 475
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Post by r57shell » Thu Aug 14, 2014 2:34 pm

Where is source of delay?
Are you filling whole buffer before start playing?
Image

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

Post by Stef » Thu Aug 14, 2014 3:43 pm

Chilly Willy> Yeah unfortunately here it does not help at all (tried that when i was doing my first PCM attempt and experienced crappy results :p).
r57shell wrote:Where is source of delay?
Are you filling whole buffer before start playing?
The buffer was just too long, i explained the source of the issue in the post from 11th august. Anyway i was able to resolve it by using shorter buffer. I realize i forgot to update the topic here (as i also have a topic about it on Sega-16) :

Here is a new version :
https://dl.dropboxusercontent.com/u/933 ... mod_v4.bin

The latency is ok now, reduced buffer size to 32 bytes, and write buffer is only separated from read buffer by 2 segments (it was 3 as my circular buffer is 4 segments length). I cannot do any shorter latency else i will start to experience reads over write position in some case... hopefully latency is almost not perceptible now :)
I fixed a minor bug in the priority thing but it did not fixed the missing SFX bug :-/ my Z80 driver does some stuff a bit differently (as the internal counter update), maybe the 68k sound driver was using it for something after all. Also i can really heard that even if samples are far better than in the original game they are still a bit scratchy because of the early DMA. That is something i will try to fix at some point too.

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

Post by Stef » Sun Aug 24, 2014 8:04 pm

Here are version 5 :
https://dl.dropboxusercontent.com/u/...sf2_mod_v5.bin
https://dl.dropboxusercontent.com/u/...5_filtered.bin

One using filtered samples, other using originals ones.

Unfortunately i tested on the real hardware and still there is some missing SFX sometime... I believe it does happen really rarely now but still happen :-/
I really don't see any reasons for that, I am even reading commands several time at each sample during the VBlank... Definitely there is something weird in the sound driver (68k side i mean). What could help me is that have a debugger to spy what does the 68k sound driver in game, what are reads & writes on Z80 memory during a complete frame and at which scanline...


They are based on my second driver, i believe the sample quality is a bit better as i does take care of not using 68k bus even before the V-Int.
We can still hear a bit of distortion (specially on die) but they are caused by the 68k accessing YM for music, i can't do anything for that (sound driver design).

I'm afraid that without better debug tools it will be very difficult for me to understand what the original 68k sound driver does for PCM playback and fix that stupid missing SFX bug :-/

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests