gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Find the example to use SFX in mikmod

#163063 - wink99_th - Sun Sep 21, 2008 3:31 am

now I can play music by using mikmod lib. but i would like to play sound effect (wave file). I use libnds play SFX like this
Code:

void SFX_click()
{
     TransferSoundData click = {
      click_raw,      /* Sample address */
      click_raw_size,   /* Sample length */
      11025,            /* Sample rate */
      127,            /* Volume */
      64,               /* panning */
      1                /* format */
   };
   playSound(&click);
}

I play SFX alone. It's work. But when I mix between music and SFX, the SFX is weird sound. So i want to change to use mikmod SFX ( play SAMPLE). In mikmod doucument,I think it show how to use function in PC not in NDS. for example
Code:

    /* load samples */
    sfx1 = Sample_Load("first.wav");
 

Could someone show me the example code to play SFX by mikmod?

#163088 - a128 - Mon Sep 22, 2008 8:00 am

check tetattDS they do it

http://tetattds.googlecode.com/files/tetattds-2.0-src.zip

#163097 - gauauu - Mon Sep 22, 2008 2:58 pm

Do they? When I looked at the source recently, they were using libnds's playSound().

Of course, they might have also been using mikmod for SFX as well, but if so, I didn't see that code during my cursory viewing.

#163120 - gauauu - Tue Sep 23, 2008 4:29 am

By the way, I can play my SFX using playSound while mikmod is playing a mod file, and there's no issue...so maybe something else is the problem?

#163129 - wink99_th - Tue Sep 23, 2008 1:53 pm

In my opinion, maybe my code take much cpu time? Or Sound data is not correct. I use audacity to convert a wave sound.
this is my code and execute file . Using "B" button to toggle (on-off) music.
http://www.thaigcc.com/nds/Prj-03.7z

#163132 - gauauu - Tue Sep 23, 2008 3:33 pm

What format are your sound files in? I've tried opening them in audacity, and can't get them to play anything that sounds remotely "normal" to the ear.

Try saving them as mono, 8-bit signed pcms, and see if it works.

#163134 - wink99_th - Tue Sep 23, 2008 5:07 pm

Thank you gauauu.
sound file is wav format. And I covert to .raw file(header less, 8 signed PCM) by audacity. You can play the raw by using menu : Project-> import raw data. The audacity can guess the format sound. I don't know when I stop music , the sfx sound is ok?

#163135 - gauauu - Tue Sep 23, 2008 7:10 pm

In that case, I have no idea.