Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // XXX: Find the first sync
- uint32\_t id3\_bytes\_read = 0;
- uint8\_t id3\_buffer\[2881\] = {0};
- uint32\_t last\_file\_location = 0;
- uint32\_t current\_file\_location = 0;
- ptrdiff\_t diff = 0;
- do {
- last_file_location = f_tell(&track);
- // XXX: Get a chunk of data from the SD card
- retSD = f_read(&track, id3_buffer, 1024, (UINT *) &id3_bytes_read);
- if (FR_OK != retSD) {
- FatFsError(retSD);
- }
- // XXX: Set the read data as mad stream
- mad\_stream\_buffer(&id3\_stream, (unsigned char const \*) id3\_buffer, sizeof id3\_buffer);
- // XXX: Try to decode it, TODO: check return
- mad\_frame\_decode(&id3\_frame, &id3\_stream);
- // XXX: Try to find a SYNC flag
- if (0 == mad\_stream\_sync(&id3\_stream)) {
- diff = id3_stream.this_frame - id3_buffer;
- break;
- }
- HAL\_Delay(25);
- } while (1);
- current_file_location = f_tell(&track);
- DBG_println("We're at 0x%X", current_file_location);
- DBG_println("Diff: 0x%X (%d)", current_file_location - (last_file_location + diff), current_file_location - (last_file_location + diff));
- // XXX: Go back N bytes so from now on we read data from the location of the first SYNC flag
- retSD = f_lseek(&track, current_file_location - (current_file_location - last_file_location + diff));
- // XXX: We're done
- mad_stream_finish(&id3_stream);
- mad_frame_finish(&id3_frame);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement