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                : emw-kradio@nocabal.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 <QtCore/QString>
00027 #include <kconfig.h>
00028 
00029 class KConfigGroup;
00030 
00031 struct KDE_EXPORT SoundFormat {
00032     unsigned     m_SampleRate;
00033     unsigned     m_Channels;
00034     unsigned     m_SampleBits;
00035     bool         m_IsSigned;
00036     unsigned     m_Endianess;
00037     QString      m_Encoding;     // "raw", "mp3", ...  (no "wav", because it's only header + raw data)
00038 
00039     SoundFormat(unsigned sample_rate, unsigned channels, unsigned sample_bits, bool is_signed, unsigned endianess, const QString &enc)
00040         : m_SampleRate(sample_rate), m_Channels(channels), m_SampleBits(sample_bits), m_IsSigned(is_signed), m_Endianess(endianess), m_Encoding(enc) {}
00041     SoundFormat(unsigned sample_rate, unsigned channels, unsigned sample_bits, bool is_signed, unsigned endianess)
00042         : m_SampleRate(sample_rate), m_Channels(channels), m_SampleBits(sample_bits), m_IsSigned(is_signed), m_Endianess(endianess), m_Encoding("raw") {}
00043     SoundFormat(unsigned sample_rate, unsigned channels, unsigned sample_bits, bool is_signed)
00044         : m_SampleRate(sample_rate), m_Channels(channels), m_SampleBits(sample_bits), m_IsSigned(is_signed), m_Endianess(BYTE_ORDER), m_Encoding("raw") {}
00045     SoundFormat(bool stereo)
00046         : m_SampleRate(44100), m_Channels(stereo ? 2 : 1), m_SampleBits(16), m_IsSigned(true), m_Endianess(BYTE_ORDER), m_Encoding("raw") {}
00047     SoundFormat()
00048         : m_SampleRate(44100), m_Channels(2), m_SampleBits(16), m_IsSigned(true), m_Endianess(BYTE_ORDER), m_Encoding("raw") {}
00049 
00050     bool operator == (const SoundFormat &o) const { return m_SampleRate == o.m_SampleRate &&
00051                                                            m_Channels   == o.m_Channels   &&
00052                                                            m_SampleBits == o.m_SampleBits &&
00053                                                            m_IsSigned   == o.m_IsSigned   &&
00054                                                            m_Endianess  == o.m_Endianess  &&
00055                                                            m_Encoding   == o.m_Encoding
00056                                                     ;
00057                                                    }
00058     bool operator != (const SoundFormat &o) const  { return !operator == (o); }
00059 
00060     int      sampleSize() const;      // size of a single sample
00061     int      frameSize() const;       // sampleSize * channels
00062     int      minValue() const;
00063     int      maxValue() const;
00064 
00065     void     restoreConfig(const QString &prefix, const KConfigGroup &c);
00066     void     saveConfig   (const QString &prefix,       KConfigGroup &c) const;
00067 
00068     int      convertSampleToInt(const char *sample, bool do_scale) const;
00069     void     convertIntToSample(int src, char *dst, bool is_scaled) const;
00070     void     convertSamplesToInts(const char *src, int  *dst, size_t n, bool do_scale) const;
00071     void     convertIntsToSamples(const int  *src, char *dst, size_t n, bool is_scaled) const;
00072     void     convertSamplesToFloat (const char   *src, float **dst, size_t n_frames) const;
00073     void     convertFloatsToSamples(const float **src,   char *dst, size_t n_frames) const;
00074 
00075     void     scaleSamples(char *_src, float scale, size_t n_frames) const;
00076 
00077 };
00078 
00079 
00080 #endif

Generated on Tue Jun 2 19:19:57 2009 for kradio4 by  doxygen 1.5.8