Audio frequency generator: Difference between revisions
Content added Content deleted
No edit summary |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 30: | Line 30: | ||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
< |
<syntaxhighlight lang=Action!>byte |
||
volu,dist,freq,key=764 |
volu,dist,freq,key=764 |
||
Line 83: | Line 83: | ||
sndrst() mar=2 graphics(0) |
sndrst() mar=2 graphics(0) |
||
return</ |
return</syntaxhighlight> |
||
=={{header|Axe}}== |
=={{header|Axe}}== |
||
{{untested|Axe}} |
{{untested|Axe}} |
||
< |
<syntaxhighlight lang=axe>ClrHome |
||
Disp "FREQ:",i |
Disp "FREQ:",i |
||
10→F |
10→F |
||
Line 99: | Line 99: | ||
Output(5,0,F▶Dec) |
Output(5,0,F▶Dec) |
||
Freq(F,10000) |
Freq(F,10000) |
||
End</ |
End</syntaxhighlight> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
Line 105: | Line 105: | ||
The duration of the monotone is set in advance (to a small number of seconds) and the application ends when it finishes playing. Consequently, a method to silence it is not required. |
The duration of the monotone is set in advance (to a small number of seconds) and the application ends when it finishes playing. Consequently, a method to silence it is not required. |
||
< |
<syntaxhighlight lang=go>package main |
||
import ( |
import ( |
||
Line 173: | Line 173: | ||
err := cmd.Run() |
err := cmd.Run() |
||
check(err) |
check(err) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
Uses the PortAudio library. |
Uses the PortAudio library. |
||
< |
<syntaxhighlight lang=julia>using PortAudio |
||
if Sys.iswindows() |
if Sys.iswindows() |
||
Line 291: | Line 291: | ||
@async(inputtask(chan)) |
@async(inputtask(chan)) |
||
playtone(ostr) |
playtone(ostr) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Locomotive Basic}}== |
=={{header|Locomotive Basic}}== |
||
< |
<syntaxhighlight lang=locobasic>10 mode 1:input "Enter initial frequency in Hz";f:cls |
||
20 if sq(2)<128 then sound 2,62500/f,100 |
20 if sq(2)<128 then sound 2,62500/f,100 |
||
30 a$=inkey$ |
30 a$=inkey$ |
||
Line 303: | Line 303: | ||
70 locate 1,1:print f"Hz " |
70 locate 1,1:print f"Hz " |
||
80 print:print " Use h and l to adjust frequency;":print " q to quit." |
80 print:print " Use h and l to adjust frequency;":print " q to quit." |
||
90 goto 20</ |
90 goto 20</syntaxhighlight> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
As in the Go version, we use the Sox "play" command to emulate the audio frequency generator. This version is a faithful translation of the Go version, even if the way things are done is pretty different. |
As in the Go version, we use the Sox "play" command to emulate the audio frequency generator. This version is a faithful translation of the Go version, even if the way things are done is pretty different. |
||
< |
<syntaxhighlight lang=Nim>import osproc, strutils |
||
type Waveform {.pure.} = enum |
type Waveform {.pure.} = enum |
||
Line 337: | Line 337: | ||
let args = ["-n", "synth", $dur, $kind, $freq, "vol", $vol, "dB"] |
let args = ["-n", "synth", $dur, $kind, $freq, "vol", $vol, "dB"] |
||
echo execProcess("play", args = args, options = {poStdErrToStdOut, poUsePath})</ |
echo execProcess("play", args = args, options = {poStdErrToStdOut, poUsePath})</syntaxhighlight> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
< |
<syntaxhighlight lang=perl>use strict 'vars'; |
||
use feature 'say'; |
use feature 'say'; |
||
use feature 'state'; |
use feature 'state'; |
||
Line 374: | Line 374: | ||
return $freq; |
return $freq; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<syntaxhighlight lang=Phix>(notonline)--> |
||
<span style="color: #000080;font-style:italic;">-- demo/rosetta/Audio_frequency_generator.exw</span> |
<span style="color: #000080;font-style:italic;">-- demo/rosetta/Audio_frequency_generator.exw</span> |
||
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
||
Line 439: | Line 439: | ||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span> |
||
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
=={{header|Pure Data}}== |
=={{header|Pure Data}}== |
||
Line 641: | Line 641: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang=ring> |
||
# Project : Audio frequency generator |
# Project : Audio frequency generator |
||
Line 804: | Line 804: | ||
ok |
ok |
||
return |
return |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
Line 812: | Line 812: | ||
SuperCollider is a sound programming language, so the task is predictably easy. |
SuperCollider is a sound programming language, so the task is predictably easy. |
||
< |
<syntaxhighlight lang=SuperCollider> |
||
// the server application detects audio hardware. |
// the server application detects audio hardware. |
||
Server.default.boot; |
Server.default.boot; |
||
Line 844: | Line 844: | ||
// sound stops on exit |
// sound stops on exit |
||
Server.default.quit; |
Server.default.quit; |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
{{libheader|Snack}} |
{{libheader|Snack}} |
||
This does not work on Windows due the use of the external <tt>stty</tt> program. |
This does not work on Windows due the use of the external <tt>stty</tt> program. |
||
< |
<syntaxhighlight lang=tcl>package require sound |
||
set baseFrequency 261.63 |
set baseFrequency 261.63 |
||
Line 911: | Line 911: | ||
# Stop the sound playing |
# Stop the sound playing |
||
$sound stop |
$sound stop |
||
exit</ |
exit</syntaxhighlight> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
The ability to call external processes such as ''SoX'' is expected to be added to Wren-cli in the next release. In the meantime, we embed the following Wren script in a C host to complete this task. |
The ability to call external processes such as ''SoX'' is expected to be added to Wren-cli in the next release. In the meantime, we embed the following Wren script in a C host to complete this task. |
||
< |
<syntaxhighlight lang=ecmascript>/* audio_frequency_generator.wren */ |
||
class C { |
class C { |
||
Line 958: | Line 958: | ||
var args = ["-n", "-V1", "synth", durS, kindS, freqS, "vol", volS, "dB"].join(" ") |
var args = ["-n", "-V1", "synth", durS, kindS, freqS, "vol", volS, "dB"].join(" ") |
||
C.play(args)</ |
C.play(args)</syntaxhighlight> |
||
<br> |
<br> |
||
We now embed this in the following C program, compile and run it. |
We now embed this in the following C program, compile and run it. |
||
< |
<syntaxhighlight lang=c>#include <stdio.h> |
||
#include <stdio_ext.h> |
#include <stdio_ext.h> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
Line 1,053: | Line 1,053: | ||
free(script); |
free(script); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|ZX Spectrum Basic}}== |
=={{header|ZX Spectrum Basic}}== |
||
Line 1,065: | Line 1,065: | ||
There is no volume control on the Spectrum. |
There is no volume control on the Spectrum. |
||
< |
<syntaxhighlight lang=zxbasic>10 REM The crappest signal generator in the world |
||
20 REM We do not check for boundary errors in this simple demo |
20 REM We do not check for boundary errors in this simple demo |
||
30 LET n=1 |
30 LET n=1 |
||
Line 1,073: | Line 1,073: | ||
70 PRINT AT 0,0;n," " |
70 PRINT AT 0,0;n," " |
||
80 BEEP 0.1,n: REM beep for 0.1 second at n semitones relative to middle C |
80 BEEP 0.1,n: REM beep for 0.1 second at n semitones relative to middle C |
||
90 GO TO 40</ |
90 GO TO 40</syntaxhighlight> |