Last active
December 2, 2023 03:02
-
-
Save theoknock/a552a68efb492b217d2d5c49840cb6d8 to your computer and use it in GitHub Desktop.
...
This file contains hidden or 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
static void (^generate_samples)(AVAudioFrameCount); | |
static void (^(^sample_generator)(const AVAudioFrameCount *))(const AVAudioFrameCount) = ^ (const AVAudioFrameCount * samples_t) { | |
static AVAudioFramePosition sample; | |
static AVAudioFramePosition * sample_t = &sample; | |
return ^ (AVAudioFrameCount frames) { | |
for (AVAudioFramePosition frame = 0; frame < frames; frame++, (*sample_t)++) { | |
(*sample_t = ((((*sample_t - *samples_t) >> (WORD_BIT - 1)) & (*sample_t ^ 0)) ^ 0)); | |
printf("Frame %lld out of %u frames\n", -~frame, frames); | |
} | |
printf("Sampled %lld out of %u samples\n\n", *sample_t, *samples_t); | |
}; | |
}; | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
AVAudioFrameCount samples = 30; | |
generate_samples = sample_generator((AVAudioFrameCount *)&samples); | |
generate_samples(10); | |
generate_samples(10); | |
generate_samples(10); | |
generate_samples(2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Console output:
Frame 1 out of 10 frames
Frame 2 out of 10 frames
Frame 3 out of 10 frames
Frame 4 out of 10 frames
Frame 5 out of 10 frames
Frame 6 out of 10 frames
Frame 7 out of 10 frames
Frame 8 out of 10 frames
Frame 9 out of 10 frames
Frame 10 out of 10 frames
Sampled 10 out of 30 samples
Frame 1 out of 10 frames
Frame 2 out of 10 frames
Frame 3 out of 10 frames
Frame 4 out of 10 frames
Frame 5 out of 10 frames
Frame 6 out of 10 frames
Frame 7 out of 10 frames
Frame 8 out of 10 frames
Frame 9 out of 10 frames
Frame 10 out of 10 frames
Sampled 20 out of 30 samples
Frame 1 out of 10 frames
Frame 2 out of 10 frames
Frame 3 out of 10 frames
Frame 4 out of 10 frames
Frame 5 out of 10 frames
Frame 6 out of 10 frames
Frame 7 out of 10 frames
Frame 8 out of 10 frames
Frame 9 out of 10 frames
Frame 10 out of 10 frames
Sampled 30 out of 30 samples
Frame 1 out of 2 frames
Frame 2 out of 2 frames
Sampled 2 out of 30 samples