SuperTuxKart
Loading...
Searching...
No Matches
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
45class MusicOggStream : public Music
46{
47public:
48 MusicOggStream(float loop_start, float loop_end);
49 virtual ~MusicOggStream();
50
51 virtual void update();
52 virtual void updateFaster(float percent, float max_pitch);
53
54 virtual bool load(const std::string& filename);
55
56 virtual bool playMusic();
57 virtual bool stopMusic();
58 virtual bool pauseMusic();
59 virtual bool resumeMusic();
60 virtual void setVolume(float volume);
61 virtual bool isPlaying();
62
63protected:
64 bool empty();
65 bool check(const char* what);
66 std::string errorString(int code);
67
68private:
69 bool release();
70 bool streamIntoBuffer(ALuint buffer);
71
72 float m_loop_start;
73 float m_loop_end;
74 std::string m_fileName;
75 FILE* m_oggFile;
76 OggVorbis_File m_oggStream;
77 vorbis_info* m_vorbisInfo;
78 bool m_error;
79
80 std::atomic_bool m_playing;
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