Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finding accurate track length by iterating using input buffer #81

Closed
rmsaad opened this issue Oct 26, 2020 · 10 comments
Closed

Finding accurate track length by iterating using input buffer #81

rmsaad opened this issue Oct 26, 2020 · 10 comments

Comments

@rmsaad
Copy link

rmsaad commented Oct 26, 2020

Hello,

I haven't been using this library for very long so I am wondering if there is faster way to find track length than what I have done below. Currently it is way to slow to even be useful.

while(1){
		bytesread = 0;
		samplesCount += mp3dec_decode_frame(&mp3d, (const uint8_t*) &input_data[0], MP3_BUF, 0, &info); 									
		memmove(&input_data[0], &input_data[info.frame_bytes], (MP3_BUF - info.frame_bytes));      											
		f_read(&FileRead, &input_data[MP3_BUF - info.frame_bytes], info.frame_bytes, (unsigned int*) &bytesread);  							
		
		if(bytesread == 0){																													
			while(info.frame_bytes){																											
				bufPos += info.frame_bytes;																										
				samplesCount += mp3dec_decode_frame(&mp3d, (const uint8_t*) &input_data[bufPos], MP3_BUF - bufPos, 0, &info);					
			}
		}
		if (info.frame_bytes <= 0) break;									
	}
	return samplesCount/info.hz;
@lieff
Copy link
Owner

lieff commented Oct 26, 2020

Hi)

There is faster way if mp3 file contains vbr tag. You can use minimp3_ex to automatically use faster way:

    mp3dec_ex_t dec;
    if (mp3dec_ex_open(&dec, input_file_name, MP3D_SEEK_TO_SAMPLE))
    {
        /* error */
    }
    /* dec.samples, dec.info.hz, dec.info.layer, dec.info.channels should be filled */

You also can use MP3D_DO_NOT_SCAN flag. In that case only fast way used, dec.samples is filled if vbr tag found and dec.samples == 0 otherwise.

@rmsaad
Copy link
Author

rmsaad commented Oct 26, 2020

Thanks for the quick reply.

Unfortunately I am working on embedded project where the mp3s are stored on a USB(FATFS), the file handling functions in minimp3_ex.h do not work.

@lieff
Copy link
Owner

lieff commented Oct 27, 2020

You can try minimp3_ex with MINIMP3_NO_STDIO and use mp3dec_ex_open_cb with custom io functions.

@rmsaad
Copy link
Author

rmsaad commented Oct 28, 2020

Thank you,

I will try that out , it seems like the best option.

@rmsaad rmsaad closed this as completed Oct 28, 2020
@rmsaad
Copy link
Author

rmsaad commented Oct 29, 2020

Sorry again,

Is there another way to read the vbr tag, I only have 128 KB of RAM and 64 KB of CCRAM to work with and the memory allocation in mp3dec_ex_open is returning MP3D_E_MEMORY error.

@rmsaad rmsaad reopened this Oct 29, 2020
@rmsaad
Copy link
Author

rmsaad commented Oct 29, 2020

is it possible to make MINIMP3_IO_SIZE smaller?

@lieff
Copy link
Owner

lieff commented Oct 29, 2020

Yes, try following config:

#define MAX_FRAME_SYNC_MATCHES      3
#define MINIMP3_BUF_SIZE (8*1024)
#define MINIMP3_IO_SIZE (16*1024)

@rmsaad
Copy link
Author

rmsaad commented Oct 29, 2020

Thank you for your help,

It seems to be working now.

@rmsaad rmsaad closed this as completed Oct 29, 2020
@rmsaad
Copy link
Author

rmsaad commented Nov 20, 2020

the MINIMP3_NO_STDIO mp3dec_ex_close() function does not free dec->file.buffer. I just copied that bit from the other close function, it seems to be freeing that memory now.

@lieff
Copy link
Owner

lieff commented Nov 20, 2020

Thanks for catching this) Fixed in c02ef01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants