2007-05-27 12:01:53 -04:00
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
2015-03-29 20:31:42 -04:00
|
|
|
// Copyright (C) 2006-2015 Patrick Ammann <pammann@aro.ch>
|
2007-05-27 12:01:53 -04:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
2008-06-12 20:53:52 -04:00
|
|
|
// as published by the Free Software Foundation; either version 3
|
2007-05-27 12:01:53 -04:00
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
2008-09-17 23:24:19 -04:00
|
|
|
#ifndef HEADER_SFX_OPENAL_HPP
|
|
|
|
#define HEADER_SFX_OPENAL_HPP
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2018-07-06 21:48:43 -04:00
|
|
|
#ifdef ENABLE_SOUND
|
2011-11-26 20:14:16 -05:00
|
|
|
|
2007-05-27 12:01:53 -04:00
|
|
|
#include <assert.h>
|
|
|
|
#ifdef __APPLE__
|
2020-01-12 02:21:49 -05:00
|
|
|
# define OPENAL_DEPRECATED
|
2007-05-27 12:01:53 -04:00
|
|
|
# include <OpenAL/al.h>
|
|
|
|
#else
|
|
|
|
# include <AL/al.h>
|
|
|
|
#endif
|
2008-09-17 23:24:19 -04:00
|
|
|
#include "audio/sfx_base.hpp"
|
2012-12-09 20:31:41 -05:00
|
|
|
#include "utils/leak_check.hpp"
|
2017-09-02 22:35:41 -04:00
|
|
|
#include "utils/cpp2011.hpp"
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2010-04-23 16:36:13 -04:00
|
|
|
/**
|
|
|
|
* \brief OpenAL implementation of the abstract SFXBase interface
|
|
|
|
* \ingroup audio
|
|
|
|
*/
|
2008-09-17 23:24:19 -04:00
|
|
|
class SFXOpenAL : public SFXBase
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2008-09-17 23:24:19 -04:00
|
|
|
private:
|
2014-10-13 18:01:26 -04:00
|
|
|
LEAK_CHECK()
|
|
|
|
|
2014-10-13 17:05:04 -04:00
|
|
|
/** Buffers hold sound data. */
|
|
|
|
SFXBuffer* m_sound_buffer;
|
|
|
|
|
|
|
|
/** Sources are points emitting sound. */
|
|
|
|
ALuint m_sound_source;
|
|
|
|
|
2014-10-13 18:01:26 -04:00
|
|
|
/** The status of this SFX. */
|
|
|
|
SFXStatus m_status;
|
|
|
|
|
2014-10-16 17:27:40 -04:00
|
|
|
/** If the sfx is positional. */
|
2008-11-06 02:17:11 -05:00
|
|
|
bool m_positional;
|
2014-10-16 17:27:40 -04:00
|
|
|
|
|
|
|
/** Default gain value. */
|
|
|
|
float m_default_gain;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-10-11 16:26:31 -04:00
|
|
|
/** The OpenAL source contains this info, but if audio is disabled initially then
|
|
|
|
the sound source won't be created and we'll be left with no clue when enabling
|
|
|
|
sounds later */
|
|
|
|
bool m_loop;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-10-11 16:26:31 -04:00
|
|
|
/** Contains a volume if set through the "volume" method, or a negative number if
|
|
|
|
this method was not called.
|
|
|
|
The OpenAL source contains this info, but if audio is disabled initially then
|
|
|
|
the sound source won't be created and we'll be left with no clue when enabling
|
|
|
|
sounds later. */
|
|
|
|
float m_gain;
|
2013-09-19 19:46:51 -04:00
|
|
|
|
|
|
|
/** The master gain set in user preferences */
|
|
|
|
float m_master_gain;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2014-10-13 18:01:26 -04:00
|
|
|
/** If this sfx should also free the sound buffer. */
|
2012-12-09 18:30:26 -05:00
|
|
|
bool m_owns_buffer;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2014-10-17 20:46:22 -04:00
|
|
|
/** How long the sfx has been playing. */
|
|
|
|
float m_play_time;
|
2011-08-06 16:37:54 -04:00
|
|
|
|
2014-10-13 18:01:26 -04:00
|
|
|
public:
|
2015-02-09 16:32:05 -05:00
|
|
|
SFXOpenAL(SFXBuffer* buffer, bool positional, float volume,
|
2014-10-13 18:01:26 -04:00
|
|
|
bool owns_buffer = false);
|
|
|
|
virtual ~SFXOpenAL();
|
|
|
|
|
2018-07-06 22:43:05 -04:00
|
|
|
virtual void updatePlayingSFX(float dt) OVERRIDE;
|
2017-09-02 22:35:41 -04:00
|
|
|
virtual bool init() OVERRIDE;
|
|
|
|
virtual void play() OVERRIDE;
|
|
|
|
virtual void reallyPlayNow(SFXBuffer* buffer = NULL) OVERRIDE;
|
|
|
|
virtual void play(const Vec3 &xyz, SFXBuffer* buffer = NULL) OVERRIDE;
|
|
|
|
virtual void reallyPlayNow(const Vec3 &xyz, SFXBuffer* buffer = NULL) OVERRIDE;
|
2018-07-06 22:43:05 -04:00
|
|
|
virtual void setLoop(bool status) OVERRIDE;
|
|
|
|
virtual void reallySetLoop(bool status) OVERRIDE;
|
|
|
|
virtual void stop() OVERRIDE;
|
|
|
|
virtual void reallyStopNow() OVERRIDE;
|
|
|
|
virtual void pause() OVERRIDE;
|
|
|
|
virtual void reallyPauseNow() OVERRIDE;
|
|
|
|
virtual void resume() OVERRIDE;
|
|
|
|
virtual void reallyResumeNow() OVERRIDE;
|
|
|
|
virtual void deleteSFX() OVERRIDE;
|
|
|
|
virtual void setSpeed(float factor) OVERRIDE;
|
|
|
|
virtual void reallySetSpeed(float factor) OVERRIDE;
|
|
|
|
virtual void setPosition(const Vec3 &position) OVERRIDE;
|
|
|
|
virtual void reallySetPosition(const Vec3 &p) OVERRIDE;
|
|
|
|
virtual void setSpeedPosition(float factor, const Vec3 &p) OVERRIDE;
|
|
|
|
virtual void reallySetSpeedPosition(float f,const Vec3 &p) OVERRIDE;
|
|
|
|
virtual void setVolume(float volume) OVERRIDE;
|
|
|
|
virtual void reallySetVolume(float volume) OVERRIDE;
|
|
|
|
virtual void setMasterVolume(float volume) OVERRIDE;
|
|
|
|
virtual void reallySetMasterVolumeNow(float volue) OVERRIDE;
|
|
|
|
virtual void onSoundEnabledBack() OVERRIDE;
|
|
|
|
virtual void setRolloff(float rolloff) OVERRIDE;
|
2014-10-20 07:37:19 -04:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Returns if this sfx is looped or not. */
|
2018-07-06 22:43:05 -04:00
|
|
|
virtual bool isLooped() OVERRIDE { return m_loop; }
|
2014-10-20 07:37:19 -04:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Returns the status of this sfx. */
|
2018-07-06 22:43:05 -04:00
|
|
|
virtual SFXStatus getStatus() OVERRIDE { return m_status; }
|
2014-10-13 18:01:26 -04:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Returns the buffer associated with this sfx. */
|
2018-07-06 22:43:05 -04:00
|
|
|
virtual const SFXBuffer* getBuffer() const OVERRIDE
|
|
|
|
{ return m_sound_buffer; }
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2008-09-17 23:24:19 -04:00
|
|
|
}; // SFXOpenAL
|
|
|
|
|
2011-11-26 20:14:16 -05:00
|
|
|
#endif
|
2008-09-17 23:24:19 -04:00
|
|
|
#endif // HEADER_SFX_OPENAL_HPP
|
2007-05-27 12:01:53 -04:00
|
|
|
|