Re: [LAU] mixing multiple samples into a single audio file based on start times

From: Kjetil S. Matheussen <k.s.matheussen@email-addr-hidden>
Date: Sun Jan 25 2009 - 18:59:24 EET

On Sun, 25 Jan 2009, Kjetil S. Matheussen wrote:

>
> Erik Nomitch:
>>
>> Hi,
>>
>> I'm making a random "beat" generator based on a directory tree of
>> samples and a map file. Currently, it shuffles sample order and
>> creates a list of samples and their corresponding start time (example
>> list below).
>>
>> I need a good way to mix all of these seperate samples into one single
>> audio file based on the time at which each starts at. Any
>> recommendations or thoughts would be appreciated. File format doesn't
>> matter, I'll use whatever is easiest.
>>
>> Thanks,
>> Erik Nomitch
>>
>> ex:
>> at: 0.0 play /home/tux/.projects/elign/808/clap/808Clap-Kult_C2A.wav
>> at: 2.0 play /home/tux/.projects/elign/808/clap/808Clap-Kult_C2S.wav
>> at: 4.0 play /home/tux/.projects/elign/808/clap/808Clap-Kult_T1A.wav
>> at: 6.0 play /home/tux/.projects/elign/808/clap/808Clap-Kult_T1S.wav
>> at: 8.0 play /home/tux/.projects/elign/808/clap/808Clap-Kult_aOrig.wav
>> at: 10.0 play /home/tux/.projects/elign/808/clap/808Clap-R8_01.wav
>> at: 12.0 play /home/tux/.projects/elign/808/clap/808Clap-R8_01_ST.wav
>> at: 14.0 play /home/tux/.projects/elign/808/clap/808Clap-R8_01_VT1.wav
>> at: 4.0 play /home/tux/.projects/elign/808/clap/808Clap-Kult_C2A.wav
>> at: 6.0 play /home/tux/.projects/elign/808/clap/808Clap-Kult_C2S.wav
>> at: 8.0 play /home/tux/.projects/elign/808/clap/808Clap-Kult_T1A.wav
>> at: 10.0 play /home/tux/.projects/elign/808/clap/808Clap-Kult_T1S.wav
>> at: 12.0 play /home/tux/.projects/elign/808/clap/808Clap-Kult_aOrig.wav
>> at: 14.0 play /home/tux/.projects/elign/808/clap/808Clap-R8_01.wav
>> at: 16.0 play /home/tux/.projects/elign/808/clap/808Clap-R8_01_ST.wav
>> at: 18.0 play /home/tux/.projects/elign/808/clap/808Clap-R8_01_VT1.wav
>> at: 4.0 play /home/tux/.projects/elign/808/clap/808Clap-Kult_C2A.wav
>> at: 8.0 play /home/tux/.projects/elign/808/clap/808Clap-Kult_C2S.wav
>> at: 12.0 play /home/tux/.projects/elign/808/clap/808Clap-Kult_T1A.wav
>> at: 16.0 play /home/tux/.projects/elign/808/clap/808Clap-Kult_T1S.wav
>> at: 20.0 play /home/tux/.projects/elign/808/clap/808Clap-Kult_aOrig.wav
>> at: 24.0 play /home/tux/.projects/elign/808/clap/808Clap-R8_01.wav
>> at: 28.0 play /home/tux/.projects/elign/808/clap/808Clap-R8_01_ST.wav
>> at: 32.0 play /home/tux/.projects/elign/808/clap/808Clap-R8_01_VT1.wav
>> etc...
>>
>
> Below is some code I have hacked together for Snd to do this.
> Compile snd with the "--with-guile" option, save your txt
> above ("at: etc.") into a file called "score.txt", start Snd, and paste the
> code below into the terminal you started
> snd in.
>
> Alternatively, you can save the code below into a
> file, and use the "-b" option to start a gui-less
> Snd which load and runs a specified script file.
>

Oops, I didn't test this on a clean Snd, and there seems
to be a lot of dependencies. Instead, use
snd-ls, http://heim.ifi.uio.no/~ksvalast/arkiv/src/snd/,
and the code below instead:

(define (map-file filename func)
   (let* ((fd (open-file filename "r"))
          (line (read-line fd))
          (ret '()))
     (while (not (eof-object? line))
       (set! ret (cons (func line) ret))
       (set! line (read-line fd)))
     (reverse ret)))

(define* (fileplay seconds filename)
   (let* ((samples (seconds->samples seconds))
          (end (+ (mus-sound-frames filename) samples)))
     (for-each (lambda (ch)
                 (define fd (make-readin filename :channel ch))
                 (run
                  (lambda ()
                    (do ((i samples (1+ i))) ((= i end))
                      (out-any i (readin fd) ch *output*)))))
               (iota (mus-sound-chans filename)))))

(define (create score samplerate channels outfile)
   (set! (optimization) 6)
   (primitive-eval `(with-sound (:srate ,samplerate :channels ,channels :output ,outfile)
                                ,@(map (lambda (start filename)
                                         `(fileplay ,start ,filename))
                                       (map string->number (map cadr (map-file score (lambda (l) (string-split l #\space)))))
                                       (map cadddr (map-file score (lambda (l) (string-split l #\space))))))))

(create "score.txt" 44100 2 "/tmp/test.wav")

_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@email-addr-hidden
http://lists.linuxaudio.org/mailman/listinfo/linux-audio-user
Received on Sun Jan 25 20:15:02 2009

This archive was generated by hypermail 2.1.8 : Sun Jan 25 2009 - 20:15:02 EET