VIDEO: Allow setting the mixer sound type used to play audio tracks

This commit is contained in:
Bastien Bouclet 2017-07-10 21:36:19 +02:00
parent 22ce8dbf38
commit ec49730711
30 changed files with 117 additions and 93 deletions

View file

@ -76,13 +76,13 @@ enum {
};
AVIDecoder::AVIDecoder(Audio::Mixer::SoundType soundType) :
_frameRateOverride(0), _soundType(soundType) {
AVIDecoder::AVIDecoder() :
_frameRateOverride(0) {
initCommon();
}
AVIDecoder::AVIDecoder(const Common::Rational &frameRateOverride, Audio::Mixer::SoundType soundType) :
_frameRateOverride(frameRateOverride), _soundType(soundType) {
AVIDecoder::AVIDecoder(const Common::Rational &frameRateOverride) :
_frameRateOverride(frameRateOverride) {
initCommon();
}
@ -91,7 +91,7 @@ AVIDecoder::~AVIDecoder() {
}
AVIDecoder::AVIAudioTrack *AVIDecoder::createAudioTrack(AVIStreamHeader sHeader, PCMWaveFormat wvInfo) {
return new AVIAudioTrack(sHeader, wvInfo, _soundType);
return new AVIAudioTrack(sHeader, wvInfo, getSoundType());
}
bool AVIDecoder::seekToFrame(uint frame) {
@ -1007,8 +1007,13 @@ void AVIDecoder::AVIVideoTrack::setDither(const byte *palette) {
_videoCodec->setDither(Image::Codec::kDitherTypeVFW, palette);
}
AVIDecoder::AVIAudioTrack::AVIAudioTrack(const AVIStreamHeader &streamHeader, const PCMWaveFormat &waveFormat, Audio::Mixer::SoundType soundType)
: _audsHeader(streamHeader), _wvInfo(waveFormat), _soundType(soundType), _audioStream(0), _packetStream(0), _curChunk(0) {
AVIDecoder::AVIAudioTrack::AVIAudioTrack(const AVIStreamHeader &streamHeader, const PCMWaveFormat &waveFormat, Audio::Mixer::SoundType soundType) :
AudioTrack(soundType),
_audsHeader(streamHeader),
_wvInfo(waveFormat),
_audioStream(0),
_packetStream(0),
_curChunk(0) {
}
AVIDecoder::AVIAudioTrack::~AVIAudioTrack() {

View file

@ -62,8 +62,8 @@ namespace Video {
*/
class AVIDecoder : public VideoDecoder {
public:
AVIDecoder(Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType);
AVIDecoder(const Common::Rational &frameRateOverride, Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType);
AVIDecoder();
AVIDecoder(const Common::Rational &frameRateOverride);
virtual ~AVIDecoder();
bool loadStream(Common::SeekableReadStream *stream);
@ -263,7 +263,6 @@ protected:
virtual void createAudioStream();
virtual void queueSound(Common::SeekableReadStream *stream);
Audio::Mixer::SoundType getSoundType() const { return _soundType; }
void skipAudio(const Audio::Timestamp &time, const Audio::Timestamp &frameTime);
virtual void resetStream();
uint32 getCurChunk() const { return _curChunk; }
@ -288,7 +287,6 @@ protected:
AVIStreamHeader _audsHeader;
PCMWaveFormat _wvInfo;
Audio::Mixer::SoundType _soundType;
Audio::AudioStream *_audioStream;
Audio::PacketizedAudioStream *_packetStream;
uint32 _curChunk;
@ -317,7 +315,6 @@ protected:
bool _foundMovieList;
uint32 _movieListStart, _movieListEnd;
Audio::Mixer::SoundType _soundType;
Common::Rational _frameRateOverride;
int _videoTrackCounter, _audioTrackCounter;

View file

@ -1349,7 +1349,9 @@ void BinkDecoder::BinkVideoTrack::IDCTPut(DecodeContext &ctx, int16 *block) {
}
}
BinkDecoder::BinkAudioTrack::BinkAudioTrack(BinkDecoder::AudioInfo &audio) : _audioInfo(&audio) {
BinkDecoder::BinkAudioTrack::BinkAudioTrack(BinkDecoder::AudioInfo &audio, Audio::Mixer::SoundType soundType) :
AudioTrack(soundType),
_audioInfo(&audio) {
_audioStream = Audio::makeQueuingAudioStream(_audioInfo->outSampleRate, _audioInfo->outChannels == 2);
}
@ -1598,7 +1600,7 @@ void BinkDecoder::initAudioTrack(AudioInfo &audio) {
else if (audio.codec == kAudioCodecDCT)
audio.dct = new Common::DCT(frameLenBits, Common::DCT::DCT_III);
addTrack(new BinkAudioTrack(audio));
addTrack(new BinkAudioTrack(audio, getSoundType()));
}
} // End of namespace Video

View file

@ -320,7 +320,7 @@ private:
class BinkAudioTrack : public AudioTrack {
public:
BinkAudioTrack(AudioInfo &audio);
BinkAudioTrack(AudioInfo &audio, Audio::Mixer::SoundType soundType);
~BinkAudioTrack();
/** Decode an audio packet. */

View file

@ -2784,6 +2784,7 @@ void VMDDecoder::setAutoStartSound(bool autoStartSound) {
}
AdvancedVMDDecoder::AdvancedVMDDecoder(Audio::Mixer::SoundType soundType) {
setSoundType(soundType);
_decoder = new VMDDecoder(g_system->getMixer(), soundType);
_decoder->setAutoStartSound(false);
}
@ -2860,11 +2861,9 @@ Common::Rational AdvancedVMDDecoder::VMDVideoTrack::getFrameRate() const {
return _decoder->getFrameRate();
}
AdvancedVMDDecoder::VMDAudioTrack::VMDAudioTrack(VMDDecoder *decoder) : _decoder(decoder) {
}
Audio::Mixer::SoundType AdvancedVMDDecoder::VMDAudioTrack::getSoundType() const {
return _decoder->getSoundType();
AdvancedVMDDecoder::VMDAudioTrack::VMDAudioTrack(VMDDecoder *decoder) :
AudioTrack(decoder->getSoundType()),
_decoder(decoder) {
}
Audio::AudioStream *AdvancedVMDDecoder::VMDAudioTrack::getAudioStream() const {

View file

@ -595,8 +595,6 @@ private:
public:
VMDAudioTrack(VMDDecoder *decoder);
Audio::Mixer::SoundType getSoundType() const;
protected:
virtual Audio::AudioStream *getAudioStream() const;

View file

@ -142,7 +142,7 @@ void MPEGPSDecoder::readNextPacket() {
} else if (startCode >= 0x1C0 && startCode <= 0x1DF) {
#ifdef USE_MAD
// MPEG Audio stream
MPEGAudioTrack *audioTrack = new MPEGAudioTrack(*packet);
MPEGAudioTrack *audioTrack = new MPEGAudioTrack(*packet, getSoundType());
stream = audioTrack;
_streamMap[startCode] = audioTrack;
addTrack(audioTrack);
@ -512,7 +512,8 @@ void MPEGPSDecoder::MPEGVideoTrack::findDimensions(Common::SeekableReadStream *f
// The audio code here is almost entirely based on what we do in mp3.cpp
MPEGPSDecoder::MPEGAudioTrack::MPEGAudioTrack(Common::SeekableReadStream &firstPacket) {
MPEGPSDecoder::MPEGAudioTrack::MPEGAudioTrack(Common::SeekableReadStream &firstPacket, Audio::Mixer::SoundType soundType) :
AudioTrack(soundType) {
_audStream = Audio::makePacketizedMP3Stream(firstPacket);
}

View file

@ -113,7 +113,7 @@ private:
// An MPEG audio track
class MPEGAudioTrack : public AudioTrack, public MPEGStream {
public:
MPEGAudioTrack(Common::SeekableReadStream &firstPacket);
MPEGAudioTrack(Common::SeekableReadStream &firstPacket, Audio::Mixer::SoundType soundType);
~MPEGAudioTrack();
bool sendPacket(Common::SeekableReadStream *packet, uint32 pts, uint32 dts);

View file

@ -247,7 +247,7 @@ void PSXStreamDecoder::readNextPacket() {
// We only handle one audio channel so far
if (track == 1) {
if (!_audioTrack) {
_audioTrack = new PSXAudioTrack(sector);
_audioTrack = new PSXAudioTrack(sector, getSoundType());
addTrack(_audioTrack);
}
@ -308,7 +308,8 @@ static const int s_xaTable[5][2] = {
{ 122, -60 }
};
PSXStreamDecoder::PSXAudioTrack::PSXAudioTrack(Common::SeekableReadStream *sector) {
PSXStreamDecoder::PSXAudioTrack::PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType) :
AudioTrack(soundType) {
assert(sector);
_endOfTrack = false;

View file

@ -125,7 +125,7 @@ private:
class PSXAudioTrack : public AudioTrack {
public:
PSXAudioTrack(Common::SeekableReadStream *sector);
PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType);
~PSXAudioTrack();
bool endOfTrack() const;

View file

@ -267,8 +267,10 @@ void QuickTimeDecoder::VideoSampleDesc::initCodec() {
_videoCodec = Image::createQuickTimeCodec(_codecTag, _parentTrack->width, _parentTrack->height, _bitsPerSample & 0x1f);
}
QuickTimeDecoder::AudioTrackHandler::AudioTrackHandler(QuickTimeDecoder *decoder, QuickTimeAudioTrack *audioTrack)
: _decoder(decoder), _audioTrack(audioTrack) {
QuickTimeDecoder::AudioTrackHandler::AudioTrackHandler(QuickTimeDecoder *decoder, QuickTimeAudioTrack *audioTrack) :
SeekableAudioTrack(decoder->getSoundType()),
_decoder(decoder),
_audioTrack(audioTrack) {
}
void QuickTimeDecoder::AudioTrackHandler::updateBuffer() {

View file

@ -277,7 +277,7 @@ uint32 BigHuffmanTree::getCode(Common::BitStream &bs) {
return v;
}
SmackerDecoder::SmackerDecoder(Audio::Mixer::SoundType soundType) : _soundType(soundType) {
SmackerDecoder::SmackerDecoder() {
_fileStream = 0;
_firstFrameStart = 0;
_frameTypes = 0;
@ -369,7 +369,7 @@ bool SmackerDecoder::loadStream(Common::SeekableReadStream *stream) {
if (_header.audioInfo[i].compression == kCompressionRDFT || _header.audioInfo[i].compression == kCompressionDCT)
warning("Unhandled Smacker v2 audio compression");
addTrack(new SmackerAudioTrack(_header.audioInfo[i], _soundType));
addTrack(new SmackerAudioTrack(_header.audioInfo[i], getSoundType()));
}
}
@ -754,7 +754,8 @@ void SmackerDecoder::SmackerVideoTrack::unpackPalette(Common::SeekableReadStream
}
SmackerDecoder::SmackerAudioTrack::SmackerAudioTrack(const AudioInfo &audioInfo, Audio::Mixer::SoundType soundType) :
_audioInfo(audioInfo), _soundType(soundType) {
AudioTrack(soundType),
_audioInfo(audioInfo) {
_audioStream = Audio::makeQueuingAudioStream(_audioInfo.sampleRate, _audioInfo.isStereo);
}

View file

@ -59,7 +59,7 @@ class BigHuffmanTree;
*/
class SmackerDecoder : public VideoDecoder {
public:
SmackerDecoder(Audio::Mixer::SoundType soundType = Audio::Mixer::kSFXSoundType);
SmackerDecoder();
virtual ~SmackerDecoder();
virtual bool loadStream(Common::SeekableReadStream *stream);
@ -164,8 +164,6 @@ private:
bool isRewindable() const { return true; }
bool rewind();
Audio::Mixer::SoundType getSoundType() const { return _soundType; }
void queueCompressedBuffer(byte *buffer, uint32 bufferSize, uint32 unpackedSize);
void queuePCM(byte *buffer, uint32 bufferSize);
@ -173,7 +171,6 @@ private:
Audio::AudioStream *getAudioStream() const;
private:
Audio::Mixer::SoundType _soundType;
Audio::QueuingAudioStream *_audioStream;
AudioInfo _audioInfo;
};
@ -186,8 +183,6 @@ private:
byte *_frameTypes;
uint32 _firstFrameStart;
Audio::Mixer::SoundType _soundType;
};
} // End of namespace Video

View file

@ -47,7 +47,7 @@
namespace Video {
TheoraDecoder::TheoraDecoder(Audio::Mixer::SoundType soundType) : _soundType(soundType) {
TheoraDecoder::TheoraDecoder() {
_fileStream = 0;
_videoTrack = 0;
@ -177,7 +177,7 @@ bool TheoraDecoder::loadStream(Common::SeekableReadStream *stream) {
th_setup_free(theoraSetup);
if (_hasAudio) {
_audioTrack = new VorbisAudioTrack(_soundType, _vorbisInfo);
_audioTrack = new VorbisAudioTrack(getSoundType(), _vorbisInfo);
// Get enough audio data to start us off
while (!_audioTrack->hasAudio()) {
@ -330,7 +330,8 @@ void TheoraDecoder::TheoraVideoTrack::translateYUVtoRGBA(th_ycbcr_buffer &YUVBuf
static vorbis_info *info = 0;
TheoraDecoder::VorbisAudioTrack::VorbisAudioTrack(Audio::Mixer::SoundType soundType, vorbis_info &vorbisInfo) : _soundType(soundType) {
TheoraDecoder::VorbisAudioTrack::VorbisAudioTrack(Audio::Mixer::SoundType soundType, vorbis_info &vorbisInfo) :
AudioTrack(soundType) {
vorbis_synthesis_init(&_vorbisDSP, &vorbisInfo);
vorbis_block_init(&_vorbisDSP, &_vorbisBlock);
info = &vorbisInfo;

View file

@ -61,7 +61,7 @@ namespace Video {
*/
class TheoraDecoder : public VideoDecoder {
public:
TheoraDecoder(Audio::Mixer::SoundType soundType = Audio::Mixer::kMusicSoundType);
TheoraDecoder();
virtual ~TheoraDecoder();
/**
@ -110,8 +110,6 @@ private:
VorbisAudioTrack(Audio::Mixer::SoundType soundType, vorbis_info &vorbisInfo);
~VorbisAudioTrack();
Audio::Mixer::SoundType getSoundType() const { return _soundType; }
bool decodeSamples();
bool hasAudio() const;
bool needsAudio() const;
@ -126,7 +124,6 @@ private:
int _audioBufferFill;
ogg_int16_t *_audioBuffer;
Audio::Mixer::SoundType _soundType;
Audio::QueuingAudioStream *_audStream;
vorbis_block _vorbisBlock;
@ -142,8 +139,6 @@ private:
Common::SeekableReadStream *_fileStream;
Audio::Mixer::SoundType _soundType;
ogg_sync_state _oggSync;
ogg_page _oggPage;
ogg_packet _oggPacket;

View file

@ -40,6 +40,7 @@ VideoDecoder::VideoDecoder() {
_playbackRate = 0;
_audioVolume = Audio::Mixer::kMaxChannelVolume;
_audioBalance = 0;
_soundType = Audio::Mixer::kPlainSoundType;
_pauseLevel = 0;
_needsUpdate = false;
_lastTimeChange = 0;
@ -143,6 +144,15 @@ void VideoDecoder::setBalance(int8 balance) {
((AudioTrack *)*it)->setBalance(_audioBalance);
}
Audio::Mixer::SoundType VideoDecoder::getSoundType() const {
return _soundType;
}
void VideoDecoder::setSoundType(Audio::Mixer::SoundType soundType) {
assert(!isVideoLoaded());
_soundType = soundType;
}
bool VideoDecoder::isVideoLoaded() const {
return !_tracks.empty();
}
@ -577,7 +587,11 @@ Audio::Timestamp VideoDecoder::FixedRateVideoTrack::getDuration() const {
return getFrameTime(getFrameCount());
}
VideoDecoder::AudioTrack::AudioTrack() : _volume(Audio::Mixer::kMaxChannelVolume), _balance(0), _muted(false) {
VideoDecoder::AudioTrack::AudioTrack(Audio::Mixer::SoundType soundType) :
_volume(Audio::Mixer::kMaxChannelVolume),
_soundType(soundType),
_balance(0),
_muted(false) {
}
bool VideoDecoder::AudioTrack::endOfTrack() const {
@ -605,7 +619,7 @@ void VideoDecoder::AudioTrack::start() {
Audio::AudioStream *stream = getAudioStream();
assert(stream);
g_system->getMixer()->playStream(getSoundType(), &_handle, stream, -1, _muted ? 0 : getVolume(), getBalance(), DisposeAfterUse::NO);
g_system->getMixer()->playStream(_soundType, &_handle, stream, -1, _muted ? 0 : getVolume(), getBalance(), DisposeAfterUse::NO);
// Pause the audio again if we're still paused
if (isPaused())
@ -624,7 +638,7 @@ void VideoDecoder::AudioTrack::start(const Audio::Timestamp &limit) {
stream = Audio::makeLimitingAudioStream(stream, limit, DisposeAfterUse::NO);
g_system->getMixer()->playStream(getSoundType(), &_handle, stream, -1, _muted ? 0 : getVolume(), getBalance(), DisposeAfterUse::YES);
g_system->getMixer()->playStream(_soundType, &_handle, stream, -1, _muted ? 0 : getVolume(), getBalance(), DisposeAfterUse::YES);
// Pause the audio again if we're still paused
if (isPaused())
@ -679,7 +693,8 @@ bool VideoDecoder::SeekableAudioTrack::seek(const Audio::Timestamp &time) {
return stream->seek(time);
}
VideoDecoder::StreamFileAudioTrack::StreamFileAudioTrack() {
VideoDecoder::StreamFileAudioTrack::StreamFileAudioTrack(Audio::Mixer::SoundType soundType) :
SeekableAudioTrack(soundType) {
_stream = 0;
}
@ -737,7 +752,7 @@ bool VideoDecoder::addStreamFileTrack(const Common::String &baseName) {
if (!isVideoLoaded())
return false;
StreamFileAudioTrack *track = new StreamFileAudioTrack();
StreamFileAudioTrack *track = new StreamFileAudioTrack(getSoundType());
bool result = track->loadFromFile(baseName);

View file

@ -430,6 +430,18 @@ public:
*/
void setBalance(int8 balance);
/**
* Get the mixer sound type audio is being played with.
*/
Audio::Mixer::SoundType getSoundType() const;
/**
* Set the mixer sound type used to play the audio tracks.
*
* This must be set before calling loadStream().
*/
void setSoundType(Audio::Mixer::SoundType soundType);
/**
* Add an audio track from a stream file.
*
@ -667,7 +679,7 @@ protected:
*/
class AudioTrack : public Track {
public:
AudioTrack();
AudioTrack(Audio::Mixer::SoundType soundType);
virtual ~AudioTrack() {}
TrackType getTrackType() const { return kTrackTypeAudio; }
@ -712,11 +724,6 @@ protected:
*/
uint32 getRunningTime() const;
/**
* Get the sound type to be used when playing this audio track
*/
virtual Audio::Mixer::SoundType getSoundType() const { return Audio::Mixer::kPlainSoundType; }
/**
* Mute the track
*/
@ -732,6 +739,7 @@ protected:
private:
Audio::SoundHandle _handle;
Audio::Mixer::SoundType _soundType;
byte _volume;
int8 _balance;
bool _muted;
@ -743,7 +751,7 @@ protected:
*/
class RewindableAudioTrack : public AudioTrack {
public:
RewindableAudioTrack() {}
RewindableAudioTrack(Audio::Mixer::SoundType soundType) : AudioTrack(soundType) {}
virtual ~RewindableAudioTrack() {}
bool isRewindable() const { return true; }
@ -765,7 +773,7 @@ protected:
*/
class SeekableAudioTrack : public AudioTrack {
public:
SeekableAudioTrack() {}
SeekableAudioTrack(Audio::Mixer::SoundType soundType) : AudioTrack(soundType) {}
virtual ~SeekableAudioTrack() {}
bool isSeekable() const { return true; }
@ -789,7 +797,7 @@ protected:
*/
class StreamFileAudioTrack : public SeekableAudioTrack {
public:
StreamFileAudioTrack();
StreamFileAudioTrack(Audio::Mixer::SoundType soundType);
~StreamFileAudioTrack();
/**
@ -953,6 +961,7 @@ private:
uint32 _pauseStartTime;
byte _audioVolume;
int8 _audioBalance;
Audio::Mixer::SoundType _soundType;
AudioTrack *_mainAudioTrack;
};