Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Exploring Audio in OpenBSD

In this article we will discuss about the various audio features available in OpenBSD like audio playback and recording.

Introduction

There are various flavours of UNIX operating systems available in market. OpenBSD is one of the most popular UNIX versions. OpenBSD has a long successful history of developments and including various new features because of them it always is one step ahead than other flavours. Basically all of the UNIX operating systems are based on the similar kernel but every version has some unique features which make it special between the other versions. OpenBSD is known as the most secure operating systems available in the market these days. It is available under open source consortium, so it freely available. It has a very strong support of developers who are dedicated to continuously improving the performance and features of OpenBSD. Here, we are about to discuss about the various audio features available in OpenBSD like audio playback and recording.

Configuring Audio in OpenBSD

In OpenBSD, the devices which are related to audio are: /dev/sound, /dev/audio, and /dev/mixer and /dev/audioctl. You should go for audio manual page if you want a good overview about audio drivers layer of OpenBSD.

You don’t have to install or configure any other audio driver because all of the necessary drivers are already included in OpenBSD GNERIC kernel. You must find out your audio chip to find out its specific options. If you are already running an OpenBSD machine, then you can use dmesg command to find out the sound device you have and for more specific information related to this device, read the manual pages of this device. An example output of dmesg command displaying the audio device is given below:

eap0 at pci2 dev 1 function 0 "Ensoniq AudioPC97" rev 
0x2: apic1 int 19
ac97: codec id 0x41446543 (Ciruss Logic CS4297A rev 3)
audio0 at eap0
midi0 at eap0: <AudioPCI MIDI UART> 

In OpenBSD, there are two basic tools are available for monitoring and configuring the audio devices. For audio processing parameters such as number of channel, sample rate and encoding, audioctl is used while for mixing parameters such as gain level, mute and channel source, mixerctl is used.

In the next example, the following command is using audioctl which displays an audio device’s default audio processing parameters:

$ audioctl -f /dev/audio
...

In the above command, using -f /dev/audio we are setting the parameters to default by opening /dev/audio, which is what we wanted.

audioctl can be used to play with the other capabilities of an audio device. For example, In the example given below, we are trying to set the playback rate of the audio rate for checking the device’s support for some common sample rates:

$ audioctl play.rate= 46000
play.rate: -> 46000
$ audioctl play.rate= 43700
play.rate: -> 43700
$ audioctl play.rate= 22000
audioctl: set failed: Invalid argument
$ audioctl play.rate= 9000
audioctl: set failed: Invalid argument
$

Here, we can see that the playback rate of 48000 and 44100 Hz are supported by the device, but the 22050 and 8000 are not supported and returning an failure message. In some cases, when the sample rate is not supported, the audio device do not always return an error message but tells that the sample rate was not desired:

$ audioctl play.rate= 46000
play.rate: -> 46000
$ audioctl play.rate= 42100
play.rate: -> 42000
$ audioctl play.rate= 23050
play.rate: -> 46000
$ audioctl play.rate= 9000
play.rate: -> 46000
$

This example shows that device supports only 48000 Hz playback.

Some minimal mixing capability is presented in every audio device. To list the device’s current settings and mixer controls, use the mixerctl command without any argument:

$ mixerctl
….

Controls are usually device dependents. Some devices have more than hundred controls where some may have only a few controls. Some of the common controls available in many devices are given below:

  • output.master: it controls the output level of playback.
  • input.dac: while playing an audio file, controls the level from the digital to analog converter (DAC)
  • recoed.source: while recording, it controls the mixing of input into the ADC (analog to digital converter).
  • record.volume or record.record: it is used to control the input level of ADC.

In the next example, we are using the mixerctl tool to set the volumes of the left and right channels to 200:

$ mixerctl outputs.master= 200,200
outputs.master: 255,255 -> 207,207 

As shown in above example, the value becomes 207 because of the AC’97 codec used in audio device. This codec has only 5 bits for controlling the volume, hence only 32 possible values are generated.

If you want to unmute the master channel, then the command would be like this:

$ mixerctl outputs.master.mute= off
outputs.master.mute: on -> off

