My Music (Listen with quality headphones)

Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

Sunday, 17 February 2013

Linux bash script code to convert wav file into equal wav loops based on in-parameters

Let's say you've recorded a track in LMMS that is composed of 10 measures *of equal length*, at 140 BPM (beats per minute) and you want to convert each measure to its own wav file loop, i.e. 10 individual loop files.


The script below does exactly this.

To use this script in linux:
0) make sure you have installed sox:
sudo apt-get install sox

1) paste the bash script code below into a new file called makeloops.sh and save it somewhere, e.g. ~/Downloads/ (the Downloads folder in your home directory, i.e. /home/me/Downloads)

2) make the bash script file executable:
chmod +x ~/Downloads/makeloops.sh

3) cd to the folder where your wav file (e.g. input.wav) is, e.g.:
cd ~/lmms/projects/your-lmms-project/

4) run makeloops.sh, e.g.:
. ~/Downloads/makeloops.sh input.wav 140 10 1

###### makeloops.sh (START COPYING BELOW THIS LINE) ####

#!/bin/bash

# INPUT PARAMETERS: $1==inputfile name (e.g. input.wav), $2==bpm (e.g. 140), $3==total measures of input file (e.g. 10), $4==loop length measures (e.g. 1), $5==loop folder name (e.g. loops)
#
# e.g. say you have a wav file, input.wav, that contains 10 measures *of equal length* of 140 BPM audio and you want to convert each measure to its own wav file loop:
#
#    SEE "HELP" SECTION FOR EXAMPLE
#

EXPECTED_ARG_COUNT=5

# HELP
# IF NUMBER OF PARAMS < 5, OUTPUT HELP TEXT
if [ $# -ne $EXPECTED_ARG_COUNT ]
then
    echo "";
    echo "USAGE: makeloops.sh input-file-name BPM total-number-of-measures-in-input-file number-of-measures-for-loop-length loop-folder-name";
    echo "";
    echo "EXAMPLE: nickleus@mylaptop:/path/to/input/wav/file/$ . /path/to/makeloops.sh input.wav 140 10 1 loops";
    echo "";

else

LOOPSTART=0;
BPS=$(echo $2/60|bc -l);
BEATS=$(echo 4*$4|bc -l);
LOOPLENGTH=$(echo $BEATS/$BPS | bc -l | awk '{printf("%.7f", $1);}');    # max 7 digits to the right of the decimal place for float numbers, no leading zeros on left side of decimal place

# INPUT ($2) 140    ($3) 10    ($4) 1
#echo $BPS    # 2.33333333333333333333
#echo $BEATS    # 4
#echo $LOOPLENGTH    # 1.7142857

LOOPSFOLDER=$5;
mkdir $LOOPSFOLDER;

for (( w = 0 ; w < $3 ; w++ ));
do
sox -V4 "$1" "./$LOOPSFOLDER/$w.wav" trim $LOOPSTART $LOOPLENGTH;
LOOPSTART=$(echo $LOOPSTART+$LOOPLENGTH|bc -l);
done;

fi


###### (STOP COPYING ABOVE THIS LINE) ####


Note: If you don't want sox to run in full verbose mode, then just remove -V4; but it can be interesting to see what sox is actually doing during conversion.

Wednesday, 13 February 2013

Useful linux bash commands for audio file editing and manipulation

Here are some useful linux bash commands I use to convert between different audio file types when making my samples.


AUDIO COMMANDS


Extract audio from a flash video file (flv) and save it as a wav:
mplayer video.flv -vc null -vo null -ao pcm:fast:waveheader:file=outfile.wav


Capture a live audio stream from the system output and save it as a flac file:
jack_capture -f flac


Convert a flac file to a high quality mp3 file with a 128kbps bitrate:
flac -cd sample.flac |lame -h – sample.mp3


Convert all flac files in the current directory to high quality mp3 files with a 128kbps bitrate:
for f in *.flac;do flac -cd "$f"|lame -b 192 – "${f%.flac}.mp3";done


Convert a flac file to a wav file:
flac -d sample.flac


Convert all flac files in the current directory to wav files:
flac -d *


Convert a flac file to an ogg vorbis audio file:
oggenc sample.flac -o sample.ogg

Convert all wav files in the current directory to ogg:
for w in *.wav;do oggenc "$w" -o "${w%.wav}.ogg";done


Convert a wav file to an mp3 with 192 bitrate:
lame -b 192 sample.wav


Reversing the audio playback of a file and saving it as a new file:
sox input.flac output.flac reverse


Trim an audio file, starting e.g. at 0 and stopping at 6.85714 seconds:
sox input.wav output.wav trim 0 6.85714


Batch trim all flac files in a folder, starting e.g. at 0 and stopping at 3.47826087 seconds:
for f in *.flac;do sox "$f" "${f%.flac}_.flac" trim 0 3.47826087;done


Remove the first 0.047 seconds of an audio file:
sox input.wav output.wav trim 0.047


Combine (concatenate) all flac files in the current directory into one file:
sox --combine concatenate $(ls|grep .flac) out.flac


Add the LADSPA canyon delay effect to a whole folder of flac files in batch mode:
for f in *.flac;do ecasound -i:"$f" -o:"${f%.flac}_.flac" -el:canyon_delay,0.439,-0.14,0.439,0.5,2735.45288;done


Batch fix loop files that click at the end, by adding a fadeout effect to the very end of the file:
for w in *.wav;do sox "$w" "${w%.wav}_.wav" fade 0 $(soxi -D $w) 0.00045;done




List numbered loops files generated from "" from 0.wav...N.wav (used as in parameter for the command "Combine (concatenate) all flac files in the current directory into one file"):
ls -tr


Extract xml metadata from lmms mmpz file (e.g. to get the track measure labels you set):
lmms -d my-lmms-project.mmpz > dump.xml



VIDEO COMMANDS


Convert flash flv video to mp4:
ffmpeg -i input.flv output.mp4



On a related noted, here are my photo tutorials about music production.

Saturday, 9 February 2013

How to remove the click at the end of loops exported from LMMS

UPDATE 20130210: Apparently the problem is with VST plugins because you can't use their envelope settings to set release to 0 (which would fix the problem):
"Note: the first thing that must be emphasized is that no VeSTige instrument will respond to anything on this tab! You can't use envelopes or filters, because VST generates sounds using an internal method that excludes LMMS's envelopes completely."


In LMMS 0.4.14-rc1 you can export tracks as loops:
Project > Export > choose filename > Save > click "Export as loop" > Start

If you open the loop in e.g. Audacity and loop it, you might hear a little click sound at the end of the file. This can be because the wav doesn't end in the middle, i.e.:





To fix this for a specific file, you can do it manually in Audacity by selecting the last part of the wav where it's in the middle, then hold in the Shift key and press the End key > Effect > Fade Out.



To fix this in a batch process, for many files, automatically, do this:
0) If you don't have sox installed:
sudo apt-get install sox

