foobar2000 SDK  2015-08-03
Public Types | Public Member Functions | Static Public Member Functions | Data Fields
t_replaygain_config

#include <replaygain.h>

Public Types

enum  { source_mode_none, source_mode_track, source_mode_album, source_mode_byPlaybackOrder }
 
enum  { processing_mode_none, processing_mode_gain, processing_mode_gain_and_peak, processing_mode_peak }
 
typedef t_uint32 t_processing_mode
 
typedef t_uint32 t_source_mode
 

Public Member Functions

 t_replaygain_config ()
 
 t_replaygain_config (t_source_mode p_source_mode, t_processing_mode p_processing_mode, float p_preamp_without_rg, float p_preamp_with_rg)
 
void format_name (pfc::string_base &p_out) const
 
bool is_active () const
 
bool operator!= (const t_replaygain_config &other) const
 
bool operator== (const t_replaygain_config &other) const
 
audio_sample query_scale (const file_info &info) const
 
audio_sample query_scale (const metadb_handle_ptr &info) const
 
audio_sample query_scale (const replaygain_info &info) const
 
void reset ()
 

Static Public Member Functions

static bool equals (const t_replaygain_config &v1, const t_replaygain_config &v2)
 

Data Fields

float m_preamp_with_rg
 
float m_preamp_without_rg
 
t_processing_mode m_processing_mode
 
t_source_mode m_source_mode
 

Detailed Description

Structure storing ReplayGain configuration: album/track source data modes, gain/peak processing modes and preamp values.

Definition at line 2 of file replaygain.h.

Member Typedef Documentation

Definition at line 13 of file replaygain.h.

Definition at line 13 of file replaygain.h.

Member Enumeration Documentation

anonymous enum
Enumerator
source_mode_none 
source_mode_track 
source_mode_album 
source_mode_byPlaybackOrder 

Definition at line 4 of file replaygain.h.

4  {
8  // New in 1.3.8
9  // SPECIAL MODE valid only for playback settings; if set, track gain will be used for random & shuffle-tracks modes, album for shuffle albums & ordered playback.
11  };
anonymous enum

Constructor & Destructor Documentation

t_replaygain_config::t_replaygain_config ( )
inline

Definition at line 15 of file replaygain.h.

15 {reset();}
t_replaygain_config::t_replaygain_config ( t_source_mode  p_source_mode,
t_processing_mode  p_processing_mode,
float  p_preamp_without_rg,
float  p_preamp_with_rg 
)
inline

Definition at line 16 of file replaygain.h.

17  : m_source_mode(p_source_mode), m_processing_mode(p_processing_mode), m_preamp_without_rg(p_preamp_without_rg), m_preamp_with_rg(p_preamp_with_rg) {}
t_source_mode m_source_mode
Definition: replaygain.h:20
float m_preamp_without_rg
Definition: replaygain.h:22
t_processing_mode m_processing_mode
Definition: replaygain.h:21

Member Function Documentation

static bool t_replaygain_config::equals ( const t_replaygain_config v1,
const t_replaygain_config v2 
)
inlinestatic

Definition at line 32 of file replaygain.h.

32  {
34  }
t_source_mode m_source_mode
Definition: replaygain.h:20
float m_preamp_without_rg
Definition: replaygain.h:22
t_processing_mode m_processing_mode
Definition: replaygain.h:21
void t_replaygain_config::format_name ( pfc::string_base p_out) const

Definition at line 100 of file replaygain.cpp.

101 {
102  switch(m_processing_mode)
103  {
105  p_out = "None.";
106  break;
108  switch(m_source_mode)
109  {
110  case source_mode_none:
111  if (m_preamp_without_rg == 0) p_out = "None.";
112  else p_out = PFC_string_formatter() << "Preamp : " << format_dbdelta(m_preamp_without_rg);
113  break;
114  case source_mode_track:
115  {
117  fmt << "Apply track gain";
118  if (m_preamp_without_rg != 0 || m_preamp_with_rg != 0) fmt << ", with preamp";
119  fmt << ".";
120  p_out = fmt;
121  }
122  break;
123  case source_mode_album:
124  {
126  fmt << "Apply album gain";
127  if (m_preamp_without_rg != 0 || m_preamp_with_rg != 0) fmt << ", with preamp";
128  fmt << ".";
129  p_out = fmt;
130  }
131  break;
132  };
133  break;
135  switch(m_source_mode)
136  {
137  case source_mode_none:
138  if (m_preamp_without_rg >= 0) p_out = "None.";
139  else p_out = PFC_string_formatter() << "Preamp : " << format_dbdelta(m_preamp_without_rg);
140  break;
141  case source_mode_track:
142  {
144  fmt << "Apply track gain";
145  if (m_preamp_without_rg != 0 || m_preamp_with_rg != 0) fmt << ", with preamp";
146  fmt << ", prevent clipping according to track peak.";
147  p_out = fmt;
148  }
149  break;
150  case source_mode_album:
151  {
153  fmt << "Apply album gain";
154  if (m_preamp_without_rg != 0 || m_preamp_with_rg != 0) fmt << ", with preamp";
155  fmt << ", prevent clipping according to album peak.";
156  p_out = fmt;
157  }
158  break;
159  };
160  break;
162  switch(m_source_mode)
163  {
164  case source_mode_none:
165  p_out = "None.";
166  break;
167  case source_mode_track:
168  p_out = "Prevent clipping according to track peak.";
169  break;
170  case source_mode_album:
171  p_out = "Prevent clipping according to album peak.";
172  break;
173  };
174  break;
175  }
176 }
t_source_mode m_source_mode
Definition: replaygain.h:20
float m_preamp_without_rg
Definition: replaygain.h:22
t_processing_mode m_processing_mode
Definition: replaygain.h:21
bool t_replaygain_config::is_active ( ) const

