|
Video files in Allgro? |
Kitty Cat
Member #2,815
October 2002
|
For Ogg music, you probably shouldn't load it all at once, anyway. I'll continue looking into this problem, but for now, you could try to do this to play the music: APEG_STREAM *stream = apeg_open_stream("15.ogg"); if(!stream) error("couldn't open 15.ogg because: %s", apeg_error); .. /* in main loop, regularly call: */ if(apeg_advance_stream(stream, TRUE) != APEG_OK) error("song stopped because: %s", apeg_error); /* if you're not looping, that can return APEG_EOF, which is not an error */ .. /* when done: */ apeg_close_stream(stream); stream = NULL;
-- |
Martano
Member #6,536
October 2005
|
I needed to change the error messages to: if(!stream){ set_gfx_mode(GFX_TEXT,0,0,0,0); allegro_message("couldn't open 15.ogg because: %s", apeg_error); exit(EXIT_FAILURE); }
, because it didn't recognized "error". |
Kitty Cat
Member #2,815
October 2002
|
You'd have to show more code. If the stream opened, and you regularly call that function, you should hear the music. Quote: it didn't recognized "error" It was psuedo code, letting you know to handle it like an error if that happened. -- |
Martano
Member #6,536
October 2005
|
Here is the function where I am using the command:
|
Evert
Member #794
November 2000
|
Call me slow, but I don't see any apeg_advance_stream() calls in that code... |
Martano
Member #6,536
October 2005
|
There is no "apeg_advance_stream()". What is it? I am only using: APEG_STREAM *stream = apeg_open_stream("15.ogg"); apeg_close_stream(stream); stream = NULL;
|
Evert
Member #794
November 2000
|
Quote: There is no "apeg_advance_stream()". What is it?
Kitty cat said: but for now, you could try to do this to play the music: APEG_STREAM *stream = apeg_open_stream("15.ogg"); Be a bit more careful about reading other people's posts (especially if they wrote the thing you're using)! Right now, all you're doing is reading the file from disk. You're not playing it, so it stands to reason that you don't hear any music playing when you run your code! |
Martano
Member #6,536
October 2005
|
Sorry. I don't know why I changed that part of the code. It is working now. Thanks again. ------------ How to set the volume of the song? |
Kitty Cat
Member #2,815
October 2002
|
Quote: How to set the volume of the song?
Use Quote: And is there a way to put an ogg file inside a datafile? Yes. Just put it in as a binary chunk, then read with either: /* Direct from disk: */ stream = apeg_open_stream("datafile.dat#object_name"); /* if loaded into memory: */ stream = apeg_open_memory_stream(datafile[object_name].dat, datafile[object_name].size); Then use apeg_advance_stream and apeg_close_stream as normal. -- |
Martano
Member #6,536
October 2005
|
What is a binary chunk? Because I couldn't use grabber to load the ogg. |
Kitty Cat
Member #2,815
October 2002
|
If you use dat, it should load it as binary automatically. Using the -t switch (-t VORB or -t VRBS) is probably a good idea, too. -- |
Martano
Member #6,536
October 2005
|
Thanks! Now I need to play a sound until the end and them continue the program. I was trying this: while(t < 10) { t++; if(apeg_advance_stream(stream, TRUE) != APEG_OK) { set_gfx_mode(GFX_TEXT,0,0,0,0); allegro_message("Nao pode tocar o som, porque: %s", apeg_error); exit(EXIT_FAILURE); } rest(1000); } But the "rest" cuts sound each second. It only works this way: while(t < 10000) { t++; if(apeg_advance_stream(stream, TRUE) != APEG_OK) { set_gfx_mode(GFX_TEXT,0,0,0,0); allegro_message("Nao pode tocar o som, porque: %s", apeg_error); exit(EXIT_FAILURE); } } But this would make the time to be different in each computer. |
Zaphos
Member #1,468
August 2001
|
How about: while((ret = apeg_advance_stream(stream, FALSE)) == APEG_OK) {} if (ret == APEG_ERROR) { set_gfx_mode(GFX_TEXT,0,0,0,0); allegro_message("Nao pode tocar o som, porque: %s", apeg_error); exit(EXIT_FAILURE); } So you keep calling the function until it returns with EOF or ERROR
|
Martano
Member #6,536
October 2005
|
Thanks! Now it is working! Well.... you all REALLY helped me! Look the size of this thread! -------- New problem I need to play a song while it shows a image, wait, and shows another image, wait.... But when I use the wait function, it cuts the song.
The song must be played since the: APEG_STREAM *stream = apeg_open_stream("musini.ogg"); until the last lines. |
Kitty Cat
Member #2,815
October 2002
|
You're not calling apeg_advance_stream anywhere. You need to call it regularly or else it won't get a new batch of samples to the card in time. -- |
Martano
Member #6,536
October 2005
|
I know. But I don't know where I should use it. |
Zaphos
Member #1,468
August 2001
|
options:
|
Kitty Cat
Member #2,815
October 2002
|
or: Also, the esperar(1/30) call isn't going to do anything. 1/30 = 0 to an int, so you're waiting 0 seconds (call clock(), call clock() again, and see that enough time has passed, and return immediately). -- |
Martano
Member #6,536
October 2005
|
Quote: (2) You can use a separate thread to play the music. How? Quote: (3) redesign the loop so it allows for what you need to do. How? |
vpenquerch
Member #233
April 2000
|
How to redesign the loop ? Start with the last loop that works for you, and think about where you can draw things without breaking the sound. If you know why the sound doesn't break with that particular loop, then you'll see how easy it is to add the draw code. But, for this, you need to understand why this loop works and some others you've tried do not. When you've understood this, if you don't already, you'll find it much easier to continue your program without breaking the sound play (or other things). |
Martano
Member #6,536
October 2005
|
In real I didn't understand how you can play a song using the "if" function. You are not sending a command, but just checking it. The command should come in "{}", after the "if()".At least this is what I know about the "if" function. But I liked the 2nd option, about a new thread, looks like very useful. But I have no idea about how to do it. |
Kitty Cat
Member #2,815
October 2002
|
if() isn't a function, it's something the compiler uses to branch code. You call apeg_advance_stream(stream, TRUE) in the if check, which the compiler knows to call that function and then check its return value against APEG_OK (and then gives the if() "command" a true or false value based on the comparison that's used to determine whether to execute the following code block or not). It would be easy to rewrite your main loops to call apeg's polling function, however it's your code, and I don't know what your ultimate goal is. You're the one most qualified to modify it. -- |
Martano
Member #6,536
October 2005
|
Got it! Thanks! (But I am still curious about the "2nd thread". Does anyone know a tutorial about it?) -------------------------------- EDIT: Errrrr. How to use the if(apeg_advance_stream(stream, TRUE) != APEG_OK) while showing this dialog: DIALOG dlg[] = { /* (proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */ { d_box_proc, 170, 215, 300, 50, 0, 16777215, 0, 0, 0, 0, NULL, NULL, NULL }, { d_text_proc, 180, 225, 250, 20, 0, 16777215, 0, 0, 0, 0, (void*)"Escreva o código para carregar:", NULL, NULL }, { d_edit_proc, 180, 245, 250, 20, 0, 16777215, 0, D_EXIT,20, 0, (void*)the_code, NULL, NULL }, { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL } }; do_dialog(dlg, 2);
|
Zaphos
Member #1,468
August 2001
|
You could make it a gui item like clock proc in excustom.c (see your allegro examples folder), and then call apeg_advance_stream when your procedure recieves MSG_DRAW and/or MSG_IDLE messages. As to the second thread stuff, for portable code you could use a pthreads library for windows, and for nonportable code you could use windows threads; pthreads has a tutorial here: [url http://www.cs.nmsu.edu/~jcook/Tools/pthreads/pthreads.html] and windows threads has a tutorial here: [url http://www.flipcode.com/articles/article_multithreading.shtml] pthreads code might look like this: void *playfunc(void *s) { while (apeg_advance_stream((APEG_STREAM *)s, TRUE) == APEG_OK) {} return NULL; } // and later, in main, to start the music: pthread_t music; pthread_create (&music, NULL, playfunc, stream); // and later if you want to wait for the music to end: pthread_join(music, NULL);
|
Victor Williams Stafusa da Silva
Member #4,212
January 2004
|
I saw that: This isn't good. It will pass zero to esperar() because the parameter is an int. You should do that: EDIT: Didn't read all the replies. Looks like Kitty Cat already said that. [The attack of the space bugs - Speedhack 2005] [Rambananas - Speedhack 2006] [Make clean - Speedhack 2009] [The source god - TINS 2010] |
|
|