foobar2000 SDK  2015-08-03
replaygain_info.cpp
Go to the documentation of this file.
1 #include "foobar2000.h"
2 
3 #ifdef _MSC_VER
4 #define RG_FPU() fpu_control_roundnearest bah;
5 #else
6 #define RG_FPU()
7 #endif
8 
9 bool replaygain_info::g_format_gain(float p_value,char p_buffer[text_buffer_size])
10 {
11  RG_FPU();
12  if (p_value == gain_invalid)
13  {
14  p_buffer[0] = 0;
15  return false;
16  }
17  else
18  {
19  pfc::float_to_string(p_buffer,text_buffer_size - 4,p_value,2,true);
20  strcat(p_buffer," dB");
21  return true;
22  }
23 }
24 
25 bool replaygain_info::g_format_peak(float p_value,char p_buffer[text_buffer_size])
26 {
27  RG_FPU();
28  if (p_value == peak_invalid)
29  {
30  p_buffer[0] = 0;
31  return false;
32  }
33  else
34  {
35  pfc::float_to_string(p_buffer,text_buffer_size,p_value,6,false);
36  return true;
37  }
38 }
39 
41 {
46 }
47 
48 static const char meta_album_gain[] = "replaygain_album_gain", meta_album_peak[] = "replaygain_album_peak", meta_track_gain[] = "replaygain_track_gain", meta_track_peak[] = "replaygain_track_peak";
49 
50 bool replaygain_info::g_is_meta_replaygain(const char * p_name,t_size p_name_len)
51 {
52  return
53  stricmp_utf8_ex(p_name,p_name_len,meta_album_gain,~0) == 0 ||
54  stricmp_utf8_ex(p_name,p_name_len,meta_album_peak,~0) == 0 ||
55  stricmp_utf8_ex(p_name,p_name_len,meta_track_gain,~0) == 0 ||
56  stricmp_utf8_ex(p_name,p_name_len,meta_track_peak,~0) == 0;
57 }
58 
59 bool replaygain_info::set_from_meta_ex(const char * p_name,t_size p_name_len,const char * p_value,t_size p_value_len)
60 {
61  RG_FPU();
62  if (stricmp_utf8_ex(p_name,p_name_len,meta_album_gain,~0) == 0)
63  {
64  m_album_gain = (float)pfc::string_to_float(p_value,p_value_len);
65  return true;
66  }
67  else if (stricmp_utf8_ex(p_name,p_name_len,meta_album_peak,~0) == 0)
68  {
69  m_album_peak = (float)pfc::string_to_float(p_value,p_value_len);
70  if (m_album_peak < 0) m_album_peak = 0;
71  return true;
72  }
73  else if (stricmp_utf8_ex(p_name,p_name_len,meta_track_gain,~0) == 0)
74  {
75  m_track_gain = (float)pfc::string_to_float(p_value,p_value_len);
76  return true;
77  }
78  else if (stricmp_utf8_ex(p_name,p_name_len,meta_track_peak,~0) == 0)
79  {
80  m_track_peak = (float)pfc::string_to_float(p_value,p_value_len);
81  if (m_track_peak < 0) m_track_peak = 0;
82  return true;
83  }
84  else return false;
85 }
86 
87 
89 {
90  t_size ret = 0;
91  if (is_album_gain_present()) ret++;
92  if (is_album_peak_present()) ret++;
93  if (is_track_gain_present()) ret++;
94  if (is_track_peak_present()) ret++;
95  return ret;
96 }
97 
98 void replaygain_info::set_album_gain_text(const char * p_text,t_size p_text_len)
99 {
100  RG_FPU();
101  if (p_text != 0 && p_text_len > 0 && *p_text != 0)
102  m_album_gain = (float)pfc::string_to_float(p_text,p_text_len);
103  else
105 }
106 
107 void replaygain_info::set_track_gain_text(const char * p_text,t_size p_text_len)
108 {
109  RG_FPU();
110  if (p_text != 0 && p_text_len > 0 && *p_text != 0)
111  m_track_gain = (float)pfc::string_to_float(p_text,p_text_len);
112  else
114 }
115 
116 void replaygain_info::set_album_peak_text(const char * p_text,t_size p_text_len)
117 {
118  RG_FPU();
119  if (p_text != 0 && p_text_len > 0 && *p_text != 0)
120  m_album_peak = (float)pfc::string_to_float(p_text,p_text_len);
121  else
123 }
124 
125 void replaygain_info::set_track_peak_text(const char * p_text,t_size p_text_len)
126 {
127  RG_FPU();
128  if (p_text != 0 && p_text_len > 0 && *p_text != 0)
129  m_track_peak = (float)pfc::string_to_float(p_text,p_text_len);
130  else
132 }
133 
135 {
136  replaygain_info ret = r1;
137  if (!ret.is_album_gain_present()) ret.m_album_gain = r2.m_album_gain;
138  if (!ret.is_album_peak_present()) ret.m_album_peak = r2.m_album_peak;
139  if (!ret.is_track_gain_present()) ret.m_track_gain = r2.m_track_gain;
140  if (!ret.is_track_peak_present()) ret.m_track_peak = r2.m_track_peak;
141  return ret;
142 }
void set_album_gain_text(const char *p_text, t_size p_text_len=pfc_infinite)
void remove_album_gain()
Definition: file_info.h:34
bool is_track_peak_present() const
Definition: file_info.h:32
int SHARED_EXPORT stricmp_utf8_ex(const char *p1, t_size len1, const char *p2, t_size len2)
void remove_album_peak()
Definition: file_info.h:36
float m_track_gain
Definition: file_info.h:4
double string_to_float(const char *src, t_size max)
static bool g_format_peak(float p_value, char p_buffer[text_buffer_size])
float m_album_peak
Definition: file_info.h:5
Structure containing ReplayGain scan results from some playable object, also providing various helper...
Definition: file_info.h:2
size_t t_size
Definition: int_types.h:48
static const char meta_track_gain[]
static bool g_is_meta_replaygain(const char *p_name, t_size p_name_len=pfc_infinite)
static bool g_format_gain(float p_value, char p_buffer[text_buffer_size])
t_size get_value_count()
void set_album_peak_text(const char *p_text, t_size p_text_len=pfc_infinite)
void set_track_peak_text(const char *p_text, t_size p_text_len=pfc_infinite)
static replaygain_info g_merge(replaygain_info r1, replaygain_info r2)
void float_to_string(char *out, t_size out_max, double val, unsigned precision, bool b_sign)
bool is_album_peak_present() const
Definition: file_info.h:31
bool is_track_gain_present() const
Definition: file_info.h:30
bool set_from_meta_ex(const char *p_name, t_size p_name_len, const char *p_value, t_size p_value_len)
static const char meta_album_peak[]
float m_album_gain
Definition: file_info.h:4
void remove_track_gain()
Definition: file_info.h:35
bool is_album_gain_present() const
Definition: file_info.h:29
void remove_track_peak()
Definition: file_info.h:37
static const char meta_track_peak[]
float m_track_peak
Definition: file_info.h:5
static const char meta_album_gain[]
void set_track_gain_text(const char *p_text, t_size p_text_len=pfc_infinite)