File: segment.scm

package info (click to toggle)
snd 3.4-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 5,148 kB
  • ctags: 12,594
  • sloc: ansic: 86,516; lisp: 3,480; sh: 1,507; makefile: 119
file content (53 lines) | stat: -rw-r--r-- 1,671 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(define segment
  (lambda (marks-not-files)
    ;; run through currently selected file looking for sound segments
    ;; and write each to a separate (aiff) file named segN.snd, or
    ;; mark the segment boundaries if marks-not-files
    (let* ((snd (selected-sound))
	   (soundname (file-name snd))
	   (chans (sound-chans soundname))
	   (frames (snd-length snd))
	   (output-counter 0)
	   (hop-size 32)
	   (silent-max (* hop-size .001))
	   (seg-start -1))
      (do ((frame 0 (+ frame hop-size)) )
	  ((>= frame frames))
	;; check each channel 
	(let ((chan-max 0.0))
	  (do ((chan 0 (1+ chan))) 
	      ((= chan chans))
	    (let ((data (samples frame (+ frame hop-size) snd chan))
		  (sum 0.0))
	      (do ((i 0 (1+ i)))
		  ((= i hop-size))
		(set! sum (+ sum (abs (vector-ref data i)))))
	      (if (> sum chan-max) (set! chan-max sum))))

	  (if (> chan-max silent-max)
	      (if (< seg-start 0) 
		  (set! seg-start frame))
	      (if (and (>= seg-start 0) (> frame seg-start))
		  (begin
		    (set! output-counter (1+ output-counter))
		    (if marks-not-files
			(begin
			  (report-in-minibuffer (string-append "segment " 
							       (number->string output-counter) 
							       ": " 
							       (number->string seg-start) 
							       " " 
							       (number->string frame)))
			  (add-mark seg-start snd 0)
			  (add-mark frame snd 0))
			(begin
			  (let* ((old-sync (syncing? snd)))
			    (set-syncing #t snd)
			    (make-region seg-start frame snd)
			    (save-region 0 (string-append "seg" (number->string output-counter) ".snd"))
			    (set-syncing old-sync snd))))
		    (set! seg-start -1))))))
      "done")))