From b883d27a1f4ca5bce829462fbc3fa10fc77e92b7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 29 Sep 2019 01:44:59 +0200 Subject: [PATCH] - XA, too. --- src/sound/music/i_music.cpp | 3 ++- src/sound/music/i_musicinterns.h | 2 +- src/sound/musicformats/music_xa.cpp | 29 +++++++++++++++++------------ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/sound/music/i_music.cpp b/src/sound/music/i_music.cpp index 631085aec3..4fa282d058 100644 --- a/src/sound/music/i_music.cpp +++ b/src/sound/music/i_music.cpp @@ -465,7 +465,8 @@ MusInfo *I_RegisterSong (FileReader &reader, MidiDeviceSetting *device) } else if ((id[0] == MAKE_ID('R', 'I', 'F', 'F') && id[2] == MAKE_ID('C', 'D', 'X', 'A'))) { - streamsource = XA_OpenSong(reader); + auto mreader = new FileReaderMusicInterface(reader); + streamsource = XA_OpenSong(mreader); // this takes over the reader. } // Check for game music else if ((fmt = GME_CheckFormat(id[0])) != nullptr && fmt[0] != '\0') diff --git a/src/sound/music/i_musicinterns.h b/src/sound/music/i_musicinterns.h index a200aeee0f..c792d88db8 100644 --- a/src/sound/music/i_musicinterns.h +++ b/src/sound/music/i_musicinterns.h @@ -155,7 +155,7 @@ class StreamSource; StreamSource *MOD_OpenSong(MusicIO::FileInterface* reader, DumbConfig* config, int samplerate); StreamSource* GME_OpenSong(MusicIO::FileInterface* reader, const char* fmt, float stereo_depth, int sample_rate); StreamSource *SndFile_OpenSong(FileReader &fr); -StreamSource* XA_OpenSong(FileReader& reader); +StreamSource* XA_OpenSong(MusicIO::FileInterface* reader); StreamSource* OPL_OpenSong(MusicIO::FileInterface* reader, OPLConfig *config); // stream song ------------------------------------------ diff --git a/src/sound/musicformats/music_xa.cpp b/src/sound/musicformats/music_xa.cpp index 5c06d3369b..0d77ce86eb 100644 --- a/src/sound/musicformats/music_xa.cpp +++ b/src/sound/musicformats/music_xa.cpp @@ -1,5 +1,6 @@ -#include "i_musicinterns.h" #include "streamsource.h" +#include "../libraries/music_common/fileio.h" + /** * PlayStation XA (ADPCM) source support for MultiVoc * Adapted and remixed from superxa2wav @@ -27,8 +28,9 @@ XA_DATA_START = (0x44-48) inline float constexpr DblToPCMF(double dt) { return float(dt) * (1.f/32768.f); } typedef struct { - FileReader reader; + MusicIO::FileInterface *reader; size_t committed; + size_t length; bool blockIsMono; bool blockIs18K; bool finished; @@ -184,12 +186,12 @@ static void getNextXABlock(xa_data *xad, bool looping ) do { - size_t bytes = xad->reader.GetLength() - xad->reader.Tell(); + size_t bytes = xad->length - xad->reader->tell(); if (sizeof(XASector) < bytes) bytes = sizeof(XASector); - xad->reader.Read(&ssct, bytes); + xad->reader->read(&ssct, (int)bytes); } while (ssct.sectorFiller[46] != (SUBMODE_REAL_TIME_SECTOR | SUBMODE_FORM | SUBMODE_AUDIO_DATA)); @@ -208,11 +210,11 @@ static void getNextXABlock(xa_data *xad, bool looping ) decodeSoundSectMono(&ssct, xad); } - if (xad->reader.GetLength() == xad->reader.Tell()) + if (xad->length == xad->reader->tell()) { if (looping) { - xad->reader.Seek(XA_DATA_START, FileReader::SeekSet); + xad->reader->seek(XA_DATA_START, SEEK_SET); xad->t1 = xad->t2 = xad->t1_x = xad->t2_x = 0; } else @@ -231,7 +233,7 @@ static void getNextXABlock(xa_data *xad, bool looping ) class XASong : public StreamSource { public: - XASong(FileReader & readr); + XASong(MusicIO::FileInterface *readr); SoundStreamInfo GetFormat() override; bool Start() override; bool GetData(void *buffer, size_t len) override; @@ -246,11 +248,14 @@ protected: // //========================================================================== -XASong::XASong(FileReader &reader) +XASong::XASong(MusicIO::FileInterface * reader) { - reader.Seek(XA_DATA_START, FileReader::SeekSet); - xad.reader = std::move(reader); + reader->seek(0, SEEK_END); + xad.length = reader->tell(); + reader->seek(XA_DATA_START, SEEK_SET); + xad.reader = reader; xad.t1 = xad.t2 = xad.t1_x = xad.t2_x = 0; + getNextXABlock(&xad, false); } @@ -270,7 +275,7 @@ bool XASong::Start() { if (xad.finished && m_Looping) { - xad.reader.Seek(XA_DATA_START, FileReader::SeekSet); + xad.reader->seek(XA_DATA_START, SEEK_SET); xad.t1 = xad.t2 = xad.t1_x = xad.t2_x = 0; xad.finished = false; } @@ -342,7 +347,7 @@ bool XASong::GetData(void *vbuff, size_t len) // //========================================================================== -StreamSource *XA_OpenSong(FileReader &reader) +StreamSource *XA_OpenSong(MusicIO::FileInterface *reader) { return new XASong(reader); }