Definition at line 178 of file replaygain.cpp.

179 {
180  switch(m_processing_mode)
181  {
183  return false;
185  switch(m_source_mode)
186  {
187  case source_mode_none:
188  return m_preamp_without_rg != 0;
189  case source_mode_track:
190  return true;
191  case source_mode_album:
192  return true;
193  };
194  return false;
196  switch(m_source_mode)
197  {
198  case source_mode_none:
199  return m_preamp_without_rg < 0;
200  case source_mode_track:
201  return true;
202  case source_mode_album:
203  return true;
204  };
205  return false;
207  switch(m_source_mode)
208  {
209  case source_mode_none:
210  return false;
211  case source_mode_track:
212  return true;
213  case source_mode_album:
214  return true;
215  };
216  return false;
217  default:
218  return false;
219  }
220 }
t_source_mode m_source_mode
Definition: replaygain.h:20
float m_preamp_without_rg
Definition: replaygain.h:22
t_processing_mode m_processing_mode
Definition: replaygain.h:21
bool t_replaygain_config::operator!= ( const t_replaygain_config other) const
inline

Definition at line 36 of file replaygain.h.

36 {return !equals(*this, other);}
static bool equals(const t_replaygain_config &v1, const t_replaygain_config &v2)
Definition: replaygain.h:32
bool t_replaygain_config::operator== ( const t_replaygain_config other) const
inline

Definition at line 35 of file replaygain.h.

35 {return equals(*this, other);}
static bool equals(const t_replaygain_config &v1, const t_replaygain_config &v2)
Definition: replaygain.h:32
audio_sample t_replaygain_config::query_scale ( const file_info info) const

Definition at line 11 of file replaygain.cpp.

12 {
13  return query_scale(info.get_replaygain());
14 }
audio_sample query_scale(const file_info &info) const
Definition: replaygain.cpp:11
virtual replaygain_info get_replaygain() const =0
Retrieves ReplayGain information.
audio_sample t_replaygain_config::query_scale ( const metadb_handle_ptr info) const

Definition at line 61 of file replaygain.cpp.

62 {
63  return query_scale(p_object->get_async_info_ref()->info());
64 }
audio_sample query_scale(const file_info &info) const
Definition: replaygain.cpp:11
audio_sample t_replaygain_config::query_scale ( const replaygain_info info) const

Definition at line 16 of file replaygain.cpp.

16  {
17  const audio_sample peak_margin = 1.0;//used to be 0.999 but it must not trigger on lossless
18 
19  audio_sample peak = peak_margin;
20  audio_sample gain = 0;
21 
22  bool have_rg_gain = false, have_rg_peak = false;
23 
25  {
26  float gain_select = replaygain_info::gain_invalid, peak_select = replaygain_info::peak_invalid;
28  {
29  if (info.is_track_gain_present()) {gain = info.m_track_gain; have_rg_gain = true; }
30  else if (info.is_album_gain_present()) {gain = info.m_album_gain; have_rg_gain = true; }
31  if (info.is_track_peak_present()) {peak = info.m_track_peak; have_rg_peak = true; }
32  else if (info.is_album_peak_present()) {peak = info.m_album_peak; have_rg_peak = true; }
33  }
34  else
35  {
36  if (info.is_album_gain_present()) {gain = info.m_album_gain; have_rg_gain = true; }
37  else if (info.is_track_gain_present()) {gain = info.m_track_gain; have_rg_gain = true; }
38  if (info.is_album_peak_present()) {peak = info.m_album_peak; have_rg_peak = true; }
39  else if (info.is_track_peak_present()) {peak = info.m_track_peak; have_rg_peak = true; }
40  }
41  }
42 
43  gain += have_rg_gain ? m_preamp_with_rg : m_preamp_without_rg;
44 
45  audio_sample scale = 1.0;
46 
48  {
49  scale *= audio_math::gain_to_scale(gain);
50  }
51 
53  {
54  if (scale * peak > peak_margin)
55  scale = (audio_sample)(peak_margin / peak);
56  }
57 
58  return scale;
59 }
bool is_track_peak_present() const
Definition: file_info.h:32
void SHARED_EXPORT scale(const audio_sample *p_source, t_size p_count, audio_sample *p_output, audio_sample p_scale)
p_source/p_output can point to same buffer
float m_track_gain
Definition: file_info.h:4
t_source_mode m_source_mode
Definition: replaygain.h:20
float m_album_peak
Definition: file_info.h:5
float m_preamp_without_rg
Definition: replaygain.h:22
float audio_sample
Definition: audio_sample.h:6
bool is_album_peak_present() const
Definition: file_info.h:31
bool is_track_gain_present() const
Definition: file_info.h:30
float m_album_gain
Definition: file_info.h:4
bool is_album_gain_present() const
Definition: file_info.h:29
float m_track_peak
Definition: file_info.h:5
t_processing_mode m_processing_mode
Definition: replaygain.h:21
void t_replaygain_config::reset ( )

Field Documentation

float t_replaygain_config::m_preamp_with_rg

Definition at line 22 of file replaygain.h.

float t_replaygain_config::m_preamp_without_rg

Definition at line 22 of file replaygain.h.

t_processing_mode t_replaygain_config::m_processing_mode

Definition at line 21 of file replaygain.h.

t_source_mode t_replaygain_config::m_source_mode

Definition at line 20 of file replaygain.h.


The documentation for this struct was generated from the following files: