Small clean-up of sound code. This is *not* The Fix.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@421 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2006-04-03 16:39:37 +00:00
parent 5dfb75bd5b
commit e74a105b6f
5 changed files with 62 additions and 54 deletions

View File

@ -393,7 +393,7 @@
06AFA01500A58FB77F000001 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = /System/Library/Frameworks/OpenGL.framework; sourceTree = "<absolute>"; };
083325DB09DDBCDE00F5B8E4 /* OOColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OOColor.h; path = src/Core/OOColor.h; sourceTree = "<group>"; };
083325DC09DDBCDE00F5B8E4 /* OOColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OOColor.m; path = src/Core/OOColor.m; sourceTree = "<group>"; };
0865432206B8447D000CA0AB /* Oolite.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Oolite.app; sourceTree = BUILT_PRODUCTS_DIR; };
0865432206B8447D000CA0AB /* OoliteDev.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OoliteDev.app; sourceTree = BUILT_PRODUCTS_DIR; };
0878FD2F086EF845004CB752 /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = /System/Library/Frameworks/Carbon.framework; sourceTree = "<absolute>"; };
08CB1FEC09D3F2AA001EA329 /* customsounds.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; name = customsounds.plist; path = Resources/Config/customsounds.plist; sourceTree = "<group>"; };
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
@ -998,7 +998,7 @@
19C28FACFE9D520D11CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
0865432206B8447D000CA0AB /* Oolite.app */,
0865432206B8447D000CA0AB /* OoliteDev.app */,
);
name = Products;
sourceTree = "<group>";
@ -1124,10 +1124,10 @@
251610CF099544090037C2E1 /* OOCASoundReferencePoint.m */,
251610D4099544090037C2E1 /* OOCASoundDecoder.h */,
251610DB099544090037C2E1 /* OOCASoundDecoder.m */,
251610DC099544090037C2E1 /* OOErrorDescription.m */,
251610F0099544190037C2E1 /* VirtualRingBuffer.m */,
251610F1099544190037C2E1 /* VirtualRingBuffer.h */,
251610D8099544090037C2E1 /* OOErrorDescription.h */,
251610DC099544090037C2E1 /* OOErrorDescription.m */,
251610F1099544190037C2E1 /* VirtualRingBuffer.h */,
251610F0099544190037C2E1 /* VirtualRingBuffer.m */,
);
name = Audio;
sourceTree = "<group>";
@ -1304,7 +1304,7 @@
name = Oolite;
productInstallPath = "$(HOME)/Applications";
productName = Oolite;
productReference = 0865432206B8447D000CA0AB /* Oolite.app */;
productReference = 0865432206B8447D000CA0AB /* OoliteDev.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */

View File

