How to stream sounds?

BlitzMax Forums/BlitzMax Programming/How to stream sounds?

Tibit(Posted 2005) [#1]
If it is possible then I think we have Voice Chat =)

But I have no idea of how streaming of sounds or music work. Any who knows? Anyone got resources/links?


Tibit(Posted 2005) [#2]
I've manage to sample the sounds. I can get a certain byte number of the sound and play it (Tested with a wav file). But I don't know how to read 1..10 then 10..20 and then 30..40 and so on.

I need to chop the sound into samples. Then add the samples together into the same sound. The idea is to do this continually so what you hear is what they play.



'AudioStreaming
Strict 

Graphics 100,20,0

Global Audio:TAudioSample
Global Sample:TAudioSample
Global Sound:TSound
Global Music:TChannel
Audio = LoadAudioSample( "hybrid.wav" )


	Local hertz = 44100'Samle speed
	Local readSize = 20000 '2
	
	Repeat' This loop does not work!?!
	
		Sample1 = CreateStaticAudioSample( Audio.Samples		 , readSize, hertz, SF_STEREO16LE )
		Sample2 = CreateStaticAudioSample( Audio.Samples[readSize], readSize, hertz, SF_STEREO16LE )
		Sample3 = CreateStaticAudioSample( Audio.Samples[readSize*2], readSize, hertz, SF_STEREO16LE )
		'Audio.Samples:+readSize
	Until readsize = 20000*3 '0.2MB
		
	Sound = LoadSound( Sample , False )
	If Sound Music = PlaySound( Sound, Music ); DebugLog "PLAY!" Else DebugLog "PLAY FAILED!"
	
	While ChannelPlaying(Music) ;Wend


I don't know how Byte Pointers work and I imagine that's the problem. Right now I kinda hate them, at least a little.
The CreateAudioSample wants a byte Ptr. The LoadAudioSample returns a TAudioSample which has a field called samples which contains a byte ptr so it fits, kinda.

LoadSound works on a sample so if I just could send the Audio.Samples bytes (which is no problem). Perhaps I need to work with Streams. Because the pointer in a stream is moved while you read it if I'm right.

Please! Help!


Tibit(Posted 2005) [#3]
Is it impossible to do this from BlitzMax? How do I access some external libraries to get the mic anyway? How am I supposed to divide the sample up in good byte parts [Send] and [RECEIVE] then resemble them?