Video files in Allgro?
Martano

Is there a way to play a video file ( like .avi ) in Allegro?

ReyBrujo

Yes, several. Apeg is the one that comes to my mind.

Kitty Cat

Note that APEG won't play AVI files. It will play MPEG-1 and Ogg Vorbis/Theora files, though.

Martano

Ogg? Can it play music files too?

Ariesnl

If you're making a freeware / opensource game you could use Fmod vor music and sound effects

Martano

I am making a small game, just for my friends. ;D

And I would like to play a video and some musics. I am using .wav files, but they are too big. Is there a way to use .gif files too?

Ariesnl

not that I know..

wav is good for soundeffects for other things ude MP3 or trackermusic ( mod s3m etc) midi sounds bad

Kitty Cat

APEG can play Ogg Vorbis audio/music too, yes.

Tobias Dammers
Quote:

And I would like to play a video and some musics. I am using .wav files, but they are too big. Is there a way to use .gif files too?

You do realize that .gif files are images (albeit with limited animation possibilities), not audio or video files?

Martano
Quote:

You do realize that .gif files are images (albeit with limited animation possibilities), not audio or video files?

Sure. ;D
But I would like to use .gif to save some space. Is there a way to do this?

Michael Jensen

There is a png library that you can use (which is much more flexible than gif, and about the same size) if you don't need animation, gif limits you to 256 colors anyway, why not use the built in pcx? (also loading gif animations would be a lot harder than putting a list of images into a single pcx file, the only limits that I know of with pcx is that allegro will only load 8 bit pcx files, no loss compared to gif tho) also pcx are RLE encoded so you see a huge compression compared to bmp. (png is still smaller)

Evert
Quote:

the only limits that I know of with pcx is that allegro will only load 8 bit pcx files

Eh?

PCX is a bad choice for true colour image files though... the RLE compression doesn't help as much as with 8 bit images. You also need to be careful about selecting what palette entries you use the most for a PCX file, otherwise you'll end up with a much larger file (I oncereduced a PCX file more than 50% in size by reshuffling the palette).

There is also a trick (that is seldom if ever used) that makes it possible to have more than 256 colours in one GIF image. I lost the link though.

Martano

So.... I tried to download the Apeg. But I found only the code, so needs to compile.... but as always.... ERRORS:
____________________________________________________

C:\Hangar6\apeg\main.cpp In function `void setenv(const char*, const char*, int)':

38 C:\Hangar6\apeg\main.cpp `_putenv' undeclared (first use this function)

C:\Hangar6\apeg\main.cpp In function `int check_obj_deps(char*, time_t)':

143 C:\Hangar6\apeg\main.cpp invalid conversion from `void*' to `char*'

__________________________________________________

Missing Library?
Is there a place where I can download the compiled version?

Kitty Cat

It looks like you're trying to compile cbuild.c as a C++ file, which won't work. Just use the makefile, it'll compile cbuild for you then you can run cbuild to build the library. You'll also need libogg, libvorbis, and libtheora to use Ogg media.

Martano

How to use the makefile?

Kitty Cat

Run 'make' or 'mingw32-make'.

Martano

I copied "make.exe" to the same folder where the "makefile" is. I ran the "make.exe" but it complains: "Couldn't find the file."

I tried with the "mingw32-make.exe", but got the same error.

Arthur Kalliokoski

The name of the makefile isn't makefile.txt or something, is it? If you're using windows then the file display junk might be hiding the extensions. Right click "makefile" and select properties to see true name.

Martano

There are 2 makefiles: "Makefile" and "Makefile.win".

Do I need to use any command with the "make.exe" or just run it?

Arthur Kalliokoski

Oh, Microsoft stuff... I've never had MS stuff, but I remember seeing a lot of references to "nmake" which I guess is the Microsoft equivalent to make.exe

Martano

