diff options
Diffstat (limited to 'audio')
-rw-r--r-- | audio/decoders/aac.cpp | 2 | ||||
-rw-r--r-- | audio/decoders/aac.h | 9 | ||||
-rw-r--r-- | audio/decoders/adpcm.cpp | 4 | ||||
-rw-r--r-- | audio/decoders/quicktime.cpp | 4 | ||||
-rw-r--r-- | audio/decoders/quicktime.h | 12 | ||||
-rw-r--r-- | audio/decoders/voc.cpp | 6 | ||||
-rw-r--r-- | audio/mididrv.cpp | 57 | ||||
-rw-r--r-- | audio/midiparser_xmidi.cpp | 33 | ||||
-rw-r--r-- | audio/mixer.cpp | 38 | ||||
-rw-r--r-- | audio/mixer.h | 16 | ||||
-rw-r--r-- | audio/mixer_intern.h | 2 | ||||
-rw-r--r-- | audio/mpu401.cpp | 5 | ||||
-rw-r--r-- | audio/rate.cpp | 3 | ||||
-rw-r--r-- | audio/softsynth/fmtowns_pc98/towns_audio.cpp | 26 | ||||
-rw-r--r-- | audio/softsynth/fmtowns_pc98/towns_midi.cpp | 44 | ||||
-rw-r--r-- | audio/softsynth/fmtowns_pc98/towns_midi.h | 6 | ||||
-rw-r--r-- | audio/softsynth/fmtowns_pc98/towns_pc98_driver.cpp | 2 | ||||
-rw-r--r-- | audio/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp | 4 | ||||
-rw-r--r-- | audio/softsynth/mt32.cpp | 4 | ||||
-rw-r--r-- | audio/softsynth/opl/mame.cpp | 2 |
20 files changed, 179 insertions, 100 deletions
diff --git a/audio/decoders/aac.cpp b/audio/decoders/aac.cpp index 7949b5b561..874062a702 100644 --- a/audio/decoders/aac.cpp +++ b/audio/decoders/aac.cpp @@ -127,7 +127,7 @@ int AACStream::readBuffer(int16 *buffer, const int numSamples) { // Dip into our remaining samples pool if it's available if (_remainingSamples) { samples = MIN<int>(numSamples, _remainingSamplesSize - _remainingSamplesPos); - + memcpy(buffer, _remainingSamples + _remainingSamplesPos, samples * 2); _remainingSamplesPos += samples; diff --git a/audio/decoders/aac.h b/audio/decoders/aac.h index f14fa9488b..efcbcc6f42 100644 --- a/audio/decoders/aac.h +++ b/audio/decoders/aac.h @@ -46,13 +46,16 @@ namespace Audio { class AudioStream; /** - * Create a new AudioStream from the AAC data in the given stream. + * Create a new AudioStream from the AAC data of an MPEG-4 file in the given stream. * - * @param stream the SeekableReadStream from which to read the AAC data + * @note This should *only* be called by our QuickTime/MPEG-4 decoder since it relies + * on the MPEG-4 extra data. If you want to decode a file using AAC, go use + * makeQuickTimeStream() instead! + * @param stream the SeekableReadStream from which to read the AAC data * @param disposeStream whether to delete the stream after use * @param extraData the SeekableReadStream from which to read the AAC extra data * @param disposeExtraData whether to delete the extra data stream after use - * @return a new AudioStream, or NULL, if an error occurred + * @return a new AudioStream, or NULL, if an error occurred */ AudioStream *makeAACStream( Common::SeekableReadStream *stream, diff --git a/audio/decoders/adpcm.cpp b/audio/decoders/adpcm.cpp index d28ed222a5..f75196c882 100644 --- a/audio/decoders/adpcm.cpp +++ b/audio/decoders/adpcm.cpp @@ -342,14 +342,14 @@ do { \ _topNibble = true; \ } \ } while (0) - + int DK3_ADPCMStream::readBuffer(int16 *buffer, const int numSamples) { int samples = 0; assert((numSamples % 4) == 0); - while (samples < numSamples && !_stream->eos() && _stream->pos() < _endpos) { + while (samples < numSamples && !_stream->eos() && _stream->pos() < _endpos) { if ((_stream->pos() % _blockAlign) == 0) { _stream->readUint16LE(); // Unknown uint16 rate = _stream->readUint16LE(); // Copy of rate diff --git a/audio/decoders/quicktime.cpp b/audio/decoders/quicktime.cpp index 0f2e76658b..0ad2821cd5 100644 --- a/audio/decoders/quicktime.cpp +++ b/audio/decoders/quicktime.cpp @@ -220,7 +220,7 @@ void QuickTimeAudioDecoder::setAudioStreamPos(const Timestamp &where) { // First, we need to track down what audio sample we need Audio::Timestamp curAudioTime = where.convertToFramerate(_tracks[_audioTrackIndex]->timeScale); uint32 sample = curAudioTime.totalNumberOfFrames(); - uint32 seekSample = sample; + uint32 seekSample = sample; if (!isOldDemuxing()) { // We shouldn't have audio samples that are a different duration @@ -246,7 +246,7 @@ void QuickTimeAudioDecoder::setAudioStreamPos(const Timestamp &where) { totalSamples += chunkSampleCount; } - + // Reposition the audio stream queueNextAudioChunk(); if (sample != totalSamples) { diff --git a/audio/decoders/quicktime.h b/audio/decoders/quicktime.h index ff81ec9390..9f6c6c20e0 100644 --- a/audio/decoders/quicktime.h +++ b/audio/decoders/quicktime.h @@ -45,13 +45,13 @@ namespace Common { namespace Audio { class SeekableAudioStream; - + /** * Try to load a QuickTime sound file from the given file name and create a SeekableAudioStream * from that data. * - * @param filename the filename of the file from which to read the data - * @return a new SeekableAudioStream, or NULL, if an error occurred + * @param filename the filename of the file from which to read the data + * @return a new SeekableAudioStream, or NULL, if an error occurred */ SeekableAudioStream *makeQuickTimeStream(const Common::String &filename); @@ -59,9 +59,9 @@ SeekableAudioStream *makeQuickTimeStream(const Common::String &filename); * Try to load a QuickTime sound file from the given seekable stream and create a SeekableAudioStream * from that data. * - * @param stream the SeekableReadStream from which to read the data - * @param disposeAfterUse whether to delete the stream after use - * @return a new SeekableAudioStream, or NULL, if an error occurred + * @param stream the SeekableReadStream from which to read the data + * @param disposeAfterUse whether to delete the stream after use + * @return a new SeekableAudioStream, or NULL, if an error occurred */ SeekableAudioStream *makeQuickTimeStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); diff --git a/audio/decoders/voc.cpp b/audio/decoders/voc.cpp index 74ea4440a1..be53f945ac 100644 --- a/audio/decoders/voc.cpp +++ b/audio/decoders/voc.cpp @@ -118,7 +118,11 @@ static byte *loadVOCFromStream(Common::ReadStream &stream, int &size, int &rate, debug(9, "VOC Data Block: %d, %d, %d", rate, packing, len); if (packing == 0) { if (size) { - ret_sound = (byte *)realloc(ret_sound, size + len); + byte *tmp = (byte *)realloc(ret_sound, size + len); + if (!tmp) + error("Cannot reallocate memory for VOC Data Block"); + + ret_sound = tmp; } else { ret_sound = (byte *)malloc(len); } diff --git a/audio/mididrv.cpp b/audio/mididrv.cpp index 22d473a518..b71c02f991 100644 --- a/audio/mididrv.cpp +++ b/audio/mididrv.cpp @@ -190,27 +190,35 @@ MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) { case MT_NULL: reslt = hdl; + break; default: break; } Common::String failedDevStr; + if (getMusicType(hdl) == MT_INVALID) { + // If the expressly selected driver or device cannot be found (no longer compiled in, turned off, etc.) + // we display a warning and continue. + failedDevStr = ConfMan.get("music_driver"); + Common::String warningMsg = Common::String::format(_("The selected audio device '%s' was not found (e.g. might be turned off or disconnected). Attempting to fall back to the next available device..."), failedDevStr.c_str()); + GUI::MessageDialog dialog(warningMsg); + dialog.runModal(); + } + MusicType tp = getMusicType(reslt); if (tp != MT_INVALID && tp != MT_AUTO) { if (checkDevice(reslt)) { return reslt; } else { - // If the expressly selected device is unavailable we display a warning and continue. + // If the expressly selected device cannot be used we display a warning and continue. failedDevStr = getDeviceString(hdl, MidiDriver::kDeviceName); - Common::String warningMsg = Common::String::format(_("Failed to detect the selected audio device '%s'. See log file for more information. Attempting to fall back to the next available device..."), failedDevStr.c_str()); + Common::String warningMsg = Common::String::format(_("The selected audio device '%s' cannot be used. See log file for more information. Attempting to fall back to the next available device..."), failedDevStr.c_str()); GUI::MessageDialog dialog(warningMsg); dialog.runModal(); } } - reslt = 0; - // If the selected driver did not match the flags setting, // we try to determine a suitable and "optimal" music driver. const MusicPlugin::List p = MusicMan.getPlugins(); @@ -220,34 +228,44 @@ MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) { while (flags != MDT_NONE) { if ((flags & MDT_MIDI) && !skipMidi) { // If a preferred MT32 or GM device has been selected that device gets returned if available. + Common::String devStr; if (flags & MDT_PREFER_MT32) - hdl = getDeviceHandle(ConfMan.get("mt32_device")); + devStr = ConfMan.get("mt32_device"); else if (flags & MDT_PREFER_GM) - hdl = getDeviceHandle(ConfMan.get("gm_device")); + devStr = ConfMan.get("gm_device"); else - hdl = getDeviceHandle("auto"); + devStr = "auto"; + hdl = getDeviceHandle(devStr); const MusicType type = getMusicType(hdl); // If we have a "Don't use GM/MT-32" setting we skip this part and jump // to AdLib, PC Speaker etc. detection right away. if (type != MT_NULL) { - if (type != MT_AUTO && type != MT_INVALID) { + if (type == MT_INVALID) { + // If the preferred (expressly requested) selected driver or device cannot be found (no longer compiled in, turned off, etc.) + // we display a warning and continue. Don't warn about the missing device if we did already (this becomes relevant if the + // missing device is selected as preferred device and also as GM or MT-32 device). + if (failedDevStr != devStr) { + Common::String warningMsg = Common::String::format(_("The preferred audio device '%s' was not found (e.g. might be turned off or disconnected). Attempting to fall back to the next available device..."), devStr.c_str()); + GUI::MessageDialog dialog(warningMsg); + dialog.runModal(); + } + } else if (type != MT_AUTO) { if (checkDevice(hdl)) { if (flags & MDT_PREFER_MT32) // If we have a preferred MT32 device we disable the gm/mt32 mapping (more about this in mididrv.h). _forceTypeMT32 = true; return hdl; } else { - // If the preferred (expressly requested) device is unavailable we display a warning and continue. - // Don't warn about the missing device if we did already (this becomes relevant if the failing + // If the preferred (expressly requested) device cannot be used we display a warning and continue. + // Don't warn about the failing device if we did already (this becomes relevant if the failing // device is selected as preferred device and also as GM or MT-32 device). - if (failedDevStr != getDeviceString(hdl, MidiDriver::kDeviceName)) { - Common::String warningMsg = Common::String::format(_("Failed to detect the preferred device '%s'. See log file for more information. Attempting to fall back to the next available device..."), getDeviceString(hdl, MidiDriver::kDeviceName).c_str()); + if (failedDevStr != getDeviceString(hdl, MidiDriver::kDeviceName)) { + Common::String warningMsg = Common::String::format(_("The preferred audio device '%s' cannot be used. See log file for more information. Attempting to fall back to the next available device..."), getDeviceString(hdl, MidiDriver::kDeviceName).c_str()); GUI::MessageDialog dialog(warningMsg); dialog.runModal(); } - hdl = 0; } } @@ -262,15 +280,12 @@ MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) { hdl = d->getHandle(); if (checkDevice(hdl)) return hdl; - else - // No warning here, since the user hasn't expressly requested anything. - hdl = 0; } } } } - // Now we default to the first available device with music type 'MT_GM' if not + // Now we default to the first available device with music type 'MT_GM' if not // MT-32 is preferred or if MT-32 is preferred but all other devices have failed. if (!(flags & MDT_PREFER_MT32) || flags == (MDT_PREFER_MT32 | MDT_MIDI)) { for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); ++m) { @@ -280,9 +295,6 @@ MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) { hdl = d->getHandle(); if (checkDevice(hdl)) return hdl; - else - // No warning here, since the user hasn't expressly requested anything. - hdl = 0; } } } @@ -336,15 +348,12 @@ MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) { hdl = d->getHandle(); if (checkDevice(hdl)) return hdl; - else - // No warning here, since the user hasn't expressly requested anything. - hdl = 0; } } } } - return reslt; + return 0; } MidiDriver *MidiDriver::createMidi(MidiDriver::DeviceHandle handle) { diff --git a/audio/midiparser_xmidi.cpp b/audio/midiparser_xmidi.cpp index 7c3cf102d1..85491faaf8 100644 --- a/audio/midiparser_xmidi.cpp +++ b/audio/midiparser_xmidi.cpp @@ -256,26 +256,25 @@ bool MidiParser_XMIDI::loadMusic(byte *data, uint32 size) { // Add eight bytes i += 8; - if (memcmp(buf, "INFO", 4)) { - // Must align - pos += (chunk_len + 1) & ~1; - i += (chunk_len + 1) & ~1; - continue; - } - - // Must be at least 2 bytes long - if (chunk_len < 2) { - warning("Invalid chunk length %d for 'INFO' block", (int)chunk_len); - return false; - } + if (memcmp(buf, "INFO", 4) == 0) { + // Must be at least 2 bytes long + if (chunk_len < 2) { + warning("Invalid chunk length %d for 'INFO' block", (int)chunk_len); + return false; + } - _num_tracks = (byte)read2low(pos); + _num_tracks = (byte)read2low(pos); - if (chunk_len > 2) { - warning("Chunk length %d is greater than 2", (int)chunk_len); - pos += chunk_len - 2; + if (chunk_len > 2) { + warning("Chunk length %d is greater than 2", (int)chunk_len); + //pos += chunk_len - 2; + } + break; } - break; + + // Must align + pos += (chunk_len + 1) & ~1; + i += (chunk_len + 1) & ~1; } // Didn't get to fill the header diff --git a/audio/mixer.cpp b/audio/mixer.cpp index fb4fffb8d8..128224ae85 100644 --- a/audio/mixer.cpp +++ b/audio/mixer.cpp @@ -94,6 +94,13 @@ public: void setVolume(const byte volume); /** + * Gets the channel's own volume. + * + * @return volume + */ + byte getVolume(); + + /** * Sets the channel's balance setting. * * @param balance new balance @@ -101,6 +108,13 @@ public: void setBalance(const int8 balance); /** + * Gets the channel's balance setting. + * + * @return balance + */ + int8 getBalance(); + + /** * Notifies the channel that the global sound type * volume settings changed. */ @@ -342,6 +356,14 @@ void MixerImpl::setChannelVolume(SoundHandle handle, byte volume) { _channels[index]->setVolume(volume); } +byte MixerImpl::getChannelVolume(SoundHandle handle) { + const int index = handle._val % NUM_CHANNELS; + if (!_channels[index] || _channels[index]->getHandle()._val != handle._val) + return 0; + + return _channels[index]->getVolume(); +} + void MixerImpl::setChannelBalance(SoundHandle handle, int8 balance) { Common::StackLock lock(_mutex); @@ -352,6 +374,14 @@ void MixerImpl::setChannelBalance(SoundHandle handle, int8 balance) { _channels[index]->setBalance(balance); } +int8 MixerImpl::getChannelBalance(SoundHandle handle) { + const int index = handle._val % NUM_CHANNELS; + if (!_channels[index] || _channels[index]->getHandle()._val != handle._val) + return 0; + + return _channels[index]->getBalance(); +} + uint32 MixerImpl::getSoundElapsedTime(SoundHandle handle) { return getElapsedTime(handle).msecs(); } @@ -482,11 +512,19 @@ void Channel::setVolume(const byte volume) { updateChannelVolumes(); } +byte Channel::getVolume() { + return _volume; +} + void Channel::setBalance(const int8 balance) { _balance = balance; updateChannelVolumes(); } +int8 Channel::getBalance() { + return _balance; +} + void Channel::updateChannelVolumes() { // From the channel balance/volume and the global volume, we compute // the effective volume for the left and right channel. Note the diff --git a/audio/mixer.h b/audio/mixer.h index 1fbe265488..de709e13fe 100644 --- a/audio/mixer.h +++ b/audio/mixer.h @@ -211,6 +211,14 @@ public: virtual void setChannelVolume(SoundHandle handle, byte volume) = 0; /** + * Get the channel volume for the given handle. + * + * @param handle the sound to affect + * @return channel volume + */ + virtual byte getChannelVolume(SoundHandle handle) = 0; + + /** * Set the channel balance for the given handle. * * @param handle the sound to affect @@ -220,6 +228,14 @@ public: virtual void setChannelBalance(SoundHandle handle, int8 balance) = 0; /** + * Get the channel balance for the given handle. + * + * @param handle the sound to affect + * @return channel balance + */ + virtual int8 getChannelBalance(SoundHandle handle) = 0; + + /** * Get approximation of for how long the channel has been playing. */ virtual uint32 getSoundElapsedTime(SoundHandle handle) = 0; diff --git a/audio/mixer_intern.h b/audio/mixer_intern.h index a04eb55c5b..dc361ce560 100644 --- a/audio/mixer_intern.h +++ b/audio/mixer_intern.h @@ -105,7 +105,9 @@ public: virtual bool isSoundTypeMuted(SoundType type) const; virtual void setChannelVolume(SoundHandle handle, byte volume); + virtual byte getChannelVolume(SoundHandle handle); virtual void setChannelBalance(SoundHandle handle, int8 balance); + virtual int8 getChannelBalance(SoundHandle handle); virtual uint32 getSoundElapsedTime(SoundHandle handle); virtual Timestamp getElapsedTime(SoundHandle handle); diff --git a/audio/mpu401.cpp b/audio/mpu401.cpp index caad945258..966e367a93 100644 --- a/audio/mpu401.cpp +++ b/audio/mpu401.cpp @@ -33,7 +33,10 @@ void MidiChannel_MPU401::init(MidiDriver *owner, byte channel) { bool MidiChannel_MPU401::allocate() { if (_allocated) return false; - return (_allocated = true); + + _allocated = true; + + return true; } MidiDriver *MidiChannel_MPU401::device() { diff --git a/audio/rate.cpp b/audio/rate.cpp index 83abd6150b..0fc23a8a54 100644 --- a/audio/rate.cpp +++ b/audio/rate.cpp @@ -298,6 +298,9 @@ public: _bufferSize = osamp; } + if (!_buffer) + error("[CopyRateConverter::flow] Cannot allocate memory for temp buffer"); + // Read up to 'osamp' samples into our temporary buffer len = input.readBuffer(_buffer, osamp); diff --git a/audio/softsynth/fmtowns_pc98/towns_audio.cpp b/audio/softsynth/fmtowns_pc98/towns_audio.cpp index beee5f1cad..28591117f0 100644 --- a/audio/softsynth/fmtowns_pc98/towns_audio.cpp +++ b/audio/softsynth/fmtowns_pc98/towns_audio.cpp @@ -67,7 +67,7 @@ public: void updateEnvelopeGenerator(); - void setInstrument(uint8 *instr); + void setInstrument(uint8 *instr); void setLevel(uint8 lvl); void setPitch(uint32 pt); void setBalance(uint8 blc); @@ -272,12 +272,12 @@ private: static const uint8 _fmDefaultInstrument[]; }; -TownsAudioInterfaceInternal::TownsAudioInterfaceInternal(Audio::Mixer *mixer, TownsAudioInterface *owner, TownsAudioInterfacePluginDriver *driver, bool externalMutexHandling) : +TownsAudioInterfaceInternal::TownsAudioInterfaceInternal(Audio::Mixer *mixer, TownsAudioInterface *owner, TownsAudioInterfacePluginDriver *driver, bool externalMutexHandling) : TownsPC98_FmSynth(mixer, kTypeTowns, externalMutexHandling), _fmInstruments(0), _pcmInstruments(0), _pcmChan(0), _waveTables(0), _waveTablesTotalDataSize(0), _baserate(55125.0f / (float)mixer->getOutputRate()), _tickLength(0), _timer(0), _drv(driver), _drvOwner(owner), _pcmSfxChanMask(0), _musicVolume(Audio::Mixer::kMaxMixerVolume), _sfxVolume(Audio::Mixer::kMaxMixerVolume), - _outputVolumeFlags(0), _fmChanPlaying(0), + _outputVolumeFlags(0), _fmChanPlaying(0), _numReservedChannels(0), _numWaveTables(0), _updateOutputVol(false), _ready(false) { #define INTCB(x) &TownsAudioInterfaceInternal::intf_##x @@ -431,7 +431,7 @@ void TownsAudioInterfaceInternal::releaseRef(TownsAudioInterface *owner) { return; _refCount--; - + if (_refCount) { if (_refInstance) _refInstance->removePluginDriver(owner); @@ -484,7 +484,7 @@ int TownsAudioInterfaceInternal::processCommand(int command, va_list &args) { if (command < 0 || command > 81) return 4; - + Common::StackLock lock(_mutex); int res = (this->*_intfOpcodes[command])(args); @@ -564,7 +564,7 @@ void TownsAudioInterfaceInternal::nextTickEx(int32 *buffer, uint32 bufferSize) { } finOutL += oL; finOutR += oR; - + if (!(_pcmChan[ii]._activeKey || _pcmChan[ii]._activeEffect)) _pcmChan[ii]._activeOutput = false; } @@ -996,7 +996,7 @@ int TownsAudioInterfaceInternal::intf_setOutputMute(va_list &args) { if (mute & 2) memset(&_outputMute[12], 1, 4); if (mute & 1) - memset(&_outputMute[8], 1, 4); + memset(&_outputMute[8], 1, 4); _outputMute[(f < 0x80) ? 11 : 15] = 0; f += f; @@ -1009,8 +1009,8 @@ int TownsAudioInterfaceInternal::intf_setOutputMute(va_list &args) { _outputMute[(f < 0x80) ? 0 : 4] = 0; f += f; _outputMute[(f < 0x80) ? 1 : 5] = 0; - f += f; - + f += f; + updateOutputVolume(); return 0; } @@ -1581,7 +1581,7 @@ void TownsAudio_PcmChannel::clear() { _envTotalLevel = _envAttackRate = _envDecayRate = _envSustainLevel = _envSustainRate = _envReleaseRate = 0; _envStep = _envCurrentLevel = 0; - _envState = kEnvReady; + _envState = kEnvReady; _activeKey = _activeEffect = _activeOutput = _keyPressed = _reserved = false; @@ -1650,7 +1650,7 @@ void TownsAudio_PcmChannel::keyOn(uint8 note, uint8 velo, TownsAudio_WaveTable * _activeEffect = true; else _keyPressed = _activeKey = true; - + _activeOutput = true; } @@ -1742,7 +1742,7 @@ void TownsAudio_PcmChannel::setBalance(uint8 blc) { void TownsAudio_PcmChannel::updateOutput() { if (_activeKey || _activeEffect) { _pos += _step; - + if (&_data[_pos >> 11] >= _loopEnd) { if (_loopLen) { _pos -= _loopLen; @@ -1811,7 +1811,7 @@ void TownsAudio_PcmChannel::setVelo(uint8 velo) { _envTotalLevel = ((_envTotalLevel * lvl) >> 14) & 0xff; _envSustainLevel = ((_envSustainLevel * lvl) >> 14) & 0xff; envAttack(); - _tl = (_envCurrentLevel >> 8) << 1; + _tl = (_envCurrentLevel >> 8) << 1; } } diff --git a/audio/softsynth/fmtowns_pc98/towns_midi.cpp b/audio/softsynth/fmtowns_pc98/towns_midi.cpp index 071a697615..e415a0dda5 100644 --- a/audio/softsynth/fmtowns_pc98/towns_midi.cpp +++ b/audio/softsynth/fmtowns_pc98/towns_midi.cpp @@ -36,7 +36,7 @@ public: void setupProgram(const uint8 *data, uint8 mLevelPara, uint8 tLevelPara); void setupEffects(int index, uint8 flags, const uint8 *effectData); void setModWheel(uint8 value); - + void connect(TownsMidiInputChannel *chan); void disconnect(); @@ -100,7 +100,7 @@ private: uint8 _operator1Tl; uint8 _sustainNoteOff; int16 _duration; - + uint16 _freq; int16 _freqAdjust; @@ -134,7 +134,7 @@ public: void controlChange(byte control, byte value); void pitchBendFactor(byte value); void priority(byte value); - void sysEx_customInstrument(uint32 type, const byte *instr); + void sysEx_customInstrument(uint32 type, const byte *instr); private: void controlModulationWheel(byte value); @@ -145,7 +145,7 @@ private: void releasePedal(); TownsMidiOutputChannel *_out; - + uint8 *_instrument; uint8 _prg; uint8 _chanIndex; @@ -175,7 +175,7 @@ private: class TownsMidiChanState { public: TownsMidiChanState(); - ~TownsMidiChanState() {} + ~TownsMidiChanState() {} uint8 get(uint8 type); uint8 unk1; @@ -247,7 +247,7 @@ void TownsMidiOutputChannel::setupProgram(const uint8 *data, uint8 mLevelPara, u // music (unsuitable data is just forced into the wrong audio device). static const uint8 mul[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 12, 12, 15, 15 }; - uint8 chan = _chanMap[_chan]; + uint8 chan = _chanMap[_chan]; uint8 mulAmsFms1 = _driver->_chanState[chan].mulAmsFms = data[0]; uint8 tl1 = _driver->_chanState[chan].tl = (data[1] | 0x3f) - mLevelPara; @@ -296,7 +296,7 @@ void TownsMidiOutputChannel::setupProgram(const uint8 *data, uint8 mLevelPara, u void TownsMidiOutputChannel::setupEffects(int index, uint8 flags, const uint8 *effectData) { uint16 effectMaxLevel[] = { 0x2FF, 0x1F, 0x07, 0x3F, 0x0F, 0x0F, 0x0F, 0x03, 0x3F, 0x0F, 0x0F, 0x0F, 0x03, 0x3E, 0x1F }; uint8 effectType[] = { 0x1D, 0x1C, 0x1B, 0x00, 0x03, 0x04, 0x07, 0x08, 0x0D, 0x10, 0x11, 0x14, 0x15, 0x1e, 0x1f, 0x00 }; - + EffectEnvelope *s = &_effectEnvelopes[index]; EffectDef *d = &_effectDefs[index]; @@ -354,7 +354,7 @@ void TownsMidiOutputChannel::connect(TownsMidiInputChannel *chan) { void TownsMidiOutputChannel::disconnect() { keyOff(); - + TownsMidiOutputChannel *p = _prev; TownsMidiOutputChannel *n = _next; @@ -448,10 +448,10 @@ int TownsMidiOutputChannel::advanceEffectEnvelope(EffectEnvelope *s, EffectDef * s->state = kEnvReady; return 0; } - } + } int32 t = s->currentLevel + s->incrPerStep; - + s->incrCountRem += s->incrPerStepRem; if (s->incrCountRem >= s->numSteps) { s->incrCountRem -= s->numSteps; @@ -492,7 +492,7 @@ void TownsMidiOutputChannel::initNextEnvelopeState(EffectEnvelope *s) { if (v & 0x80) e = _driver->randomValue(e); - + if (!e) e = 1; @@ -525,7 +525,7 @@ void TownsMidiOutputChannel::initNextEnvelopeState(EffectEnvelope *s) { int16 TownsMidiOutputChannel::getEffectStartLevel(uint8 type) { uint8 chan = (type < 13) ? _chanMap2[_chan] : ((type < 26) ? _chanMap[_chan] : _chan); - + if (type == 28) return 15; else if (type == 29) @@ -539,8 +539,8 @@ int16 TownsMidiOutputChannel::getEffectStartLevel(uint8 type) { uint8 res = (_driver->_chanState[chan].get(def[0] >> 5) & def[2]) >> def[1]; if (def[3]) res = def[3] - res; - - return res; + + return res; } int TownsMidiOutputChannel::getEffectModLevel(int lvl, int mod) { @@ -554,12 +554,12 @@ int TownsMidiOutputChannel::getEffectModLevel(int lvl, int mod) { return ((lvl + 1) * mod) >> 5; if (mod < 0) { - if (lvl < 0) + if (lvl < 0) return _driver->_operatorLevelTable[((-lvl) << 5) - mod]; else return -_driver->_operatorLevelTable[(lvl << 5) - mod]; } else { - if (lvl < 0) + if (lvl < 0) return -_driver->_operatorLevelTable[((-lvl) << 5) + mod]; else return _driver->_operatorLevelTable[((-lvl) << 5) + mod]; @@ -577,7 +577,7 @@ void TownsMidiOutputChannel::keyOff() { } void TownsMidiOutputChannel::keyOnSetFreq(uint16 frq) { - uint16 note = (frq << 1) >> 8; + uint16 note = (frq << 1) >> 8; frq = (_freqMSB[note] << 11) | _freqLSB[note] ; out(0xa4, frq >> 8); out(0xa0, frq & 0xff); @@ -701,7 +701,7 @@ void TownsMidiInputChannel::noteOff(byte note) { void TownsMidiInputChannel::noteOn(byte note, byte velocity) { TownsMidiOutputChannel *oc = _driver->allocateOutputChannel(_priority); - + if (!oc) return; @@ -711,7 +711,7 @@ void TownsMidiInputChannel::noteOn(byte note, byte velocity) { oc->_note = note; oc->_sustainNoteOff = 0; oc->_duration = _instrument[29] * 63; - + oc->_operator1Tl = (_instrument[1] & 0x3f) + _driver->_operatorLevelTable[((velocity >> 1) << 5) + (_instrument[4] >> 2)]; if (oc->_operator1Tl > 63) oc->_operator1Tl = 63; @@ -840,7 +840,7 @@ MidiDriver_TOWNS::MidiDriver_TOWNS(Audio::Mixer *mixer) : _timerProc(0), _timerP _channels = new TownsMidiInputChannel*[32]; for (int i = 0; i < 32; i++) _channels[i] = new TownsMidiInputChannel(this, i > 8 ? (i + 1) : i); - + _out = new TownsMidiOutputChannel*[6]; for (int i = 0; i < 6; i++) _out[i] = new TownsMidiOutputChannel(this, i); @@ -964,7 +964,7 @@ MidiChannel *MidiDriver_TOWNS::allocateChannel() { if (!_isOpen) return 0; - for (int i = 0; i < 32; ++i) { + for (int i = 0; i < 32; ++i) { TownsMidiInputChannel *chan = _channels[i]; if (chan->allocate()) return chan; @@ -1023,7 +1023,7 @@ TownsMidiOutputChannel *MidiDriver_TOWNS::allocateOutputChannel(uint8 pri) { res = _out[_allocCurPos]; } } - + if (res) res->disconnect(); diff --git a/audio/softsynth/fmtowns_pc98/towns_midi.h b/audio/softsynth/fmtowns_pc98/towns_midi.h index 9aa7c93b35..8c764c55d9 100644 --- a/audio/softsynth/fmtowns_pc98/towns_midi.h +++ b/audio/softsynth/fmtowns_pc98/towns_midi.h @@ -57,7 +57,7 @@ private: void updateOutputChannels(); TownsMidiOutputChannel *allocateOutputChannel(uint8 pri); - + int randomValue(int para); TownsMidiInputChannel **_channels; @@ -72,11 +72,11 @@ private: uint32 _tickCounter; uint8 _allocCurPos; uint8 _rand; - + bool _isOpen; uint8 *_operatorLevelTable; - + const uint16 _baseTempo; }; diff --git a/audio/softsynth/fmtowns_pc98/towns_pc98_driver.cpp b/audio/softsynth/fmtowns_pc98/towns_pc98_driver.cpp index 49fe97caf1..001d258873 100644 --- a/audio/softsynth/fmtowns_pc98/towns_pc98_driver.cpp +++ b/audio/softsynth/fmtowns_pc98/towns_pc98_driver.cpp @@ -1265,7 +1265,7 @@ void TownsPC98_AudioDriver::fadeStep() { void TownsPC98_AudioDriver::pause() { _musicPlaying = false; } - + void TownsPC98_AudioDriver::cont() { _musicPlaying = true; } diff --git a/audio/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp b/audio/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp index 63007ba93c..b4967a556f 100644 --- a/audio/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp +++ b/audio/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp @@ -1160,12 +1160,12 @@ int TownsPC98_FmSynth::readBuffer(int16 *buffer, const int numSamples) { for (int i = 0; i < 2; i++) { if (_timers[i].enabled && _timers[i].cb) { if (!_timers[i].smpTillCb) { - + if (locked && _externalMutex) { _mutex.unlock(); locked = false; } - + (this->*_timers[i].cb)(); if (!locked && _externalMutex) { diff --git a/audio/softsynth/mt32.cpp b/audio/softsynth/mt32.cpp index 6d13ec33b4..6703a6f7b7 100644 --- a/audio/softsynth/mt32.cpp +++ b/audio/softsynth/mt32.cpp @@ -564,8 +564,8 @@ bool MT32EmuMusicPlugin::checkDevice(MidiDriver::DeviceHandle) const { warning("The MT-32 emulator requires one of the two following file sets (not bundled with ScummVM):\n Either 'MT32_CONTROL.ROM' and 'MT32_PCM.ROM' or 'CM32L_CONTROL.ROM' and 'CM32L_PCM.ROM'"); return false; } - - return true; + + return true; } Common::Error MT32EmuMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const { diff --git a/audio/softsynth/opl/mame.cpp b/audio/softsynth/opl/mame.cpp index 74699ba4c6..15e869ba33 100644 --- a/audio/softsynth/opl/mame.cpp +++ b/audio/softsynth/opl/mame.cpp @@ -725,6 +725,8 @@ static int OPLOpenTable(void) { ENV_CURVE = (int *)malloc(sizeof(int) * (2*EG_ENT+1)); + if (!ENV_CURVE) + error("[OPLOpenTable] Cannot allocate memory"); /* envelope counter -> envelope output table */ for (i=0; i < EG_ENT; i++) { |