how can i do music on megadrive?

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

Moderator: BigEvilCorporation

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

Post by TmEE co.(TM) » Wed Jan 24, 2007 7:37 am

Z80 is there for SMS compatibility thats why YM2612 int is not connected.
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

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

Post by Stef » Sun Jan 28, 2007 12:07 pm

Fonzie wrote: :arrow: I have another question :)
I tried to make a DAC player that use 4bit samples. So i took a 8bit .wav sample and removed the lower 4bits (set to 0) and i get... a background "CHHHHHH" over my sample. I don't think it is normal, or i misunderstood something about 4bit samples?

:arrow: I also played with downsampling 8bit samples... to 16 11 8 4 2 1khz... And i noticed that, on my computer sound cart, the samples don't get grainy at all... It just get woofed (loosing details)... On megadrive, a 1khz sample would sound horrible, what does my soundcart do to avoid that?
I've exactly the same problem with 4 bits sample. I did my own converter and tried several method but i can't get a decent sound. It's heavily distorted compared to the original 8 bits sample. 4 bits is anyway very bad quality but i guess that a simple "remove 4 lower bits" isn't enough to convert correctly a 8 bits to a 4 bits sample. Some sort of noise filter and roundind process should be used. I searched for a 8 bits to 4 bits audio converter but i can't find something which give acceptable result :-/

About the downsampling, your sound card probably apply a soft of filter.

Fonzie
Genny lover
Posts: 323
Joined: Tue Aug 29, 2006 11:17 am
Contact:

Post by Fonzie » Sun Jan 28, 2007 12:48 pm

Nice you got same problem (in some ways lol)
I had GTA3 and all musics on the disc were 4bit/44khz and sounded great... So i suspect there is a way to remove the CHHHHH.

We need a music expert :)

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

Post by Stef » Sun Jan 28, 2007 9:47 pm

Are you sure about the GTA3 music in 4 bits ?
Maybe you mistake with the MS ADPCM 4 bits or other 4 bits audio format which use some compression method.
Pure 4 bits PCM can't be "good quality" bt at least it can be acceptable.
I did more tests, i now get better result but still dispointting.
I first work with a 16 Khz 8 bits sample. I apply a dynamic gain to egalize then i apply normalization to use the best we can the total 0-255 range.
After that i do my 4 bits conversion with rounding method (not only removing the lower 4 bits). The result is better but i still get a "SHHHHH" in the sample. I think we need a complex algorythme to do smart and good 4 bits conversion. Unfortunatly i'm not a sound expert :-/

Fonzie
Genny lover
Posts: 323
Joined: Tue Aug 29, 2006 11:17 am
Contact:

Post by Fonzie » Sun Jan 28, 2007 10:01 pm

I see... Maybe it was 4bit adpcm... I cannot check since it was rented game...

If i remember correctly, the 32x documentation mentions that GEMS3.0 supports "Delta 4bit" DAC... I suspect it is a sort of adpcm-looking format specialy designed for the z80.

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

Post by TmEE co.(TM) » Mon Jan 29, 2007 6:32 am

Audio converter in QB, converts ordinary 8-bit PCM wav to 4-bit PCM:

Code: Select all

