hey,

im trying to use the mpg123 library to extract the sound data from the mp3 file....

ive used this example to decode the file:
http://mpg123.de/api/mpg123__to__wav_8c-source.shtml

i can extract the info about the file but the actual sound data im having troubles....

because it doenst give me the whole data in one big chunk.. but in small parts (and since i dont know how big it is gonna be i cant assign an array length...)

I have been reading data from wave files without any problems (manually, no libraries) and now i want to also read mp3 files with this library.....

i hope you can help me :)

thx

Daan

Read the file twice, first time works out the total size, then you allocate what you need and read again.

Or maybe another way....

Read the file twice, first time works out the total size, then you allocate what you need and read again.

Or maybe another way....

ok so i found out how to find the amount of samples in the file.. so i can assign an amount of memory... but when i use:

buffer_size = mpg123_outblock( mMp3Handle );
		//buffer_size = 16;

		mMp3Data = new unsigned char[buffer_size];
		mData = new char[mp3_size*2];

		int y = 0;
		do
		{
			err = mpg123_read( mMp3Handle, mMp3Data, (buffer_size/2), &decoded );
 			//for (int i = 0; i < buffer_size; i+= decoded/sizeof(char))
 			//{
 			//	mData[y] = (char)mMp3Data[i];
 			//	y++;
			// }
			mData[y] = (char)mMp3Data;
			y++;
		} while (err==MPG123_OK);

to read the data... but it doenst give me back any sensible material (mostly 0's)... im having trouble finding out how to handle the data the mpg123_read function supplies to the mMp3Data....

i really cant figure this out :S

http://www.mpg123.de/api/group__mpg123__input.shtml#g2777c4c390a18fe289f2a491fa390707
I don't know why you're ignoring err
I don't know why you divided the size by 2
I don't know why you're stepping by decoded

first of all im not ignoring err... am i ? it in the while...

im dividing by 2 because the samples are shorts and i read chars.... (i think)

and i tried the commented part but it doesnt supply anything better.....

and sorry.. but your not really helping me in any way.....

i have no idea what this function is doing.. and the documentation is not really helping me.. (maybe its above my level.. but i just want to read sample data from mp3's... it shouldnt be that hard....!?!?)

I hope someone can lead me in the right direction, supply me with a working peice of code or help me with other library implementation....

thx anyways... :D

> first of all im not ignoring err... am i ? it in the while...
But you're doing stuff between the assignment and the test.
Which means you're going to do something bad before you realise it.

> im dividing by 2 because the samples are shorts and i read chars.... (i think)
"I think" is a sure sign of bugs.
Figure it out, and put the correct code in.
Don't "just think" and hope it'll turn out all right.

> and sorry.. but your not really helping me in any way.....
And the snippets you provide are nowhere near enough to evaluate if you're doing anything else wrong, so I guess we're both SOL.

Start with something simple, say read in the header and print out the information in the header (say the sample rate). Until you can manage that, the rest of the problem is inaccessible.
Plus it will give you confidence that you're using the library correctly.

A lot of the time, I just post stuff in the hope it will make people think, rather than just giving out a straight answer. It might be what you want, but it's seldom useful in the long run.

Plus I don't really feel like downloading a library, producing a nice worked example just for you.

This article has been dead for over six months. Start a new discussion instead.