1
/***************************************************************************
2
soundformat.h - description
5
copyright : (C) 2004 by Martin Witte
6
email : witte@kawo1.rwth-aachen.de
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
18
#ifndef KRADIO_SOUNDFORMAT_H
19
#define KRADIO_SOUNDFORMAT_H
30
unsigned m_SampleRate;
32
unsigned m_SampleBits;
35
QString m_Encoding; // "raw", "mp3", ... (no "wav", because it's only header + raw data)
37
SoundFormat(unsigned sample_rate, unsigned channels, unsigned sample_bits, bool is_signed, unsigned endianess, const QString &enc)
38
: m_SampleRate(sample_rate), m_Channels(channels), m_SampleBits(sample_bits), m_IsSigned(is_signed), m_Endianess(endianess), m_Encoding(enc) {}
39
SoundFormat(unsigned sample_rate, unsigned channels, unsigned sample_bits, bool is_signed, unsigned endianess)
40
: m_SampleRate(sample_rate), m_Channels(channels), m_SampleBits(sample_bits), m_IsSigned(is_signed), m_Endianess(endianess), m_Encoding("raw") {}
41
SoundFormat(unsigned sample_rate, unsigned channels, unsigned sample_bits, bool is_signed)
42
: m_SampleRate(sample_rate), m_Channels(channels), m_SampleBits(sample_bits), m_IsSigned(is_signed), m_Endianess(BYTE_ORDER), m_Encoding("raw") {}
43
SoundFormat(bool stereo)
44
: m_SampleRate(44100), m_Channels(stereo ? 2 : 1), m_SampleBits(16), m_IsSigned(true), m_Endianess(BYTE_ORDER), m_Encoding("raw") {}
46
: m_SampleRate(44100), m_Channels(2), m_SampleBits(16), m_IsSigned(true), m_Endianess(BYTE_ORDER), m_Encoding("raw") {}
48
bool operator == (const SoundFormat &o) const { return m_SampleRate == o.m_SampleRate &&
49
m_Channels == o.m_Channels &&
50
m_SampleBits == o.m_SampleBits &&
51
m_IsSigned == o.m_IsSigned &&
52
m_Endianess == o.m_Endianess &&
53
m_Encoding == o.m_Encoding
56
bool operator != (const SoundFormat &o) const { return !operator == (o); }
58
int sampleSize() const; // size of a single sample
59
int frameSize() const; // sampleSize * channels
63
void restoreConfig(const QString &prefix, KConfig *c);
64
void saveConfig(const QString &prefix, KConfig *c) const;
66
int convertSampleToInt(const char *sample, bool do_scale) const;
67
void convertIntToSample(int src, char *dst, bool is_scaled) const;
68
void convertSamplesToInts(const char *src, int *dst, size_t n, bool do_scale) const;
69
void convertIntsToSamples(const int *src, char *dst, size_t n, bool is_scaled) const;
70
void convertSamplesToFloat (const char *src, float **dst, size_t n) const;
71
void convertFloatsToSamples(const float **src, char *dst, size_t n) const;