Category: Audio
Syntax:
audCreateStream:Int(rate:Int, channels:Int)
Int
Starts a stream of raw sound samples that the program supplies itself. Returns the stream's handle.
Creates a stream playing at rate samples a second (44100 for CD quality) with 1 (mono) or 2 (stereo) channels, and starts it playing straight away. Feed it 16-bit samples with audQueueStream. While nothing is queued it plays silence, and it carries on when more arrives.
It's for sound the program makes as it goes: a synthesiser, an emulator's sound chip, a tracker player. Returns 0 if the rate isn't between 1000 and 192000, channels isn't 1 or 2, or the audio couldn't start. Free it with audFreeStream.
View detailed documentation online
Global buf:Short[4410]
Function Main()
Local s:Int = audCreateStream(44100, 2)
Local i:Int, v:Int, phase:Int
Local t0:Int = sysMillisecs()
While sysMillisecs() - t0 < 3000 ; 3 seconds of a 441 Hz square wave
If audStreamQueued(s) < 4410 Then
For i = 0 To 2204
v = ((phase / 50) Mod 2) * 8000 - 4000
buf[i * 2] = v ; left
buf[i * 2 + 1] = v ; right
phase = phase + 1
Next
audQueueStream(s, buf, 4410)
EndIf
Wend
audFreeStream(s)
Return False
EndFunction
BambooBasic © 2026 Michael Denathorn