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 #ifdef __APPLE__ 37 # define OPENAL_DEPRECATED 38 # include <OpenAL/al.h> 39 #else 40 # include <AL/al.h> 41 #endif 42 #include "audio/music.hpp" 43 44 #include <atomic> 45 46 /** 47 * \brief ogg files based implementation of the Music interface 48 * \ingroup audio 49 */ 50 class MusicOggStream : public Music 51 { 52 public: 53 MusicOggStream(float loop_start); 54 virtual ~MusicOggStream(); 55 56 virtual void update(); 57 virtual void updateFaster(float percent, float max_pitch); 58 59 virtual bool load(const std::string& filename); 60 61 virtual bool playMusic(); 62 virtual bool stopMusic(); 63 virtual bool pauseMusic(); 64 virtual bool resumeMusic(); 65 virtual void setVolume(float volume); 66 virtual bool isPlaying(); 67 68 protected: 69 bool empty(); 70 bool check(const char* what); 71 std::string errorString(int code); 72 73 private: 74 bool release(); 75 bool streamIntoBuffer(ALuint buffer); 76 77 float m_loop_start; 78 std::string m_fileName; 79 FILE* m_oggFile; 80 OggVorbis_File m_oggStream; 81 vorbis_info* m_vorbisInfo; 82 bool m_error; 83 84 std::atomic_bool m_playing; 85 86 ALuint m_soundBuffers[2]; 87 ALuint m_soundSource; 88 ALenum nb_channels; 89 90 bool m_pausedMusic; 91 92 //one full second of audio at 44100 samples per second 93 static const int m_buffer_size = 11025*4; 94 }; 95 96 #endif 97 98 #endif // HEADER_MUSICOGG_HPP 99