[CM] Hacking mark-explode

Bill Schottstaedt bil@ccrma.Stanford.EDU
Thu, 24 Jun 2004 04:30:01 -0700


Here's a version of mark-explode that lets you set the header type and data format:

(define* (mark-explode #:optional (htype mus-next) (dformat mus-bfloat))
   "(mark-explode :optional header-type data-format) splits a sound into a bunch of sounds based on mark placements"
   (let ((start 0)
	(file-ctr 0)
	(snd (or (selected-sound) (car (sounds)))))
     (for-each
      (lambda (mark)
        (let ((end (mark-sample mark)))
	 (if (> end start)
	     (let ((filename (format #f "mark-~D.snd" file-ctr)))
	       (set! file-ctr (1+ file-ctr))
	       (do ((i 0 (1+ i)))
		   ((= i (chans snd)))
		 (set! (selection-member? snd i) #t)
		 (set! (selection-position snd i) start)
		 (set! (selection-frames snd i) (- end start)))
	       (save-selection filename :header-type htype :data-format dformat :srate (srate snd))
	       (do ((i 0 (1+ i)))
		   ((= i (chans snd)))
		 (set! (selection-member? snd i) #f))))
	 (set! start end)))
      (car (marks snd)))
     (update-time-graph snd)))

The original function got the marks via (caar (marks)) -- this one
specifies the sound, so it uses (car (marks)) -- it's only looking
at the first channel for the marks.  In this case the input header
type is (header-type snd).  The input data format is (data-format snd).
If you're working with mono sounds, the do loops can obviously be
removed.