Ooops
May 27, 2022, 03:27:46

Author Topic: Easy Blitzmax Streaming realtime audio with Raylib  (Read 4156 times)

Offline GW

  • Sr. Member
  • ****
  • Posts: 266
Re: Easy Blitzmax Streaming realtime audio with Raylib
« Reply #15 on: May 08, 2022, 09:32:16 »
It's hard to understand what you're doing and what problems you're having. 
You said that your audio stream is setup to process 16bit, 2 channel audio. In that case you'll need to write short (2-byte) values to the buffer.
It would probably be best to create a short pointer to the buffer array to make writing easier.  the audio values are written in a left-channel, right-channel, left-channel... of short values. 

Offline mainsworthy

  • Sr. Member
  • ****
  • Posts: 263
Re: Easy Blitzmax Streaming realtime audio with Raylib
« Reply #16 on: May 08, 2022, 19:40:22 »
sorry I missed your reply before I posted  how do i set the channel position, this seems to be whats going wrong there is there  some sort of command like  fa_ChannelPosition(channel) to set the read  position of the audio player , or can i only read it?

.
OK, The sliders are position and value on each slider, got that

Im filling the buffer every time I have played a bufffer full, got that

the tune Im hearing seems to happen when I run out of data to fill buffer, kinda default driver tune.

but I still dont hear the buffer, to I need to do some math on the buffer data prior to putting it in bufffer like  Value%=Abs(Test.samples-127)

any help would be great!, but Im learning, I learn slow but once i know i know forever, never done audio its unbelievable, but fun
« Last Edit: May 08, 2022, 21:14:34 by mainsworthy »

Offline GW

  • Sr. Member
  • ****
  • Posts: 266
Re: Easy Blitzmax Streaming realtime audio with Raylib
« Reply #17 on: May 08, 2022, 21:18:44 »
Are you generating audio to play or are you playing audio from a file?

Offline mainsworthy

  • Sr. Member
  • ****
  • Posts: 263
Re: Easy Blitzmax Streaming realtime audio with Raylib
« Reply #18 on: May 08, 2022, 21:31:05 »
Are you generating audio to play or are you playing audio from a file?

im trying to fill the buffer with a 2 channel 16bit audio stream and then play it, I am so new to this audio stuff. i know its 44 byte header aswell but after 10 cycles it would be ok anyway.   I know this is wrong buffer[Pos + fq] = GetAudio() * 30000  i need to set to begining or something, just realised its streaming so you cant set the position , its continouse

If fill = 1
   Local readpos:Int = fa_ChannelPosition(channel)
   Local Write:Int = readpos + FRAG * 1 - writepos
   Local frags:Int = Write / FRAG
   
      While frags > 0
       Pos = writepos Mod (FRAG * 8)

      For fq = 0 Until FRAG * 8
      If aut+(Pos) < end of wav -4
      buffer[Pos+fq] = modstore[aut+fq]
      aut = aut + 1
      buffer[Pos+fq+1] = modstore[aut+fq]
      aut = aut + 1
 buffer[Pos+fq+2] = modstore[aut+fq]
      aut = aut + 1
   buffer[Pos+fq+3] = modstore[aut+fq]
      aut = aut + 1
      
    buffer[Pos + fq] = GetAudio() * 30000

         EndIf
      Next
   
      writepos:+FRAG
      frags:-1
   Wend
'score = 0

fill = 0

Return
EndIf
« Last Edit: May 08, 2022, 21:40:29 by mainsworthy »

Offline GW

  • Sr. Member
  • ****
  • Posts: 266
Re: Easy Blitzmax Streaming realtime audio with Raylib
« Reply #19 on: May 08, 2022, 22:12:44 »
Here is an basic example that uses the Raylib mod with the audio to stream for a 16bit stereo file.
The raylib drawing stuff is not needed to use the audio library. 
I would recommend that you make the most basic program you can to confirm that the streaming works correctly, then work on the other stuff.
Sample audio file can be downloaded here: http://www.gutterbox.com/download/sample.wav

Code: [Select]
SuperStrict
Framework brl.basic
Import brl.retro
Import ray.lib
Import ray.audio

Const BUFFERSIZE:Int = 2048 * 2

'// The Raylib drawing routines are optional.

InitWindow(500, 500, "stream")
InitAudioDevice()

Global my_stream:RAudioStream = InitAudioStream(44100, 16, 2)

Global a_writebuff:Short[BUFFERSIZE * 2]         
Global writeBuf:Short Ptr = Varptr a_writebuff[0]
Global BufPtr%
Global song:RWave = LoadWave("sample.wav")
Global songPtr:Short Ptr = song.Data

PlayAudioStream(my_stream)

SetMasterVolume(0.33)

While Not WindowShouldClose()
BeginDrawing()
ClearBackground(Black)

'// Audio stuff here //
'/////////
Local buffproc:Int = IsAudioStreamProcessed(my_stream) '// audio stream wants more data
If buffproc Then
For Local i:Int = 0 Until BUFFERSIZE * 2 Step 2
writeBuf[i] = songPtr[BufPtr]
writeBuf[i + 1] = songPtr[BufPtr + 1]
BufPtr:+2

BufPtr:Mod song.sampleCount*2
Next
UpdateAudioStream(my_stream, writeBuf, BUFFERSIZE * 2)
End If
'/////////

DrawText("song ptr: "+String(Int(BufPtr)), 10,10,20,Gray)
EndDrawing()
Wend



Offline mainsworthy

  • Sr. Member
  • ****
  • Posts: 263
Re: Easy Blitzmax Streaming realtime audio with Raylib
« Reply #20 on: May 08, 2022, 22:50:39 »
Here is an basic example that uses the Raylib mod with the audio to stream for a 16bit stereo file.
The raylib drawing stuff is not needed to use the audio library. 
I would recommend that you make the most basic program you can to confirm that the streaming works correctly, then work on the other stuff.
Sample audio file can be downloaded here: http://www.gutterbox.com/download/sample.wav

Code: [Select]
SuperStrict
Framework brl.basic
Import brl.retro
Import ray.lib
Import ray.audio

Const BUFFERSIZE:Int = 2048 * 2

'// The Raylib drawing routines are optional.

InitWindow(500, 500, "stream")
InitAudioDevice()

Global my_stream:RAudioStream = InitAudioStream(44100, 16, 2)

Global a_writebuff:Short[BUFFERSIZE * 2]         
Global writeBuf:Short Ptr = Varptr a_writebuff[0]
Global BufPtr%
Global song:RWave = LoadWave("sample.wav")
Global songPtr:Short Ptr = song.Data

PlayAudioStream(my_stream)

SetMasterVolume(0.33)

While Not WindowShouldClose()
BeginDrawing()
ClearBackground(Black)

'// Audio stuff here //
'/////////
Local buffproc:Int = IsAudioStreamProcessed(my_stream) '// audio stream wants more data
If buffproc Then
For Local i:Int = 0 Until BUFFERSIZE * 2 Step 2
writeBuf[i] = songPtr[BufPtr]
writeBuf[i + 1] = songPtr[BufPtr + 1]
BufPtr:+2

BufPtr:Mod song.sampleCount*2
Next
UpdateAudioStream(my_stream, writeBuf, BUFFERSIZE * 2)
End If
'/////////

DrawText("song ptr: "+String(Int(BufPtr)), 10,10,20,Gray)
EndDrawing()
Wend


Thanks GW im on it now.

Offline mainsworthy

  • Sr. Member
  • ****
  • Posts: 263
Re: Easy Blitzmax Streaming realtime audio with Raylib
« Reply #21 on: May 09, 2022, 01:10:26 »
GW , its quite and a little slow, but I can now hear a Wav file, Thankyou so much. its all downhill from here

Offline Midimaster

  • Hero Member
  • *****
  • Posts: 638
    • Midimaster Music Education Software
Re: Easy Blitzmax Streaming realtime audio with Raylib
« Reply #22 on: May 09, 2022, 07:09:37 »
...back from africa

Offline mainsworthy

  • Sr. Member
  • ****
  • Posts: 263
Re: Easy Blitzmax Streaming realtime audio with Raylib
« Reply #23 on: May 09, 2022, 12:21:18 »


https://agamecreator.itch.io/the-search-for-extra-terrestrials-program   here is the link if you want to try it

Thanks MidiMaster, I cant believe it , I have been watching the Carrier signal play a tune, and I thought it was my Wav files, cant believe it, I learned so much. I would love to know how you stop a channel and restart it with the same name. I can stopchannel but it wont restart. any help will be grately recieved

I have discovered a new geek hobby, "The Search For Extra Terrestrial Inteligence" its great fun

« Last Edit: May 10, 2022, 02:18:33 by mainsworthy »

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal