Back to documentation

2000 December 1

YIFF Sound Server
Configuration HOWTO

Contents

  1. Basics about sound on computers
  2. Y Sound System terminology
  3. Requirements
  4. Setting up yiffrc
  5. `Walk-though' using the Y Sound Server
  6. Y server run on demand rules

Basics about sound on computers

Knowing the fundimentals on how your computer produces sound is the most important topic of configuring the YIFF Sound Server, newbies and advanced gurus should take a moment to review this section throughly!

Your computer produces (and records) sound using an audio adapter, more commonly reffered to as a sound card. The Y Sound System reffers to this as the recorder (details in the next section). We will reffer to it as the sound card for now...

The sound card has the following configurable attributes (some sound cards may have additional attributes and features):

It is critical that you know how to calculate the above information when configuring the YIFF Sound Server (and using Y client applications too).

YIFF and the Y system handles data in bytes, for instance if you set the sample rate to 11025 Hz and the sample size was set to 8 bits with 1 channel then you would have 11025 * 1 * 1 = 11025 bytes per second. Since there are 8 bits in one byte, but what if the sample size was 16 bits? Then that would be two bytes per sample. So now you would have 11025 * 2 * 1 = 22050 bytes per second.

In the above two examples the number of channels remained at a constant 1. What if you had a sample rate of 11025 Hz and sample size was set to 8 bits but channels is set to 2? Although each sample is represented by one byte, you have two channels therefore it is one sample per channel. So with two channels you would have a total of 11025 * 1 * 2 = 22050 bytes per second even though the sample size is set to 8 bits (one byte).

Lastly if the sample rate was 22050 Hz and the sample size was set to 16 bits (2 bytes) and channels set to 2. Then you would have 22050 * 2 * 2 = 88200 bytes.

Now we add one more attribute in to the equation and that is buffer fragment size. The sound card driver does not handle updates in seconds, rather it updates things in cycles. A cycle can have a variable relationship with real time, it is determined by the other attributes sample rate, sample size, channels, and buffer fragment size.

Software under most circumstances calculates the cycle, however YIFF allows you to either let it calculate it or allow you to set an explicit value for a set of conditions. The cycle is usually measured in microseconds (abbriviated us), and is calculated with the following equation:

That equation calculates the cycle for a typical double buffer (two buffer fragments) situation. Assuming sample_rate and channels are greater than 0 and sample_size_bits is greater than or equal to 8. buffer_fragment_size is a 2^n value (ie 256, 512, 1024, etc...). Note that this equation conforms to the Open Sound System (OSS) implmentation.

If the cycle interval is too big then you will here rapit `clicks' or `gaps' in the sound, if it is set too small then the buffers will slowly overflow. Note that YIFF will try its best to keep the buffer from overflowing by resyncing the sound driver every few seconds (you can adjust this interval too). So it's generally safer to make the cycle interval value a tad smaller at a cost to performance. However in most situations the calculated theoretical cycle interval will work just fine.

Back to the top.

Y Sound System terminology

The Y Sound System employs a few additional terms to generalize additional conceptual properties about using your sound card. These conceptual properties will help make it easier to work with sound using the Y system at a higher level.

Back to the top.

Requirements

  1. A system with any of the following drivers installed:
  2. Latest YIFF Sound Server installed (but not configured)

Back to the top.

Setting up yiffrc

The yiffrc is a configuration file which the YIFF Sound Server needs in order to run properly, this file is usually placed in /etc/yiff/yiffrc.

A default copy is placed in /etc/yiff/yiffrc when you first install the YIFF Sound Server.

