New XGM driver !

SGDK only sub forum

Moderator: Stef

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

Post by Stef »

Right now no, i keep the "DAC en" writes and i believe i will need them anyway. As you said, they can be used to simulate small "pause" operations on FM6.
Davidian
Newbie
Posts: 9
Joined: Wed Jul 16, 2014 9:50 am
Location: Spain

Post by Davidian »

Hi,

Here you can listen a tune for Antarex with the XGM driver captured from the stereo output of a PAL Mega Drive I with no filters, equalization...

https://soundcloud.com/david-alt-sanche ... -level-1-1

The setup for this music is:

5 FM + 1 PCM for drums (1 snare, 1 bassdrum and 2 toms @8Khz because we were using the VGM driver) + PSG Noise for the hat.

VGM 1.60 made with Deflemask.

Turn volume to the max and hope you like it.

I'm making some tests with the other PCM channels for effects. Any news i will keep you informed.

Of course, thank you very much Stef for this driver. It will suppose a new level in the sound of homebrew games :wink:
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

Hi Davidian,

Thanks for the preview ! A very nice tune which really suit for that type of game, well done ! I'm happy to hear you successfully moved to the XGM driver, it's good to see it used :)
I still have some stuff to fix or improve (pause / stop music command, auto enable/disable DAC mode for FM5).

Another good news is that i am discussing with Delek so he can add support for the XGM driver in DefleMask editor (and so have access to 4 PCM at 14 Khz for music). It will still export in VGM (with 4 PCM channels) but my next xgmtool version will be able to translate them in XGM format.
db-electronics
Very interested
Posts: 89
Joined: Mon Feb 24, 2014 6:04 pm
Location: Kapuskasing, Ontario, Canada
Contact:

Post by db-electronics »

Stef, great work on this driver!

I've been reading the Z80 source code and I have a question. I reached line 373 (in here) and I noticed something odd:

Code: Select all

; readMixAndUnsign
; ----------------
; ?   ->  HL  ->  point to the sample source (ROM)
; ?   ->  DE  ->  point to write buffer
; $80 ->  B
;
; read 1 sample and mix it with output buffer, then unsign it
; = 40 (+11 when overflow)

            macro readMixAndUnsign

            LD      A, (DE)         ; read value in write buf   ' 7     |
            ADD     (HL)            ; mix with source sample    ' 7+1   | (25)
            JP      PO, .ok         ; check overflow            ' 10    |

            LD      A, B            ; fix overflow              ' 4     |
            ADC     $FF             ; A = $7F/$80               ' 7     | +11

.ok
            ADD     B               ; unsign                    ' 4     |
            LD      (DE), A         ; write sample in buffer    ' 7     | 19 (44)
            INC     E               ;                           ' 4     |
            INC     L               ; next                      ' 4     |

            endm                    ;                           ' 44 (+11)
ADD and ADC are supposed to take two operands as far as I know ;)

http://www.villehelin.com/mnemonics_z80_a.txt

Is this intentional or is there some other ADD mnemonic which I've never encountered using WLADX?
What does db stand for? Well that's an excellent question...
http://www.db-electronics.ca
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

Most z80 assemblers assume A is the target when left off. In fact, some z80 assembler books don't even show A as the target for opcodes targeting A - it's just assumed.
db-electronics
Very interested
Posts: 89
Joined: Mon Feb 24, 2014 6:04 pm
Location: Kapuskasing, Ontario, Canada
Contact:

Post by db-electronics »

Chilly Willy wrote:Most z80 assemblers assume A is the target when left off. In fact, some z80 assembler books don't even show A as the target for opcodes targeting A - it's just assumed.
Well I learned something today! WLA DX doesn't let me do that!
What does db stand for? Well that's an excellent question...
http://www.db-electronics.ca
hodgy100
Newbie
Posts: 2
Joined: Sat Jan 17, 2015 7:26 pm

Post by hodgy100 »

Hey. Thanks a bunch for this new driver its awesome! I can play music without using a load of memory and easily play sound effects too!

I just have a quick question, if I want to create some sort music visualiser do you know how I can access data on the sound channels?
e.g is it playing and at what volume. This would help me loads with the effect I'm trying to achieve in my game.

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

Post by Stef »

Thanks for the kind comment :D
Well unfortunately you don't have much of the sound data state in the XGM driver mainly because of the small amount of free Z80 memory (less than 256 bytes).

You have states of the D1R and RR ym2612 registers and also the state of DAC enabled register but this one is not really useful.
Then you have PSG envelop state and the PCM buffer.

Here is the address for different meaningful informations for you:

