This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
^(int d1, int(^c2)(void)) | |
{ | |
return c2; | |
} (^(int c1) | |
{ | |
return c1; | |
} (^(int b1) | |
{ | |
return b1; | |
} (a1)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double (^normalize)(double, double, double) = ^double(double min, double max, double value) | |
{ | |
double result = (value - min) / (max - min); | |
return result; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double (^scale)(double, double, double, double, double) = ^double(double min_new, double max_new, double value, double min_old, double max_old) | |
{ | |
double result = min_new + ((((value - min_old) * (max_new - min_new))) / (max_old - min_old)); | |
return result; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AVAudioPCMBuffer * (^bufferSamples)(AVAudioFrameCount, AVAudioChannelCount, AVAudioFormat *, double) = ^AVAudioPCMBuffer *(AVAudioFrameCount frame_count, AVAudioChannelCount channel_count, AVAudioFormat *audioFormat, double duration_n_secs) | |
{ | |
AVAudioFrameCount frameCount = audioFormat.sampleRate * duration; | |
AVAudioPCMBuffer *pcmBuffer = [[AVAudioPCMBuffer alloc] initWithPCMFormat:audioFormat frameCapacity:frameCount]; | |
pcmBuffer.frameLength = frameCount; | |
float *left_channel = pcmBuffer.floatChannelData[0]; | |
float *right_channel = (channelCount == 2) ? pcmBuffer.floatChannelData[1] : nil; | |
int amplitude_frequency = arc4random_uniform(8) + 4; | |
for (int index = 0; index < frame_count; index++) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef Math_h | |
#define Math_h | |
#include <stdarg.h> | |
#include <stdio.h> | |
#include <stddef.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
// A block that performs a given mathematical operation, encapsulated in a struct |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A "base struct" from which other "substructs" will inherit | |
typedef struct { | |
int value; | |
} base_struct; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef void (^PlayedToneCompletionBlock)(void); | |
typedef void (^BufferRenderedCompletionBlock)(AVAudioPlayerNode * _Nonnull player_node, AVAudioPCMBuffer * _Nonnull buffer, PlayedToneCompletionBlock _Nonnull playedToneCompletionBlock); | |
static void(^createAudioBuffer)(AVAudioPlayerNode *, AVAudioSession *, AVAudioFormat *, BufferRenderedCompletionBlock) = ^(AVAudioPlayerNode * player_node, AVAudioSession * audioSession, AVAudioFormat * audioFormat, BufferRenderedCompletionBlock bufferRenderedCompletionBlock) | |
{ | |
// playerNode buffer scheduler goes here | |
[player_node scheduleBuffer:^AVAudioPCMBuffer * (void (^buffer_sample)(AVAudioFrameCount, double, double, double, float *, AVAudioChannelCount)) | |
{ | |
double duration = random_source_drand48(0.25, 1.75);; | |
AVAudioFrameCount frameCount = ([audioFormat sampleRate] * duration); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prints 'x = 2.0' to the Console log | |
#import "custom_dispatch_source.h" | |
typedef struct ContextData | |
{ | |
double x; | |
} ContextData; | |
@interface custom_dispatch_source () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef CMTime(^CurrentCMTime)(void); | |
static CurrentCMTime _Nonnull current_cmtime = ^ CMTime (void) { | |
return CMClockGetTime(CMClockGetHostTimeClock()); | |
}; | |
typedef NSString * _Nonnull (^StringFromTime)(CMTime); | |
static StringFromTime _Nonnull cmTimeString = ^ NSString * (CMTime cm_time) { | |
NSString *stringFromCMTime; | |
float seconds = round(CMTimeGetSeconds(cm_time)); | |
int hh = (int)floorf(seconds / 3600.0f); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension Double { | |
var radians: Double { return Measurement(value: self, unit: UnitAngle.degrees).converted(to: UnitAngle.radians).value } | |
var degrees: Double { return Measurement(value: self, unit: UnitAngle.radians).converted(to: UnitAngle.degrees).value } | |
} |
OlderNewer