Created
April 5, 2019 22:53
-
-
Save paniq/a44a6ea103693192bb7fbfe18c8e1792 to your computer and use it in GitHub Desktop.
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 ..tukan.audio | |
using import ..tukan.sdl | |
using import itertools | |
let audio = tukan.audio | |
let BUFFERSIZE = 256 | |
let NUMBUFFERS = 2 | |
inline audio-queue (srate) | |
Collector | |
inline () 0:u32 | |
inline (t) true | |
inline (t) t | |
inline (src t) | |
let buf n = (src) | |
if (t != 0:u32) | |
# wait for buffer to drain | |
while ((audio.queued) > ((NUMBUFFERS * n) as f32)) | |
SDL_Delay 0 | |
audio.queue buf n | |
if (t == 0:u32) | |
audio.play true | |
t + 1:u32 | |
inline audio-buffer-sink (samplecount) | |
let samples = (alloca-array f32 (2 * samplecount)) | |
Collector | |
inline () 0 | |
inline (n) (n < samplecount) | |
inline (n) | |
_ samples n | |
inline (src n) | |
let s = (src) | |
samples @ (n * 2) = s.x | |
samples @ (n * 2 + 1) = s.y | |
n + 1 | |
inline test-audio (f opts...) | |
""""f must return a collector that receives the current sample index | |
and writes a vec2 | |
let total-time = (va-option time opts... 3600) | |
SDL_Init SDL_INIT_AUDIO | |
let samples = (BUFFERSIZE * NUMBUFFERS) | |
audio.init (samples = samples) | |
print "buffersize:" (deref audio.buffersize) | |
->> (range (audio.samplerate * total-time)) | |
f audio.samplerate | |
cascade | |
audio-buffer-sink BUFFERSIZE | |
audio-queue audio.samplerate | |
audio.play-until-empty; | |
audio.exit; | |
SDL_Quit; | |
do | |
let test-audio | |
locals; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment