how can i do music on megadrive?

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

Moderator: BigEvilCorporation

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

Post by Stef »

TmEE co.(TM) wrote:8 and 16KHz, sounds interesting, but changing banks is still a real sample rate killer...

My idea: play 1 sample alone, no mixing, play 2nd sample and mix it with one from another channel. Then you can have 2 channels, which one plays at half speed.
I don't understand your last point, doesn't look like the same idea than Pascal was speaking about ?
TmEE co.(TM)
Very interested
Posts: 2452
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) »

Stef wrote:I don't understand your last point, doesn't look like the same idea than Pascal was speaking about ?
2channels, 1 at half speed, if 1st channel is 16KHz, other will be @ 8KHz.
You play 2 samples form 1 channel, and when you play 2nd sample, you mix it with one sample from the 2nd channel. It will be little hassle to get such thing working though...

Your driver implementation is so fast because it does practically everything on registers, I can't reach 56KHz because 1 regset is for sample playback and other is reserved for music part and I must do some things in memory (counting down lenght to know when to end/restart).
IF I play only one channel, I could use all the regs and achieve very high sampling rate though :wink: .
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 »

TmEE co.(TM) wrote:
Stef wrote:I don't understand your last point, doesn't look like the same idea than Pascal was speaking about ?
2channels, 1 at half speed, if 1st channel is 16KHz, other will be @ 8KHz.
You play 2 samples form 1 channel, and when you play 2nd sample, you mix it with one sample from the 2nd channel. It will be little hassle to get such thing working though...

Your driver implementation is so fast because it does practically everything on registers, I can't reach 56KHz because 1 regset is for sample playback and other is reserved for music part and I must do some things in memory (counting down lenght to know when to end/restart).
IF I play only one channel, I could use all the regs and achieve very high sampling rate though :wink: .
Hehe, yep my single channel player put all data in register ;)
The 2ch player also heavily use register (EXX instruction very usefull here) but the structure of the code doesn't permit me to speed up a lot when the player is doing only 1 channel. Anyway i've to use a fixe rate or my sample would play too fast when only 1 channel is actually playing (or slower when 2 channels are played, depend your point of view :p)

56 Khz is anyway not usefull at all, it was just a sort of proof of concept...
KanedaFr
Administrateur
Posts: 1154
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr »

ok...DAC is good but I now have a problem with all other...

let me explain

Code: Select all

Vint :
-> bankswitch
-> psg data
-> bankswitch
-> FM data

Loop:
-> bankswitch
-> DAC data
so, as you, perhaps, can see, I'm able to play the 3 things (with DAC not at 40KHz!)
my problem, when Vint occurs while I'm playing with DAC, bank switch occurs and DAC is then reading my FM data ...

it's a wonderful world between vint bankswitches and loop bankswitches....

the only possibilities I saw : di / dac stuff / ei
which is impossible :(

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

Post by Stef »

KanedaFr wrote:ok...DAC is good but I now have a problem with all other...

let me explain

Code: Select all

Vint :
-> bankswitch
-> psg data
-> bankswitch
-> FM data

Loop:
-> bankswitch
-> DAC data
so, as you, perhaps, can see, I'm able to play the 3 things (with DAC not at 40KHz!)
my problem, when Vint occurs while I'm playing with DAC, bank switch occurs and DAC is then reading my FM data ...

it's a wonderful world between vint bankswitches and loop bankswitches....

the only possibilities I saw : di / dac stuff / ei
which is impossible :(

some idea ?
Actually i also tried to do some weird tasks in the V-int handler.
But you just can't do anything which "corrupt" the main processing.
The only thing you can do in V-Int code is to set flag as "playPSG" to 1.
Then in your main loop you check for that flag at sometime and you do the PSG process :)
Actually except setting some sort of flag in the V-int routine, you can't do anything.

The same is true on 68000 side, if your main loop is doing some VDP stuff, you V-int code can't do any VDP stuff...
TmEE co.(TM)
Very interested
Posts: 2452
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) »

My Music (not there yet) & Sound Engine does this (simplified):

Vint:
EXX
BankSwitch
DoFM
MaybeDoPSG
BankSwitch -> for DAC
EXX
RETI

Maincode
DI
InitFMsynth
EI
Start:
BankSwitch
LoadSample1
BankSwitch
MixSamples
PlaySample
Goto Start

I wonder, how much the FM code affects sample rate...?
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
Fonzie
Genny lover
Posts: 323
Joined: Tue Aug 29, 2006 11:17 am
Contact:

Post by Fonzie »

Code: Select all

Vint :
-> Read previous bankswitch
-> bankswitch
-> psg data
-> bankswitch
-> FM data
-> Set back bankswitch
Loop:
-> bankswitch
-> DAC data

I'm probably off ^^ probably...
8bitwizard
Very interested
Posts: 159
Joined: Sat Feb 24, 2007 11:35 pm
Location: San Antonio, TX

Post by 8bitwizard »

