Page 11 of 20
Posted: Tue Feb 20, 2007 1:02 pm
by Stef
TmEE co.(TM) wrote:I looked at your 2ch mixer code, and I looked at it again, and I must say, that I didn't get it

I can quickly describe it :
CB = WAV 0 length arranged (0-15 bits)
DE = WAV 0 address (0-15 bits)
IXL = WAV 0 address (15-23 bits)
IYL = WAV 0 last data value (used for mixing)
CB' = WAV 1 length arranged (0-15 bits)
DE' = WAV 1 address (0-15 bits)
IXH = WAV 1 address (15-23 bits)
IYL = WAV 1 last data value (used for mixing)
As you can see, i tried to maximize registers usage
Beside that, (STATUS) keep info of "playing" for both channel 0 and channel 1, if we're not playing, i'm using silent data for mixing.
I tried to minimize "jump" which made stuff a bit more complexe... i do not use DJNZ but "DEC B and JR carry" which is faster in "no carry" case (which happen almost everytime).
I don't have the code here so i can't really remember perfectly, but that should give you some tips... what part you don't understand ?
Posted: Tue Feb 20, 2007 1:05 pm
by Stef
Interestings links
About that part in PSG sample :
<<A last method is to select a sound with a very low frequency, and change the volume faster than this frequency. This method is not used in any MSX game that I know, since it is very inaccurate. But it’s used a lot in the Sega Master System, in games like “Afterburner”. >>
It's exactly what i intented to do, i also did a converter to convert 8 bits sample to 4 bits PSG sample (and taking care of the log decible conversion). But honestly 4 bits raw sample is just too bad (specially because of this weird PSG envelope stuff)

It can be ok for some small explodes sound etc... but definitly not to play a real long PCM sample. Adjusting it on 2 or 3 channels to improve quality just eats too many time and kill the interest of having severals channels, it's better to use the DAC if possible imo.
Posted: Tue Feb 20, 2007 1:26 pm
by Stef
Pascal wrote:Stef, i'm trying to use your driver in asm program, i converted my samples to 14000khz being 8 bit unsigned.
now for playing , i just got a huge scratch sound at the beginning and then nothing (sample is 50 secs length). I look & relook at my playing sample code and i don't see what's i'm doing wrong :s here's my code (i'm not a too gud asm coder ^^)
EDIT: ok i figured it out , i forgot to add 1 to the address after i set the sample address , why is pb[3] missing ? Also what's the best frequency & setting for the sample (i'm right with uint8) ? which one did u used for particle ?
thanks
Code: Select all
// sample address
pb[0] = addr >> 0;
pb[1] = addr >> 8;
pb[2] = addr >> 16;
pb[3] ??? why not use pb[3] directly ??
// sample length
pb[4] = len >> 0;
pb[5] = len >> 8;
pb[6] = len >> 16;
I guess you're speaking about the 2 channels players.
14000 Khz is ok

But unsigned is not :p
* The basic sample z80 player with variable playback rate need unsigned 8 bits sample.
* Driver which can play 2 samples at same time need signed 8 bits sample at a fixed ~14Khz rate (i can't do better for now :-/). I'm not checking for overflow during the mix (for speed reason) so if you play 2 high volume samples at same time, you can overflow and destroy output sound. Hopefully this happen quite rarely and you can definitly avoid it just by lowerering volume level of yours samples.
The 2 channels players need 8 bits signed sample unlike the basic player.
You should also look at the "startPlaySample2C" function in the audio.c file. If you want to correctly use the driver, you need to set values as this function do.
I guess the pb[3] stuff is just because of my aligning data habit :p
It's stupid here since the address BUS is 24 bits...
Posted: Tue Feb 20, 2007 1:35 pm
by Pascal
thanks for your reply , as usual i could have figured it out myself, thanks for your time
about the pb[3] , my question was not : why not setting the 24 to 32 bits address , but rather why not having consecutive addresses for address and len parameters, so in asm you prevent a (addq #1,address) and only use post address increment, nothing technical , just practical

Posted: Tue Feb 20, 2007 1:47 pm
by Stef
Pascal wrote:thanks for your reply , as usual i could have figured it out myself, thanks for your time
about the pb[3] , my question was not : why not setting the 24 to 32 bits address , but rather why not having consecutive addresses for address and len parameters, so in asm you prevent a (addq #1,address) and only use post address increment, nothing technical , just practical

Yeah i know but in fact both are linked, i'm not using consecutive address because when i store data, i want them to be 1, 2 or 4 bytes len, i don't like 3 bytes len data :p
I know there is no sense of doing that here since only 3 bytes are needed... for the last byte you can use a CLR.B (A1)+ (not sure about opcode form)

Posted: Tue Feb 20, 2007 2:02 pm
by TmEE co.(TM)
Stef wrote:I don't have the code here so i can't really remember perfectly, but that should give you some tips... what part you don't understand ?
Actually most of it.
I just figured out a way to improve my code, now I can free one reg (actually 2). Anyway my driver uses 8-bit unsigned samples, with 4 byte header: 3 bytes of lenght, 1 byte of time constant(may not be used at all).
When my urge to mod my MD2 stops (improving RGB), I'll post some source

Posted: Wed Feb 21, 2007 4:29 pm
by Stef
TmEE co.(TM) wrote:Stef wrote:I don't have the code here so i can't really remember perfectly, but that should give you some tips... what part you don't understand ?
Actually most of it.
I just figured out a way to improve my code, now I can free one reg (actually 2). Anyway my driver uses 8-bit unsigned samples, with 4 byte header: 3 bytes of lenght, 1 byte of time constant(may not be used at all).
When my urge to mod my MD2 stops (improving RGB), I'll post some source

You still plan to play 2 ch at same time ? using 8 bit unsigned sample will make some extra instructions needed.
Posted: Thu Feb 22, 2007 6:37 am
by TmEE co.(TM)
I don't like any signed stuff and how can you mix signed stuff easier ?
Posted: Thu Feb 22, 2007 8:33 am
by Stef
TmEE co.(TM) wrote:I don't like any signed stuff and how can you mix signed stuff easier ?
When you use unsigned data, $80 is the silent value... you can't do a simple "add" to mix your sample. You can with signed data as $00 is the silent value

Posted: Thu Feb 22, 2007 8:51 am
by TmEE co.(TM)
You did "ADD reg, #80" on sample data in your code, why is it required ?
I just add two samples together if I use 7-bit unsigned, or do some shifts if I use 8-bit unsigned and then add them together.
Posted: Thu Feb 22, 2007 9:31 am
by Stef
TmEE co.(TM) wrote:You did "ADD reg, #80" on sample data in your code, why is it required ?
Because the DAC expect unsigned sample

so i've to unsign the value before giving it to the DAC.
I just add two samples together if I use 7-bit unsigned, or do some shifts if I use 8-bit unsigned and then add them together.
Actually if you use 7 bit unsigned or shifting for 8 bit it's ok

7 bit sample aren't "common" but if you find a WAV tool which can build them, it's probably a good solution since you don't need anything else than a "add" instruction and the quality loss over 8 bits sample is acceptabled.
Using signed 8 bits sample permit to keep the quality of 8 bits sample and have only an extra "add $80" instruction.
Posted: Thu Feb 22, 2007 10:37 am
by RedAngel
It may be not very useful to use the PSG for samples (low quality and more Z80 cycles needed) but as Stef said, it could be useful for sound effects. It seems we can learn a lot from the MSX scene:
More PSG related information.
Posted: Thu Feb 22, 2007 10:47 am
by KanedaFr
RedAngel wrote:It may be not very useful to use the PSG for samples (low quality and more Z80 cycles needed) but as Stef said, it could be useful for sound effects. It seems we can learn a lot from the MSX scene:
More PSG related information.
I confirm that...
I'm finishing 32XKMod, and I'll show you the power of PSG

Posted: Thu Feb 22, 2007 1:41 pm
by Stef
KanedaFr wrote:RedAngel wrote:It may be not very useful to use the PSG for samples (low quality and more Z80 cycles needed) but as Stef said, it could be useful for sound effects. It seems we can learn a lot from the MSX scene:
More PSG related information.
I confirm that...
I'm finishing 32XKMod, and I'll show you the power of PSG

hehe

what do you plan exactly ? :p
Posted: Thu Feb 22, 2007 6:59 pm
by TmEE co.(TM)
Stef wrote:Using signed 8 bits sample permit to keep the quality of 8 bits sample and have only an extra "add $80" instruction.
Which is faster, shift or add ?