--- mixplayd --- a mp3 mixing player daemon (c) Siegfried Wagner 01/08/27 1. ABOUT mixplayd is a daemon that can be told (over a tcp connection) to play mp3 (and ogg) files from the local file system (where the daemon resists). It can't be controlled directly but with telnet. How this is done and what you can do, see below. It also has a built-in multi-channel mixer, so you can play several mp3 files on different channels with different volumes simultanously. This is very useful for fading over between songs. Another very useful feature is the change of the number of channels and even the number of soundcards and named pipes at run time! Yes, it also supports unix named pipes, so you can run it even without a soundcard! See below for examples. The main purpose of mixplayd is to be used with special frontends which also can be found on the homepage: http://mixplayd.sourceforge.net/ A sample perl-client is included with the package. mixplayd doesn't come with its own decoder, instead it needs a preinstalled working decoder. I strongly recommend madplay from underbit Technologies which can be obtained for free from http://www.underbit.com/products/mad/ If you prefer to use another one (e.g. mpg123) you have to know about its command line arguments, e.g. you need to know how tell the encoder the frame where the decoding should start or you won't be able to seek in the file. You then have to change defaults.h according to the new decoder. NEW: There is now also support for OggVorbis files (www.vorbis.com). The preferred encoder here is ogg123 from vorbis-tools. You also need to have libvorbis installed in order for getting OggVorbis support. You will find both on www.vorbis.com 2. COMPILING AND INSTALLATION please read the instructions in INSTALL 3. QUICK START mixplayd understands a few command line options, but these are all optional. It will start simply by typing ./mixplayd (in the directory where you compiled the code). Without a command line argument the default behaviour is, that mixplayd tries to get all available soundcards from /dev/dsp0 to /dev/dsp7 and then binds to tcp port 8888 on the localhost. Finally it forks itself into background (so don't think it hasn't started properly only because of the shell prompt coming again ;-) When no sound device can be opened an error message appears and mixplayd terminates! But you can use mixplayd even on a machine without a soundcard, when you create a unix named pipe and give the name of that on the command line with -npipes. Further explanations how this is done and can be used see below. IMPORTANT: At the moment there is no authorization mechanism for the connecting client, so the connections were limited to localhost for security reasons! Now that the daemon has started you can test it with a telnet localhost 8888. Now type: play 0 /path/to/my/favorite/song.mp3[RETURN] (of course you have to replace the path with a real path!) Now if your soundcard volume is up and speaker are plugged to your soundcards output you should hear the song playing. You can open more than one connection at a time (but there's a limit). This is useful if another "regular" client is controlling the daemon and you just want adjust anything for the moment by a short telnet connect. Now you would ask: How can I load a playlist? Answer: You can't! The purpose of mixplayd is not to do anything of it's own, including playlist management, crossover fading and so on. It relies on a controlling client which will do that for it. With the package included is a sample perl-client which you found in the subdirectory simple-player. See explanations below. 4. COMMAND LINE ARGUMENTS The most of them are self-explanatory: -h, -help or --help Shows a brief summary of the command line options. -version Prints version number and exits. -port port_no Run the server on the specified port (default 8888). ­snddev device0,device1,... Set sound devices to use (default: use all soundcards available (/dev/dsp??)). -nosound Don't use any sound device at all (only named pipes). -npipes name0,name1,... Write sound to the given named pipes. -logfile file Write a logfile. -v, -verbose Don't fork into background and write informations to stdout. -d, -debug Turn on additional debug information. If you give one or more sound devices with -snddev then only these will be used and no further probing will be done. When using unix named pipes with -npipes and -nosound is not given, then the named pipes were used additional to the soundcard(s). In normal daemon mode it will be interesting using a logfile with -logfile, otherwise you can't see what the daemon is doing. If you want to see all status and activites you probably want to use the not daemonized mode with the -verbose switch. 5. THE CONTROL COMMUNICATION Now the interesting part: What can you do with mixplayd? mixplayd is a multi-channel mixer, that is you can play more then one file at a time, each with a different volume. The main purpose for this is to get a nice fading over between songs. (But in the future it's also interesting for DJing 'cause pitching will be added sometime!) You communicate with the daemon through a tcp connection by sending the commands as listed below followed by a newline (or return in telnet). On every command you send you get a reply if it failed or was successful with the command-name as prefix (in [] brackets), so you know that it's a command reply. With the file defaults.h not changed mixplayd starts up with four mixer channels numbered from 0 to 3. If you want to see what they're doing use the command: stat - show the status informations of all mixer channels every second (or turn displaying off if it was previously on) This looks like: 18:47:35 ch 0 stopped 00:00..00:00 (100) ch 1 stopped 00:00..00:00 (100) 18:47:35 ch 2 stopped 00:00..00:00 (100) ch 3 stopped 00:00..00:00 (100) where "ch" stands for channel followed by the channel number and then a time value (00:00) in minutes and seconds of the play position of the song, then a time value of the song length also in minutes and seconds and finally in brackets the current volume of the channel. When playing a song you may also get a message like: 23:34:01 warning: low level (12) This appears when the sound output level of all mixer channels mixed together is under a defined value (which can be changed in defaults.h) and can be used to detect a fading end of a song or if something is not ok (like volume too low). NEW: There is now also the ability to get the status for once by using the command "getstat". This may be the preferred way for polling the informations regularly by a frontend. The other commands are: play - start playing the new mp3 on mixer-channel load - the same as above except that the song doesn't start playing start - start or resume playing (after pause) from the actual position on pause - stop playing on but stay at position stop - stop playing on and go back to the beginning of song rew [] - seek rewind on for seconds or the default (see defaults.h) fwd [] - the same as above in the opposite direction seek - jump to position on , where is in seconds info - print some information about the file and the settings on vol - change the volume on to (0 is muted and 100 default) fadeout - fade out the playing song on and pause NEW added commands: autocue - if threshold > 0 turn on automatic cueing (silence detection at beginning) is the number of times the signal level has to reach until it is considered to be not silence note: some good values are threshold = 1000 and count = 4 pitch - change pitch to on note: 1.0 is normal speed and a range from 0.92 to 1.08 is usual. addsong - add new song to playlist on note: these channel-playlists are handled internally, so the result will look like one big song! This is especially useful if you have a continuous mix cd which is divided into the tracks and other similar situations. attention: before you can add a song you first have to load one with the load command! note: with a new load or play command the existing playlist on that channel will be destroyed. And now some special commands: live - connect to a live mp3 source and play that is the complete URL including http:// and a trailing / is the rate of the sound of the live source in Hz (eg. 44100) is 1 for a mono live source and 2 for stereo addchan - add a new mixer channel at run time! note: there is a limit of channels defined in defaults.h remchan - remove the last mixer channel setsound - set or remove output on to sound device with is the (internal) number of the sound device (from 0) note: to get a list of which number corresponds to which device use command listsound is the switch to turn it on (=1) or off (=0) default is: all channels play on every sound device listsound - list all connected sound devices (including named pipes) and their number addsound - add a new sound device is either 'dev' for a real soundcard or 'pipe' for a named pipe is the device of the soundcard or the name of the named pipe note: there is a limit of sound devices defined in defaults.h remsound - remove the sound device with and finally: close - close current connection to server shutdown - quit server 6. THE EXAMPLE simple-player.pl Enter the directory simple-player. You must have write access to it or copy the whole directory to a place where you have. Then create a file called "mp3list" with all your mp3 files listed (e.g. by using find /path/to/mp3/files/ -name \*.mp3 >mp3list). This will be the pool from which a new shuffled playlist (called "playlist") will be generated and which will be played through. If you want to change the names or want to give a base path so that the files listed in mp3list can be with a relative path just edit the configuration section of simple-player.pl When starting simple-player.pl it connects to the daemon which must be running first (on port 8888 or otherwise give the port as argument), then looks if there's a file "stat" and an existing "playlist" and if not it generates them. In the "stat"-file the current position of the playlist is stored. So that the simple-player.pl can be stopped and started again and no one would ever notice ;-) The "stat"-file is also useful if you want to modify the "playlist" by another script like a web-cgi where you can drop a wishlist!? It's all up to your imagination. This is an example! Feel free to experiment and develop a nice client by your own! 7. OTHER FRONTENDS (=clients) At the moment a few friends of mine were working on a simple qt-frontend and on a web-frontend for playlist (and wishlist!) maintenance. If you want to make your own, do it! I would be very pleased if you tell me about, so that I can list it on the projects homepage. 8. A FEW ADDITIONAL NOTES What's all that about named pipes? unix named pipes are a nice way to exchange a flow of data between different programs on one machine. You can create a named pipe with mkfifo, so for example let's make a /tmp/soundpipe: Type in a shell mkfifo /tmp/soundpipe. Now start mixplayd with -npipes /tmp/soundpipe -nosound, and you will see it won't go. You have to open the named pipe first, so do something like cat /tmp/soundpipe >recorded_mix.raw & and then start mixplayd with the above arguments again. (But after it is opened once you can close and reopen it again as you want.) I hope you understand that there's a lot more you can do with this, like running mixplayd on a machine without a soundcard and redirecting the sound to another machine with soundcard: cat /tmp/soundpipe | ssh soundrechner 'cat -|aplay -m' (if you use alsa) For my special use I need this feature for streaming the sound to a shoutcast server with a self-written upstream.pl and the use of libshout and Shout.pm. More information about that can be found on the projects homepage (not yet but soon!). A last note: It seems that the time measure isn't very good, so that the songs often stop before the calculated duration time is reached (mostly it is 2 seconds before), and when you seek around the time calculation get even more worse. But I think it's not that worse than to worry about? If you have any ideas how to fix that, please mail me (see below). 9. LEGAL STUFF mixplayd is copyrighted by Siegfried Wagner This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 10. CONTACTS AND WEBPAGE The main webpage for mixplayd is http://mixplayd.sourceforge.net/ Please send any suggestions, bugfixes, or anything else to red_eagle@users.sourceforge.net