0
0

Hello i have some problems to play a stream using gtk and fmod.
I made a small interface with gtk and when i click on the button, i call a function to play the sound.
But my problem is that when i click nothing is done. So here is my function
[code:3adbru36]void on_play()
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound1;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;

/*
    Create a System object and initialize.
*/
result = FMOD_System_Create(&system);

result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL);
result = FMOD_System_CreateSound(system, "C:\\Program Files\\CodeBlocks\\codes\\sound.mp3", FMOD_HARDWARE | FMOD_LOOP_OFF, 0, &sound1);

result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, 0, &channel);

FMOD_System_Update(system);

Sleep(1);
result = FMOD_Sound_Release(sound1);
result = FMOD_System_Close(system);
result = FMOD_System_Release(system);

}
[/code:3adbru36]
Thank you if you can find the solution
titor

  • You must to post comments
0
0

What you do allow fmodex to play only for 1 millisecond, you will have to loop until the songs end or when the "stop" buttons is clicked (for example) or whatever logical action is done.

  • You must to post comments
0
0

Thank you very much. I found this code in the example folder, and i didn’t understand what this function sleep was supposed to do.
But i have another problem i erased this function from the code, but not any sound is played, only if i give a huge number to sleep.
Ex: Sleep(10000000000);

Do you now how to solve this problem?

And my program seems to bug while playing and it used 85 000 ko in the memory, and 99% of my cpu. I think it’s because of the initialisation of fmodex.
titor

  • You must to post comments
0
0

[quote:26jktsq2]
void on_play()
{
FMOD_SYSTEM *system;
FMOD_SOUND *sound1;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;

/*
    Create a System object and initialize.
*/
result = FMOD_System_Create(&system);

result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL);
result = FMOD_System_CreateSound(system, "C:\\Program Files\\CodeBlocks\\codes\\sound.mp3", FMOD_HARDWARE | FMOD_LOOP_OFF, 0, &sound1);

result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, 0, &channel);

int playing = 1;
do {
 FMOD_System_Update(system);
 FMOD_Channel_IsPlaying(channel, &playing);
} while playing; 

Sleep(1);
result = FMOD_Sound_Release(sound1);
result = FMOD_System_Close(system);
result = FMOD_System_Release(system);

}
[/quote:26jktsq2]

Btw, this is a blocked function, gtk will wait until on_play() return so here this mean when the song ends playing.
How i resolve this is using threads, i use one for all fmod ex related functions.

  • You must to post comments
0
0

init fmod when your program starts, release it when your program ends, and only create and play your sound in the on_play function

  • You must to post comments
0
0

Hum thank you for your answers.
to karlkox : what do you mean by using threads ?
What the function is supposed to return ?

  • You must to post comments
0
0

what he means:

your while loop won’t return until the sound is finished, so no other code can be executed in the same thread. as your GUI uses the same thread, you can’t do anything with your app when the sound plays.

so you can create another thread just to play the sound, but if you do it like I said you won’t have to, as fmod creates some threads internally to play the sounds.

  • You must to post comments
0
0

I had covered up three books on C++(past 4 years) and nowhere
i found a lesson on multi-threaded applications.In fact had I not learned
QT GUI library on my own , I would have known threads only in theory
my whole life . QT has nice "QThread" class which makes the extra
thread i need sometimes ๐Ÿ˜›

For GUI applications , the main thread(int main()) is your GUI thread.
In fact GUI thread is the main thread as a rule(in your main() function).
Rest heavy computing parts of the programs are threaded left-right ๐Ÿ˜€
so that the User Interface remains responsive and doesnt gets
locked up .

In fact , presently i am learning C# (2 huge books "Beginning Visual C# 2005" and "Professional C# 2005") and there also , nothing on creating
threads.
:roll:
Thanks !

  • You must to post comments
0
0

[quote:njk7vfj8]In fact , presently i am learning C# (2 huge books "Beginning Visual C# 2005" and "Professional C# 2005") and there also , nothing on creating
threads. [/quote:njk7vfj8]
You should have a look at [b:njk7vfj8]Chapter 13: Threading[/b:njk7vfj8], on page 349 ๐Ÿ˜‰

  • You must to post comments
0
0

Oh yes ! ๐Ÿ˜› I can be so ignorant sometimes . ๐Ÿ˜†
But its in the Second book and i have just completed first one .

Yes ,chapter 13 ,found it , It means this book has to be an exceptionally good one.

Regarding c/c++ i think that it is the Indian writers who miss out on
important topics like threading , virtual functions (i am from India).
Or probably they dont know anything advanced .

As far as I can say about my college Professors(all of them are Phd and M.Tech in Computer Science) , they dont have their even pointer basics clear ,leave alone anything like polymorphism . Virtual functions are
unknown to them , and ask them to implement exception handling in
front of a c++ program , and you are sure to be humiliated.
I wonder how can be India the 2 nd largest software producer (after US)
when such stupid teachers exist everywhere !

Regarding chapter 13 , Thanks ๐Ÿ˜‰

  • You must to post comments
0
0

[quote="Roma":3ujvtssj]Regarding c/c++ i think that it is the Indian writers who miss out on
important topics like threading , virtual functions (i am from India).
Or probably they dont know anything advanced .

As far as I can say about my college Professors(all of them are Phd and M.Tech in Computer Science) , they dont have their even pointer basics clear ,leave alone anything like polymorphism . Virtual functions are
unknown to them , and ask them to implement exception handling in
front of a c++ program , and you are sure to be humiliated.
I wonder how can be India the 2 nd largest software producer (after US)
when such stupid teachers exist everywhere ![/quote:3ujvtssj]

oO… I’ve heard Indian programmers are good…
Virtual functions belong to the basics of object oriented programming… they just have to know that…

  • You must to post comments
Showing 10 results
Your Answer

Please first to submit.