diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-01-23 22:21:29 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-04-04 23:09:12 +0200 |
| commit | 0e164ad80f0ceff9d643f3b466690d013c3be19d (patch) | |
| tree | c656a136c12ff3c5d9bf8f7331610162de0c0592 /src/lib/player.cc | |
| parent | 8eb951b71fa90e54c8da64e54cf5ddf6bf0809cf (diff) | |
Add fade in/out option to the content audio tab (#1026).
Diffstat (limited to 'src/lib/player.cc')
| -rw-r--r-- | src/lib/player.cc | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/lib/player.cc b/src/lib/player.cc index abd051bed..12a53bc63 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -1049,12 +1049,28 @@ Player::audio (weak_ptr<Piece> wp, AudioStreamPtr stream, ContentAudio content_a DCPOMATIC_ASSERT (content_audio.audio->frames() > 0); - /* Gain */ - - if (content->gain() != 0) { - auto gain = make_shared<AudioBuffers>(content_audio.audio); - gain->apply_gain (content->gain()); - content_audio.audio = gain; + /* Gain and fade */ + + auto const fade_coeffs = content->fade (stream, content_audio.frame, content_audio.audio->frames(), rfr); + if (content->gain() != 0 || !fade_coeffs.empty()) { + auto gain_buffers = make_shared<AudioBuffers>(content_audio.audio); + if (!fade_coeffs.empty()) { + /* Apply both fade and gain */ + DCPOMATIC_ASSERT (fade_coeffs.size() == static_cast<size_t>(gain_buffers->frames())); + auto const channels = gain_buffers->channels(); + auto const frames = fade_coeffs.size(); + auto data = gain_buffers->data(); + auto const gain = db_to_linear (content->gain()); + for (auto channel = 0; channel < channels; ++channel) { + for (auto frame = 0U; frame < frames; ++frame) { + data[channel][frame] *= gain * fade_coeffs[frame]; + } + } + } else { + /* Just apply gain */ + gain_buffers->apply_gain (content->gain()); + } + content_audio.audio = gain_buffers; } /* Remap */ |
