comparison engine/core/audio/sounddecoder.h @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children 90005975cdbb
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 /***************************************************************************
2 * Copyright (C) 2005-2008 by the FIFE team *
3 * http://www.fifengine.de *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef FIFE_SOUNDDECODER_H
23 #define FIFE_SOUNDDECODER_H
24
25 // Standard C++ library includes
26
27 // Platform specific includes
28
29 // 3rd party library includes
30
31 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line
33 // First block: files included from the FIFE root src directory
34 // Second block: files included from the same folder
35
36 #include "soundconfig.h"
37 #include "fife_openal.h"
38
39 namespace FIFE {
40
41 class SoundDecoder {
42 public:
43
44 virtual ~SoundDecoder() {}
45
46 /** Returns the decoded length of the file in bytes
47 */
48 virtual unsigned long getDecodedLength() = 0;
49
50 /** A stream or not?
51 *
52 * The decision if we decode the whole audio file in one buffer or use a
53 * kind of streaming depends on the value of MAX_KEEP_IN_MEM from
54 * soundconfig.h
55 *
56 * @return Return true for a streaming decoder, false if the sound is
57 * decoded in one buffer
58 */
59 bool needsStreaming() { return getDecodedLength() > MAX_KEEP_IN_MEM; }
60
61 /** Sets the current position in the file (in bytes)
62 *
63 * @return 0 (False), if the positioning was successful
64 */
65 virtual bool setCursor(unsigned long pos) = 0;
66
67 /** Request the decoding of the next part of the stream.
68 *
69 * @param length The length of the decoded part
70 * @return 0 (False), if decoding was successful
71 */
72 virtual bool decode(unsigned long length) = 0;
73
74 /** Returns the next decoded buffer.
75 *
76 * The length of the buffer is returned by getBufferSize().
77 */
78 virtual void *getBuffer() = 0;
79
80 /** Returns the byte-size of the buffer returned by getBuffer().
81 */
82 virtual unsigned long getBufferSize() = 0;
83
84 /** Releases the buffer returned by getBuffer()
85 */
86 virtual void releaseBuffer() = 0;
87
88 /** Tests if the audio data is stereo data or mono.
89 *
90 * @return Returns true if the audio data is stereo, false if mono.
91 */
92 bool isStereo() {
93 return m_isstereo;
94 }
95
96 /** Returns the openAL-Format of the audio file
97 */
98 ALenum getALFormat() {
99 if (m_isstereo) {
100 return m_is8bit ? AL_FORMAT_STEREO8 : AL_FORMAT_STEREO16;
101 } else {
102 return m_is8bit ? AL_FORMAT_MONO8 : AL_FORMAT_MONO16;
103 }
104 }
105
106 /** Returns the bit resolution
107 */
108 short getBitResolution() {
109 return m_is8bit ? 8 : 16;
110 }
111
112 /** Returns the sample rate
113 */
114 unsigned long getSampleRate() {
115 return m_samplerate;
116 }
117
118 protected:
119 bool m_isstereo;
120 bool m_is8bit;
121 unsigned long m_samplerate;
122 };
123 }
124
125 #endif