68k based PCM Audio mixer for YM2612

SGDK only sub forum

Moderator: Stef

Post Reply
masteries
Very interested
Posts: 53
Joined: Thu Jul 30, 2020 3:33 pm

68k based PCM Audio mixer for YM2612

Post by masteries » Mon Aug 09, 2021 10:25 pm

Greetings again mates,

I am currently working... or thinking in reuse the PCM audio mixer I wrote for the Atari STE

Its 100% 68k assembly based. The STE has a DAC chip that fetch samples from system RAM at a precise rate.

The fetching adresses are writable by the 68k CPU, and at each VBLANK interrupt the 68k mixer assembly code is being executed, and the PCM chip fetching registers are updated with the new addresses (next audio frame of the mixing buffer).


I suppose that DAC capabilities of the YM2612 acta in the same way, but I don't have the information about how to use this chip in this way.


As well, instead a 3x uncompressed @12.5 KHz mono voices mixer, for MD I prefer to add another channel based in ADPCM, for music playback, due to music is based on audio loops, reading a custom music sheet.

All samples are audio frame sized, obviously you cant evaluate if a sample is finished at middle of mixing... xD unless you want to ruin the performance.


In the STE, ADPCM is not recommended due to 68k CPU is also required (a lot) for display rendering, and prepare blitter orders... But MD is a graphical beast compared to STE, and more CPU is available for audio purposes.



In order to accomplish this task, I need to know how to configure YM2612 in mono 8 bits DAC only mode, how to configure sample fetching rate, how to write sample fetching registers... and how to configure a VBL IRQ function in SGDK

Thanks in advance,

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

Re: 68k based PCM Audio mixer for YM2612

Post by TmEE co.(TM) » Tue Aug 10, 2021 9:26 am

You're in for a big disappointment because the PCM on MD doesn't work anywhere near like it does on the ST. You just have one IO port in the YM that you must manually feed with new data, all timing is up to you as there is no automatic sample fetching and you don't have any regular interrupt to do the timing for you either (line ints do get close but they stop in border).

Games use Z80 to do this work, leaving 68K available for the game itself.
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

masteries
Very interested
Posts: 53
Joined: Thu Jul 30, 2020 3:33 pm

Re: 68k based PCM Audio mixer for YM2612

Post by masteries » Tue Aug 10, 2021 10:27 am

TmEE co.(TM) wrote:
Tue Aug 10, 2021 9:26 am
You're in for a big disappointment because the PCM on MD doesn't work anywhere near like it does on the ST. You just have one IO port in the YM that you must manually feed with new data, all timing is up to you as there is no automatic sample fetching and you don't have any regular interrupt to do the timing for you either (line ints do get close but they stop in border).

Games use Z80 to do this work, leaving 68K available for the game itself.
Hmmm ...

There is no DMA at sample fetching, beautiful!

But...

Can the Z80 be used to feed the YM DAC register?
I suppose that the Z80 can only send samples at some fixed rates, due to you need to use "NOP" as waiting order, and move as send instruction

Can be the 68k still be used to prepare the mixed buffers, and copy the next frame to be played to the Z80 RAM, while the Z80 is feeding the previous
mixed frame? Currently each frame are 250 Bytes or samples


VBL IRQ is the mechanism needed; on the STE I never activate the end of DMA IRQ, is not needed; due to you know the sampling rate, and your mixing frames are equally in lenght of a sampling frame. :)

Is there VBL IRQ available at MD? Or I shall need to use a polling mechanism such Wait for VBL? xD


Obviously this approach is a replication of the automatic sample feeding (DMA), but using the Z80 in an simple data feeding way, while the rest of the mixer remains the same, with the addition of an ADPCM Channel

The Z80 will never be stopped, when there is no sound output, it will still sending the same data, but these are mixed as zeros

masteries
Very interested
Posts: 53
Joined: Thu Jul 30, 2020 3:33 pm

Re: 68k based PCM Audio mixer for YM2612

Post by masteries » Tue Aug 10, 2021 1:10 pm

