PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Using Sounds.... help, please :)

Hi all, I'm trying to modify the Sound funcs in easyce 1.6, to allow me to load, play, and then delete etc,

e.g
Code:

#define FRED "fred.wav
unsigned short* fred_p;

void load_sound(char* a_file, unsigned short* m_buffer)
{
int fsize = filesize( a_file );
if (fsize)
{
FILE* wav = fopen( fullpath( a_file ), "rb" );
m_buffer = new unsigned char[fsize];
fread(m_buffer, 1, fsize, wav );
fclose( wav );
}
else
{
m_buffer = 0;
}
}


void play_sound(unsigned short* a_Snd)
{
if (a_Snd != 0) sndPlaySound( (ACHAR*)a_Snd, SND_ASYNC + SND_MEMORY );
}


main{}
{
load_sound(FRED,fred_p);
play_sound(fred_p);
delete [] fred_p;
}


what an I doing wrong, of should I just use whats there, and if so, how ?
More to the point why does this not work:

Code:

sndPlaySound((ACHAR*)fullpath("test.wav"), SND_ASYNC + SND_MEMORY );


I get nothing, I tried removing the fullpath(, but still nothing, could mikmod be stuffing things up?
I know i had just asked a question about sound in another post, but I may have an answer.

I know
sndPlaySound(L"\\myfolder\\mysound, SND_ASYNC)
works. The 'L' Makes sure the function handels the charicters right. I am not sure what your "fullpath(); function returns, but that may be the problem.
<b>SND_MEMORY - The parameter specified by lpszSoundName points to an image of a waveform sound in memory.</b>

You are passing a filename, not a pointer to a chunk of data. Don't use the SND_MEMORY flag.

Dan East
I've the following code working....

sndPlaySound(L"\\my documents\\test.wav",SND_ASYNC);

But, this will only work before mikmod is initalized.

If it is called after mikmod is init. then it just does not play, and if it is called just before init. the program crashes, I assume mikmod does not like a sound playing during init.

anyhow any ideas as to how to play a sound, as well as have mod's (it's) playing.... ?
and don't anyone way fmod..... ;)
MikMod would have to mix your sound effect into the rest of the samples its playing from the current mod. It should have that capability.

Dan East
I had a look at the header file for mikmod, and I can't see anything.... mmm I feel a "hack" comming on, maybe jakko has had some luck with it ?
You haven't read the documentation of MikMod properly. :) There's a lot of functionality to play samples together with music. Works fine for me, no hacking neccesary. ;)
OK, assuming I have read the "info" correctly, then this should work:

Code:

//headers
#define SOUNDA "test.wav"
SAMPLE* sounda_p;

//sample code
sounda_p = Sample_Load(SOUNDA);
if (sounda_p) Sample_Play(sounda_p,0,0);
else print("error",100,100,65556,screen_buffer_p,14);



not only does it not work, but it does not show the error either.... I also tried to pass fullpath(sounda_p) as well...

-Help, Please!
Thanks all, with some indepth reading etc, I have managed to get mikmod running correctly, mixing sfx and it's together, however I have noticed that there is about a 300ms delay before you hear the sound from calling it, so for some effects like explosions etc, I had to delay the visual effect ~300ms to get it to sync correctly, is there a way of overcomming this problem...

the following code show how I currently "set" mikmod:

Code:

MikMod_RegisterAllDrivers();
MikMod_RegisterAllLoaders();
md_mode = DMODE_SOFT_MUSIC | DMODE_SOFT_SNDFX;
md_mixfreq = 11025;
md_reverb = 0;
MikMod_Init("");

//load song 1 into buffer
load_song(1);

//Player_SetVolume(player.music_volume);
//load sfx
sound1_p = Sample_Load(fullpath(SOUND1));

//reserve 2 channels for sfx
MikMod_SetNumVoices(-1, 2);
MikMod_EnableOutput();


I thought it may have been a reverb thing, so I put reverb to 0, but it's still delaying.... ??

the doco for mikmod does mention that it uses a sound buffer, and the bigger the buffer, the less you have to call it, but I can't see any function / var to get it's size, assumably the smaller the better for mixing in sfx's ?, any suggestions

-Thanks, Brendan
#%#$%^, man I've just found this function in the header file for mikmod (nice of them to list it in the docs......has anyone played around with it, know a good value to set it too?....

MikMod_SetWinCEBufferSize(int BufferSize);

-Brendan
I read in the MikMod documentation that the larger the buffer you make, the less you have to call MikMod_Update(). I really havent played much with setting the buffer size though. If you have a large sound, i suppose it would atleast have to be that big or MikMod crashes(atleast on my jornada it does).

On another note, since youve been playing with it, does MikMod seem to make your wavs play background noise if played without music? Im not sure if theres something I can do about this.(phantom suggested 44hz sounds, wich I tried) The biggest problem I have, is I dont know if its just my device, or the code I have written.
It's probably just your device. Pushing stereo sound through a crappy little mono speaker degrades anything. If your device supports stereo through the headphone jack, then try listening to your game's sounds with headphones.