[CM] memory fault within run macro

Steven Jones plewto at gmail.com
Fri, 23 Nov 2007 03:06:22 -0600

Hi All,
I'm attempting to write a compound unit generator which ring modulates
a sine wave with narrow-band noise. I'm using a three element array to
hold the various primitive unit generators. The first array element is
a symbol to identify the structure, the second is a rand-interp object
and the third an oscil object. When I execute the test instrument
however I get a memory-fault error.  The offending code appears to be
the rand-interp in the nseband macro. I have also tried rand with the
same result.

Im using SBCL on Fedora 5.

(defmacro make-nseband (&key (frequency 440)(bw 10))
  `(make-array 3 :initial-contents (list
				    (make-rand-interp :frequency ,bw)
				    (make-oscil :frequency ,frequency)

(defmacro nseband? (obj)
  `(and (arrayp ,obj)(eq (aref ,obj 0) 'nseband)))

(defmacro nseband (obj &optional (fm 0))
    (rand-interp (aref ,obj 1))		;; *** APPARENT TROUBLE SPOT
    (oscil (aref ,obj 2) ,fm)

(definstrument test (&key (dur 1)(frq 440)(bw 10)(amp 1))
  (let* ((s1 (* dur *srate*))
	 (obj (make-nseband :frequency frq :bw bw)))

    (dotimes (i 3)
      (format t "~%obj[~A] ==> ~A" i (aref obj i)))

    (with-sound ()
       (loop for s from 0 below s1 do
	     (outa s (nseband obj)))))))

This is the error message

* (test)

obj[0] ==> NSEBAND
obj[1] ==> #<rand-interp: freq: 0.003 (10 Hz), phase: 0.0 (0 degrees),
amplitude: 1.000, increment: 0.0>
obj[2] ==> #<oscil: freq: 0.125 (440 Hz), phase: 0.0 (0 degrees)>
debugger invoked on a SB-SYS:MEMORY-FAULT-ERROR in thread #<THREAD
"initial thread" {AA72831}>:
  Unhandled memory fault at #x4. <...snip...>

 Thanks for any suggestions
--Steven Jones