Release notes for Sonorus STUDI/O OSS driver
============================================

IMPORTANT! The STUDI/O driver is a separately priced option of OSS. Please
remember to check this option when ordering your OSS license.
The driver software itself is included in the standard OSS
installation package but will require the option to be listed
in the license file.

** Sonorus STUDI/O is supported only in Linux (x86 version) **

** The current STUDI/O driver version may not work properly **
** under SMP kernels on some (dual CPU) systems. **

** Syncronizing with an external ADAT source is not fully supported **
You can use internal clock when doing ADAT recording but this may cause
sync loss problems.

What is Sonorus STUDI/O
-----------------------

Sonorus STUDI/O is a high end audio card with two optical digital input
and output ports. Both ports can be configured to work in S/PDIF (stereo)
or ADAT (8 channels) modes. This gives up to 16 simultaneous input and
output channels. In addition the card has a 18 bit analog output (monitor)
port. There is a mixer that can be used to mix any combination of the
input and output signals to the monitor port. In addition OSS supports the
monitor port as an independent stereo output device.

Both 16 and 24 bit (actually 32 bit msb aligned) formats are
supported.

See http://www.sonorus.com for more information about STUDI/O.

Applications of STUDI/O OSS driver
----------------------------------

The STUDI/O card is very versatile device. Together with OSS you can use it
for example to following tasks:

- Transferring data to/from DAT tapes or any devices having optical S/PDIF
connectors. It's also possible to copy data directly from device to device.
- Transferring data to/from 8 channel Alesis ADAT compatible devices.
- By connecting high quality external DAC and/or ADC devices to the optical
ports it's possible to do very high quality playback and recording. Optical
connections provide perfect isolation against noise emitted from the computer
system. Depending on the converters being used it's possible to use
2, 4, 8, 10 or 16 simultaneous inputs and outputs (or many combinations of
them). Cheap 16 bit converters can be used while up to 24 bit high performance
ones are supported.
- Several digital mixing console combinations will be supported.

Installation
------------

The STUDI/O driver is included in the standard OSS installation package
and the card will be detected automatically during installation. However
the STUDIO option will be required in the license file before the driver
works. It's included in the evaluation licenses and needs to be checked when
ordering the permanent license.

Device files
------------

The STUDI/O driver will create several audio device files (/dev/dsp#,
/dev/audio#) when started. The number of device files depends on the mode
in which the card is being used (will be described in the next chapter).

The first device being created is an output device for the analog monitor
device. It will always work in stereo mode (mono use is not possible).

There are separete sets of device files for both the output and the input
channels. The number of devices being created depends on the selected mode.
The following example shows the devices for mode 0 (device numbering may
be different if there are other sound devices installed):

Audio devices:
0: STUDI/O monitor output (stereo)
1: STUDI/O output A0
2: STUDI/O output A1
3: STUDI/O output B0
4: STUDI/O output B1
5: STUDI/O input A0
6: STUDI/O input A1
7: STUDI/O input B0
8: STUDI/O input B1

In the above case monitor output is the /dev/dsp0 device. Output devices
for the S/PDIF channels A0, A1 (port A), B0 and B1 (port B) are /dev/dsp1 to
/dev/dsp4 (respectively). The input device files are /dev/dsp5 to /dev/dsp8).

Monitor and output ports can be opened only for write access (O_WRONLY) while
the input devices are read only (O_RDONLY). For fuplex use you will need to
two devices. One or more of the output ports for writing and one or more
of the input ports for reading.

As mentioned earlier the monitor port works always in stereo mode. The digital
devices can be used in 1 to N channel modes where the N depends on the
device file being used and the studio mode. In the 2*ADAT modes N can be as
large as 16.

