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(;;)
{
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);
}
#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!
// 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");
--- /dev/null
+#!/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);
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 \
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