59 enc_linear8 = 2,enc_linear16 = 3,enc_linear24 = 4,
60 enc_linear32 = 5,enc_float = 6,enc_double = 7};
74 s < -1.0 ? -1.0 : s > 1.0 ? 1.0 : s;
75 return (T)(s*max_abs);
87 return (1.0/down_scaling) * s;
108 typedef uint8_t enc_sample_type;
109 static const std::size_t enc_sample_size =
sizeof(enc_sample_type);
110 static enc_sample_type encode(
const double& s)
112 int16_t l = limit_audio_sample<int16_t, SHRT_MAX>(s);
115 static double decode(
const enc_sample_type& s)
117 return audio_sample_to_double<int16_t, SHRT_MAX>((
ulaw_expand(s)));
128 typedef int8_t enc_sample_type;
129 static const std::size_t enc_sample_size =
sizeof(enc_sample_type);
130 static enc_sample_type encode(
const double& s)
132 return limit_audio_sample<enc_sample_type, SCHAR_MAX>(s);
134 static double decode(
const enc_sample_type& s)
136 return audio_sample_to_double<enc_sample_type, SCHAR_MAX>(s);
147 typedef int16_t enc_sample_type;
148 static const std::size_t enc_sample_size =
sizeof(enc_sample_type);
149 static enc_sample_type encode(
const double& s)
151 return limit_audio_sample<enc_sample_type, SHRT_MAX>(s);
153 static double decode(
const enc_sample_type& s)
155 return audio_sample_to_double<enc_sample_type, SHRT_MAX>(s);
163 static const int32_t max_abs_value = (1<<23) - 1;
164 explicit Sample_24(uint32_t v = 0):_value(v){}
165 uint32_t value()
const {
return _value;}
166 void value(uint32_t v){_value = v;}
173 template<
typename Binary_Out_Stream>
176 uint32_t sample = v.value();
177 char *c =
reinterpret_cast<char *
>(&sample);
178 if(s.get_endianity() == s.get_native_endianity()){
184 s.put(c[2]); s.put(c[1]); s.put(c[0]);
190 template<
typename Binary_In_Stream>
194 char *c =
reinterpret_cast<char *
>(&sample);
195 if(s.get_endianity() == s.get_native_endianity()){
201 s.get(c[2]); s.get(c[1]); s.get(c[0]);
203 if(s) v.value(sample);
215 static const std::size_t enc_sample_size = 3;
218 return Sample_24(limit_audio_sample<int32_t, Sample_24::max_abs_value>(s));
222 return audio_sample_to_double<int32_t, Sample_24::max_abs_value>(s.value());
234 typedef int32_t enc_sample_type;
235 static const std::size_t enc_sample_size =
sizeof(enc_sample_type);
236 static enc_sample_type encode(
const double& s)
238 return limit_audio_sample<enc_sample_type, INT_MAX>(s);
240 static double decode(
const enc_sample_type& s)
242 return audio_sample_to_double<enc_sample_type, INT_MAX>(s);
257 typedef float enc_sample_type;
258 static const std::size_t enc_sample_size =
sizeof(enc_sample_type);
259 static enc_sample_type encode(
const double& s)
261 return (enc_sample_type)(s < -INT_MAX ? -INT_MAX : s > INT_MAX ? INT_MAX : s);
263 static double decode(
const enc_sample_type& s){
return s;}
275 typedef double enc_sample_type;
276 static const std::size_t enc_sample_size =
sizeof(enc_sample_type);
277 static enc_sample_type encode(
const double& s) {
return s;}
278 static double decode(
const enc_sample_type& s){
return s;}
288 typedef uint8_t enc_sample_type;
289 static const std::size_t enc_sample_size =
sizeof(enc_sample_type);
290 static enc_sample_type encode(
const double& s)
292 int16_t l = limit_audio_sample<int16_t, SHRT_MAX>(s);
295 static double decode(
const enc_sample_type& s)
297 return audio_sample_to_double<int16_t, SHRT_MAX>((
alaw_expand(s)));
329 #endif // #ifndef AUDIOFILE_H