Linux Commandline Player

Status
Not open for further replies.

width=100%|size=5|color=blue|color1=blue|color2=red

[h=Introduction]%1[/h]

With this guide I'd like to show you, how to setup a no frills mini command line player for Linux, with the main focus on sound-quality. It's gonna be very basic for now.

With this setup you'll experience a better sound quality compared to all other Linux applications and the majority of known applications on other known operating systems. ( I can tell you - that there is even more to gain - later!)

This little project is meant to introduce you to the sound quality potential of Linux Audio.
(I've written my own more comprehensive player that covers what you'd expect from a normal player - We'll come to that later on.)

The player will make use of the IMO best sound-engine available under Linux called ecasound, a Linux realtime kernel and certain tweaks which will be a prerequisite for a great sounding system.

You don't have to be afraid to use the command line. I'll guide you through that journey.

You'll manage to have it singing in 30 minutes maximum - if below prerequisites are met.



[h=Prerequisites]%1[/h]

1. Linux knowledge: Very basic commandline knowledge - ls, cd, cp, ps, pwd ( You'll even learn it, if you follow the guide)
2. Installed Linux - Ubuntu Karmic or Linux Mint Helena
3. Access to your sound files , which should be .wav and 44.1/16 for now
4. A soundcard or DAC working under Linux
5. A quality audio system

THIS IS A MUST:

6. Backup of your system and music library


[h=Setup]%1[/h]

Note1: You can copy (mark and ctrl-c) and paste below command lines into a terminal by pressing the left and right mouse button at the same time.

1. Open a terminal. (Right-click on the desktop - "Open in Terminal")
2. We need to install some packages now -- run following command:

Code:
sudo apt-get install linux-rt schedtool ecasound vbetool

3. Now we'll allow all users to apply realtime priority to selected processes.

Code:
sudo su
echo "* - rtprio 99" >> /etc/security/limits.conf 
echo "* - nice -10" >> /etc/security/limits.conf 
echo "* - memlock 4000000" >> /etc/security/limits.conf
exit

4. Now we setup the initial alias with the actual command string to be able to start the player.
At the end of the ~/.bashrc file ( the .bashrc initializes your terminal shell (bash) environment any time you start a terminal)
we add below alias by editing that file:


Code:
gedit ~/.bashrc

alias eca440h='if [ "$( ls *wav )" != "" ] ; then clear ; rm /dev/shm/*wav &>/dev/null ; cp *wav /dev/shm ; ls /dev/shm/*wav | while read "i" ; do echo -n "Playing: $i" ; schedtool -F -p 80 -a 0x3 -e ecasound -q -B:rt -b:128 -r:90 -f:s16_le,2,44100,i -i:"$i" -o:alsahw,0,0 -f:s16_le,2,44100 ; echo ; done ; fi'

save&exit

5. Now you just need to reboot the system into the rt-kernel and you're set.

DONE! It just took 10 minutes - didn't it ? 😉

Explanation - What will above alias be doing?

It'll copy all .wav-files it finds to RAM from within the directory where it got started. A minimum of 2GB RAM would be required for this particular alias to work on a standard up to 800MB redbook CD.
Files with a format of 44.1/16 will then be played back by ecasound at a realtime priority of 90 ( -r 90) on the 2nd physical processor ( -a 0x2 or -a 0x3 - would set the affinity correctly - you need to look up what value to choose for your processor - cat /proc/cpuinfo ).
The chosen Alsa interface is hw - the direct path to the sound device.

In below Example section you'll find several other solutions covering - flac, other samplerates, volume control, other interfaces and e.g. how to use this on a RME 9632 without the need for using the HDSPconf settings for different samplerates)

[h=Operation]%1[/h]

IMPORTANT NOTE:

The initial alias/command example won't have volume control enabled. It runs your data out at 0db. In case you have a direct DAC - Amp connection, you'll blow your speakers.
Avoid this example in any case, if you don't have a separate volume control in place.
Any Linux mixer or volume control will be out of loop when running this alias. Any Linux mixer or control setting won't have any impact.
I'd recommend to try example 6 below instead. it allows to set the attenuation at start. Though the result will be slightly worse then the default alias without any attenuation.

AGAIN: In general I won't take any responsibility, if you blow up your speakers or anything else in your system by following my recommendations or examples.

Let's give it a try:

6. Open a terminal again

7. Select your album and start playback

You just cd into your album directory and enter the alias

Code:
cd <musicbasedir>
ls | more   # the will list all albums ( subdirectories)  in the directory
cd <albumdir> # the directory where your .wav files are stored, that'll depend on your directory structure of course
eca440h

8. Next Song

Press
Code:
CTRL-C

9. Stop

Press quickly
Code:
CTRL-C CTRL-C

Note:
If you experience odd behavior, such as skipping, Xruns, etc. during playback you might have to change the buffer value of ecasound : Change the -b option (default=128) of ecasound to another power of 2 value: e.g. 64 or 256

[h= More examples]%1[/h]

You can "add" below aliases to your .bashrc. See 4. Please note the changed alias-ids. You're free to choose whatever id as long as it not a Linux command.

Note2: You can look up all command line options of the used programs by typing e.g. "man ecasound" or "man schedtool".

1. Output to Alsa output plughw in case hw is not working.
This might happen if the soundcard driver is not properly written.

alias eca440h='if [ "$( ls *wav )" != "" ] ; then clear ; rm /dev/shm/*wav &>/dev/null ; cp *wav /dev/shm ; ls /dev/shm/*wav | while read "i" ; do echo -n "Playing: $i" ; schedtool -F -p 80 -a 0x2 -e ecasound -q -B:rt -b:128 -r:90 -f:s16_le,2,44100,i -i:"$i" -o:alsaplugin,0,0 -f:s16_le,2,44100 ; echo ; done ; fi'

2. Output to your 2nd soundcard, which would be Alsa card 1.
You can look up your card id by typing "aplay -l" in a terminal.

alias eca441h='if [ "$( ls *wav )" != "" ] ; then clear ; rm /dev/shm/*wav &>/dev/null ; cp *wav /dev/shm ; ls /dev/shm/*wav | while read "i" ; do echo -n "Playing: $i" ; schedtool -F -p 80 -a 0x3 -e ecasound -q -B:rt -b:128 -r:90 -f:s16_le,2,44100,i -i:"$i" -o:alsahw,1,0 -f:s16_le,2,44100 ; echo ; done ; fi'

3. Applying a different sample rate. e.g 24/96. No files get copied one by one to RAM.

alias eca960h='if [ "$( ls *wav )" != "" ] ; then clear ; rm /dev/shm/*wav &>/dev/null ; ls *wav | while read "i" ; cp "$i" /dev/shm ; do echo -n "Playing: $i" ; schedtool -F -p 80 -a 0x3 -e ecasound -q -B:rt -b:128 -r:90 -f:s24_le,2,96000,i -i:/dev/shm/"$i" -o:alsahw,0,0 -f:s24_le,2,96000 ; rm /dev/shm/*wav; echo ; done ; fi'


4. Running flacs. Ecasound supports flac playback Though it would be better to decode them beforehand and not on the fly.

alias eca440hf='if [ "$( ls *flac )" != "" ] ; then clear ; rm /dev/shm/*flac &>/dev/null ; cp *flac /dev/shm ; ls /dev/shm/*flac | while read "i" ; do echo -n "Playing: $i" ; schedtool -F -p 90 -a 0x3 -e ecasound -q -B:rt -b:128 -r:80 -f:s16_le,2,44100,i -i:"$i" -o:alsahw,0,0 -f:s16_le,2,44100 ; echo ; done ; fi'

5. If you run low memory or you work with Hirez Files you can copy the files one after one to RAM. This will of course introduce very small gaps during playback.

alias eca440h='if [ "$( ls *wav )" != "" ] ; then clear ; rm /dev/shm/*wav &>/dev/null ; ls *wav | while read "i" ; cp "$i" /dev/shm ; do echo -n "Playing: $i" ; schedtool -F -p 80 -a 0x3 -e ecasound -q -B:rt -b:64 -r:90 -f:s16_le,2,44100,i -i:/dev/shm/"$i" -o:alsahw,0,0 -f:s16_le,2,44100 ; rm /dev/shm/*wav; echo ; done ; fi'


6. This alias applies 50% ( 6db) attenuation - see option -ea:50%. On the fly attenuation sounds worse then offline attenuation.

alias eca440h='if [ "$( ls *wav )" != "" ] ; then clear ; rm /dev/shm/*wav &>/dev/null ; ls *wav | while read "i" ; do cp "$i" /dev/shm ; echo -n "Playing: $i" ; schedtool -F -p 90 -a 0x3 -e ecasound -q -B:rt -b:128 -r:80 -f:s16_le,2,44100,i -i:/dev/shm/"$i" -o:alsahw,0,0 -f:s16_le,2,44100 -ea:50%; echo ; rm /dev/shm/*wav ; done ; fi'


7. RME HDSP 9632: Switching automatically samplerates on HDSPmixer
Attributes on amixer command: 2=44 || auto,32,44,48,64,88,96,128,176,192

alias eca440h='if [ "$( ls *wav )" != "" ] ; then clear ; amixer -q -c 0 cset numid=11 2 ; rm /dev/shm/*wav &>/dev/null ; cp *wav /dev/shm ; cd /dev/shm ; ls *wav | sort | while read "i" ; do echo -n "Playing: $i" ; schedtool -F -p 80 -a 0x3 -e ecasound -q -B:rt -b:64 -r:90 -f:s16_le,2,44100,i -i:"$i" -o:alsahw,0,0 -f:s16_le,2,44100 ; echo ; done ; fi'

alias eca960h='if [ "$( ls *wav )" != "" ] ; then clear ; amixer -q -c 0 cset numid=11 6 ; rm /dev/shm/*wav &>/dev/null ; ls *wav | while read "i" ; do cp "$i" /dev/shm ; echo -n "Playing: $i" ; schedtool -F -p 80 -a 0x3 -e ecasound -q -B:rt -b:64 -r:90 -f:s24_le,2,96000,i -i:/dev/shm/"$i" -o:alsahw,0,0 -f:s24_le,2,96000 ; rm /dev/shm/*wav; echo ; done ; fi'

8. Ultimate: Flying blind and enjoy! Run this one as root in recovery mode. It turns your screen completely off.
Introduce all below aliases to your .bashrc in below order. Make sure that your normal user .bashrc is copied to /root
This one should deliver the best sound of all. Don't forget to disconnect your ethernet cable.

alias vbon='vbetool dpms on'
alias vbon='vbetool dpms off'

alias eca440hv='if [ "$( ls *wav )" != "" ] ; then clear ; vboff ; rm /dev/shm/*wav &>/dev/null ; ls *wav | while read "i" ; do cp "$i" /dev/shm ; do echo -n "Playing: $i" ; schedtool -F -p 80 -a 0x3 -e ecasound -q -B:rt -b:64 -r:90 -f:s16_le,2,44100,i -i:/dev/shm/"$i" -o:alsahw,0,0 -f:s16_le,2,44100 ; rm /dev/shm/*wav; echo ; done ; fi ; vbon '




[h=Tips And Tricks]%1[/h]

1. Running without X-Windows

What to expect: You'll notice immediately less grain, better low-end, less flutter echos and more.

Prerequiste: You need to setup a root password first while you're logged in to Gnome as normal user! And you need to copy your edited .bashrc to /root
Don't forget to cp your .bashrc any time you update it to /root.
1. Open a terminal and enter

Code:
sudo su
passwd
cp /home/<your-userid>/.bashrc /root

Boot your system into recovery rt-kernel mode and login as root without network. You'll look at a big terminal now.

Follow "Operation" instructions as described above.


2. Prepare yourself a "cd" alias to switch to your musicbasedir quickly.
That'll make life much easier.

Example:

alias cdm="cd /media/media/music"

Replace path with your own path to your music basedir. By typing the command "pwd", Linux will show you the full path name you're currently in.

In a terminal it is sufficient now to type cdm to get to your musicbasedir.


[h=References]%1[/h]

Ecasound homepage
The "Linux Audio the Way To Go" thread

[h=Changelog]%1[/h]

19-03-2011:soundcheck:Initial writeup
21-03-2011:soundcheck:Introduction of ultimate playback solution - with screen off in recovery mode
 
Last edited:
OK, then here:

My prob is, if I run eca440h, I get

/dev/shm/<myfile.wav>ERROR: could not set PID 5385 to F: SCHED_FIFO - Operation not permitted

The respective lines in /etc/security/limits.conf are:

@audio - rtprio99
@audio - nice -10
@audio - memlock unlimited

and <currentuser> is member of the group 'audio'

Rüdiger
 
I found a small glitch:
When a soundfile contains an ',' eca440h can't read it properly.
For instance:

Code:
Playing: /dev/shm/Tim Berne - Out, the Regular.wav---
ecasound: ERROR: [ECA-SESSION] : "Audio object '/dev/shm/Tim Berne - Out' does not match any of the known audio device types or file formats.

Rüdiger
 
Status
Not open for further replies.