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)
115 static double decode(
const enc_sample_type& 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)
134 static double decode(
const enc_sample_type& 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)
153 static double decode(
const enc_sample_type& 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;}
173template<
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]);
190template<
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;
216 static enc_sample_type encode(
const double& s)
220 static double decode(
const enc_sample_type& s)
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)
240 static double decode(
const enc_sample_type& 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)
295 static double decode(
const enc_sample_type& s)
Generic template class for Audio samples.
Small class to represent 24-bit PCM samples.
Implementation of G.711 logarithmic codecs.
Audio_Encoding
Supported encoding types for audio samples.
int16_t alaw_expand(uint8_t s)
G.711 u-Law expansion function. Returns decoded value for previously compressed sample s....
uint8_t ulaw_compress(int16_t s)
G.711 u-Law compression function. Returns encoded value for sample s.
int16_t ulaw_expand(uint8_t s)
G.711 u-Law expansion function. Returns decoded value for previously compressed sample s....
uint8_t alaw_compress(int16_t s)
G.711 a-Law compression function. Returns encoded value for sample s.
T limit_audio_sample(double s)
Helper function for scaling and limiting of audio samples.
double audio_sample_to_double(T s)
Helper function for scaling and limiting of audio samples.
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
std::istream & operator>>(std::istream &input, bin &outbin)
Input stream of bin.
std::size_t encoded_sample_size(Audio_Encoding e)
Size of encoded sample based on the encoding type e.