I am trying to build a Nyquist code that can convert text to tones. I added an interface for tone duration and waveform type (drop down list). The code doesn’t work and this is the bug output. Please help me fix this
;nyquist plug-in
;version 4
;type generate
;name "Text to Tones"
;action "Encoding text into tones..."
;info "Encodes text into sequential tones, where each character corresponds to a specific pitch."
;control input "Words to encode" string "" "Paste the text here"
;control wave-type "Waveform Type" choice "Sine" "Square" "Sawtooth" "Square No Alias" "Triangle"
;control tone-dur "Tone Duration (seconds)" real "0.1" 0.01 10.0
(setf input-stream (make-string-input-stream input))
(defun tone (freq)
"Generates a tone at a given frequency (in Hz) and duration based on the selected waveform type."
(case (char-upcase wave-type)
("SINE" (osc freq tone-dur))
("SQUARE" (osc freq tone-dur *table-square*))
("SAWTOOTH" (osc freq tone-dur *table-sawtooth*))
("SQUARE NO ALIAS" (osc freq tone-dur *table-square-no-alias*))
("TRIANGLE" (osc freq tone-dur *table-triangle*))))
; Initialize output
(let ((out (s-rest 0)))
(do* ((ch (read-char input-stream) (read-char input-stream))
(i 0 (1+ i)))
((not ch)) ; Stop when end of input is reached
(setf ch (char-upcase ch)) ; Convert to uppercase
(setf note
(case ch
(#\A (tone 1))
(#\B (tone 2))
(#\J (tone 3))
(#\D (tone 4))
(#\E (tone 5))
(#\W (tone 6))
(#\Z (tone 7))
(#\H (tone 8))
(#\U (tone 9))
(#\Y (tone 10))
(#\K (tone 20))
(#\L (tone 30))
(#\M (tone 40))
(#\N (tone 50))
(#\S (tone 60))
(#\I (tone 70))
(#\F (tone 80))
(#\! (tone 90))
(#\Q (tone 100))
(#\R (tone 200))
(#\O (tone 300))
(#\T (tone 400))
(#\C (tone 500))
(#\J (tone 600))
(#\P (tone 700))
(#\? (tone 800))
(#\V (tone 900))
(#\G (tone 1000))
(#\space (s-rest tone-dur)) ; Silence for spaces
(t nil))) ; Ignore unsupported characters
(if note
(setf out
(sim out
(at (* i tone-dur) (cue note)))))) ; Append each tone sequentially
out) ; Return the final audio output
[Moderator: Code tags added for readability]