0
0

Hi!

I use following code for mp3 playback
the code compiled with BC++5.02 and MSVC++ 7 versions
but every time windows Task manager shows %100 cpu usage
when fmod are running please help me!

pentium III 450, 192 mb ram, sb128, xp pro sp2
idle cpu usage is %4 to %8
if fmod runs, page file changes 3-4 mb

include <stdio.h>

include “fmod.h”

include “fmod_errors.h”

pragma comment( lib, “fmodbc.lib” )

//#pragma comment( lib, “fmodvc.lib” )

define TRUE 1

define FALSE 0

int channel = -1;

int main(void)
{
FSOUND_STREAM *stream;
FSOUND_SAMPLE *sptr;
char key;
if (FSOUND_GetVersion() < FMOD_VERSION)
{
printf(“Error : You are using the wrong DLL version!
You should be using FMOD %.02f\n”, FMOD_VERSION);
return 1;
}
FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND);
FSOUND_Stream_SetBufferSize(1000);

if (!FSOUND_Init(44100, 32, 0))
{
printf(“Error!\n”);
printf(“%s\n”, FMOD_ErrorString(FSOUND_GetError()));
FSOUND_Close();
return 1;
}
stream = FSOUND_Stream_Open(“….mp3”, FSOUND_NORMAL | FSOUND_MPEGACCURATE , 0, 0);

sptr = FSOUND_Stream_GetSample(stream);

if (sptr)
{
int freq;
FSOUND_Sample_GetDefaults(sptr, &freq, NULL, NULL, NULL);
printf(“Name : %s\n”, FSOUND_Sample_GetName(sptr));
printf(“Frequency : %d\n\n”, freq);
}
key = 0;
do
{
channel = FSOUND_Stream_PlayEx(FSOUND_FREE, stream, NULL, TRUE);
FSOUND_SetPaused(channel, FALSE);
} while (key != -1);
FSOUND_Stream_Close(stream);
FSOUND_Close();

return 0;
}

  • You must to post comments
0
0

this section of code is causing the high cpu usage:
[code:4dvpin5w]
do
{
channel = FSOUND_Stream_PlayEx(FSOUND_FREE, stream, NULL, TRUE);
FSOUND_SetPaused(channel, FALSE);
} while (key != -1); [/code:4dvpin5w]
becasue you are repeatedly calling fsound_play, better code would be some thing like this:
[code:4dvpin5w]
channel = FSOUND_Stream_PlayEx(FSOUND_FREE, stream, NULL, TRUE);
FSOUND_SetPaused(channel, FALSE);
do
{
wait(100);
} while (key != -1);
[/code:4dvpin5w]

  • You must to post comments
0
0

Lots of thanks

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.