open "wavfile.wav" for binary as #1    'open source file
open "convert.4bt" for binary as #2    'destination file
Lenght&=(lof(1)-58)\2                  'get the lenght - header
seek #1, 58                            'skip header
for i& = 0 to Lenght&                  'loop until all data processed
n1%=((asc(input$(#1,1)) and &Hf0) \ 16 'get a nibble
n2%=((asc(input$(#1,1)) and &Hf0)      'and another
b$=chr$(n1% or n2%)                    'make them one byte
put #2,,b$                             'write it
next i&                                'and start all over again
close                                  'close open files
it is slow but makes the converison (well, not to wav)
Last edited by TmEE co.(TM) on Wed Jan 31, 2007 8:27 am, edited 5 times in total.
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

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

Post by Stef » Mon Jan 29, 2007 10:05 am

Fonzie wrote:I see... Maybe it was 4bit adpcm... I cannot check since it was rented game...

If i remember correctly, the 32x documentation mentions that GEMS3.0 supports "Delta 4bit" DAC... I suspect it is a sort of adpcm-looking format specialy designed for the z80.
Delta 4 bits is exactly the ADPCM 4 bits stuff. As far i can understand it, instead of coding the height of the sample, we code the delta. But the final output must be done in a 8 bits DAC

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

Post by Stef » Mon Jan 29, 2007 10:06 am

TmEE co.(TM) wrote:Audio converter in QB, converts ordinary 8-bit PCM wav to 4-bit PCM:

Code: Select all

open "wavfile.wav" for binary as #1    'open source file
open "convert.4bt" for binary as #2    'destination file
Lenght&=lof(1)-58                      'get the lenght - header
seek #1, 58                            'skip header
for i& = 0 to Lenght&                  'loop until all data processed
n1%=((asc(input$(#1,1)) and &Hf0) \ 16 'get a nibble
n2%=(asc(input$(#1,1)) and &Hf0        'and another
b$=chr$(n1% or n2%)                    'make them one byte
put #1,,b$                             'write it
next i&                                'and start all over again
close                                  'close open files
it is slow but makes the converison (well, not to wav)
I done almost the same stuff, but in Delphi ;)

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

Post by TmEE co.(TM) » Mon Jan 29, 2007 1:49 pm

oops, there were some inaccuracies in my code (well, I wrote it by heart and with winter gloves(don't ask why :wink: )), I fixed the code. As far as i know, DPCM is just delta and ADPCM is delta which can change a little. DPCM would be much simpler to decode than ADPCM. still, you need to be a wizard to get decent sampling rate with Z80.
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

Mask of Destiny
Very interested
Posts: 615
Joined: Thu Nov 30, 2006 6:30 am

Post by Mask of Destiny » Wed Jan 31, 2007 5:27 am

Stef wrote:
Fonzie wrote:I see... Maybe it was 4bit adpcm... I cannot check since it was rented game...

If i remember correctly, the 32x documentation mentions that GEMS3.0 supports "Delta 4bit" DAC... I suspect it is a sort of adpcm-looking format specialy designed for the z80.
Delta 4 bits is exactly the ADPCM 4 bits stuff. As far i can understand it, instead of coding the height of the sample, we code the delta. But the final output must be done in a 8 bits DAC
Technically basic 4-bit delta PCM is just DPCM, ADPCM is slightly more sophisticated in that the compressor and decompressor try to predict the next value and a small delta value is provided to correct the error in the prediction. I suppose you could say that DPCM is an ADPCM variant where the next value is predicted to be the same as the current value.

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

Post by TmEE co.(TM) » Wed Jan 31, 2007 8:31 am

I guess, it is simpler to use 4-bit PCM than DPCM or ADPCM, I can't imagine getting sampling rate over 8KHz decoding DPCM/ADPCM with z80.
All of these formats cause some noise, and it ruins the sound when sampling rate is low but 4-bit PCM does not need to be decoded so sampling rate can be as high as 16KHz (if you modify my code).
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

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

Post by Stef » Wed Jan 31, 2007 10:07 am

Well, in fact i just wrote the 4 bits PCM player for Z80 but the result is really disapointing... My idea was to use the PSG as 3 DAC capable of playing 4 bits PCM data. The PSG codes the envelope on 4 bits so by setting the tone to 0 we can use PSG channel as 4 bits DAC by modifying quickly the envelope level. I did my own 8 bits PCM sample to 4 bits PCM sample (using rounding values and taking care of the decibel conversion for the PSG envelope).
But i've to admit that 4 bits PCM is just too bad, quality is definitly not acceptable for me... I think that doing mixing on the YM2612 DAC with conventional 8 bits sample stays a better solution.

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

Post by TmEE co.(TM) » Wed Jan 31, 2007 11:25 am

PSG is not very good at playing samples, and I think it will be slower than mixing 8-bit samples. Duke3D can mix 3 channels with music pretty good.
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

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

Post by Stef » Wed Jan 31, 2007 12:19 pm

5 Khz is not something which can be called "pretty good", but i've to admit that sound not that bad at least ;)
After Burner 2 uses the PSG as DAC for the voices. They sound not too bad but for music it's not enough imo.
Last edited by Stef on Wed Jan 31, 2007 1:54 pm, edited 1 time in total.

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

Post by TmEE co.(TM) » Wed Jan 31, 2007 1:32 pm

Stef wrote:5 Khz is not something which can called "pretty good", but i've to admit that sound not that bad at least ;)
I don't know if you have tested Duke3D on the real thing, but I can say, that it looks and sounds awful on emulators, sound is bad especially on Gens, because its DAC is not very good. On the real thing, its a different story (mostly).
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

Post Reply