KanedaFr wrote:ok...DAC is good but I now have a problem with all the only possibilities I saw : di / dac stuff / ei
which is impossible :(
A trick I learned from ColecoVision might help:

When doing something that will conflict with the interrupt, set a "busy" flag. In the interrupt, if the "busy" flag is set, don't do the sound code right away, but set another "interrupt deferred" flag. In the main Z80 loop, check for this flag, then you can call the sound code for the FM/PSG stuff.

Or don't have the interrupt do anything but set a "time to update FM/PSG" flag, and always handle it in the main Z80 loop, since the timing doesn't need to be as accurate as the PCM.

In addition to sound, this trick was used to work around a big problem with the TMS9918A video. You had to read the VDP status register to acknowledge the vblank interrupt, but if the vblank interrupt (hooked up to NMI, so you couldn't just DI/EI, also level-sensitive, so you HAD to acknowledge the interrupt!) happened in the middle of a VDP address write, reading the status register would cause the VDP to reset the control port mode, stuff would get written to the wrong address, and you would get glitchy video.
TmEE co.(TM)
Very interested
Posts: 2452
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) »

Least we don't have to ack any ints here :) But checking if something happens on the FM side in DAC loop really kills the sampling rate, we check for commands, it takes sampling rate down, then we have to check for some other stuff... :(
8bitwizard, maybe you want to try to make your own z80 driver too, you have lots of experience with z80, maybe you're able to make the fastest driver :wink:
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 »

8bitwizard wrote:
KanedaFr wrote:ok...DAC is good but I now have a problem with all the only possibilities I saw : di / dac stuff / ei
which is impossible :(
A trick I learned from ColecoVision might help:

When doing something that will conflict with the interrupt, set a "busy" flag. In the interrupt, if the "busy" flag is set, don't do the sound code right away, but set another "interrupt deferred" flag. In the main Z80 loop, check for this flag, then you can call the sound code for the FM/PSG stuff.

Or don't have the interrupt do anything but set a "time to update FM/PSG" flag, and always handle it in the main Z80 loop, since the timing doesn't need to be as accurate as the PCM.

In addition to sound, this trick was used to work around a big problem with the TMS9918A video. You had to read the VDP status register to acknowledge the vblank interrupt, but if the vblank interrupt (hooked up to NMI, so you couldn't just DI/EI, also level-sensitive, so you HAD to acknowledge the interrupt!) happened in the middle of a VDP address write, reading the status register would cause the VDP to reset the control port mode, stuff would get written to the wrong address, and you would get glitchy video.
Hehe, sounds like the same i said in my previous post ;) Actually i also prefer this way. But as only the bank register can be modified here, the method of restoring it before exiting V-Int code is ok :)
TmEE co.(TM)
Very interested
Posts: 2452
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) »

I think, I'm giving up on my 2ch code, I'm unable to achieve reasonable rampling rate :( Least I got pretty good 1ch 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
KanedaFr
Administrateur
Posts: 1154
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr »

ah ah!!
8bits gave more hints, I didn't see it like this when I first read Stef post ;)

I got the point but as TmEE said, it will drop the DAC freq :(

If I add FM switch + FM play + (PSG switch + PSG play)*3 on loop..I'll have 1Khz DAC :(

or perhaps here is the real reason to optimize more my DAC driver (I really thought 9Khz was enought for what I want)

thanks anyway, I knew asking here will give me hints ;)

EDIT: perhaps the freq will not drop that much since the PSG/FM will not be done at each loop...
I already used that 'trick' of doing some stuff every X loop and won some hz...
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

KanedaFr wrote:ah ah!!
8bits gave more hints, I didn't see it like this when I first read Stef post ;)

I got the point but as TmEE said, it will drop the DAC freq :(

If I add FM switch + FM play + (PSG switch + PSG play)*3 on loop..I'll have 1Khz DAC :(

or perhaps here is the real reason to optimize more my DAC driver (I really thought 9Khz was enought for what I want)

thanks anyway, I knew asking here will give me hints ;)

EDIT: perhaps the freq will not drop that much since the PSG/FM will not be done at each loop...
I already used that 'trick' of doing some stuff every X loop and won some hz...
Doing PSG / FM stuff at V-int period won't really kill the DAC rate, the rate will stay the same except at the PSG/FM update time, that create a sort of "hole" in the sample. It's why almost voices sound somewhat crappy in Genesis game :-/ Faster is your update PSM/FM code, better the sample is.
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

I wrote a stereo sample player these 2 last days. It's worked perfectly with Kega but not with Gens :p
On real hardware, it was first just doing silent... After i figured some weird stuff about the YM2612 chip, i was able to get it up on real hardware, unfortunatly the used trick doesn't work because of the YM2612 hardware latency :-/
Too bad, having stereo sample on Genesis would have been a neat trick (as it doesn't support it natively)... anyway i've already some others ideas in head ^^
TmEE co.(TM)
Very interested
Posts: 2452
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) »

Stef wrote:I wrote a stereo sample player these 2 last days. It's worked perfectly with Kega but not with Gens :p
On real hardware, it was first just doing silent... After i figured some weird stuff about the YM2612 chip, i was able to get it up on real hardware, unfortunatly the used trick doesn't work because of the YM2612 hardware latency :-/
Too bad, having stereo sample on Genesis would have been a neat trick (as it doesn't support it natively)... anyway i've already some others ideas in head ^^
Hehe, I did such thing too !!! But it was in 68K code though. I played 16 samples from one channel and 16 from another. I didn't have my SRAM cart then so I don't know what it would do on real HW, and I probably can't check it, 'cos I think I fried it (was in bus conflict all night, RAMs were pretty hot).
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