0
0

Hi, how are you.

I have a problem with a music player that i’m writing with fmod. This is the structure of the program:

This player have a gui, made with GTK, with two buttons (play, next).
I’ve created two threads, one is the gui that analize the user interaction, and other
is a thread that init a system fmod and update them with
"FMOD_System_Update".

The thread that init sound is:

[code:2ec9uoq5]FMOD_SYSTEM *ssystem; //global variable

void *init_sound_intf(void *obj)
{
FMOD_RESULT ret;
dlsystem dsystem = (dlsystem)obj;

    ret = FMOD_System_Create(&ssystem);

    if(ret == FMOD_OK) {

        ret = FMOD_System_Init(ssystem, 32, FMOD_INIT_NORMAL, NULL);
        if(ret == FMOD_OK) {
/*This is temporal*/    while( 1 ) {
                FMOD_System_Update(ssystem);
                Sleep(10);      
            }
        }
        FMOD_System_Close(ssystem);
        FMOD_System_Release(ssystem);
    }

return NULL;

}
[/code:2ec9uoq5]

When you click, for example the play button, this function is called by gui:

[code:2ec9uoq5]int playlist_play(dlsystem dsystem)
{
unsigned int id;
FMOD_RESULT ret;
char url[64];

    id = extract_id(dsystem->sqlsystem);
    snprintf(url, sizeof(url)-1, "http://11.11.11.11/mp3/0/%d.mp3", id);

    ret = FMOD_System_CreateSound(ssystem, url, FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0 ,&dsystem->dsound->sound);
    if( ret != FMOD_OK )
        printf("FMOD error! (%d) %s\n", ret, FMOD_ErrorString(ret));

    ret = FMOD_System_PlaySound(ssystem, FMOD_CHANNEL_FREE, dsystem->dsound->sound, 0, &dsystem->dsound->channel);
    if( ret != FMOD_OK )
        printf("FMOD error! (%d) %s\n", ret, FMOD_ErrorString(ret));

    return 0;   

}
[/code:2ec9uoq5]

The trouble is that sometimes the song that is been played sounds bad (like a scratched CD), some parts of the music are repeated for some time, then
the playback continues.

Maybe I do something bad? Need some buffer?

If you need more info, ask me.

Thanks a lot

  • You must to post comments
0
0

You cannot have system update in another thread.

  • You must to post comments
0
0

Hi, good morning.

I have a doubt. I want increase the stream’s buffer for have more margin to preload of sound.
I tried with this function: [code:1c43ajul]FMOD_System_SetStreamBufferSize[/code:1c43ajul] but it seems don’t work. For I want to do, this function is appropriate ?

Thanks a lot, regards

  • You must to post comments
0
0

[quote="piskoleber":g6queam6][quote="peter":g6queam6]A mutex is one approach. I haven’t used GTK but, most event driven gui libraries have some kind of mechanism for polling from the main thread. Quick google search for timer events turned up ‘g_timeout_add’, maybe calling System::update that way would be a better approach?[/quote:g6queam6]

Sorry, it was my mistake, i didn’t think in this way. I will read about ‘g_timeout_add’, maybe is better than mutex.

Thanks a lot[/quote:g6queam6]

If it’s for a gui/application, a mutex is fine, for a game or an application that calls fmod functions constantly/often, I would try to move the update call in the main thread…

In a windows window application, your peekmessage loop for example

System Update does not need to be called that often… You get a good 5 seconds of time before things start to act up… 30 seconds for my setup on my PC… so it’s fine to have it called in the main thread even if the code in the main thread may stall for a few seconds.

  • You must to post comments
0
0

Uhm, the problem is that my application analizes the gui(play buttons etc), and if i sleep the main thread for one second i think that this will be a "problem".
Maybe if i call fmod_system_update every 1ms it still works fine.

However, i think that the problem that sound sounds like scratched cd is not caused by fmod_system_update and the threads.

I put a little "qos" in my pc(for test my theory):

[code:1pzsedpr]tc qdisc change dev eth0 root handle 1:0 tbf rate 5kbit buffer 1600 limit 3000[/code:1pzsedpr]
5kbit is very hardcore, i know, but i wanted to try it.

Well, with this "qos", the sound sounds bad, very bad(scratched cd ), obviously because i use a stream and the bandwith is "inexistent", but If i load song in memory, the problem disappears.

Maybe i need amplify the buffer for the stream.

Thanks!

  • You must to post comments
0
0

[quote="icuurd12b42":13jkbvvr][quote="piskoleber":13jkbvvr][quote="peter":13jkbvvr]A mutex is one approach. I haven’t used GTK but, most event driven gui libraries have some kind of mechanism for polling from the main thread. Quick google search for timer events turned up ‘g_timeout_add’, maybe calling System::update that way would be a better approach?[/quote:13jkbvvr]

