Basic Sound for FreeBasic
Basic Sound for FreeBasic
deleted
Last edited by KLBear on Mar 16, 2022 4:27, edited 1 time in total.
Re: Basic Sound for FreeBasic
Hi KLBEAR
Yes, I used this thing in pinball maths, a final run, but it invokes the motherboard speaker I believe, and laptops, among others, can't use it.
I dug it up from somewhere else in the forums, or QB, I can't remember.
But for some it's a handy little sub.
Yes, I used this thing in pinball maths, a final run, but it invokes the motherboard speaker I believe, and laptops, among others, can't use it.
I dug it up from somewhere else in the forums, or QB, I can't remember.
But for some it's a handy little sub.
- Instruction "Out" outputs a value to a hardware port :
Using true port access in the Windows version requires the program to install a device driver for the present session. For that reason, Windows executables using hardware port access should be run with administrator permits each time the computer is restarted. Further runs don't require admin rights as they just use the already installed driver. The driver is only 3K in size and is embedded in the executable.
(extract of documentation)
- An alternative to your function "Sound" is to call the windows function "Beep" (from Windows NT for full functioning) that generates simple tones on the speaker. The function is synchronous; it does not return control to its caller until the sound finishes. The parameters are identical (frequency in hertz of the sound, duration in milliseconds of the sound).
See below the program modified
Using true port access in the Windows version requires the program to install a device driver for the present session. For that reason, Windows executables using hardware port access should be run with administrator permits each time the computer is restarted. Further runs don't require admin rights as they just use the already installed driver. The driver is only 3K in size and is embedded in the executable.
(extract of documentation)
- An alternative to your function "Sound" is to call the windows function "Beep" (from Windows NT for full functioning) that generates simple tones on the speaker. The function is synchronous; it does not return control to its caller until the sound finishes. The parameters are identical (frequency in hertz of the sound, duration in milliseconds of the sound).
See below the program modified
Code: Select all
Declare Sub Sound Alias "Beep" (Byval freq As Uinteger, dur As Uinteger)
'klbear sound demo
'Declare Sub Sound(Byval freq As Uinteger, dur As Uinteger)
Common Shared As Integer c,d,e,f,g,a,b,c1,i,n,dur
'musical notes c1 is c an octave higher
c = 523:d = 587:e = 659:f = 698
g = 784:a = 880:b = 988:c1 = 1047
'Sound effect
dur = 40
For i = 1000 To 1 Step -20
Sound(i,dur)
Next
Sleep 10,1
For i = 1 To 1000 Step 20
Sound(i,dur)
Next
Sleep 200,1
'musical scale
dur = 300
Sound(c, dur):Sound(d, dur):Sound(e, dur)
Sound(f, dur):Sound(g, dur):Sound(a, dur)
Sound(b, dur):Sound(c1, dur)
Sleep 500,1
'lower octave
c = 131:d = 147:e = 165:f = 175
g = 196:a = 220:b = 247:c1 = 262
'a musical tune
dur = 200
Sound(c, dur):Sound(d, dur):Sound(e, dur)
Sound(d, dur):Sound(c, dur):Sound(d, dur)
Sound(e, dur)
dur = 400
Sound(c, dur)
Sleep 40,1
Sound(c, dur)
End
'Sub Sound(Byval freq As Uinteger, dur As Uinteger)
'Dim t As Double,f1 As Unsigned Short
'f1 = 1193181 \ freq
'Out &h61,Inp(&h61) Or 3
'Out &h43,&hb6
'Out &h42,LoByte(f1)
'Out &h42,HiByte(f1)
't=Timer
'While ((Timer - t) * 1000) < dur
'Sleep 0,1
'Wend
'turn off sound
'Out &h61,Inp(&h61) And &hfc
'End Sub
Re: Basic Sound for FreeBasic
deleted