Audio frequency generator: Difference between revisions

Added FreeBASIC
(added Raku programming solution)
(Added FreeBASIC)
 
(One intermediate revision by one other user not shown)
Line 98:
Freq(F,10000)
End</syntaxhighlight>
 
=={{header|FreeBASIC}}==
[https://www.un4seen.com/ Library: BASS]
<syntaxhighlight lang="vbnet">#include "bass.bi"
#include "fbgfx.bi"
 
Dim Shared As Integer freq = 440, volume = 50
Dim Shared As HSTREAM stream
 
Sub CheckKeys()
If Multikey(SC_LEFT) Then freq -= 10
If Multikey(SC_RIGHT) Then freq += 10
If Multikey(SC_UP) Then volume += 5
If Multikey(SC_DOWN) Then volume -= 5
' Limit frequency and volume to reasonable values
If freq < 20 Then freq = 20
If freq > 20000 Then freq = 20000
If volume < 0 Then volume = 0
If volume > 100 Then volume = 100
' Update the stream with the new frequency and volume
BASS_ChannelSetAttribute(stream, BASS_ATTRIB_FREQ, freq)
BASS_ChannelSetAttribute(stream, BASS_ATTRIB_VOL, volume / 100.0)
End Sub
 
' Initialize BASS using the default device at 44.1 KHz.
If (BASS_Init(-1, 44100, 0, 0, 0) = False) Then
Print "Could not initialize audio! BASS returned error " & BASS_ErrorGetCode()
Sleep
End
End If
 
' Create a stream
stream = BASS_StreamCreate(44100, 1, 0, @BASS_STREAMPROC_PUSH, NULL)
If stream = 0 Then
Print "Error creating stream: "; BASS_ErrorGetCode()
BASS_Free
Sleep
End 1
End If
 
' Start the stream
BASS_ChannelPlay(stream, False)
 
Do
CheckKeys
Sleep 10
Loop Until Inkey$ <> ""
 
' Clean up
BASS_StreamFree(stream)
BASS_Free</syntaxhighlight>
 
=={{header|Go}}==
Line 838 ⟶ 891:
 
[https://www.dropbox.com/s/jf5uq0bbts40wto/CalmoSoftFrequency.avi?dl=0 Audio frequency generator]
 
=={{header|Sidef}}==
{{trans|Raku}}
<syntaxhighlight lang="ruby">var (kindS = 'sine', kind = 0, freq = 0, vol = 0, dur = 0)
 
while ((freq < 40) || (freq > 10000)) {
freq = (Sys.read("Enter frequency in Hz (40 to 10000) : ", Num) || next)
}
 
while ((vol < 1) || (vol > 50)) {
vol = (Sys.read("Enter volume in dB (1 to 50) : ", Num) || next)
}
 
while ((dur < 2) || (dur > 10)) {
dur = (Sys.read("Enter duration in seconds (2 to 10) : ", Num) || next)
}
 
while ((kind < 1) || (kind > 3)) {
kind = (Sys.read("Enter kind (1 = Sine, 2 = Square, 3 = Sawtooth) : ", Num) || next)
 
given(kind) {
when (1) { kindS = 'sine' }
when (2) { kindS = 'square' }
when (3) { kindS = 'sawtooth' }
}
}
 
var args = ["-n", "synth", dur, kindS, freq, "vol", vol, "dB"]
Sys.run('play', args...)</syntaxhighlight>
 
=={{header|SuperCollider}}==
2,130

edits