XGM music playing state: 0xA00102 bit 6
PCM channel playing state: 0xA00102 bit 0 to bit 3 (channel 0 to channel 3)
D1L / RR registers state: 0xA00144-0xA0015B (6 channels * 4 operators)
PSG envelop: 0xA0015C-0xA0015F (4 channels)
DAC enabled: 0xA00160 (bit 7)
Circular PCM buffer: 0xA01800-0xA01BFF

You can find the current read PCM segment at 0xA00140.
Note that the address is stored as byte so you only have bit 8 and bit 9 as the lower bits are always 0.
For instance if you read 0 from 0xA00140 then current PCM read buffer is 0xA01800, if you read 3 then current read PCM buffer is 0xA01B00...

I think that's all for music data / state :)
hodgy100
Newbie
Posts: 2
Joined: Sat Jan 17, 2015 7:26 pm

Post by hodgy100 »

Thanks!
I'll see what I can do with it :)
KanedaFr
Administrateur
Posts: 1154
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr »

Can you tell us the use of priority for PCM ?

Does it mean a PCM with priority 1 will be played while a priority 2 pcm is muted ? or priority 2 will be played after priority 1 ?


and what about ID ?
Does it mean we could pre-load PCMs and then call their ID for playing ?


also I see on SGDK sound.c you use prio 0, id 0 to silent PCM
does it mean we should avoid these values ?



last one, can you confirm PCM is 8bit 14Khz ?


lot of questions, no ? ;)
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

KanedaFr wrote:Can you tell us the use of priority for PCM ?

Does it mean a PCM with priority 1 will be played while a priority 2 pcm is muted ? or priority 2 will be played after priority 1 ?
Higher priority has priority mean priority 2 will play over priority 1 but not the contrary :)
and what about ID ?
Does it mean we could pre-load PCMs and then call their ID for playing ?
Sort of, actually XGM driver internally assign id to PCM sample.
0 is reserved (used to turn PCM off)
1-63 is reserved for music
64-255 is reserved for SFX

So for instance when you want to play SFX you can do this :

Code: Select all

// set sample id (>= 64 for SFX else you can override music PCM)
SND_setPCM_XGM(66, loop1_14k, sizeof(loop1_14k));
// then play sample at priority 10 on channel 4
SND_startPlayPCM_XGM(66, 10, SOUND_PCM_CH4);
Of course you can do all your

Code: Select all

SND_setPCM_XGM(id, sample, sizeof(sample));
at initialization time then only use

Code: Select all

SND_startPlayPCM_XGM(id, priority, channel);
at game time.

Note that the sound sample example contains code example for the XGM driver use :
https://github.com/Stephane-D/SGDK/blob ... src/main.c

also I see on SGDK sound.c you use prio 0, id 0 to silent PCM
does it mean we should avoid these values ?
Exactly, id #0 is used to silent PCM channel ;)
last one, can you confirm PCM is 8bit 14Khz ?
8 bits signed at 14 Khz, but i would say that you don't really care, if you declare your sample in a .res resource file then you can just use a WAV file to play through the XGM driver, just declare it this way :

Code: Select all

WAV <name> <file> [driver [outrate]]
where driver is 5 for the XGM driver. outrate is automatically set to 14 Khz (this parameter is used only for driver 1) but it's better to convert your WAV to 14 Khz before as the internal tool which is used to resample sample uses a poor algorithm and sound is generally bad when resampling is needed.

Here you can find the description about .res file :
https://github.com/Stephane-D/SGDK/blob ... escomp.txt

And here the description of the XGM driver & format :
https://sgdk.googlecode.com/svn/trunk/bin/xgm.txt
KanedaFr
Administrateur
Posts: 1154
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr »

Thanks, I totally missed I had to use 64+ for SFX

I have 10 sfx, I so could use setPCM_XGM for the 10, since it will only write it 's address and size , right ?
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

If you don't play any music it won't hurt to use id #1 to #63 for PCM, but if you play music then you have to use #64 or more.
I don't really understand your last question by the way :p
KanedaFr
Administrateur
Posts: 1154
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr »

;)

It was related to call as much as SND_setPCM_XGM at game init
then simply call SND_startPlayPCM_XGM when needed

Did you allocate enough memory for 10 SFX ?
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef »

Having 10 or 100 SFX does not eat more "memory", SFX are just plain PCM and so consume ROM. As soon you have them fitting in your ROM, you can play them freely with the XGM driver.
You actually have 63 PCM id reserved for music and 192 for SFX... I think that is more than enough (and you can change id allocation without any restriction) ;)
You can indeed do all your SND_setPCM_XGM(..) calls at beginning then just use SND_startPlayPCM_XGM(..)
Post Reply