Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » AllegroMP3 == chaos in my mind.

This thread is locked; no one can reply to it. rss feed Print
 1   2 
AllegroMP3 == chaos in my mind.
Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

is a pack file really requiered and what is a packfile??

Yes, and its just a file handle. You use it to read and/or write to files.

Quote:

how is this data type built up? and what is the idea of having this thing

Almp3 provides the type and builds it for you with 'almp3_create_mp3'.

char data[x];//ok? what the hell is this?
//why is the "data" stored as an char array?

What type does almp3_create_mp3 take? char*? or void*? use which ever it happens to take, then follow the "len" directions.

int len;//what is this?...Its the length of the mp3 data in bytes.

Something like this should work:

unsigned int len = file_size_ex("filename.ext");
void *data = malloc(len);
if(data == NULL) { DIE A HORRIBLE DEATH! }

len = pack_fread(data, x, mp3file);//see above..
Should change that to:
len = pack_fread(data, len, mp3file);pack_fread returns the actual number of bytes read, so if it didn't read all of "len" you only have that many...

  mp3file = pack_fopen(filename, F_READ);//this is obviously something packfile    
  //related.. what should filename be? the path in char data type? ex: "muu.mp3".??

This really needs to go above the pack_fread. really. And the filename can be "whatever.mp3" or any C string.

almp3_play_mp3stream(mp3, x, 255, 128);//trying to play it..
Almost:
almp3_play_mp3stream(mp3, len, 255, 128);You have to tell it how much data there is to decode.

hth.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Albin Engström
Member #8,110
December 2006
avatar

Another attempt... i'm really grateful for the help, and i'm sorry i'm learning this so slowly - -.

1void muu(char filename)
2{
3 using namespace sfx::music;
4
5 mp3file = NULL;
6 mp3 = NULL;
7
8 mp3file = pack_fopen(filename, F_READ);//opens a file?
9
10 unsigned int len;//unsigned?
11 len = file_size_ex(filename);//gets the size of file?
12
13 char *data = (char *) malloc (len);//malloc? googled it but didn't find any
14 //explanations i could understand..
15 
16 if(data == NULL) {allegro_message("MOOO");};
17
18 len = pack_fread(data, len, mp3file);//i don't really understand whats going on
19 //here, first len got the value of "file size" and now what?
20
21 mp3 = almp3_create_mp3(data, len);
22
23 almp3_play_mp3(mp3, len, 255, 128);//mp3 = what to "decode" len = how much to
24 //"decode"?
25}

Quote:

int almp3_poll_mp3(ALMP3_MP3 *mp3);
This functions needs to be called in order to keep the ALMP3_MP3
playing properly, since the mp3s need to be decoded at real time
(either that, or to a huge memory buffer).

I got the impression this was only used for streaming?

This didn't work, it didn't crash, i just didn't play. It's funny how you sometimes want it to crash... at least that gives you a clue about whats wrong.

Help appreciated!

off-topic: how come pixels colored "0,0,1" display the underlying active mediaplayer window... in windowed mode. i use vlc mediaplayer.

Thomas Fjellstrom
Member #476
June 2000
avatar

1void muu(char filename)
2{
3 using namespace sfx::music;
4
5 mp3file = NULL;
6 mp3 = NULL;
7
8 mp3file = pack_fopen(filename, F_READ);//opens a file?
9 //> Yup.
10
11 unsigned int len;//unsigned?
12 //> A "signed" integer uses one bit for the "sign" (if its negative or positive) meaning you only have 31 bits of space, or a number up to 2billion instead of 4billion (2GB versus 4GB).
13 
14 len = file_size_ex(filename);//gets the size of file?
15 //> Yup.
16
17 char *data = (char *) malloc (len);//malloc? googled it but didn't find any
18 //explanations i could understand..
19 //> Ok, all computers have some ammount of "RAM", this is where programs are executed, and where programs store in use data, like loaded bitmaps, etc.
20 //> malloc lets you get a "len" sized chunk of it to use however you want.
21 
22 if(data == NULL) {allegro_message("MOOO");};
23 //> This is really a fatal error, using data after this check will cause memory corruption and a crash, or just a crash.
24
25 len = pack_fread(data, len, mp3file);//i don't really understand whats going on
26 //here, first len got the value of "file size" and now what?
27 //> Now that you have the "len" from file_size_ex, you pass it into fread so it attempts to read "len" bytes of data from the file (hopefully all of it).
28 //> If fread _can't_ read "len" bytes, it returns the number of bytes it did read, or -1 on error. Which makes me think it should actually be this instead:
29 long newlen = pack_fread(data, len, mp3file);
30 if(newlen == -1) {
31 // ERROR!
32 }
33 else if(newlen == 0) {
34 // Probably an error as well.
35 }
36 
37 len = newlen; //> save the new length.
38 
39 mp3 = almp3_create_mp3(data, len);
40
41 almp3_play_mp3(mp3, len, 255, 128);//mp3 = what to "decode" len = how much to
42 //"decode"?
43 //> Yup.
44}

Quote:

I got the impression this was only used for streaming?

What I and the others mean by streaming is incrementally loading the data of the disk and passing it into the decoder.

I suppose you could call what almp3 does with non mp3stream's streaming, but best not, otherwise it can get confusing.

almp3_poll_mp3 is used to tell almp3 to send some more data to the soundcard, a bit at a time, since you can't actually fit 40MB (decoded size of mp3 data) of sound data in most sound cards ;)

If almp3_poll_mp3 didn't poll in this fashion you'd need to decode all of the mp3 data into ram, and then place it into a SAMPLE, and play that. But that can eat up a lot of memory. So instead, it holds just the mp3 data, and when you poll, it decodes enough information to fill the buffer, and then queues it to play with allegro's sound system.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Albin Engström
Member #8,110
December 2006
avatar

Finally it worked!!.

You're my hero Thomas!! ;D.

thanks to all the other nice people too!!
WOOOHOOO!!!!

but i still have questions ^^:
1: what is the sign used for? (unsigned signed stuff).

2: malloc lets me use the memory however i want eh,
so examples of not using how i want would be: int, char and stuff?
i kinda get it but at the same time not.. no, i don't think i get it at all..

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

1: what is the sign used for? (unsigned signed stuff).

If an integer is unsigned, its range is from 0 through 2^32
If an integer is signed (which all are by default), the range is -2^31 through 2^31.

Quote:

2: malloc lets me use the memory however i want eh,

It lets you get an arbitryily sized chunk of memory to use for just about anything. Dynamically allocating variables (int, char, arrays, structs, etc). Or whatever.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

 1   2 


Go to: