Play wav music and sound effect

SGDK only sub forum

Moderator: Stef

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Play wav music and sound effect

Post by dub » Sat Oct 24, 2015 3:48 pm

Hi, I want to play music and sound effect in my game but I'm a really bad artist (gfx or music).

So I'll use wav music with loop. I've read the rescomp file and import my wav file (51 sec) after a update (8bit unsigned mono 8khz).
My file size is good : 400 ko and nice when listening. I could insert 6 music files and some sound effect.

But, before I begin to modify your sample sound, I have one question. I play my music file with the drivers 0 (8 bits 8khz single channel PCM driver).

Can I use at the same time this driver for playing music, and another driver to play sfx ?
I don't think it's possible, but I'm not sure.

If I change my outrate to 16khz, my file is nearly two time more big. It's not bad but I'll need a 64MB rom. Can we have more than 64MB rom ?

MrTamk1s
Very interested
Posts: 75
Joined: Sun Jan 04, 2015 10:27 pm
Location: Pennsylvania
Contact:

Re: Play wav music and sound effect

Post by MrTamk1s » Sat Oct 24, 2015 4:36 pm

You should be able to use the XGM Driver's x4 PCM mixer for this. Play the .wav song loop on one PCM channel, and use the other x3 for sfx.
SGDK homebrew dev and Unity3D Indie dev.
Sega does what Nintendont!

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Play wav music and sound effect

Post by dub » Sat Oct 24, 2015 5:20 pm

Thanks I test it with Z80_DRIVER_4PCM

Works well, I use a 16KHz fmusic file.
So do I need to align my wav file to 256 or 128 or it's automatic ? with the app sizebnd -262144

And I have another questions. :wink:

Can I create a 8MO (64Mb) rom with sgdk. The rom crash on KFusion if I create a rom larger than 4Mo ?
Can I create a ROM with dynamic option: If SegaCD in, I play music on CD, but if there is no SegaCD, I play music from the cart ? And can sgdk play music from CD, I didn't find info or how do that ?

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

Re: Play wav music and sound effect

Post by Stef » Sun Oct 25, 2015 10:08 pm

4PCM driver is nice as it supports 16 levels of envelop but on other hand XGM driver uses 14 Khz sample (a bit less rom) and also offer protection against DMA bus contention if you plan to use a lot the DMA capabilities.
About sample alignement, rescomp will do it for you. Just declare your sample as WAV, and use the good driver value so rescomp know how to convert the WAN files :)

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Play wav music and sound effect

Post by dub » Mon Oct 26, 2015 9:15 am

Thank you both.

I was thinking the xgm driver is for xgm file only :oops: And because I wish to use the loop function.
But after reading your doc, I can certainly use the "SND_isPlayingPCM_XGM" function to restart the music.

For playing music from SegaCd, I've found a post (I haven't saved the link) from Chilly Willy. I've downloaded the sample to use the source code in asm for doing it. Later ...

For the size of the ROM. I read some doc and it seems that we can use only 4MB. For up, we need bank switching. I don't understand how to do this. Can we use the bank switch only for music, I think we need to give the right adress of the Data ?

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

Re: Play wav music and sound effect

Post by Stef » Mon Oct 26, 2015 9:55 am

Actually you can use rom up to 8 MB (even 10 MB with a bit of extra hardware) without bank switching but if you do it, you are not anymore compatible with Sega CD nor 32X addon. Also you need a specific emulator to handle large rom like that.
Bank switch is the safe and official way to go for rom above 4 MB but then you need to switch bank when you access data > 4MB and you need to write specific code to handle these cases (SGDK do not give tools for that right now).

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Play wav music and sound effect

Post by dub » Mon Oct 26, 2015 11:03 am

