Bidirectional looping problem

You're new to the LinuxSampler world? You don't know where to start and nothing works? Here's the place to ask for help.
Post Reply
io7m
Newbie
Posts: 10
Joined: Tue Oct 03, 2017 11:03 am
Contact:

Bidirectional looping problem

Post by io7m » Tue Oct 03, 2017 11:22 am

Hello.

I have the following:

http://ataxia.io7m.com/2017/10/03/fish_kit.gig

It's an experimental drum kit that uses bidirectional looping to indefinitely extend "percussion" sounds.

The problem: Bidirectional looping seems not to work for most samples. I seem to get ordinary forward looping. It's particularly noticeable on the ride cymbal samples around C4, because they have a flanging effect applied to them and it's very obvious upon listening that the sample is being looped only in the forward direction.

Is there something I'm doing wrong?

plusminus
Newbie
Posts: 22
Joined: Tue Jun 21, 2016 3:32 am

Re: Bidirectional looping problem

Post by plusminus » Wed Oct 04, 2017 6:28 am

linuxsampler loop size needs to be in around 32000 for bidirectional loop
to kick in. You can make adjustments before compiling if you're building your own.
Read here:
https://www.linuxsampler.org/debian.html

while building instruments in gigedit, If my loop sizes are less than 32000 (usually percussions or hits),
I'll open the sample in audacity, copy and paste making the sample twice as long then reversing the pasted part.
I'll set the loop direction in gigedit to foward. You'll never hear the difference ;) .

io7m
Newbie
Posts: 10
Joined: Tue Oct 03, 2017 11:03 am
Contact:

Re: Bidirectional looping problem

Post by io7m » Wed Oct 04, 2017 11:17 am

plusminus wrote:linuxsampler loop size needs to be in around 32000 for bidirectional loop
to kick in.
OK, thanks!

When you say that it has to be around 32000 before looping kicks in, do you mean that the total sample length has to be >= 32000, or do you mean that the loop start point has to be at >= 32000 samples?

What's the rationale for having that minimum length? I've developed a few samplers in my time via tools like Pure Data and it seems rather odd that there'd be a minimum length at all...
plusminus wrote: while building instruments in gigedit, If my loop sizes are less than 32000 (usually percussions or hits),
I'll open the sample in audacity, copy and paste making the sample twice as long then reversing the pasted part.
I'll set the loop direction in gigedit to foward. You'll never hear the difference ;) .
Got it.

io7m
Newbie
Posts: 10
Joined: Tue Oct 03, 2017 11:03 am
Contact:

Re: Bidirectional looping problem

Post by io7m » Wed Oct 04, 2017 5:06 pm

I've just realized you said "loop size", as in the number of samples between the loop start and loop end points.

plusminus
Newbie
Posts: 22
Joined: Tue Jun 21, 2016 3:32 am

Re: Bidirectional looping problem

Post by plusminus » Wed Oct 04, 2017 10:42 pm

io7m wrote:I've just realized you said "loop size", as in the number of samples between the loop start and loop end points.
Sorry, i should of emphasized on that .
I also meant to say the loop size samples have to be around 32000 or greater (not in or around) for loop size to kick in.
Why this is?... i dont know. maybe sample caching.
I halved the number in "--enable-preload-samples=65536" during compile (going back to the link in my last post) allowing for smaller loop size and bidirectional looping, but with that came stream errors. I know i can find a sweet spot but I find experimenting (in audacity) by lengthening the sample; e.g. copy,paste and reversing the later half, produces interesting results with forward or bidirectional looping.

io7m
Newbie
Posts: 10
Joined: Tue Oct 03, 2017 11:03 am
Contact:

Re: Bidirectional looping problem

Post by io7m » Wed Oct 04, 2017 11:34 pm

Small script I'm using to preprocess samples in the manner you describe:

Code: Select all

#!/bin/sh

