Jump to content

Audio frequency generator: Difference between revisions

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

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.