I will research the 4 PCM channels audio driver, and the 2 ADPCM channels one; in order to create a new one. :)

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

Re: 68k based PCM Audio mixer for YM2612

Post by TmEE co.(TM) » Tue Aug 10, 2021 8:45 pm

You have line and frame interrupts so that is not a problem, though Z80 only gets frame interrupt.

Yes, Z80 can do it, and you are supposed to use Z80 for it (and all the sound tasks in general).

You cannot send data to Z80 RAM without stopping the Z80 so updating any buffers while also doing playback is going to be difficult when timings must be maintained. Z80 can access RAM in cartridge ROM area though so it could be used to pass data if necessary (most emulators are only going to support what games did which was some save memory at odd bytes only) but it probably is better to do all the PCM things directly on Z80 as several existing sound drivers do, leaving 68K completely free for the important tasks though Z80 accessing ROM will have some speed penalty on 68K (and 68K will slow Z80 down some amount too when Z80 has to access ROM).
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

masteries
Very interested
Posts: 53
Joined: Thu Jul 30, 2020 3:33 pm

Re: 68k based PCM Audio mixer for YM2612

Post by masteries » Wed Aug 25, 2021 5:04 pm

TmEE co.(TM) wrote:
Tue Aug 10, 2021 8:45 pm
You have line and frame interrupts so that is not a problem, though Z80 only gets frame interrupt.

Yes, Z80 can do it, and you are supposed to use Z80 for it (and all the sound tasks in general).

You cannot send data to Z80 RAM without stopping the Z80 so updating any buffers while also doing playback is going to be difficult when timings must be maintained. Z80 can access RAM in cartridge ROM area though so it could be used to pass data if necessary (most emulators are only going to support what games did which was some save memory at odd bytes only) but it probably is better to do all the PCM things directly on Z80 as several existing sound drivers do, leaving 68K completely free for the important tasks though Z80 accessing ROM will have some speed penalty on 68K (and 68K will slow Z80 down some amount too when Z80 has to access ROM).
Yes, I write my own test using 68k to Z80 RAM, with a custom Z80 driver that mixes at 12.5KHz, as an experiment.

But continous writing to Z80 RAM produces noticeable noise... an my trials in write a modified Z80 driver failed catastrophically... xD
really I am losing an humongous amount of time with these trial and error prone, while game development is the one topic that demands me,

I am thinking in a paid request for a custom driver, and post the request here,

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

Re: 68k based PCM Audio mixer for YM2612

Post by Stef » Thu Aug 26, 2021 10:04 pm

Writing a Z80 sound driver is probably one of the most difficult part when developing game for the system to be honest.
Did you had a look on existing Z80 driver from SGDK ? otherwise you can try to publish here the specification of the driver you need and hire someone to do it for you.

masteries
Very interested
Posts: 53
Joined: Thu Jul 30, 2020 3:33 pm

Re: 68k based PCM Audio mixer for YM2612

Post by masteries » Fri Aug 27, 2021 11:53 am

Stef wrote:
Thu Aug 26, 2021 10:04 pm
Writing a Z80 sound driver is probably one of the most difficult part when developing game for the system to be honest.
Did you had a look on existing Z80 driver from SGDK ? otherwise you can try to publish here the specification of the driver you need and hire someone to do it for you.

Yes, as you said is very challenging,

I was understanding and writing my own, but it is very awful.... xD
I spent all this week without succesful results, and I will made the proposition for a 3x ADPCM channels driver at 16 KHz ( 200€ ), or 14 KHz (170€)

Also, testing the current Z80 drivers (1PCM, 2ADPCM, 4PCM) these works pretty well,
also I was heavily testing how to manage the change from one wav. loop to another wav. loop

If managed correctly, these functions:

if(SND_isPlaying_2ADPCM(SOUND_PCM_CH1_MSK) == 0)

or

if(SND_isPlaying_PCM() == 0)

works pretty well when your task is to inmediately start the playback of another loop,

Post Reply