1 /* 2 * Copyright 2003-2021 The Music Player Daemon Project 3 * http://www.musicpd.org 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 #ifndef MPD_CROSSFADE_HXX 21 #define MPD_CROSSFADE_HXX 22 23 #include "Chrono.hxx" 24 25 struct AudioFormat; 26 class SignedSongTime; 27 28 struct CrossFadeSettings { 29 /** 30 * Songs shorter than this will never cross-fade. 31 */ 32 static constexpr SignedSongTime MIN_TOTAL_TIME{std::chrono::seconds{20}}; 33 34 /** 35 * The configured cross fade duration [s]. 36 */ 37 FloatDuration duration{0}; 38 39 float mixramp_db{0}; 40 41 /** 42 * The configured MixRapm delay [s]. A non-positive value 43 * disables MixRamp. 44 */ 45 FloatDuration mixramp_delay{-1}; 46 IsEnabledCrossFadeSettings47 constexpr bool IsEnabled() const noexcept { 48 return duration.count() > 0; 49 } 50 51 /** 52 * Calculate how many music pipe chunks should be used for crossfading. 53 * 54 * @param current_total_time the duration of the current song 55 * @param next_total_time the duration of the new song 56 * @param replay_gain_db the ReplayGain adjustment used for this song 57 * @param replay_gain_prev_db the ReplayGain adjustment used on the last song 58 * @param mixramp_start the next songs mixramp_start tag 59 * @param mixramp_prev_end the last songs mixramp_end setting 60 * @param af the audio format of the new song 61 * @param old_format the audio format of the current song 62 * @param max_chunks the maximum number of chunks 63 * @return the number of chunks for crossfading, or 0 if cross fading 64 * should be disabled for this song change 65 */ 66 [[gnu::pure]] 67 unsigned Calculate(SignedSongTime current_total_time, 68 SignedSongTime next_total_time, 69 float replay_gain_db, float replay_gain_prev_db, 70 const char *mixramp_start, 71 const char *mixramp_prev_end, 72 AudioFormat af, AudioFormat old_format, 73 unsigned max_chunks) const noexcept; 74 75 private: 76 /** 77 * Can the described song be cross-faded? 78 */ 79 [[gnu::pure]] 80 bool CanCrossFadeSong(SignedSongTime total_time) const noexcept; 81 }; 82 83 #endif 84