選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. ;;; this is obsolete -- it needs some replacement for the mus-audio* functions
  2. (when (provided? 'snd-motif)
  3. (with-let (sublet *motif*)
  4. ;; set up our user-interface
  5. (let* ((app (car (main-widgets)))
  6. (shell (let* ((xdismiss (XmStringCreate "Go away" XmFONTLIST_DEFAULT_TAG))
  7. (xhelp (XmStringCreate "Help" XmFONTLIST_DEFAULT_TAG))
  8. (titlestr (XmStringCreate "FM Forever!" XmFONTLIST_DEFAULT_TAG))
  9. (dialog (XmCreateTemplateDialog (cadr (main-widgets)) "FM Forever!"
  10. (list XmNcancelLabelString xdismiss
  11. XmNhelpLabelString xhelp
  12. XmNautoUnmanage #f
  13. XmNdialogTitle titlestr
  14. XmNresizePolicy XmRESIZE_GROW
  15. XmNnoResize #f
  16. XmNtransient #f))))
  17. (XtAddCallback dialog
  18. XmNhelpCallback (lambda (w context info)
  19. (snd-print "This dialog lets you experiment with simple FM")))
  20. (XmStringFree xhelp)
  21. (XmStringFree xdismiss)
  22. (XmStringFree titlestr)
  23. dialog))
  24. (dpy (XtDisplay shell))
  25. (screen (DefaultScreenOfDisplay dpy))
  26. ;; (cmap (DefaultColormap dpy (DefaultScreen dpy)))
  27. (black (BlackPixelOfScreen screen))
  28. (white (WhitePixelOfScreen screen)))
  29. (define (set-flabel label value)
  30. (let ((s1 (XmStringCreate (format #f "~,3F" value) XmFONTLIST_DEFAULT_TAG)))
  31. (XtVaSetValues label (list XmNlabelString s1))
  32. (XmStringFree s1)))
  33. (define (set-ilabel label value)
  34. (let ((s1 (XmStringCreate (format #f "~D" value) XmFONTLIST_DEFAULT_TAG)))
  35. (XtVaSetValues label (list XmNlabelString s1))
  36. (XmStringFree s1)))
  37. (let* ((form (XtCreateManagedWidget "form" xmFormWidgetClass shell
  38. (list XmNbackground white
  39. XmNforeground black
  40. XmNresizePolicy XmRESIZE_GROW)))
  41. ;; toggle named "play"
  42. (play-button (XtCreateManagedWidget "play" xmToggleButtonWidgetClass form
  43. (list XmNleftAttachment XmATTACH_FORM
  44. XmNbottomAttachment XmATTACH_NONE
  45. XmNtopAttachment XmATTACH_FORM
  46. XmNrightAttachment XmATTACH_NONE
  47. XmNbackground white)))
  48. ;; carrier freq
  49. (carrier (XtCreateManagedWidget "carrier freq:" xmLabelWidgetClass form
  50. (list XmNleftAttachment XmATTACH_FORM
  51. XmNbottomAttachment XmATTACH_NONE
  52. XmNtopAttachment XmATTACH_WIDGET
  53. XmNtopWidget play-button
  54. XmNrightAttachment XmATTACH_NONE
  55. XmNrecomputeSize #f
  56. XmNbackground white)))
  57. (freq-label (XtCreateManagedWidget "label" xmLabelWidgetClass form
  58. (list XmNleftAttachment XmATTACH_WIDGET
  59. XmNleftWidget carrier
  60. XmNbottomAttachment XmATTACH_NONE
  61. XmNtopAttachment XmATTACH_OPPOSITE_WIDGET
  62. XmNtopWidget carrier
  63. XmNrightAttachment XmATTACH_NONE
  64. XmNbackground white)))
  65. (freq-scale (XtCreateManagedWidget "carrier freq" xmScaleWidgetClass form
  66. (list XmNleftAttachment XmATTACH_WIDGET
  67. XmNleftWidget freq-label
  68. XmNbottomAttachment XmATTACH_NONE
  69. XmNtopAttachment XmATTACH_OPPOSITE_WIDGET
  70. XmNtopWidget freq-label
  71. XmNrightAttachment XmATTACH_FORM
  72. XmNshowValue #f
  73. XmNorientation XmHORIZONTAL
  74. XmNbackground *position-color*)))
  75. ;; amp
  76. (amp-label (XtCreateManagedWidget "label" xmLabelWidgetClass form
  77. (let ((amp (XtCreateManagedWidget "amp:" xmLabelWidgetClass form
  78. (list XmNleftAttachment XmATTACH_FORM
  79. XmNbottomAttachment XmATTACH_NONE
  80. XmNtopAttachment XmATTACH_WIDGET
  81. XmNtopWidget carrier
  82. XmNrightAttachment XmATTACH_NONE
  83. XmNrecomputeSize #f
  84. XmNbackground white))))
  85. (list XmNleftAttachment XmATTACH_WIDGET
  86. XmNleftWidget amp
  87. XmNbottomAttachment XmATTACH_NONE
  88. XmNtopAttachment XmATTACH_OPPOSITE_WIDGET
  89. XmNtopWidget amp
  90. XmNrightAttachment XmATTACH_NONE
  91. XmNbackground white))))
  92. (amp-scale (XtCreateManagedWidget "amp" xmScaleWidgetClass form
  93. (list XmNleftAttachment XmATTACH_WIDGET
  94. XmNleftWidget amp-label
  95. XmNbottomAttachment XmATTACH_NONE
  96. XmNtopAttachment XmATTACH_OPPOSITE_WIDGET
  97. XmNtopWidget amp-label
  98. XmNrightAttachment XmATTACH_FORM
  99. XmNshowValue #f
  100. XmNorientation XmHORIZONTAL
  101. XmNbackground *position-color*)))
  102. ;; fm index
  103. (fm-label (XtCreateManagedWidget "label" xmLabelWidgetClass form
  104. (let ((fm-index (XtCreateManagedWidget "fm index:" xmLabelWidgetClass form
  105. (list XmNleftAttachment XmATTACH_FORM
  106. XmNbottomAttachment XmATTACH_NONE
  107. XmNtopAttachment XmATTACH_WIDGET
  108. XmNtopWidget amp-scale
  109. XmNrightAttachment XmATTACH_NONE
  110. XmNrecomputeSize #f
  111. XmNbackground white))))
  112. (list XmNleftAttachment XmATTACH_WIDGET
  113. XmNleftWidget fm-index
  114. XmNbottomAttachment XmATTACH_NONE
  115. XmNtopAttachment XmATTACH_OPPOSITE_WIDGET
  116. XmNtopWidget fm-index
  117. XmNrightAttachment XmATTACH_NONE
  118. XmNbackground white))))
  119. (fm-scale (XtCreateManagedWidget "fm index" xmScaleWidgetClass form
  120. (list XmNleftAttachment XmATTACH_WIDGET
  121. XmNleftWidget fm-label
  122. XmNbottomAttachment XmATTACH_NONE
  123. XmNtopAttachment XmATTACH_OPPOSITE_WIDGET
  124. XmNtopWidget fm-label
  125. XmNrightAttachment XmATTACH_FORM
  126. XmNshowValue #f
  127. XmNorientation XmHORIZONTAL
  128. XmNbackground *position-color*)))
  129. ;; c/m ratio
  130. (cm-label (XtCreateManagedWidget "label" xmLabelWidgetClass form
  131. (let ((cm-ratio (XtCreateManagedWidget "c/m ratio:" xmLabelWidgetClass form
  132. (list XmNleftAttachment XmATTACH_FORM
  133. XmNbottomAttachment XmATTACH_NONE
  134. XmNtopAttachment XmATTACH_WIDGET
  135. XmNtopWidget fm-scale
  136. XmNrightAttachment XmATTACH_NONE
  137. XmNrecomputeSize #f
  138. XmNbackground white))))
  139. (list XmNleftAttachment XmATTACH_WIDGET
  140. XmNleftWidget cm-ratio
  141. XmNbottomAttachment XmATTACH_NONE
  142. XmNtopAttachment XmATTACH_OPPOSITE_WIDGET
  143. XmNtopWidget cm-ratio
  144. XmNrightAttachment XmATTACH_NONE
  145. XmNbackground white))))
  146. (cm-scale (XtCreateManagedWidget "cm ratio" xmScaleWidgetClass form
  147. (list XmNleftAttachment XmATTACH_WIDGET
  148. XmNleftWidget cm-label
  149. XmNbottomAttachment XmATTACH_NONE
  150. XmNtopAttachment XmATTACH_OPPOSITE_WIDGET
  151. XmNtopWidget cm-label
  152. XmNrightAttachment XmATTACH_FORM
  153. XmNshowValue #f
  154. XmNorientation XmHORIZONTAL
  155. XmNbackground *position-color*))))
  156. (let ((frequency 220.0)
  157. (low-frequency 40.0)
  158. (high-frequency 2000.0)
  159. (amplitude 0.5)
  160. (index 1.0)
  161. (high-index 3.0)
  162. (ratio 1)
  163. (high-ratio 10)
  164. (playing 0.0)
  165. (carosc (make-oscil 0.0))
  166. (modosc (make-oscil 0.0)))
  167. (define (freq-callback w c i)
  168. (set! frequency (+ low-frequency (* (.value i) (/ (- high-frequency low-frequency) 100.0))))
  169. (set-flabel freq-label frequency))
  170. (define (amp-callback w c i)
  171. (set! amplitude (/ (.value i) 100.0))
  172. (set-flabel amp-label amplitude))
  173. (define (fm-callback w c i)
  174. (set! index (* (.value i) (/ high-index 100.0)))
  175. (set-flabel fm-label index))
  176. (define (ratio-callback w c i)
  177. (set! ratio (floor (* (.value i) (/ high-ratio 100.0))))
  178. (set-ilabel cm-label ratio))
  179. ;; add scale-change (drag and value-changed) callbacks
  180. (XtAddCallback freq-scale XmNdragCallback freq-callback)
  181. (XtAddCallback freq-scale XmNvalueChangedCallback freq-callback)
  182. (XtAddCallback amp-scale XmNdragCallback amp-callback)
  183. (XtAddCallback amp-scale XmNvalueChangedCallback amp-callback)
  184. (XtAddCallback fm-scale XmNdragCallback fm-callback)
  185. (XtAddCallback fm-scale XmNvalueChangedCallback fm-callback)
  186. (XtAddCallback cm-scale XmNdragCallback ratio-callback)
  187. (XtAddCallback cm-scale XmNvalueChangedCallback ratio-callback)
  188. (XtAddCallback play-button XmNvalueChangedCallback (lambda (w c i) (set! playing (if (.set i) 1.0 0.0))))
  189. ;; set initial values
  190. (set-flabel freq-label frequency)
  191. (set-flabel amp-label amplitude)
  192. (set-flabel fm-label index)
  193. (set-ilabel cm-label ratio)
  194. (XmScaleSetValue freq-scale (floor (* 100 (/ (- frequency low-frequency) (- high-frequency low-frequency)))))
  195. (XmScaleSetValue amp-scale (floor (* 100 amplitude)))
  196. (XmScaleSetValue fm-scale (floor (* 100 (/ index high-index))))
  197. (XmScaleSetValue cm-scale (floor (* ratio (/ 100 high-ratio))))
  198. (XtManageChild shell)
  199. (XtRealizeWidget shell)
  200. ;; send fm data to dac
  201. (let* ((bufsize 256)
  202. (work-proc #f)
  203. (port (mus-audio-open-output mus-audio-default 22050 1 mus-lshort (* bufsize 2))))
  204. (if (< port 0)
  205. (format () "can't open DAC!"))
  206. (XmAddWMProtocolCallback (cadr (main-widgets)) ; shell
  207. (XmInternAtom dpy "WM_DELETE_WINDOW" #f)
  208. (lambda (w c i)
  209. (XtRemoveWorkProc work-proc) ; odd that there's no XtAppRemoveWorkProc
  210. (mus-audio-close port))
  211. #f)
  212. (XtAddCallback shell
  213. XmNcancelCallback (lambda (w context info)
  214. (XtRemoveWorkProc work-proc)
  215. (mus-audio-close port)
  216. (XtUnmanageChild shell)))
  217. (set! work-proc (XtAppAddWorkProc app
  218. (lambda (ignored-arg)
  219. (let ((data (make-float-vector bufsize)))
  220. (do ((i 0 (+ 1 i)))
  221. ((= i bufsize))
  222. (float-vector-set! data i (* amplitude playing
  223. (oscil carosc
  224. (+ (hz->radians frequency)
  225. (* index
  226. (oscil modosc
  227. (hz->radians (* ratio frequency)))))))))
  228. (mus-audio-write port data bufsize)
  229. #f))))))))))