sounds in code ?

BlitzMax Forums/BlitzMax Programming/sounds in code ?

OK.. I think Im getting to grips with the Audio commands. Thanx again for the replies.. seems my problem is not as complex as I thought.. it was just I didnt understand what I was doing ( it happens a lot ).

Still.. just in case its of any help to anyone else who wants to create sounds in code heres my quick and dirty test code I knocked up tonight.

SuperStrict

Local sound:TSound

'sound = createsound(1,1,11025,100,100)
sound = createsound(1,8000,1000,100,0)

PlaySound(sound)

Input



Function createsound:TSound(duration:Float,startfrequency:Float,endfrequency:Float, startvolume:Float, endvolume:Float)
	Local sample:TAudioSample
	Local totalsamples:Int
	Local freqAngle:Float	
	Local volume:Float
	Local multiplier:Float
	Local k:Float
	Local angle:Float
	Local currentFreq:Float
		
	totalsamples = 11025*duration

	sample = CreateAudioSample( totalsamples,11025,SF_MONO8 )
	
	For k=0 Until totalsamples
		multiplier = k / totalsamples
		volume = ( startvolume - ( ( startvolume-endvolume ) * multiplier ) )  * 127.5 / 100
		
		currentFreq = startfrequency + ( ( endfrequency-startfrequency ) * multiplier )
		freqAngle = currentFreq/11025*180
		Print "freqangle ; " + freqangle
		angle :+ freqAngle
		angle = angle Mod 360

		sample.samples[k]=Sin(angle)*volume+127.5
	Next
	
	Local sound:TSound=LoadSound( sample,False )
	
	Return sound
End Function


This is basically the first part of what I was after.
Im not convinced the sound itself is actually the frequency of the sound but its good enough for now.
The createsound function will create a TSound. The first param is duration in seconds, then you supply start and end frequencie ( 0-11025 ) and start/end volume ( 0-100%).

Now I need a way of supplying a list of these params so I can create sounds made of any number of these chanks of sounds.

Maybe when I get that working I can apply effects to the sound... so I can do them there explosion sounds.