~ubuntu-branches/ubuntu/utopic/kradio/utopic

« back to all changes in this revision

Viewing changes to kradio3/src/libkradio/soundformat.h

  • Committer: Bazaar Package Importer
  • Author(s): Marc 'HE' Brockschmidt
  • Date: 2008-03-16 19:00:02 UTC
  • mfrom: (3.1.2 gutsy)
  • Revision ID: james.westby@ubuntu.com-20080316190002-sdjqu8cahhx7c6tk
Tags: 0.1.1.1~20061112-3.1
* Non-maintainer upload.
* Fix gcc-4.3 FTBFS, patch by Kibi (Closes: #455390)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
                      soundformat.h  -  description
3
 
                             -------------------
4
 
    begin                : Sun Aug 1 2004
5
 
    copyright            : (C) 2004 by Martin Witte
6
 
    email                : witte@kawo1.rwth-aachen.de
7
 
 ***************************************************************************/
8
 
 
9
 
/***************************************************************************
10
 
 *                                                                         *
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.                                   *
15
 
 *                                                                         *
16
 
 ***************************************************************************/
17
 
 
18
 
#ifndef KRADIO_SOUNDFORMAT_H
19
 
#define KRADIO_SOUNDFORMAT_H
20
 
 
21
 
#ifdef HAVE_CONFIG_H
22
 
#include <config.h>
23
 
#endif
24
 
 
25
 
#include <endian.h>
26
 
#include <qstring.h>
27
 
#include <kconfig.h>
28
 
 
29
 
struct SoundFormat {
30
 
    unsigned     m_SampleRate;
31
 
    unsigned     m_Channels;
32
 
    unsigned     m_SampleBits;
33
 
    bool         m_IsSigned;
34
 
    unsigned     m_Endianess;
35
 
    QString      m_Encoding;     // "raw", "mp3", ...  (no "wav", because it's only header + raw data)
36
 
 
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") {}
45
 
    SoundFormat()
46
 
        : m_SampleRate(44100), m_Channels(2), m_SampleBits(16), m_IsSigned(true), m_Endianess(BYTE_ORDER), m_Encoding("raw") {}
47
 
 
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
54
 
                                                    ;
55
 
                                                   }
56
 
    bool operator != (const SoundFormat &o) const  { return !operator == (o); }
57
 
 
58
 
    int      sampleSize() const;      // size of a single sample
59
 
    int      frameSize() const;       // sampleSize * channels
60
 
    int      minValue() const;
61
 
    int      maxValue() const;
62
 
 
63
 
    void     restoreConfig(const QString &prefix, KConfig *c);
64
 
    void     saveConfig(const QString &prefix, KConfig *c) const;
65
 
 
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;
72
 
};
73
 
 
74
 
 
75
 
#endif