FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
sounddecoder.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2019 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library 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 GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, 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 
48  virtual uint64_t getDecodedLength() const = 0;
49 
59  bool needsStreaming() const { return getDecodedLength() > MAX_KEEP_IN_MEM; }
60 
65  virtual bool setCursor(uint64_t pos) = 0;
66 
72  virtual bool decode(uint64_t length) = 0;
73 
78  virtual void* getBuffer() const = 0;
79 
82  virtual uint64_t getBufferSize() = 0;
83 
86  virtual void releaseBuffer() = 0;
87 
92  bool isStereo() const {
93  return m_isstereo;
94  }
95 
98  ALenum getALFormat() const {
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 
108  int16_t getBitResolution() const {
109  return m_is8bit ? 8 : 16;
110  }
111 
114  uint64_t getSampleRate() const{
115  return m_samplerate;
116  }
117 
118  protected:
120  bool m_is8bit;
121  uint64_t m_samplerate;
122  };
123 }
124 
125 #endif
bool needsStreaming() const
A stream or not?
Definition: sounddecoder.h:59
uint64_t getSampleRate() const
Returns the sample rate.
Definition: sounddecoder.h:114
virtual void releaseBuffer()=0
Releases the buffer returned by getBuffer()
virtual uint64_t getBufferSize()=0
Returns the byte-size of the buffer returned by getBuffer().
virtual void * getBuffer() const =0
Returns the next decoded buffer.
virtual bool decode(uint64_t length)=0
Request the decoding of the next part of the stream.
const uint32_t MAX_KEEP_IN_MEM
Definition: soundconfig.h:187
bool isStereo() const
Tests if the audio data is stereo data or mono.
Definition: sounddecoder.h:92
virtual uint64_t getDecodedLength() const =0
Returns the decoded length of the file in bytes.
virtual bool setCursor(uint64_t pos)=0
Sets the current position in the file (in bytes)
int16_t getBitResolution() const
Returns the bit resolution.
Definition: sounddecoder.h:108
virtual ~SoundDecoder()
Definition: sounddecoder.h:44
ALenum getALFormat() const
Returns the openAL-Format of the audio file.
Definition: sounddecoder.h:98