if [ $# -ne 2 ]
then
  echo "usage: in out" 2>&1
  exit 1
fi

FILE_IN="$1"
shift
FILE_OUT="$1"
shift

LOOP_START='0.3'
LOOP_END='0.35'

TEMPORARIES=`mktemp -d` || exit 1
trap "rm -rv $TEMPORARIES" EXIT || exit 1

#
# First, trim all leading and trailing silence from the sample.
#

TRIMMED=`mktemp -p "${TEMPORARIES}" initial_trim.XXXXXXXX.wav` || exit 1
sox -V6 "${FILE_IN}" "${TRIMMED}" silence 1 0.001 1% reverse silence 1 0.001 1% reverse || exit 1

#
# Then, measure the trimmed sample and work out where the loop
# start and loop end points should be.
#

TIME=`soxi -D "${TRIMMED}"` || exit 1
LOOP_TIME_START=`echo "${TIME} * ${LOOP_START}" | bc -l` || exit 1
LOOP_TIME_END=`echo "${TIME} * ${LOOP_END}" | bc -l` || exit 1

#
# Now, cut out the piece of audio between the start and end loop
# points, reverse it, and then concatenate copies of the ordinary
# and reversed pieces to a truncated copy of the original sample.
#

SPLIT_FORWARDS=`mktemp -p "${TEMPORARIES}" half_f.XXXXXXXX.wav` || exit 1
SPLIT_BACKWARDS=`mktemp -p "${TEMPORARIES}" half_r.XXXXXXXX.wav` || exit 1
SPLIT_INITIAL=`mktemp -p "${TEMPORARIES}" init.XXXXXXXX.wav` || exit 1

sox -V6 "${TRIMMED}" "${SPLIT_INITIAL}" trim 0 "${LOOP_TIME_START}" || exit 1
sox -V6 "${TRIMMED}" "${SPLIT_FORWARDS}" trim "${LOOP_TIME_START}" "${LOOP_TIME_END}" || exit 1
sox -V6 "${SPLIT_FORWARDS}" "${SPLIT_BACKWARDS}" reverse || exit 1

SEQUENCE="${SPLIT_INITIAL} ${SPLIT_FORWARDS}"
SEQUENCE="${SEQUENCE} ${SPLIT_BACKWARDS} ${SPLIT_FORWARDS}"
SEQUENCE="${SEQUENCE} ${SPLIT_BACKWARDS} ${SPLIT_FORWARDS}"
SEQUENCE="${SEQUENCE} ${SPLIT_BACKWARDS} ${SPLIT_FORWARDS}"
SEQUENCE="${SEQUENCE} ${SPLIT_BACKWARDS} ${SPLIT_FORWARDS}"
SEQUENCE="${SEQUENCE} ${SPLIT_BACKWARDS} ${SPLIT_FORWARDS}"
SEQUENCE="${SEQUENCE} ${SPLIT_BACKWARDS} ${SPLIT_FORWARDS}"
SEQUENCE="${SEQUENCE} ${SPLIT_BACKWARDS} ${SPLIT_FORWARDS}"
SEQUENCE="${SEQUENCE} ${SPLIT_BACKWARDS}"

sox -V6 ${SEQUENCE} "${FILE_OUT}" || exit 1

plusminus
Newbie
Posts: 22
Joined: Tue Jun 21, 2016 3:32 am

Re: Bidirectional looping problem

Post by plusminus » Thu Oct 05, 2017 2:58 am

How is this utilized?
Edit: never mind. i installed sox and it works!! This is great :mrgreen:
Thanks for this.

io7m
Newbie
Posts: 10
Joined: Tue Oct 03, 2017 11:03 am
Contact:

Re: Bidirectional looping problem

Post by io7m » Wed Oct 25, 2017 4:18 pm

Hello!

plusminus: I received your message about processing directories, but unfortunately I don't have a high enough user level here to send private messages.

In order to process a directory full of samples, you could do something like this:

Let's assume you've got all of your original samples in a subdirectory called samples, and the loop.sh script is in the current directory:

Code: Select all

$ ls -alF loop.sh
-rwxr-xr-x 1 someone someone 1959 2017-10-04 22:35 loop.sh

$ ls -alF samples
drwxr-xr-x 2 someone someone   4096 2017-10-03 11:12 ./
drwxr-xr-x 7 someone someone   4096 2017-10-04 22:39 ../
-rw-r--r-- 1 someone someone 115236 2017-10-02 20:45 fk_01.wav
-rw-r--r-- 1 someone someone 115260 2017-10-02 20:45 fk_02.wav
-rw-r--r-- 1 someone someone 115276 2017-10-02 20:45 fk_03.wav
-rw-r--r-- 1 someone someone 115196 2017-10-02 20:45 fk_04.wav
-rw-r--r-- 1 someone someone 115252 2017-10-02 20:45 fk_05.wav
-rw-r--r-- 1 someone someone 115260 2017-10-02 20:45 fk_06.wav
-rw-r--r-- 1 someone someone 115252 2017-10-02 20:45 fk_07.wav
-rw-r--r-- 1 someone someone 115228 2017-10-02 20:45 fk_08.wav
-rw-r--r-- 1 someone someone 115260 2017-10-02 20:45 fk_09.wav
-rw-r--r-- 1 someone someone 345620 2017-10-02 20:45 fk_10.wav
-rw-r--r-- 1 someone someone 147344 2017-10-03 09:56 fk_11.wav
-rw-r--r-- 1 someone someone 142608 2017-10-03 09:57 fk_12.wav
-rw-r--r-- 1 someone someone 143940 2017-10-03 09:58 fk_13.wav
-rw-r--r-- 1 someone someone 148184 2017-10-03 09:58 fk_14.wav
-rw-r--r-- 1 someone someone  22464 2017-10-03 11:11 fk_15.wav
-rw-r--r-- 1 someone someone  42196 2017-10-03 11:12 fk_16.wav
What you want to be able to say is "for each file f that has a name ending in .wav, run loop.sh on f and put the output into a directory called samples_extended with the same filename as the original". You can translate that statement almost word for word into shell script:

Code: Select all

$ mkdir samples_extended
$ cd samples
$ for f in *.wav; do ../loop.sh "$f" "../samples_extended/$f"; done
You should now see a lot of extended samples in samples_extended:

Code: Select all

$ cd ..
$ ls -alF samples_extended
drwxr-xr-x 2 someone someone   4096 2017-10-04 16:12 ./
drwxr-xr-x 7 someone someone   4096 2017-10-04 22:39 ../
-rw-r--r-- 1 someone someone 185336 2017-10-04 16:13 fk_01.wav
-rw-r--r-- 1 someone someone 215344 2017-10-04 16:13 fk_02.wav
-rw-r--r-- 1 someone someone 318308 2017-10-04 16:13 fk_03.wav
-rw-r--r-- 1 someone someone 110220 2017-10-04 16:13 fk_04.wav
-rw-r--r-- 1 someone someone 143328 2017-10-04 16:13 fk_05.wav
-rw-r--r-- 1 someone someone 264432 2017-10-04 16:13 fk_06.wav
-rw-r--r-- 1 someone someone 156344 2017-10-04 16:13 fk_07.wav
-rw-r--r-- 1 someone someone 288908 2017-10-04 16:13 fk_08.wav
-rw-r--r-- 1 someone someone  92692 2017-10-04 16:13 fk_09.wav
-rw-r--r-- 1 someone someone 178864 2017-10-04 16:13 fk_10.wav
-rw-r--r-- 1 someone someone 749312 2017-10-04 16:13 fk_11.wav
-rw-r--r-- 1 someone someone 749580 2017-10-04 16:13 fk_12.wav
-rw-r--r-- 1 someone someone 700492 2017-10-04 16:13 fk_13.wav
-rw-r--r-- 1 someone someone 736568 2017-10-04 16:13 fk_14.wav
-rw-r--r-- 1 someone someone  50344 2017-10-04 16:13 fk_15.wav
-rw-r--r-- 1 someone someone 104152 2017-10-04 16:13 fk_16.wav
You can see from the fifth column that the samples in samples_extended are larger.

There's a good (free) book on this stuff here: http://linuxcommand.org/tlcl.php

Don't sweat not knowing how to do it. The UNIX shell has a well-deserved reputation for being ugly, inconsistent, and awkward to learn.

plusminus
Newbie
Posts: 22
Joined: Tue Jun 21, 2016 3:32 am

Re: Bidirectional looping problem

Post by plusminus » Wed Oct 25, 2017 4:45 pm

:D :D :D :D :D
I hope i wasn't too obvious ;)
Superb!... And thank you for the link.
It will make great reading.

Post Reply