- mp3_current_file = f;
- fseek(f, 0, SEEK_END);
- mp3_file_len = ftell(f);
-
- // search for first sync word, skipping stuff like ID3 tags
- while (mp3_file_pos < 128*1024) {
- int offs, bytes;
-
- fseek(f, mp3_file_pos, SEEK_SET);
- bytes = fread(mp3_input_buffer, 1, sizeof(mp3_input_buffer), f);
- if (bytes < 4)
- break;
- offs = mp3_find_sync_word(mp3_input_buffer, bytes);
- if (offs >= 0) {
- mp3_file_pos += offs;
- break;
- }
- mp3_file_pos += bytes - 2;
- }
-
- // seek..
- if (pos) {
- unsigned long long pos64 = mp3_file_len - mp3_file_pos;
- pos64 *= pos;
- mp3_file_pos += pos64 >> 10;
- }
-
- mp3_decode();
-}
-
-void mp3_update(int *buffer, int length, int stereo)
-{
- int length_mp3, shr = 0;
- void (*mix_samples)(int *dest_buf, short *mp3_buf, int count) = mix_16h_to_32;
-
- if (mp3_current_file == NULL || mp3_file_pos >= mp3_file_len)
- return; /* no file / EOF */
-
- length_mp3 = length;
- if (PsndRate <= 11025 + 100) {
- mix_samples = mix_16h_to_32_s2;
- length_mp3 <<= 2; shr = 2;
- }
- else if (PsndRate <= 22050 + 100) {
- mix_samples = mix_16h_to_32_s1;
- length_mp3 <<= 1; shr = 1;
- }
-
- if (1152 - mp3_buffer_offs >= length_mp3) {
- mix_samples(buffer, cdda_out_buffer + mp3_buffer_offs*2, length<<1);
-
- mp3_buffer_offs += length_mp3;
- } else {
- int ret, left = 1152 - mp3_buffer_offs;
-
- mix_samples(buffer, cdda_out_buffer + mp3_buffer_offs*2, (left>>shr)<<1);
- ret = mp3_decode();
- if (ret == 0) {
- mp3_buffer_offs = length_mp3 - left;
- mix_samples(buffer + ((left>>shr)<<1), cdda_out_buffer, (mp3_buffer_offs>>shr)<<1);
- } else
- mp3_buffer_offs = 0;
- }