From 7f17121df8225409746cfa8a8b283d32076757ad Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Thu, 8 Mar 2018 11:38:02 +0200 Subject: [PATCH] Fixed crash in MIDI to wave writer --- src/sound/i_musicinterns.h | 2 +- src/sound/mididevices/music_wavewriter_mididevice.cpp | 6 +++--- src/sound/musicformats/music_midistream.cpp | 7 ++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/sound/i_musicinterns.h b/src/sound/i_musicinterns.h index 9679fec934..b7acf60b75 100644 --- a/src/sound/i_musicinterns.h +++ b/src/sound/i_musicinterns.h @@ -198,7 +198,7 @@ protected: class MIDIWaveWriter : public SoftSynthMIDIDevice { public: - MIDIWaveWriter(const char *filename, MIDIDevice *devtouse); + MIDIWaveWriter(const char *filename, SoftSynthMIDIDevice *devtouse); ~MIDIWaveWriter(); int Resume(); int Open(MidiCallback cb, void *userdata) diff --git a/src/sound/mididevices/music_wavewriter_mididevice.cpp b/src/sound/mididevices/music_wavewriter_mididevice.cpp index 1f109aea2c..99590ee883 100644 --- a/src/sound/mididevices/music_wavewriter_mididevice.cpp +++ b/src/sound/mididevices/music_wavewriter_mididevice.cpp @@ -87,11 +87,11 @@ struct FmtChunk // //========================================================================== -MIDIWaveWriter::MIDIWaveWriter(const char *filename, MIDIDevice *playdevice) - : SoftSynthMIDIDevice(playDevice->GetSampleRate()) +MIDIWaveWriter::MIDIWaveWriter(const char *filename, SoftSynthMIDIDevice *playdevice) + : SoftSynthMIDIDevice(playdevice->GetSampleRate()) { File = FileWriter::Open(filename); - playDevice = (SoftSynthMIDIDevice*) playdevice; + playDevice = playdevice; if (File != nullptr) { // Write wave header uint32_t work[3]; diff --git a/src/sound/musicformats/music_midistream.cpp b/src/sound/musicformats/music_midistream.cpp index 2b4e1c34e5..873f9d92f5 100644 --- a/src/sound/musicformats/music_midistream.cpp +++ b/src/sound/musicformats/music_midistream.cpp @@ -319,8 +319,13 @@ bool MIDIStreamer::DumpWave(const char *filename, int subsong, int samplerate) assert(MIDI == NULL); auto devtype = SelectMIDIDevice(DeviceType); + if (devtype == MDEV_MMAPI) + { + Printf("MMAPI device is not supported"); + return false; + } MIDI = CreateMIDIDevice(devtype, samplerate); - MIDI = new MIDIWaveWriter(filename, MIDI); + MIDI = new MIDIWaveWriter(filename, reinterpret_cast(MIDI)); return InitPlayback(); }