Siren audio engine in progress
This commit is contained in:
@@ -76,6 +76,8 @@
|
|||||||
E44F38251683B23000399B5D /* KRRenderSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = E44F38231683B22C00399B5D /* KRRenderSettings.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
E44F38251683B23000399B5D /* KRRenderSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = E44F38231683B22C00399B5D /* KRRenderSettings.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
E44F38281683B24800399B5D /* KRRenderSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E44F38271683B24400399B5D /* KRRenderSettings.cpp */; };
|
E44F38281683B24800399B5D /* KRRenderSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E44F38271683B24400399B5D /* KRRenderSettings.cpp */; };
|
||||||
E44F38291683B24800399B5D /* KRRenderSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E44F38271683B24400399B5D /* KRRenderSettings.cpp */; };
|
E44F38291683B24800399B5D /* KRRenderSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E44F38271683B24400399B5D /* KRRenderSettings.cpp */; };
|
||||||
|
E459040416C30CC5002B00A0 /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E459040316C30CC5002B00A0 /* AudioUnit.framework */; };
|
||||||
|
E459040616C30CD9002B00A0 /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E459040516C30CD9002B00A0 /* AudioUnit.framework */; };
|
||||||
E460292616681CFF00261BB9 /* KRTextureAnimated.h in Headers */ = {isa = PBXBuildFile; fileRef = E460292516681CFE00261BB9 /* KRTextureAnimated.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
E460292616681CFF00261BB9 /* KRTextureAnimated.h in Headers */ = {isa = PBXBuildFile; fileRef = E460292516681CFE00261BB9 /* KRTextureAnimated.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
E460292816681D1000261BB9 /* KRTextureAnimated.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E460292716681D1000261BB9 /* KRTextureAnimated.cpp */; };
|
E460292816681D1000261BB9 /* KRTextureAnimated.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E460292716681D1000261BB9 /* KRTextureAnimated.cpp */; };
|
||||||
E460292B16682BF700261BB9 /* libfbxsdk-2013.3-static.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E460292916682BD900261BB9 /* libfbxsdk-2013.3-static.a */; };
|
E460292B16682BF700261BB9 /* libfbxsdk-2013.3-static.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E460292916682BD900261BB9 /* libfbxsdk-2013.3-static.a */; };
|
||||||
@@ -396,6 +398,8 @@
|
|||||||
E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRContextObject.h; sourceTree = "<group>"; };
|
E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRContextObject.h; sourceTree = "<group>"; };
|
||||||
E44F38231683B22C00399B5D /* KRRenderSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRRenderSettings.h; sourceTree = "<group>"; };
|
E44F38231683B22C00399B5D /* KRRenderSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRRenderSettings.h; sourceTree = "<group>"; };
|
||||||
E44F38271683B24400399B5D /* KRRenderSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRRenderSettings.cpp; sourceTree = "<group>"; };
|
E44F38271683B24400399B5D /* KRRenderSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRRenderSettings.cpp; sourceTree = "<group>"; };
|
||||||
|
E459040316C30CC5002B00A0 /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/AudioUnit.framework; sourceTree = DEVELOPER_DIR; };
|
||||||
|
E459040516C30CD9002B00A0 /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = System/Library/Frameworks/AudioUnit.framework; sourceTree = SDKROOT; };
|
||||||
E460292516681CFE00261BB9 /* KRTextureAnimated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRTextureAnimated.h; sourceTree = "<group>"; };
|
E460292516681CFE00261BB9 /* KRTextureAnimated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRTextureAnimated.h; sourceTree = "<group>"; };
|
||||||
E460292716681D1000261BB9 /* KRTextureAnimated.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRTextureAnimated.cpp; sourceTree = "<group>"; };
|
E460292716681D1000261BB9 /* KRTextureAnimated.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRTextureAnimated.cpp; sourceTree = "<group>"; };
|
||||||
E460292916682BD900261BB9 /* libfbxsdk-2013.3-static.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libfbxsdk-2013.3-static.a"; path = "lib/gcc4/ub/libfbxsdk-2013.3-static.a"; sourceTree = FBXSDK; };
|
E460292916682BD900261BB9 /* libfbxsdk-2013.3-static.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libfbxsdk-2013.3-static.a"; path = "lib/gcc4/ub/libfbxsdk-2013.3-static.a"; sourceTree = FBXSDK; };
|
||||||
@@ -584,6 +588,7 @@
|
|||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
E459040616C30CD9002B00A0 /* AudioUnit.framework in Frameworks */,
|
||||||
E41B6BA816BE436100B510EB /* CoreAudio.framework in Frameworks */,
|
E41B6BA816BE436100B510EB /* CoreAudio.framework in Frameworks */,
|
||||||
E4F027FA1698116000D4427D /* AudioToolbox.framework in Frameworks */,
|
E4F027FA1698116000D4427D /* AudioToolbox.framework in Frameworks */,
|
||||||
E4F027D31697A01300D4427D /* OpenAL.framework in Frameworks */,
|
E4F027D31697A01300D4427D /* OpenAL.framework in Frameworks */,
|
||||||
@@ -597,6 +602,7 @@
|
|||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
E459040416C30CC5002B00A0 /* AudioUnit.framework in Frameworks */,
|
||||||
E41B6BAA16BE437800B510EB /* CoreAudio.framework in Frameworks */,
|
E41B6BAA16BE437800B510EB /* CoreAudio.framework in Frameworks */,
|
||||||
E4F027F71698115600D4427D /* AudioToolbox.framework in Frameworks */,
|
E4F027F71698115600D4427D /* AudioToolbox.framework in Frameworks */,
|
||||||
E4F027D51697A02D00D4427D /* OpenAL.framework in Frameworks */,
|
E4F027D51697A02D00D4427D /* OpenAL.framework in Frameworks */,
|
||||||
@@ -999,6 +1005,7 @@
|
|||||||
E4BBBB931512A41500F43B5B /* Frameworks */ = {
|
E4BBBB931512A41500F43B5B /* Frameworks */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
E459040316C30CC5002B00A0 /* AudioUnit.framework */,
|
||||||
E41B6BA916BE437800B510EB /* CoreAudio.framework */,
|
E41B6BA916BE437800B510EB /* CoreAudio.framework */,
|
||||||
10CC33A3168530A300BB9846 /* libPVRTexLib.a */,
|
10CC33A3168530A300BB9846 /* libPVRTexLib.a */,
|
||||||
E460292916682BD900261BB9 /* libfbxsdk-2013.3-static.a */,
|
E460292916682BD900261BB9 /* libfbxsdk-2013.3-static.a */,
|
||||||
@@ -1087,6 +1094,7 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
E4F027F91698116000D4427D /* AudioToolbox.framework */,
|
E4F027F91698116000D4427D /* AudioToolbox.framework */,
|
||||||
|
E459040516C30CD9002B00A0 /* AudioUnit.framework */,
|
||||||
E41B6BA716BE436100B510EB /* CoreAudio.framework */,
|
E41B6BA716BE436100B510EB /* CoreAudio.framework */,
|
||||||
E491016413C99B9E0098455B /* Foundation.framework */,
|
E491016413C99B9E0098455B /* Foundation.framework */,
|
||||||
E4F027D21697A01300D4427D /* OpenAL.framework */,
|
E4F027D21697A01300D4427D /* OpenAL.framework */,
|
||||||
|
|||||||
@@ -24,10 +24,11 @@ KRAudioBuffer::KRAudioBuffer(KRAudioManager *manager, KRAudioSample *sound, int
|
|||||||
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(alGenBuffers(1, &m_bufferID));
|
||||||
ALDEBUG(alBufferData(m_bufferID, m_dataFormat, m_pData->getStart(), m_frameCount * m_bytesPerFrame, m_frameRate));
|
ALDEBUG(alBufferData(m_bufferID, m_dataFormat, m_pData->getStart(), m_frameCount * m_bytesPerFrame, m_frameRate));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
KRAudioBuffer::~KRAudioBuffer()
|
KRAudioBuffer::~KRAudioBuffer()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,12 +38,282 @@ ALvoid alcMacOSXRenderingQualityProc(const ALint value);
|
|||||||
|
|
||||||
KRAudioManager::KRAudioManager(KRContext &context) : KRContextObject(context)
|
KRAudioManager::KRAudioManager(KRContext &context) : KRContextObject(context)
|
||||||
{
|
{
|
||||||
|
m_audio_engine = KRAKEN_AUDIO_OPENAL;
|
||||||
|
|
||||||
|
// OpenAL
|
||||||
m_alDevice = 0;
|
m_alDevice = 0;
|
||||||
m_alContext = 0;
|
m_alContext = 0;
|
||||||
|
|
||||||
|
// Siren
|
||||||
|
m_auGraph = NULL;
|
||||||
|
m_auMixer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRAudioManager::initAudio()
|
void KRAudioManager::initAudio()
|
||||||
|
{
|
||||||
|
switch(m_audio_engine) {
|
||||||
|
case KRAKEN_AUDIO_OPENAL:
|
||||||
|
initOpenAL();
|
||||||
|
break;
|
||||||
|
case KRAKEN_AUDIO_SIREN:
|
||||||
|
initSiren();
|
||||||
|
break;
|
||||||
|
case KRAKEN_AUDIO_NONE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// audio render procedure, don't allocate memory, don't take any locks, don't waste time
|
||||||
|
static OSStatus renderInput(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
|
||||||
|
{
|
||||||
|
static float phase;
|
||||||
|
static float pan_phase;
|
||||||
|
// Get a reference to the object that was passed with the callback
|
||||||
|
// In this case, the AudioController passed itself so
|
||||||
|
// that you can access its data.
|
||||||
|
KRAudioManager *THIS = (KRAudioManager*)inRefCon;
|
||||||
|
|
||||||
|
// Get a pointer to the dataBuffer of the AudioBufferList
|
||||||
|
|
||||||
|
AudioUnitSampleType *outA = (AudioUnitSampleType *)ioData->mBuffers[0].mData;
|
||||||
|
AudioUnitSampleType *outB = (AudioUnitSampleType *)ioData->mBuffers[1].mData; // Non-Interleaved only
|
||||||
|
|
||||||
|
// Calculations to produce a 600 Hz sinewave
|
||||||
|
// A constant frequency value, you can pass in a reference vary this.
|
||||||
|
float freq = 300;
|
||||||
|
// The amount the phase changes in single sample
|
||||||
|
double phaseIncrement = M_PI * freq / 44100.0;
|
||||||
|
// Pass in a reference to the phase value, you have to keep track of this
|
||||||
|
// so that the sin resumes right where the last call left off
|
||||||
|
|
||||||
|
// Loop through the callback buffer, generating samples
|
||||||
|
for (UInt32 i = 0; i < inNumberFrames; ++i) {
|
||||||
|
|
||||||
|
// calculate the next sample
|
||||||
|
float sinSignal = sin(phase);
|
||||||
|
// Put the sample into the buffer
|
||||||
|
// Scale the -1 to 1 values float to
|
||||||
|
// -32767 to 32767 and then cast to an integer
|
||||||
|
float left_channel = sinSignal * (sin(pan_phase) * 0.5f + 0.5f);
|
||||||
|
float right_channel = sinSignal * (-sin(pan_phase) * 0.5f + 0.5f);
|
||||||
|
#if CA_PREFER_FIXED_POINT
|
||||||
|
// Interleaved
|
||||||
|
// outA[i*2] = (SInt16)(left_channel * 32767.0f);
|
||||||
|
// outA[i*2 + 1] = (SInt16)(right_channel * 32767.0f);
|
||||||
|
|
||||||
|
// Non-Interleaved
|
||||||
|
outA[i] = (SInt32)(left_channel * 0x1000000f);
|
||||||
|
outB[i] = (SInt32)(right_channel * 0x1000000f);
|
||||||
|
#else
|
||||||
|
|
||||||
|
// Interleaved
|
||||||
|
// outA[i*2] = (Float32)left_channel;
|
||||||
|
// outA[i*2 + 1] = (Float32)right_channel;
|
||||||
|
|
||||||
|
// Non-Interleaved
|
||||||
|
outA[i] = (Float32)left_channel;
|
||||||
|
outB[i] = (Float32)right_channel;
|
||||||
|
#endif
|
||||||
|
// calculate the phase for the next sample
|
||||||
|
phase = phase + phaseIncrement;
|
||||||
|
pan_phase = pan_phase + 1 / 44100.0 * M_PI;
|
||||||
|
}
|
||||||
|
// Reset the phase value to prevent the float from overflowing
|
||||||
|
if (phase >= M_PI * freq) {
|
||||||
|
phase = phase - M_PI * freq;
|
||||||
|
}
|
||||||
|
|
||||||
|
return noErr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void KRSetAUCanonical(AudioStreamBasicDescription &desc, UInt32 nChannels, bool interleaved)
|
||||||
|
{
|
||||||
|
desc.mFormatID = kAudioFormatLinearPCM;
|
||||||
|
#if CA_PREFER_FIXED_POINT
|
||||||
|
desc.mFormatFlags = kAudioFormatFlagsCanonical | (kAudioUnitSampleFractionBits << kLinearPCMFormatFlagsSampleFractionShift);
|
||||||
|
#else
|
||||||
|
desc.mFormatFlags = kAudioFormatFlagsCanonical;
|
||||||
|
#endif
|
||||||
|
desc.mChannelsPerFrame = nChannels;
|
||||||
|
desc.mFramesPerPacket = 1;
|
||||||
|
desc.mBitsPerChannel = 8 * sizeof(AudioUnitSampleType);
|
||||||
|
if (interleaved)
|
||||||
|
desc.mBytesPerPacket = desc.mBytesPerFrame = nChannels * sizeof(AudioUnitSampleType);
|
||||||
|
else {
|
||||||
|
desc.mBytesPerPacket = desc.mBytesPerFrame = sizeof(AudioUnitSampleType);
|
||||||
|
desc.mFormatFlags |= kAudioFormatFlagIsNonInterleaved;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
desc.mSampleRate = 44100.0; // set sample rate
|
||||||
|
desc.mFormatID = kAudioFormatLinearPCM;
|
||||||
|
desc.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
|
||||||
|
desc.mBitsPerChannel = sizeof(AudioSampleType) * 8; // AudioSampleType == 16 bit signed ints
|
||||||
|
desc.mChannelsPerFrame = 2;
|
||||||
|
desc.mFramesPerPacket = 1;
|
||||||
|
desc.mBytesPerFrame = (desc.mBitsPerChannel / 8) * desc.mChannelsPerFrame;
|
||||||
|
desc.mBytesPerPacket = desc.mBytesPerFrame * desc.mFramesPerPacket;
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRAudioManager::initSiren()
|
||||||
|
{
|
||||||
|
if(m_auGraph == NULL) {
|
||||||
|
// ----====---- Initialize Core Audio Objects ----====----
|
||||||
|
OSDEBUG(NewAUGraph(&m_auGraph));
|
||||||
|
|
||||||
|
// ---- Create output node ----
|
||||||
|
AudioComponentDescription output_desc;
|
||||||
|
output_desc.componentType = kAudioUnitType_Output;
|
||||||
|
#if TARGET_OS_IPHONE
|
||||||
|
output_desc.componentSubType = kAudioUnitSubType_RemoteIO;
|
||||||
|
#else
|
||||||
|
output_desc.componentSubType = kAudioUnitSubType_DefaultOutput;
|
||||||
|
#endif
|
||||||
|
output_desc.componentFlags = 0;
|
||||||
|
output_desc.componentFlagsMask = 0;
|
||||||
|
output_desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
||||||
|
AUNode outputNode = 0;
|
||||||
|
OSDEBUG(AUGraphAddNode(m_auGraph, &output_desc, &outputNode));
|
||||||
|
|
||||||
|
// ---- Create mixer node ----
|
||||||
|
AudioComponentDescription mixer_desc;
|
||||||
|
mixer_desc.componentType = kAudioUnitType_Mixer;
|
||||||
|
mixer_desc.componentSubType = kAudioUnitSubType_MultiChannelMixer;
|
||||||
|
mixer_desc.componentFlags = 0;
|
||||||
|
mixer_desc.componentFlagsMask = 0;
|
||||||
|
mixer_desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
||||||
|
AUNode mixerNode = 0;
|
||||||
|
OSDEBUG(AUGraphAddNode(m_auGraph, &mixer_desc, &mixerNode ));
|
||||||
|
|
||||||
|
// ---- Connect mixer to output node ----
|
||||||
|
OSDEBUG(AUGraphConnectNodeInput(m_auGraph, mixerNode, 0, outputNode, 0));
|
||||||
|
|
||||||
|
// ---- Open the audio graph ----
|
||||||
|
OSDEBUG(AUGraphOpen(m_auGraph));
|
||||||
|
|
||||||
|
// ---- Get a handle to the mixer ----
|
||||||
|
OSDEBUG(AUGraphNodeInfo(m_auGraph, mixerNode, NULL, &m_auMixer));
|
||||||
|
|
||||||
|
// ---- Add output channel to mixer ----
|
||||||
|
UInt32 bus_count = 1;
|
||||||
|
OSDEBUG(AudioUnitSetProperty(m_auMixer, kAudioUnitProperty_ElementCount, kAudioUnitScope_Input, 0, &bus_count, sizeof(bus_count)));
|
||||||
|
|
||||||
|
// ---- Attach render function to channel ----
|
||||||
|
AURenderCallbackStruct renderCallbackStruct;
|
||||||
|
renderCallbackStruct.inputProc = &renderInput;
|
||||||
|
renderCallbackStruct.inputProcRefCon = this;
|
||||||
|
OSDEBUG(AUGraphSetNodeInputCallback(m_auGraph, mixerNode, 0, &renderCallbackStruct)); // 0 = mixer input number
|
||||||
|
|
||||||
|
AudioStreamBasicDescription desc;
|
||||||
|
memset(&desc, 0, sizeof(desc));
|
||||||
|
|
||||||
|
UInt32 size = sizeof(desc);
|
||||||
|
memset(&desc, 0, sizeof(desc));
|
||||||
|
OSDEBUG(AudioUnitGetProperty( m_auMixer,
|
||||||
|
kAudioUnitProperty_StreamFormat,
|
||||||
|
kAudioUnitScope_Input,
|
||||||
|
0, // 0 = mixer input number
|
||||||
|
&desc,
|
||||||
|
&size));
|
||||||
|
|
||||||
|
KRSetAUCanonical(desc, 2, false);
|
||||||
|
desc.mSampleRate = 44100.0f;
|
||||||
|
/*
|
||||||
|
desc.mSampleRate = 44100.0; // set sample rate
|
||||||
|
desc.mFormatID = kAudioFormatLinearPCM;
|
||||||
|
desc.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
|
||||||
|
desc.mBitsPerChannel = sizeof(AudioSampleType) * 8; // AudioSampleType == 16 bit signed ints
|
||||||
|
desc.mChannelsPerFrame = 2;
|
||||||
|
desc.mFramesPerPacket = 1;
|
||||||
|
desc.mBytesPerFrame = (desc.mBitsPerChannel / 8) * desc.mChannelsPerFrame;
|
||||||
|
desc.mBytesPerPacket = desc.mBytesPerFrame * desc.mFramesPerPacket;
|
||||||
|
*/
|
||||||
|
|
||||||
|
OSDEBUG(AudioUnitSetProperty(m_auMixer,
|
||||||
|
kAudioUnitProperty_StreamFormat,
|
||||||
|
kAudioUnitScope_Input,
|
||||||
|
0, // 0 == mixer input number
|
||||||
|
&desc,
|
||||||
|
sizeof(desc)));
|
||||||
|
|
||||||
|
// ---- Apply properties to mixer output ----
|
||||||
|
OSDEBUG(AudioUnitSetProperty(m_auMixer,
|
||||||
|
kAudioUnitProperty_StreamFormat,
|
||||||
|
kAudioUnitScope_Output,
|
||||||
|
0, // Always 0 for output bus
|
||||||
|
&desc,
|
||||||
|
sizeof(desc)));
|
||||||
|
|
||||||
|
|
||||||
|
memset(&desc, 0, sizeof(desc));
|
||||||
|
size = sizeof(desc);
|
||||||
|
OSDEBUG(AudioUnitGetProperty(m_auMixer,
|
||||||
|
kAudioUnitProperty_StreamFormat,
|
||||||
|
kAudioUnitScope_Output,
|
||||||
|
0,
|
||||||
|
&desc,
|
||||||
|
&size));
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// AUCanonical on the iPhone is the 8.24 integer format that is native to the iPhone.
|
||||||
|
|
||||||
|
KRSetAUCanonical(desc, 2, false);
|
||||||
|
desc.mSampleRate = 44100.0f;
|
||||||
|
// int channel_count = 2;
|
||||||
|
// bool interleaved = true;
|
||||||
|
//
|
||||||
|
// desc.mFormatID = kAudioFormatLinearPCM;
|
||||||
|
//#if CA_PREFER_FIXED_POINT
|
||||||
|
// desc.mFormatFlags = kAudioFormatFlagsCanonical | (kAudioUnitSampleFractionBits << kLinearPCMFormatFlagsSampleFractionShift);
|
||||||
|
//#else
|
||||||
|
// desc.mFormatFlags = kAudioFormatFlagsCanonical;
|
||||||
|
//#endif
|
||||||
|
// desc.mChannelsPerFrame = channel_count;
|
||||||
|
// desc.mFramesPerPacket = 1;
|
||||||
|
// desc.mBitsPerChannel = 8 * sizeof(AudioUnitSampleType);
|
||||||
|
// if (interleaved) {
|
||||||
|
// desc.mBytesPerPacket = desc.mBytesPerFrame = channel_count * sizeof(AudioUnitSampleType);
|
||||||
|
// } else {
|
||||||
|
// desc.mBytesPerPacket = desc.mBytesPerFrame = sizeof(AudioUnitSampleType);
|
||||||
|
// desc.mFormatFlags |= kAudioFormatFlagIsNonInterleaved;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// ----
|
||||||
|
|
||||||
|
OSDEBUG(AudioUnitSetProperty(m_auMixer,
|
||||||
|
kAudioUnitProperty_StreamFormat,
|
||||||
|
kAudioUnitScope_Output,
|
||||||
|
0,
|
||||||
|
&desc,
|
||||||
|
sizeof(desc)));
|
||||||
|
|
||||||
|
|
||||||
|
OSDEBUG(AudioUnitSetParameter(m_auMixer, kMultiChannelMixerParam_Volume, kAudioUnitScope_Input, 0, 1.0, 0));
|
||||||
|
OSDEBUG(AudioUnitSetParameter(m_auMixer, kMultiChannelMixerParam_Volume, kAudioUnitScope_Output, 0, 1.0, 0));
|
||||||
|
|
||||||
|
OSDEBUG(AUGraphInitialize(m_auGraph));
|
||||||
|
|
||||||
|
OSDEBUG(AUGraphStart(m_auGraph));
|
||||||
|
|
||||||
|
CAShow(m_auGraph);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void KRAudioManager::cleanupSiren()
|
||||||
|
{
|
||||||
|
if(m_auGraph) {
|
||||||
|
OSDEBUG(AUGraphStop(m_auGraph));
|
||||||
|
OSDEBUG(DisposeAUGraph(m_auGraph));
|
||||||
|
m_auGraph = NULL;
|
||||||
|
m_auMixer = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRAudioManager::initOpenAL()
|
||||||
{
|
{
|
||||||
if(m_alDevice == 0) {
|
if(m_alDevice == 0) {
|
||||||
// ----- Initialize OpenAL -----
|
// ----- Initialize OpenAL -----
|
||||||
@@ -86,12 +356,14 @@ void KRAudioManager::initAudio()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KRAudioManager::~KRAudioManager()
|
void KRAudioManager::cleanupAudio()
|
||||||
{
|
{
|
||||||
for(map<std::string, KRAudioSample *>::iterator name_itr=m_sounds.begin(); name_itr != m_sounds.end(); name_itr++) {
|
cleanupOpenAL();
|
||||||
delete (*name_itr).second;
|
cleanupSiren();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KRAudioManager::cleanupOpenAL()
|
||||||
|
{
|
||||||
if(m_alContext) {
|
if(m_alContext) {
|
||||||
ALDEBUG(alcDestroyContext(m_alContext));
|
ALDEBUG(alcDestroyContext(m_alContext));
|
||||||
m_alContext = 0;
|
m_alContext = 0;
|
||||||
@@ -100,6 +372,15 @@ KRAudioManager::~KRAudioManager()
|
|||||||
ALDEBUG(alcCloseDevice(m_alDevice));
|
ALDEBUG(alcCloseDevice(m_alDevice));
|
||||||
m_alDevice = 0;
|
m_alDevice = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
KRAudioManager::~KRAudioManager()
|
||||||
|
{
|
||||||
|
for(map<std::string, KRAudioSample *>::iterator name_itr=m_sounds.begin(); name_itr != m_sounds.end(); name_itr++) {
|
||||||
|
delete (*name_itr).second;
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanupAudio();
|
||||||
|
|
||||||
for(std::vector<KRDataBlock *>::iterator itr = m_bufferPoolIdle.begin(); itr != m_bufferPoolIdle.end(); itr++) {
|
for(std::vector<KRDataBlock *>::iterator itr = m_bufferPoolIdle.begin(); itr != m_bufferPoolIdle.end(); itr++) {
|
||||||
delete *itr;
|
delete *itr;
|
||||||
@@ -109,8 +390,12 @@ 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));
|
ALDEBUG(alcMakeContextCurrent(m_alContext));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void KRAudioManager::setViewMatrix(const KRMat4 &viewMatrix)
|
void KRAudioManager::setViewMatrix(const KRMat4 &viewMatrix)
|
||||||
{
|
{
|
||||||
@@ -125,12 +410,12 @@ void KRAudioManager::setViewMatrix(const KRMat4 &viewMatrix)
|
|||||||
vectorForward.normalize();
|
vectorForward.normalize();
|
||||||
|
|
||||||
makeCurrentContext();
|
makeCurrentContext();
|
||||||
// player_position = KRVector3(1.0, 0.0, 0.0); // FINDME - HACK - TEST CODE
|
if(m_audio_engine == KRAKEN_AUDIO_OPENAL) {
|
||||||
ALDEBUG(alListener3f(AL_POSITION, player_position.x, player_position.y, player_position.z));
|
ALDEBUG(alListener3f(AL_POSITION, player_position.x, player_position.y, player_position.z));
|
||||||
ALfloat orientation[] = {vectorForward.x, vectorForward.y, vectorForward.z, vectorUp.x, vectorUp.y, vectorUp.z};
|
ALfloat orientation[] = {vectorForward.x, vectorForward.y, vectorForward.z, vectorUp.x, vectorUp.y, vectorUp.z};
|
||||||
// ALfloat orientation[] = {0.0, 1.0, 0.0, 0.0, 1.0, 0.0}; // FINDME - HACK - TEST CODE
|
|
||||||
ALDEBUG(alListenerfv(AL_ORIENTATION, orientation));
|
ALDEBUG(alListenerfv(AL_ORIENTATION, orientation));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void KRAudioManager::add(KRAudioSample *sound)
|
void KRAudioManager::add(KRAudioSample *sound)
|
||||||
{
|
{
|
||||||
@@ -215,3 +500,8 @@ ALvoid alcMacOSXRenderingQualityProc(const ALint value)
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KRAudioManager::audio_engine_t KRAudioManager::getAudioEngine()
|
||||||
|
{
|
||||||
|
return m_audio_engine;
|
||||||
|
}
|
||||||
|
|||||||
@@ -61,15 +61,40 @@ 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();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
map<std::string, KRAudioSample *> m_sounds;
|
map<std::string, KRAudioSample *> m_sounds;
|
||||||
|
|
||||||
std::vector<KRDataBlock *> m_bufferPoolIdle;
|
std::vector<KRDataBlock *> m_bufferPoolIdle;
|
||||||
|
|
||||||
|
|
||||||
|
void initAudio();
|
||||||
|
void initOpenAL();
|
||||||
|
void initSiren();
|
||||||
|
|
||||||
|
void cleanupAudio();
|
||||||
|
void cleanupOpenAL();
|
||||||
|
void cleanupSiren();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
audio_engine_t m_audio_engine;
|
||||||
|
|
||||||
|
// OpenAL Handles
|
||||||
ALCcontext* m_alContext;
|
ALCcontext* m_alContext;
|
||||||
ALCdevice* m_alDevice;
|
ALCdevice* m_alDevice;
|
||||||
|
|
||||||
void initAudio();
|
// Siren Handles
|
||||||
|
AUGraph m_auGraph;
|
||||||
|
AudioUnit m_auMixer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -373,7 +373,7 @@ void KRAudioSource::play()
|
|||||||
ALDEBUG(alSourcef(m_sourceID, AL_REFERENCE_DISTANCE, m_referenceDistance));
|
ALDEBUG(alSourcef(m_sourceID, AL_REFERENCE_DISTANCE, m_referenceDistance));
|
||||||
ALDEBUG(alSourcef(m_sourceID, AL_ROLLOFF_FACTOR, m_rolloffFactor));
|
ALDEBUG(alSourcef(m_sourceID, AL_ROLLOFF_FACTOR, m_rolloffFactor));
|
||||||
ALDEBUG(alcASASetSourceProc(ALC_ASA_REVERB_SEND_LEVEL, m_sourceID, &m_reverb, sizeof(m_reverb)));
|
ALDEBUG(alcASASetSourceProc(ALC_ASA_REVERB_SEND_LEVEL, m_sourceID, &m_reverb, sizeof(m_reverb)));
|
||||||
// ALDEBUG(alSourcei(m_sourceID, AL_SOURCE_RELATIVE, AL_FALSE));
|
ALDEBUG(alSourcei(m_sourceID, AL_SOURCE_RELATIVE, AL_FALSE));
|
||||||
} else {
|
} else {
|
||||||
ALDEBUG(alSourcei(m_sourceID, AL_SOURCE_RELATIVE, AL_TRUE));
|
ALDEBUG(alSourcei(m_sourceID, AL_SOURCE_RELATIVE, AL_TRUE));
|
||||||
ALDEBUG(alSource3f(m_sourceID, AL_POSITION, 0.0, 0.0, 0.0));
|
ALDEBUG(alSource3f(m_sourceID, AL_POSITION, 0.0, 0.0, 0.0));
|
||||||
@@ -410,7 +410,6 @@ void KRAudioSource::updatePosition()
|
|||||||
ALfloat obstruction = 0.0f; // type ALfloat -100.0 db (most obstruction) - 0.0 db (no obstruction, 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();
|
KRVector3 worldPosition = getWorldTranslation();
|
||||||
// worldPosition = KRVector3(0.0, 0.5, 0.0); // FINDME - HACK - TEST CODE
|
|
||||||
ALDEBUG(alSource3f(m_sourceID, AL_POSITION, worldPosition.x, worldPosition.y, worldPosition.z));
|
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_GAIN, m_gain));
|
||||||
ALDEBUG(alSourcef(m_sourceID, AL_MIN_GAIN, 0.0));
|
ALDEBUG(alSourcef(m_sourceID, AL_MIN_GAIN, 0.0));
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ using std::queue;
|
|||||||
#include <AudioToolbox/AudioToolbox.h>
|
#include <AudioToolbox/AudioToolbox.h>
|
||||||
#include <AudioToolbox/AudioFile.h>
|
#include <AudioToolbox/AudioFile.h>
|
||||||
#include <AudioToolbox/ExtendedAudioFile.h>
|
#include <AudioToolbox/ExtendedAudioFile.h>
|
||||||
|
#include <AudioToolbox/AUGraph.h>
|
||||||
#include <OpenAL/al.h>
|
#include <OpenAL/al.h>
|
||||||
#include <OpenAL/alc.h>
|
#include <OpenAL/alc.h>
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
@@ -116,6 +117,14 @@ fprintf(stderr, "Error at line number %d, in file %s. alGetError() returned %i f
|
|||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define OSDEBUG(x) \
|
||||||
|
{ \
|
||||||
|
OSStatus e = x; \
|
||||||
|
if( e != noErr) \
|
||||||
|
{ \
|
||||||
|
fprintf(stderr, "Error at line number %d, in file %s. Returned %d for call %s\n",__LINE__, __FILE__, e, #x ); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
#define KRMIN(x,y) ((x) < (y) ? (x) : (y))
|
#define KRMIN(x,y) ((x) < (y) ? (x) : (y))
|
||||||
#define KRMAX(x,y) ((x) > (y) ? (x) : (y))
|
#define KRMAX(x,y) ((x) > (y) ? (x) : (y))
|
||||||
|
|||||||
@@ -63,15 +63,10 @@ using namespace std;
|
|||||||
|
|
||||||
- (id)init
|
- (id)init
|
||||||
{
|
{
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
BOOL isIpad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
|
BOOL isIpad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
|
||||||
BOOL isRetina = [[UIScreen mainScreen] scale] >= 2.0;
|
BOOL isRetina = [[UIScreen mainScreen] scale] >= 2.0;
|
||||||
#else
|
|
||||||
BOOL isIpad = false;
|
|
||||||
BOOL isRetina = false;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
|
||||||
if(isIpad && isRetina) {
|
if(isIpad && isRetina) {
|
||||||
KRContext::KRENGINE_MAX_VBO_HANDLES = 10000;
|
KRContext::KRENGINE_MAX_VBO_HANDLES = 10000;
|
||||||
KRContext::KRENGINE_MAX_VBO_MEM = 128000000 * 2;
|
KRContext::KRENGINE_MAX_VBO_MEM = 128000000 * 2;
|
||||||
@@ -105,7 +100,7 @@ using namespace std;
|
|||||||
KRContext::KRENGINE_TARGET_TEXTURE_MEM_MIN = 96000000;
|
KRContext::KRENGINE_TARGET_TEXTURE_MEM_MIN = 96000000;
|
||||||
KRContext::KRENGINE_MAX_TEXTURE_DIM = 2048;
|
KRContext::KRENGINE_MAX_TEXTURE_DIM = 2048;
|
||||||
KRContext::KRENGINE_MIN_TEXTURE_DIM = 64;
|
KRContext::KRENGINE_MIN_TEXTURE_DIM = 64;
|
||||||
KRContext::KRENGINE_MAX_TEXTURE_THROUGHPUT = 32000000;
|
KRContext::KRENGINE_MAX_TEXTURE_THROUGHPUT = 128000000;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_context = NULL;
|
_context = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user