DOSBox-X
|
00001 /* 00002 * DOSBox-X MP3 Seek Table Handler 00003 * ------------------------------- 00004 * See mp3_seek_table.cpp for more documentation. 00005 * 00006 * The seek table handler makes use of the following single-header 00007 * public libraries: 00008 * - dr_mp3: http://mackron.github.io/dr_mp3.html, by David Reid 00009 * - archive: https://github.com/voidah/archive, by Arthur Ouellet 00010 * - xxHash: http://cyan4973.github.io/xxHash, by Yann Collet 00011 * 00012 * Copyright (C) 2020 The DOSBox-X Team 00013 * Copyright (C) 2018-2019 Kevin R. Croft <krcroft@gmail.com> 00014 * 00015 * This program is free software; you can redistribute it and/or modify 00016 * it under the terms of the GNU General Public License as published by 00017 * the Free Software Foundation; either version 2 of the License, or 00018 * (at your option) any later version. 00019 * 00020 * This program is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * You should have received a copy of the GNU General Public License along 00026 * with this program; if not, write to the Free Software Foundation, Inc., 00027 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00028 */ 00029 00030 #include <vector> // provides: vector 00031 #include <SDL.h> // provides: SDL_RWops 00032 #include "archive.h" // provides: archive 00033 00034 // Ensure we only get the API 00035 #ifdef DR_MP3_IMPLEMENTATION 00036 # undef DR_MP3_IMPLEMENTATION 00037 #endif 00038 #include "dr_mp3.h" // provides: drmp3 00039 00040 // Note: this C++ struct must match (in binary-form) the "drmp3_seek_point" struct 00041 // defined in dr_mp3.h. If that changes, then update this to match, along 00042 // with adjusting the Serialize() template function that union's the values. 00043 // 00044 struct drmp3_seek_point_serial { 00045 drmp3_uint64 seekPosInBytes; // Points to the first byte of an MP3 frame. 00046 drmp3_uint64 pcmFrameIndex; // The index of the PCM frame this seek point targets. 00047 drmp3_uint16 mp3FramesToDiscard; // The number of whole MP3 frames to be discarded before pcmFramesToDiscard. 00048 drmp3_uint16 pcmFramesToDiscard; 00049 template <class T> void Serialize(T& archive) { 00050 archive & seekPosInBytes & pcmFrameIndex & mp3FramesToDiscard & pcmFramesToDiscard; 00051 } 00052 }; 00053 00054 // Our private-decoder structure where we hold: 00055 // - a pointer to the working dr_mp3 instance 00056 // - a template vector of seek_points (the serializeable form) 00057 struct mp3_t { 00058 drmp3* p_dr = nullptr; // the actual drmp3 instance we open, read, and seek within 00059 std::vector<drmp3_seek_point_serial> seek_points_vector = {}; 00060 }; 00061 00062 uint64_t populate_seek_points(struct SDL_RWops* const context, 00063 mp3_t* p_mp3, 00064 const char* seektable_filename, 00065 bool &result);