From f5169186bda5452e7ecca6cee93de9042a33a9a6 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Thu, 7 Jun 2007 04:52:28 +0000 Subject: [PATCH] r11721: --- dtmf.lisp | 54 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/dtmf.lisp b/dtmf.lisp index ef282ac..957281c 100644 --- a/dtmf.lisp +++ b/dtmf.lisp @@ -38,7 +38,7 @@ (in-package #:cluck) -(defconstant* +dtmf-tones+ +(defconstant +dtmf-tones+ '( ;; keypad (1 . (1209 . 697)) @@ -58,10 +58,10 @@ (\# . (1477 . 941)) (D . (1633 . 941)) - ;; event - (busy . (480 . 620)) - (dial-tone . (350 . 440)) - (ringback . (440 . 480)) + ;; events + (busy . (620 . 480)) + (dial-tone . (440 . 350)) + (ringback . (480 . 440)) )) (defun dtmf-ratios () @@ -79,8 +79,7 @@ ;; A(low) / A(high) between 0.7 and 0.9 (defun dtmf-waveform (key duration sample-freq - &key (min -1d0) (max 1d0) - (element-type 'double-float) + &key (min -1d0) (max 1d0) (element-type 'double-float) &aux dtmf-record) "Returns the DTMF waveform of a key code for duration seconds at a sample frequency of sample-freq. Waveform normalized to -1 to 1 output." @@ -143,17 +142,30 @@ at a sample frequency of sample-freq. Waveform normalized to -1 to 1 output." (format os "~F~A~F~%" time delimiter (aref wave i)) (incf time period))))) + +;;; Functions optionally defined if supporting packages have already +;;; been loaded +;;; +;;; Functions requiring CL-WAV-SYNTH, used for it WAV file writing + +(eval-when (:compile-toplevel :load-toplevel :execute) + (when (find-package '#:cl-wav-synth) + (pushnew :kmr-cl-wav-synth cl:*features*))) + +#+:kmr-cl-wav-synth (defun write-dtmf-wav (file key duration &key (sample-freq 8000) (n-bits-per-sample 8) &aux wave) (setq wave (dtmf-waveform key duration sample-freq :min (ecase n-bits-per-sample - (8 -128) - (16 -32768)) + (8 0) + (16 -32768)) :max (ecase n-bits-per-sample - (8 127) - (16 32767)) - :element-type (list 'signed-byte n-bits-per-sample))) + (8 255) + (16 32767)) + :element-type (ecase n-bits-per-sample + (8 '(unsigned-byte 8)) + (16 '(signed-byte 16))))) (unless wave (return-from write-dtmf-wav nil)) (let ((sample (make-instance 'cl-wav-synth:sample @@ -167,7 +179,18 @@ at a sample frequency of sample-freq. Waveform normalized to -1 to 1 output." (cl-wav-synth:write-sample file sample) sample)) -#| +(eval-when (:compile-toplevel :load-toplevel :execute) + (when (find :kmr-cl-wav-synth cl:*features*) + (setq cl:*features* (delete :kmr-cl-wav-synth cl:*features*)))) + + +;;; Functions requiring CGN, a plotting package + +(eval-when (:compile-toplevel :load-toplevel :execute) + (when (find-package '#:cgn) + (pushnew :kmr-cgn cl:*features*))) + +#+:kmr-cgn (defun plot-dtmf (key duration sample-freq &aux wave) (setq wave (dtmf-waveform key duration sample-freq)) (unless wave (return-from plot-dtmf nil)) @@ -190,4 +213,7 @@ at a sample frequency of sample-freq. Waveform normalized to -1 to 1 output." (cgn:set-range 'y -1 1) (cgn:plot-points x y) ))) -|# + +(eval-when (:compile-toplevel :load-toplevel :execute) + (when (find :kmr-cgn cl:*features*) + (setq cl:*features* (delete :kmr-cgn cl:*features*)))) -- 2.34.1