When an input or output device file is opened it will be in one channel (mono)
mode. When the application changes the number of channels a check will be made
to see if desired number of channels are available and the channels will be
allocated for the device file. For example when /dev/dsp1 is set to 4 channel
mode the /dev/dsp2, /dev/dsp3 and /dev/dsp4 devices will be joined with it.
After that none of these devices cannot be opened until /dev/dsp1 is closed.
This means that in the above case /dev/dsp1 and /dev/dsp5 can be used in
1, 2, 3 or 4 channel modes while it's possible to use /dev/dsp4 and /dev/dsp8
only in one channel mode.

It's possible to use the available devices in any combination of modes provided
that the channel ranges don't intersect. For example it's possible to open
/dev/dsp1 and /dev/dsp3 and to set both of them to stereo mode. Alternatively
all of the devices (1 to 4) can be opened separately and used in mono mode.

When more than one channels are allocated for a device file the samples for
each channel will be interleaved in the audio data stream. For example
(3 channel mode):
ch1_sample1, ch2_sample1, ch3_sample1, ch1_sample2, ch2_sample2, ch3_sample2.

Note that all the device files may not be created automatically when
the STUDI/O card is configured for modes supporting more than 16 channels.
A method for fixing this situation is described later in this document.

Clock source issues
-------------------

The sample rate used for all the device files can be derived from
various sources. The settings can be changed using the ossmix utility.
The associated parameters will be described later in this document.

The main clock source is determined by the fpga.clock parameter).
By default the clock is derived from the S/PDIF port A ("AES"). The other
alternatives are dixed 44.1kHz or 48 kHz rates (derived from an internal
crystal oscillator) or PLL oscillator.

Operating mode of the PLL circuit is determined by the fpga.pll setting.
The available alternatives are locking to the port A or port B input signals,
internal sample rate timer or external sync input (from optional sync
backplane).

In addition to the main clock some modes support different sampling
rate for the output port A than the one used by the other inputs and outputs.
This can be used for example to produce a real time 44.1kHz mix of a
performance otherwise occurring using 48kHz sample rate. This
SRC clock can be set using the fpga.srcclock setting which works just
like fpga.clock.

These settings can be changed any time but it's highly recommended to do
changes only when none of the device files are in use. However the changes
will not take effect before the device is reactivated (by starting an
input or output operation).

During recording the clock should be determined from the input port
used as the source. Otherwise incoming signal will be completely distorted.
Internal source should be used when no input is connected to the digital
input ports. If sync is dropped during recording/playback the device will
be stopped and all applications using it will receive an I/O error (EIO).

Starting the recording and/or playback operations
-------------------------------------------------

It's not yet possible to start recording/playback operations using several
device files simultaneously. All device files will start the transfer as
soon as read is called or enough data (128 samples/channel) is written to the
the device file. There will be methods for syncronous operation of device
files in the final STUDI/O driver version.

Changing sampling parameters
----------------------------

This chapter is intended only for programmers writing applications that use
the STUDI/O card.

1) Changing sampling rate

Application programs will not be able to change the sampling rate themselves.
The sampling rate is selected by the mixer/control panel settings (see below)
and this rate will be returned to the application. Applications using
STUDI/O should be able to handle this by adopting to the selected sample rate
or by aborting the operation.

2) Changing sample format

Both 16 bit (AFMT_S16_NE) and 24/32 bit (AFMT_S32_NE) formats are supported.

3) Changing number of channels

The monitor output device (/dev/dsp0) is fixed to 2 channel (stereo) mode.
For other device files it's possible to change the number of channels as
described earlier.

NOTE! Some applications use the SNDCTL_DSP_GETBLKSIZE in incorrect way
(it should always be called after selecting the sampling parameters).
recording will not work with applications that call this ioctl before
selecting the sample rate, number of channels and/or sample format.

NOTE! Applications should not change the sampling parameters after
starting the read or write operation. The device file should be
closed and reopened before doing this. In particular number
of channels cannot be decreased without reopening the device.

NOTE! Fragment size will always be controlled by the driver and it will be
set to match 64 samples/channel when using the selected sample format
(for example 256 bytes for 16bit/stereo format). The
SNDCTL_DSP_SETFRAGMENT ioctl can be used to change the number of
fragments but it will not have any effect to the fragment size.

