[HowTo] Running OSS4 together with ALSA

OSS specific Linux discussion (x86/amd64)

Moderators: hannu, dev, cesium

igorzwx
Known Member
Posts: 1256
Joined: Sun Jun 28, 2009 9:31 pm

[HowTo] Running OSS4 together with ALSA

Postby igorzwx » Fri Feb 02, 2018 6:43 pm

There might be several reasons for loading ALSA drivers together with OSS4:

1. OSS4 does not support USB MIDI keyboards
_http://ossnext.trueinstruments.com/forum/viewtopic.php?f=3&t=5801

2 oss_wrapper (PulseAudio emulation for OSS4) fails to work with TeamSpeak3 [TS3], and some other apps.
_http://ossnext.trueinstruments.com/forum/viewtopic.php?f=3&t=5762

3. One may want to test "apulse" (PulseAudio emulation for ALSA)
It is "open source" _https://github.com/i-rinat/apulse/

It is not difficult to load some ALSA modules together with OSS4.
You have to change a few lines in two files with a text editor, reload OSS4,
and configure ALSA (this can be easily done with Petrov's plugin).

ALSA drivers can be used for USB MIDI Keyboards, USB headsets/soundcards, or any other audio device supported by ALSA.

We will try a simple configuration:

OSS4 + ALSA + USB soundcard

Code: Select all

OSS4 → oss_hdaudio    # Intel High Definition Audio ALC887
ALSA → snd_usb_audio  # iMic USB audio system _https://support.griffintechnology.com/product/imic/


The basic principle: you should not have conflicting drivers loaded.

snd_usb_audio (ALSA driver) conflicts with oss_usb (OSS4 driver), but it does not conflict with other OSS4 drivers.

oss_hdaudio (OSS4) conflicts with ALSA drivers for HDA codecs, but it does not conflict with ALSA drivers for USB devices and many other ALSA modules.

The solution is rather obvious:
oss_hdaudio → Intel HDA codec
snd_usb_audio → USB audio device

The problem is that OSS4 may simply remove all ALSA modules, if one of them is loaded.

OSS4 is started with the "soundon" script.

1. If ALSA drivers are installed, but unloaded, "soundon" does nothing about them.

2. If at least one ALSA module is loaded, "soundon" removes all ALSA modules from the Linux kernel and compresses them into a "secret archive".

To disable this "feature" in "soundon" script, you can open it with a text editor and remove a few lines (or comment them out with "#").

However, if this "feature" is disabled, and the "soundon" script ignores ALSA modules, you should do something yourself to prevent driver conflicts:

1. blacklist all ALSA modules and unload them.
2. remove the unwanted OSS4 driver (oss_usb) from the list of "installed_drivers" and unload it.

Then you can load the ALSA driver you need (snd_usb_audio).

------------------------------------------------------------
NOTE: It is supposed that you blacklisted all ALSA modules
and unloaded them, before installing OSS4.
Otherwise, your ALSA modules could be removed by OSS4.
------------------------------------------------------------

If ALSA modules are already deleted by OSS4, you can simply uninstall OSS4. It will restore your ALSA modules.
Then you can blacklist all ALSA modules:

Code: Select all

$ sudo dpkg-reconfigure linux-sound-base


and unload them (this can be done with reboot).
The manual is here: _https://help.ubuntu.com/community/OpenSound#Blacklisting_ALSA_Kernel_Modules

After reboot, run lsmod to see whether ALSA modules are loaded or not.

Code: Select all

$ lsmod | grep snd


If lsmod command does not list any "snd" driver, you can install OSS4.

If ALSA modules are still loaded, you may need to update "initramfs":
_https://linuxconfig.org/how-to-blacklist-a-module-on-ubuntu-debian-linux
_http://ossnext.trueinstruments.com/forum/viewtopic.php?f=3&t=5828#p21528

When ALSA drivers are blacklisted and unloaded (but available for use), and OSS4 is installed and working,
you may need to unload oss_usb driver.

Code: Select all

$ lsmod | grep oss
oss_usb               116113  2
oss_hdaudio           152241  4
osscore               581591  4 oss_usb,oss_hdaudio


To prevent OSS4 from loading oss_usb driver, you can simply remove it from the list of "installed drivers"
/usr/lib/oss/etc/installed_drivers

This can be done with a text editor:

Code: Select all

$ sudo pluma /usr/lib/oss/etc/installed_drivers


It should look like this:

Code: Select all

$ cat /usr/lib/oss/etc/installed_drivers
oss_hdaudio #Intel High Definition Audio (PPT)
# oss_usb #Generic USB audio/MIDI device (BETA)


The line "oss_usb #Generic USB audio/MIDI device (BETA)" can be removed or commented out with "#".

To unload oss_usb, you have to reload OSS4:

Code: Select all

$ sudo soundoff
$ sudo soundon


oss_usb disappeared:

Code: Select all

$ lsmod | grep oss
oss_hdaudio           152241  0
osscore               581591  1 oss_hdaudio


Now you can try to load ALSA driver snd_usb_audio

Code: Select all

$ sudo modprobe snd_usb_audio


This command will load ALSA driver snd_usb_audio and its "dependencies" (some other ALSA modules).
It will not load any unwanted ALSA driver which may conflict with oss_hdaudio.

Code: Select all

$ lsmod | grep snd
snd_usb_audio         105029  5
snd_pcm                80235  3 snd_usb_audio
snd_timer              24412  3 snd_pcm
snd_page_alloc         14037  1 snd_pcm
snd_hwdep              13273  1 snd_usb_audio
snd_usbmidi_lib        24211  1 snd_usb_audio
snd_rawmidi            25383  1 snd_usbmidi_lib
snd_seq_device         14138  1 snd_rawmidi
snd                    62146  13 snd_usb_audio,snd_pcm,snd_timer,snd_hwdep,snd_usbmidi_lib,snd_rawmidi,snd_seq_device
soundcore              14600  1 snd


Now you have to edit the "soundon" script

Save a copy of "soundon":

Code: Select all

$ mkdir mumu
$ cd mumu
$ sudo cp /usr/sbin/soundon ./soundon-copy.txt
$ ls
soundon-copy.txt


Open the "soundon" script with a text editor:

Code: Select all

$ sudo pluma /usr/sbin/soundon


To disable the removal of ALSA modules in the soundon script, you have to remove (or comment out with "#") some lines.

It should look like this:

Code: Select all

if test -d /proc/asound || grep -q '^ *14 ' < /proc/devices
then
#   if ! sh $OSSLIBDIR/scripts/remove_drv.sh>> $LOG
#   then
#      echo Failed to disable conflicting sound drivers >> $LOG
#      echo Failed to disable conflicting sound drivers
#      echo Reboot and try running soundon again
#      echo
#      echo Also check that you have not compiled sound support statically
#      echo into the kernel.
#      exit 50
#   fi
   echo "ALSA modules currently loaded:"
   lsmod | grep snd
fi


Now it will list ALSA drivers (lsmod | grep snd), instead of removing them.

Code: Select all

$ sudo soundoff
$ sudo soundon
ALSA modules currently loaded:
snd_usb_audio         105029  0
snd_pcm                80235  1 snd_usb_audio
snd_timer              24412  1 snd_pcm
snd_page_alloc         14037  1 snd_pcm
snd_hwdep              13273  1 snd_usb_audio
snd_usbmidi_lib        24211  1 snd_usb_audio
snd_rawmidi            25383  1 snd_usbmidi_lib
snd_seq_device         14138  1 snd_rawmidi
snd                    62146  7 snd_usb_audio,snd_pcm,snd_timer,snd_hwdep,snd_usbmidi_lib,snd_rawmidi,snd_seq_device
soundcore              14600  1 snd


At the end of the soundon script (before "exit 0") add "modprobe snd_usb_audio"

It should look like this:

Code: Select all

modprobe snd_usb_audio
exit 0


Now you can test the crappy sound of ALSA with your USB soundcard.

igorzwx
Known Member
Posts: 1256
Joined: Sun Jun 28, 2009 9:31 pm

Re: [HowTo] Running OSS4 together with ALSA

Postby igorzwx » Fri Feb 02, 2018 7:23 pm

Testing ALSA

Code: Select all

$ find /dev/snd -type c
/dev/snd/controlC1
/dev/snd/pcmC1D0c
/dev/snd/pcmC1D0p
/dev/snd/seq
/dev/snd/timer


You can unloal ALSA with "alsa force-unload"

Code: Select all

$ sudo alsa force-unload
Terminating processes: 2839
2839.
Unloading ALSA sound driver modules: snd-usb-audio snd-pcm snd-timer snd-page-alloc snd-hwdep snd-usbmidi-lib snd-rawmidi snd-seq-device.
$ sudo alsa force-unload
Unloading ALSA sound driver modules: (none loaded).


Code: Select all

$ find /dev/snd -type c
/dev/snd/seq
/dev/snd/timer
$ lsmod | grep snd


You can load ALSA for your USB device:

Code: Select all

$ sudo modprobe snd_usb_audio


Code: Select all

$ lsmod | grep snd
snd_usb_audio         105029  0
snd_pcm                80235  1 snd_usb_audio
snd_timer              24412  1 snd_pcm
snd_page_alloc         14037  1 snd_pcm
snd_hwdep              13273  1 snd_usb_audio
snd_usbmidi_lib        24211  1 snd_usb_audio
snd_rawmidi            25383  1 snd_usbmidi_lib
snd_seq_device         14138  1 snd_rawmidi
snd                    62146  7 snd_usb_audio,snd_pcm,snd_timer,snd_hwdep,snd_usbmidi_lib,snd_rawmidi,snd_seq_device
soundcore              14600  1 snd


Code: Select all

$ find /dev/snd -type c
/dev/snd/controlC1
/dev/snd/pcmC1D0c
/dev/snd/pcmC1D0p
/dev/snd/seq
/dev/snd/timer


Let us check audio playback:

Code: Select all

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 1: system [iMic USB audio system], device 0: USB Audio [USB Audio]


This means hw:1,0 [card 1, device 0]

Run ALSA mixer and adjust level of playback and recording

Code: Select all

$ alsamixer -c 1


The manual is here: _https://wiki.archlinux.org/index.php/Advanced_Linux_Sound_Architecture#Unmute_with_alsamixer

You may also try a sort of "Volume Control" applet, e.g. "mate-volume-control-applet".

To save mixer setting, execute:

Code: Select all

$ sudo alsactl store


Speaker test:

Code: Select all

$ speaker-test -D hw:1,0 -c 2
Playback device is hw:1,0
Stream parameters are 48000Hz, S16_LE, 2 channels
Using 16 octaves of pink noise
Playback open error: -16,Device or resource busy


The device is busy.
To free your ALSA device, you can run "fuser" (interactive mode):

Code: Select all

$ fuser -ikv $(find /dev/snd -type c 2>/dev/null)
                     USER        PID ACCESS COMMAND
/dev/snd/pcmC1D0p:   igor      15135 F...m min
Kill process 15135 ? (y/N) y
/dev/snd/timer:      igor      15135 f.... min
Kill process 15135 ? (y/N) y
Could not kill process 15135: No such process


Now the audio device (hw:1,0) is free:

Code: Select all

$ fuser -av $(find /dev/snd -type c 2>/dev/null)
                     USER        PID ACCESS COMMAND
/dev/snd/controlC1:
/dev/snd/pcmC1D0c:
/dev/snd/pcmC1D0p:
/dev/snd/seq:
/dev/snd/timer:


and you can run "speaker-test":

Code: Select all

$ speaker-test -D hw:1,0 -c 2
Playback device is hw:1,0
Stream parameters are 48000Hz, S16_LE, 2 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 96 to 262144
Period size range from 48 to 131072
Using max buffer size 262144
Periods = 4
was set period_size = 65536
was set buffer_size = 262144
 0 - Front Left
 1 - Front Right
Time per period = 5.534560
 0 - Front Left
 1 - Front Right
Time per period = 5.535968


Code: Select all

$ aplay -D hw:1,0 *.wav
Playing WAVE '11 Historia De Un Amor.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo


Code: Select all

$ arecord -D hw:1,0 -f S16_LE -r 48000 1-exp_rec_alsa.wav
Recording WAVE '1-exp_rec_alsa.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono


ALSA works, but it might be difficult to use.
You may need to configure it. This can be easily done with Petrov's plugin.

igorzwx
Known Member
Posts: 1256
Joined: Sun Jun 28, 2009 9:31 pm

Re: [HowTo] Running OSS4 together with ALSA

Postby igorzwx » Fri Feb 02, 2018 7:45 pm

Petrov's plugin for ALSA

ALSA is difficult to configure, and its sound seems to be dangerous for health.

The simplest solution for such problems might be Petrov's plugin for ALSA.
It disables crappy resamplers of ALSA and replaces them with the "exact scientific resampler".
ALSA configuration files can be easily created with Petrov's "arateconf".

Download Petrov's plugin for ALSA (fftrate.zip)
_http://ossnext.trueinstruments.com/forum/viewtopic.php?f=3&t=5788#p21155

Unsip it, and install deb-packages:
alsa-config-utils
libasound2-plugin-fftrate

Open /etc/fftrate.conf with a text editor:

Code: Select all

$ sudo pluma /etc/fftrate.conf


and enable fft resampler.

It should look like this:

Code: Select all

$ cat /etc/fftrate.conf
# Transform type
# Available: dct, fft (default: dct)
#transform = dct
transform = fft

# Window type
# Available: vorbis, hanning, rect (default: vorbis)
#window = vorbis

# Set zummer for self detection
# Available: on, off (default: off)
#zummer = off


dct is "exact resampler"
fft is "very exact resampler"


Run arateconf (interactive mode):

Code: Select all

$ arateconf


and configure ALSA for your should card.

Example:

Code: Select all

$ arateconf

|  Main menu  |
---------------

    Curr. | Used | Play (def) | Rec (def) | Available cards
----------|------|------------|-----------|-----------------------------------
0 - >>>>> |  *   |  *     *   |  *    *   | USB-Audio - iMic USB audio system

U - Toggle used flag
P - Set this device as default player
R - Set this device as default recorder

O - Output device: system,0
I - Input device : system,0

F - Format: 48000 Hz, 2 ch, 'S16_LE'
C - Converter: fftrate

A - Show all plugins [ ]
M - Plug-ins:
 [X] Convert,  [ ] Expand, [X] Asym
 [ ] Play Vol, [X] Dmix
 [ ] Rec. Vol, [X] Dsnoop
 [ ] Phonon,   [ ] Normalizator

T - Test
S - Save to '/home/igor/.asoundrc'
X - Delete '/home/igor/.asoundrc'

ESC - Exit
> t
Testing H/W compatibility ...

Device: system
Output:
 Open device "hw:system,0" ... Ok.
 Set rate 48000 Hz ... Ok.
 Set channels 2 ... Ok.
 Set format 'S16_LE' ... Ok.
 Set buffer size 7680 -> 7680
 Set period size 1920 -> 1920
Input:
 Open device "hw:system,0" ... Ok.
 Set rate 48000 Hz ... Ok.
 Set format 'S16_LE' ... Ok.
 Set buffer size 7680 -> 7680
 Set period size 1920 -> 1920

Press any key ...


Do not forget to test your configuration and save ~/.asoundrc

Code: Select all

T - Test
S - Save to '/home/igor/.asoundrc'


asoundrc for iMic USB should look like this:

Code: Select all

$ cat ~/.asoundrc
# ALSA library configuration file managed by arateconf.
#
# MANUAL CHANGES TO THIS FILE WILL BE OVERWRITTEN!
#
# Manual changes to the ALSA library configuration should be implemented
# by editing the ~/.asoundrc file, not by editing this file.


#=====================================================
# Configuration for system
#-----------------------------------------------------

# Perform dmixer
pcm.dmixer
{
   type         dmix
   ipc_key         1024
   ipc_perm      0666

   hint
   {
      show      off
      description   "Direct mixing of multiple audio streams"
   }

   slave
   {
      pcm      "hw:system,0"

      rate      48000
      channels   2
      format      S16_LE

      period_size   1920
      buffer_size   7680
   }
}


# Perform dsnooper
pcm.dsnooper
{
   type         dsnoop
   ipc_key         1025
   ipc_perm      0666

   hint
   {
      show      off
      description   "Recording from the same device for several applications simultaneously"
   }

   slave
   {
      pcm      "hw:system,0"

      rate      48000
      format      S16_LE

      period_size   1920
      buffer_size   7680
   }
}


# Perform duplex
pcm.duplex
{
   type         asym
   playback.pcm      "dmixer"
   capture.pcm      "dsnooper"

   hint
   {
      show      off
      description   "Full duplex for simultaneous playback and recording"
   }
}


# Perform convert
pcm.convert
{
   type         rate
   converter      fftrate

   hint
   {
      show      off
      description   "Sample rate converter"
   }

   slave
   {
      pcm   "duplex"
      rate   48000
      format   S16_LE
   }
}


#=====================================================
# Configuration for default audio device
#-----------------------------------------------------

# Perform plug device
pcm.!default
{
   type         plug
   slave.pcm      "convert"
   hint.description   "Default device"
}


Now you can test the "default audio device":

Code: Select all

$ aplay *.wav
Playing WAVE '11 Historia De Un Amor.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Converter: fftrate (build: Jan 31 2013, 18:37:15, linux-i386)
Input:  44100 Hz, 2 ch, 's16_le' (0x2): dummy = 0, period = 1764
Output: 48000 Hz, 2 ch, 's16_le' (0x2): dummy = 0, period = 1920
Rates:  44100 --> 48000 (J: 0.00%, T: FFT, W: Vorbis)
Ok.


Code: Select all

$ arecord -f S16_LE -r 48000 2-exp_rec_alsa.wav
Recording WAVE '2-exp_rec_alsa.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
Converter: fftrate (build: Jan 31 2013, 18:37:15, linux-i386)
Input:  48000 Hz, 2 ch, 's16_le' (0x2): dummy = 0, period = 1920
Output: 48000 Hz, 2 ch, 's16_le' (0x2): dummy = 0, period = 1920
Rates:  48000 --> 48000 (J: 0.00%, T: None, W: Planar)
Ok.


"T: FFT" means fft resampler
"T: DCT" is dct resampler
"T: None" - resampling is not needed (48kHz → 48kHz)


Return to “Linux”

Who is online

Users browsing this forum: No registered users and 3 guests