]> git.rm.cloudns.org Git - xonotic/mediasource.git/commitdiff
make this mess work with fluidsynth too :P
authorRudolf Polzer <divverent@xonotic.org>
Wed, 12 Oct 2011 04:28:18 +0000 (06:28 +0200)
committerRudolf Polzer <divverent@xonotic.org>
Wed, 12 Oct 2011 04:28:18 +0000 (06:28 +0200)
sound/weapons/loopfinder/findloop.c
sound/weapons/tuba_loopnote_maker.mid [deleted file]
sound/weapons/tuba_loopnote_maker.mid.pl [new file with mode: 0644]
sound/weapons/tuba_loopnote_maker.sh

index 661f41d1b9dfdcc9bae0536df233805ed503c24c..22073187ceab3a9f4eed2d50f0a8951e7ecef997 100644 (file)
@@ -81,12 +81,12 @@ sf_count_t findMaximumSingle(double (*func) (sf_count_t), sf_count_t x0, sf_coun
        return bestpos;
 }
 
-sf_count_t findMaximum(double (*func) (sf_count_t), sf_count_t x0, sf_count_t xgm, sf_count_t x1)
+sf_count_t findMaximum(double (*func) (sf_count_t), sf_count_t x0, sf_count_t xg, sf_count_t xg2, sf_count_t x1)
 {
-       sf_count_t xg, xg2, xg0, xg20;
+       sf_count_t xg0, xg20;
 
-       xg0 = xg = MAX(x0, xgm - 65536);
-       xg20 = xg2 = MIN(xgm + 65536, x1);
+       xg0 = xg = MAX(x0, MIN(xg, x1));
+       xg20 = xg2 = MAX(x0, MIN(xg2, x1));
 
        for(;;)
        {
@@ -128,6 +128,7 @@ int main(int argc, char **argv)
 
        sf_count_t size = MIN(infile_info.frames, strtod(argv[3], NULL) * infile_info.samplerate);
        sf_count_t guess = strtod(argv[4], NULL) * infile_info.samplerate;
+       sf_count_t guess2 = strtod(argv[5], NULL) * infile_info.samplerate;
        int channels = infile_info.channels;
        size_t fftsize = atoi(argv[2]);
        size_t ndata = channels * (fftsize/2 + 1);
@@ -214,7 +215,7 @@ int main(int argc, char **argv)
        }
 #endif
 
-       sf_count_t best = findMaximum(similarityAt, 0, guess - fftsize, size - 2 * fftsize);
+       sf_count_t best = findMaximum(similarityAt, 0, guess - fftsize, guess2 - fftsize, size - 2 * fftsize);
        fprintf(stderr, "Result: %.9f (sample %ld)\n", (best + fftsize) / (double) infile_info.samplerate, (long) (best + fftsize));
 
        // Now write it!
@@ -239,7 +240,7 @@ int main(int argc, char **argv)
 
        // 2. Open sound file
        fprintf(stderr, "Opening...\n");
-       SNDFILE *outfile = sf_open(argv[5], SFM_WRITE, &infile_info);
+       SNDFILE *outfile = sf_open(argv[6], SFM_WRITE, &infile_info);
        if(!outfile)
                err(1, "open");
 
diff --git a/sound/weapons/tuba_loopnote_maker.mid b/sound/weapons/tuba_loopnote_maker.mid
deleted file mode 100644 (file)
index d1023ac..0000000
Binary files a/sound/weapons/tuba_loopnote_maker.mid and /dev/null differ
diff --git a/sound/weapons/tuba_loopnote_maker.mid.pl b/sound/weapons/tuba_loopnote_maker.mid.pl
new file mode 100644 (file)
index 0000000..5f9a3f3
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use MIDI;
+use MIDI::Opus;
+
+my ($file, $delta, $program, $velocity, $transpose, @notes) = @ARGV;
+
+my $track = MIDI::Track->new();
+
+$track->new_event('set_tempo', 0, $delta * 1000000);
+$track->new_event('patch_change', 0, 0, $program - 1);
+for(@notes)
+{
+       $track->new_event('note_on', 96, 0, $transpose + $_, $velocity);
+       $track->new_event('note_off', 96, 0, $transpose + $_, $velocity);
+}
+
+my $opus = MIDI::Opus->new({
+               format => 0,
+               ticks => 96,
+               tracks => [ $track ],
+               });
+
+$opus->write_to_file($file);
index ce9fd9bd24032c036a0b10175f186958a8034b6f..7c1d55aa79c2f02991a86fb2625cf8a9b9111c68 100755 (executable)
@@ -9,26 +9,31 @@ set -ex
 
 synth=$1; shift
 program=$1; shift
+velocity=$1; shift
+transpose=$1; shift
 tubaid=$1; shift
 
+delta=2
+fftsize=512
+loopmin=1.1
+loopmax=1.5
+len=1.8
+
+perl tuba_loopnote_maker.mid.pl tuba_loopnote_maker.mid $delta $program $velocity $transpose -18 -12 -6 0 6 12 18 24
+
 case "$synth" in
        timidity)
-               timidity -Ow -EI$program "$@" -o out.wav tuba_loopnote_maker.mid
+               timidity -Ow "$@" -o out.wav tuba_loopnote_maker.mid
                normalize out.wav
                ;;
        fluidsynth)
-               {
-                       echo "prog 0 $program"
-               } > in.cfg
-               fluidsynth -v -f in.cfg -n -i -l -T wav -F out.wav "$@" tuba_loopnote_maker.mid
+               fluidsynth -v -n -i -l -T wav -F out.wav "$@" tuba_loopnote_maker.mid
                normalize out.wav
                ;;
 esac
 
-start=0
-step=4
-loop=1.0
-len=1.5
+start=$delta
+step=$(($delta*2))
 for note in -18 -12 -6 0 6 12 18 24; do
        sox out.wav n$note.wav \
                trim $start $step \
@@ -37,7 +42,7 @@ for note in -18 -12 -6 0 6 12 18 24; do
        fn=tuba"$tubaid"_loopnote"$note".ogg 
 
        # now find loop point
-       loopfinder/findloop n$note.wav 4096 $len $loop t$note.wav | while read -r SAMPLES SECONDS; do
+       loopfinder/findloop n$note.wav $fftsize $len $loopmin $loopmax t$note.wav | while read -r SAMPLES SECONDS; do
                oggenc -q9 -o "$fn" -c "LOOP_START=$SAMPLES" t$note.wav
        done