Analog monitor (mix) output
---------------------------

In addition to the monitor output device file (/dev/dsp0 in the above case)
the analog monitor output connector receives a mix of the digital input and
output signals. This mixing process is controlled by the mixer settings that
are changeable using the ossmix utility shipped with OSS (see below).

The default mixer volume settings are selected so that even numbered channels
(A0, A2, A4, ... B0, B2, B4, ..., B(N-1)) will be mixed only to the left
channel of the analog monitor mix while the other channels are sent only to
the right channel. When the A0 port is used in mono mode the output will be
heard only from the left monitor channel. It's possible to change panning
for the outputs or inputs using the ossmix utility.

Channel pairs A0+A1, A2+A3, ..., B0+B1, B2+B3, ... can be used as stereo
pairs. When different combinations (such as A1+A2) are used the channels
will be reversed. This can be fixed by adjusting the mixer settings.

Load time (soundon) settings
----------------------------

There are few setup options that can be changed in devices.cfg and options.cfg
files in the directory where OSS is installed. These settings will take effect
when OSS is started next time (using soundon).

The operation mode of the STUDI/O board is defined by the studio_mode variable
in the options.cfg file (for example studio_mode=0). The operation mode
affects assignment of the optical ports. The following modes are available:

studio_mode=0 2*S/PDIF in, 2*S/PDIF out.
studio_mode=1 ADAT+S/PDIF(SRC) in, ADAT+S/PDIF out.
studio_mode=2 2*ADAT in, 2*ADAT out (not supported)
studio_mode=3 ADAT+SPDIF(SRC) in, 2*ADAT out (for Korg 168RC
digital mixing console). Supported but OUTB
channels don't get assigned properly.

NOTE! studio_mode=2 is not supported due to unidentified system
lockup problems. In most cases studio_mode=3 will give the same
functionality.

The studio_aes_mode option can be used to select between the consumer and
pro S/PDIF formats.

studio_aes_mode= ? 0=consumer and 1=pro (not supported yet)

Note that by default OSS will create only 16 audio device files. This will not
be enough if STUDI/O board is used in one of the ADAT or ADAT+S/PDIF modes.
More device files can be created by adding the following line to devices.cfg:

/DSPX

By default OSS will allocate 64k of buffer for each input, output and monitor
channel. This can be changed by defining the studio_buffsize parameter in
options.cfg. For example studio_buffsize=64 will set the buffer size to
64k (the default). Larger buffers may be required if there are overrun/underrun
problems during hard disk recording. However great care should be taken that
the total buffer space required will not exceed the available RAM space
in the system. One buffer will be allocated for each channels and there can
be up to 16+16+2=34 channels in the 2*ADAT in/2*ADAT out mode. This will
consume 2.1M of RAM with 64k buffers.

Start time settings
-------------------

