Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

VIDEO: Add volume/balance control to VideoDecoder

  • Loading branch information...
commit 10f7e805c20c164a7b3a20832237341136165e28 1 parent 792d1e6
@clone2727 clone2727 authored
View
12 engines/agos/animation.cpp
@@ -333,7 +333,7 @@ void MoviePlayerDXA::startSound() {
if (_bgSoundStream != NULL) {
_vm->_mixer->stopHandle(_bgSound);
- _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_bgSound, _bgSoundStream);
+ _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_bgSound, _bgSoundStream, -1, getVolume(), getBalance());
}
}
@@ -399,6 +399,16 @@ bool MoviePlayerDXA::processFrame() {
return false;
}
+void MoviePlayerDXA::updateVolume() {
+ if (g_system->getMixer()->isSoundHandleActive(_bgSound))
+ g_system->getMixer()->setChannelVolume(_bgSound, getVolume());
+}
+
+void MoviePlayerDXA::updateBalance() {
+ if (g_system->getMixer()->isSoundHandleActive(_bgSound))
+ g_system->getMixer()->setChannelBalance(_bgSound, getBalance());
+}
+
///////////////////////////////////////////////////////////////////////////////
// Movie player for Smacker movies
///////////////////////////////////////////////////////////////////////////////
View
5 engines/agos/animation.h
@@ -83,6 +83,11 @@ class MoviePlayerDXA : public MoviePlayer, Video::DXADecoder {
void nextFrame();
virtual void stopVideo();
+protected:
+ // VideoDecoder API
+ void updateVolume();
+ void updateBalance();
+
private:
void handleNextFrame();
bool processFrame();
View
12 engines/sci/video/robot_decoder.cpp
@@ -116,7 +116,7 @@ bool RobotDecoder::loadStream(Common::SeekableReadStream *stream) {
if (_header.hasSound) {
_audioStream = Audio::makeQueuingAudioStream(11025, false);
- _mixer->playStream(Audio::Mixer::kMusicSoundType, &_audioHandle, _audioStream);
+ _mixer->playStream(Audio::Mixer::kMusicSoundType, &_audioHandle, _audioStream, -1, getVolume(), getBalance());
}
readPaletteChunk(_header.paletteDataSize);
@@ -361,6 +361,16 @@ void RobotDecoder::close() {
reset();
}
+void RobotDecoder::updateVolume() {
+ if (g_system->getMixer()->isSoundHandleActive(_audioHandle))
+ g_system->getMixer()->setChannelVolume(_audioHandle, getVolume());
+}
+
+void RobotDecoder::updateBalance() {
+ if (g_system->getMixer()->isSoundHandleActive(_audioHandle))
+ g_system->getMixer()->setChannelBalance(_audioHandle, getBalance());
+}
+
#endif
} // End of namespace Sci
View
5 engines/sci/video/robot_decoder.h
@@ -71,6 +71,11 @@ class RobotDecoder : public Video::FixedRateVideoDecoder {
Common::Point getPos() const { return _pos; }
protected:
+ // VideoDecoder API
+ void updateVolume();
+ void updateBalance();
+
+ // FixedRateVideoDecoder API
Common::Rational getFrameRate() const { return Common::Rational(60, 10); }
private:
View
12 engines/sword25/fmv/theora_decoder.cpp
@@ -289,7 +289,7 @@ bool TheoraDecoder::loadStream(Common::SeekableReadStream *stream) {
}
if (_audStream)
- g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, _audHandle, _audStream);
+ g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, _audHandle, _audStream, -1, getVolume(), getBalance());
} else {
// tear down the partial vorbis setup
vorbis_info_clear(&_vorbisInfo);
@@ -550,6 +550,16 @@ void TheoraDecoder::translateYUVtoRGBA(th_ycbcr_buffer &YUVBuffer) {
Graphics::convertYUV420ToRGB(&_surface, YUVBuffer[kBufferY].data, YUVBuffer[kBufferU].data, YUVBuffer[kBufferV].data, YUVBuffer[kBufferY].width, YUVBuffer[kBufferY].height, YUVBuffer[kBufferY].stride, YUVBuffer[kBufferU].stride);
}
+void TheoraDecoder::updateVolume() {
+ if (g_system->getMixer()->isSoundHandleActive(*_audHandle))
+ g_system->getMixer()->setChannelVolume(*_audHandle, getVolume());
+}
+
+void TheoraDecoder::updateBalance() {
+ if (g_system->getMixer()->isSoundHandleActive(*_audHandle))
+ g_system->getMixer()->setChannelBalance(*_audHandle, getBalance());
+}
+
} // End of namespace Sword25
#endif
View
3  engines/sword25/fmv/theora_decoder.h
@@ -87,6 +87,9 @@ class TheoraDecoder : public Video::VideoDecoder {
bool endOfVideo() const;
protected:
+ // VideoDecoder API
+ void updateVolume();
+ void updateBalance();
void pauseVideoIntern(bool pause);
private:
View
12 video/avi_decoder.cpp
@@ -262,7 +262,7 @@ bool AviDecoder::loadStream(Common::SeekableReadStream *stream) {
// Initialize the video stuff too
_audStream = createAudioStream();
if (_audStream)
- _mixer->playStream(_soundType, _audHandle, _audStream);
+ _mixer->playStream(_soundType, _audHandle, _audStream, -1, getVolume(), getBalance());
debug (0, "Frames = %d, Dimensions = %d x %d", _header.totalFrames, _header.width, _header.height);
debug (0, "Frame Rate = %d", _vidsHeader.rate / _vidsHeader.scale);
@@ -451,4 +451,14 @@ void AviDecoder::queueAudioBuffer(uint32 chunkSize) {
}
}
+void AviDecoder::updateVolume() {
+ if (g_system->getMixer()->isSoundHandleActive(*_audHandle))
+ g_system->getMixer()->setChannelVolume(*_audHandle, getVolume());
+}
+
+void AviDecoder::updateBalance() {
+ if (g_system->getMixer()->isSoundHandleActive(*_audHandle))
+ g_system->getMixer()->setChannelBalance(*_audHandle, getBalance());
+}
+
} // End of namespace Video
View
5 video/avi_decoder.h
@@ -202,6 +202,11 @@ class AviDecoder : public FixedRateVideoDecoder {
bool hasDirtyPalette() const { return _dirtyPalette; }
protected:
+ // VideoDecoder API
+ void updateVolume();
+ void updateBalance();
+
+ // FixedRateVideoDecoder API
Common::Rational getFrameRate() const { return Common::Rational(_vidsHeader.rate, _vidsHeader.scale); }
private:
View
12 video/bink_decoder.cpp
@@ -120,7 +120,7 @@ void BinkDecoder::startAudio() {
const AudioTrack &audio = _audioTracks[_audioTrack];
_audioStream = Audio::makeQueuingAudioStream(audio.outSampleRate, audio.outChannels == 2);
- g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_audioHandle, _audioStream);
+ g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_audioHandle, _audioStream, -1, getVolume(), getBalance());
} // else no audio
}
@@ -1647,4 +1647,14 @@ void BinkDecoder::IDCTPut(DecodeContext &ctx, int16 *block) {
}
}
+void BinkDecoder::updateVolume() {
+ if (g_system->getMixer()->isSoundHandleActive(_audioHandle))
+ g_system->getMixer()->setChannelVolume(_audioHandle, getVolume());
+}
+
+void BinkDecoder::updateBalance() {
+ if (g_system->getMixer()->isSoundHandleActive(_audioHandle))
+ g_system->getMixer()->setChannelBalance(_audioHandle, getBalance());
+}
+
} // End of namespace Video
View
5 video/bink_decoder.h
@@ -78,7 +78,12 @@ class BinkDecoder : public FixedRateVideoDecoder {
// Bink specific
bool loadStream(Common::SeekableReadStream *stream, const Graphics::PixelFormat &format);
+
protected:
+ // VideoDecoder API
+ void updateVolume();
+ void updateBalance();
+
static const int kAudioChannelsMax = 2;
static const int kAudioBlockSizeMax = (kAudioChannelsMax << 11);
View
24 video/coktel_decoder.cpp
@@ -1292,7 +1292,7 @@ void IMDDecoder::processFrame() {
// Start the audio stream if necessary
if (startSound && _soundEnabled) {
_mixer->playStream(_soundType, &_audioHandle, _audioStream,
- -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO);
+ -1, getVolume(), getBalance(), DisposeAfterUse::NO);
_soundStage = kSoundPlaying;
}
@@ -1474,6 +1474,16 @@ Graphics::PixelFormat IMDDecoder::getPixelFormat() const {
return Graphics::PixelFormat::createFormatCLUT8();
}
+void IMDDecoder::updateVolume() {
+ if (g_system->getMixer()->isSoundHandleActive(_audioHandle))
+ g_system->getMixer()->setChannelVolume(_audioHandle, getVolume());
+}
+
+void IMDDecoder::updateBalance() {
+ if (g_system->getMixer()->isSoundHandleActive(_audioHandle))
+ g_system->getMixer()->setChannelBalance(_audioHandle, getBalance());
+}
+
VMDDecoder::File::File() {
offset = 0;
@@ -2161,7 +2171,7 @@ void VMDDecoder::processFrame() {
if (startSound && _soundEnabled) {
if (_hasSound && _audioStream) {
_mixer->playStream(_soundType, &_audioHandle, _audioStream,
- -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO);
+ -1, getVolume(), getBalance(), DisposeAfterUse::NO);
_soundStage = kSoundPlaying;
} else
_soundStage = kSoundNone;
@@ -2687,6 +2697,16 @@ bool VMDDecoder::isPaletted() const {
return _isPaletted;
}
+void VMDDecoder::updateVolume() {
+ if (g_system->getMixer()->isSoundHandleActive(_audioHandle))
+ g_system->getMixer()->setChannelVolume(_audioHandle, getVolume());
+}
+
+void VMDDecoder::updateBalance() {
+ if (g_system->getMixer()->isSoundHandleActive(_audioHandle))
+ g_system->getMixer()->setChannelBalance(_audioHandle, getBalance());
+}
+
} // End of namespace Video
#endif // VIDEO_COKTELDECODER_H
View
10 video/coktel_decoder.h
@@ -284,6 +284,11 @@ class IMDDecoder : public CoktelDecoder {
Graphics::PixelFormat getPixelFormat() const;
+protected:
+ // VideoDecoder API
+ void updateVolume();
+ void updateBalance();
+
private:
enum Command {
kCommandNextSound = 0xFF00,
@@ -388,6 +393,11 @@ class VMDDecoder : public CoktelDecoder {
Graphics::PixelFormat getPixelFormat() const;
+protected:
+ // VideoDecoder API
+ void updateVolume();
+ void updateBalance();
+
private:
enum PartType {
kPartTypeSeparator = 0,
View
12 video/psx_decoder.cpp
@@ -385,7 +385,7 @@ void PSXStreamDecoder::queueAudioFromSector(Common::SeekableReadStream *sector)
uint rate = (format & (1 << 2)) ? 18900 : 37800;
_audStream = Audio::makeQueuingAudioStream(rate, stereo);
- g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_audHandle, _audStream);
+ g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_audHandle, _audStream, -1, getVolume(), getBalance());
}
sector->seek(24);
@@ -694,4 +694,14 @@ void PSXStreamDecoder::decodeBlock(Common::BitStream *bits, byte *block, int pit
}
}
+void PSXStreamDecoder::updateVolume() {
+ if (g_system->getMixer()->isSoundHandleActive(_audHandle))
+ g_system->getMixer()->setChannelVolume(_audHandle, getVolume());
+}
+
+void PSXStreamDecoder::updateBalance() {
+ if (g_system->getMixer()->isSoundHandleActive(_audHandle))
+ g_system->getMixer()->setChannelBalance(_audHandle, getBalance());
+}
+
} // End of namespace Video
View
5 video/psx_decoder.h
@@ -81,6 +81,11 @@ class PSXStreamDecoder : public VideoDecoder {
Graphics::PixelFormat getPixelFormat() const { return _surface->format; }
bool endOfVideo() const { return _stream->pos() >= _stream->size(); }
+protected:
+ // VideoDecoder API
+ void updateVolume();
+ void updateBalance();
+
private:
void initCommon();
Common::SeekableReadStream *_stream;
View
14 video/qt_decoder.cpp
@@ -97,7 +97,7 @@ void QuickTimeDecoder::startAudio() {
updateAudioBuffer();
for (uint32 i = 0; i < _audioTracks.size(); i++) {
- g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_audioHandles[i], _audioTracks[i], -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO);
+ g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_audioHandles[i], _audioTracks[i], -1, getVolume(), getBalance(), DisposeAfterUse::NO);
// Pause the audio again if we're still paused
if (isPaused())
@@ -236,6 +236,18 @@ bool QuickTimeDecoder::loadStream(Common::SeekableReadStream *stream) {
return true;
}
+void QuickTimeDecoder::updateVolume() {
+ for (uint32 i = 0; i < _audioHandles.size(); i++)
+ if (g_system->getMixer()->isSoundHandleActive(_audioHandles[i]))
+ g_system->getMixer()->setChannelVolume(_audioHandles[i], getVolume());
+}
+
+void QuickTimeDecoder::updateBalance() {
+ for (uint32 i = 0; i < _audioHandles.size(); i++)
+ if (g_system->getMixer()->isSoundHandleActive(_audioHandles[i]))
+ g_system->getMixer()->setChannelBalance(_audioHandles[i], getBalance());
+}
+
void QuickTimeDecoder::init() {
Audio::QuickTimeAudioDecoder::init();
View
4 video/qt_decoder.h
@@ -133,6 +133,10 @@ class QuickTimeDecoder : public SeekableVideoDecoder, public Audio::QuickTimeAud
Common::QuickTimeParser::SampleDesc *readSampleDesc(Track *track, uint32 format);
+ // VideoDecoder API
+ void updateVolume();
+ void updateBalance();
+
private:
void init();
View
12 video/smk_decoder.cpp
@@ -667,7 +667,7 @@ void SmackerDecoder::handleAudioTrack(byte track, uint32 chunkSize, uint32 unpac
}
if (!_audioStarted) {
- _mixer->playStream(_soundType, &_audioHandle, _audioStream, -1, 255);
+ _mixer->playStream(_soundType, &_audioHandle, _audioStream, -1, getVolume(), getBalance());
_audioStarted = true;
}
} else {
@@ -819,4 +819,14 @@ void SmackerDecoder::unpackPalette() {
free(chunk);
}
+void SmackerDecoder::updateVolume() {
+ if (g_system->getMixer()->isSoundHandleActive(_audioHandle))
+ g_system->getMixer()->setChannelVolume(_audioHandle, getVolume());
+}
+
+void SmackerDecoder::updateBalance() {
+ if (g_system->getMixer()->isSoundHandleActive(_audioHandle))
+ g_system->getMixer()->setChannelBalance(_audioHandle, getBalance());
+}
+
} // End of namespace Video
View
8 video/smk_decoder.h
@@ -77,9 +77,15 @@ class SmackerDecoder : public FixedRateVideoDecoder {
virtual void handleAudioTrack(byte track, uint32 chunkSize, uint32 unpackedSize);
protected:
- Common::Rational getFrameRate() const { return _frameRate; }
Common::SeekableReadStream *_fileStream;
+ // VideoDecoder API
+ void updateVolume();
+ void updateBalance();
+
+ // FixedRateVideoDecoder API
+ Common::Rational getFrameRate() const { return _frameRate; }
+
protected:
void unpackPalette();
// Possible runs of blocks
View
14 video/video_decoder.cpp
@@ -22,6 +22,8 @@
#include "video/video_decoder.h"
+#include "audio/mixer.h" // for kMaxChannelVolume
+
#include "common/rational.h"
#include "common/file.h"
#include "common/system.h"
@@ -61,6 +63,8 @@ void VideoDecoder::reset() {
_curFrame = -1;
_startTime = 0;
_pauseLevel = 0;
+ _audioVolume = Audio::Mixer::kMaxChannelVolume;
+ _audioBalance = 0;
}
bool VideoDecoder::endOfVideo() const {
@@ -94,6 +98,16 @@ void VideoDecoder::resetPauseStartTime() {
_pauseStartTime = g_system->getMillis();
}
+void VideoDecoder::setVolume(byte volume) {
+ _audioVolume = volume;
+ updateVolume();
+}
+
+void VideoDecoder::setBalance(int8 balance) {
+ _audioBalance = balance;
+ updateBalance();
+}
+
uint32 FixedRateVideoDecoder::getTimeToNextFrame() const {
if (endOfVideo() || _curFrame < 0)
return 0;
View
46 video/video_decoder.h
@@ -185,6 +185,40 @@ class VideoDecoder {
*/
bool isPaused() const { return _pauseLevel != 0; }
+ /**
+ * Get the current volume at which the audio in the video is being played
+ * @return the current volume at which the audio in the video is being played
+ */
+ virtual byte getVolume() const { return _audioVolume; }
+
+ /**
+ * Set the volume at which the audio in the video should be played.
+ * This setting remains until reset() is called (which may be called
+ * from loadStream() or close()). The default volume is the maximum.
+ *
+ * @note This function calls updateVolume() by default.
+ *
+ * @param volume The volume at which to play the audio in the video
+ */
+ virtual void setVolume(byte volume);
+
+ /**
+ * Get the current balance at which the audio in the video is being played
+ * @return the current balance at which the audio in the video is being played
+ */
+ virtual int8 getBalance() const { return _audioBalance; }
+
+ /**
+ * Set the balance at which the audio in the video should be played.
+ * This setting remains until reset() is called (which may be called
+ * from loadStream() or close()). The default balance is 0.
+ *
+ * @note This function calls updateBalance() by default.
+ *
+ * @param balance The balance at which to play the audio in the video
+ */
+ virtual void setBalance(int8 balance);
+
protected:
/**
* Resets _curFrame and _startTime. Should be called from every close() function.
@@ -207,12 +241,24 @@ class VideoDecoder {
*/
void resetPauseStartTime();
+ /**
+ * Update currently playing audio tracks with the new volume setting
+ */
+ virtual void updateVolume() {}
+
+ /**
+ * Update currently playing audio tracks with the new balance setting
+ */
+ virtual void updateBalance() {}
+
int32 _curFrame;
int32 _startTime;
private:
uint32 _pauseLevel;
uint32 _pauseStartTime;
+ byte _audioVolume;
+ int8 _audioBalance;
};
/**
Please sign in to comment.
Something went wrong with that request. Please try again.