...I am lost... :-[

I downloaded a program called "nmake" for Windowns 2000. But it didn't work. Is there a "nmake" for XP? ( My Windows is XP )

And.... isn't there an easier way to use apeg?

Kitty Cat

I'm lost. APEG has only one makefile, called Makefile. The make you run is the same one you used to build Allegro and the Ogg stuff. You don't need to copy it to APEG's directory because it should be in your PATH environment variable.

Michael Jensen

make will automatically load "makefile." from the directory you run it from (as in makefile with NO extension) to make anything else you need to supply a file name.

As KC already said you do NOT need it to be in the same folder; remove it now.

As for version of windows, make has nothing to do with the version of windows you have, but instead has to do with the version of the compiler it was designed for, nmake is with microsoft's visual c++, you should use the same make that you built allegro with (or whatever make APEG is compatable with...)

Quote:

PCX is a bad choice for true colour image files though... the RLE compression doesn't help as much as with 8 bit images.

That's a really good point.

Quote:

You also need to be careful about selecting what palette entries you use the most for a PCX file, otherwise you'll end up with a much larger file (I oncereduced a PCX file more than 50% in size by reshuffling the palette).

Unless you have no runs, or 90% of your colors are above like 240 (or so?) in the pallette this really isn't an issue; 99% of image conversions should be smaller than bitmaps, and I've never encountered one that wouldn't be, it really seems like you'd have to doctor it that way, or have an extreemly prominant background color as index 255.

Quote:

You'll also need libogg, libvorbis, and libtheora to use Ogg media.

One of the reasons that I complain that we don't have enough built into allegro, if your project uses APEG, now you also have to manually install libogg, libvorbis, libtheora (and any dependencies they have).... and ANYONE who wants to recompile your code not only needs allegro, but also libogg, libvorbis, libtheora (and any dependencies they have), and APEG.... and APEG is not an isolated case for this; there are many other libraries with nighmareish cascading trees of dependencies... :'(

edit: (Also consider, who knows what version of which library a specific library is dependant on? and NO it's not as simple as just downloading it and running make; first off it's finding the files to download, which I kid you not for some auxiallary libraries I gave up on... and some simply do not make(current build is broken) or are the wrong version... etc etc, I've run into MANY problems of this type before, and it's not just typing make.)

Evert
Quote:

Unless you have no runs, or 90% of your colors are above like 240 (or so?) in the pallette this really isn't an issue; 99% of image conversions should be smaller than bitmaps, and I've never encountered one that wouldn't be, it really seems like you'd have to doctor it that way, or have an extreemly prominant background color as index 255.

It can happen if you have an image with many colours. You won't get a 100% size increase from that though, mostly a 33%.
The image I had that I was refering to did seem that it was specifically tailored to be bad for PCX files - it had 63 colours in it, all of them above 192 (which is the magical number).

Quote:

One of the reasons that I complain that we don't have enough built into allegro

You're spoiled by Allegro having so few external dependencies. ;)
Anyway, we won't be including all sorts of thirdparty libraries into the Allegro distribution.

Kitty Cat
Quote:

if your project uses APEG, now you also have to manually install libogg, libvorbis, libtheora (and any dependencies they have).... and ANYONE who wants to recompile your code not only needs allegro, but also libogg, libvorbis, libtheora (and any dependencies they have), and APEG...

Dependancies can be a bitch, unfortunately. Some pacakge managers can help, by installing the dependancies before the requested package automatically (which is why I'd recommend distros like Gentoo or Sourcemage). Unfortuantely Windows isn't very well off in this regard, not only by not having a package manager, but also by having a crippling shell. You can use MSYS, which I was able to use to build libogg/libtheora/libvorbis/etc, but that would be yet another dependancy..

And this is why Allegro doesn't support PNG or ZIP or any of that stuff built in, or else it'd have the same dependancy issues. Dynamicly loading shared libs would absolve the need for them to be required at compile time (and thusly become a run-time thing), but that will only work on platforms that can use shared libs and would lock your program into needing the shared libs without any easy way of staticlinking them.

Michael Jensen
Quote:

The image I had that I was refering to did seem that it was specifically tailored to be bad for PCX files - it had 63 colours in it, all of them above 192 (which is the magical number).

I guess that's kind of my point -- unless your image converting program is mega crazy that should never happen! :P

Quote:

Anyway, we won't be including all sorts of thirdparty libraries into the Allegro distribution.

Of course not, and you wont be doing what I want either (building that functionality into allegro itself) because that would also be crazy.

Quote:

Dynamicly loading shared libs would absolve the need for them to be required at compile time (and thusly become a run-time thing)

YOU FREAKING GENIUS! NOW GO AND IMPLIMENT IT!

Quote:

but that will only work on platforms that can use shared libs and would lock your program into needing the shared libs without any easy way of staticlinking them.

are there any besides DOS? I vote drop DOS... on the other hand you could always impliment this as an add-on library (sadly it makes half an ounce of sense, in that you'd only ever have to build one library, and just download .so's .lib's .a's or .dll's for something, and you could use it right out of the box.)

It's 1:45 am, isn't it? Can you tell? ;)

edit:

Quote:

You're spoiled by Allegro having so few external dependencies.

Allegro has external dependencies? ???

Actually I'm spoiled by the .NET framework/development environments with it's really tight debugger, and all kinds of autocompletion/intellisense and even autoformatting options! (that work!) 8-)

Evert
Quote:

Of course not, and you wont be doing what I want either (building that functionality into allegro itself) because that would also be crazy.

Well, we're not going to reinvent the wheel if that's what you mean.
But it simply becomes unwieldy to have that many external dependencies, not to mention the sheer size of the download. That's not saying someone can't make an Allegro package that contains it all, but we won't be the ones doing it.

Quote:

I vote drop DOS...

We did. Or at least we did unless someone can (and wants to) do the the work required to port the DOS drivers to the new API.

As for adding functionalty at runtime by dynamic loading of shared libraries, it sounds nifty. We need a good way to report to the user what is and isn't available at runtime though, so that he or she can respond appropriately.

Quote:

It's 1:45 am, isn't it?

No, it isn't. It's 11.15 am.

Quote:

Allegro has external dependencies?

Sure it does. On Windows, it's limited to the DirectX development headers and standard Win32 libraries; in *NIX it has loads of optional dependencies: X11 with a load of extensions (this is the main dependency), ALSA, aRts, SVGALib, fbdev, pthreads(actually, this is required)...
You normally don't notice that many of these dependencies are there because they're pretty much installed anyway or, in UNIX, the corresponding driver is simply not build. But the most common problems people run into when compiling Allegro are missing DirectX headers (in Windows) or missing X11 development libraries (in *NIX).

HoHo
Quote:

are there any besides DOS?

I think original Quake used some magic to get something similar to dynamic linking work in dos.
[edit]
but of course that is not saying that allegro devs should do that too

Kitty Cat
Quote:

YOU FREAKING GENIUS! NOW GO AND IMPLIMENT IT!

It's not so clear-cut, unfortunately. Theoretically, it would work. But to do so, I'd have to copy out the exposed/used structures and typedefs. This is where undefined exposed structures (or whatever the name is) come in handy, because you'd just have the structure name, and you'd be basically dealing with pointers, while using accessor functions from the lib to get/set the data. The problem with defined exposed structures is if the size or member arrangement ever changes, the ABI instantly breaks and you need to recompile. In this way I hope Allegro's new API will allow run-time dynamic loading, but that's neither here nor there for this topic..

The problem is, and I didn't think about this 'til after the last post, is that libogg, libvorbis, and libtheora aren't designed to be dynamicly loaded like that. They have exposed structures that you directly access. libogg and libvorbis may be used so much that changing the structures would be devestating to a good number of programs that use the shared lib/dll (and thus should be okay to just copy the structures), but I don't believe libtheora is at that point yet.

Michael Jensen
Quote:

Well, we're not going to reinvent the wheel if that's what you mean.

Right, I pointed out that either end of the stick is either out of allegro's scope, or just plain crazy.

Quote:

We did. Or at least we did unless someone can (and wants to) do the the work required to port the DOS drivers to the new API.

Are you talking allegro 5? Tight.

Quote:

No, it isn't. It's 11.15 am.

Obviously you're not in Seattle right now, are you? And it's 3:11 AM now, so there.

Quote:

Sure it does.

Never thought of it like that...

Quote:

It's not so clear-cut, unfortunately. Theoretically, it would work.

Don't take it personal KC, I was j/k. Altho if the person to write such a library would come up with a standard struct definition protocol, and the dll's to be plugged into this library all supported that struct definition protocol (possibly supplying an emulation/translation layer), and it was FAST.... well then. But also what if santa clause could fly around the world 200 bazillion times a second, and I were able to do well on my japanese test tomorrow.... today... crap time for bed... goodnight.

HoHo
Quote:

Are you talking allegro 5? Tight.

I think he meant 4.3

Martano

Now I am really lost.... :o

What do I need to do to use APEG?
I have the "make.exe" that came with Dev-C++ ( I think ). Should I use a shell to run it? What should I type?

Michael Jensen
Quote:

I think he meant 4.3

There's an API change in 4.3?

Andrés: Sorry for taking your thread so off-topic, I'm a troll :(! Anyway, does APEG come with a readme.txt or buildme.txt or something?

Martano
Quote:

Andrés: Sorry for taking your thread so off-topic, I'm a troll ! Anyway, does APEG come with a readme.txt or buildme.txt or something?

No problem. ;D

Yes, it have "apeg.txt".
But it says:

"To build APEG, first run make to compile a CBuild executable.If you have an sh-compatible shell, you can also run the cbuild.csource file directly, instead of creating the executable. You cancheck 'cbuild--help' for a list of available options. Now, runcbuild and let it do its thing."

But how to run "make"?

Kitty Cat
Quote:

But how to run "make"?

The same way you did when you built Allegro and the Ogg/Vorbis/Theora libs. Open a command shell, switch to the directory APEG is in, and run make. As long as it's in your path , it'll run from there.

Jonny Cook

If you want, you can just download the binaries here. I compiled it a while ago and I had some problems with it too. Hope this helps.

Tobias Dammers

No. Someone not capable of running make does not deserve binaries. Kidding... but I do have a point, don't I?

Randal Stackpoole

Everyone should be accessible to it. Even Christopher Reeve.

Evert
Quote:

There's an API change in 4.3?

4.3 is the `gradually change Allegro 4.2's API into the new Allegro5 API' branch. So yes, there is.

Martano

I tried to run "make" again, but still got errors.
So I downloaded the binaries. (Huge thanks for them! ;D)

But "apeg.txt" says about an "CBuild executable", where is it?

Michael Jensen

Since you have the binaries you probably don't need it; it sounds like you run make to get cbuild, and you run cbuild to get the binaries.

Martano

But I need to include "<apeg.h>", and I have no "apeg.h". :'(

Derezo

Yes.
"apeg.h" means that apeg.h is in the same directory as the source.
<apeg.h> means that it would be in your compiler's include directory.

Quote:

Everyone should be accessible to it. Even Christopher Reeve.

You do know he's been dead for quite some time, right? :-/

Michael Jensen

Right, so the binaries would be JUST the part that is compiled. Apeg.h should be included in the source distro, as it wouldn't be modified at all during the build process, you should just manually copy it to your compiler's include directory.

Martano
Quote:

Yes.
"apeg.h" means that apeg.h is in the same directory as the source.
<apeg.h> means that it would be in your compiler's include directory.

Sorry, I meant: I don't have the apeg.h file. And the apeg.txt says that I will need it to use APEG.

-------------------------------------
EDIT:

Quote:

Right, so the binaries would be JUST the part that is compiled. Apeg.h should be included in the source distro, as it wouldn't be modified at all during the build process, you should just manually copy it to your compiler's include directory.

I'm dumb!, I didn't see that. ;D

Thanks to everyone! I will try it.

Michael Jensen

Sorry if I wasn't clear, it should be in the source package, somewhere.

Martano
Quote:

I'm dumb! I didn't see that.

:o

COOL!

I typed: L o l , I didn't see that.

And it shows: I'm dumb! I didn't see that.

:D

_____________________________________________

EDIT:

I copied the apeg.h to the include folder. Changed the linkers to:

libapeg.a
libogg.a
libtheora.a
libvorbisenc.a
libvorbis.a
-lalleg

And I am trying to compile one of the examples (exsimple.c) that comes with APEG. But I am having many of these errors:

[Linker error] undefined reference to `pack_fopen_vtable'

Did I do something wrong about the linkers?

Kitty Cat
Quote:

[Linker error] undefined reference to `pack_fopen_vtable'

Do you have Allegro 4.2?

Martano

No.... I have Version 4.0.3

Kitty Cat

You need 4.2 (or a late 4.1 WIP, but there's no reason for that).

Martano

I downloaded "all420.zip" and unzipped it in my allegro folder, overwriting all. But still get the same errors.

Victor Williams Stafusa da Silva
Andréas Martano said:

I downloaded "all420.zip" and unzipped it in my allegro folder, overwriting all. But still get the same errors.

Did you runned "fix", "make" and "make install"?

Evert

Just grab a binary package from the files section of Allegro.cc

Thomas Fjellstrom

Also, don't just overwrite, delete the original folder, then uncompress the new. Otherwise things will screw up.

Martano

I always get an error when trying to run make.

But the binaries in the download page are from 4.0.3

....too late already overwrote them. :-/

--------------------------------------------------

Found them! Found the binaries for 4.2 .
Thanks. I am downloading them.

Evert
Quote:

I always get an error when trying to run make.

What's the error message and how do you run make?

Quote:

....too late already overwrote them.

Not a problem. Just delete the directory tree and unpack a clean package.

Martano
Quote:

What's the error message and how do you run make?

I open a shell, go to the makefile folder and type: makefile
Then it says: Don't recognize the file.
I tried to type: run makefile
Then it says: Don't recognize 'run'.

After I tried to change the name of the makefile to "makefile.exe". And used the shell again. With the APEG makefile it complains about a fatal error. With the Allegro makefile it doesn't complain, but do nothing (at least I saw no change).

----------------------------------------------

I copied Allegro 4.2 to the right folders and I am getting these errors now:

[Linker error] undefined reference to `oggpackB_readinit'

What is the mean of "Linker error" is it about the includes, linker (-lalleg), or what?

Michael Faerber

Do not rename Makefile to Makefile.exe!!

Instead you have to run an existing make.exe or mingw32-make.exe in the directory where the Makefile is located.

Example:

Your mingw32-make.exe is in C:\MINGW\BIN. Your Makefile is in C:\ALLEGRO.

You have to open a command line window and type:

CD C:\ALLEGRO
C:\MINGW\BIN\mingw32-make.exe

Evert
Quote:

I open a shell, go to the makefile folder and type: makefile
Then it says: Don't recognize the file.
I tried to type: run makefile
Then it says: Don't recognize 'run'.

Ok, have you read the instructions in allegro/doc/build/ (pick the one for your compiler, probably MinGW or MSVC)?
How you should run make and install Allegro is explained there (the short answer is what Michael said, but you may want to read the instructions anyway).
You won't need this if you already installed a binary package, but it wouldbe good to read it at least once anyway.

Martano

Thanks for the explanation. :)

But now I am having only this error when compiling the example code:

C:\Dev-Cpp\Meus\ABCD\Makefile.win [Build Error] [Testes.exe] Error 1

If I delete the:

libapeg.a
libogg.a
libtheora.a
libvorbis.a
libvorbisenc.a

from the linker, the error disappears. But I get "linker errors".

-----------------------------------------

Now I copied the APEG binaries to the same folder of the test project.
And I am getting this kind of errors:

[Linker error] undefined reference to `oggpackB_read'

I am not even using the command: oggpackB_read

Kitty Cat

You should probably show us the actual error. Saying that removing the libs from the linker removes the errors but gives you errors doesn't make much sense.

PS. you normally use -lname to specify a library (libname.a) on the command line.

Victor Williams Stafusa da Silva

Sorry to saying that in this form, but its looks like that you fuked up your compiler completely deleting, renaming and replacing files when you shouldn't do that. And fuked allegro too.

I recommed to delete your compiler and your allegro and reinstall they from the start...

Martano

I tried to put a "-" before the "libapeg.a", but got an error saying that couldn't find: -libapeg.a

----

The problem is:

If I have:

libapeg.a
libogg.a
libtheora.a
libvorbis.a
libvorbisenc.a
-lalleg

in the linkers, I get many errors of this type:

[Linker error] undefined reference to `oggpackB_readinit'
[Linker error] undefined reference to `oggpackB_read'
[Linker error] undefined reference to `oggpackB_read'
more undefined references to `oggpackB_read' follow

-

If I put only:

-lalleg

int the linker, I get only these errors:

C:\Dev-Cpp\Meus\ABCD\testes.o In function `Z13_mangled_mainiPPc':
[Linker error] undefined reference to `apeg_play_mpg'
[Linker error] undefined reference to `apeg_error'
C:\Dev-Cpp\Meus\ABCD\testes.o ld returned 1 exit status
C:\Dev-Cpp\Meus\ABCD\Makefile.win [Build Error] [Testes.exe] Error 1

-

The code is:

1#include <string.h>
2#include <stdio.h>
3 
4#include <allegro.h>
5#include "apeg.h"
6 
7 
8int main(int argc, char *argv[])
9{
10 int ret, depth;
11 
12 if(allegro_init() != 0)
13 {
14 fprintf(stderr, "Error initializing Allegro: %s\n", allegro_error);
15 return -1;
16 }
17 
18 // Check to make sure we have enough cmd-line args
19 if(argc < 2)
20 {
21 allegro_message("Usage: %s <filename.mpg>\n"
22 " <filename.mpg> can be either a file or an embedded datafile object.\n",
23 argv[0]);
24 
25 return 1;
26 }
27 
28 install_timer();
29 
30 install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL);
31 
32 // Set gfx mode
33 depth = desktop_color_depth();
34 if(!depth)
35 depth = 8;
36 
37 set_color_depth(depth);
38 if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0)
39 {
40 if(set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0) != 0)
41 {
42 allegro_message("Couldn't set mode 640x480x%i:\n%s\n", depth,
43 allegro_error);
44 return -1;
45 }
46 }
47 clear_to_color(screen, makecol(0, 0, 0));
48 
49 install_keyboard();
50 
51 ret = apeg_play_mpg(argv[1], screen, FALSE, NULL);
52 if(ret == APEG_ERROR)
53 {
54 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
55 allegro_message("APEG Error: %s\n", apeg_error);
56 }
57 
58 return ret;
59}
60END_OF_MAIN()

