The RSound package generates sounds. It generates a bunch of them at startup, and in general, there’s no way to know exactly what frame rates the machine supports. Historically, 44.1KHz has been the standard, but recently, 48K has been gaining traction, and many of my students’ machines no longer support 44.1K at all.
After waffling for a while on how best to solve this, I think that the right solution is to add a preference for this. I investigated the interface, and thanks to the exceptional DrRacket docs, I had no trouble implementing the preference. I have two questions/concerns: 1) I notice that I don’t seem to have any other packages that have preferences, and I feel a bit funny about adding a top-level preference pane to DrRacket. Currently, my preference panel contains exactly one choice box, with the choices 44100 and 48000. Should I attach this to some other preference panel? 2) Should I be adding this preference pane in the phase1 or phase2 callbacks of the tool interface, or in the base module invocation? I picked phase1, and it seems to work. Based on my reading of the phase1 and phase2 docs, it seems like… it shouldn’t matter, and maybe I should just put it in the unit invocation. Finally, here’s the source code for the tool.rkt file. Any comments much appreciated! Best, John https://github.com/jbclements/RSound/blob/forty-eight-k/rsound/tool.rkt or simply as inline text: #lang racket/gui (require drracket/tool framework) (provide tool@) ;; the list of permissible default frame rates. ;; This is used for generation of all built-in sounds, and is the ;; default for pstreams and in other places. You can change it with ;; the default-frame-rate parameter, but this won't affect the sounds ;; that are already generated. ;; For ease of use, we limit this setting to one of a few possibilities. ;; there's really no reason not to allow anything between 8K and 48K except ;; that it would confuse people. I don't know whether 96K would present ;; problems... it might slow down sound generation unacceptably. (define LEGAL-DEFAULT-FRS '(44100 48000)) ;; if the existing preference is not one of the legal ones, reset to this: (define RESET-FR 44100) (define tool@ (unit (import drracket:tool^) (export drracket:tool-exports^) (define (phase1) (define FR-pref-from-file (get-preference 'rsound:default-frame-rate)) (define FR-pref (cond [(member FR-pref-from-file LEGAL-DEFAULT-FRS) FR-pref-from-file] [else (put-preferences '(rsound:default-frame-rate) (list RESET-FR)) RESET-FR])) (define FR-pref-idx (for/first ([i (in-naturals)] [fr (in-list LEGAL-DEFAULT-FRS)] #:when (= FR-pref fr)) i)) (preferences:add-panel "RSound" (λ (parent) (define vpanel (new vertical-panel% (parent parent) (alignment '(left top)))) (new choice% [label "default frame rate"] [choices (map number->string LEGAL-DEFAULT-FRS)] [parent vpanel] [selection FR-pref-idx] [callback (λ (choicebox evt) (when (equal? (send evt get-event-type) 'choice) (match (send choicebox get-selection) [#f (error 'choice-callbox "internal error: no default frame rate selected (should be impossible?)")] [n (put-preferences '(rsound:default-frame-rate) (list (list-ref LEGAL-DEFAULT-FRS n)))])))]) vpanel))) (define (phase2) (void)))) -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.