Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am tkemp on github.
  • I am timkemp (https://keybase.io/timkemp) on keybase.
  • I have a public key ASDYIE8BXfz6QnylI0N5fE0CBNafD80Gr5FWOWqXfb9_vAo

To claim this, I am signing this object:

@tkemp
tkemp / iOSASBD.c
Created December 11, 2012 20:53
ASBD for iOS native/canonical
AudioStreamBasicDescription _outputASBD;
memset(&_outputASBD, 0, sizeof(_outputASBD));
_outputASBD.mSampleRate = 44100.0;
_outputASBD.mFormatID = kAudioFormatLinearPCM;
_outputASBD.mFormatFlags = kAudioFormatFlagsCanonical; // Equivalent to kAudioFormatFlagIsSignedInteger | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked
_outputASBD.mBytesPerPacket = 2 * 2;
_outputASBD.mBytesPerFrame = 2 * 2;
_outputASBD.mFramesPerPacket = 1;
_outputASBD.mChannelsPerFrame = 2;
_outputASBD.mBitsPerChannel = 16;
@tkemp
tkemp / SetStreamFormat.c
Created December 11, 2012 20:51
Set AudioFilePlayer AU stream format
// Get the ASBD from the player unit
UInt32 playerASBDsz;
checkError(AudioUnitGetProperty(_playerUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
BUS_PLAYER_OUTPUT,
&_playerASBD,
&playerASBDsz),
"AudioUnitSetProperty failed: getting stream format from the player unit", false);
@tkemp
tkemp / AvailableASBDs.c
Created December 9, 2012 18:12
Get details on available AudioStreamBasicDescriptions for various file formats
void AUM_printAvailableStreamFormatsForId(AudioFileTypeID fileTypeID, UInt32 mFormatID)
{
AudioFileTypeAndFormatID fileTypeAndFormat;
fileTypeAndFormat.mFileType = fileTypeID;
fileTypeAndFormat.mFormatID = mFormatID;
UInt32 fileTypeIDChar = CFSwapInt32HostToBig(fileTypeID);
UInt32 mFormatChar = CFSwapInt32HostToBig(mFormatID);
OSStatus audioErr = noErr;
UInt32 infoSize = 0;
@tkemp
tkemp / PrintASBD.m
Created December 6, 2012 17:08
Print an AudioStreamBasicDescription for a given AUGraph node
-(void) printASBDforNode:(AUNode) node scope:(int) scope bus:(int) bus {
AudioStreamBasicDescription testASBD;
UInt32 asbdSize = sizeof (AudioStreamBasicDescription);
AudioUnit nodeUnit;
AUGraphNodeInfo(_graph, node, NULL, &nodeUnit);
AudioUnitGetProperty(nodeUnit,
kAudioUnitProperty_StreamFormat,
scope,
bus, // bus
@tkemp
tkemp / gist:3912342
Created October 18, 2012 14:50
Get Mail.app subject and message URL in a drag/drop operation
// In init or wherever:
[self registerForDraggedTypes:
[NSArray arrayWithObjects:@"public.url-name",nil]];
// In performDragOperation:
NSString * subject = [[sender draggingPasteboard] stringForType:@"public.url-name"];
NSURL * url = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
@tkemp
tkemp / SMImpl.cpp
Created October 10, 2012 16:38
Simple C++ State machine implementation
// The transition table itself
SMTransition MyClass::transitionTable[] = {
{ SMStateStart, SMEventAlpha, &MyClass::transToOne },
{ SMStateStart, SMEventBeta, &MyClass::transToTwo },
...
{ SMStateAny, SMEventAnyEvent, &MyClass::transDoNothing }
};
// Macro to give us the number of transitions in the table
#define TR_COUNT (sizeof(transitionTable) / sizeof(*transitionTable))
@tkemp
tkemp / SMHeader.h
Created October 10, 2012 16:07
Simple C++ State machine header
class MyClass;
typedef enum SMState {
SMStateStart,
SMStateOne,
SMStateTwo,
SMStateFinal,
SMStateAny
} SMState;