Another sound question

BlitzMax Forums/BlitzMax Beginners Area/Another sound question

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hi gang,

You have no idea how frustrating this is for a casual programmer like myself. Why doesn't Blitz have better sound commands?

What I'm trying to do is just play simple sounds, maybe two or three notes at a time. I'm not interested in loading WAV files or OGG or anything like that, I want the computer just to beep and boop on que.

Here's my code so far:

Global duration:Int=0
Global note:Int=0

Graphics 640,480,0
Playnote(0,100)
WaitKey
End

Function PlayNote(note,duration)
Local sample1:TAudioSample=CreateAudioSample( 16,13675,SF_MONO8 )
For Local k=0 Until 32
sample1.samples[k]=Sin(k*360/32)*127.5+127.5+note
Next
Local sound1:TSound=LoadSound( sample1,True )

timer=CreateTimer(20)
channel=AllocChannel()

PlaySound sound1,channel

For i=1 To duration; WaitTimer timer; Next
StopChannel channel
End Function


Basically, it works...but it sounds awful. How do I get a pure note, middle C? From there I can step backwards and forwards thru the musical scale.

Here's a formula that I found on the web: amplitude * SIN( 360 * time / period ). That's great, but I'm an idiot on some topics and implementing this is bumping up against my dummy regions.

P.S. Ultimately I'd like to create a function that works like the old Atari SOUND command (SOUND voice, pitch, distortion, loudness)