Kitty Cat
Quote:

I tried to put a "-" before the "libapeg.a", but got an error saying that couldn't find: -libapeg.a

Becuase that's not right. The lib<name>.a files should be in your compiler's lib directory, and you link with them using -l<name> (similar to how Allegro is liballeg.a and you link with -lalleg).

Martano

Thanks again.

But now I am getting only this error:

C:\Dev-Cpp\Meus\ABCD\Makefile.win [Build Error] [Testes.exe] Error 1

I will try to reinstall Dev and Allegro like Victor said.

Kitty Cat
Quote:

But now I am getting only this error:

C:\Dev-Cpp\Meus\ABCD\Makefile.win [Build Error] [Testes.exe] Error 1

That's not the error. That just says that there was an error. The actual error should be before that.

Martano

But the compile tab says only that.

The Compile Log says:
__________________________________

Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Meus\ABCD\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Meus\ABCD\Makefile.win" all
g++.exe -D__DEBUG__ testes.o -o "Testes.exe" -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/Meus/allegro/lib" -L"C:/Dev-Cpp/lib" -l<libapeg.a> -l<libogg.a> -l<libtheora.a> -l<libvorbis.a> -l<libvorbisenc.a> -lalleg -lgmon -pg -g3

O sistema nÆo pode encontrar o arquivo especificado. (The system couldn't find the file)

make.exe: *** [Testes.exe] Error 1

Execution terminated
_________________________________________

Kitty Cat

It can't find the libs. Double check those -l switches, and see why they aren't the same as liballeg.a/-lalleg

Martano

The linkers that I am using are:

-l<libapeg.a>
-l<libogg.a>
-l<libtheora.a>
-l<libvorbis.a>
-l<libvorbisenc.a>
-lalleg

Kitty Cat

Reread my post. :)

