2
2
* Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
3
3
* Author: Yan Morin <yan.morin@savoirfairelinux.com>
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
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__
37
39
#include "audio/audioloop.h"
38
40
#include "audio/codecs/audiocodec.h"
39
41
#include "audio/codecs/codecDescriptor.h"
45
* @brief Abstract interface for file readers
47
class AudioFile : public AudioLoop
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
58
virtual bool loadFile (const std::string& filename, AudioCodec *codec , unsigned int sampleRate) = 0;
61
* Start the sound file
75
* Tells whether or not the file is playing
76
* @return bool True if yes
42
92
* @file audiofile.h
43
93
* @brief A class to manage sound files
46
class AudioFile : public AudioLoop
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
67
bool loadFile(const std::string& filename, AudioCodec *codec , unsigned int sampleRate);
70
* Start the sound file
72
void start() { _start = true; }
77
void stop() { _start = false; }
80
* Tells whether or not the file is playing
81
* @return bool True if yes
84
bool isStarted() { return _start; }
88
AudioFile(const AudioFile& rh);
90
// Assignment Operator
91
AudioFile& operator=( const AudioFile& rh);
93
/** The absolute path to the sound file */
94
std::string _filename;
96
/** Your preferred codec */
103
#endif // __AUDIOFILE_H__
96
class RawFile : public AudioFile
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
117
virtual bool loadFile (const std::string& filename, AudioCodec *codec , unsigned int sampleRate);
121
RawFile (const RawFile& rh);
123
// Assignment Operator
124
RawFile& operator= (const RawFile& rh);
126
/** The absolute path to the sound file */
127
std::string _filename;
129
/** Your preferred codec */
134
class WaveFile : public AudioFile
143
bool openFile (const std::string& fileName, int audioSamplingRate);
147
bool isFileExist (const std::string& fileName);
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
158
virtual bool loadFile (const std::string& filename, AudioCodec *codec , unsigned int sampleRate);
164
bool openExistingWaveFile (const std::string& fileName, int audioSamplingRate);
166
SOUND_FORMAT _snd_format;
172
unsigned long _file_size;
174
unsigned long _data_offset;
178
SOUND_FORMAT _data_type;
182
std::fstream _file_stream;
184
std::string _fileName;