- reordering code a bit to see where the stream must be started.

This commit is contained in:
Christoph Oelckers 2019-09-29 22:54:13 +02:00
parent d06ec56c2e
commit c7b379483e
3 changed files with 21 additions and 9 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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<MIDISource> source;
std::unique_ptr<SoundStream> 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