git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

commit 093998389c547e50f41fb3131136d0ecbc14bd39
parent 044196733218f66096ff6130200cb547f258ebcb
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Fri, 13 Jan 2023 17:24:28 +0200

"Port" GBAudioClient

Diffstat:
RCocoa/GBAudioClient.h -> AppleCommon/GBAudioClient.h0
AAppleCommon/GBAudioClient.m115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DCocoa/GBAudioClient.m111-------------------------------------------------------------------------------
MMakefile12++++++------
4 files changed, 121 insertions(+), 117 deletions(-)

diff --git a/Cocoa/GBAudioClient.h b/AppleCommon/GBAudioClient.h diff --git a/AppleCommon/GBAudioClient.m b/AppleCommon/GBAudioClient.m @@ -0,0 +1,115 @@ +#import <Foundation/Foundation.h> +#import <AudioToolbox/AudioToolbox.h> +#import "GBAudioClient.h" + +static OSStatus render( + GBAudioClient *self, + AudioUnitRenderActionFlags *ioActionFlags, + const AudioTimeStamp *inTimeStamp, + UInt32 inBusNumber, + UInt32 inNumberFrames, + AudioBufferList *ioData) + +{ + GB_sample_t *buffer = (GB_sample_t *)ioData->mBuffers[0].mData; + + self.renderBlock(self.rate, inNumberFrames, buffer); + + return noErr; +} + +@implementation GBAudioClient +{ + AudioComponentInstance audioUnit; +} + +-(id) initWithRendererBlock:(void (^)(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer)) block + andSampleRate:(UInt32) rate +{ + if (!(self = [super init])) { + return nil; + } + + // Configure the search parameters to find the default playback output unit + // (called the kAudioUnitSubType_RemoteIO on iOS but + // kAudioUnitSubType_DefaultOutput on Mac OS X) + AudioComponentDescription defaultOutputDescription; + defaultOutputDescription.componentType = kAudioUnitType_Output; +#if TARGET_OS_IPHONE + defaultOutputDescription.componentSubType = kAudioUnitSubType_RemoteIO; +#else + defaultOutputDescription.componentSubType = kAudioUnitSubType_DefaultOutput; +#endif + defaultOutputDescription.componentManufacturer = kAudioUnitManufacturer_Apple; + defaultOutputDescription.componentFlags = 0; + defaultOutputDescription.componentFlagsMask = 0; + + // Get the default playback output unit + AudioComponent defaultOutput = AudioComponentFindNext(NULL, &defaultOutputDescription); + NSAssert(defaultOutput, @"Can't find default output"); + + // Create a new unit based on this that we'll use for output + OSErr err = AudioComponentInstanceNew(defaultOutput, &audioUnit); + NSAssert1(audioUnit, @"Error creating unit: %hd", err); + + // Set our tone rendering function on the unit + AURenderCallbackStruct input; + input.inputProc = (void*)render; + input.inputProcRefCon = (__bridge void * _Nullable)(self); + err = AudioUnitSetProperty(audioUnit, + kAudioUnitProperty_SetRenderCallback, + kAudioUnitScope_Input, + 0, + &input, + sizeof(input)); + NSAssert1(err == noErr, @"Error setting callback: %hd", err); + + AudioStreamBasicDescription streamFormat; + streamFormat.mSampleRate = rate; + streamFormat.mFormatID = kAudioFormatLinearPCM; + streamFormat.mFormatFlags = + kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked | kAudioFormatFlagsNativeEndian; + streamFormat.mBytesPerPacket = 4; + streamFormat.mFramesPerPacket = 1; + streamFormat.mBytesPerFrame = 4; + streamFormat.mChannelsPerFrame = 2; + streamFormat.mBitsPerChannel = 2 * 8; + err = AudioUnitSetProperty (audioUnit, + kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Input, + 0, + &streamFormat, + sizeof(AudioStreamBasicDescription)); + NSAssert1(err == noErr, @"Error setting stream format: %hd", err); + err = AudioUnitInitialize(audioUnit); + NSAssert1(err == noErr, @"Error initializing unit: %hd", err); + + self.renderBlock = block; + _rate = rate; + + return self; +} + +-(void) start +{ + OSErr err = AudioOutputUnitStart(audioUnit); + NSAssert1(err == noErr, @"Error starting unit: %hd", err); + _playing = true; + +} + + +-(void) stop +{ + AudioOutputUnitStop(audioUnit); + _playing = false; +} + +-(void) dealloc +{ + [self stop]; + AudioUnitUninitialize(audioUnit); + AudioComponentInstanceDispose(audioUnit); +} + +@end diff --git a/Cocoa/GBAudioClient.m b/Cocoa/GBAudioClient.m @@ -1,111 +0,0 @@ -#import <Foundation/Foundation.h> -#import <AudioToolbox/AudioToolbox.h> -#import "GBAudioClient.h" - -static OSStatus render( - GBAudioClient *self, - AudioUnitRenderActionFlags *ioActionFlags, - const AudioTimeStamp *inTimeStamp, - UInt32 inBusNumber, - UInt32 inNumberFrames, - AudioBufferList *ioData) - -{ - GB_sample_t *buffer = (GB_sample_t *)ioData->mBuffers[0].mData; - - self.renderBlock(self.rate, inNumberFrames, buffer); - - return noErr; -} - -@implementation GBAudioClient -{ - AudioComponentInstance audioUnit; -} - --(id) initWithRendererBlock:(void (^)(UInt32 sampleRate, UInt32 nFrames, GB_sample_t *buffer)) block - andSampleRate:(UInt32) rate -{ - if (!(self = [super init])) { - return nil; - } - - // Configure the search parameters to find the default playback output unit - // (called the kAudioUnitSubType_RemoteIO on iOS but - // kAudioUnitSubType_DefaultOutput on Mac OS X) - AudioComponentDescription defaultOutputDescription; - defaultOutputDescription.componentType = kAudioUnitType_Output; - defaultOutputDescription.componentSubType = kAudioUnitSubType_DefaultOutput; - defaultOutputDescription.componentManufacturer = kAudioUnitManufacturer_Apple; - defaultOutputDescription.componentFlags = 0; - defaultOutputDescription.componentFlagsMask = 0; - - // Get the default playback output unit - AudioComponent defaultOutput = AudioComponentFindNext(NULL, &defaultOutputDescription); - NSAssert(defaultOutput, @"Can't find default output"); - - // Create a new unit based on this that we'll use for output - OSErr err = AudioComponentInstanceNew(defaultOutput, &audioUnit); - NSAssert1(audioUnit, @"Error creating unit: %hd", err); - - // Set our tone rendering function on the unit - AURenderCallbackStruct input; - input.inputProc = (void*)render; - input.inputProcRefCon = (__bridge void * _Nullable)(self); - err = AudioUnitSetProperty(audioUnit, - kAudioUnitProperty_SetRenderCallback, - kAudioUnitScope_Input, - 0, - &input, - sizeof(input)); - NSAssert1(err == noErr, @"Error setting callback: %hd", err); - - AudioStreamBasicDescription streamFormat; - streamFormat.mSampleRate = rate; - streamFormat.mFormatID = kAudioFormatLinearPCM; - streamFormat.mFormatFlags = - kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked | kAudioFormatFlagsNativeEndian; - streamFormat.mBytesPerPacket = 4; - streamFormat.mFramesPerPacket = 1; - streamFormat.mBytesPerFrame = 4; - streamFormat.mChannelsPerFrame = 2; - streamFormat.mBitsPerChannel = 2 * 8; - err = AudioUnitSetProperty (audioUnit, - kAudioUnitProperty_StreamFormat, - kAudioUnitScope_Input, - 0, - &streamFormat, - sizeof(AudioStreamBasicDescription)); - NSAssert1(err == noErr, @"Error setting stream format: %hd", err); - err = AudioUnitInitialize(audioUnit); - NSAssert1(err == noErr, @"Error initializing unit: %hd", err); - - self.renderBlock = block; - _rate = rate; - - return self; -} - --(void) start -{ - OSErr err = AudioOutputUnitStart(audioUnit); - NSAssert1(err == noErr, @"Error starting unit: %hd", err); - _playing = true; - -} - - --(void) stop -{ - AudioOutputUnitStop(audioUnit); - _playing = false; -} - --(void) dealloc -{ - [self stop]; - AudioUnitUninitialize(audioUnit); - AudioComponentInstanceDispose(audioUnit); -} - -@end diff --git a/Makefile b/Makefile @@ -183,10 +183,10 @@ SYSROOT := $(shell xcodebuild -sdk iphoneos -version Path 2> $(NULL)) ifeq ($(SYSROOT),) $(error Could not find an iOS SDK) endif -CFLAGS += -arch arm64 -miphoneos-version-min=11.0 -isysroot $(SYSROOT) +CFLAGS += -arch arm64 -miphoneos-version-min=11.0 -isysroot $(SYSROOT) -IAppleCommon LDFLAGS += -arch arm64 OCFLAGS += -x objective-c -fobjc-arc -Wno-deprecated-declarations -isysroot $(SYSROOT) -LDFLAGS += -lobjc -framework UIKit -framework Foundation -framework CoreGraphics -framework Metal -framework MetalKit -framework AVFoundation -miphoneos-version-min=11.0 -isysroot $(SYSROOT) +LDFLAGS += -lobjc -framework UIKit -framework Foundation -framework CoreGraphics -framework Metal -framework MetalKit -framework AudioToolbox -framework AVFoundation -miphoneos-version-min=11.0 -isysroot $(SYSROOT) CODESIGN := codesign -fs - else ifeq ($(PLATFORM),Darwin) @@ -198,7 +198,7 @@ ifeq ($(SYSROOT),/Library/Developer/CommandLineTools/SDKs/) $(error Could not find a macOS SDK) endif -CFLAGS += -F/Library/Frameworks -mmacosx-version-min=10.9 -isysroot $(SYSROOT) +CFLAGS += -F/Library/Frameworks -mmacosx-version-min=10.9 -isysroot $(SYSROOT) -IAppleCommon OCFLAGS += -x objective-c -fobjc-arc -Wno-deprecated-declarations -isysroot $(SYSROOT) LDFLAGS += -framework AppKit -mmacosx-version-min=10.9 -isysroot $(SYSROOT) GL_LDFLAGS := -framework OpenGL @@ -255,8 +255,8 @@ all: cocoa sdl tester libretro CORE_SOURCES := $(shell ls Core/*.c) SDL_SOURCES := $(shell ls SDL/*.c) $(OPEN_DIALOG) $(patsubst %,SDL/audio/%.c,$(SDL_AUDIO_DRIVERS)) TESTER_SOURCES := $(shell ls Tester/*.c) -IOS_SOURCES := $(shell ls iOS/*.m) -COCOA_SOURCES := $(shell ls Cocoa/*.m) $(shell ls HexFiend/*.m) $(shell ls JoyKit/*.m) +IOS_SOURCES := $(shell ls iOS/*.m) $(shell ls AppleCommon/*.m) +COCOA_SOURCES := $(shell ls Cocoa/*.m) $(shell ls HexFiend/*.m) $(shell ls JoyKit/*.m) $(shell ls AppleCommon/*.m) QUICKLOOK_SOURCES := $(shell ls QuickLook/*.m) $(shell ls QuickLook/*.c) ifeq ($(PLATFORM),windows32) @@ -385,7 +385,7 @@ endif $(BIN)/SameBoy.app/Contents/MacOS/SameBoy: $(CORE_OBJECTS) $(COCOA_OBJECTS) -@$(MKDIR) -p $(dir $@) - $(CC) $^ -o $@ $(LDFLAGS) $(FAT_FLAGS) -framework OpenGL -framework AudioUnit -framework AVFoundation -framework CoreVideo -framework CoreMedia -framework IOKit -framework PreferencePanes -framework Carbon -framework QuartzCore -framework Security -framework WebKit -weak_framework Metal -weak_framework MetalKit + $(CC) $^ -o $@ $(LDFLAGS) $(FAT_FLAGS) -framework OpenGL -framework AudioToolbox -framework AVFoundation -framework CoreVideo -framework CoreMedia -framework IOKit -framework PreferencePanes -framework Carbon -framework QuartzCore -framework Security -framework WebKit -weak_framework Metal -weak_framework MetalKit ifeq ($(CONF), release) $(STRIP) $@ endif

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.