There are several parameters that can be changed before starting recording
and/or playback (actually they can be changed any time but the change will
take effect when recording/playback is (re)activated next time. These
parameters include for example clock source. These settings can be changed
using the command line based ossmix program (a GUI based one will be released
in future). The following start time options are available (some of them
are not available in all modes):

setup.mon1l (currently A0)
setup.mon2l (currently OFF)
setup.mon1r (currently A1)
setup.mon2r (currently B1)
These settings can be used to route the monitor mix to up to two
pairs of digital output ports. The default value is OFF which means
that the monitor mix is not sent to the digital outputs. This feature
can be used for example for real time mixing of a performance to a
DAT tape.

fpga.srcclock <44.1K|48K|PLL|AES> (currently AES)
In studio_mode 0 this setting determines the sampling rate of
output port A (sample rate conversion). 44.1K and 48K are fixed
sampling rates based on internal clock. PLL is sample rate generated
by PLL (see below). AES is the sampling rate of input port A.

fpga.clock <44.1K|48K|PLL|AES> (currently AES)
This setting defines the sampling rate for all input and output
ports (except output A in studio_mode 0). meanings of the values are
as above. PLL mode is not supported. For ADAT recording you should
use fixed 44.1K or 48K clock.

fpga.pll (currently TIMER1)
PLL source used when PLL is selected for fpga.srcclock or fpga.clock.
PORTA and PORTB are the sampling rates measured from the input ports.
TIMER1 is internally generated sampling rate (setup.srate). EXTERNAL
means external sync input.

aes.copy (currently PERMITTED)
Copy enable bit of the consumer S/PDIF format.

aes.preemphasis (currently NONE)
The pre emphasis field of the consumer S/PDIF format.

aes.audio (currently AUDIO)

aes.category (currently 3)
The category field of the consumer S/PDIF format. See the AES/EBU
interface specification for more details.

aes.generat (currently 0)
The generation bit of the consumer S/PDIF format. Note that
interpretation of this bit depends on the aes.category field.

Online mixer/control parameters
-------------------------------

There are few parameters that can be changed any time and the change will
take effect immediately. The main volume (analog monitor output volume)
parameter can be changed using any mixer program. In addition there are
some parameters that can be changed only using ossmix. These ones include
settings for independent digital channel volumes. The following settings
can be adjusted any time:

vol [:] (currently 50:50)
This setting defines master volume of the analog monitor output.

mixer.out_a0 [:] (currently 100:0)
mixer.out_a1 [:] (currently 0:100)
...
mixer.out_b0 [:] (currently 100:0)
mixer.out_b1 [:] (currently 0:100)
...
There are individual controls for each output channels which define
how much of this signal is added to the monitor mix. Note the default
settings which are totally out of balance (a0 is routed only to the left
monitor channel and a1 to the right one and so on). Number of the available
controls will vary depending on the mode.

mixer.in_a0 [:] (currently 100:0)
mixer.in_a1 [:] (currently 0:100)
...
mixer.in_b0 [:] (currently 100:0)
mixer.in_b1 [:] (currently 0:100)
...
Like above but for the digital inputs.


Peak meter and other online status information
----------------------------------------------

STUDI/O card has capability to provide many kind of online information such
as peak meters for the channels and some error/status variables. This
information is not readable with current OSS version but support for this
will be implemented in future.

Performance issues
------------------

Doing full duplex (hard disk recording) work using 16 simultaneous
channels will push the system to it's performance limits. The system
(disk hardware) as well as the application(s) being used must be able
to handle the volume of data (sustained). Otherwise recorded samples may be
dropped and/or output may be distorted (clicks, pauses or buzzing sounds).

The default buffer size (63k/channel) is enough to hold about 0.5 seconds of
audio data. This means that the delays caused by disk and processing activity
must be less than 0.5 second in all situations. In Linux this is known to
cause problems at the times the system syncs accumulated write buffers to
disk. The total data volume caused by simultaneous 16 channel recording
and playback at 48kHz/16 bits is 2*16*48000*2=4.15 megabytes/second.

It's possible to make the system more tolerant to performance problems
by increasing the buffer size using the studio_buffsize option. However
better results can be obtained by using application level buffering and
by storing the data on raw disk partitions instead of regular files on
a filesystem. Using fast SCSI disk(s) is a must. IDE DISKS ARE NOT SUPPORTED
TOGETHER WITH STUDI/O. IDE disk activity will cause serious timing problems
when STUDI/O card is operating.

Limitations of the current STUDI/O driver
-----------------------------------------

There are some limitations in this version of the STUDI/O OSS driver.
Most of them have been discussed earlier. Below is a list of the most
important ones:

- The 2*ADAT mode is not supported.
- Only one STUDI/O card is verified to work simultaneously.
- It's not yet possible to set the sampling rate related with the
"TIMER1" choice of the fpga.pll setting.
- The external sync backplane is not supported.
- Support for the peak meters is not available yet.