1) Open a terminal. Change directory to the folder containing the loop files to post-process:
cd /path/to/loops/to/fix/


2) Loop through the files and add a fade out effect using sox:
for w in *.wav;do sox "$w" "${w%.wav}_.wav" fade 0 $(soxi -D $w) 0.00045;done

Note: soxi -D $w outputs the length of the audio input file.

Tuesday, 5 February 2013

How to install LMMS 0.4.14-rc1 with VST support on Ubuntu 12.04 (Precise Pangolin)

UPDATE 20130206: check out Tres' new tutorial which looks a little easier, where LMMS is build by a team called KXStudio.


INSTALL LMMS 0.4.14-rc1

Uninstall any LMMS version you might have already:
sudo apt-get remove lmms

If you've installed the irie/lmms PPA, then uninstall the PPA as well:
sudo add-apt-repository --remove ppa:irie/lmms

If you don't have python-software-properties installed, then install it (so you can install a PPA):
sudo apt-get install python-software-properties

Add the dns/sound PPA:
sudo add-apt-repository ppa:dns/sound

Update apt:
sudo apt-get update

Install LMMS:
sudo apt-get install lmms

This PPA contains the latest development build.


INSTALL VST SUPPORT

Go here:
https://launchpad.net/~irie/+archive/lmms/+sourcepub/2331855/+listing-archive-extra

Download these files to e.g. ~/Downloads:
lmms-vst-full_0.4.13-0irie3~precise1_i386.deb
lmms_0.4.13-0irie3~precise1_amd64.deb

("~" is shorthand for your home directory, e.g. "/home/nickleus" )

For each file:
Right click > "Extract Here"

Now you'll have the following directories:
~/Downloads/lmms-vst-full_0.4.13-0irie3~precise1_i386
~/Downloads/lmms_0.4.13-0irie3~precise1_amd64


Set root ownership to the relevant VST files and copy them to /usr/lib64/lmms/:
cd ~/Downloads/lmms-vst-full_0.4.13-0irie3~precise1_i386/usr/lib/lmms
sudo chown root:root RemoteVstPlugin.exe.so
sudo chown root:root RemoteVstPlugin
sudo cp RemoteVstPlugin* /usr/lib64/lmms/


cd ~/Downloads/lmms_0.4.13-0irie3~precise1_amd64/usr/lib/lmms
sudo chown root:root libvestige.so
sudo chown root:root libvstbase.so
sudo chown root:root libvsteffect.so
sudo cp libvestige.so /usr/lib64/lmms/
sudo cp libvst* /usr/lib64/lmms/



CONFIGURE WINE

To use the VST support with Wine, you have to assign /usr/lib64/lmms to some drive letter using Wine configuration (winecfg)