To configure yiffrc manually, run your prefered text editor and read through the entire configuration file first. Each section and parameter should come fully commented (a comment is a line starting with a # character). Read each comment carefully and set the appropriate value. Some more important or obscure parameters will be described as follows

Preset Y Audio Modes

Preset Y Audio Modes are located in a section of configuration blocks starting with BeginYAudioMode and ending with EndYAudioMode. Reffer to the basic properties of sound cards to set the appropriate values, note that you should only change these values if they do not work out at first (ie if you experience delays or 'clicks' during playing of sound). Preset Y Audio Modes make it easier for Y clients to change the Audio parameters by using preset ones which it would consider as `known working Audio parameters'.

Below is a sample section for Y Audio Modes:


BeginYAudioMode
    Name = Default
    Cycle = 30959
    WriteAhead = 46438
    SampleSize = 8
    Channels = 1
    SampleRate = 11025
    AllowFragmenting = yes
    Fragments = 2
    FragmentSize = 512
    FlipStereo = no
    Direction = Play
EndYAudioMode

BeginYAudioMode
    Name = PlayMono8000
    Cycle = 42666
    WriteAhead = 63999
    SampleSize = 8
    Channels = 1
    SampleRate = 8000
    AllowFragmenting = yes
    Fragments = 2
    FragmentSize = 512
    FlipStereo = no
    Direction = Play
EndYAudioMode

BeginYAudioMode   
    Name = PlayStereo8000
    Cycle = 42666
    WriteAhead = 63999
    SampleSize = 8
    Channels = 2
    SampleRate = 8000
    AllowFragmenting = yes
    Fragments = 2
    FragmentSize = 1024
    FlipStereo = no
    Direction = Play
EndYAudioMode

BeginYAudioMode   
    Name = PlayMono11025
    Cycle = 30959
    WriteAhead = 46438
    SampleSize = 8
    Channels = 1
    SampleRate = 11025
    AllowFragmenting = yes
    Fragments = 2
    FragmentSize = 512
    FlipStereo = no
    Direction = Play
EndYAudioMode

BeginYAudioMode   
    Name = PlayStereo11025
    Cycle = 30959
    WriteAhead = 46438
    SampleSize = 8
    Channels = 2
    SampleRate = 11025
    AllowFragmenting = yes
    Fragments = 2
    FragmentSize = 1024
    FlipStereo = no
    Direction = Play
EndYAudioMode

BeginYAudioMode   
    Name = PlayMono22050
    Cycle = 30959
    WriteAhead = 46438
    SampleSize = 8
    Channels = 1
    SampleRate = 22050
    AllowFragmenting = yes
    Fragments = 2
    FragmentSize = 1024
    FlipStereo = no
    Direction = Play
EndYAudioMode

BeginYAudioMode   
    Name = PlayStereo22050
    Cycle = 30959
    WriteAhead = 46438
    SampleSize = 8
    Channels = 2
    SampleRate = 22050
    AllowFragmenting = yes
    Fragments = 2
    FragmentSize = 2048
    FlipStereo = no
    Direction = Play
EndYAudioMode

That was just a sample of a few basic Y Audio Modes, note that the names of the Y Audio Modes are important. You should have all the standardized modes defined, reffer to the default yiffrc that was installed with the rest of the YIFF Sound System for a complete listing.

Note that AllowFragmenting should always be yes (it's backwards compatability for older versions of Linux). The number of fragments Fragments should be 2 (for double buffering).

MIDI Player Command

MIDI support requires an external player, there is a parameter called MIDIPlayCommand it specifies the command to have YIFF run when a Y client program requests that a MIDI type sound object needs to be played.

Example command if your player was pmidi:


MIDIPlayCommand = /usr/bin/pmidi -p 65:0 %f

Note that the %f will be replaced with the full path to the sound object.

Another related parameter is MIDIDevicePort, this value is the ALSA MIDI device port number. This value is only used if you are using ALSA, typically you can leave this value as 0.

Y Sound Paths

You can define one or more search paths called Y Sound Paths which are directories to look for Sound object files (.wav or .mid files for example). When a Y client gives a relative path to the YIFF server, the YIFF server will search through each one of these paths for the sound object looking for a match. The Y Sound Paths configuration block begins with a BeginYSoundPath and ends with a EndYSoundPath. The search goes through the listing from first Y Sound Path defined to the last one.

For example


BeginYSoundPath
    Path = /usr/share/sounds
EndYSoundPath

BeginYSoundPath
    Path = /tmp
EndYSoundPath

This covers most of the problem areas that might cause confusion during configuring.

If you are still having trouble configuring or have additional questions about configuration, feel free to ask the authors.

To test if everything is working, make sure your sound drivers are loaded and run:

Be sure to read the next section which shows you how to run the YIFF Sound Server and modify it with the Y utility programs at run time. ...Plus many other features!

Back to the top.

`Walk-though' using the Y Sound Server

Now hopefully you have atleast one working preset Y Audio Mode and are ready to hear it work.

Starting the YIFF Sound Server

You can start the YIFF Sound Server as the user with the lowest permissions, YIFF only needs access to the devices and locations specified in the yiffrc configuration file.

To start the YIFF Sound Server, just type (modify paths as needed):

The above command should have started the YIFF Sound Server and print any warnings or errors encountered. Some typical errors you might encounter are:

Note that the YIFF Sound Server will automatically run in the background, if however you want to run YIFF in the foreground then add --foreground to the command, for example:

To get a list of command line arguments for YIFF, type: You can type the above regardless if YIFF running or not.

To formally start YIFF you should run:

This is a script file that calls YIFF and sets up additional resources (such as yhosts).

Is the YIFF Sound Server running?

There are two ways to check that:

  1. ps aux|grep yiff
  2. yrecinfo
The first command will basically check the complete list of processes and show you the line (if any) for the pid of the YIFF Sound Server. The second line is a more Y specific way of checking, yrecinfo will print the status of the YIFF Sound Server if it was able to connect to it or an error message if it was not able to connect. A typical successful output from yrecinfo would look like:


recorder: 127.0.0.1:9433
version: 2.11
cycle load: 3.4%
maximum protocol statement: 30000 bytes
cycle set: 2
cycle: 30959 microseconds
compensated cycle: 30959 microseconds
write ahead: 46438 microseconds
cumulative latency: 0 microseconds
sample rate: 11025 Hz
channels: 1
sample size: 8 bits
bytes per second: 11025 bytes
allow sound buffer fragments: yes
sound buffer fragments: 2
sound buffer size: 512 bytes
flip stereo: no
direction: 0

By default yrecinfo connects to port 9433 on the computer it is running on, to specify an particular address and port, type:

The above is the same as running yrecinfo without any arguments but as you can see, you can get a different address by simply changing 127.0.0.1 to a different address. For a different port just change 9433 to the port number you want. You should note that all Y compliant applications will handle the --recorder <address>:<port> argument. As always to get a full list of arguments available, run with the argument --help, for example:

Playing something

If everything looks good so far, then its time to check if the YIFF Sound Server can play something. Select a reasonably lengthed (1 MB or so) wav, voc, or raw sound file and type:

Replace /home/me/mysound.wav with the full path to the sound file in question. Remember that if you pass a relative path, the file will be searched through the Y Sound Paths list and if it is not found yplay will return stating an error (the current working directory is not checked). The -v and -m arguments specify verbose and automatically change Audio values as needed (respectivly). Typically the -m argument is discuraged because changing the Audio mode as needed will cause any other Y client application's sound objects to be killed. You can press ctrl+c at any time during yplay's playback to stop it.

Next try and see if you can play a MIDI sound object, it's the same procedure with yplay except that you tell it to play a midi file, for example:

This might produce an error if your MIDI player program is not set up properly. Run yiffconfig or edit /etc/yiff/yiffrc to change the MIDIPlayCommand parameter as needed.

Changing the Y Audio Mode manually

You can easilly switch preset Y Audio Modes or set specific Audio modes using yset. This is a very powerful command, as it allows you to manipulate many aspects of the YIFF Sound Server at run time. For example, to switch preset Y Audio Modes first type:

This will print the YIFF Sound server status and a list of available Y Audio Modes. Make note of a particular Y Audio Mode name you like to switch to and type: Replace PlayStereo11025 with the Y Audio Mode you want to switch to (make sure it appeared in the yrecinfo list). You may hear a 'click' as the Audio values are updated.

There are many options to yset, again to get a list of arguments type:

Shell out

One additional feature that should be pointed out at this time is that the YIFF Sound Server can shell out, what this means is that the YIFF Sound Server will continue to; run normally, handle Y client connections, and play sound... or so it seems. What its really doing is everything except play sound. It will still communicate with the Y client programs connected to it and 'lie' to them when they request to play a sound (it will pretend its playing the sound but not actually play it). This is similar in principal as a GUI switching to full screen mode to allow a non-GUI program to run (old MS-Windows users should know what we mean here). So basically YIFF will stop using the digital sound processor device specified by the configuration parameter DSPDevice so other non-Y applications can use it. So to shell out type:

You should get a message indicating the Y server has been shelled out, now type: Do not specify the -m argument above (you'll see why in a moment). When you press enter you will see that it appears the sound is playing normally but you will hear nothing comming from the speakers. Now press ctrl+c and type: Any preset Y Audio Mode or Audio values will do, this will unshell and bring YIFF back to running normally (make sure no other non-Y applications are ysing the digital sound processor device when you type this). To conferm that sound is back, type: Note that if you had specified -m to yplay, it would have changed the Audio and thus unshell.

Mixers

One thing that yset cannot manipulate are the Y mixers. This is where a new command called ymixer is used, note that not all sound cards have mixers and if even so not all mixer channels exist (maybe not even vol, so double check your sound card manual first before continuing on in this section).

First to get a list of all Y mixers, just type:

You should get a list of mixer channel names and their respective values in percent.

To set a specific Y mixer value type:

This will set the mixer vol to left channel 70 percent and right channel 40 percent. To verify type: You may notice a slight different in output value as the YIFF server adjusts to the internal values.

Note that the mixer device is specified in the yiffrc configuration file by the parameter MixerDevice. You can set this parameter's value to nothing to indicate you have no mixer.

Your Y mixer settings are stored in a file called /var/state/yiff/mixer this file is automatically loaded when you run the YIFF Sound Server and rewritten when you shut down the YIFF Sound Server.

Allowing foreign Y clients

Since Y Sound Systems is a network transparent system, it allows Y clients from other computers to connect to the Y server, but not unless you say so.

To allow a Y client on another computer to connect to a YIFF Sound Server currently running on your computer type (on your comptuer):

This will add the host wolfpack.twu.net IP address to the list of foreign yhosts (ip addresses) allowed to connect to the YIFF Sound Server on your computer. Note that its better to specify an IP address as it is more precise in security, for example: To remove an address type: Note the - character which specifies to remove the address from the allowed list of addresses.

Remember that changes you make using yhost are not permanent, they will be gone once you shut down your YIFF Sound Server. So to preserve changes you should add the yhost to your /etc/init.d/yiff script.

Beware, allowing programs from other computers to control YIFF will allow them to do bad things, such as shutting down YIFF or having it play a million sound objects at once. Only specify yhost addresses of computers you trust!

Shutting down the YIFF Sound Server

To shut down the YIFF Sound Server type:

This will have YIFF stop all sound objects being played, destroy all sound objects, close connections to any Y client applications currently connected and then shut down.

Back to the top.

Y server run on demand rules

These are the rules for the conditions in when the YIFF Sound Server is started and shutdown (automatically) by Y client programs:

  1. If a program wants to connect to the YIFF server, first that program attempts a connect, if it is unable to connect then it attempts to start the YIFF server (and makes note that it started YIFF) and attempts to connect again.
  2. If a program is currently connected to YIFF and wants to disconnect, first it recalls if it started YIFF, if it did, it will shutdown YIFF, otherwise it will just disconnect from YIFF.
Remember, you can always shut down the Y server at any time using yshutdown.

You can also send a kill -s INT <pid> to the YIFF Sound Server, it will recieve that signal and shutdown normally.

YIFF also responds to the HUP signal, type kill -s HUP <pid> YIFF reload its configuration and reset its resources. Warning, this may disconnect any Y client programs currently connected.

Where to go from here?

Once you have everything set up you may want to take a look at the links to other neat and wonderful Y applications.

Back to the top.