[plt-scheme] audio in Scheme

From: Jacob Matthews (jacobm at cs.uchicago.edu)
Date: Fri Dec 5 01:12:46 EST 2008

Last year, when I got Paul Hudak's "The Haskell School of Expression",
I started working my way through his Haskore example using Scheme
instead of Haskell. My haskore variation had primitives similar to
Stephen's:

;; music ::= (make-note pitch duration)
;;         | (make-rst duration)
;;         | (seq (listof music))
;;         | (par (listof music))

I.e., music is a note, a rest, some musics played one after the other,
or some musics played in parallel.

The hard part of this program was the MIDI file output, which is why I
think it's worth mailing it out rather than just telling people to
look at Hudak's book. [He doesn't explain how to write the low-level
output library, he just provides one. The MIDI file format turns out
to be pretty hairy.] I'm attaching the file I wrote then here, with
the warning that it was uncommented and possibly incomplete, and I
don't really remember how it worked anymore. It probably has bugs, and
if it does I can't fix them.

That said, I just verified that you can do

> (music->midi (make-seq (list (Gmaj 1) (Gmaj 1) (Dmaj 2) (Cmaj 1) (Gmaj 2))) "testing.midi")

and it makes testing.midi contain a sound file that sounds like you'd
expect. (Verified against the version of PLT Scheme in SVN as of
November 8.)

I send this out in case someone wants to take it and do something with it.

-jacob



On Thu, Dec 4, 2008 at 6:48 AM, Stephen Bloch <sbloch at adelphi.edu> wrote:
> I'm very interested in this audio stuff for a pedagogical reason: I'd like
> to supplement the "tiles" and "image" teachpacks with audio analogues (for
> the benefit of visually-impaired students or just those who learn better
> aurally than visually).
>
> So what would I need?
>
> 1) I'd like to be able to copy and paste audio clips from, say, a Web page
> or a file into DrScheme, as I can currently copy and paste images.  I don't
> know how this would work, or whether it's already possible :-)  Is there an
> audio data type analogous to image-snip% ?
>
> 2) Obvious easy operations on audio clips: concatenate, reverse (in the time
> dimension), increase/decrease volume (i.e. scalar multiplication of
> amplitude), play simultaneously (i.e. add pointwise), amplitude-modulate
> (i.e. multiply pointwise), speed up and slow down (i.e. scalar
> multiplication in the time domain), find peak amplitude.
>
> 3) Easy primitives: sine, square, and triangle waves of specified frequency
> and duration.
>
> 4) Not quite so trivial operations: transpose up or down without changing
> durations, change durations without changing pitch, invert pitches, apply a
> specified volume envelope (e.g. ADSR), convolve with a specified impulse
> response (e.g. to apply echo and reverb effects; is this actually the same
> operation?)
>
> And of course, all of this needs to have a simple enough interface to be
> accessible to non-CS-major students who have been programming for only a few
> days. :-)
>
> Once we've got this, it would be nice to modify the animation teachpack so
> the "display" has both a visual and an audio track, both computed by
> user-provided functions on the model....
>
> Stephen Bloch
> sbloch at adelphi.edu
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: midi.ss
Type: application/octet-stream
Size: 8615 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20081204/9cccafbf/attachment.obj>

Posted on the users mailing list.