[audacity4blind] New plug-in: Audio Chunker

  • From: "David R. Sky" <davidsky@xxxxxxxxxxxxxx>
  • To: audacity4blind@xxxxxxxxxxxxx
  • Date: Sat, 2 Sep 2006 03:54:17 -0700 (PDT)

* chunker.ny: Audio Chunker
(attached to this post)

Chops your audio selection into equal-length chunks of audio, then
spaces them equally apart in time.

Variables:

1. Number of audio chunks: from 1 to 120, default 16.

2. Gap time - percent: The duration of the gap between each audio
chunk. 50% means the silence gaps are 50% of the duration of the
audio chunks, 100% means the gap between audio chunks is the same
duration as the audio chunks. From 0 to 200 percent.

3. Fade in/out times - ms: Without which there would be annoying
clicks at the start and end of each audio chunk. Default
20milliseconds. If you set the number of audio chunks to 1, the
result will simply be a fade-in and fade-out applied at the start
and end of the single audio chunk.

Works on mono and stereo audio.

Written by David R. Sky, September 2, 2006.
Thanks to Roger Dannenberg for some Nyquist clarifications.
Released under terms of the GNU Public License
http://www.opensource.org/licenses/gpl-license.php

;nyquist plug-in

;version 2

;type process

;name "Audio chunker..."

;action "Chunking and shifting audio..."

;info "by David R. Sky\nReleased under terms of GNU Public License"



;control chunks "Number of audio chunks" int "" 16 1 120

;control gap-t "Gap time - percent" int "" 50 0 200

;control fade "Fade in/out times - ms" int "" 20 0 500



; Audio chunker by David R. Sky, September 2, 2006.

; Thanks to Roger Danenberg for several Nyquist clarifications

; related to shifting audio in time [at-abs]

; Released under terms of the GNU Public License

; http://www.opensource.org/licenses/gpl-license.php



; divides selection into equal duration chunks,

; then moves these to a later position in time



; initialize variables:



; selection duration

(setf dur (/ len *sound-srate*))

; set number of chunks from 1-120 inclusive

; prevents possible stack overflow issues above 120 events

; for 1 chunk, simply applies fade-in and fade-outs

; at start and end of chunk

(setf chunks (max 1 (min 120 chunks)))

; setting chunk duration

(setf chunk-t (/ dur chunks))

; fade in/out times

; so no sharp clicks at start/end of chunks 

; unless fade time is very fast

(setf fade (* 0.001 fade))

; if fade time is more than half of chunk duration,

; set fade to half of chunk duration

(setf fade (if (> fade (* 0.5 chunk-t))

(* 0.5 chunk-t) fade))

; gap-t:

; moving a chunk 100% means moving that chunk forward

; by 100% of the duration of chunk

; (silence gap of 1 cchunk duration)

; 0% means no position change for each chunk from original audio

(setf gap-t (* gap-t -0.01))





(let (old x start end open close result)



; extract function for this plug-in

; chunker-extract

(defun c-extract (open close sound)

(if (arrayp sound)

(vector 

(extract-abs open close (aref sound 0))

(extract-abs open close (aref sound 1)))

(extract-abs open close sound)))



; copy s to local var old and discard s

(setq old s)

(setq s nil)



; making individual audio chunks

(defun make-chunk (chunk-t i)

; define start and end times,

; which are used to extract chunk from old

(setf start (* i chunk-t))

(setf end (+ start chunk-t))

; extracting chunk from old

(c-extract start end 

; applying fade-in and fade-out

(mult 

(pwl 0 0 (/ start dur) 0 (/ (+ start fade) dur) 1.0 

(/ (- end fade) dur) 1.0 (/ end dur) 0 1)

(cue old)

) ; end mult

) ; end c-extract

) ; end defun make-chunk



; moving individual audio chunks into proper time positions

(defun move-chunks (chunk-t gap-t chunks)

(simrep (i chunks)

(at-abs (* i (- chunk-t (* gap-t chunk-t)))

(cue 

; (

; above left paren: opening of a possible added effect function

; to process each chunk differently,

; use i for changing variable of added function

(make-chunk chunk-t i)

; ) 

; above right paren: close of possible added effect function

) ; end cue

) ; end at-abs

) ; end simrep

) ; end defun move-chunks





; chunking audio

(move-chunks chunk-t gap-t chunks)

) ; close let



Other related posts:

  • » [audacity4blind] New plug-in: Audio Chunker