Playing with rsound

28 views
Skip to first unread message

wanderley...@gmail.com

unread,
Dec 7, 2019, 5:40:14 PM12/7/19
to Racket-Users List
I started to playing around with rsound while reading its documentation.  I wrote the following code:

    #lang racket
    (require rsound)
    (require rsound/piano-tones)
    (define (chord . notes)
      (rs-overlay* (map piano-tone notes)))
    (play (rs-overlay (rs-append (chord 60 64 67)
                                 (chord 60 64 67))
                      (rs-append (piano-tone 72)
                                 (piano-tone 72))))


and I was expecting to hear `(piano-tone 72)` on the begin of the two chords.  The second `(piano-tone 72)` starts few milliseconds after the second chord starts.

Can you help me understand why this is happening?

Thanks,
wander

John Clements

unread,
Dec 7, 2019, 7:39:05 PM12/7/19
to wanderley...@gmail.com, Racket-Users List
The problem here is that the piano notes are not all the same duration. Specifically, your chord (chord 60 64 67) is a bit longer:

(rs-frames (chord 60 64 67)) -> 161634 frames
(rs-frames (piano-tone 72)) -> 144000 frames

There are a lot of ways of solving this, including clipping the two sounds to the same length and using the `assemble` function. but here’s one simple way:


(require rsound)
(require rsound/piano-tones)
(define (chord . notes)
(rs-overlay* (map piano-tone notes)))
(play (rs-append (rs-overlay (chord 60 64 67)
(piano-tone 72))
(rs-overlay (chord 60 65 69)
(piano-tone 72))
(rs-overlay (chord 62 67 71)
(piano-tone 74))
(rs-overlay (chord 64 67 72)
(piano-tone 84))))


(that is, put the append on the outside, and the rs-overlays inside it.)

(Also, yes, I made it a little I-IV-V-I instead of the same chord twice.)

John
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAAmHZodfci0HM0_b%2BPaEuGBojyJsKwOhDKd-%2Bgi3jJHhaHi7Hg%40mail.gmail.com.



wanderley...@gmail.com

unread,
Dec 7, 2019, 11:28:02 PM12/7/19
to John Clements, Racket-Users List
Thanks!  I will play with clip and assemble.
--
Abraço,
Wanderley Guimarães
Reply all
Reply to author
Forward
0 new messages