Try to make audio gain work again.
authorCarl Hetherington <cth@carlh.net>
Sun, 18 Aug 2013 22:19:22 +0000 (23:19 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 18 Aug 2013 22:19:22 +0000 (23:19 +0100)
src/lib/audio_buffers.cc
src/lib/audio_buffers.h
src/lib/player.cc

index a15288a3b86c64b66f5567a3f93e7321e6e48279..e80142b8e518ad2efe66f5f1c1ee4b90f6dcafa6 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <cassert>
 #include <cstring>
+#include <cmath>
 #include <stdexcept>
 #include "audio_buffers.h"
 
@@ -260,3 +261,15 @@ AudioBuffers::accumulate_frames (AudioBuffers const * from, int read_offset, int
        }
 }
 
+/** @param dB gain in dB */
+void
+AudioBuffers::apply_gain (float dB)
+{
+       float const linear = pow (10, dB / 20);
+       
+       for (int i = 0; i < _channels; ++i) {
+               for (int j = 0; j < _frames; ++j) {
+                       _data[i][j] *= linear;
+               }
+       }
+}
index 0950f5d6775abdb15584b7af6e652aef1245a095..75bc686f83086df201ecd200510c04cbeb6b59e1 100644 (file)
@@ -57,6 +57,8 @@ public:
        void make_silent (int c);
        void make_silent (int from, int frames);
 
+       void apply_gain (float);
+
        void copy_from (AudioBuffers const * from, int frames_to_copy, int read_offset, int write_offset);
        void move (int from, int to, int frames);
        void accumulate_channel (AudioBuffers const *, int, int);
index f8ccb0142af5d3a95bdb03f4a965971049f50825..ebc8102143c167934a38e929cb586ca6caf4668c 100644 (file)
@@ -300,6 +300,13 @@ Player::process_audio (weak_ptr<Piece> weak_piece, shared_ptr<const AudioBuffers
        shared_ptr<AudioContent> content = dynamic_pointer_cast<AudioContent> (piece->content);
        assert (content);
 
+       /* Gain */
+       if (content->audio_gain() != 0) {
+               shared_ptr<AudioBuffers> gain (new AudioBuffers (audio));
+               gain->apply_gain (content->audio_gain ());
+               audio = gain;
+       }
+
        /* Resample */
        if (content->content_audio_frame_rate() != content->output_audio_frame_rate()) {
                shared_ptr<Resampler> r = resampler (content, true);