Quote:

It can't find the libs. Double check those -l switches, and see why they aren't the same as liballeg.a/-lalleg

Martano
Quote:

Reread my post.

Quote:
It can't find the libs. Double check those -l switches, and see why they aren't the same as liballeg.a/-lalleg
--

Sorry... I didn't understand it. :-[

What do you want to say with "double check" and "why they aren't the same"?

Kitty Cat

Well, to use liballeg.a, you use -lalleg. So, to use libapeg.a, you use...?

Martano

-lapeg ?

Didn't work :-[ :

cannot find -lapeg

I will try to reinstall.

Michael Jensen
Quote:

But the compile tab

I didn't know the command line had a compile tab... anyway let us know what happens.

Martano

APEG.txt:

"Windows users: If you're going to link against the static version of
Allegro, you'll need to create another lib of APEG. First you should run
'cbuild clean' to rid your drive of the object files (so they will
rebuild) and the temp lib. Then set the environment variable STATICLINK
(or pass --enable-static), followed by 'cbuild' and 'cbuild install'.
This will create apeg_s for you to use when linking with alleg_s."

Do I need to do that? Because I have only the binaries, and not 'cbuild' and 'cbuild install'.

------------

I reinstalled XP, dev-cpp, allegro (copied the binaries to "C:\Dev-Cpp\include" and "C:\Dev-Cpp\lib", and the 3 ".dll" files to the folder of my project) and APEG (copied the ".h" files to "C:\Dev-Cpp\include", the ".a" files to "C:\Dev-Cpp\lib", and the ".dll" files to my project folder).

Then I changed the linkers of my project to:

-lapeg
-logg
-ltheora
-lvorbis
-lvorbisenc
-lalleg

But when I try to compile I receive many errors of this type:

[Linker error] undefined reference to `oggpackB_readinit'
[Linker error] undefined reference to `oggpackB_read'
[Linker error] undefined reference to `oggpackB_read'
more undefined references to `oggpackB_read' follow
[Linker error] undefined reference to `oggpackB_readinit'
[Linker error] undefined reference to `oggpackB_read'

The problem is, as you can see in the code showed in previous post, I am not using any "ogg". But when I try to delete the linkers related to APEG, I get only these errors:

