Removed OpenAL legacy code
Windows implementation in progress
This commit is contained in:
@@ -10,11 +10,9 @@
|
|||||||
#include "KRAudioManager.h"
|
#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_pSoundManager = manager;
|
||||||
m_dataFormat = dataFormat;
|
|
||||||
m_frameCount = frameCount;
|
m_frameCount = frameCount;
|
||||||
m_frameRate = frameRate;
|
m_frameRate = frameRate;
|
||||||
m_bytesPerFrame = bytesPerFrame;
|
m_bytesPerFrame = bytesPerFrame;
|
||||||
@@ -25,20 +23,10 @@ KRAudioBuffer::KRAudioBuffer(KRAudioManager *manager, KRAudioSample *sound, int
|
|||||||
m_pSoundManager->makeCurrentContext();
|
m_pSoundManager->makeCurrentContext();
|
||||||
m_pData = m_pSoundManager->getBufferData(m_frameCount * m_bytesPerFrame);
|
m_pData = m_pSoundManager->getBufferData(m_frameCount * m_bytesPerFrame);
|
||||||
fn_populate(sound, index, m_pData->getStart());
|
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()
|
KRAudioBuffer::~KRAudioBuffer()
|
||||||
{
|
{
|
||||||
if(m_bufferID) {
|
|
||||||
ALDEBUG(alDeleteBuffers(1, &m_bufferID));
|
|
||||||
m_bufferID = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_pSoundManager->recycleBufferData(m_pData);
|
m_pSoundManager->recycleBufferData(m_pData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,11 +35,6 @@ KRAudioSample *KRAudioBuffer::getAudioSample()
|
|||||||
return m_audioSample;
|
return m_audioSample;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int KRAudioBuffer::getBufferID()
|
|
||||||
{
|
|
||||||
return m_bufferID;
|
|
||||||
}
|
|
||||||
|
|
||||||
int KRAudioBuffer::getFrameCount()
|
int KRAudioBuffer::getFrameCount()
|
||||||
{
|
{
|
||||||
return m_frameCount;
|
return m_frameCount;
|
||||||
|
|||||||
@@ -18,10 +18,9 @@ class KRAudioSample;
|
|||||||
class KRAudioBuffer
|
class KRAudioBuffer
|
||||||
{
|
{
|
||||||
public:
|
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();
|
~KRAudioBuffer();
|
||||||
|
|
||||||
unsigned int getBufferID();
|
|
||||||
int getFrameCount();
|
int getFrameCount();
|
||||||
int getFrameRate();
|
int getFrameRate();
|
||||||
signed short *getFrameData();
|
signed short *getFrameData();
|
||||||
@@ -32,14 +31,11 @@ private:
|
|||||||
KRAudioManager *m_pSoundManager;
|
KRAudioManager *m_pSoundManager;
|
||||||
|
|
||||||
int m_index;
|
int m_index;
|
||||||
ALenum m_dataFormat;
|
int m_frameCount;
|
||||||
int m_frameCount;
|
|
||||||
int m_frameRate;
|
int m_frameRate;
|
||||||
int m_bytesPerFrame;
|
int m_bytesPerFrame;
|
||||||
KRDataBlock *m_pData;
|
KRDataBlock *m_pData;
|
||||||
|
|
||||||
unsigned int m_bufferID;
|
|
||||||
|
|
||||||
KRAudioSample *m_audioSample;
|
KRAudioSample *m_audioSample;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -37,12 +37,13 @@
|
|||||||
#include "KRContext.h"
|
#include "KRContext.h"
|
||||||
#include "KRVector2.h"
|
#include "KRVector2.h"
|
||||||
#include "KRCollider.h"
|
#include "KRCollider.h"
|
||||||
|
#ifdef __APPLE__
|
||||||
#include <Accelerate/Accelerate.h>
|
#include <Accelerate/Accelerate.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
OSStatus alcASASetListenerProc(const ALuint property, ALvoid *data, ALuint dataSize);
|
KRAudioManager::KRAudioManager(KRContext &context)
|
||||||
ALvoid alcMacOSXRenderingQualityProc(const ALint value);
|
: KRContextObject(context)
|
||||||
|
, m_initialized(false)
|
||||||
KRAudioManager::KRAudioManager(KRContext &context) : KRContextObject(context)
|
|
||||||
{
|
{
|
||||||
m_enable_audio = true;
|
m_enable_audio = true;
|
||||||
m_enable_hrtf = true;
|
m_enable_hrtf = true;
|
||||||
@@ -50,9 +51,10 @@ KRAudioManager::KRAudioManager(KRContext &context) : KRContextObject(context)
|
|||||||
m_reverb_max_length = 8.0f;
|
m_reverb_max_length = 8.0f;
|
||||||
|
|
||||||
m_anticlick_block = true;
|
m_anticlick_block = true;
|
||||||
|
#ifdef __APPLE__
|
||||||
mach_timebase_info(&m_timebase_info);
|
mach_timebase_info(&m_timebase_info);
|
||||||
|
#endif
|
||||||
|
|
||||||
m_audio_engine = KRAKEN_AUDIO_SIREN;
|
|
||||||
m_high_quality_hrtf = false;
|
m_high_quality_hrtf = false;
|
||||||
|
|
||||||
m_listener_scene = NULL;
|
m_listener_scene = NULL;
|
||||||
@@ -60,23 +62,22 @@ KRAudioManager::KRAudioManager(KRContext &context) : KRContextObject(context)
|
|||||||
m_global_gain = 0.20f;
|
m_global_gain = 0.20f;
|
||||||
m_global_reverb_send_level = 1.0f;
|
m_global_reverb_send_level = 1.0f;
|
||||||
m_global_ambient_gain = 1.0f;
|
m_global_ambient_gain = 1.0f;
|
||||||
|
|
||||||
|
|
||||||
// OpenAL
|
#ifdef __APPLE__
|
||||||
m_alDevice = 0;
|
// Apple Core Audio
|
||||||
m_alContext = 0;
|
|
||||||
|
|
||||||
// Siren
|
|
||||||
m_auGraph = NULL;
|
m_auGraph = NULL;
|
||||||
m_auMixer = NULL;
|
m_auMixer = NULL;
|
||||||
|
|
||||||
|
// 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_audio_frame = 0;
|
||||||
|
|
||||||
|
|
||||||
m_output_sample = 0;
|
m_output_sample = 0;
|
||||||
for(int i=KRENGINE_AUDIO_BLOCK_LOG2N; i <= KRENGINE_REVERB_MAX_FFT_LOG2; i++) {
|
|
||||||
m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_reverb_input_samples = NULL;
|
m_reverb_input_samples = NULL;
|
||||||
m_reverb_input_next_sample = 0;
|
m_reverb_input_next_sample = 0;
|
||||||
@@ -93,20 +94,6 @@ KRAudioManager::KRAudioManager(KRContext &context) : KRContextObject(context)
|
|||||||
m_output_accumulation = NULL;
|
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()
|
unordered_map<std::string, KRAudioSample *> &KRAudioManager::getSounds()
|
||||||
{
|
{
|
||||||
return m_sounds;
|
return m_sounds;
|
||||||
@@ -160,12 +147,12 @@ void KRAudioManager::setListenerScene(KRScene *scene)
|
|||||||
m_listener_scene = scene;
|
m_listener_scene = scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// Apple Core Audio
|
||||||
void KRAudioManager::renderAudio(UInt32 inNumberFrames, AudioBufferList *ioData)
|
void KRAudioManager::renderAudio(UInt32 inNumberFrames, AudioBufferList *ioData)
|
||||||
{
|
{
|
||||||
// uint64_t start_time = mach_absolute_time();
|
// uint64_t start_time = mach_absolute_time();
|
||||||
|
AudioUnitSampleType *outA = (AudioUnitSampleType *)ioData->mBuffers[0].mData;
|
||||||
|
|
||||||
AudioUnitSampleType *outA = (AudioUnitSampleType *)ioData->mBuffers[0].mData;
|
|
||||||
AudioUnitSampleType *outB = (AudioUnitSampleType *)ioData->mBuffers[1].mData; // Non-Interleaved only
|
AudioUnitSampleType *outB = (AudioUnitSampleType *)ioData->mBuffers[1].mData; // Non-Interleaved only
|
||||||
|
|
||||||
int output_frame = 0;
|
int output_frame = 0;
|
||||||
@@ -208,11 +195,9 @@ void KRAudioManager::renderAudio(UInt32 inNumberFrames, AudioBufferList *ioData)
|
|||||||
outB[output_frame] = (Float32)right_channel;
|
outB[output_frame] = (Float32)right_channel;
|
||||||
#endif
|
#endif
|
||||||
output_frame++;
|
output_frame++;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// uint64_t end_time = mach_absolute_time();
|
// uint64_t end_time = mach_absolute_time();
|
||||||
// uint64_t duration = (end_time - start_time) * m_timebase_info.numer / m_timebase_info.denom; // Nanoseconds
|
// uint64_t duration = (end_time - start_time) * m_timebase_info.numer / m_timebase_info.denom; // Nanoseconds
|
||||||
// double ms = duration;
|
// 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());
|
// 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());
|
// 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)
|
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)
|
void KRAudioManager::renderReverbImpulseResponse(int impulse_response_offset, int frame_count_log2)
|
||||||
{
|
{
|
||||||
|
|
||||||
int frame_count = 1 << frame_count_log2;
|
int frame_count = 1 << frame_count_log2;
|
||||||
int fft_size = frame_count * 2;
|
int fft_size = frame_count * 2;
|
||||||
int fft_size_log2 = frame_count_log2 + 1;
|
int fft_size_log2 = frame_count_log2 + 1;
|
||||||
|
|
||||||
DSPSplitComplex reverb_sample_data_complex = m_workspace[0];
|
SplitComplex reverb_sample_data_complex = m_workspace[0];
|
||||||
DSPSplitComplex impulse_block_data_complex = m_workspace[1];
|
SplitComplex impulse_block_data_complex = m_workspace[1];
|
||||||
DSPSplitComplex conv_data_complex = m_workspace[2];
|
SplitComplex conv_data_complex = m_workspace[2];
|
||||||
|
|
||||||
int reverb_offset = (m_reverb_input_next_sample + KRENGINE_AUDIO_BLOCK_LENGTH - frame_count);
|
int reverb_offset = (m_reverb_input_next_sample + KRENGINE_AUDIO_BLOCK_LENGTH - frame_count);
|
||||||
if(reverb_offset < 0) {
|
if(reverb_offset < 0) {
|
||||||
@@ -425,14 +410,16 @@ void KRAudioManager::renderBlock()
|
|||||||
m_mutex.unlock();
|
m_mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// Apple Core Audio
|
||||||
|
|
||||||
// audio render procedure, don't allocate memory, don't take any locks, don't waste time
|
// 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)
|
OSStatus KRAudioManager::renderInput(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
|
||||||
{
|
{
|
||||||
((KRAudioManager*)inRefCon)->renderAudio(inNumberFrames, ioData);
|
((KRAudioManager*)inRefCon)->renderAudio(inNumberFrames, ioData);
|
||||||
return noErr;
|
return noErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KRSetAUCanonical(AudioStreamBasicDescription &desc, UInt32 nChannels, bool interleaved)
|
void KRSetAUCanonical(AudioStreamBasicDescription &desc, UInt32 nChannels, bool interleaved)
|
||||||
{
|
{
|
||||||
desc.mFormatID = kAudioFormatLinearPCM;
|
desc.mFormatID = kAudioFormatLinearPCM;
|
||||||
@@ -451,6 +438,7 @@ void KRSetAUCanonical(AudioStreamBasicDescription &desc, UInt32 nChannels, bool
|
|||||||
desc.mFormatFlags |= kAudioFormatFlagIsNonInterleaved;
|
desc.mFormatFlags |= kAudioFormatFlagIsNonInterleaved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // Apple Core Audio
|
||||||
|
|
||||||
void KRAudioManager::initHRTF()
|
void KRAudioManager::initHRTF()
|
||||||
{
|
{
|
||||||
@@ -837,7 +825,7 @@ void KRAudioManager::initHRTF()
|
|||||||
KRVector2 pos = *itr;
|
KRVector2 pos = *itr;
|
||||||
KRAudioSample *sample = getHRTFSample(pos);
|
KRAudioSample *sample = getHRTFSample(pos);
|
||||||
for(int channel=0; channel < 2; channel++) {
|
for(int channel=0; channel < 2; channel++) {
|
||||||
DSPSplitComplex spectral;
|
SplitComplex spectral;
|
||||||
spectral.realp = m_hrtf_data + sample_index * 1024 + channel * 512;
|
spectral.realp = m_hrtf_data + sample_index * 1024 + channel * 512;
|
||||||
spectral.imagp = m_hrtf_data + sample_index * 1024 + channel * 512 + 256;
|
spectral.imagp = m_hrtf_data + sample_index * 1024 + channel * 512 + 256;
|
||||||
sample->sample(0, 128, channel, spectral.realp, 1.0f, false);
|
sample->sample(0, 128, channel, spectral.realp, 1.0f, false);
|
||||||
@@ -860,7 +848,7 @@ KRAudioSample *KRAudioManager::getHRTFSample(const KRVector2 &hrtf_dir)
|
|||||||
return get(szName);
|
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;
|
KRVector2 dir = hrtf_dir;
|
||||||
int sample_channel = channel;
|
int sample_channel = channel;
|
||||||
@@ -1024,10 +1012,10 @@ void KRAudioManager::getHRTFMix(const KRVector2 &dir, KRVector2 &dir1, KRVector2
|
|||||||
mix4 = azim_blend2 * elev_blend;
|
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;
|
m_output_sample = KRENGINE_AUDIO_BLOCK_LENGTH;
|
||||||
|
|
||||||
// initialize double-buffer for reverb input
|
// initialize double-buffer for reverb input
|
||||||
@@ -1052,7 +1040,12 @@ void KRAudioManager::initSiren()
|
|||||||
for(int i=KRENGINE_AUDIO_BLOCK_LOG2N; i <= KRENGINE_REVERB_MAX_FFT_LOG2; i++) {
|
for(int i=KRENGINE_AUDIO_BLOCK_LOG2N; i <= KRENGINE_REVERB_MAX_FFT_LOG2; i++) {
|
||||||
m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N] = vDSP_create_fftsetup( KRENGINE_REVERB_MAX_FFT_LOG2, kFFTRadix2);
|
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 ----====----
|
// ----====---- Initialize Core Audio Objects ----====----
|
||||||
OSDEBUG(NewAUGraph(&m_auGraph));
|
OSDEBUG(NewAUGraph(&m_auGraph));
|
||||||
|
|
||||||
@@ -1095,8 +1088,8 @@ void KRAudioManager::initSiren()
|
|||||||
|
|
||||||
// ---- Attach render function to channel ----
|
// ---- Attach render function to channel ----
|
||||||
AURenderCallbackStruct renderCallbackStruct;
|
AURenderCallbackStruct renderCallbackStruct;
|
||||||
renderCallbackStruct.inputProc = &renderInput;
|
renderCallbackStruct.inputProc = &renderInput;
|
||||||
renderCallbackStruct.inputProcRefCon = this;
|
renderCallbackStruct.inputProcRefCon = this;
|
||||||
OSDEBUG(AUGraphSetNodeInputCallback(m_auGraph, mixerNode, 0, &renderCallbackStruct)); // 0 = mixer input number
|
OSDEBUG(AUGraphSetNodeInputCallback(m_auGraph, mixerNode, 0, &renderCallbackStruct)); // 0 = mixer input number
|
||||||
|
|
||||||
AudioStreamBasicDescription desc;
|
AudioStreamBasicDescription desc;
|
||||||
@@ -1104,7 +1097,7 @@ void KRAudioManager::initSiren()
|
|||||||
|
|
||||||
UInt32 size = sizeof(desc);
|
UInt32 size = sizeof(desc);
|
||||||
memset(&desc, 0, sizeof(desc));
|
memset(&desc, 0, sizeof(desc));
|
||||||
OSDEBUG(AudioUnitGetProperty( m_auMixer,
|
OSDEBUG(AudioUnitGetProperty( m_auMixer,
|
||||||
kAudioUnitProperty_StreamFormat,
|
kAudioUnitProperty_StreamFormat,
|
||||||
kAudioUnitScope_Input,
|
kAudioUnitScope_Input,
|
||||||
0, // 0 = mixer input number
|
0, // 0 = mixer input number
|
||||||
@@ -1161,26 +1154,26 @@ void KRAudioManager::initSiren()
|
|||||||
|
|
||||||
OSDEBUG(AUGraphInitialize(m_auGraph));
|
OSDEBUG(AUGraphInitialize(m_auGraph));
|
||||||
|
|
||||||
// ----====---- Initialize HRTF Engine ----====----
|
|
||||||
|
|
||||||
initHRTF();
|
|
||||||
|
|
||||||
// ----====---- Start the audio system ----====----
|
// ----====---- Start the audio system ----====----
|
||||||
OSDEBUG(AUGraphStart(m_auGraph));
|
OSDEBUG(AUGraphStart(m_auGraph));
|
||||||
|
|
||||||
// CAShow(m_auGraph);
|
// CAShow(m_auGraph);
|
||||||
|
#endif // Core Audio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KRAudioManager::cleanupSiren()
|
void KRAudioManager::cleanupAudio()
|
||||||
{
|
{
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// Apple Core Audio
|
||||||
if(m_auGraph) {
|
if(m_auGraph) {
|
||||||
OSDEBUG(AUGraphStop(m_auGraph));
|
OSDEBUG(AUGraphStop(m_auGraph));
|
||||||
OSDEBUG(DisposeAUGraph(m_auGraph));
|
OSDEBUG(DisposeAUGraph(m_auGraph));
|
||||||
m_auGraph = NULL;
|
m_auGraph = NULL;
|
||||||
m_auMixer = NULL;
|
m_auMixer = NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if(m_reverb_input_samples) {
|
if(m_reverb_input_samples) {
|
||||||
free(m_reverb_input_samples);
|
free(m_reverb_input_samples);
|
||||||
@@ -1207,73 +1200,15 @@ void KRAudioManager::cleanupSiren()
|
|||||||
m_reverb_impulse_responses_weight[i] = 0.0f;
|
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++) {
|
for(int i=KRENGINE_AUDIO_BLOCK_LOG2N; i <= KRENGINE_REVERB_MAX_FFT_LOG2; i++) {
|
||||||
if(m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N]) {
|
if(m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N]) {
|
||||||
vDSP_destroy_fftsetup(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;
|
m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
#endif
|
||||||
|
|
||||||
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()
|
KRAudioManager::~KRAudioManager()
|
||||||
@@ -1292,11 +1227,6 @@ KRAudioManager::~KRAudioManager()
|
|||||||
void KRAudioManager::makeCurrentContext()
|
void KRAudioManager::makeCurrentContext()
|
||||||
{
|
{
|
||||||
initAudio();
|
initAudio();
|
||||||
if(m_audio_engine == KRAKEN_AUDIO_OPENAL) {
|
|
||||||
if(m_alContext != 0) {
|
|
||||||
ALDEBUG(alcMakeContextCurrent(m_alContext));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRAudioManager::setListenerOrientationFromModelMatrix(const KRMat4 &modelMatrix)
|
void KRAudioManager::setListenerOrientationFromModelMatrix(const KRMat4 &modelMatrix)
|
||||||
@@ -1330,11 +1260,6 @@ void KRAudioManager::setListenerOrientation(const KRVector3 &position, const KRV
|
|||||||
m_listener_up = up;
|
m_listener_up = up;
|
||||||
|
|
||||||
makeCurrentContext();
|
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)
|
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)
|
void KRAudioManager::activateAudioSource(KRAudioSource *audioSource)
|
||||||
{
|
{
|
||||||
m_activeAudioSources.insert(audioSource);
|
m_activeAudioSources.insert(audioSource);
|
||||||
@@ -1685,10 +1577,10 @@ void KRAudioManager::renderAmbient()
|
|||||||
|
|
||||||
void KRAudioManager::renderHRTF()
|
void KRAudioManager::renderHRTF()
|
||||||
{
|
{
|
||||||
DSPSplitComplex *hrtf_accum = m_workspace + 0;
|
SplitComplex *hrtf_accum = m_workspace + 0;
|
||||||
DSPSplitComplex *hrtf_impulse = m_workspace + 1;
|
SplitComplex *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
|
SplitComplex *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_sample = m_workspace + 2;
|
||||||
|
|
||||||
int impulse_response_channels = 2;
|
int impulse_response_channels = 2;
|
||||||
int hrtf_frames = 128;
|
int hrtf_frames = 128;
|
||||||
@@ -1749,11 +1641,11 @@ void KRAudioManager::renderHRTF()
|
|||||||
memset(hrtf_sample->realp + hrtf_frames, 0, sizeof(float) * hrtf_frames);
|
memset(hrtf_sample->realp + hrtf_frames, 0, sizeof(float) * hrtf_frames);
|
||||||
memset(hrtf_sample->imagp, 0, sizeof(float) * fft_size);
|
memset(hrtf_sample->imagp, 0, sizeof(float) * fft_size);
|
||||||
|
|
||||||
DSPSplitComplex hrtf_spectral;
|
SplitComplex hrtf_spectral;
|
||||||
|
|
||||||
if(m_high_quality_hrtf) {
|
if(m_high_quality_hrtf) {
|
||||||
// High quality, interpolated HRTF
|
// High quality, interpolated HRTF
|
||||||
hrtf_spectral= *hrtf_accum;
|
hrtf_spectral = *hrtf_accum;
|
||||||
|
|
||||||
float mix[4];
|
float mix[4];
|
||||||
KRVector2 dir[4];
|
KRVector2 dir[4];
|
||||||
@@ -1766,7 +1658,7 @@ void KRAudioManager::renderHRTF()
|
|||||||
|
|
||||||
for(int i=0; i < 1 /*4 */; i++) {
|
for(int i=0; i < 1 /*4 */; i++) {
|
||||||
if(mix[i] > 0.0f) {
|
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.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_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);
|
vDSP_zvadd(hrtf_impulse, 1, hrtf_accum, 1, hrtf_accum, 1, fft_size);
|
||||||
|
|||||||
@@ -127,14 +127,6 @@ public:
|
|||||||
KRDataBlock *getBufferData(int size);
|
KRDataBlock *getBufferData(int size);
|
||||||
void recycleBufferData(KRDataBlock *data);
|
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 activateAudioSource(KRAudioSource *audioSource);
|
||||||
void deactivateAudioSource(KRAudioSource *audioSource);
|
void deactivateAudioSource(KRAudioSource *audioSource);
|
||||||
|
|
||||||
@@ -189,27 +181,32 @@ private:
|
|||||||
std::set<KRAudioSample *> m_openAudioSamples;
|
std::set<KRAudioSample *> m_openAudioSamples;
|
||||||
|
|
||||||
void initAudio();
|
void initAudio();
|
||||||
void initOpenAL();
|
|
||||||
void initSiren();
|
|
||||||
void initHRTF();
|
void initHRTF();
|
||||||
|
|
||||||
void cleanupAudio();
|
void cleanupAudio();
|
||||||
void cleanupOpenAL();
|
|
||||||
void cleanupSiren();
|
bool m_initialized;
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
audio_engine_t m_audio_engine;
|
// Apple Core Audio
|
||||||
|
|
||||||
// OpenAL Handles
|
|
||||||
ALCcontext* m_alContext;
|
|
||||||
ALCdevice* m_alDevice;
|
|
||||||
|
|
||||||
// Siren Handles
|
|
||||||
AUGraph m_auGraph;
|
AUGraph m_auGraph;
|
||||||
AudioUnit m_auMixer;
|
AudioUnit m_auMixer;
|
||||||
|
|
||||||
static OSStatus renderInput(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData);
|
static OSStatus renderInput(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData);
|
||||||
void renderAudio(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
|
__int64_t m_audio_frame; // Number of audio frames processed since the start of the application
|
||||||
|
|
||||||
float *m_reverb_input_samples; // Circular-buffered reverb input, single channel
|
float *m_reverb_input_samples; // Circular-buffered reverb input, single channel
|
||||||
@@ -223,11 +220,8 @@ private:
|
|||||||
int m_output_accumulation_block_start;
|
int m_output_accumulation_block_start;
|
||||||
int m_output_sample;
|
int m_output_sample;
|
||||||
|
|
||||||
FFTSetup m_fft_setup[KRENGINE_REVERB_MAX_FFT_LOG2 - KRENGINE_AUDIO_BLOCK_LOG2N + 1];
|
|
||||||
float *m_workspace_data;
|
float *m_workspace_data;
|
||||||
DSPSplitComplex m_workspace[3];
|
SplitComplex m_workspace[3];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
float *getBlockAddress(int block_offset);
|
float *getBlockAddress(int block_offset);
|
||||||
void renderBlock();
|
void renderBlock();
|
||||||
@@ -240,12 +234,12 @@ private:
|
|||||||
|
|
||||||
std::vector<KRVector2> m_hrtf_sample_locations;
|
std::vector<KRVector2> m_hrtf_sample_locations;
|
||||||
float *m_hrtf_data;
|
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);
|
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);
|
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);
|
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;
|
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
|
float m_reverb_zone_total_weight = 0.0f; // For normalizing zone weights
|
||||||
|
|
||||||
boost::signals2::mutex m_mutex;
|
boost::signals2::mutex m_mutex;
|
||||||
|
#ifdef __APPLE__
|
||||||
mach_timebase_info_data_t m_timebase_info;
|
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;
|
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 "KRDataBlock.h"
|
||||||
#include "KRAudioBuffer.h"
|
#include "KRAudioBuffer.h"
|
||||||
#include "KRContext.h"
|
#include "KRContext.h"
|
||||||
|
#ifdef __APPLE__
|
||||||
#include <Accelerate/Accelerate.h>
|
#include <Accelerate/Accelerate.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
KRAudioSample::KRAudioSample(KRContext &context, std::string name, std::string extension) : KRResource(context, name)
|
KRAudioSample::KRAudioSample(KRContext &context, std::string name, std::string extension) : KRResource(context, name)
|
||||||
{
|
{
|
||||||
m_pData = new KRDataBlock();
|
m_pData = new KRDataBlock();
|
||||||
m_extension = extension;
|
m_extension = extension;
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// Apple Audio Toolbox
|
||||||
m_audio_file_id = 0;
|
m_audio_file_id = 0;
|
||||||
m_fileRef = NULL;
|
m_fileRef = NULL;
|
||||||
|
#endif
|
||||||
m_totalFrames = 0;
|
m_totalFrames = 0;
|
||||||
m_bytesPerFrame = 0;
|
m_bytesPerFrame = 0;
|
||||||
m_frameRate = 0;
|
m_frameRate = 0;
|
||||||
@@ -57,8 +61,11 @@ KRAudioSample::KRAudioSample(KRContext &context, std::string name, std::string e
|
|||||||
m_pData = data;
|
m_pData = data;
|
||||||
m_extension = extension;
|
m_extension = extension;
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// Apple Audio Toolbox
|
||||||
m_audio_file_id = 0;
|
m_audio_file_id = 0;
|
||||||
m_fileRef = NULL;
|
m_fileRef = NULL;
|
||||||
|
#endif
|
||||||
m_totalFrames = 0;
|
m_totalFrames = 0;
|
||||||
m_bytesPerFrame = 0;
|
m_bytesPerFrame = 0;
|
||||||
m_frameRate = 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
|
OSStatus KRAudioSample::ReadProc( // AudioFile_ReadProc
|
||||||
void * inClientData,
|
void * inClientData,
|
||||||
SInt64 inPosition,
|
SInt64 inPosition,
|
||||||
@@ -231,10 +240,13 @@ OSStatus KRAudioSample::WriteProc( // AudioFile_WriteProc
|
|||||||
{
|
{
|
||||||
return -1; // Writing not supported
|
return -1; // Writing not supported
|
||||||
}
|
}
|
||||||
|
#endif // Apple Audio Toolbox
|
||||||
|
|
||||||
void KRAudioSample::openFile()
|
void KRAudioSample::openFile()
|
||||||
{
|
{
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// Apple Audio Toolbox
|
||||||
|
|
||||||
// AudioFileInitializeWithCallbacks
|
// AudioFileInitializeWithCallbacks
|
||||||
if(m_fileRef == NULL) {
|
if(m_fileRef == NULL) {
|
||||||
|
|
||||||
@@ -279,15 +291,19 @@ void KRAudioSample::openFile()
|
|||||||
int maxFramesPerBuffer = KRENGINE_AUDIO_MAX_BUFFER_SIZE / m_bytesPerFrame;
|
int maxFramesPerBuffer = KRENGINE_AUDIO_MAX_BUFFER_SIZE / m_bytesPerFrame;
|
||||||
m_bufferCount = (m_totalFrames+maxFramesPerBuffer-1)/maxFramesPerBuffer; // CEIL(_totalFrames / maxFramesPerBuffer)
|
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;
|
m_channelsPerFrame = outputFormat.mChannelsPerFrame;
|
||||||
|
|
||||||
getContext().getAudioManager()->_registerOpenAudioSample(this);
|
getContext().getAudioManager()->_registerOpenAudioSample(this);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#pragma message ( "TODO - implement for Windows" )
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRAudioSample::closeFile()
|
void KRAudioSample::closeFile()
|
||||||
{
|
{
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// Apple Audio Toolbox
|
||||||
if(m_fileRef) {
|
if(m_fileRef) {
|
||||||
ExtAudioFileDispose(m_fileRef);
|
ExtAudioFileDispose(m_fileRef);
|
||||||
m_fileRef = NULL;
|
m_fileRef = NULL;
|
||||||
@@ -297,6 +313,7 @@ void KRAudioSample::closeFile()
|
|||||||
AudioFileClose(m_audio_file_id);
|
AudioFileClose(m_audio_file_id);
|
||||||
m_audio_file_id = 0;
|
m_audio_file_id = 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
getContext().getAudioManager()->_registerCloseAudioSample(this);
|
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 maxFramesPerBuffer = KRENGINE_AUDIO_MAX_BUFFER_SIZE / sound->m_bytesPerFrame;
|
||||||
int startFrame = index * maxFramesPerBuffer;
|
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;
|
AudioBufferList outputBufferInfo;
|
||||||
outputBufferInfo.mNumberBuffers = 1;
|
outputBufferInfo.mNumberBuffers = 1;
|
||||||
outputBufferInfo.mBuffers[0].mDataByteSize = frameCount * sound->m_bytesPerFrame;
|
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
|
// Read the data into an AudioBufferList
|
||||||
ExtAudioFileSeek(sound->m_fileRef, startFrame);
|
ExtAudioFileSeek(sound->m_fileRef, startFrame);
|
||||||
ExtAudioFileRead(sound->m_fileRef, (UInt32*)&frameCount, &outputBufferInfo);
|
ExtAudioFileRead(sound->m_fileRef, (UInt32*)&frameCount, &outputBufferInfo);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
KRAudioBuffer *KRAudioSample::getBuffer(int index)
|
KRAudioBuffer *KRAudioSample::getBuffer(int index)
|
||||||
@@ -356,9 +375,9 @@ KRAudioBuffer *KRAudioSample::getBuffer(int index)
|
|||||||
|
|
||||||
int maxFramesPerBuffer = KRENGINE_AUDIO_MAX_BUFFER_SIZE / m_bytesPerFrame;
|
int maxFramesPerBuffer = KRENGINE_AUDIO_MAX_BUFFER_SIZE / m_bytesPerFrame;
|
||||||
int startFrame = index * maxFramesPerBuffer;
|
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) {
|
if(m_bufferCount == 1) {
|
||||||
// [self closeFile]; // We don't need to hold on to a file handle if not streaming
|
// [self closeFile]; // We don't need to hold on to a file handle if not streaming
|
||||||
|
|||||||
@@ -67,45 +67,46 @@ private:
|
|||||||
|
|
||||||
std::string m_extension;
|
std::string m_extension;
|
||||||
KRDataBlock *m_pData;
|
KRDataBlock *m_pData;
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// Apple Audio Toolbox
|
||||||
AudioFileID m_audio_file_id;
|
AudioFileID m_audio_file_id;
|
||||||
ExtAudioFileRef m_fileRef;
|
ExtAudioFileRef m_fileRef;
|
||||||
|
|
||||||
|
static OSStatus ReadProc( // AudioFile_ReadProc
|
||||||
|
void * inClientData,
|
||||||
|
SInt64 inPosition,
|
||||||
|
UInt32 requestCount,
|
||||||
|
void * buffer,
|
||||||
|
UInt32 * actualCount);
|
||||||
|
|
||||||
|
static OSStatus WriteProc( // AudioFile_WriteProc
|
||||||
|
void * inClientData,
|
||||||
|
SInt64 inPosition,
|
||||||
|
UInt32 requestCount,
|
||||||
|
const void *buffer,
|
||||||
|
UInt32 * actualCount);
|
||||||
|
|
||||||
|
static SInt64 GetSizeProc( // AudioFile_GetSizeProc
|
||||||
|
void * inClientData);
|
||||||
|
|
||||||
|
|
||||||
|
static OSStatus SetSizeProc( // AudioFile_SetSizeProc
|
||||||
|
void * inClientData,
|
||||||
|
SInt64 inSize);
|
||||||
|
#endif
|
||||||
|
|
||||||
int m_bufferCount;
|
int m_bufferCount;
|
||||||
|
|
||||||
SInt64 m_totalFrames;
|
__int64_t m_totalFrames;
|
||||||
int m_frameRate;
|
int m_frameRate;
|
||||||
int m_bytesPerFrame;
|
int m_bytesPerFrame;
|
||||||
int m_channelsPerFrame;
|
int m_channelsPerFrame;
|
||||||
ALenum m_dataFormat;
|
|
||||||
|
|
||||||
void openFile();
|
void openFile();
|
||||||
void closeFile();
|
void closeFile();
|
||||||
void loadInfo();
|
void loadInfo();
|
||||||
|
|
||||||
static OSStatus ReadProc( // AudioFile_ReadProc
|
|
||||||
void * inClientData,
|
|
||||||
SInt64 inPosition,
|
|
||||||
UInt32 requestCount,
|
|
||||||
void * buffer,
|
|
||||||
UInt32 * actualCount);
|
|
||||||
|
|
||||||
static OSStatus WriteProc( // AudioFile_WriteProc
|
|
||||||
void * inClientData,
|
|
||||||
SInt64 inPosition,
|
|
||||||
UInt32 requestCount,
|
|
||||||
const void *buffer,
|
|
||||||
UInt32 * actualCount);
|
|
||||||
|
|
||||||
static SInt64 GetSizeProc( // AudioFile_GetSizeProc
|
|
||||||
void * inClientData);
|
|
||||||
|
|
||||||
|
|
||||||
static OSStatus SetSizeProc( // AudioFile_SetSizeProc
|
|
||||||
void * inClientData,
|
|
||||||
SInt64 inSize);
|
|
||||||
|
|
||||||
|
|
||||||
static void PopulateBuffer(KRAudioSample *sound, int index, void *data);
|
static void PopulateBuffer(KRAudioSample *sound, int index, void *data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,6 @@
|
|||||||
#include "KRAudioSample.h"
|
#include "KRAudioSample.h"
|
||||||
#include "KRAudioBuffer.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)
|
KRAudioSource::KRAudioSource(KRScene &scene, std::string name) : KRNode(scene, name)
|
||||||
{
|
{
|
||||||
m_currentBufferFrame = 0;
|
m_currentBufferFrame = 0;
|
||||||
@@ -44,7 +42,6 @@ KRAudioSource::KRAudioSource(KRScene &scene, std::string name) : KRNode(scene, n
|
|||||||
m_is3d = true;
|
m_is3d = true;
|
||||||
m_isPrimed = false;
|
m_isPrimed = false;
|
||||||
m_audioFile = NULL;
|
m_audioFile = NULL;
|
||||||
m_sourceID = 0;
|
|
||||||
m_gain = 1.0f;
|
m_gain = 1.0f;
|
||||||
m_pitch = 1.0f;
|
m_pitch = 1.0f;
|
||||||
m_looping = false;
|
m_looping = false;
|
||||||
@@ -61,11 +58,6 @@ KRAudioSource::KRAudioSource(KRScene &scene, std::string name) : KRNode(scene, n
|
|||||||
|
|
||||||
KRAudioSource::~KRAudioSource()
|
KRAudioSource::~KRAudioSource()
|
||||||
{
|
{
|
||||||
if(m_sourceID) {
|
|
||||||
getContext().getAudioManager()->makeCurrentContext();
|
|
||||||
ALDEBUG(alDeleteSources(1, &m_sourceID));
|
|
||||||
m_sourceID = 0;
|
|
||||||
}
|
|
||||||
while(m_audioBuffers.size()) {
|
while(m_audioBuffers.size()) {
|
||||||
delete m_audioBuffers.front();
|
delete m_audioBuffers.front();
|
||||||
m_audioBuffers.pop();
|
m_audioBuffers.pop();
|
||||||
@@ -164,20 +156,6 @@ void KRAudioSource::prime()
|
|||||||
queueBuffer();
|
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;
|
m_isPrimed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -187,13 +165,6 @@ void KRAudioSource::queueBuffer()
|
|||||||
{
|
{
|
||||||
KRAudioBuffer *buffer = m_audioFile->getBuffer(m_nextBufferIndex);
|
KRAudioBuffer *buffer = m_audioFile->getBuffer(m_nextBufferIndex);
|
||||||
m_audioBuffers.push(buffer);
|
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();
|
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)
|
void KRAudioSource::setGain(float gain)
|
||||||
{
|
{
|
||||||
m_gain = 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()
|
float KRAudioSource::getGain()
|
||||||
@@ -258,12 +223,6 @@ float KRAudioSource::getGain()
|
|||||||
void KRAudioSource::setPitch(float pitch)
|
void KRAudioSource::setPitch(float pitch)
|
||||||
{
|
{
|
||||||
m_pitch = 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)
|
void KRAudioSource::setReferenceDistance(float reference_distance)
|
||||||
{
|
{
|
||||||
m_referenceDistance = 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()
|
float KRAudioSource::getReverb()
|
||||||
@@ -290,15 +243,8 @@ float KRAudioSource::getReverb()
|
|||||||
void KRAudioSource::setReverb(float reverb)
|
void KRAudioSource::setReverb(float reverb)
|
||||||
{
|
{
|
||||||
m_reverb = 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()
|
float KRAudioSource::getRolloffFactor()
|
||||||
{
|
{
|
||||||
return m_rolloffFactor;
|
return m_rolloffFactor;
|
||||||
@@ -307,12 +253,6 @@ float KRAudioSource::getRolloffFactor()
|
|||||||
void KRAudioSource::setRolloffFactor(float rolloff_factor)
|
void KRAudioSource::setRolloffFactor(float rolloff_factor)
|
||||||
{
|
{
|
||||||
m_rolloffFactor = 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)
|
void KRAudioSource::setLooping(bool looping)
|
||||||
@@ -357,15 +297,6 @@ void KRAudioSource::setIs3D(bool is3D)
|
|||||||
m_is3d = 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()
|
void KRAudioSource::advanceBuffer()
|
||||||
{
|
{
|
||||||
if(m_audioBuffers.size()) {
|
if(m_audioBuffers.size()) {
|
||||||
@@ -381,25 +312,6 @@ void KRAudioSource::physicsUpdate(float deltaTime)
|
|||||||
|
|
||||||
KRAudioManager *audioManager = getContext().getAudioManager();
|
KRAudioManager *audioManager = getContext().getAudioManager();
|
||||||
audioManager->activateAudioSource(this);
|
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()
|
void KRAudioSource::play()
|
||||||
@@ -414,23 +326,6 @@ void KRAudioSource::play()
|
|||||||
m_start_audio_frame = audioManager->getAudioFrame() - m_paused_audio_frame;
|
m_start_audio_frame = audioManager->getAudioFrame() - m_paused_audio_frame;
|
||||||
m_paused_audio_frame = -1;
|
m_paused_audio_frame = -1;
|
||||||
audioManager->activateAudioSource(this);
|
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;
|
m_playing = true;
|
||||||
}
|
}
|
||||||
@@ -474,24 +369,6 @@ KRAudioSample *KRAudioSource::getAudioSample()
|
|||||||
return m_audioFile;
|
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)
|
void KRAudioSource::advanceFrames(int frame_count)
|
||||||
{
|
{
|
||||||
m_currentBufferFrame += 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);
|
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 std::string getElementName();
|
||||||
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
||||||
virtual void loadXML(tinyxml2::XMLElement *e);
|
virtual void loadXML(tinyxml2::XMLElement *e);
|
||||||
virtual bool hasPhysics();
|
|
||||||
virtual void physicsUpdate(float deltaTime);
|
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);
|
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;
|
float m_rolloffFactor;
|
||||||
bool m_enable_occlusion;
|
bool m_enable_occlusion;
|
||||||
bool m_enable_obstruction;
|
bool m_enable_obstruction;
|
||||||
|
|
||||||
void updatePosition();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(KRAUDIOSOURCE_H) */
|
#endif /* defined(KRAUDIOSOURCE_H) */
|
||||||
|
|||||||
@@ -13,6 +13,10 @@
|
|||||||
#include "KRAudioManager.h"
|
#include "KRAudioManager.h"
|
||||||
#include "KRAudioSample.h"
|
#include "KRAudioSample.h"
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
int KRContext::KRENGINE_MAX_SHADER_HANDLES;
|
int KRContext::KRENGINE_MAX_SHADER_HANDLES;
|
||||||
int KRContext::KRENGINE_GPU_MEM_MAX;
|
int KRContext::KRENGINE_GPU_MEM_MAX;
|
||||||
int KRContext::KRENGINE_GPU_MEM_TARGET;
|
int KRContext::KRENGINE_GPU_MEM_TARGET;
|
||||||
@@ -44,7 +48,9 @@ void *KRContext::s_log_callback_user_data = NULL;
|
|||||||
KRContext::KRContext() : m_streamer(*this)
|
KRContext::KRContext() : m_streamer(*this)
|
||||||
{
|
{
|
||||||
m_streamingEnabled = false;
|
m_streamingEnabled = false;
|
||||||
|
#ifdef __APPLE__
|
||||||
mach_timebase_info(&m_timebase_info);
|
mach_timebase_info(&m_timebase_info);
|
||||||
|
#endif
|
||||||
|
|
||||||
m_bDetectedExtensions = false;
|
m_bDetectedExtensions = false;
|
||||||
m_current_frame = 0;
|
m_current_frame = 0;
|
||||||
@@ -317,7 +323,11 @@ float KRContext::getAbsoluteTime() const
|
|||||||
|
|
||||||
long KRContext::getAbsoluteTimeMilliseconds()
|
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
|
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()
|
bool KRContext::getStreamingEnabled()
|
||||||
|
|||||||
@@ -36,9 +36,11 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
int KRAKEN_MEM_PAGE_SIZE = getpagesize();
|
int KRAKEN_MEM_PAGE_SIZE = getpagesize();
|
||||||
#define KRAKEN_MEM_ROUND_DOWN_PAGE(x) ((x) & ~(KRAKEN_MEM_PAGE_SIZE - 1))
|
#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)
|
#define KRAKEN_MEM_ROUND_UP_PAGE(x) ((((x) - 1) & ~(KRAKEN_MEM_PAGE_SIZE - 1)) + KRAKEN_MEM_PAGE_SIZE)
|
||||||
|
#endif
|
||||||
|
|
||||||
int m_mapCount = 0;
|
int m_mapCount = 0;
|
||||||
size_t m_mapSize = 0;
|
size_t m_mapSize = 0;
|
||||||
|
|||||||
@@ -449,9 +449,9 @@ KRDataBlock &KRMeshManager::getRandomParticles()
|
|||||||
|
|
||||||
int iVertex=0;
|
int iVertex=0;
|
||||||
for(int iParticle=0; iParticle < KRENGINE_MAX_RANDOM_PARTICLES; iParticle++) {
|
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.x = (float)(rand() % 2000) / 1000.0f - 1000.0f;
|
||||||
vertex_data[iVertex].vertex.y = (float)(arc4random() % 2000) / 1000.0f - 1000.0f;
|
vertex_data[iVertex].vertex.y = (float)(rand() % 2000) / 1000.0f - 1000.0f;
|
||||||
vertex_data[iVertex].vertex.z = (float)(arc4random() % 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.u = -0.5f;
|
||||||
vertex_data[iVertex].uva.v = -inscribed_circle_radius;
|
vertex_data[iVertex].uva.v = -inscribed_circle_radius;
|
||||||
iVertex++;
|
iVertex++;
|
||||||
|
|||||||
Reference in New Issue
Block a user