mirror of
https://github.com/ZDoom/ZMusic.git
synced 2025-03-21 01:50:53 +00:00
Implement ZMusic_GetStreamInfo using GetStreamInfoEx
This commit is contained in:
parent
3696d8fa27
commit
db05f4a8ef
14 changed files with 39 additions and 87 deletions
|
@ -51,7 +51,6 @@ public:
|
|||
virtual std::string GetStats();
|
||||
virtual int GetDeviceType() const { return MDEV_DEFAULT; }
|
||||
virtual bool CanHandleSysex() const { return true; }
|
||||
virtual SoundStreamInfo GetStreamInfo() const;
|
||||
virtual SoundStreamInfoEx GetStreamInfoEx() const;
|
||||
|
||||
protected:
|
||||
|
@ -82,7 +81,6 @@ public:
|
|||
virtual int Open() override;
|
||||
virtual bool ServiceStream(void* buff, int numbytes);
|
||||
int GetSampleRate() const { return SampleRate; }
|
||||
SoundStreamInfo GetStreamInfo() const override;
|
||||
SoundStreamInfoEx GetStreamInfoEx() const override;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -170,17 +170,6 @@ std::string MIDIDevice::GetStats()
|
|||
return "This MIDI device does not have any stats.";
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// MIDIDevice :: GetStreamInfo
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
SoundStreamInfo MIDIDevice::GetStreamInfo() const
|
||||
{
|
||||
return { 0, 0, 0 }; // i.e. do not use streaming.
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// MIDIDevice :: GetStreamInfoEx
|
||||
|
|
|
@ -86,22 +86,6 @@ SoftSynthMIDIDevice::~SoftSynthMIDIDevice()
|
|||
Close();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// SoftSynthMIDIDevice :: GetStreamInfo
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
SoundStreamInfo SoftSynthMIDIDevice::GetStreamInfo() const
|
||||
{
|
||||
int chunksize = (SampleRate / StreamBlockSize) * 4;
|
||||
if (!isMono)
|
||||
{
|
||||
chunksize *= 2;
|
||||
}
|
||||
return { chunksize, SampleRate, isMono? 1:2 };
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// SoftSynthMIDIDevice :: GetStreamInfoEx
|
||||
|
|
|
@ -87,7 +87,6 @@ public:
|
|||
int ServiceEvent();
|
||||
void SetMIDISource(MIDISource* _source);
|
||||
bool ServiceStream(void* buff, int len) override;
|
||||
SoundStreamInfo GetStreamInfo() const override;
|
||||
SoundStreamInfoEx GetStreamInfoEx() const override;
|
||||
|
||||
int GetDeviceType() const override;
|
||||
|
@ -447,12 +446,6 @@ bool MIDIStreamer::InitPlayback()
|
|||
}
|
||||
}
|
||||
|
||||
SoundStreamInfo MIDIStreamer::GetStreamInfo() const
|
||||
{
|
||||
if (MIDI) return MIDI->GetStreamInfo();
|
||||
else return { 0, 0, 0 };
|
||||
}
|
||||
|
||||
SoundStreamInfoEx MIDIStreamer::GetStreamInfoEx() const
|
||||
{
|
||||
if (MIDI) return MIDI->GetStreamInfoEx();
|
||||
|
|
|
@ -54,7 +54,6 @@ public:
|
|||
void ChangeSettingNum(const char *name, double value) override { if (m_Source) m_Source->ChangeSettingNum(name, value); }
|
||||
void ChangeSettingString(const char *name, const char *value) override { if(m_Source) m_Source->ChangeSettingString(name, value); }
|
||||
bool ServiceStream(void* buff, int len) override;
|
||||
SoundStreamInfo GetStreamInfo() const override { return m_Source->GetFormat(); }
|
||||
SoundStreamInfoEx GetStreamInfoEx() const override { return m_Source->GetFormatEx(); }
|
||||
|
||||
|
||||
|
|
|
@ -64,7 +64,6 @@ public:
|
|||
//bool SetPosition(int ms);
|
||||
bool SetSubsong(int subsong) override;
|
||||
bool Start() override;
|
||||
SoundStreamInfo GetFormat() override;
|
||||
SoundStreamInfoEx GetFormatEx() override;
|
||||
void ChangeSettingNum(const char* setting, double val) override;
|
||||
std::string GetStats() override;
|
||||
|
@ -1029,17 +1028,6 @@ DumbSong::~DumbSong()
|
|||
if (duh) unload_duh(duh);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// DumbSong GetFormat
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
SoundStreamInfo DumbSong::GetFormat()
|
||||
{
|
||||
return { 32*1024, srate, 2 };
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// DumbSong GetFormatEx
|
||||
|
|
|
@ -57,7 +57,6 @@ public:
|
|||
void ChangeSettingNum(const char *name, double val) override;
|
||||
std::string GetStats() override;
|
||||
bool GetData(void *buffer, size_t len) override;
|
||||
SoundStreamInfo GetFormat() override;
|
||||
SoundStreamInfoEx GetFormatEx() override;
|
||||
|
||||
protected:
|
||||
|
@ -168,11 +167,6 @@ GMESong::GMESong(Music_Emu *emu, int sample_rate)
|
|||
}
|
||||
|
||||
|
||||
SoundStreamInfo GMESong::GetFormat()
|
||||
{
|
||||
return { 32*1024, SampleRate, -2 };
|
||||
}
|
||||
|
||||
SoundStreamInfoEx GMESong::GetFormatEx()
|
||||
{
|
||||
return { 32*1024, SampleRate, SampleType_Int16, ChannelConfig_Stereo };
|
||||
|
|
|
@ -50,7 +50,6 @@ public:
|
|||
SndFileSong(SoundDecoder *decoder, uint32_t loop_start, uint32_t loop_end, bool startass, bool endass);
|
||||
~SndFileSong();
|
||||
std::string GetStats() override;
|
||||
SoundStreamInfo GetFormat() override;
|
||||
SoundStreamInfoEx GetFormatEx() override;
|
||||
bool GetData(void *buffer, size_t len) override;
|
||||
|
||||
|
@ -450,12 +449,6 @@ SndFileSong::SndFileSong(SoundDecoder *decoder, uint32_t loop_start, uint32_t lo
|
|||
Channels = iChannels == ChannelConfig_Stereo? 2:1;
|
||||
}
|
||||
|
||||
SoundStreamInfo SndFileSong::GetFormat()
|
||||
{
|
||||
// deal with this once the configuration is handled better.
|
||||
return { 64/*snd_streambuffersize*/ * 1024, SampleRate, -Channels };
|
||||
}
|
||||
|
||||
SoundStreamInfoEx SndFileSong::GetFormatEx()
|
||||
{
|
||||
ChannelConfig chans;
|
||||
|
|
|
@ -54,7 +54,6 @@ public:
|
|||
~OPLMUSSong ();
|
||||
bool Start() override;
|
||||
void ChangeSettingInt(const char *name, int value) override;
|
||||
SoundStreamInfo GetFormat() override;
|
||||
SoundStreamInfoEx GetFormatEx() override;
|
||||
|
||||
protected:
|
||||
|
@ -94,18 +93,6 @@ OPLMUSSong::OPLMUSSong(MusicIO::FileInterface* reader, OPLConfig* config)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
SoundStreamInfo OPLMUSSong::GetFormat()
|
||||
{
|
||||
int samples = int(OPL_SAMPLE_RATE / 14);
|
||||
return { samples * 4, int(OPL_SAMPLE_RATE), current_opl_core == 0? 1:2 };
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
SoundStreamInfoEx OPLMUSSong::GetFormatEx()
|
||||
{
|
||||
int samples = int(OPL_SAMPLE_RATE / 14);
|
||||
|
|
|
@ -235,7 +235,6 @@ class XASong : public StreamSource
|
|||
{
|
||||
public:
|
||||
XASong(MusicIO::FileInterface *readr);
|
||||
SoundStreamInfo GetFormat() override;
|
||||
SoundStreamInfoEx GetFormatEx() override;
|
||||
bool Start() override;
|
||||
bool GetData(void *buffer, size_t len) override;
|
||||
|
@ -261,12 +260,6 @@ XASong::XASong(MusicIO::FileInterface * reader)
|
|||
getNextXABlock(&xad, false);
|
||||
}
|
||||
|
||||
SoundStreamInfo XASong::GetFormat()
|
||||
{
|
||||
auto SampleRate = xad.blockIs18K? 18900 : 37800;
|
||||
return { 64*1024, SampleRate, 2};
|
||||
}
|
||||
|
||||
SoundStreamInfoEx XASong::GetFormatEx()
|
||||
{
|
||||
auto SampleRate = xad.blockIs18K? 18900 : 37800;
|
||||
|
|
|
@ -21,7 +21,6 @@ public:
|
|||
virtual bool SetPosition(unsigned position) { return false; }
|
||||
virtual bool SetSubsong(int subsong) { return false; }
|
||||
virtual bool GetData(void *buffer, size_t len) = 0;
|
||||
virtual SoundStreamInfo GetFormat() { return {65536, m_OutputRate, 2 }; } // Default format is: System's output sample rate, 32 bit float, stereo
|
||||
virtual SoundStreamInfoEx GetFormatEx() = 0;
|
||||
virtual std::string GetStats() { return ""; }
|
||||
virtual void ChangeSettingInt(const char *name, int value) { }
|
||||
|
|
|
@ -31,7 +31,6 @@ public:
|
|||
virtual void ChangeSettingNum(const char* setting, double value) {} // "
|
||||
virtual void ChangeSettingString(const char* setting, const char* value) {} // "
|
||||
virtual bool ServiceStream(void *buff, int len) { return false; }
|
||||
virtual SoundStreamInfo GetStreamInfo() const { return { 0,0,0 }; }
|
||||
virtual SoundStreamInfoEx GetStreamInfoEx() const = 0;
|
||||
|
||||
enum EState
|
||||
|
|
|
@ -455,9 +455,24 @@ DLL_EXPORT zmusic_bool ZMusic_IsMIDI(MusInfo *song)
|
|||
DLL_EXPORT void ZMusic_GetStreamInfo(MusInfo *song, SoundStreamInfo *fmt)
|
||||
{
|
||||
if (!fmt) return;
|
||||
if (!song) *fmt = {};
|
||||
std::lock_guard<FCriticalSection> lock(song->CritSec);
|
||||
*fmt = song->GetStreamInfo();
|
||||
*fmt = {};
|
||||
|
||||
if (!song)
|
||||
return;
|
||||
|
||||
SoundStreamInfoEx fmtex;
|
||||
{
|
||||
std::lock_guard<FCriticalSection> lock(song->CritSec);
|
||||
fmtex = song->GetStreamInfoEx();
|
||||
}
|
||||
if (fmtex.mSampleRate > 0)
|
||||
{
|
||||
fmt->mBufferSize = fmtex.mBufferSize;
|
||||
fmt->mSampleRate = fmtex.mSampleRate;
|
||||
fmt->mNumChannels = ZMusic_ChannelCount(fmtex.mChannelConfig);
|
||||
if (fmtex.mSampleType == SampleType_Int16)
|
||||
fmt->mNumChannels *= -1;
|
||||
}
|
||||
}
|
||||
|
||||
DLL_EXPORT void ZMusic_GetStreamInfoEx(MusInfo *song, SoundStreamInfoEx *fmt)
|
||||
|
|
|
@ -49,3 +49,24 @@ struct CustomFileReader : public MusicIO::FileInterface
|
|||
|
||||
|
||||
void ZMusic_Printf(int type, const char* msg, ...);
|
||||
|
||||
inline uint8_t ZMusic_SampleTypeSize(SampleType stype)
|
||||
{
|
||||
switch(stype)
|
||||
{
|
||||
case SampleType_UInt8: return sizeof(uint8_t);
|
||||
case SampleType_Int16: return sizeof(int16_t);
|
||||
case SampleType_Float32: return sizeof(float);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline uint8_t ZMusic_ChannelCount(ChannelConfig chans)
|
||||
{
|
||||
switch(chans)
|
||||
{
|
||||
case ChannelConfig_Mono: return 1;
|
||||
case ChannelConfig_Stereo: return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue