~ubuntu-branches/ubuntu/saucy/sflphone/saucy

« back to all changes in this revision

Viewing changes to sflphone-common/src/audio/sound/audiofile.h

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-12-24 16:33:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20101224163355-tkvvikqxbrbav6up
Tags: 0.9.11-1
* New upstream release
* Add new build dependencies on libwebkit-dev and libyaml-dev

* Bump Standards-Version up to 3.9.1
* Bump debhelper compatibility to 8
* Patch another typo in the upstream code (lintian notice)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *  Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
3
3
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
4
4
 *
5
 
 *  Inspired by tonegenerator of 
 
5
 *  Inspired by tonegenerator of
6
6
 *   Laurielle Lea <laurielle.lea@savoirfairelinux.com> (2004)
7
7
 *  Inspired by ringbuffer of Audacity Project
8
 
 * 
 
8
 *
9
9
 *  This program is free software; you can redistribute it and/or modify
10
10
 *  it under the terms of the GNU General Public License as published by
11
11
 *  the Free Software Foundation; either version 3 of the License, or
34
34
#ifndef __AUDIOFILE_H__
35
35
#define __AUDIOFILE_H__
36
36
 
 
37
#include <fstream>
 
38
 
37
39
#include "audio/audioloop.h"
38
40
#include "audio/codecs/audiocodec.h"
39
41
#include "audio/codecs/codecDescriptor.h"
40
42
 
 
43
 
 
44
/**
 
45
 * @brief Abstract interface for file readers
 
46
 */
 
47
class AudioFile : public AudioLoop
 
48
{
 
49
    public:
 
50
 
 
51
        /**
 
52
        * Load a sound file in memory
 
53
        * @param filename  The absolute path to the file
 
54
        * @param codec     The codec to decode and encode it
 
55
        * @param sampleRate     The sample rate to read it
 
56
        * @return bool   True on success
 
57
        */
 
58
        virtual bool loadFile (const std::string& filename, AudioCodec *codec , unsigned int sampleRate) = 0;
 
59
 
 
60
        /**
 
61
         * Start the sound file
 
62
         */
 
63
        void start() {
 
64
            _start = true;
 
65
        }
 
66
 
 
67
        /**
 
68
         * Stop the sound file
 
69
         */
 
70
        void stop() {
 
71
            _start = false;
 
72
        }
 
73
 
 
74
        /**
 
75
         * Tells whether or not the file is playing
 
76
         * @return bool True if yes
 
77
         *                false otherwise
 
78
         */
 
79
        bool isStarted() {
 
80
            return _start;
 
81
        }
 
82
 
 
83
    protected:
 
84
 
 
85
        /** start or not */
 
86
        bool _start;
 
87
};
 
88
 
 
89
 
 
90
 
41
91
/**
42
92
 * @file audiofile.h
43
93
 * @brief A class to manage sound files
44
94
 */
45
95
 
46
 
class AudioFile : public AudioLoop
47
 
{
48
 
public:
49
 
  /**
50
 
   * Constructor
51
 
   */
52
 
  AudioFile();
53
 
  
54
 
  /**
55
 
   * Destructor
56
 
   */
57
 
  ~AudioFile();
58
 
 
59
 
 
60
 
  /**
61
 
   * Load a sound file in memory
62
 
   * @param filename  The absolute path to the file
63
 
   * @param codec     The codec to decode and encode it
64
 
   * @param sampleRate  The sample rate to read it
65
 
   * @return bool   True on success
66
 
   */
67
 
  bool loadFile(const std::string& filename, AudioCodec *codec , unsigned int sampleRate);
68
 
  
69
 
  /**
70
 
   * Start the sound file
71
 
   */
72
 
  void start() { _start = true; }
73
 
  
74
 
  /**
75
 
   * Stop the sound file
76
 
   */
77
 
  void stop()  { _start = false; }
78
 
  
79
 
  /**
80
 
   * Tells whether or not the file is playing
81
 
   * @return bool True if yes
82
 
   *              false otherwise
83
 
   */
84
 
  bool isStarted() { return _start; }
85
 
 
86
 
private:
87
 
  // Copy Constructor
88
 
  AudioFile(const AudioFile& rh);
89
 
 
90
 
  // Assignment Operator
91
 
  AudioFile& operator=( const AudioFile& rh);
92
 
 
93
 
  /** The absolute path to the sound file */
94
 
  std::string _filename;
95
 
  
96
 
  /** Your preferred codec */ 
97
 
  AudioCodec* _codec;
98
 
  
99
 
  /** Start or not */
100
 
  bool _start;
101
 
};
102
 
 
103
 
#endif // __AUDIOFILE_H__
 
96
class RawFile : public AudioFile
 
97
{
 
98
    public:
 
99
        /**
 
100
         * Constructor
 
101
         */
 
102
        RawFile();
 
103
 
 
104
        /**
 
105
         * Destructor
 
106
         */
 
107
        ~RawFile();
 
108
 
 
109
 
 
110
        /**
 
111
         * Load a sound file in memory
 
112
         * @param filename  The absolute path to the file
 
113
         * @param codec     The codec to decode and encode it
 
114
         * @param sampleRate    The sample rate to read it
 
115
         * @return bool   True on success
 
116
         */
 
117
        virtual bool loadFile (const std::string& filename, AudioCodec *codec , unsigned int sampleRate);
 
118
 
 
119
    private:
 
120
        // Copy Constructor
 
121
        RawFile (const RawFile& rh);
 
122
 
 
123
        // Assignment Operator
 
124
        RawFile& operator= (const RawFile& rh);
 
125
 
 
126
        /** The absolute path to the sound file */
 
127
        std::string _filename;
 
128
 
 
129
        /** Your preferred codec */
 
130
        AudioCodec* _codec;
 
131
};
 
132
 
 
133
 
 
134
class WaveFile : public AudioFile
 
135
{
 
136
 
 
137
    public:
 
138
 
 
139
        WaveFile ();
 
140
 
 
141
        ~WaveFile();
 
142
 
 
143
        bool openFile (const std::string& fileName, int audioSamplingRate);
 
144
 
 
145
        bool closeFile();
 
146
 
 
147
        bool isFileExist (const std::string& fileName);
 
148
 
 
149
        bool isFileOpened();
 
150
 
 
151
        /**
 
152
             * Load a sound file in memory
 
153
             * @param filename  The absolute path to the file
 
154
             * @param codec     The codec to decode and encode it
 
155
             * @param sampleRate        The sample rate to read it
 
156
             * @return bool   True on success
 
157
             */
 
158
        virtual bool loadFile (const std::string& filename, AudioCodec *codec , unsigned int sampleRate);
 
159
 
 
160
    private:
 
161
 
 
162
        bool setWaveFile();
 
163
 
 
164
        bool openExistingWaveFile (const std::string& fileName, int audioSamplingRate);
 
165
 
 
166
        SOUND_FORMAT _snd_format;
 
167
 
 
168
        long _byte_counter;
 
169
 
 
170
        int _nb_channels;
 
171
 
 
172
        unsigned long _file_size;
 
173
 
 
174
        unsigned long _data_offset;
 
175
 
 
176
        SINT16 _channels;
 
177
 
 
178
        SOUND_FORMAT _data_type;
 
179
 
 
180
        double _file_rate;
 
181
 
 
182
        std::fstream _file_stream;
 
183
 
 
184
        std::string _fileName;
 
185
 
 
186
};
 
187
 
 
188
#endif
 
189