aboutsummaryrefslogtreecommitdiff
path: root/video
diff options
context:
space:
mode:
authorMatthew Hoops2012-05-27 21:18:32 -0400
committerMatthew Hoops2012-05-28 14:00:16 -0400
commit10f7e805c20c164a7b3a20832237341136165e28 (patch)
tree5a561ded0a078ddd744b42337d253730bd5177ea /video
parent792d1e6f6ae3d910fcc88f43dc92a1a761496c1e (diff)
downloadscummvm-rg350-10f7e805c20c164a7b3a20832237341136165e28.tar.gz
scummvm-rg350-10f7e805c20c164a7b3a20832237341136165e28.tar.bz2
scummvm-rg350-10f7e805c20c164a7b3a20832237341136165e28.zip
VIDEO: Add volume/balance control to VideoDecoder
Diffstat (limited to 'video')
-rw-r--r--video/avi_decoder.cpp12
-rw-r--r--video/avi_decoder.h5
-rw-r--r--video/bink_decoder.cpp12
-rw-r--r--video/bink_decoder.h5
-rw-r--r--video/coktel_decoder.cpp24
-rw-r--r--video/coktel_decoder.h10
-rw-r--r--video/psx_decoder.cpp12
-rw-r--r--video/psx_decoder.h5
-rw-r--r--video/qt_decoder.cpp14
-rw-r--r--video/qt_decoder.h4
-rw-r--r--video/smk_decoder.cpp12
-rw-r--r--video/smk_decoder.h8
-rw-r--r--video/video_decoder.cpp14
-rw-r--r--video/video_decoder.h46
14 files changed, 175 insertions, 8 deletions
diff --git a/video/avi_decoder.cpp b/video/avi_decoder.cpp
index 28fa712d4f..2ea7e8d90e 100644
--- a/video/avi_decoder.cpp
+++ b/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
diff --git a/video/avi_decoder.h b/video/avi_decoder.h
index edd08c42a0..fb4dae6711 100644
--- a/video/avi_decoder.h
+++ b/video/avi_decoder.h
@@ -202,6 +202,11 @@ public:
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:
diff --git a/video/bink_decoder.cpp b/video/bink_decoder.cpp
index 4738c3c8c0..538487f067 100644
--- a/video/bink_decoder.cpp
+++ b/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
diff --git a/video/bink_decoder.h b/video/bink_decoder.h
index f1eadc6f17..a5e1b10270 100644
--- a/video/bink_decoder.h
+++ b/video/bink_decoder.h
@@ -78,7 +78,12 @@ public:
// 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);
diff --git a/video/coktel_decoder.cpp b/video/coktel_decoder.cpp
index ae0c35cd76..be36874db4 100644
--- a/video/coktel_decoder.cpp
+++ b/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
diff --git a/video/coktel_decoder.h b/video/coktel_decoder.h
index b99a44f332..68696d5ff3 100644
--- a/video/coktel_decoder.h
+++ b/video/coktel_decoder.h
@@ -284,6 +284,11 @@ public:
Graphics::PixelFormat getPixelFormat() const;
+protected:
+ // VideoDecoder API
+ void updateVolume();
+ void updateBalance();
+
private:
enum Command {
kCommandNextSound = 0xFF00,
@@ -388,6 +393,11 @@ public:
Graphics::PixelFormat getPixelFormat() const;
+protected:
+ // VideoDecoder API
+ void updateVolume();
+ void updateBalance();
+
private:
enum PartType {
kPartTypeSeparator = 0,
diff --git a/video/psx_decoder.cpp b/video/psx_decoder.cpp
index 74f740f614..df91a2badd 100644
--- a/video/psx_decoder.cpp
+++ b/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
diff --git a/video/psx_decoder.h b/video/psx_decoder.h
index 3695cb0f42..4364ec4bbb 100644
--- a/video/psx_decoder.h
+++ b/video/psx_decoder.h
@@ -81,6 +81,11 @@ public:
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;
diff --git a/video/qt_decoder.cpp b/video/qt_decoder.cpp
index 585f5927a1..aba545abc0 100644
--- a/video/qt_decoder.cpp
+++ b/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();
diff --git a/video/qt_decoder.h b/video/qt_decoder.h
index 1f614df18b..ce32562d64 100644
--- a/video/qt_decoder.h
+++ b/video/qt_decoder.h
@@ -133,6 +133,10 @@ protected:
Common::QuickTimeParser::SampleDesc *readSampleDesc(Track *track, uint32 format);
+ // VideoDecoder API
+ void updateVolume();
+ void updateBalance();
+
private:
void init();
diff --git a/video/smk_decoder.cpp b/video/smk_decoder.cpp
index 439fe9027d..359f4cb9bd 100644
--- a/video/smk_decoder.cpp
+++ b/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
diff --git a/video/smk_decoder.h b/video/smk_decoder.h
index fd5d658bdd..516882e7c8 100644
--- a/video/smk_decoder.h
+++ b/video/smk_decoder.h
@@ -77,9 +77,15 @@ public:
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
diff --git a/video/video_decoder.cpp b/video/video_decoder.cpp
index ae82a3374c..44d7917652 100644
--- a/video/video_decoder.cpp
+++ b/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;
diff --git a/video/video_decoder.h b/video/video_decoder.h
index 2b99a2b1bf..3bb75ade09 100644
--- a/video/video_decoder.h
+++ b/video/video_decoder.h
@@ -185,6 +185,40 @@ public:
*/
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 @@ protected:
*/
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;
};
/**