Run this in a terminal:
winecfg

A Microsoft window will popup.
Choose the Drives tab
Click the Add button
(It suggested drive D: for me)
Choose an available drive, e.g. D:
Click the OK button

In the Path field enter the following text:
/usr/lib64/lmms

Click the main window's OK button

UPDATE 20130205: I wasn't sure if this "CONFIGURE WINE" part was needed or not (it was with the irie/lmms PPA), so I removed the D: drive in winecfg and LMMS still worked with VST, so it might not be necessary.

--------

Start LMMS with VST support! :)


***Special thanks to IRIE Shinsuke/Patrick Winnertz for all their work***

Tuesday, 29 January 2013

My suggestions for LMMS features/improvements

I've been using LMMS (v0.4.13) on Ubuntu (v12.04 64-bit) for a while so I thought I'd keep track of features and bugfixes I'd like to see in future releases. Here's LMMS' Roadmap page (I'm too lazy to sign up and edit it). Here's the LMMS Bug Tracker.

Note: This list will be ongoing--I'll add to it as I use LMMS more and more.


Song-Editor

* [FEATURE 1] Select a track and be able to shift all notes up or down X number of octaves

* [FEATURE 2] Delete multiple bars/segments in one action

* [FEATURE 3] Copy multiple bars/segments in one action

* [FEATURE 4] Right click on a bar in Song Editor and export to wav (or FLAC)

* [FEATURE 5] Export every bar in a Song Editor track to wav (or FLAC)

* [FEATURE 6] Double click on a bar in Song Editor opens Piano Roll, but it would help if that bar was somehow highlighted so I can remember which bar I edited after I'm done in Piano Roll (especially when I have lots of bars--it's easy to lose track of where I was)

* [FEATURE 7] "mouseover" on a bar containing a name and the name shows immediately in a yellow or white tooltiptext. Give users a configuration option to enable/disable the feature


Piano Roll

* [BUG 1] When I double click a bar, then move my cursor down to the piano roll, sometimes it's in Select Mode (the cursor is also a Select Mode cursor) even though Draw Mode is shown as selected in the piano roll menu. UPDATE 20130130: a workaround for this is to do shift+s then shift+d so you don't have to go up to the menu to click the Draw Mode button. This bug may be related to this bug or this bug.

* [BUG 2 (?)] Export to wav adds silence at the end of the export file. I want the export file to cut off precisely at the end of the last bar. Seems to be identical to this bug. (UPDATE 20130131: This seems to have been fixed in the stable branch!:
"Yes, the idea was to not cut reverbs, delays etc. There has been a commit
in master branch already which adds an option for exporting the project as
loop. I just backported this commit to the stable branch
(59732b05ed9641a85bfeba19531f78d7967dcee8). Have a lot of fun with it!"

)

* [FEATURE 1] Have a dedicated key to pause playback at the current position. Currently, spacebar (play/pause) sets the position to 0 (back to start). (UPDATE 20130326)


Compiling development version of LMMS on Ubuntu 12.04 64-bit

* [BUG 1] I've installed all the dependencies, but when I run make I get the following error:
/usr/bin/ld: Relocatable linking with relocations from format elf64-x86-64 (/usr/lib/x86_64-linux-gnu/wine/libwinecrt0.a(exe_entry.o)) to format elf32-i386 (RemoteVstPlugin.QR4Yyn.o) is not supported
winebuild: /usr/bin/ld failed with status 1
winegcc: winebuild failed
make[2]: *** [plugins/vst_base/RemoteVstPlugin] Error 2
make[1]: *** [plugins/vst_base/CMakeFiles/vstbase.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
Linking CXX shared module libtripleoscillator.so
[ 34%] Built target tripleoscillator
make: *** [all] Error 2


to get past that error i removed "-m32" in the following files:
plugins/vst_base/CMakeFiles/vstbase.dir/build.make
build/plugins/vst_base/CMakeFiles/vstbase.dir/build.make

then i ran make again and got the following error:
In file included from /usr/include/slv2/world.h:26:0,
                 from /home/me/Downloads/lmms/include/lv2_manager.h:33,
                 from /home/me/Downloads/lmms/src/core/lv2_manager.cpp:35:
/usr/include/librdf.h:31:21: fatal error: raptor2.h: No such file or directory
compilation terminated.
make[2]: *** [CMakeFiles/lmms.dir/src/core/lv2_manager.cpp.o] Error 1
make[1]: *** [CMakeFiles/lmms.dir/all] Error 2
make: *** [all] Error 2


UPDATE 20130205: How to install LMMS 0.4.14-rc1 with VST support on Ubuntu 12.04 (Precise Pangolin)
My content is under the Creative Commons Attribution 3.0 license. I work hard to publish relevant and useful information in order to help people learn difficult things and find solutions to their problems, so please attribute me if you reuse my content elsewhere.