#define RAUDIO_STANDALONE
Import "Raylib\src\raudio.c"Extern Function IsAudioDeviceReady%() Function InitAudioDevice() Function CloseAudioDevice() Function IsAudioBufferProcessed:Int(stream:AudioStream) '// Check If any audio stream buffers requires refill Function PlayAudioStream(stream:AudioStream) '// Play audio stream Function InitAudioStream:AudioStream(sampleRate:UInt, sampleSize:UInt, channels:UInt) '// Init audio stream (To stream raw audio pcm data) Function UpdateAudioStream(stream:AudioStream, Data:Byte Ptr, samplesCount:Int) '// Update audio stream buffers with data Function SetMasterVolume(volume:Float)EndExtern
Rem Audio streaming with 'Raylib Audio' Example 2019 A.Woodard "GW"EndremSuperStrictFramework brl.basic Import brl.glmax2dImport "C:\Dev\temp\Raylib\src\raudio.c"Extern Function IsAudioDeviceReady%() Function InitAudioDevice() Function CloseAudioDevice() Function IsAudioBufferProcessed:Int(stream:AudioStream) '// Check If any audio stream buffers requires refill Function PlayAudioStream(stream:AudioStream) '// Play audio stream Function InitAudioStream:AudioStream(sampleRate:UInt, sampleSize:UInt, channels:UInt) '// Init audio stream (To stream raw audio pcm data) Function UpdateAudioStream(stream:AudioStream, Data:Byte Ptr, samplesCount:Int) '// Update audio stream buffers with data Function SetMasterVolume(volume:Float)EndExternStruct AudioStream Field sampleRate:UInt '// Frequency (samples per second) Field sampleSize:UInt '// Bit depth (bits per sample): 8, 16, 32 (24 Not supported) Field channels:UInt '// Number of channels (1-mono, 2-stereo) Field audioBuffer:Byte Ptr '// Pointer To internal data used by the audio system. Field format% '// Audio format specifier Field source% '// Audio source id Field buffers%[2] '// Audio buffers (Double buffering)End Struct'--------------------------------START-----------------------------------------------AppTitle = "RayLib realtime audio streaming"Graphics 1024, 500SetLineWidth(1.5)InitAudioDevice()If Not IsAudioDeviceReady() RuntimeError("No Audio")EndIfOnEnd(CloseAudioDevice)Const BUFFERSIZE:Int = 2048Global mystream:AudioStream = InitAudioStream(44100, 32, 1) ; '// Create the audio stream Global a_writebuff:Float[BUFFERSIZE] '// create a buffer and a pointer to the bufferGlobal writeBuf:Float Ptr = VarPtr a_writebuff[0]Global Time:Float = 0Const TWOPI:Double = Pi * 2PlayAudioStream(mystream) '// Start playingSetMasterVolume(0.25) '// easy on the earsPrint "Starting!"Const FRQ:Float = 107.66Global phase:FloatWhile True If KeyHit(KEY_ESCAPE) Then End Local buffproc:Int = IsAudioBufferProcessed(mystream) '// if the sound card wants more data this is true If buffproc Then For Local i:Int = 0 Until BUFFERSIZE '// Get waveform phase:+FRQ * (TWOPI / mystream.samplerate) If phase > Pi Then phase:-TWOPI Local x:Float = sw(FRQ, phase) 'calc audio data '//Mod w/mouse x:*Float(MouseY()) / GraphicsHeight() '// change volume by MouseY Local yy:Float = Float(MouseX()) / GraphicsWidth() '// change gain by MouseX If Abs(x * (yy)) > 0.5 Then x = Sine(-x) '//fold distortion '//write to buffer a_writebuff[i] = x * 0.25 Next UpdateAudioStream(mystream, writeBuf, BUFFERSIZE) '// tell raylib to use the new buffer Draw EndIfWend'--------------------------------------------------------------------------------------------------------------------------- Function Draw() Local y:Float Local y2:Float Local t:Int = 0 For Local i:Int = 0 Until BUFFERSIZE Step 2 y = y2 y2 = 250 + (a_writebuff[i] * 500) DrawLine(i / 2, y, i / 2, y2) Next Flip Cls Time:+1End Function'---------------------------------------------------------------------------------------------------------------------------Function Sine:Double(x:Double) Return Sin(x / (Pi / 180.0))End Function'---------------------------------------------------------------------------------------------------------------------------Function sw:Float(f:Float, ph:Float) Local i:Float = 1, x:Float While (f * i) < (4000 * (1.1 + Sin(Time * 4))) x:+(Sine(ph * i) * (1.0 / i)) i:+1 + Abs(Sine(Time / 10)) Wend Return xEnd Function'---------------------------------------------------------------------------------------------------------------------------
Is that vanilla BMAX or NG?
Hi GW,nice example and presentation. Good job Upon further examination, Raylib seems like a minimalist all-in-one solution for simple game development, where the audio portion is a wrapper for underline miniaudio library.Miniaudio itself seems like a useful library with support for playback, decode, streaming and capture. I think Bmax is missing a comprehensive audio package at the moment, that is up-to-date, fully supported with the ability to playback and record.Also, I like to standalone approach, with no dependencies, and a supportive license. Very Blitzlike :-)-Henri
I've been looking at a direct miniAudio implementation, but haven't had the time recently to work on it.