Sorry, it was my mistake, i didn’t think in this way. I will read about ‘g_timeout_add’, maybe is better than mutex.

Thanks a lot[/quote:13jkbvvr]

If it’s for a gui/application, a mutex is fine, for a game or an application that calls fmod functions constantly/often, I would try to move the update call in the main thread…

In a windows window application, your peekmessage loop for example

System Update does not need to be called that often… You get a good 5 seconds of time before things start to act up… 30 seconds for my setup on my PC… so it’s fine to have it called in the main thread even if the code in the main thread may stall for a few seconds.[/quote:13jkbvvr]

The application is a music player which reproduces music constanly (like a radio).
In the examples that come with fmod, i see that fmod_system_update is called every 10ms.
I moved fmod_system_update to the main thread (gtk calls a function every 10ms which this calls system_update function).

I thought that a mutex maybe is a big overhead for my application, because i lock the mutex every 10ms to call system_update.

Is an "error" call the fmod_system_update function every 10ms? I don’t understand very well the reason for call it more or less often

Thanks for your attention,

Regards

  • You must to post comments
0
0

I don’t know the underlying code. but, in therory, I assume the faster you call system update, the less the chances of other function reporting eroneous values… like getting to playing position for example.

In one of my apps, a simple music player with visualisation, when the application is not focussed, I sleep in my main thread for like 1 second. System update gets calle every second and I have no trouble, though in this state, all I do is play some muisic without querying anything else.

In games running at 60 fps and others running at 30 fps… You can see games running at 60 get their system update called faster than at 30. Still the system performs adequatly in both cases.

  • You must to post comments
0
0

[quote="peter":1oql0fl3]A mutex is one approach. I haven’t used GTK but, most event driven gui libraries have some kind of mechanism for polling from the main thread. Quick google search for timer events turned up ‘g_timeout_add’, maybe calling System::update that way would be a better approach?[/quote:1oql0fl3]

Sorry, it was my mistake, i didn’t think in this way. I will read about ‘g_timeout_add’, maybe is better than mutex.

Thanks a lot

  • You must to post comments
0
0

A mutex is one approach. I haven’t used GTK but, most event driven gui libraries have some kind of mechanism for polling from the main thread. Quick google search for timer events turned up ‘g_timeout_add’, maybe calling System::update that way would be a better approach?

  • You must to post comments
0
0

[quote="icuurd12b42":17b60erx]Why would you want to use a different thread? The problem is that you have calls that setup sounds start sounds in another thread, and system update in another. without any traffic control, you will have potential for both thread to step on each others toes…

I have safely called system update from another thread for when windows shows a modal dialog box.

You can use mutex to control the flow at the risk of slowing down the process… It depends what you do and how often you do it.[/quote:17b60erx]

Hi.

The function that starts the sound (create_sound and play_sound) only be called when a user click play button or next button. And the function that creates the fmod system and calls fmod_system_update is into a loop that only stop when user click "close" button. I read that the fmod_system_update function should be called quite often.
My aplication has one loop, the gui (gtk analizes the user interaction for some events, for example play button, next button, close button etc) and this is the reason because i put the fmod init and update system in a thread that contains another loop.

If i want make this thread safely, i could put a mutex like this:

In the thread that updates fmod:

[code:17b60erx]lock();
fmod_system_update
unlock();[/code:17b60erx]

And in the function that has been called when user click play button:

[code:17b60erx]lock();
create_stream
play_sound
unlock();[/code:17b60erx]

But i don’t know if this is a great overhead for aplication.
Thanks,

Regards

  • You must to post comments
0
0

Why would you want to use a different thread? The problem is that you have calls that setup sounds start sounds in another thread, and system update in another. without any traffic control, you will have potential for both thread to step on each others toes…

I have safely called system update from another thread for when windows shows a modal dialog box.

You can use mutex to control the flow at the risk of slowing down the process… It depends what you do and how often you do it.

  • You must to post comments
0
0

[quote="audiodev":8sfxadcn]All calls (init, update, createSound, getEvent) etc must come from the same thread or through a thread safe wrapper.[/quote:8sfxadcn]

Are you talking about mutex, no?

  • You must to post comments
0
0

All calls (init, update, createSound, getEvent) etc must come from the same thread or through a thread safe wrapper.

  • You must to post comments
0
0

The thread that calls FMOD_System_Update is the same thread that initializes it.

Is this a problem?

  • You must to post comments
Showing 13 results
Your Answer

Please first to submit.