27 #define OV_EXCLUDE_STATIC_CALLBACKS
29 #undef OV_EXCLUDE_STATIC_CALLBACKS
34 #if defined(_DEBUG) && defined(_WINDOWS)
35 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
50 fdPlayerMuteSolo(
NULL),
58 if(Sound_Renderer_SLES *
const sles = dynamic_cast<Sound_Renderer_SLES *>(&sr.get_Renderer())) {
60 loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, sles->get_outputMixObject()};
61 audioSnk = {&loc_outmix,
NULL};
65 init(sr.get_Hello_World_Buffer());
68 Sound_Source_HW::Sound_Source_HW(
const Sound_Buffer &
buffer,
const float &pitch,
const float &gain,
69 const Point3f &position,
const Vector3f &velocity,
const bool &looping)
78 fdPlayerMuteSolo(
NULL),
86 if(Sound_Renderer_SLES *
const sles = dynamic_cast<Sound_Renderer_SLES *>(&sr.get_Renderer())) {
88 loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, sles->get_outputMixObject()};
89 audioSnk = {&loc_outmix,
NULL};
93 init(buffer, pitch, gain, position, velocity, looping);
96 Sound_Source_HW::~Sound_Source_HW() {
100 Sound_Source_HW * Sound_Source_HW::Try_Construct() {
107 if(dynamic_cast<Sound_Renderer_SLES *>(&
get_Sound().get_Renderer()))
108 return new Sound_Source_HW(
AL_NONE);
110 return source !=
AL_NONE ?
new Sound_Source_HW(source) : 0;
114 #
if !defined(DISABLE_AL) || defined(ENABLE_SLES)
119 if(dynamic_cast<Sound_Renderer_AL *>(&
get_Sound().get_Renderer())) {
145 #
if !defined(DISABLE_AL) || defined(ENABLE_SLES)
150 if(dynamic_cast<Sound_Renderer_AL *>(&
get_Sound().get_Renderer())) {
155 if(dynamic_cast<Sound_Renderer_SLES *>(&
get_Sound().get_Renderer())) {
156 (*fdPlayerVolume)->SetVolumeLevel(fdPlayerVolume, SLmillibel(2000.0
f * log10(
std::max(1.0
f, gain))));
182 #
if !defined(DISABLE_AL) || defined(ENABLE_SLES)
187 if(dynamic_cast<Sound_Renderer_AL *>(&
get_Sound().get_Renderer())) {
192 if(dynamic_cast<Sound_Renderer_SLES *>(&
get_Sound().get_Renderer())) {
193 (*fdPlayerSeek)->SetLoop(fdPlayerSeek, looping ? SL_BOOLEAN_TRUE : SL_BOOLEAN_FALSE, 0, SL_TIME_UNKNOWN);
199 #
if !defined(DISABLE_AL) || defined(ENABLE_SLES)
204 if(dynamic_cast<Sound_Renderer_AL *>(&
get_Sound().get_Renderer())) {
209 if(dynamic_cast<Sound_Renderer_SLES *>(&
get_Sound().get_Renderer())) {
210 (*fdPlayerSeek)->SetPosition(fdPlayerSeek, SLmillisecond(1000.0
f * time), SL_SEEKMODE_FAST);
252 if(dynamic_cast<Sound_Renderer_SLES *>(&
get_Sound().get_Renderer())) {
253 SLmillisecond duration;
254 (*fdPlayerPlay)->GetDuration(fdPlayerPlay, &duration);
255 if(duration != SL_TIME_UNKNOWN)
256 return duration * 0.001f;
273 if(dynamic_cast<Sound_Renderer_AL *>(&
get_Sound().get_Renderer())) {
278 if(dynamic_cast<Sound_Renderer_SLES *>(&
get_Sound().get_Renderer())) {
279 SLmillibel millibels;
280 if((*fdPlayerVolume)->GetVolumeLevel(fdPlayerVolume, &millibels) == SL_RESULT_SUCCESS)
281 gain = pow(10.0
f, millibels / 2000.0
f);
306 if(dynamic_cast<Sound_Renderer_AL *>(&
get_Sound().get_Renderer())) {
311 if(dynamic_cast<Sound_Renderer_SLES *>(&
get_Sound().get_Renderer())) {
314 if((*fdPlayerSeek)->GetLoop(fdPlayerSeek, &slooping, &start, &end) == SL_RESULT_SUCCESS)
315 return slooping != SL_BOOLEAN_FALSE;
324 if(dynamic_cast<Sound_Renderer_AL *>(&
get_Sound().get_Renderer())) {
329 if(dynamic_cast<Sound_Renderer_SLES *>(&
get_Sound().get_Renderer())) {
330 SLmillisecond milliseconds;
331 if((*fdPlayerPlay)->GetPosition(fdPlayerPlay, &milliseconds) == SL_RESULT_SUCCESS)
332 time = milliseconds / 1000.0
f;
343 return reference_distance;
364 if(dynamic_cast<Sound_Renderer_AL *>(&
get_Sound().get_Renderer())) {
369 if(dynamic_cast<Sound_Renderer_SLES *>(&
get_Sound().get_Renderer())) {
371 (*fdPlayerPlay)->SetPlayState(fdPlayerPlay, SL_PLAYSTATE_PLAYING);
378 if(dynamic_cast<Sound_Renderer_AL *>(&
get_Sound().get_Renderer())) {
383 if(dynamic_cast<Sound_Renderer_SLES *>(&
get_Sound().get_Renderer())) {
384 (*fdPlayerPlay)->SetPlayState(fdPlayerPlay, SL_PLAYSTATE_PAUSED);
391 if(dynamic_cast<Sound_Renderer_AL *>(&
get_Sound().get_Renderer())) {
396 if(dynamic_cast<Sound_Renderer_SLES *>(&
get_Sound().get_Renderer())) {
397 (*fdPlayerPlay)->SetPlayState(fdPlayerPlay, SL_PLAYSTATE_STOPPED);
404 if(dynamic_cast<Sound_Renderer_AL *>(&
get_Sound().get_Renderer())) {
413 if(dynamic_cast<Sound_Renderer_SLES *>(&
get_Sound().get_Renderer())) {
415 if((*fdPlayerPlay)->GetPlayState(fdPlayerPlay, &state) != SL_RESULT_SUCCESS)
417 return state == SL_PLAYSTATE_PLAYING ?
PLAYING :
418 state == SL_PLAYSTATE_PAUSED ?
PAUSED :
437 void Sound_Source_HW::init(
const Sound_Buffer &buffer,
const float &
442 #
if !defined(DISABLE_AL) || defined(ENABLE_SLES)
454 #
if !defined(DISABLE_AL) || defined(ENABLE_SLES)
464 if(dynamic_cast<Sound_Renderer_AL *>(&sr.
get_Renderer())) {
486 if(Sound_Renderer_SLES *
const sles = dynamic_cast<Sound_Renderer_SLES *>(&sr.
get_Renderer())) {
487 const SLInterfaceID
ids[3] = {SL_IID_SEEK, SL_IID_MUTESOLO, SL_IID_VOLUME};
488 const SLboolean req[3] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};
491 if((*sles->get_engineEngine())->CreateAudioPlayer(sles->get_engineEngine(), &fdPlayerObject, &
const_cast<SLDataSource &
>(buffer.get_audioSrc()), &audioSnk, 3, ids, req) != SL_RESULT_SUCCESS ||
492 (*fdPlayerObject)->Realize(fdPlayerObject, SL_BOOLEAN_FALSE) != SL_RESULT_SUCCESS ||
493 (*fdPlayerObject)->GetInterface(fdPlayerObject, SL_IID_PLAY, &fdPlayerPlay) != SL_RESULT_SUCCESS ||
494 (*fdPlayerObject)->GetInterface(fdPlayerObject, SL_IID_SEEK, &fdPlayerSeek) != SL_RESULT_SUCCESS ||
495 (*fdPlayerObject)->GetInterface(fdPlayerObject, SL_IID_MUTESOLO, &fdPlayerMuteSolo) != SL_RESULT_SUCCESS ||
496 (*fdPlayerObject)->GetInterface(fdPlayerObject, SL_IID_VOLUME, &fdPlayerVolume) != SL_RESULT_SUCCESS ||
497 (*fdPlayerSeek)->SetLoop(fdPlayerSeek, looping ? SL_BOOLEAN_TRUE : SL_BOOLEAN_FALSE, 0, SL_TIME_UNKNOWN) != SL_RESULT_SUCCESS ||
498 (*fdPlayerVolume)->SetVolumeLevel(fdPlayerVolume, SLmillibel(2000.0
f * log10(
std::max(1.0
f, gain)))) != SL_RESULT_SUCCESS)
500 throw Sound_Source_HW_Init_Failure();
509 void Sound_Source_HW::uninit() {
518 if (fdPlayerObject !=
NULL) {
519 (*fdPlayerObject)->Destroy(fdPlayerObject);
520 fdPlayerObject =
NULL;
523 fdPlayerMuteSolo =
NULL;
524 fdPlayerVolume =
NULL;
532 m_buffer(&
get_Sound().get_Hello_World_Buffer()),
540 m_play_position(0.0
f),
544 m_remove_from_Pool_on_destruction(
true)
561 m_position(position),
562 m_velocity(velocity),
567 m_play_position(0.0
f),
571 m_remove_from_Pool_on_destruction(
true)
577 if(m_remove_from_Pool_on_destruction)
590 m_play_position += time_step;
592 m_play_time = current_time;
594 if(duration && m_play_position > duration) {
596 m_play_position = float(fmod(m_play_position, duration));
601 m_play_position = 0.0f;
608 return m_play_position;
612 float distance = (listener_position - m_position).magnitude();
615 distance =
std::max(distance, m_reference_distance);
616 distance =
std::min(distance, m_max_distance);
617 return 1.0f - m_rolloff * (distance - m_reference_distance) /
618 (m_max_distance - m_reference_distance);
638 if(m_playing && (!duration || time < duration))
642 Sound_Source_HW * Sound_Source::unassign() {
643 Sound_Source_HW * ptr = m_hw;
656 void Sound_Source::update_state()
const {
664 m_paused = m_stopped =
false;
674 m_playing = m_stopped =
false;
678 m_playing = m_paused =
false;
static alGetSourcefv_fcn alGetSourcefv()
float get_duration() const
Get the duration of the Sound_Buffer in seconds.
float get_pitch() const
Get the pitch.
const Sound_Buffer & get_buffer() const
Get the Sound_Buffer.
void set_buffer(const Sound_Buffer &buffer)
Set the Sound_Buffer to be played.
A Snapshot of the Timer_HQ.
Sound_Source_Pool & get_Sound_Source_Pool()
Get access to the singleton.
void set_time(const float &time)
Set the current position in the Sound_Buffer, offset in seconds.
static alSourceStop_fcn alSourceStop()
void update()
Update to current Time.
#define ZENI_DEFAULT_PITCH
static alDeleteSources_fcn alDeleteSources()
static alGetSourcei_fcn alGetSourcei()
void stop()
Stop the Sound_Source_HW. (Essentially the same as pause but resets the current time.)
static void init(struct bs2b *bs2b)
static alSourcei_fcn alSourcei()
Sound_Renderer & get_Renderer()
Get the current Sound_Renderer.
const float & get_duration() const
Get the duration of the Sound_Buffer in seconds.
void play()
Begin playing or unpause the Sound_Source_HW.
float get_time() const
Get the current position in the Sound_Buffer, offset in seconds.
static alGetSourcef_fcn alGetSourcef()
void set_gain(const float &gain=ZENI_DEFAULT_GAIN)
Set the gain.
void set_reference_distance(const float &reference_distance=ZENI_DEFAULT_REFERENCE_DISTANCE)
#define ZENI_DEFAULT_GAIN
void set_looping(const bool &looping)
Set whether the Sound_Buffer should loop back to the start once it is done playing.
static alSourcef_fcn alSourcef()
STATE get_state() const
Get PLAYING/PAUSED/STOPPED.
void set_velocity(const Vector3f &velocity)
Set the velocity of the Sound_Source_HW for the doppler effect.
A 3D Point represented with floats.
#define ZENI_DEFAULT_MAX_SOUND_DISTANCE
void set_max_distance(const float &max_distance=ZENI_DEFAULT_MAX_SOUND_DISTANCE)
Vector3f get_velocity() const
Get the velocity of the Sound_Buffer.
EGLContext EGLenum EGLClientBuffer buffer
Sound & get_Sound()
Get access to the singleton.
float get_rolloff() const
A Featureful 3-Space Vector Class.
#define AL_ROLLOFF_FACTOR
void set_rolloff(const float &rolloff=ZENI_DEFAULT_ROLLOFF)
const ALuint & get_id() const
Get the OpenAL id of the Sound_Buffer.
GLsizei GLsizei GLfloat distance
static String errorString()
#define ZENI_DEFAULT_REFERENCE_DISTANCE
void ZENI_LOGD(const Zeni::String &str)
float get_reference_distance() const
#define ZENI_DEFAULT_ROLLOFF
float calculate_gain(const Point3f &listener_position) const
Get the actual volume gain, given gain+position+near_clamp+far_clamp+rolloff.
static alSourcefv_fcn alSourcefv()
float get_duration() const
Get the duration of the Sound_Buffer in seconds.
static alSourcePlay_fcn alSourcePlay()
float get_max_distance() const
bool is_looping() const
Check to see if the Sound_Buffer is set to loop back to the start once it is done playing...
#define AL_REFERENCE_DISTANCE
bool is_playing() const
Check to see if the Sound_Source_HW is playing.
void set_position(const Point3f &position)
Set the position of the Sound_Source_HW.
#define ZENI_DEFAULT_SOUND_PRIORITY
static alSourcePause_fcn alSourcePause()
bool is_stopped() const
Check to see if the Sound_Source_HW is stopped.
bool is_paused() const
Check to see if the Sound_Source_HW is paused.
float get_gain() const
Get the gain.
void pause()
Pause the Sound_Source_HW.
long double get_seconds_since(const Time_HQ &time) const
Get the number of seconds passed between 'time' and this Time.
static alGenSources_fcn alGenSources()
Point3f get_position() const
Get the position of the Sound_Buffer.
GLsizei GLsizei GLchar * source
void set_pitch(const float &pitch=ZENI_DEFAULT_PITCH)
Set the pitch.
float get_time() const
Get the current position in the Sound_Buffer, offset in seconds.