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:
cycle_us = 1,000,000 / (sample_rate * channels *
(sample_size_bits / 8)) * buffer_fragment_size / 1.5
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.
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.
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 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 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
.
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:
/usr/sbin/yiff /etc/yiff/yiffrc
Now hopefully you have atleast one working preset Y Audio Mode and are ready to hear it work.
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):
/usr/sbin/yiff /etc/yiff/yiffrc
/etc/yiff/yiffrc: No such file.
This means that the
path to the configuration file is incorrect. Please specify the correct
path to the configuration file and make sure that
/usr/sbin/yiff
has permission to check for its existance and
open it.
/usr/sbin/yiff
listens to for incoming Y client connections
(default number is 9433) is already in user by another server or is not
allowed to be binded with the current permissions on
/usr/sbin/yiff
. You may need to increase the permissions on
/usr/sbin/yiff
or reduce the permissions on (give access
to) the network port number in question.
/dev/dsp: Cannot open for playing.
This may indicate
another non-Y compliant sound application is already trying to use the
digital sound processor device, check if any other programs are currently
running (type ps aux
) that might be using
/dev/dsp
. Also check if the sound driver is installed and
loaded properly (type modprobe sound
).
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:
/usr/sbin/yiff /etc/yiff/yiffrc --foreground
/usr/sbin/yiff --help
To formally start YIFF you should run:
/etc/init.d/yiff start
There are two ways to check that:
ps aux|grep yiff
yrecinfo
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:
yrecinfo --recorder 127.0.0.1:9433
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:
yrecinfo --help
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:
yplay -v -m /home/me/mysound.wav
/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:
yplay -v -m /home/me/mysound.mid
yiffconfig
or edit /etc/yiff/yiffrc
to change the MIDIPlayCommand
parameter as needed.
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:
yrecinfo --modes
yset audio PlayStereo11025
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:
yset --help
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:
yset shellout
yplay -v /home/me/mysound.wav
-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:
yset audio default
yplay -v /home/me/mysound.wav
-m
to yplay
, it
would have changed the Audio and thus unshell.
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:
ymixer
To set a specific Y mixer value type:
ymixer vol 70 40
vol
to left channel 70 percent
and right channel 40 percent. To verify type:
ymixer vol
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.
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):
yhost wolfpack.twu.net
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:
yhost 123.45.67.89
yhost - 123.45.67.89
-
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!
To shut down the YIFF Sound Server type:
yshutdown
These are the rules for the conditions in when the YIFF Sound Server is started and shutdown (automatically) by Y client programs:
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.
Once you have everything set up you may want to take a look at the links to other neat and wonderful Y applications.