@ -34,6 +34,7 @@ Your fair use and other rights are in no way affected by the above.
#import "OOCASoundChannel.h"
#import "OOCASoundInternal.h"
#import <mach/mach.h>
#import <pthread.h>
static mach_port_t sReapPort = MACH_PORT_NULL;
@ -52,8 +53,7 @@ static SInt32 sDebugUnexpectedNullCount = 0;
*/
static OOCASoundChannel *sPlayThreadDeadList = NULL;
static OOCASoundChannel *sReapQueue = NULL;
static NSLock *sReapQueueMutex = NULL;
static pthread_mutex_t sReapQueueMutex = { 0 };
enum
{
@ -81,8 +81,7 @@ enum
enum
{
// Port messages
kMsgRecycleChannel = 1UL,
kMsgThreadUp,
kMsgThreadUp = 1UL,
kMsgDie,
kMsgThreadDied,
kMsgWakeUp
@ -148,8 +147,7 @@ static BOOL PortWait(mach_port_t inPort, PortMessage *outMessage);
if (OK)
{
sReapQueueMutex = [[NSLock alloc] init];
if (nil == sReapQueueMutex) OK = NO;
if (0 != pthread_mutex_init(&sReapQueueMutex, NULL)) OK = NO;
}
if (OK)
@ -201,18 +199,9 @@ static BOOL PortWait(mach_port_t inPort, PortMessage *outMessage);
{
if (PortWait(sReapPort, &message))
{
if (kMsgRecycleChannel == message.tag)
if (kMsgWakeUp == message.tag)
{
chan = message.value;
[chan cleanUp];
}
else if (kMsgDie == message.tag)
{
break;
}
else if (kMsgWakeUp == message.tag)
{
[sReapQueueMutex lock];
assert (!pthread_mutex_lock(&sReapQueueMutex));
while (sReapQueue)
{
@ -221,7 +210,11 @@ static BOOL PortWait(mach_port_t inPort, PortMessage *outMessage);
[chan cleanUp];
}
[sReapQueueMutex unlock];
pthread_mutex_unlock(&sReapQueueMutex);
}
else if (kMsgDie == message.tag)
{
break;
}
}
}
@ -428,6 +421,24 @@ static BOOL PortWait(mach_port_t inPort, PortMessage *outMessage);
}
- (void)reap
{
OSStatus err;
err = [[OOCASoundMixer mixer] disconnectChannel:self];
if (noErr == err)
{
_state = kState_Ended;
}
else
{
_state = kState_Broken;
_error = err;
}
}
- (void)cleanUp
{
OOSound *sound;
@ -491,7 +502,7 @@ static BOOL PortWait(mach_port_t inPort, PortMessage *outMessage);
break;
case kState_Broken:
stateString = [NSString stringWithFormat:@"broken (%i)", _error];
stateString = [NSString stringWithFormat:@"broken (%@)", AudioErrorShortNSString(_error)];
break;
default:
@ -507,7 +518,7 @@ static BOOL PortWait(mach_port_t inPort, PortMessage *outMessage);
- (OSStatus)renderWithFlags:(AudioUnitRenderActionFlags *)ioFlags frames:(UInt32)inNumFrames context:(OOCASoundRenderContext *)ioContext data:(AudioBufferList *)ioData
{
OSStatus err;
OSStatus err = noErr;
PortMessage message;
if (__builtin_expect(_stopReq, 0)) err = endOfDataReached;
@ -546,29 +557,16 @@ static BOOL PortWait(mach_port_t inPort, PortMessage *outMessage);
if (endOfDataReached == err)
{
err = [[OOCASoundMixer mixer] disconnectChannel:self];
if (noErr == err)
{
_state = kState_Ended;
}
else
{
_state = kState_Broken;
_error = err;
}
assert(kState_Playing == _state);
[self reap];
err = noErr;
_next = sPlayThreadDeadList;
sPlayThreadDeadList = self;
/*message.tag = kMsgRecycleChannel;
message.value = self;
PortSend(sReapPort, message);*/
}
if (nil != sPlayThreadDeadList && [sReapQueueMutex tryLock])
if (nil != sPlayThreadDeadList && !pthread_mutex_trylock(&sReapQueueMutex))
{
// Put sPlayThreadDeadList at front of sReapQueue
OOCASoundChannel *curr;
@ -580,7 +578,7 @@ static BOOL PortWait(mach_port_t inPort, PortMessage *outMessage);
sReapQueue = sPlayThreadDeadList;
sPlayThreadDeadList = nil;
[sReapQueueMutex unlock];
pthread_mutex_unlock(&sReapQueueMutex);
// Wake up reaper thread
message.tag = kMsgWakeUp;

View File

@ -39,7 +39,7 @@ Your fair use and other rights are in no way affected by the above.
#define kMixerGeneralChannels 32
#define SUPPORT_SOUND_INSPECTOR 0
#define SUPPORT_SOUND_INSPECTOR 1
@interface OOCASoundMixer: NSObject

View File

@ -38,3 +38,4 @@ NSString *OSStatusErrorNSString(OSStatus inCode);
NSString *AudioErrorNSString(ComponentResult inCode);
NSString *KernelResultNSString(kern_return_t inCode);
NSString *FourCharCodeToNSString(FourCharCode inCode);
NSString *AudioErrorShortNSString(OSStatus inCode);

View File

@ -37,8 +37,6 @@ Your fair use and other rights are in no way affected by the above.
#define CASE(foo) case foo: return @#foo
#define CASE2(foo, bar) case foo: return @ #foo"/"#bar
#define CASE3(foo, bar, baz) case foo: return @ #foo"/"#bar"/"#baz
#ifndef NDEBUG
@ -72,8 +70,8 @@ NSString *AudioErrorNSString(ComponentResult inCode)
CASE(kAudioConverterErr_PropertyNotSupported);
CASE(kAudioConverterErr_InvalidInputSize);
CASE(kAudioConverterErr_InvalidOutputSize);
CASE2(kAudioConverterErr_UnspecifiedError, kAudioCodecUnspecifiedError);
CASE2(kAudioConverterErr_BadPropertySizeError, kAudioCodecBadPropertySizeError);
CASE(kAudioConverterErr_UnspecifiedError);
CASE(kAudioConverterErr_BadPropertySizeError);
CASE(kAudioConverterErr_RequiresPacketDescriptionsError);
CASE(kAudioConverterErr_InputSampleRateOutOfRange);
CASE(kAudioConverterErr_OutputSampleRateOutOfRange);
@ -99,7 +97,7 @@ NSString *AudioErrorNSString(ComponentResult inCode)
CASE(kAudioUnitErr_Uninitialized);
CASE(kAudioUnitErr_InvalidScope);
CASE(kAudioUnitErr_PropertyNotWritable);
CASE3(kAudioUnitErr_CannotDoInCurrentContext, kAUGraphErr_CannotDoInCurrentContext, kAUGraphErr_CannotDoInCurrentContext);
CASE(kAudioUnitErr_CannotDoInCurrentContext);
CASE(kAudioUnitErr_InvalidPropertyValue);
CASE(kAudioUnitErr_PropertyNotInUse);
CASE(kAudioUnitErr_Initialized);
@ -121,11 +119,22 @@ NSString *AudioErrorNSString(ComponentResult inCode)
if (noErr == inCode) return @"no error";
#endif
int high = inCode >> 24;
if (high && ! (high & 0xFF))
return AudioErrorShortNSString(inCode);
}
NSString *AudioErrorShortNSString(OSStatus inCode)
{
#define PRINTABLE(x) (!((x) < ' ') && !((x) == 0x7F))
if (!(inCode & 0x80000000) &&
PRINTABLE(inCode >> 24) &&
PRINTABLE((inCode >> 16) & 0xFF) &&
PRINTABLE((inCode >> 8) & 0xFF) &&
PRINTABLE(inCode & 0xFF))
{
// Assume a four-char code
return [NSString stringWithFormat:@"\'%@\' (%i)", FourCharCodeToNSString(inCode), inCode];
return [NSString stringWithFormat:@"\'%@\'", FourCharCodeToNSString(inCode)];
}
else
{