diff --git a/src/sound/backend/i_soundinternal.h b/src/sound/backend/i_soundinternal.h index d4df22733..e53761f59 100644 --- a/src/sound/backend/i_soundinternal.h +++ b/src/sound/backend/i_soundinternal.h @@ -121,8 +121,10 @@ const char *GetSampleTypeName(enum SampleType type); const char *GetChannelConfigName(enum ChannelConfig chan); class MusInfo; +class SoundStream; struct MusPlayingInfo { + SoundStream* musicStream; FString name; MusInfo *handle; int baseorder; diff --git a/src/sound/music/i_music.h b/src/sound/music/i_music.h index 31cf33093..655d3e355 100644 --- a/src/sound/music/i_music.h +++ b/src/sound/music/i_music.h @@ -82,6 +82,7 @@ public: virtual void ChangeSettingInt(const char *setting, int value); // FluidSynth settings virtual void ChangeSettingNum(const char *setting, double value); // " virtual void ChangeSettingString(const char *setting, const char *value); // " + virtual SoundStreamInfo GetStreamInfo() const { return { 0,0,0 }; } void Start(bool loop, float rel_vol = -1.f, int subsong = 0); diff --git a/src/sound/musicformats/music_midistream.cpp b/src/sound/musicformats/music_midistream.cpp index eea775621..31237422d 100644 --- a/src/sound/musicformats/music_midistream.cpp +++ b/src/sound/musicformats/music_midistream.cpp @@ -92,6 +92,7 @@ public: void ChangeSettingString(const char* setting, const char* value) override; int ServiceEvent(); void SetMIDISource(MIDISource* _source); + SoundStreamInfo GetStreamInfo() const override; int GetDeviceType() const override; @@ -142,7 +143,9 @@ protected: int LoopLimit; FString Args; std::unique_ptr source; + std::unique_ptr Stream; + }; @@ -425,21 +428,13 @@ bool MIDIStreamer::InitPlayback() source->CheckCaps(MIDI->GetTechnology()); if (!MIDI->CanHandleSysex()) source->SkipSysex(); - auto streamInfo = MIDI->GetStreamInfo(); - if (streamInfo.mBufferSize > 0) - { - Stream.reset(GSnd->CreateStream(FillStream, streamInfo.mBufferSize, streamInfo.mNumChannels == 1 ? SoundStream::Float | SoundStream::Mono : SoundStream::Float, streamInfo.mSampleRate, MIDI.get())); - } - StartPlayback(); if (MIDI == nullptr) { // The MIDI file had no content and has been automatically closed. return false; } - int res = 1; - if (Stream) res = Stream->Play(true, 1); - if (res) res = MIDI->Resume(); + int res = MIDI->Resume(); if (res) { @@ -448,10 +443,24 @@ bool MIDIStreamer::InitPlayback() else { m_Status = STATE_Playing; + + auto streamInfo = MIDI->GetStreamInfo(); + if (streamInfo.mBufferSize > 0) + { + Stream.reset(GSnd->CreateStream(FillStream, streamInfo.mBufferSize, streamInfo.mNumChannels == 1 ? SoundStream::Float | SoundStream::Mono : SoundStream::Float, streamInfo.mSampleRate, MIDI.get())); + } + + if (Stream) res = Stream->Play(true, 1); return true; } } +SoundStreamInfo MIDIStreamer::GetStreamInfo() const +{ + if (MIDI) return MIDI->GetStreamInfo(); + else return { 0, 0, 0 }; +} + //========================================================================== // // MIDIStreamer :: StartPlayback