Nice, so I can do a 8Mo version (I doesn't use 32x or CD) and a 4Mo with CD. :D

I have made my code for loop and that's working :

Code: Select all

if (SND_isPlayingPCM_XGM(SOUND_PCM_CH2_MSK) == 0) SND_startPlayPCM_XGM(64, 15, SOUND_PCM_CH2);
Now I have problem with audio files. I use audacity. No problem with the 8khz or 16khz onmegadrive.
When I try to make a 14Khz, the sound is very bad on megadrive but good on Windows.

I export in 14000Hz, Mono, unsigned 8 bits.
I tested with the loop1.wav 14Khz whitout problem to be sure that my code is all right.

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

Re: Play wav music and sound effect

Post by Stef » Mon Oct 26, 2015 2:23 pm

Normally you even don't have to convert your WAV file as rescomp should do it for you but as the internal resampler is bad it's better to convert it at least to the good sampling rate (14 Khz for XGM driver).
Something to know is that any sound player on windows will always interpolate and filter sound so it plays better than raw 14K Khz.
Still you should have something wrong as you said that 16 or 8 Khz was working right.
Can you post a very basic project example (source and resource) showing the bad quality problem ? so i can replicate it and understand what is wrong. Thanks !

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Play wav music and sound effect

Post by dub » Mon Oct 26, 2015 3:27 pm

Yes, I certainly doing something wrong with my audio application or my code. I try with different file music like one export by Deflemask.

Code source with assets : https://www.dropbox.com/s/b1uqnm01swevv ... dk_xgm.zip
Music file before 14khz conversion : https://www.dropbox.com/s/6bexakpmfy4gufl/STARTWIN.WAV

Thanks.

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

Re: Play wav music and sound effect

Post by Stef » Mon Oct 26, 2015 11:07 pm

I just tried your code and it does not seems that bad. I used Wavosaure to do the 14 Khz resampling and the quality is a bit better but not that much. Again player on your PC applies filtering to make sound better for low sampling rate as 14 Khz.
Something that you can definitely improve is your source WAV. I saw you used a 11 Khz source wav in 8 bits, don't you have a better quality version ? 44 Khz or 22 Khz at least ?

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Play wav music and sound effect

Post by dub » Tue Oct 27, 2015 8:13 am

OK.
Thanks for wavosaure, It seem better for conversion.

I have made a audio file with deflemask (16bit, 44.1Khz), and after convert it to 8bit 14Khz. The sound is better, not perfect but much much better.
I'll continue my test :D

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Play wav music and sound effect

Post by dub » Wed Oct 28, 2015 8:39 am

I'll continue my others questions on the same post :

I'm making my level using array, one for the tiles position and one for the collision.
I have an level.h with my arrays like :

Code: Select all

u8 lev01PBCache[1120] = {
0,0,0,0, ... 0,0,0
};
I know when you block 1120 value for your array, you block a port of memory (RAM ?)

I want to have 2 arrays for each room of my game. I certainly fill all the memory like that.
Can we put array like data in rom and load them when we need.

I try lot of thing without success ... again, I always have syntax error
Like :

Code: Select all

if (level==1)  lev01PBCache[1120] = { 1,2,3,4, ... 8,7};
I can only do (and it's normal) :

Code: Select all

lev01PBCache[0]=1;
lev01PBCache[1]=2;
How can we stock more data for arrays ?

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

Re: Play wav music and sound effect

Post by Stef » Wed Oct 28, 2015 9:09 am

Just put 'const' before the declaration of your array so the compiler now the array is constant and will locate it in rom :)

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Play wav music and sound effect

Post by dub » Wed Oct 28, 2015 10:52 am

That's great. So easy. 8)

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Play wav music and sound effect

Post by dub » Wed Nov 11, 2015 10:46 am

I continue my journey with the sound drivers. I'll use the xgm driver for music vgm file and PCM sound effect. :)

I use DefelMask to test music because I don't know how do music pattern. Maybe some users use an another music software ?

So I open dmf file in DefleMask. I test in the software but when I convert with xgmtool, my music stop with playing the same note again and again.

I tried 3 export version (1.50, 1.60, 1.61) of Boss_demo.dmf to vgm and another songs without success.

I finnaly find the dmf Green_Hill_Zone and it's working. The only diffrence I can see, it's the "Bxx - Position Jump" at the end of the file 0B09
But I don't know how add manually a Position Jump with DefleMask. I read the manual without success. I want to add jump to the beginning for testing.
Does someone know how do that ?

I use DefleMask ver. 10c and I update the sgdk with the last files (xgmtool 44ko, rescomp and wavtoraw).

Edit : I test with copying the 0B09 value (Ctrl+C, Ctrl+V) of Green_hill_zone at the end of the Boss_demo file and it's working with sgdk. But I don't know how change or create my value. I only loop with pattern 09. One more step.

Image
we can see it Inside the green box.

Edit2 : Ok, I do it. We need to push Space Bar to make modification. After you can press B to add this effect.

Post Reply