C:\Dev-Cpp\Meus\ABCD\testes.o(.text+0x1a9) In function `Z13_mangled_mainiPPc':
[Linker error] undefined reference to `apeg_play_mpg'
[Linker error] undefined reference to `apeg_error'
C:\Dev-Cpp\Meus\ABCD\testes.o(.text+0x1a9) ld returned 1 exit status
C:\Dev-Cpp\Meus\ABCD\Makefile.win [Build Error] [Testes.exe] Error 1

These errors make sense, because I AM using `apeg_play_mpg' in the code.
When I add the linkers, the `apeg_play_mpg' errors are solved, but I gain the "ogg" errors.

I hope this explain all the problem.

Evert

Try permuting the order in which you link the libraries. In particular, put libogg.a before libapeg.a
EDIT: actually, try putting libapeg.a just before liballeg.a.

Martano

Now got more errors:

[Linker error] undefined reference to `vorbis_block_clear'
[Linker error] undefined reference to `vorbis_dsp_clear'
[Linker error] undefined reference to `ogg_stream_clear'
[Linker error] undefined reference to `ogg_sync_clear'
[Linker error] undefined reference to `theora_clear'
[Linker error] undefined reference to `theora_info_clear'

...

Michael Jensen
Quote:

I reinstalled XP

Why?

Quote:

Do I need to do that? Because I have only the binaries, and not 'cbuild' and 'cbuild install'.

No, because you have the binaries, you do not have to build the package.

Quote:

Then I changed the linkers of my project to:

-lapeg
-logg
-ltheora
-lvorbis
-lvorbisenc
-lalleg

that's good, just make sure that you change them to the order you need them in, as evert alluded to.

Quote:

But when I try to compile I receive many errors of this type:

[Linker error] undefined reference to `oggpackB_readinit'
[Linker error] undefined reference to `oggpackB_read'
[Linker error] undefined reference to `oggpackB_read'
more undefined references to `oggpackB_read' follow
[Linker error] undefined reference to `oggpackB_readinit'
[Linker error] undefined reference to `oggpackB_read'

Right, so the apeg library is using the ogg library, so I belive you want to include the -logg/vorbis/theora before -lapeg.

Quote:

C:\Dev-Cpp\Meus\ABCD\testes.o(.text+0x1a9) In function `Z13_mangled_mainiPPc':
[Linker error] undefined reference to `apeg_play_mpg'
[Linker error] undefined reference to `apeg_error'
C:\Dev-Cpp\Meus\ABCD\testes.o(.text+0x1a9) ld returned 1 exit status
C:\Dev-Cpp\Meus\ABCD\Makefile.win [Build Error] [Testes.exe] Error 1

Right, like you said. That makes sense.

So, even if conditional logic prevents a call from ever happening (ex: when you load your video, it's not ogg/theora/vorbis format), for your code to link properly all of the external dependencies must be known to the linker. So your project is using apeg, which is using (conditionally) ogg/vorbis/theora, etc...

Martano

I changed the order, but only got more kinds of errors:

[Linker error] undefined reference to `vorbis_block_clear'
[Linker error] undefined reference to `vorbis_dsp_clear'
[Linker error] undefined reference to `ogg_stream_clear'
[Linker error] undefined reference to `ogg_sync_clear'
[Linker error] undefined reference to `theora_clear'
[Linker error] undefined reference to `theora_info_clear'

Now not only "ogg", but "theora" and "vorbis" are in conflict too.

Kitty Cat

This is the order APEG uses for the examples:
-ltheora -lvorbis -lvorbisenc -logg -lapeg -lallegTry that.

Martano

:'(

Still got the same errors (about vorbis, theora and ogg).

Michael Jensen

it sounds like something else is using theora. vorbis, and ogg, that is being referenced before they are....

Kitty Cat

Wonder if it has anything to do with the fact that APEG's precompiled, and conflicting with the existing Ogg libs.

Michael Jensen

Right, maybe if it was compiled against a different version, then no matter what order he puts them in, it won't recognize ogg/theora/vorbis, etc because they're the wrong version. Correct?

Martano

So.... I need compile APEG.

Trying again:
______________________________________________________

C:\Hangar6\apeg>c:\dev-cpp\bin\mingw32-make.exe
cc -W -Wall -Werror -02 cbuild.c -o cbuid
process_begin: CreateProcess((null), cc -W -Werror -02 cbuild.c -o cbuild, ...) failed.
make (e=2): The system couldn't find the file.
c:\dev-cpp\bin\mingw32-make.exe: *** [cbuild] Error 2

C:\Hangar\apeg>

______________________________________________________

Got the same error as before. :-/
I still don't know how to run "make".

Kitty Cat

There's a small bug in the Makefile. Edit it and change $(MINGW) to $(MINGDIR) on the first line.

Or you can compile and run cbuild manually:

gcc -O2 -W -Wall cbuild.c -o cbuild.exe
cbuild.exe

Quote:

I still don't know how to run "make".

That's what you're doing when you run mingw32-make.exe.

Martano

I tried to correct the make file, but got the same error.
Then used the "gcc" command. It complained that didn't know the "-02" variable. So I tried without the "-02", and it created the "cbuild.exe" file. So I run the "cbuild.exe", but it showed many errors.
Please see attached file for a screen-shot with the errors.

ReyBrujo

It seems you need to download and compile the ogg vorbis library. Also, you need to set your MINGDIR variable to point where you have the gcc.exe file.

Kitty Cat

Okay, there's a few problems with the cbuild script (it should've stopped after complaining about MINGDIR), but the underlying problem is that MINGDIR isn't set. I don't quite remember h ow to set it in Windows... I think it's right-click My Computer->Properties->Advanced->Environment Variables. Set it to your base MinGW dir (C:\Dev-Cpp in this case, I think). As well, make sure C:\Dev-Cpp\bin is the first thing in your path.

Also, that's -O2, not -02 (capital letter o, not the number zero).

EDIT: I just uploaded APEG 1.1.1 (check my sig), which should fix the makefile and script issues. You'll still need to get the Theora, Vorbis, and Ogg libs and headers installed if you want support for them, though.

Martano

My MINGDIR was set to "C:\Dev-Cpp". I changed it to "C:\Dev-Cpp\bin", but got the same errors.
So downloaded the new APEG 1.1.1 and tried to run make in it. But got the same errors again. Then tried to run the "gcc ...." command, but now it stopped saying:
_____________________________________________

Testing for Xv support... tmp.c:2: error: syntax error before "tmp"
tmp.c:2:168: invalid suffix "$" on integer constant
not found

Your MINGDIR environment variable is not set!
_____________________________________________

But the variable IS set. :-/

-----------------------------------------------------------
EDIT:
Oh! Got it!
The MINGDIR variable was at my "System Variables", I created the same variable, but now at "Variables for users". Now "make" worked!

I am still trying to correct the problem with the libraries.
-----------------------------------------------------------
EDIT:
Ok, how do I compile ogg, theora and vorbis?
There are many makefiles, but they are ".am" and ".in"
I tried to read the docs, but found texts only about the commands.

Victor Williams Stafusa da Silva
the APEG Makefile said:

ifneq ($(MINGW)$(DJGPP),)

Shouldn't it be "ifeq"?

Kitty Cat
Quote:

