diff options
Diffstat (limited to 'engines/sci/sound/audio32.h')
-rw-r--r-- | engines/sci/sound/audio32.h | 231 |
1 files changed, 112 insertions, 119 deletions
diff --git a/engines/sci/sound/audio32.h b/engines/sci/sound/audio32.h index 71f5883541..a0167f3d2d 100644 --- a/engines/sci/sound/audio32.h +++ b/engines/sci/sound/audio32.h @@ -50,22 +50,23 @@ struct AudioChannel { ResourceId id; /** - * The resource loaded into this channel. + * The resource loaded into this channel. The resource is owned by + * ResourceManager. */ Resource *resource; /** - * The audio stream loaded into this channel. Can cast - * to `SeekableAudioStream` for normal channels and - * `RobotAudioStream` for robot channels. + * The audio stream loaded into this channel. Can cast to + * `SeekableAudioStream` for normal channels and `RobotAudioStream` for + * robot channels. */ - Audio::AudioStream *stream; + Common::ScopedPtr<Audio::AudioStream> stream; /** - * The converter used to transform and merge the input - * stream into the mixer's output buffer. + * The converter used to transform and merge the input stream into the + * mixer's output buffer. */ - Audio::RateConverter *converter; + Common::ScopedPtr<Audio::RateConverter> converter; /** * Duration of the channel, in ticks. @@ -83,8 +84,8 @@ struct AudioChannel { uint32 pausedAtTick; /** - * The time, in ticks, that the channel fade began. - * If 0, the channel is not being faded. + * The time, in ticks, that the channel fade began. If 0, the channel is not + * being faded. */ uint32 fadeStartTick; @@ -104,20 +105,19 @@ struct AudioChannel { int fadeTargetVolume; /** - * Whether or not the channel should be stopped and - * freed when the fade is complete. + * Whether or not the channel should be stopped and freed when the fade is + * complete. */ bool stopChannelOnFade; /** - * Whether or not this channel contains a Robot - * audio block. + * Whether or not this channel contains a Robot audio block. */ bool robot; /** - * For digital sound effects, the related VM - * Sound::nodePtr object for the sound. + * For digital sound effects, the related VM Sound::nodePtr object for the + * sound. */ reg_t soundNode; @@ -127,17 +127,37 @@ struct AudioChannel { int volume; /** - * The amount to pan to the right, from 0 to 100. - * 50 is centered, -1 is not panned. + * The amount to pan to the right, from 0 to 100. 50 is centered, -1 is not + * panned. */ int pan; + + AudioChannel &operator=(AudioChannel &other) { + id = other.id; + resource = other.resource; + stream.reset(other.stream.release()); + converter.reset(other.converter.release()); + duration = other.duration; + startedAtTick = other.startedAtTick; + pausedAtTick = other.pausedAtTick; + fadeStartTick = other.fadeStartTick; + fadeStartVolume = other.fadeStartVolume; + fadeDuration = other.fadeDuration; + fadeTargetVolume = other.fadeTargetVolume; + stopChannelOnFade = other.stopChannelOnFade; + robot = other.robot; + soundNode = other.soundNode; + volume = other.volume; + pan = other.pan; + return *this; + } }; #pragma mark - /** - * Special audio channel indexes used to select a channel - * for digital audio playback. + * Special audio channel indexes used to select a channel for digital audio + * playback. */ enum AudioChannelIndex { kRobotChannel = -3, @@ -146,10 +166,9 @@ enum AudioChannelIndex { }; /** - * Audio32 acts as a permanent audio stream into the system - * mixer and provides digital audio services for the SCI32 - * engine, since the system mixer does not support all the - * features of SCI. + * Audio32 acts as a permanent audio stream into the system mixer and provides + * digital audio services for the SCI32 engine, since the system mixer does not + * support all the features of SCI. */ class Audio32 : public Audio::AudioStream, public Common::Serializable { public: @@ -196,10 +215,10 @@ private: bool channelShouldMix(const AudioChannel &channel) const; /** - * Mixes audio from the given source stream into the - * target buffer using the given rate converter. + * Mixes audio from the given source stream into the target buffer using the + * given rate converter. */ - int writeAudioInternal(Audio::AudioStream *const sourceStream, Audio::RateConverter *const converter, Audio::st_sample_t *targetBuffer, const int numSamples, const Audio::st_volume_t leftVolume, const Audio::st_volume_t rightVolume); + int writeAudioInternal(Audio::AudioStream &sourceStream, Audio::RateConverter &converter, Audio::st_sample_t *targetBuffer, const int numSamples, const Audio::st_volume_t leftVolume, const Audio::st_volume_t rightVolume); #pragma mark - #pragma mark Channel management @@ -226,17 +245,15 @@ public: uint8 getNumUnlockedChannels() const; /** - * Finds a channel that is already configured for the - * given audio sample. + * Finds a channel that is already configured for the given audio sample. * - * @param startIndex The location of the audio resource - * information in the arguments list. + * @param startIndex The location of the audio resource information in the + * arguments list. */ int16 findChannelByArgs(int argc, const reg_t *argv, const int startIndex, const reg_t soundNode) const; /** - * Finds a channel that is already configured for the - * given audio sample. + * Finds a channel that is already configured for the given audio sample. */ int16 findChannelById(const ResourceId resourceId, const reg_t soundNode = NULL_REG) const; @@ -255,26 +272,24 @@ private: Common::Array<AudioChannel> _channels; /** - * The number of active audio channels in the mixer. - * Being active is not the same as playing; active - * channels may be paused. + * The number of active audio channels in the mixer. Being active is not the + * same as playing; active channels may be paused. */ uint8 _numActiveChannels; /** * Whether or not we are in the audio thread. * - * This flag is used instead of passing a parameter to - * `freeUnusedChannels` because a parameter would - * require forwarding through the public method `stop`, - * and there is not currently any reason for this - * implementation detail to be exposed. + * This flag is used instead of passing a parameter to `freeUnusedChannels` + * because a parameter would require forwarding through the public method + * `stop`, and there is not currently any reason for this implementation + * detail to be exposed. */ bool _inAudioThread; /** - * The list of resources from freed channels that need - * to be unlocked from the main thread. + * The list of resources from freed channels that need to be unlocked from + * the main thread. */ UnlockList _resourcesToUnlock; @@ -302,8 +317,7 @@ private: } /** - * Frees all non-looping channels that have reached the - * end of their stream. + * Frees all non-looping channels that have reached the end of their stream. */ void freeUnusedChannels(); @@ -313,8 +327,7 @@ private: void freeChannel(const int16 channelIndex); /** - * Unlocks all resources that were freed by the audio - * thread. + * Unlocks all resources that were freed by the audio thread. */ void unlockResources(); @@ -322,58 +335,58 @@ private: #pragma mark Script compatibility public: /** - * Gets the (fake) sample rate of the hardware DAC. - * For script compatibility only. + * Gets the (fake) sample rate of the hardware DAC. For script compatibility + * only. */ inline uint16 getSampleRate() const { return _globalSampleRate; } /** - * Sets the (fake) sample rate of the hardware DAC. - * For script compatibility only. + * Sets the (fake) sample rate of the hardware DAC. For script compatibility + * only. */ void setSampleRate(uint16 rate); /** - * Gets the (fake) bit depth of the hardware DAC. - * For script compatibility only. + * Gets the (fake) bit depth of the hardware DAC. For script compatibility + * only. */ inline uint8 getBitDepth() const { return _globalBitDepth; } /** - * Sets the (fake) sample rate of the hardware DAC. - * For script compatibility only. + * Sets the (fake) sample rate of the hardware DAC. For script compatibility + * only. */ void setBitDepth(uint8 depth); /** - * Gets the (fake) number of output (speaker) channels - * of the hardware DAC. For script compatibility only. + * Gets the (fake) number of output (speaker) channels of the hardware DAC. + * For script compatibility only. */ inline uint8 getNumOutputChannels() const { return _globalNumOutputChannels; } /** - * Sets the (fake) number of output (speaker) channels - * of the hardware DAC. For script compatibility only. + * Sets the (fake) number of output (speaker) channels of the hardware DAC. + * For script compatibility only. */ void setNumOutputChannels(int16 numChannels); /** - * Gets the (fake) number of preloaded channels. - * For script compatibility only. + * Gets the (fake) number of preloaded channels. For script compatibility + * only. */ inline uint8 getPreload() const { return _preload; } /** - * Sets the (fake) number of preloaded channels. - * For script compatibility only. + * Sets the (fake) number of preloaded channels. For script compatibility + * only. */ inline void setPreload(uint8 preload) { _preload = preload; @@ -381,49 +394,43 @@ public: private: /** - * The hardware DAC sample rate. Stored only for script - * compatibility. + * The hardware DAC sample rate. Stored only for script compatibility. */ uint16 _globalSampleRate; /** - * The maximum allowed sample rate of the system mixer. - * Stored only for script compatibility. + * The maximum allowed sample rate of the system mixer. Stored only for + * script compatibility. */ uint16 _maxAllowedSampleRate; /** - * The hardware DAC bit depth. Stored only for script - * compatibility. + * The hardware DAC bit depth. Stored only for script compatibility. */ uint8 _globalBitDepth; /** - * The maximum allowed bit depth of the system mixer. - * Stored only for script compatibility. + * The maximum allowed bit depth of the system mixer. Stored only for script + * compatibility. */ uint8 _maxAllowedBitDepth; /** - * The hardware DAC output (speaker) channel - * configuration. Stored only for script compatibility. + * The hardware DAC output (speaker) channel configuration. Stored only for + * script compatibility. */ uint8 _globalNumOutputChannels; /** - * The maximum allowed number of output (speaker) - * channels of the system mixer. Stored only for script - * compatibility. + * The maximum allowed number of output (speaker) channels of the system + * mixer. Stored only for script compatibility. */ uint8 _maxAllowedOutputChannels; /** - * The number of audio channels that should have their - * data preloaded into memory instead of streaming from - * disk. - * 1 = all channels, 2 = 2nd active channel and above, - * etc. - * Stored only for script compatibility. + * The number of audio channels that should have their data preloaded into + * memory instead of streaming from disk. 1 = all channels, 2 = 2nd active + * channel and above, etc. Stored only for script compatibility. */ uint8 _preload; @@ -442,8 +449,7 @@ private: int16 findRobotChannel() const; /** - * When true, channels marked as robot audio will not be - * played. + * When true, channels marked as robot audio will not be played. */ bool _robotAudioPaused; @@ -456,8 +462,8 @@ public: uint16 play(int16 channelIndex, const ResourceId resourceId, const bool autoPlay, const bool loop, const int16 volume, const reg_t soundNode, const bool monitor); /** - * Resumes playback of a paused audio channel, or of - * the entire audio player. + * Resumes playback of a paused audio channel, or of the entire audio + * player. */ bool resume(const int16 channelIndex); bool resume(const ResourceId resourceId, const reg_t soundNode = NULL_REG) { @@ -475,8 +481,7 @@ public: } /** - * Stops and unloads an audio channel, or the entire - * audio player. + * Stops and unloads an audio channel, or the entire audio player. */ int16 stop(const int16 channelIndex); int16 stop(const ResourceId resourceId, const reg_t soundNode = NULL_REG) { @@ -490,8 +495,7 @@ public: uint16 restart(const ResourceId resourceId, const bool autoPlay, const bool loop, const int16 volume, const reg_t soundNode, const bool monitor); /** - * Returns the playback position for the given channel - * number, in ticks. + * Returns the playback position for the given channel number, in ticks. */ int16 getPosition(const int16 channelIndex) const; int16 getPosition(const ResourceId resourceId, const reg_t soundNode = NULL_REG) { @@ -531,8 +535,8 @@ private: #pragma mark Effects public: /** - * Gets the volume for a given channel. Passing - * `kAllChannels` will get the global volume. + * Gets the volume for a given channel. Passing `kAllChannels` will get the + * global volume. */ int16 getVolume(const int16 channelIndex) const; int16 getVolume(const ResourceId resourceId, const reg_t soundNode) const { @@ -541,8 +545,8 @@ public: } /** - * Sets the volume of an audio channel. Passing - * `kAllChannels` will set the global volume. + * Sets the volume of an audio channel. Passing `kAllChannels` will set the + * global volume. */ void setVolume(const int16 channelIndex, int16 volume); void setVolume(const ResourceId resourceId, const reg_t soundNode, const int16 volume) { @@ -583,24 +587,21 @@ public: private: /** - * If true, audio will be mixed by reducing the target - * buffer by half every time a new channel is mixed in. - * The final channel is not attenuated. + * If true, audio will be mixed by reducing the target buffer by half every + * time a new channel is mixed in. The final channel is not attenuated. */ bool _attenuatedMixing; /** - * When true, a modified attenuation algorithm is used - * (`A/4 + B`) instead of standard linear attenuation - * (`A/2 + B/2`). + * When true, a modified attenuation algorithm is used (`A/4 + B`) instead + * of standard linear attenuation (`A/2 + B/2`). */ bool _useModifiedAttenuation; /** * Processes an audio fade for the given channel. * - * @returns true if the fade was completed and the - * channel was stopped. + * @returns true if the fade was completed and the channel was stopped. */ bool processFade(const int16 channelIndex); @@ -608,35 +609,27 @@ private: #pragma mark Signal monitoring public: /** - * Returns whether the currently monitored audio channel - * contains any signal within the next audio frame. + * Returns whether the currently monitored audio channel contains any signal + * within the next audio frame. */ bool hasSignal() const; private: /** - * The index of the channel being monitored for signal, - * or -1 if no channel is monitored. When a channel is - * monitored, it also causes the engine to play only the - * monitored channel. + * The index of the channel being monitored for signal, or -1 if no channel + * is monitored. When a channel is monitored, it also causes the engine to + * play only the monitored channel. */ int16 _monitoredChannelIndex; /** - * The data buffer holding decompressed audio data for - * the channel that will be monitored for an audio - * signal. - */ - Audio::st_sample_t *_monitoredBuffer; - - /** - * The size of the buffer, in bytes. + * The data buffer holding decompressed audio data for the channel that will + * be monitored for an audio signal. */ - size_t _monitoredBufferSize; + Common::Array<Audio::st_sample_t> _monitoredBuffer; /** - * The number of valid audio samples in the signal - * monitoring buffer. + * The number of valid audio samples in the signal monitoring buffer. */ int _numMonitoredSamples; |