0
0

I programmed a small morse program which uses wave files for the beeps, but to save space, I want to create the beeps in realtime using fmod. I searched the forum for a solution, and this was the most promising code I found:

[code:3t5r0yco]
float freq = 1020.0;
signed char F_CALLBACKAPI streamcallback(FSOUND_STREAM *stream, void *buff, int len, int param)
{
int count;
static float t = 0; // time
signed short *buffer = (signed short *)buff;

float speed = freq / (float)FSOUND_GetOutputRate() * 6.28;

for (count=0; count<len>>1; count++)
{
*buffer++ = (signed short)(sin(t) * 32767.0);

 t += speed;

}
return 1;
}
[/code:3t5r0yco]

However, I quickly was plagued with timing problems. I needed to fiddle with Sleep(); functions and separate threads a lot to create blocking and non-blocking versions, but actually, I haven’t found a good solution for making functions like:
CreateNonBlockingBeep(int duration, float frequency);
CreateBlockingBeep(int duration, float frequency);

My program is Borland C++ based. Does anyone has an idea? Thanks a lot.

Greetz, Tjeerd

  • You must to post comments
0
0

I meant that when I call this function:

FSOUND_Stream_Play(FSOUND_FREE, stream);

Then the beep starts. When I want the beep to stop after one second, then I need to use this code:

FSOUND_Stream_Play(FSOUND_FREE, stream);
Sleep(1000);
FSOUND_Stream_Stop(stream);

But now the code is blocking. When I want a non-blocking version, I need to put that code in another thread. I was wondering whether I can put some code inside the callback function to specify how long the beep should play.

I have another problem. After the sound is playing for a minute or so, then suddenly the frequency of the sound changes… Also when the beep stops because of the Stop function, then the speaker makes a plop. Is it possible to fade the sound in and out?

I am not sure what the callback function actually does. It changes a variable which represents a sine at runtime, right?

Greetz

  • You must to post comments
0
0

Out of curiosity, couldn’t you just generate the whole pattern of beeps first, then play it? Why not insert silence instead of starting and stopping the soundwave?

  • You must to post comments
0
0

Ok Thanks. I’ll try it.

Tjeerd

  • You must to post comments
0
0

I have a problem with the latency of the stream method. When the user presses a specific key, the program must instantly generate a beep.

I can reduce some of the latency by starting the stream at the program startup, and fill the buffer with a sin wave instantly, when the user presses the beep key. However, with this method I still have too much latency.

My current solution with playing wav files is much faster but of course using wav files results in an unnecessary program file size.

How can I reduce the latency of the stream system so that it is as fast as: FSOUND_PlaySound()
with
FSOUND_SetBufferSize(50)

Thanks

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.