Sine wave: Difference between revisions

Content added Content deleted
(→‎{{header|Delphi}}: add Emacs Lisp)
Line 126: Line 126:
<lang lisp>(defun play-sine (freq dur)
<lang lisp>(defun play-sine (freq dur)
"Play a sine wave for dur seconds."
"Play a sine wave for dur seconds."
(setq header (concat ; AU header:
(setq header (unibyte-string ; AU header:
(unibyte-string 46 115 110 100) ; ".snd" magic number
46 115 110 100 ; ".snd" magic number
(unibyte-string 0 0 0 24) ; start of data bytes
0 0 0 24 ; start of data bytes
(unibyte-string 255 255 255 255) ; file size is unknown
255 255 255 255 ; file size is unknown
(unibyte-string 0 0 0 3) ; 16 bit PCM samples
0 0 0 3 ; 16 bit PCM samples
(unibyte-string 0 0 172 68) ; 44,100 samples/s
0 0 172 68 ; 44,100 samples/s
(unibyte-string 0 0 0 1))) ; mono
0 0 0 1)) ; mono
(setq s (apply #'concat header (mapcar (lambda (x) (unibyte-string
(setq s (apply #'concat header (mapcar (lambda (x) (unibyte-string
(mod (+ 128 (round (+ 128 (* 127 (sin
(mod (+ 128 (round (+ 128 (* 127 (sin