From 9785d5007a7754ab988b51a8780d6a3dcc80dce4 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Fri, 18 Jan 2019 19:19:25 +0100 Subject: ZVISION: Boost volume for MPEG cutscenes The high-resolution videos play back at much lower volume than the original ones. This adds hard-coded values for how much to amplify each cutscene. It's all done by ear, and it does introduce some clipping, but I think it should be acceptable. Of course, it could also be a problem with the audio decoder, so this may be the wrong approach entirely. --- audio/decoders/ac3.cpp | 20 +++++++++++++------- audio/decoders/ac3.h | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'audio') diff --git a/audio/decoders/ac3.cpp b/audio/decoders/ac3.cpp index c569179996..1b2a3bff76 100644 --- a/audio/decoders/ac3.cpp +++ b/audio/decoders/ac3.cpp @@ -24,6 +24,7 @@ #include "common/ptr.h" #include "common/stream.h" #include "common/textconsole.h" +#include "common/util.h" #include "audio/audiostream.h" #include "audio/decoders/ac3.h" @@ -37,7 +38,7 @@ namespace Audio { class AC3Stream : public PacketizedAudioStream { public: - AC3Stream(); + AC3Stream(double decibel); ~AC3Stream(); bool init(Common::SeekableReadStream &firstPacket); @@ -62,9 +63,14 @@ private: byte *_inBufPtr; int _flags; int _sampleRate; + double _audioGain; }; -AC3Stream::AC3Stream() : _a52State(0), _frameSize(0), _inBufPtr(0), _flags(0), _sampleRate(0) { +AC3Stream::AC3Stream(double decibel = 0.0) : _a52State(0), _frameSize(0), _inBufPtr(0), _flags(0), _sampleRate(0) { + if (decibel != 0.0) + _audioGain = pow(2, decibel / 6); + else + _audioGain = 1.0; } AC3Stream::~AC3Stream() { @@ -153,7 +159,7 @@ void AC3Stream::queuePacket(Common::SeekableReadStream *data) { } else { // TODO: Eventually support more than just stereo max int flags = A52_STEREO | A52_ADJUST_LEVEL; - sample_t level = 32767; + sample_t level = 32767 * _audioGain; if (a52_frame(_a52State, _inBuf, &flags, &level, 0) != 0) error("Frame fail"); @@ -165,8 +171,8 @@ void AC3Stream::queuePacket(Common::SeekableReadStream *data) { if (a52_block(_a52State) == 0) { sample_t *samples = a52_samples(_a52State); for (int j = 0; j < 256; j++) { - *outputPtr++ = (int16)samples[j]; - *outputPtr++ = (int16)samples[j + 256]; + *outputPtr++ = (int16)CLIP(samples[j], -32768, 32767); + *outputPtr++ = (int16)CLIP(samples[j + 256], -32768, 32767); } outputLength += 1024; @@ -189,8 +195,8 @@ void AC3Stream::queuePacket(Common::SeekableReadStream *data) { } } -PacketizedAudioStream *makeAC3Stream(Common::SeekableReadStream &firstPacket) { - Common::ScopedPtr stream(new AC3Stream()); +PacketizedAudioStream *makeAC3Stream(Common::SeekableReadStream &firstPacket, double decibel) { + Common::ScopedPtr stream(new AC3Stream(decibel)); if (!stream->init(firstPacket)) return 0; diff --git a/audio/decoders/ac3.h b/audio/decoders/ac3.h index a51107a410..249d1dcfa2 100644 --- a/audio/decoders/ac3.h +++ b/audio/decoders/ac3.h @@ -41,7 +41,7 @@ class PacketizedAudioStream; * @param firstPacket The stream containing the first packet of data * @return A new PacketizedAudioStream, or NULL on error */ -PacketizedAudioStream *makeAC3Stream(Common::SeekableReadStream &firstPacket); +PacketizedAudioStream *makeAC3Stream(Common::SeekableReadStream &firstPacket, double decibel = 0.0); } // End of namespace Audio -- cgit v1.2.3