soundformat.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                       soundformat.h  -  description
00003                              -------------------
00004     begin                : Sun Aug 1 2004
00005     copyright            : (C) 2004 by Martin Witte
00006     email                : witte@kawo1.rwth-aachen.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef KRADIO_SOUNDFORMAT_H
00019 #define KRADIO_SOUNDFORMAT_H
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024 
00025 #include <endian.h>
00026 #include <qstring.h>
00027 #include <kconfig.h>
00028 
00029 struct SoundFormat {
00030     unsigned     m_SampleRate;
00031     unsigned     m_Channels;
00032     unsigned     m_SampleBits;
00033     bool         m_IsSigned;
00034     unsigned     m_Endianess;
00035     QString      m_Encoding;     // "raw", "mp3", ...  (no "wav", because it's only header + raw data)
00036 
00037     SoundFormat(unsigned sample_rate, unsigned channels, unsigned sample_bits, bool is_signed, unsigned endianess, const QString &enc)
00038         : m_SampleRate(sample_rate), m_Channels(channels), m_SampleBits(sample_bits), m_IsSigned(is_signed), m_Endianess(endianess), m_Encoding(enc) {}
00039     SoundFormat(unsigned sample_rate, unsigned channels, unsigned sample_bits, bool is_signed, unsigned endianess)
00040         : m_SampleRate(sample_rate), m_Channels(channels), m_SampleBits(sample_bits), m_IsSigned(is_signed), m_Endianess(endianess), m_Encoding("raw") {}
00041     SoundFormat(unsigned sample_rate, unsigned channels, unsigned sample_bits, bool is_signed)
00042         : m_SampleRate(sample_rate), m_Channels(channels), m_SampleBits(sample_bits), m_IsSigned(is_signed), m_Endianess(BYTE_ORDER), m_Encoding("raw") {}
00043     SoundFormat(bool stereo)
00044         : m_SampleRate(44100), m_Channels(stereo ? 2 : 1), m_SampleBits(16), m_IsSigned(true), m_Endianess(BYTE_ORDER), m_Encoding("raw") {}
00045     SoundFormat()
00046         : m_SampleRate(44100), m_Channels(2), m_SampleBits(16), m_IsSigned(true), m_Endianess(BYTE_ORDER), m_Encoding("raw") {}
00047 
00048     bool operator == (const SoundFormat &o) const { return m_SampleRate == o.m_SampleRate &&
00049                                                            m_Channels   == o.m_Channels &&
00050                                                            m_SampleBits == o.m_SampleBits &&
00051                                                            m_IsSigned   == o.m_IsSigned &&
00052                                                            m_Endianess  == o.m_Endianess &&
00053                                                            m_Encoding   == o.m_Encoding
00054                                                     ;
00055                                                    }
00056     bool operator != (const SoundFormat &o) const  { return !operator == (o); }
00057 
00058     int      sampleSize() const;      // size of a single sample
00059     int      frameSize() const;       // sampleSize * channels
00060     int      minValue() const;
00061     int      maxValue() const;
00062 
00063     void     restoreConfig(const QString &prefix, KConfig *c);
00064     void     saveConfig(const QString &prefix, KConfig *c) const;
00065 
00066     int      convertSampleToInt(const char *sample, bool do_scale) const;
00067     void     convertIntToSample(int src, char *dst, bool is_scaled) const;
00068     void     convertSamplesToInts(const char *src, int  *dst, size_t n, bool do_scale) const;
00069     void     convertIntsToSamples(const int  *src, char *dst, size_t n, bool is_scaled) const;
00070     void     convertSamplesToFloat (const char   *src, float **dst, size_t n) const;
00071     void     convertFloatsToSamples(const float **src,   char *dst, size_t n) const;
00072 };
00073 
00074 
00075 #endif

Generated on Fri Jan 28 16:28:08 2011 for kradio by  doxygen 1.4.7