Shouldn't it be "ifeq"?

No. I want that section to run when MINGDIR or DJDIR does not equal nothing.

Quote:

Ok, how do I compile ogg, theora and vorbis?

Get a sh-compatible shell (such as the one that comes with MSys). Then you can run the configure script and then make.

Michael Jensen

you might be able to download binaries of those libaries, since I'm assuming that's all you need, and you can compile apeg agains them; also if you're not going to use that functionality, you can disable it before compiliing, and then you will not need them.

Quote:

the "-02" variable

As KC already said it's -O2; but also it means to use a specific type of optimization, there is an -O1 also. I belive -O2 is for speed...?

Quote:

I don't quite remember h ow to set it in Windows

Should be in the allegro instructions...

Quote:

Oh! Got it!

RIGHT ON! 8-)

Kitty Cat
Quote:

you might be able to download binaries of those libaries, since I'm assuming that's all you need

Last time I looked, I wasn't able to find binaries. :-/ No official ones, anyway.

As for optimization switches:

  • -O0 - Turn off optimizations. Default

  • -O1 - Light optimizations for speed

  • -O2 - More optimizations

  • -O3 - Heavy optimization. Can potentially break code or cause a performance hit

</li>
You can only use one. If you specify more than one, the last one specified is used.

Michael Jensen

Hmm... I did't know that about -03 ... I wonder if that's what dev-cpp used by default in a certain 4.x version...

I had downloaded it and compiled a working game with it (that was my own, at the commandline I was passing in -O2); but it crashed left and right, and had all kinds of issues when compiled by dev-cpp's gcc, which also liked to pass in about a page and half of other wierd ass arugments...

moral: don't use dev-cpp! :o

Kitty Cat

Note that it's rare for -O3 to cause a crash. The more code trickery you use, the more likely it is to happen, but under normal cirumstances it's fine. Generated code speed is another issue, though. That depends greatly on the code and the processor.

Martano
Quote:

Then you can run the configure script and then make.

I tried to type "configure", but it didn't recognize the command.

Kitty Cat

In a sh-shell, you need to use ./configure

Martano

I am using the shell that comes with Windows XP.
Used the "cd" command until the "libogg-1.1.2" folder.
There tried:

./configure
/configure
configure

But I got the same answer:

'....' is not recognized as a internal or external command or an operational program.

Kitty Cat
I said:

Get a sh-compatible shell (such as the one that comes with MSys). Then you can run the configure script and then make.

Martano
Quote:

I said:
Get a sh-compatible shell (such as the one that comes with MSys). Then you can run the configure script and then make.

Where can I get a sh-compatible shell?

gnolam
Kitty Cat said:

such as the one that comes with MSys

Martano

???

But....what is MSys?
Windows?
Why isn't it working?

Zaphos

MSYS is a part of MinGW: http://www.mingw.org/msys.shtml
You can't use the windows shell to run scripts written for unix shells (including configure scripts), so you need to use MSYS or something equivalent.

Martano

Ok, thanks, I downloaded MSys.
Read the "readme".
But HOW DO I USE THAT?

:o

Zaphos

Use what? MSYS? It's a shell. You run it. It gives you a prompt. You type "cd c:", then us cd to navigate to the library directory. Then you type "./configure".

Martano

OHHHHHHHHHHHH!

Thanks! I was typing "c:" only. ;D

It is too late here, need to sleep.
I will post tomorrow.
Opsss! (Today is tomorrow)
I will post later.

------------------------------------------

EDIT:

Ok, compiled ogg using the "./configure" and "make" commands.
Then tried to compile theora and vorbis the same way, but got an error that says I need to install ogg.
I tried to run "install" in the ogg folder, but got an error about "few arguments". So typed "install --help". It says:
_____________________________________________________
Usage: install [OPTION]... SOURCE DEST (1st format)
or: install [OPTION]... SOURCE... DIRECTORY (2nd format)
or: install -d [OPTION]... DIRECTORY... (3rd format)
In the first two formats, copy SOURCE to DEST or multiple SOURCE(s) to
the existing DIRECTORY, while setting permission modes and owner/group.
In the third format, create all components of the given DIRECTORY(ies).

--backup[=CONTROL] make a backup of each existing destination file
-b like --backup but does not accept an argument
-c (ignored)
-d, --directory treat all arguments as directory names; create all
components of the specified directories
-D create all leading components of DEST except the last,
then copy SOURCE to DEST; useful in the 1st format
-g, --group=GROUP set group ownership, instead of process' current group
-m, --mode=MODE set permission mode (as in chmod), instead of rwxr-xr-x
-o, --owner=OWNER set ownership (super-user only)
-p, --preserve-timestamps apply access/modification times of SOURCE files
to corresponding destination files
-s, --strip strip symbol tables, only for 1st and 2nd formats
-S, --suffix=SUFFIX override the usual backup suffix
-v, --verbose print the name of each directory as it is created
--help display this help and exit
--version output version information and exit

The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control method may be selected via the --backup option or through
the VERSION_CONTROL environment variable. Here are the values:

none, off never make backups (even if --backup is given)
numbered, t make numbered backups
existing, nil numbered if numbered backups exist, simple otherwise
simple, never always make simple backups

Report bugs to <bug-fileutils@gnu.org>.
______________________________________________

I tried the 3 formats, but only 3rd format worked. But it only created an empty folder.

Kitty Cat
Quote:

I tried to run "install" in the ogg folder, but got an error about "few arguments".

Run "make install" (without quotes) in the Ogg folder (as well as the Vorbis and Theora folders after running configure and make in them).

Martano

I used:

./configure
make
install

inside the "ogg" folder.
But when I run "./configure" inside the "theora" folder, I get this error at the end:
___________________________________

checking for Ogg... no
*** Could not run Ogg test program, checking why...
*** The test program failed to compile or link. See the file config.log for the
*** exact error that occured. This usually means Ogg was incorrectly installed
*** or that you have moved Ogg since it was installed.
configure: error:
libogg is required to build this package!
please see http://www.xiph.org/ for how to
obtain a copy.
__________________________________

My folders:

C:\Hangar6\apeg (Apeg folder)
C:\Hangar6\o (ogg folder, where I ran the configure, make and make install)
C:\Hangar6\t (theora folder, where I tried to run the configure)
C:\Hangar6\v (vorbis folder, where I tried to run the configure)

Do I need to change anything about the folders?

Kitty Cat
Quote:

./configure
make
install

Run 'make install", not 'install".

Martano

Opsss.
Mistyped.
I ran "make install"

-------------

It looks like that theora wants the "ogg.h".
But where should I place it?

Kitty Cat

In the Ogg folder, run "make uninstall". Then run "./configure --prefix=/mingw" and then "make install" again.

Martano

Thanks!

(I had to use "./configure --prefix=/mingw" in theora folder too.)

