Removed OpenAL legacy code
Windows implementation in progress
This commit is contained in:
@@ -10,11 +10,9 @@
|
||||
#include "KRAudioManager.h"
|
||||
|
||||
|
||||
KRAudioBuffer::KRAudioBuffer(KRAudioManager *manager, KRAudioSample *sound, int index, ALenum dataFormat, int frameCount, int frameRate, int bytesPerFrame, void (*fn_populate)(KRAudioSample *, int, void *))
|
||||
KRAudioBuffer::KRAudioBuffer(KRAudioManager *manager, KRAudioSample *sound, int index, int frameCount, int frameRate, int bytesPerFrame, void (*fn_populate)(KRAudioSample *, int, void *))
|
||||
{
|
||||
m_bufferID = 0;
|
||||
m_pSoundManager = manager;
|
||||
m_dataFormat = dataFormat;
|
||||
m_frameCount = frameCount;
|
||||
m_frameRate = frameRate;
|
||||
m_bytesPerFrame = bytesPerFrame;
|
||||
@@ -25,20 +23,10 @@ KRAudioBuffer::KRAudioBuffer(KRAudioManager *manager, KRAudioSample *sound, int
|
||||
m_pSoundManager->makeCurrentContext();
|
||||
m_pData = m_pSoundManager->getBufferData(m_frameCount * m_bytesPerFrame);
|
||||
fn_populate(sound, index, m_pData->getStart());
|
||||
|
||||
if(manager->getAudioEngine() == KRAudioManager::KRAKEN_AUDIO_OPENAL) {
|
||||
ALDEBUG(alGenBuffers(1, &m_bufferID));
|
||||
ALDEBUG(alBufferData(m_bufferID, m_dataFormat, m_pData->getStart(), m_frameCount * m_bytesPerFrame, m_frameRate));
|
||||
}
|
||||
}
|
||||
|
||||
KRAudioBuffer::~KRAudioBuffer()
|
||||
{
|
||||
if(m_bufferID) {
|
||||
ALDEBUG(alDeleteBuffers(1, &m_bufferID));
|
||||
m_bufferID = 0;
|
||||
}
|
||||
|
||||
m_pSoundManager->recycleBufferData(m_pData);
|
||||
}
|
||||
|
||||
@@ -47,11 +35,6 @@ KRAudioSample *KRAudioBuffer::getAudioSample()
|
||||
return m_audioSample;
|
||||
}
|
||||
|
||||
unsigned int KRAudioBuffer::getBufferID()
|
||||
{
|
||||
return m_bufferID;
|
||||
}
|
||||
|
||||
int KRAudioBuffer::getFrameCount()
|
||||
{
|
||||
return m_frameCount;
|
||||
|
||||
@@ -18,10 +18,9 @@ class KRAudioSample;
|
||||
class KRAudioBuffer
|
||||
{
|
||||
public:
|
||||
KRAudioBuffer(KRAudioManager *manager, KRAudioSample *sound, int index, ALenum dataFormat, int frameCount, int frameRate, int bytesPerFrame, void (*fn_populate)(KRAudioSample *, int, void *));
|
||||
KRAudioBuffer(KRAudioManager *manager, KRAudioSample *sound, int index, int frameCount, int frameRate, int bytesPerFrame, void (*fn_populate)(KRAudioSample *, int, void *));
|
||||
~KRAudioBuffer();
|
||||
|
||||
unsigned int getBufferID();
|
||||
int getFrameCount();
|
||||
int getFrameRate();
|
||||
signed short *getFrameData();
|
||||
@@ -32,14 +31,11 @@ private:
|
||||
KRAudioManager *m_pSoundManager;
|
||||
|
||||
int m_index;
|
||||
ALenum m_dataFormat;
|
||||
int m_frameCount;
|
||||
int m_frameRate;
|
||||
int m_bytesPerFrame;
|
||||
KRDataBlock *m_pData;
|
||||
|
||||
unsigned int m_bufferID;
|
||||
|
||||
KRAudioSample *m_audioSample;
|
||||
};
|
||||
|
||||
|
||||
@@ -37,12 +37,13 @@
|
||||
#include "KRContext.h"
|
||||
#include "KRVector2.h"
|
||||
#include "KRCollider.h"
|
||||
#ifdef __APPLE__
|
||||
#include <Accelerate/Accelerate.h>
|
||||
#endif
|
||||
|
||||
OSStatus alcASASetListenerProc(const ALuint property, ALvoid *data, ALuint dataSize);
|
||||
ALvoid alcMacOSXRenderingQualityProc(const ALint value);
|
||||
|
||||
KRAudioManager::KRAudioManager(KRContext &context) : KRContextObject(context)
|
||||
KRAudioManager::KRAudioManager(KRContext &context)
|
||||
: KRContextObject(context)
|
||||
, m_initialized(false)
|
||||
{
|
||||
m_enable_audio = true;
|
||||
m_enable_hrtf = true;
|
||||
@@ -50,9 +51,10 @@ KRAudioManager::KRAudioManager(KRContext &context) : KRContextObject(context)
|
||||
m_reverb_max_length = 8.0f;
|
||||
|
||||
m_anticlick_block = true;
|
||||
#ifdef __APPLE__
|
||||
mach_timebase_info(&m_timebase_info);
|
||||
#endif
|
||||
|
||||
m_audio_engine = KRAKEN_AUDIO_SIREN;
|
||||
m_high_quality_hrtf = false;
|
||||
|
||||
m_listener_scene = NULL;
|
||||
@@ -61,22 +63,21 @@ KRAudioManager::KRAudioManager(KRContext &context) : KRContextObject(context)
|
||||
m_global_reverb_send_level = 1.0f;
|
||||
m_global_ambient_gain = 1.0f;
|
||||
|
||||
|
||||
// OpenAL
|
||||
m_alDevice = 0;
|
||||
m_alContext = 0;
|
||||
|
||||
// Siren
|
||||
#ifdef __APPLE__
|
||||
// Apple Core Audio
|
||||
m_auGraph = NULL;
|
||||
m_auMixer = NULL;
|
||||
|
||||
m_audio_frame = 0;
|
||||
|
||||
|
||||
m_output_sample = 0;
|
||||
// Apple vDSP
|
||||
for (int i = KRENGINE_AUDIO_BLOCK_LOG2N; i <= KRENGINE_REVERB_MAX_FFT_LOG2; i++) {
|
||||
m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N] = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_audio_frame = 0;
|
||||
|
||||
m_output_sample = 0;
|
||||
|
||||
|
||||
m_reverb_input_samples = NULL;
|
||||
m_reverb_input_next_sample = 0;
|
||||
@@ -93,20 +94,6 @@ KRAudioManager::KRAudioManager(KRContext &context) : KRContextObject(context)
|
||||
m_output_accumulation = NULL;
|
||||
}
|
||||
|
||||
void KRAudioManager::initAudio()
|
||||
{
|
||||
switch(m_audio_engine) {
|
||||
case KRAKEN_AUDIO_OPENAL:
|
||||
initOpenAL();
|
||||
break;
|
||||
case KRAKEN_AUDIO_SIREN:
|
||||
initSiren();
|
||||
break;
|
||||
case KRAKEN_AUDIO_NONE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
unordered_map<std::string, KRAudioSample *> &KRAudioManager::getSounds()
|
||||
{
|
||||
return m_sounds;
|
||||
@@ -160,11 +147,11 @@ void KRAudioManager::setListenerScene(KRScene *scene)
|
||||
m_listener_scene = scene;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
// Apple Core Audio
|
||||
void KRAudioManager::renderAudio(UInt32 inNumberFrames, AudioBufferList *ioData)
|
||||
{
|
||||
// uint64_t start_time = mach_absolute_time();
|
||||
|
||||
|
||||
AudioUnitSampleType *outA = (AudioUnitSampleType *)ioData->mBuffers[0].mData;
|
||||
AudioUnitSampleType *outB = (AudioUnitSampleType *)ioData->mBuffers[1].mData; // Non-Interleaved only
|
||||
|
||||
@@ -208,11 +195,9 @@ void KRAudioManager::renderAudio(UInt32 inNumberFrames, AudioBufferList *ioData)
|
||||
outB[output_frame] = (Float32)right_channel;
|
||||
#endif
|
||||
output_frame++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// uint64_t end_time = mach_absolute_time();
|
||||
// uint64_t duration = (end_time - start_time) * m_timebase_info.numer / m_timebase_info.denom; // Nanoseconds
|
||||
// double ms = duration;
|
||||
@@ -221,6 +206,7 @@ void KRAudioManager::renderAudio(UInt32 inNumberFrames, AudioBufferList *ioData)
|
||||
// fprintf(stderr, "audio load: %5.1f%% hrtf channels: %li\n", (float)(duration * 1000 / max_duration) / 10.0f, m_mapped_sources.size());
|
||||
// printf("ms %2.3f frames %ld audio load: %5.1f%% hrtf channels: %li\n", ms, (unsigned long) inNumberFrames, (float)(duration * 1000 / max_duration) / 10.0f, m_mapped_sources.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
float *KRAudioManager::getBlockAddress(int block_offset)
|
||||
{
|
||||
@@ -229,14 +215,13 @@ float *KRAudioManager::getBlockAddress(int block_offset)
|
||||
|
||||
void KRAudioManager::renderReverbImpulseResponse(int impulse_response_offset, int frame_count_log2)
|
||||
{
|
||||
|
||||
int frame_count = 1 << frame_count_log2;
|
||||
int fft_size = frame_count * 2;
|
||||
int fft_size_log2 = frame_count_log2 + 1;
|
||||
|
||||
DSPSplitComplex reverb_sample_data_complex = m_workspace[0];
|
||||
DSPSplitComplex impulse_block_data_complex = m_workspace[1];
|
||||
DSPSplitComplex conv_data_complex = m_workspace[2];
|
||||
SplitComplex reverb_sample_data_complex = m_workspace[0];
|
||||
SplitComplex impulse_block_data_complex = m_workspace[1];
|
||||
SplitComplex conv_data_complex = m_workspace[2];
|
||||
|
||||
int reverb_offset = (m_reverb_input_next_sample + KRENGINE_AUDIO_BLOCK_LENGTH - frame_count);
|
||||
if(reverb_offset < 0) {
|
||||
@@ -425,6 +410,9 @@ void KRAudioManager::renderBlock()
|
||||
m_mutex.unlock();
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
// Apple Core Audio
|
||||
|
||||
// audio render procedure, don't allocate memory, don't take any locks, don't waste time
|
||||
OSStatus KRAudioManager::renderInput(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
|
||||
{
|
||||
@@ -432,7 +420,6 @@ OSStatus KRAudioManager::renderInput(void *inRefCon, AudioUnitRenderActionFlags
|
||||
return noErr;
|
||||
}
|
||||
|
||||
|
||||
void KRSetAUCanonical(AudioStreamBasicDescription &desc, UInt32 nChannels, bool interleaved)
|
||||
{
|
||||
desc.mFormatID = kAudioFormatLinearPCM;
|
||||
@@ -451,6 +438,7 @@ void KRSetAUCanonical(AudioStreamBasicDescription &desc, UInt32 nChannels, bool
|
||||
desc.mFormatFlags |= kAudioFormatFlagIsNonInterleaved;
|
||||
}
|
||||
}
|
||||
#endif // Apple Core Audio
|
||||
|
||||
void KRAudioManager::initHRTF()
|
||||
{
|
||||
@@ -837,7 +825,7 @@ void KRAudioManager::initHRTF()
|
||||
KRVector2 pos = *itr;
|
||||
KRAudioSample *sample = getHRTFSample(pos);
|
||||
for(int channel=0; channel < 2; channel++) {
|
||||
DSPSplitComplex spectral;
|
||||
SplitComplex spectral;
|
||||
spectral.realp = m_hrtf_data + sample_index * 1024 + channel * 512;
|
||||
spectral.imagp = m_hrtf_data + sample_index * 1024 + channel * 512 + 256;
|
||||
sample->sample(0, 128, channel, spectral.realp, 1.0f, false);
|
||||
@@ -860,7 +848,7 @@ KRAudioSample *KRAudioManager::getHRTFSample(const KRVector2 &hrtf_dir)
|
||||
return get(szName);
|
||||
}
|
||||
|
||||
DSPSplitComplex KRAudioManager::getHRTFSpectral(const KRVector2 &hrtf_dir, const int channel)
|
||||
KRAudioManager::SplitComplex KRAudioManager::getHRTFSpectral(const KRVector2 &hrtf_dir, const int channel)
|
||||
{
|
||||
KRVector2 dir = hrtf_dir;
|
||||
int sample_channel = channel;
|
||||
@@ -1024,10 +1012,10 @@ void KRAudioManager::getHRTFMix(const KRVector2 &dir, KRVector2 &dir1, KRVector2
|
||||
mix4 = azim_blend2 * elev_blend;
|
||||
}
|
||||
|
||||
void KRAudioManager::initSiren()
|
||||
void KRAudioManager::initAudio()
|
||||
{
|
||||
if(m_auGraph == NULL) {
|
||||
|
||||
if(!m_initialized == NULL) {
|
||||
m_initialized = true;
|
||||
m_output_sample = KRENGINE_AUDIO_BLOCK_LENGTH;
|
||||
|
||||
// initialize double-buffer for reverb input
|
||||
@@ -1053,6 +1041,11 @@ void KRAudioManager::initSiren()
|
||||
m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N] = vDSP_create_fftsetup( KRENGINE_REVERB_MAX_FFT_LOG2, kFFTRadix2);
|
||||
}
|
||||
|
||||
// ----====---- Initialize HRTF Engine ----====----
|
||||
initHRTF();
|
||||
|
||||
#ifdef __APPLE__
|
||||
// Apple Core Audio
|
||||
// ----====---- Initialize Core Audio Objects ----====----
|
||||
OSDEBUG(NewAUGraph(&m_auGraph));
|
||||
|
||||
@@ -1161,26 +1154,26 @@ void KRAudioManager::initSiren()
|
||||
|
||||
OSDEBUG(AUGraphInitialize(m_auGraph));
|
||||
|
||||
// ----====---- Initialize HRTF Engine ----====----
|
||||
|
||||
initHRTF();
|
||||
|
||||
// ----====---- Start the audio system ----====----
|
||||
OSDEBUG(AUGraphStart(m_auGraph));
|
||||
|
||||
// CAShow(m_auGraph);
|
||||
#endif // Core Audio
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void KRAudioManager::cleanupSiren()
|
||||
void KRAudioManager::cleanupAudio()
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
// Apple Core Audio
|
||||
if(m_auGraph) {
|
||||
OSDEBUG(AUGraphStop(m_auGraph));
|
||||
OSDEBUG(DisposeAUGraph(m_auGraph));
|
||||
m_auGraph = NULL;
|
||||
m_auMixer = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(m_reverb_input_samples) {
|
||||
free(m_reverb_input_samples);
|
||||
@@ -1207,73 +1200,15 @@ void KRAudioManager::cleanupSiren()
|
||||
m_reverb_impulse_responses_weight[i] = 0.0f;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
// Apple vDSP
|
||||
for(int i=KRENGINE_AUDIO_BLOCK_LOG2N; i <= KRENGINE_REVERB_MAX_FFT_LOG2; i++) {
|
||||
if(m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N]) {
|
||||
vDSP_destroy_fftsetup(m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N]);
|
||||
m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KRAudioManager::initOpenAL()
|
||||
{
|
||||
if(m_alDevice == 0) {
|
||||
// ----- Initialize OpenAL -----
|
||||
ALDEBUG(m_alDevice = alcOpenDevice(NULL));
|
||||
ALDEBUG(m_alContext=alcCreateContext(m_alDevice,NULL));
|
||||
ALDEBUG(alcMakeContextCurrent(m_alContext));
|
||||
|
||||
// ----- Configure listener -----
|
||||
ALDEBUG(alDistanceModel(AL_EXPONENT_DISTANCE));
|
||||
ALDEBUG(alSpeedOfSound(1116.43701f)); // 1116.43701 feet per second
|
||||
|
||||
/*
|
||||
// BROKEN IN IOS 6!!
|
||||
#if TARGET_OS_IPHONE
|
||||
ALDEBUG(alcMacOSXRenderingQualityProc(ALC_IPHONE_SPATIAL_RENDERING_QUALITY_HEADPHONES));
|
||||
#else
|
||||
ALDEBUG(alcMacOSXRenderingQualityProc(ALC_MAC_OSX_SPATIAL_RENDERING_QUALITY_HIGH));
|
||||
#endif
|
||||
*/
|
||||
bool enable_reverb = false;
|
||||
if(enable_reverb) {
|
||||
UInt32 setting = 1;
|
||||
ALDEBUG(alcASASetListenerProc(ALC_ASA_REVERB_ON, &setting, sizeof(setting)));
|
||||
ALfloat global_reverb_level = -5.0f;
|
||||
ALDEBUG(alcASASetListenerProc(ALC_ASA_REVERB_GLOBAL_LEVEL, &global_reverb_level, sizeof(global_reverb_level)));
|
||||
|
||||
setting = ALC_ASA_REVERB_ROOM_TYPE_SmallRoom; // ALC_ASA_REVERB_ROOM_TYPE_MediumHall2;
|
||||
ALDEBUG(alcASASetListenerProc(ALC_ASA_REVERB_ROOM_TYPE, &setting, sizeof(setting)));
|
||||
|
||||
|
||||
ALfloat global_reverb_eq_gain = 0.0f;
|
||||
ALDEBUG(alcASASetListenerProc(ALC_ASA_REVERB_EQ_GAIN, &global_reverb_eq_gain, sizeof(global_reverb_eq_gain)));
|
||||
|
||||
ALfloat global_reverb_eq_bandwidth = 0.0f;
|
||||
ALDEBUG(alcASASetListenerProc(ALC_ASA_REVERB_EQ_BANDWITH, &global_reverb_eq_bandwidth, sizeof(global_reverb_eq_bandwidth)));
|
||||
|
||||
ALfloat global_reverb_eq_freq = 0.0f;
|
||||
ALDEBUG(alcASASetListenerProc(ALC_ASA_REVERB_EQ_FREQ, &global_reverb_eq_freq, sizeof(global_reverb_eq_freq)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KRAudioManager::cleanupAudio()
|
||||
{
|
||||
cleanupOpenAL();
|
||||
cleanupSiren();
|
||||
}
|
||||
|
||||
void KRAudioManager::cleanupOpenAL()
|
||||
{
|
||||
if(m_alContext) {
|
||||
ALDEBUG(alcDestroyContext(m_alContext));
|
||||
m_alContext = 0;
|
||||
}
|
||||
if(m_alDevice) {
|
||||
ALDEBUG(alcCloseDevice(m_alDevice));
|
||||
m_alDevice = 0;
|
||||
}
|
||||
}
|
||||
|
||||
KRAudioManager::~KRAudioManager()
|
||||
@@ -1292,11 +1227,6 @@ KRAudioManager::~KRAudioManager()
|
||||
void KRAudioManager::makeCurrentContext()
|
||||
{
|
||||
initAudio();
|
||||
if(m_audio_engine == KRAKEN_AUDIO_OPENAL) {
|
||||
if(m_alContext != 0) {
|
||||
ALDEBUG(alcMakeContextCurrent(m_alContext));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KRAudioManager::setListenerOrientationFromModelMatrix(const KRMat4 &modelMatrix)
|
||||
@@ -1330,11 +1260,6 @@ void KRAudioManager::setListenerOrientation(const KRVector3 &position, const KRV
|
||||
m_listener_up = up;
|
||||
|
||||
makeCurrentContext();
|
||||
if(m_audio_engine == KRAKEN_AUDIO_OPENAL) {
|
||||
ALDEBUG(alListener3f(AL_POSITION, m_listener_position.x, m_listener_position.y, m_listener_position.z));
|
||||
ALfloat orientation[] = {m_listener_forward.x, m_listener_forward.y, m_listener_forward.z, m_listener_up.x, m_listener_up.y, m_listener_up.z};
|
||||
ALDEBUG(alListenerfv(AL_ORIENTATION, orientation));
|
||||
}
|
||||
}
|
||||
|
||||
void KRAudioManager::add(KRAudioSample *sound)
|
||||
@@ -1393,39 +1318,6 @@ void KRAudioManager::recycleBufferData(KRDataBlock *data)
|
||||
}
|
||||
}
|
||||
|
||||
OSStatus alcASASetListenerProc(const ALuint property, ALvoid *data, ALuint dataSize)
|
||||
{
|
||||
OSStatus err = noErr;
|
||||
static alcASASetListenerProcPtr proc = NULL;
|
||||
|
||||
if (proc == NULL) {
|
||||
proc = (alcASASetListenerProcPtr) alcGetProcAddress(NULL, "alcASASetListener");
|
||||
}
|
||||
|
||||
if (proc)
|
||||
err = proc(property, data, dataSize);
|
||||
return (err);
|
||||
}
|
||||
|
||||
ALvoid alcMacOSXRenderingQualityProc(const ALint value)
|
||||
{
|
||||
static alcMacOSXRenderingQualityProcPtr proc = NULL;
|
||||
|
||||
if (proc == NULL) {
|
||||
proc = (alcMacOSXRenderingQualityProcPtr) alcGetProcAddress(NULL, (const ALCchar*) "alcMacOSXRenderingQuality");
|
||||
}
|
||||
|
||||
if (proc)
|
||||
proc(value);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
KRAudioManager::audio_engine_t KRAudioManager::getAudioEngine()
|
||||
{
|
||||
return m_audio_engine;
|
||||
}
|
||||
|
||||
void KRAudioManager::activateAudioSource(KRAudioSource *audioSource)
|
||||
{
|
||||
m_activeAudioSources.insert(audioSource);
|
||||
@@ -1685,10 +1577,10 @@ void KRAudioManager::renderAmbient()
|
||||
|
||||
void KRAudioManager::renderHRTF()
|
||||
{
|
||||
DSPSplitComplex *hrtf_accum = m_workspace + 0;
|
||||
DSPSplitComplex *hrtf_impulse = m_workspace + 1;
|
||||
DSPSplitComplex *hrtf_convolved = m_workspace + 1; // We only need hrtf_impulse or hrtf_convolved at once; we can recycle the buffer
|
||||
DSPSplitComplex *hrtf_sample = m_workspace + 2;
|
||||
SplitComplex *hrtf_accum = m_workspace + 0;
|
||||
SplitComplex *hrtf_impulse = m_workspace + 1;
|
||||
SplitComplex *hrtf_convolved = m_workspace + 1; // We only need hrtf_impulse or hrtf_convolved at once; we can recycle the buffer
|
||||
SplitComplex *hrtf_sample = m_workspace + 2;
|
||||
|
||||
int impulse_response_channels = 2;
|
||||
int hrtf_frames = 128;
|
||||
@@ -1749,7 +1641,7 @@ void KRAudioManager::renderHRTF()
|
||||
memset(hrtf_sample->realp + hrtf_frames, 0, sizeof(float) * hrtf_frames);
|
||||
memset(hrtf_sample->imagp, 0, sizeof(float) * fft_size);
|
||||
|
||||
DSPSplitComplex hrtf_spectral;
|
||||
SplitComplex hrtf_spectral;
|
||||
|
||||
if(m_high_quality_hrtf) {
|
||||
// High quality, interpolated HRTF
|
||||
@@ -1766,7 +1658,7 @@ void KRAudioManager::renderHRTF()
|
||||
|
||||
for(int i=0; i < 1 /*4 */; i++) {
|
||||
if(mix[i] > 0.0f) {
|
||||
DSPSplitComplex hrtf_impulse_sample = getHRTFSpectral(dir[i], channel);
|
||||
SplitComplex hrtf_impulse_sample = getHRTFSpectral(dir[i], channel);
|
||||
vDSP_vsmul(hrtf_impulse_sample.realp, 1, mix+i, hrtf_impulse->realp, 1, fft_size);
|
||||
vDSP_vsmul(hrtf_impulse_sample.imagp, 1, mix+i, hrtf_impulse->imagp, 1, fft_size);
|
||||
vDSP_zvadd(hrtf_impulse, 1, hrtf_accum, 1, hrtf_accum, 1, fft_size);
|
||||
|
||||
@@ -127,14 +127,6 @@ public:
|
||||
KRDataBlock *getBufferData(int size);
|
||||
void recycleBufferData(KRDataBlock *data);
|
||||
|
||||
enum audio_engine_t {
|
||||
KRAKEN_AUDIO_NONE,
|
||||
KRAKEN_AUDIO_OPENAL,
|
||||
KRAKEN_AUDIO_SIREN
|
||||
};
|
||||
|
||||
audio_engine_t getAudioEngine();
|
||||
|
||||
void activateAudioSource(KRAudioSource *audioSource);
|
||||
void deactivateAudioSource(KRAudioSource *audioSource);
|
||||
|
||||
@@ -189,26 +181,31 @@ private:
|
||||
std::set<KRAudioSample *> m_openAudioSamples;
|
||||
|
||||
void initAudio();
|
||||
void initOpenAL();
|
||||
void initSiren();
|
||||
void initHRTF();
|
||||
|
||||
void cleanupAudio();
|
||||
void cleanupOpenAL();
|
||||
void cleanupSiren();
|
||||
|
||||
bool m_initialized;
|
||||
|
||||
audio_engine_t m_audio_engine;
|
||||
|
||||
// OpenAL Handles
|
||||
ALCcontext* m_alContext;
|
||||
ALCdevice* m_alDevice;
|
||||
|
||||
// Siren Handles
|
||||
#ifdef __APPLE__
|
||||
// Apple Core Audio
|
||||
AUGraph m_auGraph;
|
||||
AudioUnit m_auMixer;
|
||||
|
||||
static OSStatus renderInput(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData);
|
||||
void renderAudio(UInt32 inNumberFrames, AudioBufferList *ioData);
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
// Apple vDSP
|
||||
FFTSetup m_fft_setup[KRENGINE_REVERB_MAX_FFT_LOG2 - KRENGINE_AUDIO_BLOCK_LOG2N + 1];
|
||||
typedef DSPSplitComplex SplitComplex;
|
||||
#else
|
||||
typedef struct {
|
||||
float *realp;
|
||||
float *imagp;
|
||||
} SplitComplex;
|
||||
#endif
|
||||
|
||||
__int64_t m_audio_frame; // Number of audio frames processed since the start of the application
|
||||
|
||||
@@ -223,11 +220,8 @@ private:
|
||||
int m_output_accumulation_block_start;
|
||||
int m_output_sample;
|
||||
|
||||
FFTSetup m_fft_setup[KRENGINE_REVERB_MAX_FFT_LOG2 - KRENGINE_AUDIO_BLOCK_LOG2N + 1];
|
||||
float *m_workspace_data;
|
||||
DSPSplitComplex m_workspace[3];
|
||||
|
||||
|
||||
SplitComplex m_workspace[3];
|
||||
|
||||
float *getBlockAddress(int block_offset);
|
||||
void renderBlock();
|
||||
@@ -240,12 +234,12 @@ private:
|
||||
|
||||
std::vector<KRVector2> m_hrtf_sample_locations;
|
||||
float *m_hrtf_data;
|
||||
unordered_map<KRVector2, DSPSplitComplex> m_hrtf_spectral[2];
|
||||
unordered_map<KRVector2, SplitComplex> m_hrtf_spectral[2];
|
||||
|
||||
KRVector2 getNearestHRTFSample(const KRVector2 &dir);
|
||||
void getHRTFMix(const KRVector2 &dir, KRVector2 &hrtf1, KRVector2 &hrtf2, KRVector2 &hrtf3, KRVector2 &hrtf4, float &mix1, float &mix2, float &mix3, float &mix4);
|
||||
KRAudioSample *getHRTFSample(const KRVector2 &hrtf_dir);
|
||||
DSPSplitComplex getHRTFSpectral(const KRVector2 &hrtf_dir, const int channel);
|
||||
SplitComplex getHRTFSpectral(const KRVector2 &hrtf_dir, const int channel);
|
||||
|
||||
|
||||
unordered_map<std::string, siren_ambient_zone_weight_info> m_ambient_zone_weights;
|
||||
@@ -255,7 +249,9 @@ private:
|
||||
float m_reverb_zone_total_weight = 0.0f; // For normalizing zone weights
|
||||
|
||||
boost::signals2::mutex m_mutex;
|
||||
#ifdef __APPLE__
|
||||
mach_timebase_info_data_t m_timebase_info;
|
||||
#endif
|
||||
|
||||
|
||||
unordered_multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > > m_mapped_sources, m_prev_mapped_sources;
|
||||
|
||||
@@ -34,16 +34,20 @@
|
||||
#include "KRDataBlock.h"
|
||||
#include "KRAudioBuffer.h"
|
||||
#include "KRContext.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <Accelerate/Accelerate.h>
|
||||
#endif
|
||||
|
||||
KRAudioSample::KRAudioSample(KRContext &context, std::string name, std::string extension) : KRResource(context, name)
|
||||
{
|
||||
m_pData = new KRDataBlock();
|
||||
m_extension = extension;
|
||||
|
||||
#ifdef __APPLE__
|
||||
// Apple Audio Toolbox
|
||||
m_audio_file_id = 0;
|
||||
m_fileRef = NULL;
|
||||
#endif
|
||||
m_totalFrames = 0;
|
||||
m_bytesPerFrame = 0;
|
||||
m_frameRate = 0;
|
||||
@@ -57,8 +61,11 @@ KRAudioSample::KRAudioSample(KRContext &context, std::string name, std::string e
|
||||
m_pData = data;
|
||||
m_extension = extension;
|
||||
|
||||
#ifdef __APPLE__
|
||||
// Apple Audio Toolbox
|
||||
m_audio_file_id = 0;
|
||||
m_fileRef = NULL;
|
||||
#endif
|
||||
m_totalFrames = 0;
|
||||
m_bytesPerFrame = 0;
|
||||
m_frameRate = 0;
|
||||
@@ -194,6 +201,8 @@ void KRAudioSample::sample(__int64_t frame_offset, int frame_count, int channel,
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
// Apple Audio Toolbox
|
||||
OSStatus KRAudioSample::ReadProc( // AudioFile_ReadProc
|
||||
void * inClientData,
|
||||
SInt64 inPosition,
|
||||
@@ -231,10 +240,13 @@ OSStatus KRAudioSample::WriteProc( // AudioFile_WriteProc
|
||||
{
|
||||
return -1; // Writing not supported
|
||||
}
|
||||
|
||||
#endif // Apple Audio Toolbox
|
||||
|
||||
void KRAudioSample::openFile()
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
// Apple Audio Toolbox
|
||||
|
||||
// AudioFileInitializeWithCallbacks
|
||||
if(m_fileRef == NULL) {
|
||||
|
||||
@@ -279,15 +291,19 @@ void KRAudioSample::openFile()
|
||||
int maxFramesPerBuffer = KRENGINE_AUDIO_MAX_BUFFER_SIZE / m_bytesPerFrame;
|
||||
m_bufferCount = (m_totalFrames+maxFramesPerBuffer-1)/maxFramesPerBuffer; // CEIL(_totalFrames / maxFramesPerBuffer)
|
||||
|
||||
m_dataFormat = (outputFormat.mChannelsPerFrame > 1) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;
|
||||
m_channelsPerFrame = outputFormat.mChannelsPerFrame;
|
||||
|
||||
getContext().getAudioManager()->_registerOpenAudioSample(this);
|
||||
}
|
||||
#else
|
||||
#pragma message ( "TODO - implement for Windows" )
|
||||
#endif
|
||||
}
|
||||
|
||||
void KRAudioSample::closeFile()
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
// Apple Audio Toolbox
|
||||
if(m_fileRef) {
|
||||
ExtAudioFileDispose(m_fileRef);
|
||||
m_fileRef = NULL;
|
||||
@@ -297,6 +313,7 @@ void KRAudioSample::closeFile()
|
||||
AudioFileClose(m_audio_file_id);
|
||||
m_audio_file_id = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
getContext().getAudioManager()->_registerCloseAudioSample(this);
|
||||
}
|
||||
@@ -336,9 +353,10 @@ void KRAudioSample::PopulateBuffer(KRAudioSample *sound, int index, void *data)
|
||||
{
|
||||
int maxFramesPerBuffer = KRENGINE_AUDIO_MAX_BUFFER_SIZE / sound->m_bytesPerFrame;
|
||||
int startFrame = index * maxFramesPerBuffer;
|
||||
UInt32 frameCount = (UInt32)KRMIN(sound->m_totalFrames - startFrame, maxFramesPerBuffer);
|
||||
|
||||
__uint32_t frameCount = (__uint32_t)KRMIN(sound->m_totalFrames - startFrame, maxFramesPerBuffer);
|
||||
|
||||
#ifdef __APPLE__
|
||||
// Apple Audio Toolbox
|
||||
AudioBufferList outputBufferInfo;
|
||||
outputBufferInfo.mNumberBuffers = 1;
|
||||
outputBufferInfo.mBuffers[0].mDataByteSize = frameCount * sound->m_bytesPerFrame;
|
||||
@@ -348,6 +366,7 @@ void KRAudioSample::PopulateBuffer(KRAudioSample *sound, int index, void *data)
|
||||
// Read the data into an AudioBufferList
|
||||
ExtAudioFileSeek(sound->m_fileRef, startFrame);
|
||||
ExtAudioFileRead(sound->m_fileRef, (UInt32*)&frameCount, &outputBufferInfo);
|
||||
#endif
|
||||
}
|
||||
|
||||
KRAudioBuffer *KRAudioSample::getBuffer(int index)
|
||||
@@ -356,9 +375,9 @@ KRAudioBuffer *KRAudioSample::getBuffer(int index)
|
||||
|
||||
int maxFramesPerBuffer = KRENGINE_AUDIO_MAX_BUFFER_SIZE / m_bytesPerFrame;
|
||||
int startFrame = index * maxFramesPerBuffer;
|
||||
UInt32 frameCount = (UInt32)KRMIN(m_totalFrames - startFrame, maxFramesPerBuffer);
|
||||
__uint32_t frameCount = (__uint32_t)KRMIN(m_totalFrames - startFrame, maxFramesPerBuffer);
|
||||
|
||||
KRAudioBuffer *buffer = new KRAudioBuffer(getContext().getAudioManager(), this, index, m_dataFormat, frameCount, m_frameRate, m_bytesPerFrame, PopulateBuffer);
|
||||
KRAudioBuffer *buffer = new KRAudioBuffer(getContext().getAudioManager(), this, index, frameCount, m_frameRate, m_bytesPerFrame, PopulateBuffer);
|
||||
|
||||
if(m_bufferCount == 1) {
|
||||
// [self closeFile]; // We don't need to hold on to a file handle if not streaming
|
||||
|
||||
@@ -68,21 +68,11 @@ private:
|
||||
std::string m_extension;
|
||||
KRDataBlock *m_pData;
|
||||
|
||||
#ifdef __APPLE__
|
||||
// Apple Audio Toolbox
|
||||
AudioFileID m_audio_file_id;
|
||||
ExtAudioFileRef m_fileRef;
|
||||
|
||||
int m_bufferCount;
|
||||
|
||||
SInt64 m_totalFrames;
|
||||
int m_frameRate;
|
||||
int m_bytesPerFrame;
|
||||
int m_channelsPerFrame;
|
||||
ALenum m_dataFormat;
|
||||
|
||||
void openFile();
|
||||
void closeFile();
|
||||
void loadInfo();
|
||||
|
||||
static OSStatus ReadProc( // AudioFile_ReadProc
|
||||
void * inClientData,
|
||||
SInt64 inPosition,
|
||||
@@ -104,7 +94,18 @@ private:
|
||||
static OSStatus SetSizeProc( // AudioFile_SetSizeProc
|
||||
void * inClientData,
|
||||
SInt64 inSize);
|
||||
#endif
|
||||
|
||||
int m_bufferCount;
|
||||
|
||||
__int64_t m_totalFrames;
|
||||
int m_frameRate;
|
||||
int m_bytesPerFrame;
|
||||
int m_channelsPerFrame;
|
||||
|
||||
void openFile();
|
||||
void closeFile();
|
||||
void loadInfo();
|
||||
|
||||
static void PopulateBuffer(KRAudioSample *sound, int index, void *data);
|
||||
};
|
||||
|
||||
@@ -35,8 +35,6 @@
|
||||
#include "KRAudioSample.h"
|
||||
#include "KRAudioBuffer.h"
|
||||
|
||||
OSStatus alcASASetSourceProc(const ALuint property, ALuint source, ALvoid *data, ALuint dataSize);
|
||||
|
||||
KRAudioSource::KRAudioSource(KRScene &scene, std::string name) : KRNode(scene, name)
|
||||
{
|
||||
m_currentBufferFrame = 0;
|
||||
@@ -44,7 +42,6 @@ KRAudioSource::KRAudioSource(KRScene &scene, std::string name) : KRNode(scene, n
|
||||
m_is3d = true;
|
||||
m_isPrimed = false;
|
||||
m_audioFile = NULL;
|
||||
m_sourceID = 0;
|
||||
m_gain = 1.0f;
|
||||
m_pitch = 1.0f;
|
||||
m_looping = false;
|
||||
@@ -61,11 +58,6 @@ KRAudioSource::KRAudioSource(KRScene &scene, std::string name) : KRNode(scene, n
|
||||
|
||||
KRAudioSource::~KRAudioSource()
|
||||
{
|
||||
if(m_sourceID) {
|
||||
getContext().getAudioManager()->makeCurrentContext();
|
||||
ALDEBUG(alDeleteSources(1, &m_sourceID));
|
||||
m_sourceID = 0;
|
||||
}
|
||||
while(m_audioBuffers.size()) {
|
||||
delete m_audioBuffers.front();
|
||||
m_audioBuffers.pop();
|
||||
@@ -164,20 +156,6 @@ void KRAudioSource::prime()
|
||||
queueBuffer();
|
||||
}
|
||||
|
||||
if(getContext().getAudioManager()->getAudioEngine() == KRAudioManager::KRAKEN_AUDIO_OPENAL) {
|
||||
|
||||
// Initialize audio source
|
||||
getContext().getAudioManager()->makeCurrentContext();
|
||||
|
||||
m_sourceID = 0;
|
||||
ALDEBUG(alGenSources(1, &m_sourceID));
|
||||
|
||||
//alSourcei(_sourceID, AL_BUFFER, firstBuffer.bufferID);
|
||||
ALDEBUG(alSourcef(m_sourceID, AL_PITCH, m_pitch));
|
||||
ALDEBUG(alSourcei(m_sourceID, AL_LOOPING, m_looping && m_audioFile->getBufferCount() == 1));
|
||||
ALDEBUG(alSourcef(m_sourceID, AL_GAIN, m_gain));
|
||||
}
|
||||
|
||||
m_isPrimed = true;
|
||||
}
|
||||
}
|
||||
@@ -187,13 +165,6 @@ void KRAudioSource::queueBuffer()
|
||||
{
|
||||
KRAudioBuffer *buffer = m_audioFile->getBuffer(m_nextBufferIndex);
|
||||
m_audioBuffers.push(buffer);
|
||||
ALuint buffer_ids[1];
|
||||
buffer_ids[0] = buffer->getBufferID();
|
||||
|
||||
if(getContext().getAudioManager()->getAudioEngine() == KRAudioManager::KRAKEN_AUDIO_OPENAL) {
|
||||
ALDEBUG(alSourceQueueBuffers(m_sourceID, 1, buffer_ids));
|
||||
}
|
||||
|
||||
m_nextBufferIndex = (m_nextBufferIndex + 1) % m_audioFile->getBufferCount();
|
||||
}
|
||||
|
||||
@@ -242,12 +213,6 @@ void KRAudioSource::render(KRCamera *pCamera, std::vector<KRPointLight *> &point
|
||||
void KRAudioSource::setGain(float gain)
|
||||
{
|
||||
m_gain = gain;
|
||||
if(getContext().getAudioManager()->getAudioEngine() == KRAudioManager::KRAKEN_AUDIO_OPENAL) {
|
||||
if(m_isPrimed) {
|
||||
getContext().getAudioManager()->makeCurrentContext();
|
||||
ALDEBUG(alSourcef(m_sourceID, AL_GAIN, m_gain));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float KRAudioSource::getGain()
|
||||
@@ -258,12 +223,6 @@ float KRAudioSource::getGain()
|
||||
void KRAudioSource::setPitch(float pitch)
|
||||
{
|
||||
m_pitch = pitch;
|
||||
if(getContext().getAudioManager()->getAudioEngine() == KRAudioManager::KRAKEN_AUDIO_OPENAL) {
|
||||
if(m_isPrimed ) {
|
||||
getContext().getAudioManager()->makeCurrentContext();
|
||||
ALDEBUG(alSourcef(m_sourceID, AL_PITCH, m_pitch));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -274,12 +233,6 @@ float KRAudioSource::getReferenceDistance()
|
||||
void KRAudioSource::setReferenceDistance(float reference_distance)
|
||||
{
|
||||
m_referenceDistance = reference_distance;
|
||||
if(getContext().getAudioManager()->getAudioEngine() == KRAudioManager::KRAKEN_AUDIO_OPENAL) {
|
||||
if(m_isPrimed && m_is3d) {
|
||||
getContext().getAudioManager()->makeCurrentContext();
|
||||
ALDEBUG(alSourcef(m_sourceID, AL_REFERENCE_DISTANCE, m_referenceDistance));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float KRAudioSource::getReverb()
|
||||
@@ -290,14 +243,7 @@ float KRAudioSource::getReverb()
|
||||
void KRAudioSource::setReverb(float reverb)
|
||||
{
|
||||
m_reverb = reverb;
|
||||
if(getContext().getAudioManager()->getAudioEngine() == KRAudioManager::KRAKEN_AUDIO_OPENAL) {
|
||||
if(m_isPrimed && m_is3d) {
|
||||
getContext().getAudioManager()->makeCurrentContext();
|
||||
ALDEBUG(alcASASetSourceProc(ALC_ASA_REVERB_SEND_LEVEL, m_sourceID, &m_reverb, sizeof(m_reverb)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float KRAudioSource::getRolloffFactor()
|
||||
{
|
||||
@@ -307,12 +253,6 @@ float KRAudioSource::getRolloffFactor()
|
||||
void KRAudioSource::setRolloffFactor(float rolloff_factor)
|
||||
{
|
||||
m_rolloffFactor = rolloff_factor;
|
||||
if(getContext().getAudioManager()->getAudioEngine() == KRAudioManager::KRAKEN_AUDIO_OPENAL) {
|
||||
if(m_isPrimed && m_is3d) {
|
||||
getContext().getAudioManager()->makeCurrentContext();
|
||||
ALDEBUG(alSourcef(m_sourceID, AL_ROLLOFF_FACTOR, m_rolloffFactor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KRAudioSource::setLooping(bool looping)
|
||||
@@ -357,15 +297,6 @@ void KRAudioSource::setIs3D(bool is3D)
|
||||
m_is3d = is3D;
|
||||
}
|
||||
|
||||
bool KRAudioSource::hasPhysics()
|
||||
{
|
||||
if(KRNode::hasPhysics()) {
|
||||
return true;
|
||||
}
|
||||
KRAudioManager *audioManager = getContext().getAudioManager();
|
||||
return audioManager->getAudioEngine() == KRAudioManager::KRAKEN_AUDIO_OPENAL;
|
||||
}
|
||||
|
||||
void KRAudioSource::advanceBuffer()
|
||||
{
|
||||
if(m_audioBuffers.size()) {
|
||||
@@ -381,25 +312,6 @@ void KRAudioSource::physicsUpdate(float deltaTime)
|
||||
|
||||
KRAudioManager *audioManager = getContext().getAudioManager();
|
||||
audioManager->activateAudioSource(this);
|
||||
if(audioManager->getAudioEngine() == KRAudioManager::KRAKEN_AUDIO_OPENAL) {
|
||||
|
||||
if(m_isPrimed && m_playing) {
|
||||
getContext().getAudioManager()->makeCurrentContext();
|
||||
updatePosition();
|
||||
ALint processed_count = 0;
|
||||
ALDEBUG(alGetSourcei(m_sourceID, AL_BUFFERS_PROCESSED, &processed_count));
|
||||
while(processed_count-- > 0) {
|
||||
ALuint finished_buffer = 0;
|
||||
ALDEBUG(alSourceUnqueueBuffers(m_sourceID, 1, &finished_buffer));
|
||||
advanceBuffer();
|
||||
}
|
||||
|
||||
ALint val;
|
||||
// Make sure the source is still playing, and restart it if needed.
|
||||
ALDEBUG(alGetSourcei(m_sourceID, AL_SOURCE_STATE, &val));
|
||||
ALDEBUG(if(val != AL_PLAYING) alSourcePlay(m_sourceID));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KRAudioSource::play()
|
||||
@@ -414,23 +326,6 @@ void KRAudioSource::play()
|
||||
m_start_audio_frame = audioManager->getAudioFrame() - m_paused_audio_frame;
|
||||
m_paused_audio_frame = -1;
|
||||
audioManager->activateAudioSource(this);
|
||||
if(audioManager->getAudioEngine() == KRAudioManager::KRAKEN_AUDIO_OPENAL) {
|
||||
getContext().getAudioManager()->makeCurrentContext();
|
||||
prime();
|
||||
updatePosition();
|
||||
|
||||
if(m_is3d) {
|
||||
ALDEBUG(alSource3f(m_sourceID, AL_VELOCITY, 0.0f, 0.0f, 0.0f));
|
||||
ALDEBUG(alSourcef(m_sourceID, AL_REFERENCE_DISTANCE, m_referenceDistance));
|
||||
ALDEBUG(alSourcef(m_sourceID, AL_ROLLOFF_FACTOR, m_rolloffFactor));
|
||||
ALDEBUG(alcASASetSourceProc(ALC_ASA_REVERB_SEND_LEVEL, m_sourceID, &m_reverb, sizeof(m_reverb)));
|
||||
ALDEBUG(alSourcei(m_sourceID, AL_SOURCE_RELATIVE, AL_FALSE));
|
||||
} else {
|
||||
ALDEBUG(alSourcei(m_sourceID, AL_SOURCE_RELATIVE, AL_TRUE));
|
||||
ALDEBUG(alSource3f(m_sourceID, AL_POSITION, 0.0, 0.0, 0.0));
|
||||
}
|
||||
ALDEBUG(alSourcePlay(m_sourceID));
|
||||
}
|
||||
}
|
||||
m_playing = true;
|
||||
}
|
||||
@@ -474,24 +369,6 @@ KRAudioSample *KRAudioSource::getAudioSample()
|
||||
return m_audioFile;
|
||||
}
|
||||
|
||||
void KRAudioSource::updatePosition()
|
||||
{
|
||||
if(m_is3d) {
|
||||
ALfloat occlusion = 0.0f; // type ALfloat -100.0 db (most occlusion) - 0.0 db (no occlusion, 0.0 default)
|
||||
ALfloat obstruction = 0.0f; // type ALfloat -100.0 db (most obstruction) - 0.0 db (no obstruction, 0.0 default)
|
||||
|
||||
KRVector3 worldPosition = getWorldTranslation();
|
||||
ALDEBUG(alSource3f(m_sourceID, AL_POSITION, worldPosition.x, worldPosition.y, worldPosition.z));
|
||||
ALDEBUG(alSourcef(m_sourceID, AL_GAIN, m_gain));
|
||||
ALDEBUG(alSourcef(m_sourceID, AL_MIN_GAIN, 0.0));
|
||||
ALDEBUG(alSourcef(m_sourceID, AL_MAX_GAIN, 1.0));
|
||||
|
||||
ALDEBUG(alcASASetSourceProc(ALC_ASA_OCCLUSION, m_sourceID, &occlusion, sizeof(occlusion)));
|
||||
ALDEBUG(alcASASetSourceProc(ALC_ASA_OBSTRUCTION, m_sourceID, &obstruction, sizeof(obstruction)));
|
||||
ALDEBUG(alcASASetSourceProc(ALC_ASA_REVERB_SEND_LEVEL, m_sourceID, &m_reverb, sizeof(m_reverb)));
|
||||
}
|
||||
}
|
||||
|
||||
void KRAudioSource::advanceFrames(int frame_count)
|
||||
{
|
||||
m_currentBufferFrame += frame_count;
|
||||
@@ -572,17 +449,3 @@ void KRAudioSource::sample(int frame_count, int channel, float *buffer, float ga
|
||||
memset(buffer, 0, sizeof(float) * frame_count);
|
||||
}
|
||||
}
|
||||
|
||||
OSStatus alcASASetSourceProc(const ALuint property, ALuint source, ALvoid *data, ALuint dataSize)
|
||||
{
|
||||
OSStatus err = noErr;
|
||||
static alcASASetSourceProcPtr proc = NULL;
|
||||
|
||||
if (proc == NULL) {
|
||||
proc = (alcASASetSourceProcPtr) alcGetProcAddress(NULL, (const ALCchar*) "alcASASetSource");
|
||||
}
|
||||
|
||||
if (proc)
|
||||
err = proc(property, source, data, dataSize);
|
||||
return (err);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,6 @@ public:
|
||||
virtual std::string getElementName();
|
||||
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
||||
virtual void loadXML(tinyxml2::XMLElement *e);
|
||||
virtual bool hasPhysics();
|
||||
virtual void physicsUpdate(float deltaTime);
|
||||
|
||||
void render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
@@ -154,8 +153,6 @@ private:
|
||||
float m_rolloffFactor;
|
||||
bool m_enable_occlusion;
|
||||
bool m_enable_obstruction;
|
||||
|
||||
void updatePosition();
|
||||
};
|
||||
|
||||
#endif /* defined(KRAUDIOSOURCE_H) */
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
#include "KRAudioManager.h"
|
||||
#include "KRAudioSample.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
int KRContext::KRENGINE_MAX_SHADER_HANDLES;
|
||||
int KRContext::KRENGINE_GPU_MEM_MAX;
|
||||
int KRContext::KRENGINE_GPU_MEM_TARGET;
|
||||
@@ -44,7 +48,9 @@ void *KRContext::s_log_callback_user_data = NULL;
|
||||
KRContext::KRContext() : m_streamer(*this)
|
||||
{
|
||||
m_streamingEnabled = false;
|
||||
#ifdef __APPLE__
|
||||
mach_timebase_info(&m_timebase_info);
|
||||
#endif
|
||||
|
||||
m_bDetectedExtensions = false;
|
||||
m_current_frame = 0;
|
||||
@@ -317,7 +323,11 @@ float KRContext::getAbsoluteTime() const
|
||||
|
||||
long KRContext::getAbsoluteTimeMilliseconds()
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
return (long)(mach_absolute_time() / 1000 * m_timebase_info.numer / m_timebase_info.denom); // Division done first to avoid potential overflow
|
||||
#else
|
||||
return (long)GetTickCount64();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool KRContext::getStreamingEnabled()
|
||||
|
||||
@@ -36,9 +36,11 @@
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
int KRAKEN_MEM_PAGE_SIZE = getpagesize();
|
||||
#define KRAKEN_MEM_ROUND_DOWN_PAGE(x) ((x) & ~(KRAKEN_MEM_PAGE_SIZE - 1))
|
||||
#define KRAKEN_MEM_ROUND_UP_PAGE(x) ((((x) - 1) & ~(KRAKEN_MEM_PAGE_SIZE - 1)) + KRAKEN_MEM_PAGE_SIZE)
|
||||
#endif
|
||||
|
||||
int m_mapCount = 0;
|
||||
size_t m_mapSize = 0;
|
||||
|
||||
@@ -449,9 +449,9 @@ KRDataBlock &KRMeshManager::getRandomParticles()
|
||||
|
||||
int iVertex=0;
|
||||
for(int iParticle=0; iParticle < KRENGINE_MAX_RANDOM_PARTICLES; iParticle++) {
|
||||
vertex_data[iVertex].vertex.x = (float)(arc4random() % 2000) / 1000.0f - 1000.0f;
|
||||
vertex_data[iVertex].vertex.y = (float)(arc4random() % 2000) / 1000.0f - 1000.0f;
|
||||
vertex_data[iVertex].vertex.z = (float)(arc4random() % 2000) / 1000.0f - 1000.0f;
|
||||
vertex_data[iVertex].vertex.x = (float)(rand() % 2000) / 1000.0f - 1000.0f;
|
||||
vertex_data[iVertex].vertex.y = (float)(rand() % 2000) / 1000.0f - 1000.0f;
|
||||
vertex_data[iVertex].vertex.z = (float)(rand() % 2000) / 1000.0f - 1000.0f;
|
||||
vertex_data[iVertex].uva.u = -0.5f;
|
||||
vertex_data[iVertex].uva.v = -inscribed_circle_radius;
|
||||
iVertex++;
|
||||
|
||||
Reference in New Issue
Block a user