chords out of tone samples in batch

SuperCollider, Pure Data, ChucK, CSound, Nyquist, Overtone, TidalCycles, Bipscript, oh my

Moderators: MattKingUSA, khz

Post Reply
delete000
Established Member
Posts: 45
Joined: Fri Dec 31, 2021 7:48 pm
Has thanked: 12 times
Been thanked: 2 times

chords out of tone samples in batch

Post by delete000 »

I have a bunch of single tone samples (all in C) and would like to build a chord from each sample (say, CMaj7) by simply transposing and overlaying each sample to itself. The samples are properly cropped to begin and end at zero-crossings, so they can be seamlessly looped.

Anyone know what sox magic I can use to automate the process?

Context: I want to make chord samples for my Digitakt. I know I can just resample on the Digitakt, but the prospect of doing this for dozens of samples doesn't seem too appealing....

User avatar
d.healey
Established Member
Posts: 611
Joined: Fri Sep 22, 2017 8:33 pm
Has thanked: 279 times
Been thanked: 101 times

Re: chords out of tone samples in batch

Post by d.healey »

Signet can do pitch shifting. Using a bash script you could loop through a folder of samples to batch process them - https://github.com/SamWindell/Signet

David Healey
YouTube - Free HISE scripting and sample library dev tutorials
Libre Wave - Freedom respecting instruments and effects.
Chibchan
Established Member
Posts: 67
Joined: Wed Jun 19, 2013 6:56 am
Location: Brooklyn
Has thanked: 1 time
Been thanked: 9 times

Re: chords out of tone samples in batch

Post by Chibchan »

maybe get to know sox this way. Think of it as investment. :wink:

https://stackoverflow.com/questions/242 ... rate-audio

Chibchan
Established Member
Posts: 67
Joined: Wed Jun 19, 2013 6:56 am
Location: Brooklyn
Has thanked: 1 time
Been thanked: 9 times

Re: chords out of tone samples in batch

Post by Chibchan »

Nice!
just learned something. :wink:
this little bit of code will create AND delete a folder called "sox_chord" along with the 3 wav files to create chord.
save script as "C_chord", make executable and run again if needed.
Very easy to modify and create new chords.

Code: Select all

#!/bin/bash
mkdir -p sox_chord
sox -n -r 8000 sox_chord/C_output.wav synth 3 sine 261.6
sox -n -r 8000 sox_chord/E_output.wav synth 3 sine 329.63
sox -n -r 8000 sox_chord/G_output.wav synth 3 sine 392
sox -m sox_chord/*.wav C_chord.wav
rm -r sox_chord
delete000
Established Member
Posts: 45
Joined: Fri Dec 31, 2021 7:48 pm
Has thanked: 12 times
Been thanked: 2 times

Re: chords out of tone samples in batch

Post by delete000 »

@Chibchan thanks.

In the end it was simpler than I thought. I had seen how to do it with the sox synth, I just needed to figure out how to do it with samples.

Here's a quick and dirty bash script that generates most common triads and 7th chords from a wav file:

Code: Select all

wv=$1
fn=${wv:0:-4}
# Major triads
sox ${wv} 2nd-voice.wav pitch 400
sox ${wv} 3rd-voice.wav pitch 700
sox -m ${wv} 2nd-voice.wav 3rd-voice.wav ${fn}M.wav
rm -rf 2nd-voice.wav 3rd-voice.wav
# Minor triads
sox ${wv} 2nd-voice.wav pitch 300
sox ${wv} 3rd-voice.wav pitch 700
sox -m ${wv} 2nd-voice.wav 3rd-voice.wav ${fn}m.wav
rm -rf 2nd-voice.wav 3rd-voice.wav
# Diminished triads
sox ${wv} 2nd-voice.wav pitch 300
sox ${wv} 3rd-voice.wav pitch 600
sox -m ${wv} 2nd-voice.wav 3rd-voice.wav ${fn}o.wav
rm -rf 2nd-voice.wav 3rd-voice.wav
# Augmented triads
sox ${wv} 2nd-voice.wav pitch 400
sox ${wv} 3rd-voice.wav pitch 800
sox -m ${wv} 2nd-voice.wav 3rd-voice.wav ${fn}+.wav
rm -rf 2nd-voice.wav 3rd-voice.wav
# Major 7th
sox ${wv} 2nd-voice.wav pitch 400
sox ${wv} 3rd-voice.wav pitch 700
sox ${wv} 4th-voice.wav pitch 1100
sox -m ${wv} 2nd-voice.wav 3rd-voice.wav 4th-voice.wav ${fn}M7.wav
rm -rf 2nd-voice.wav 3rd-voice.wav 4th-voice.wav
# Minor 7th
sox ${wv} 2nd-voice.wav pitch 300
sox ${wv} 3rd-voice.wav pitch 700
sox ${wv} 4th-voice.wav pitch 1000
sox -m ${wv} 2nd-voice.wav 3rd-voice.wav 4th-voice.wav ${fn}m7.wav
rm -rf 2nd-voice.wav 3rd-voice.wav 4th-voice.wav
# Dominant 7th
sox ${wv} 2nd-voice.wav pitch 400
sox ${wv} 3rd-voice.wav pitch 700
sox ${wv} 4th-voice.wav pitch 1000
sox -m ${wv} 2nd-voice.wav 3rd-voice.wav 4th-voice.wav ${fn}7.wav
rm -rf 2nd-voice.wav 3rd-voice.wav 4th-voice.wav
# Minor 7b5
sox ${wv} 2nd-voice.wav pitch 300
sox ${wv} 3rd-voice.wav pitch 600
sox ${wv} 4th-voice.wav pitch 1000
sox -m ${wv} 2nd-voice.wav 3rd-voice.wav 4th-voice.wav ${fn}7b5.wav
rm -rf 2nd-voice.wav 3rd-voice.wav 4th-voice.wav
# Minor major 7th
sox ${wv} 2nd-voice.wav pitch 300
sox ${wv} 3rd-voice.wav pitch 700
sox ${wv} 4th-voice.wav pitch 1100
sox -m ${wv} 2nd-voice.wav 3rd-voice.wav 4th-voice.wav ${fn}mM7.wav
rm -rf 2nd-voice.wav 3rd-voice.wav 4th-voice.wav
# Augmented major 7th
sox ${wv} 2nd-voice.wav pitch 400
sox ${wv} 3rd-voice.wav pitch 800
sox ${wv} 4th-voice.wav pitch 1100
sox -m ${wv} 2nd-voice.wav 3rd-voice.wav 4th-voice.wav ${fn}+M7.wav
rm -rf 2nd-voice.wav 3rd-voice.wav 4th-voice.wav
# Diminished 7th
sox ${wv} 2nd-voice.wav pitch 300
sox ${wv} 3rd-voice.wav pitch 600
sox ${wv} 4th-voice.wav pitch 900
sox -m ${wv} 2nd-voice.wav 3rd-voice.wav 4th-voice.wav ${fn}o7.wav
rm -rf 2nd-voice.wav 3rd-voice.wav 4th-voice.wav

If the sample is single cycle and needs to be looped, the above can be preceded by:

Code: Select all

sox in.wav out.wav repeat 32
Post Reply