Then tried the same at vorbis, and worked.
After tried "make", but got this error:
_____________________________

collect2: ld returned 1 exit status
make[3]: *** [libvorbisfile.la] Error 1
make[3]: Leaving directory `/c/hangar6/v/lib'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/c/hangar6/v/lib'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/c/hangar6/v'
make: *** [all] Error 2
_____________________________

Tried "make install after that, but got the same error.

Then I checked the "C:\1.0\mingw\" folder to see the installed files.

There are include and lib files for ogg and theora, but no vorbis and only one dll (libogg-0.dll).

Kitty Cat

I think libtheora is currently broken. You should be able to disable libvorbisfile and/or build static-only libs instead. Check ./configure --help for the switches.

Victor Williams Stafusa da Silva

I'm gotting the same problem with allog, but i'm using only libogg and libvorbis. Trying to compile that for 12 or 13 now, and it just don't work. Libvorbis doesn't focken compiles even by the hell!

And ./configure --help doesn't give any useful flagss.

EDIT (some hours later): I was very stressed and angry with that, let's try again...

Martano

Which switch should I use? "--disable-vorbistest"?

Kitty Cat

I think it was --enable-static and/or --disable-dynamic, or something along those lines. You can also send an email to libvorbis's maintainers and inform them of the problem.

Victor Williams Stafusa da Silva

Ohhh. FINALLY!!!!

I COMPILED THAT LIBVORBIS!

After trying to understand the structure of that horrible messy, confusing, large and incompreensible makefiles, i could fix it with that script:


cd ./lib
/bin/sh ../libtool --tag=CC --mode=link gcc  -O20 -D__NO_MATH_INLINES -fsigned-char  -DUSE_MEMORY_H   -o libvorbisfile.la -no-undefined -version-info 4:0:1 vorbisfile.lo libvorbis.la 
sys_lib_search_path_spec=" =c:/Dev-Cpp/lib/gcc/mingw32/3.4.2/ c:/Dev-Cpp/lib/gcc/mingw32/ c:/Dev-Cpp/lib/gcc/ c:/Dev-Cpp/mingw32/lib/ c:/Dev-Cpp/lib/"
rm -fr  .libs/libvorbisfile.dll.a
gcc -shared  .libs/vorbisfile.o  -logg -logg.dll  ./.libs/libvorbis.dll.a  -o .libs/libvorbisfile-3.dll -Wl,--image-base=0x10000000 -Wl,--out-implib,.libs/libvorbisfile.dll.a

Save this in some file called, say "fixthatsh1t".

So, first of all: Install Ogg, which is "./configure --prefix=/mingw", then "make" and "make install".

Second, install Vorbis: "./configure --prefix=/mingw", "make", you'll get some errors about make, so run "./fixthatsh1t", run "make" again and then "make install".

Third, install Theora: I will try this later, but if we are luck it will be the same to install Ogg.

Forth (finally): Install Apeg.

But, i still need know something. When i compile my game (in Alogg), i get that:


Info: resolving _allegro_errno by linking to __imp__allegro_errno (auto-import)
fu000001.o:: undefined reference to `lib_mingw32_liballeg_a_iname'
nmth000000.o:: undefined reference to `_nm__allegro_errno'
collect2: ld returned 1 exit status

make.exe: *** [Asmodan.exe] Error 1

We are almost there!

Martano

Weeeeeeeeeeeeeeeeeeeeeeeeeeeew! :D

It worked!

GREAT THANKS TO EVERYONE!!!!

I needed to reconfigure ogg to "mingw32" (it was set to "mingw").
And needed to copy the "ogg\ogg.h", "theora\theora.h" and "vorbis\codec.h" to "apeg\include\" folder manually, and needed to copy "libapeg.a" to "Dev-Cpp\lib" manually too.
And needed to use this sequence in the linkers:

-lapeg
-ltheora
-lvorbis
-lvorbisenc
-logg
-lalleg

But got no "linker error"!

Now I just need to learn Apeg's commands. ;D

-----------------------------------

EDIT:

I need to play an .ogg music.
Found this command in apeg.txt:

SAMPLE *apeg_preload_audio(const char *filename);

I tried:

SAMPLE *apeg_preload_audio("15.ogg");

But it complained about "bad conversion - const chat to SAMPLE*".

So tried:

SAMPLE *musica = load_sample("15.ogg");
SAMPLE *apeg_preload_audio(musica);
play_sample(apeg_preload_audio, 255, 128, 1000, 0);

It compiles, but closes the program when I click to load it.

PS.: Does anyone know a good AVI->MPG converter? ;D

Evert

Sure, it'll compile, but it should die horribly when run.

Quote:

SAMPLE *spl = apeg_preload_audio("somefilename.someextension");
play_sample(spl, 255, 128, 1000, 0);

Don't take this the wrong way, but do you even know C?

Martano
Quote:

Don't take this the wrong way, but do you even know C?

In real all I know about C, I learnt reading one or two tutorials over the internet. :P

--

I tested:

SAMPLE *spl = apeg_preload_audio("example.ogg");
play_sample(spl, 255, 128, 1000, 0);

But happened the same as before. Is it possible to be using an incompatible ogg format?

Kitty Cat

Its possible apeg_preload_audio is buggy. Everytime I think I fix it, I find something else wrong. It might also be that the file isn't loading, so check if it's NULL before calling play_sample.

If it crashes before it ever gets to play_sample, try using apeg_play_mpg instead (yes, the name is a misnomer; it's a hold-over from before Ogg support was added :P). If that plays, doesn't crash, and doesn't return an error, then it's a problem in apeg_preload_audio.

Martano

apeg_play_mpg worked.

But it shows a black screen. I need to show another images, and make the music to fade out after sometime.

Kitty Cat

apeg_play_mpg was just a test to make sure it wasn't a problem with the file. I think I found the problem, so I'll upload a new version of APEG (1.1.2). Delete your current APEG directory and extract the new archive.

Martano

NEW? :o

Don't tell me that I will need to recompile that thing! :o

hehe

Downloading.... ;D

-------------------------------

EDIT:

Recompiled APEG, and updated the "libapeg.a".
Then tried again the:

SAMPLE *spl = apeg_preload_audio("15.ogg");

//++++++++++     
     if(spl == NULL)
{
   set_gfx_mode(GFX_TEXT,0,0,0,0);
   allegro_message("Could not load 15.ogg!");
   exit(EXIT_FAILURE);
}
//++++++++++ 

play_sample(spl, 255, 128, 1000, 0);

This time it closes the program without the error message. So I think the problem is in the last command.

Kitty Cat

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

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".
It compiled and opened the program. But played no music and showed no error message.

Kitty Cat

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

Here is the function where I am using the command:

1void novocarr(DATAFILE *data, BITMAP *tela)
2{
3 set_trans_blender(255, 255, 255, 128);
4
5 p = 0;
6
7 APEG_STREAM *stream = apeg_open_stream("15.ogg");
8 
9//------------
10 if(!stream)
11 {
12 set_gfx_mode(GFX_TEXT,0,0,0,0);
13 allegro_message("couldn't open 15.ogg because: %s", apeg_error);
14 exit(EXIT_FAILURE);
15 }
16//------------
17
18 while(!p == 1)
19 {
20 draw_sprite(tela,(BITMAP*)data[titulo].dat, 0, 0);
21 textprintf_ex(tela, font, 50, 240, makecol(255,255,255),-1,"%s, você deseja começar um novo jogo ou carregar outro?",the_name);
22 
23 botao0(data,tela,(BITMAP*)data[novo].dat);
24 botaoM(data,tela,(BITMAP*)data[carr].dat);
25// botao2(data,tela,(BITMAP*)data[novo].dat);
26 botaoS(data,tela,(BITMAP*)data[sair].dat);
27
28 show_mouse(tela);
29 blit(tela, screen, 0,0,0,0,640,480);
30 clear_bitmap(tela);
31
32//------------
33 if(!stream)
34 {
35 set_gfx_mode(GFX_TEXT,0,0,0,0);
36 allegro_message("song stopped because: %s", apeg_error);
37 exit(EXIT_FAILURE);
38 }
39//------------
40
41 }
42
43 /* when done: */
44apeg_close_stream(stream);
45stream = NULL;
46
47}

Evert

Call me slow, but I don't see any apeg_advance_stream() calls in that code...

Martano

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
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");
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;

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

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?
And is there a way to put an ogg file inside a datafile?

Kitty Cat
Quote:

How to set the volume of the song?

Use
int voice = apeg_get_stream_voice(stream);to get the voice number of a loaded stream, and then use
voice_set_volumeto set its volume.

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

What is a binary chunk? Because I couldn't use grabber to load the ogg.

Kitty Cat

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

Thanks! ;D

Now I need to play a sound until the end and them continue the program.
Is there a command to do this or do I need "while" function?

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

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

Thanks!

Now it is working! :D

Well.... you all REALLY helped me! Look the size of this thread! ;D

--------
EDIT:

New problem :P

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.

1void esperar(int x) //esperar = to wait
2{
3 clock_t start_time, cur_time;
4 start_time = clock();
5 while((clock() - start_time) < x * CLOCKS_PER_SEC){}
6}
7 
8void apresentar(DATAFILE *data,BITMAP *tela)
9{
10 set_trans_blender(255, 255, 255, 128);
11 draw_gouraud_sprite(screen,tela, 0, 0, 0, 0, 0, 0);
12 esperar(1);
13 draw_gouraud_sprite(screen,tela, 0, 0, 255, 0, 0, 0);
14 esperar(1);
15 draw_gouraud_sprite(screen,tela, 0, 0, 255, 255, 0, 0);
16 esperar(1);
17 draw_gouraud_sprite(screen,tela, 0, 0, 255, 255, 255, 0);
18 esperar(1);
19 draw_gouraud_sprite(screen,tela, 0, 0, 255, 255, 255, 255);
20
21 set_trans_blender(0, 0, 0, 128);
22 
23 APEG_STREAM *stream = apeg_open_stream("musini.ogg");
24
25 pisca(data, tela, (BITMAP*)data[astro].dat, 4);
26 esperar(2);
27 pisca(data, tela, (BITMAP*)data[muri].dat, 4);
28 esperar(1);
29 while(co < 255)
30 {
31 esperar(1/30);
32 co++;
33 co++;
34 draw_gouraud_sprite(tela, (BITMAP*)data[apre].dat, 250, 225, co, co, co, co);
35 blit(tela, screen, 0, 0, 0, 0, 640, 480);
36 clear(tela);
37 }
38 esperar(1);
39 while(co > 0)
40 {
41 esperar(1/30);
42 co--;
43 co--;
44 draw_gouraud_sprite(tela, (BITMAP*)data[apre].dat, 250, 225, co, co, co, co);
45 blit(tela, screen, 0, 0, 0, 0, 640, 480);
46 clear(tela);
47 }
48 esperar(1);
49 while(co < 255)
50 {
51 esperar(1/30);
52 co++;
53 draw_gouraud_sprite(tela,(BITMAP*)data[abat].dat, 0, 0, co, co, co, co);
54 blit(tela, screen, 0,0,0,0,640,480);
55 clear(tela);
56 }
57 esperar(4);
58 while(co > 0)
59 {
60 int voice = apeg_get_stream_voice(stream);
61 voice_set_volume(voice, co);
62 adjust_sample((SAMPLE*)data[musini].dat, co, 128, 1000, 0);
63 esperar(1/30);
64 co--;
65 draw_gouraud_sprite(tela,(BITMAP*)data[abat].dat, 0, 0, co, co, co, co);
66 blit(tela, screen, 0,0,0,0,640,480);
67 clear(tela);
68 }
69 esperar(1);
70
71 apeg_close_stream(stream);
72 stream = NULL;
73}

The song must be played since the:

APEG_STREAM *stream = apeg_open_stream("musini.ogg");

until the last lines.

Kitty Cat

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

I know. But I don't know where I should use it. :-[
If I use in all the "while" functions, the wait function will cut the song.

Zaphos

options:
(1) You can call apeg_advance_stream in the wait function as well.
(2) You can use a separate thread to play the music.

Kitty Cat

or:
(3) redesign the loop so it allows for what you need to do.

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
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

How to redesign the loop ?
You've got all the information in the previous posts, I think. You've just got to read it and understand it.
What you've done here is just copy code. You can do what you want by just modifying that code. The changes you need to make are unrelated to the apeg code, it's just adding your image drawing code, so you should have all the tools you need to do it yourself.

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

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

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

Got it! Thanks! :D

(But I am still curious about the "2nd thread". :P 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

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

I saw that:

void esperar(int x) //esperar = to wait
{
     clock_t start_time, cur_time;
         start_time = clock();
         while((clock() - start_time) < x * CLOCKS_PER_SEC){}
}

...

esperar(1/30);

This isn't good. It will pass zero to esperar() because the parameter is an int. You should do that:

void esperar(float x) //esperar = to wait
{
     clock_t start_time, cur_time;
         start_time = clock();
         while((clock() - start_time) < (int) (x * CLOCKS_PER_SEC)){}
}

...

esperar(1.0/30.0);

EDIT: Didn't read all the replies. Looks like Kitty Cat already said that.

Martano
Quote:

Didn't read all the replies. Looks like Kitty Cat already said that.

Thanks anyway. :)

Thanks Zaphos, I will try that when I get some free time.

Thread #543339. Printed from Allegro.cc