SuperTuxKart
music_ogg.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2007-2015 Damien Morel <divdams@free.fr>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_MUSICOGG_HPP
20 #define HEADER_MUSICOGG_HPP
21 
22 #ifdef ENABLE_SOUND
23 
24 #include <string>
25 
26 #include <ogg/ogg.h>
27 // Disable warning about potential loss of precision in vorbisfile.h
28 #if defined(WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__)
29 # pragma warning(disable:4244)
30 #endif
31 # include <vorbis/vorbisfile.h>
32 #if defined(WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__)
33 # pragma warning(default:4244)
34 #endif
35 
36 #include <AL/al.h>
37 #include "audio/music.hpp"
38 
39 #include <atomic>
40 
45 class MusicOggStream : public Music
46 {
47 public:
48  MusicOggStream(float loop_start, float loop_end);
49  virtual ~MusicOggStream();
50 
51  virtual void update();
52 
53  virtual bool load(const std::string& filename);
54 
55  virtual bool playMusic();
56  virtual bool stopMusic();
57  virtual bool pauseMusic();
58  virtual bool resumeMusic();
59  virtual void setVolume(float volume);
60  virtual bool isPlaying();
61 
62 protected:
63  bool empty();
64  bool check(const char* what);
65  std::string errorString(int code);
66 
67 private:
68  bool release();
69  bool streamIntoBuffer(ALuint buffer);
70 
71  float m_loop_start;
72  float m_loop_end;
73  std::string m_fileName;
74  FILE* m_oggFile;
75  OggVorbis_File m_oggStream;
76  vorbis_info* m_vorbisInfo;
77  bool m_error;
78 
79  std::atomic_bool m_playing;
80  std::atomic_bool m_play_initialized;
81 
82  ALuint m_soundBuffers[2];
83  ALuint m_soundSource;
84  ALenum nb_channels;
85 
86  bool m_pausedMusic;
87 
88  //one full second of audio at 44100 samples per second
89  static const int m_buffer_size = 11025*4;
90 };
91 
92 #endif
93 
94 #endif // HEADER_MUSICOGG_HPP
Abstract interface for classes that can handle music playback.
Definition: music.hpp:30
void update(float dt)
Updates all widgets that need to be updated.
Definition: engine.cpp:872