Page 3 of 5

Posted: Mon Dec 01, 2014 6:30 pm
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.

Posted: Thu Dec 11, 2014 9:03 pm
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:

Posted: Thu Dec 11, 2014 11:40 pm
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.

Posted: Mon Dec 15, 2014 9:45 pm
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?

Posted: Tue Dec 16, 2014 1:25 am
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.

Posted: Tue Dec 16, 2014 1:27 am
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!

Posted: Sat Mar 07, 2015 11:18 pm
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 :)

Posted: Mon Mar 09, 2015 1:37 pm
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 :)

Posted: Mon Mar 16, 2015 10:28 pm
by hodgy100
Thanks!
I'll see what I can do with it :)

Posted: Wed Jun 17, 2015 8:58 pm
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 ? ;)

Posted: Thu Jun 18, 2015 7:56 pm
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

Posted: Fri Jun 19, 2015 8:06 pm
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 ?

Posted: Fri Jun 19, 2015 10:23 pm
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

Posted: Sun Jun 21, 2015 9:25 pm
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 ?

Posted: Mon Jun 22, 2015 10:00 pm
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(..)