Sine wave: Difference between revisions

1,025 bytes added ,  2 years ago
→‎{{header|Delphi}}: add Emacs Lisp
(→‎{{header|Delphi}}: add Emacs Lisp)
Line 121:
end;
end.</lang>
 
=={{header|Emacs Lisp}}==
Note that this code does not work on Windows because playing sound from Emacs Lisp data variables is not supported there.
<lang lisp>(defun play-sine (freq dur)
"Play a sine wave for dur seconds."
(setq header (concat ; AU header:
(unibyte-string 46 115 110 100) ; ".snd" magic number
(unibyte-string 0 0 0 24) ; start of data bytes
(unibyte-string 255 255 255 255) ; file size is unknown
(unibyte-string 0 0 0 3) ; 16 bit PCM samples
(unibyte-string 0 0 172 68) ; 44,100 samples/s
(unibyte-string 0 0 0 1))) ; mono
(setq s (apply #'concat header (mapcar (lambda (x) (unibyte-string
(mod (+ 128 (round (+ 128 (* 127 (sin
(* 2 pi freq x (/ 44100.0))))))) 256) 0))
(number-sequence 0 (* dur 44100)))))
(play-sound (list 'sound :data s)))
 
(play-sine 440 5)</lang>
 
=={{header|Go}}==
{{works with|Ubuntu 16.04}}
Anonymous user