Message Boards Message Boards

5
|
3122 Views
|
0 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Easy generation, testing, and export of audio loops

Posted 6 years ago

I wanted to build some samples where the individual notes in a chord would repeat at various rates, and I needed to do it quickly (I had a performance coming up and of course I procrastinated). The traditional method—getting the sounds into a DAW, setting up the individual tracks for each note, setting the fade-ins and fade-outs, testing the loops, exporting, and all the rest—would have been too time consuming. The Wolfram Language made the process a breeze. Plus, I could make adjustments and test them much quicker.

This is the chord:

a nice, big sounding chord

First, I made a list of keys for when I use Map[] to build "the chord" and export the files:

keys = {"1", "2", "3", "4", "5", "6"};

Next, I set up the fade-in time and the durations of my loops. The tempo will be 80 beats per minute, so I needed to convert the number of beats into seconds for SoundNote[]:

fadein = N[2/80] *60; (*2 beats*)
time1 = N[24/80] *60; (*6 measures*)
time2 = N[20/80] *60; (*5 measures*)
time3 = N[18/80] *60; (*4.5 measures*)
time4 = N[28/80] *60; (*7 measures*)
time5 = N[16/80] *60; (*4 measures*)
time6 = N[22/80] *60; (*5.5 measures*)

Then, I set up the individual notes to be looped. The fade-in time was defined above, and I wanted the fade-out time to be half the length of the SoundNote[]. There was also no need for the final files to be in stereo, so I used AudioChannelMix[]:

note1 = AudioChannelMix[AudioFade[Sound[SoundNote["D4", time1, "BlownBottle"]], {fadein, N[time1/2]}, Method -> "Exp"], "Mono"];
note2 = AudioChannelMix[AudioFade[Sound[SoundNote["A4", time2, "BlownBottle"]], {fadein, N[time2/2]}, Method -> "Exp"], "Mono"];
note3 = AudioChannelMix[AudioFade[Sound[SoundNote["E5", time3, "BlownBottle"]], {fadein, N[time3/2]}, Method -> "Exp"], "Mono"];
note4 = AudioChannelMix[AudioFade[Sound[SoundNote["G5", time4, "BlownBottle"]], {fadein, N[time4/2]}, Method -> "Exp"], "Mono"];
note5 = AudioChannelMix[AudioFade[Sound[SoundNote["B5", time5, "BlownBottle"]], {fadein, N[time5/2]}, Method -> "Exp"], "Mono"];
note6 = AudioChannelMix[AudioFade[Sound[SoundNote["E6", time6, "BlownBottle"]], {fadein, N[time6/2]}, Method -> "Exp"], "Mono"];

Time to play! This one will start as a giant chord and then the individual notes will fade in and out:

Map[AudioPlay[ToExpression[StringJoin["note", #]], AudioLooping -> True] &, keys]

Or evaluate one at a time, in any order, and any pause between notes.

AudioPlay[note1, AudioLooping -> True]
AudioPlay[note2, AudioLooping -> True]
AudioPlay[note3, AudioLooping -> True]
AudioPlay[note4, AudioLooping -> True]
AudioPlay[note5, AudioLooping -> True]
AudioPlay[note6, AudioLooping -> True]

After enough testing or listening enjoyment, stop all sounds:

AudioStop[]

After trying out both, I decided to go with the "big chord" approach. It was nice to be able to test both before exporting. It was also nice to be able to quickly adjust the times of the individual notes by going up to my initial definitions.

And now, to export:

Map[Export[StringJoin["loop", #, ".wav"], ToExpression[StringJoin["note", #]]] &, keys]

This gave me a set of similarly named wav files (loop1.wav, loop2.wav, etc), so I could find them easily in my sample pad.

POSTED BY: Richard Miske
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract