Building an instrument

60 views
Skip to first unread message

Fabien

unread,
Nov 22, 2017, 3:57:38 PM11/22/17
to Extempore

Hello guys,

I have been inactive for the last months/years. I recently decided to get back to making music (with extempore, of course!).

So some things seem to have changed? I was redoing the tutorial on DSP and the part about building an instrument is not working anymore. I saw the fmsynth example, and I have no problem binding and playing instruments that are already in
the library, but I am pretty confused about how I can build one myself. I tried binding the example saw synth (copied directly from the doc) using the new macro make-instrument, and got told by the compiler that saw_synth_note_note didn't exist.
I tried (make-instrument testsynth saw_synth), but then got told that "no valid polymorphic options ast: (saw_synth_note##781)". I vaguely remember what an ast is, and I tried to read the make-instrument macro, but my scheme-fu is extremely rusty and I didn't understand much.

So... What must we do to make instruments now?

Thanks!

Fabien

Fabien

unread,
Nov 27, 2017, 9:09:59 PM11/27/17
to Extempore
All right! So I poked around a little bit and I think I got a least part of what is going on.

I got that make-instrument requires both a <name>_note and a <name>_fx closure.
At this point, it still feels a little bit like alchemy, but it works! I modified the saw_synth example this way (basically copying the example into the base_note from instruments.xtm):   

(bind-func saw_synth_note
  (lambda ()
    (lambda (data:NoteData* nargs:i64 dargs:SAMPLE*)
      (let ((starttime (note_starttime data))  ;; start time
            (frequency (note_frequency data))  ;; you'll probably want the note frequency (in hz)
            (amplitude (note_amplitude data))  ;; you'll probably want the note amplitude (0.0-1.0)
            (duration (note_duration data))
            (sawl (saw_c 0.))
            (sawr (saw_c 0.)))
        (lambda (time:i64 chan:i64)
          (if (> (- time starttime) duration) (note_active data #f))
          (cond ((= chan 0)
                 (sawl amplitude frequency))
                ((= chan 1)
                 (sawr amplitude frequency))
                (else 0.0)))))))

(bind-func saw_synth_fx
  (lambda ()
    (lambda (in:SAMPLE time:i64 chan:i64 dat:SAMPLE*)
      in)))

However, upon compilation, I get the message:
Unable to locate 5266453129974903 in closure environment b
Unable to locate id in closure environment type: {i8*, i8*, {i8*, i8*, float (i8*, i8*, i64, i64)*}** (i8*, i8*, %NoteData*, i64, float*)*}** d

It still compiles, and it otherwise seems to work fine. What does that message mean?
Reply all
Reply to author
Forward
0 new messages