/*
File: SoundEngine.cpp
Abstract: These functions play background music tracks, multiple sound effects,
and support stereo panning with a low-latency response.
Version: 1.7
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
("Apple") in consideration of your agreement to the following terms, and your
use, installation, modification or redistribution of this Apple software
constitutes acceptance of these terms. If you do not agree with these terms,
please do not use, install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and subject
to these terms, Apple grants you a personal, non-exclusive license, under
Apple's copyrights in this original Apple software (the "Apple Software"), to
use, reproduce, modify and redistribute the Apple Software, with or without
modifications, in source and/or binary forms; provided that if you redistribute
the Apple Software in its entirety and without modifications, you must retain
this notice and the following text and disclaimers in all such redistributions
of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may be used
to endorse or promote products derived from the Apple Software without specific
prior written permission from Apple. Except as expressly stated in this notice,
no other rights or licenses, express or implied, are granted by Apple herein,
including but not limited to any patent rights that may be infringed by your
derivative works or by other works in which the Apple Software may be
incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2008 Apple Inc. All Rights Reserved.
*/
#if !TARGET_IPHONE_SIMULATOR
/*==================================================================================================
SoundEngine.cpp
==================================================================================================*/
#if !defined(__SoundEngine_cpp__)
#define __SoundEngine_cpp__
//==================================================================================================
// Includes
//==================================================================================================
// System Includes
#include <AudioToolbox/AudioToolbox.h>
#include <CoreFoundation/CFURL.h>
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#include <map>
#include <vector>
#include <pthread.h>
#include <mach/mach.h>
// Local Includes
#include "SoundEngine.h"
#define AssertNoError(inMessage, inHandler) \
if(result != noErr) \
{ \
printf("%s: %d\n", inMessage, (int)result); \
}
#define AssertNoOALError(inMessage, inHandler) \
if((result = alGetError()) != AL_NO_ERROR) \
{ \
printf("%s: %x\n", inMessage, (int)result); \
goto inHandler; \
}
#define kNumberBuffers 3
class OpenALObject;
class BackgroundTrackMgr;
static OpenALObject *sOpenALObject = NULL;
static BackgroundTrackMgr *sBackgroundTrackMgr = NULL;
static Float32 gMasterVolumeGain = 1.0;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
typedef ALvoid AL_APIENTRY (*alBufferDataStaticProcPtr) (const ALint bid, ALenum format, ALvoid* data, ALsizei size, ALsizei freq);
ALvoid alBufferDataStaticProc(const ALint bid, ALenum format, ALvoid* data, ALsizei size, ALsizei freq)
{
static alBufferDataStaticProcPtr proc = NULL;
if (proc == NULL) {
proc = (alBufferDataStaticProcPtr) alcGetProcAddress(NULL, (const ALCchar*) "alBufferDataStatic");
}
if (proc)
proc(bid, format, data, size, freq);
return;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
typedef ALvoid AL_APIENTRY (*alcMacOSXMixerOutputRateProcPtr) (const ALdouble value);
ALvoid alcMacOSXMixerOutputRateProc(const ALdouble value)
{
static alcMacOSXMixerOutputRateProcPtr proc = NULL;
if (proc == NULL) {
proc = (alcMacOSXMixerOutputRateProcPtr) alcGetProcAddress(NULL, (const ALCchar*) "alcMacOSXMixerOutputRate");
}
if (proc)
proc(value);
return;
}
#pragma mark ***** OpenALThread *****
//==================================================================================================
// Threading functions
//==================================================================================================
class OpenALThread
{
// returns the thread's priority as it was last set by the API
#define OpenALThread_SET_PRIORITY 0
// returns the thread's priority as it was last scheduled by the Kernel
#define OpenALThread_SCHEDULED_PRIORITY 1
// Types
public:
typedef void* (*ThreadRoutine)(void* inParameter);
// Constants
public:
enum
{
kMinThreadPriority = 1,
kMaxThreadPriority = 63,
kDefaultThreadPriority = 31
};
// Construction/Destruction
public:
OpenALThread(ThreadRoutine inThreadRoutine, void* inParameter)
: mPThread(0),
mSpawningThreadPriority(getScheduledPriority(pthread_self(), OpenALThread_SET_PRIORITY)),
mThreadRoutine(inThreadRoutine),
mThreadParameter(inParameter),
mPriority(kDefaultThreadPriority),
mFixedPriority(false),
mAutoDelete(true) { }
~OpenALThread() { }
// Properties
bool IsRunning() const { return 0 != mPThread; }
void SetAutoDelete(bool b) { mAutoDelete = b; }
void SetPriority(UInt32 inPriority, bool inFixedPriority)
{
OSStatus result = noErr;
mPriority = inPriority;
mFixedPriority = inFixedPriority;
if(mPThread != 0)
{
if (mFixedPriority)
{
thread_extended_policy_data_t theFixedPolicy;
theFixedPolicy.timeshare = false; // set to true for a non-fixed thread
result = thread_policy_set(pthread_mach_thread_np(mPThread), THREAD_EXTENDED_POLICY, (thread_policy_t)&theFixedPolicy, THREAD_EXTENDED_POLICY_COUNT);
if (result) {
printf("OpenALThread::SetPriority: failed to set the fixed-priority policy");
return;
}
}
// We keep a reference to the spawning thread's priority around (initialized in the constructor),
// and set the importance of the child thread relative to the spawning thread's priority.
thread_precedence_policy_data_t thePrecedencePolicy;
thePrecedencePolicy.importance = mPriority - mSpawningThreadPriority;
result =thread_policy_set(pthread_mach_thread_np(mPThread), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&thePrecedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT);
if (result) {
printf("OpenALThread::SetPriority: failed to set the precedence policy");
return;
}
}
}
// Actions
void Start()
{
if(mPThread != 0)
{
printf("OpenALThread::Start: can't start because the thread is already running\n");
return;
}
OSStatus result;
pthread_attr_t theThreadAttributes;
result = pthread_attr_init(&theThreadAttributes);
AssertNoError("Error initializing thread", end);
result = pthread_attr_setdetachstate(&theThreadAttributes, PTHREAD_CREATE_DETACHED);
AssertNoError("Error setting thread detach state", end);
result = pthread_create(&mPThread, &theThreadAttributes, (ThreadRoutine)OpenALThread::Entry
没有合适的资源?快使用搜索试试~ 我知道了~
ios源码之西尔平斯基三角形应用Sierpinski.rar
共78个文件
pbxbtree:8个
o:8个
png:7个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 91 浏览量
2022-07-11
11:53:09
上传
评论
收藏 1.39MB RAR 举报
温馨提示
ios源码之西尔平斯基三角形应用Sierpinski.rar
资源推荐
资源详情
资源评论
收起资源包目录
ios源码之西尔平斯基三角形应用Sierpinski.rar (78个子文件)
Sierpinski
main.m 338B
Default.png 28KB
MainView.xib 7KB
thx.m4v 74KB
letsgo.m4v 112KB
Sierpinski.xcodeproj
acs.mode1v3 40KB
project.pbxproj 19KB
m.pbxuser 4KB
m.perspectivev3 42KB
acs.perspectivev3 42KB
acs.pbxuser 4KB
.DS_Store 6KB
sierpinski.png 21KB
sierpinskiBigIcon.png 31KB
AudioSupport
SoundEngine.h 15KB
SoundEngine.cpp 50KB
FlipsideView.xib 10KB
sierpinskiIcon.png 2KB
Sierpinski_Prefix.pch 181B
Info.plist 911B
Classes
MainView.h 328B
MainViewController.h 222B
FlipsideViewController.h 231B
FlipsideView.m 1KB
MainView.m 2KB
RootViewController.h 741B
FlipsideViewController.m 754B
MainViewController.m 988B
SierpinskiAppDelegate.h 470B
RootViewController.m 4KB
SierpinskiAppDelegate.m 547B
FlipsideView.h 362B
MainWindow.xib 12KB
build
Sierpinski.build
Sierpinski.pbxindex
subclasses.pbxbtree 2KB
categories.pbxbtree 1KB
symbols0.pbxsymbols 866KB
files.pbxbtree 4KB
protocols.pbxbtree 1KB
imports.pbxbtree 11KB
decls.pbxbtree 202KB
cdecls.pbxbtree 202KB
refs.pbxbtree 145KB
pbxindex.header 24B
strings.pbxstrings
control 256KB
strings 416KB
Debug-iphonesimulator
Sierpinski.build
Sierpinski~.dep 5KB
Sierpinski.dep 5KB
Sierpinski-generated-files.hmap 121B
Sierpinski-own-target-headers.hmap 793B
build-state.dat 51KB
Sierpinski-all-target-headers.hmap 793B
build-state~.dat 53KB
Sierpinski-project-headers.hmap 1KB
Objects-normal
i386
FlipsideView.o 15KB
RootViewController.o 41KB
MainView.o 14KB
SoundEngine.o 288KB
MainViewController.o 30KB
FlipsideViewController.o 30KB
Sierpinski.LinkFileList 1KB
main.o 6KB
SierpinskiAppDelegate.o 37KB
Sierpinski.hmap 2KB
Debug
Sierpinski.build
Sierpinski.dep 2KB
build-state.dat 3KB
Debug-iphonesimulator
Sierpinski.app
Default.png 28KB
FlipsideView.nib 2KB
thx.m4v 74KB
MainView.nib 1KB
letsgo.m4v 112KB
MainWindow.nib 2KB
sierpinski.png 21KB
sierpinskiIcon.png 2KB
PkgInfo 8B
Info.plist 638B
Sierpinski 131KB
Sierpinski.app.dSYM
Contents
Resources
DWARF
Sierpinski 264KB
Info.plist 594B
共 78 条
- 1
资源评论
reg183
- 粉丝: 1811
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功