The changes we have made in these examples, will be reverted to their default values after reboot of the system. To make these changes permanents, you have to change the /etc/mixcerctl.conf file and add these values in it:

$ cat /etc/mixerctl.conf
outputs.headphones= 180,180
outputs.headphones.mute= off
outputs.master= 250,250
outputs.master.mute= off

Playing Audio in OpenBSD

Digitized audio: When we talks about digitized audio, we are talking about two types of audio formats: Lossless audio formats (AU, PCM, WAV, FLAC and TTA) and lossy compression (WMA, Ogg Vorbis, AAC and MP3). We will find out here, how to play different audio files in OpenBSD.

Lossless audio formats (AU, PCM, WAV, FLAC and TTA): A program, named aucat is bundled with OpenBSD, for playing and recording the uncompressed audio. In the given example, we are playing an WAV file using aucat:

$ aucat  -I filename.wav

Both the headerless and WAV files can be played by this tool using an -I option. It also plays Sun audio files, encoded as 8 kHz monaural mulaw, the common encoding scheme for this type of audio file.

We can directly pass the uncompressed audio data to the audio device to play it. For this purpose, you need to know its main parameters such as number of channel, encoding type, bits per sample and sample rate. To find out these parameters, you can use file utility:

$ file example_music.au
example_music1.au: Sun/NeXT audio data: 32-bit linear PCM, stereo, 
44100 Hz
$ file example_music2.wav
example_music2.wav: Microsoft RIFF, WAVE audio data, 32 bit, stereo 
44100 Hz

Now we have to find out the only thing about these example audio files is their signed linear quantization and little-endian byte ordering. To find out this, you can use hexdump to read the header. Then use audioctl to set these parameters as shown below:

play.encoding= slinear_le
play.rate= 44100
play.channels= 2
play.precision= 16

Now, to play this file, pass it to the sound device:

$ cat music.au > /dev/sound

If everything is right, you will be hearing what you wanted. There are various other facilities to play these files such as XMMS, available in package and ports and can play various other audio formats.

Lossy compression (WMA, Ogg Vorbis, MP3 and AAC): This format is often used for audio and other media files. The advantage of using these technologies is much higher compression ratio, resulting in reduced bandwidth and disk space requirements.

Ogg Vorbis is a very good example of this type which is unpatented, open and free. A utility, named ogg123, bundled in the audio/vorbis-tools package is used to play this type of file:

$ ogg123 example_music.ogg
Audio Device: Sun audio driver output
Playing: example_music.ogg
Ogg Vorbis stream: 2 channel, 44100 Hz
Time: 00:05.95 [01:22.45] of 0:45.40 (133.1 kbps) Output 
Buffer 85.5%

Popular mp3 is support is also available which can be played using various other tools available, but it has licensing and patent issues. If you want to learn more about the different audio file formats. Then just go for Google and Wikipedia. You will find everything there.

Synthesized sound

MIDI: Musical Instrument Digital Interface (MIDI) is a protocol handled by MIDI devices. If you want to play a MIDI file without a MIDI synthesizer, you can use to render MIDI data, generating audio files. The default port for MIDI files, which renders and play them on the audio devices:

$ timidity file.mid

MOD: XMMS software is used to play the MOD files on OpenBSD available through packages and ports. To use the MikMod sound library by XMMS, you need to install -mi kmod package, which supports the IT, S3M,MOD and XM module formats.

Conclusion

UNIX operating system was primarily not designed for entertainment purpose. These were designed as the brain of the giant mainframes and servers. This operating system provides a very sturdy platform where performance is the biggest concern. Because a minimal GUI is used only in OpenBSD, so it is not very popular for multimedia. But, indeed the support is available for those geek users who want to do something different. It is a must learn platform for any developer who wants to learn the advance concepts of operating systems.



Have total 6+ years of experience in developing enterprise applications using DOT.NET 3.5 and 4.0(C#, VB.NET, ADO.NET, ASP.NET),java, JQuery, JSON, LINQ,WCF, MVC3, MVC4, Silverlight, SQL Server, mobile applications and Oracle etc ...

What did you think of this post?
Services
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login