Android Audio Tutorial [Part One] : Introduction


Sound Card.

sound card (also known as an audio card) is an internal expansion card that provides input and output of audio signals to and from a computer under control of computer programs. The term sound card is also applied to external audio interfaces used for professional audio applications.

Sound functionality can also be integrated onto the motherboard, using components similar to those found on plug-in cards. The integrated sound system is often still referred to as a sound card. Sound processing hardware is also present on modern video cards with HDMI to output sound along with the video using that connector; previously they used a SPDIF connection to the motherboard or sound card.

Typical uses of sound cards or sound card functionality include providing the audio component for multimedia applications such as music composition, editing video or audio, presentation, education and entertainment (games) and video projection. Sound cards are also used for computer-based communication such as voice over IP and teleconferencing.


If the sound card itself does not have a main processing chip, but only the decoding chip, it needs to perform processing through the CPU operation, then it is a "soft sound card".

Computers that typically target the low-end market will include an integrated sound card device to reduce costs.

A typical sound card usually contains three parts:



Connectors

Used for connection between sound card and external equipment such as speakers and headphones, also known as “jacks”.

Audio Circuits

The main implementation of the sound card, which is responsible for signal amplification, mixing and analog digital conversion operations.

Interface
The unit that connects the sound card to the computer bus, such as the PCI bus


We can use the "cat/proc/asound/cards" command to see the sound card devices installed in a computer, as shown in the following figure below:






Android is a Linux based system and it depends on various device driver support provided by the kernel, including the audio drivers. 

Let us take some time to learn the two main audio driver architectures under the Linux platform.

Open Sound System

The Open Sound System (OSS) is an interface for making and capturing sound in Unix and Unix-like operating systems. It is based on standard Unix devices system calls (i.e. POSIX read, write, ioctl, etc.). The term also sometimes refers to the software in a Unix kernel that provides the OSS interface; it can be thought of as a device driver (or a collection of device drivers) for sound controller hardware. The goal of OSS is to allow the writing of sound-based applications that are agnostic of the underlying sound hardware.

OSS was created by Hannu Savolainen and is distributed under four license options, three of which are free software licences, thus making OSS free software.
API
The API is designed to use the traditional Unix framework of open(), read(), write(), and ioctl(), via special devices. 

For instance, the default device for sound input and output is /dev/dsp.

Examples using the shell:

cat /dev/random > /dev/dsp # plays white noise through the speaker

cat /dev/dsp > a.a # reads data from the microphone and copies it to file a.a



Some of the Nodes used by OSS are.

a.     /dev/dsp

1.     Write data to this file “output to loud speaker”

2.     Read data to this file “Record from Microphone”

b.     /dev/mixer

1.     Mixer for related settings of audio equipment, such as volume adjustment

c.     /dev/midi00

1.     The first MIDI port, midi01, midi02, and so on

d.     /dev/sequencer

1.     Used to access synthesizers, often used to create effects used in games etc



Some of the limitations of OSS which make it a little unfavorable when compared to its peers like ALSA are.

a.     Insufficient support for new audio features.

b.     Lack of support for the latest kernel features and more.


ALSA (Advanced Linux Sound Architecture).

AdvancedLinux Sound Architecture (ALSA) is a software framework and part of the Linux kernel that provides an application programming interface (API) for sound card device drivers.

Some of the goals of the ALSA project at its inception were automatic configuration of sound-card hardware and graceful handling of multiple sound devices in a system. ALSA is released under the GNU General Public License (GPL) and the GNU Lesser General Public License (LGPL).

The sound servers PulseAudio and JACK (low-latency professional-grade audio editing and mixing), the higher-level abstraction APIs OpenAL, SDL audio, etc. work on top of ALSA and implemented sound card device drivers. On Linux systems, ALSA succeeded the older Open Sound System (OSS).

Features
ALSA was designed with some features which were not, at the time of its conception, supported by OSS:
a.     Hardware-based MIDI synthesis.
b.     Hardware mixing of multiple channels.
c.     Full-duplex operation.
d.     Multiprocessor-friendly, thread-safe device drivers.

ALSA has a larger and more complex API than OSS, so it can be more difficult to develop an application that uses ALSA as its sound technology. While ALSA may be configured to provide an OSS emulation layer, such functionality is no longer available or is not installed by default in many Linux distributions.


Besides the sound device drivers, ALSA bundles a user-space library for application developers who want to use driver features through an interface that is higher-level than the interface provided for direct interaction with the kernel drivers. Unlike the kernel API, which tries to reflect the capabilities of the hardware directly, ALSA's user-space library presents an abstraction that remains as standardized as possible across disparate underlying hardware elements.

 Some of the components in the alsa-project are.



Component
Description
alsa-driver
Kernel driver package
alsa-lib
User space function library
alsa-utils
Contains many useful components, such as
alsactl: used to save device settings
amixer: is a command line program for volume and other sound controls
alsamixer: the ncurses version of amixer

aplay and arecord: two command line programs for playing and recording multiple formats of audio
alsa-tools
Contains misc tools
alsa-firmware
Audio Firmware Support Package
alsa-plugins
Plug-in packages such as jack, pulse etc
alsa-oss
OSS-compatible analog package
pyalsa
Alsa lib for compiling Python versions


Alsa's main file nodes are as follows:

a.     Information Interface (/proc/asound)
b.     Control Interface (/dev/snd/controlCx)
c.     Mixer Interface (/dev/snd/mixerCxDy)
d.     PCM Interface (/dev/snd/pcmCxDy)
e.     Raw MIDI Interface (/dev/snd/midiCxDy)
f.      Sequencer Interface (/dev/snd/seq)
g.     Timer Interface (/dev/snd/timer)

Where, 
Cx refers to CARD number x.
Dy refers to DEVICE number y.


For more details on the alsa-project please check.



TinyALSA.

TinyALSA is a small library to interface with ALSA in the Linux kernel.

The aims are:
a.     Provide a basic pcm and mixer API.
b.     If it's not absolutely needed, don't add it to the API.
c.     Avoid supporting complex and unnecessary operations, that could be dealt with at a higher level.
d.     Provide comprehensive documentation.
  

We can see in the external/tinyalsa directory which contains a few of the few source files.




Android.mk
Android Makefile
mixer.c
Mixer Interface implementation
pcm.c
PCM Interface implementation
tinycap.c
Capture tool
tinymix.c
Mixer tool
tinyplay.c
Play Tool
Include/tinyalsa/asoundlib.h
header File


TinyAlsa is a stripped down version of alsa and does not support many interfaces like sequencer etc.


Audio Framework in Android.

The android audio subsystem decouples the userspace and kernel space implementation. 

The following diagram represents the architecture in a very simple way.







Let us briefly talk about some of the components we saw in the above figure.

Application.
This is the audio application like Mediaplayer/Youtube/A game which tries to play some sound etc.

 Framework.
Since we already have some fair idea of the Android system. We can think MediaPlayer and MediaRecorder. They are the most widely used classes for playing ore recording audio on Android system.
In fact, Android also provides two other similar classes AudioTrack and AudioRecorder.
In addition, the Android system also provides AudioManager, AudioService, and AudioSystem classes for our control of audio systems. 

Audio HAL
From a design point of view, the hardware abstraction layer is directly accessed by AudioFlinger to talk to the Linux kernel drivers. 

We will analyze all of these when we take a deep dive in Android audio architecture.




Comments

  1. very crisp and good information.

    ReplyDelete
  2. Very nice blog,keep sharing more posts with us.

    thank you...

    android developer training
    ios online training

    ReplyDelete
  3. Amazing content really helpful!
    Spy Playing Cards Devices is considered to be the best dealer in the field of advanced poker cheating scanners and devices Call +91-9999332499, 9999332099.

    ReplyDelete
  4. Amazing post! .I appreciate your hard work. Thank you for sharing. I have also shared some useful information. PicoBuds Pro Review on Ossward.org

    ReplyDelete

  5. Hi dear,

    Thank you for this wonderful post. It is very informative and useful. I would like to share something here too. A trusted Online music store for Musical instruments & Audio Equipment in India. Buy Studio Monitors, Audio Interface, Microphone, Audio Accessories.


    motu sound card price

    ReplyDelete
  6. Very Nice Post. I am very happy to see this post. Such a wonderful information to share with us. I would like to share with my friends. For more information visit here motu sound card

    ReplyDelete
  7. This is a fantastic post information. Explanations that are straightforward. Nice breaks in the content to allow us to take a breather while we work. Sound can also be built onto the motherboard using components that are comparable to those found on plug-in cards. It's a good idea to look at your gain structure if your signal level is considerably greater or lower when you bypass the device. This is an external probe extender with audio plug.

    ReplyDelete
  8. Find you Music System on Rent for Party, Conference meetings, Birthday celebration, Weddings or any other Occassion, try DG Event throughout Delhi NCR Service at doorstep

    ReplyDelete
  9. Very Nice Blog!
    Choose your smart choice sound recording device at Spy Store. Trend Audio Devices Online Shopping with free shipping at the best price (9999332499, 9999332099). Buy and Sell Spy Hidden Voice Recorder Device for office, home, vehicle, and more places. Free Demo wih free shipping, and one month replacement policy.
    Voice Recorder Device in Kolkata
    Sound Recorder Device in Chennai
    Audio Device Device in Delhi
    Audio Device Shop in India
    Shop Online Voice Recorder
    Spy Hidden Voice Recorder Device
    Audio Device in Mumbai
    Audio Device in Ahemadabad
    Audio Device in Lucknow
    Audio Device in Patna
    Audio Device in Goa

    ReplyDelete

  10. Thank you so much for posting!
    Get one of the best Sounds/Voice Recording Device at best price with free shipping in India. Choose Voice Recorder Device in Nehru Place Top Market Store 2022. Buy the latest sound recorder device for voice recording, Call at +91-9999332499, +91-9999332099.







    ReplyDelete
  11. Thank you so much for posting a unique content!
    Get the Newest the Best Voice Recorder Device in India with high quality voice/sound recording for security purposes. Spy Camera India offers all types of Audio Devices at a reasonable price with free shipping. If you have any technical issues please contact us 9999332099, 9999332499.

    ReplyDelete
  12. Spy Shop Online India’s one of the best Spy Cameras Shop. We provide all types of Gadgets to ease your lifestyle like Spy Cameras, Spy Voice recorders, GPS trackers, Magic Cards, Wireless Cameras, Pen Cameras, and many more. These devices are used for Home Security, Office Security, Vehicle Security, and other expensive things. We sell our products at wholesale price with free shipping all over India. If you have any query related to Spy Gadgets please Visit our Site spyshoponline.in or also contact us on this 9999332099, 9999332499.

    ReplyDelete
  13. Best Spy Audio Devices Prices in Delhi A professional high-quality voice recording device on Spy Shop Online. We are the top seller of Spy Audio Devices at the Cheapest price. Which is available at wholesale and retail prices in Delhi. Order now 9871582898, 9650321315

    ReplyDelete
  14. Spy Shop Online is the Leading Company. Wireless Audio Spy Devices in Patel Nagar. We Provide all types of audio devices Spy Audio Devices, power banks, Socket boards, and charger audio devices. You can get Audio Devices at Spy Shop Online Order now contact this Number 9999332099 / 9999332499

    ReplyDelete
  15. Get one of the Top Wireless Audio Spy Devices Voice Recording Device at the best price with free shipping in India. Choose a voice recorder device in Nehru's place. Top Market Store 2022. Buy the latest sound recorder device for voice recording. Call 9999332499 / 9999332099.

    ReplyDelete
  16. View the top 5 Wireless Audio Spy Devices Spy Shop Online is the best seller of wireless audio spy devices in Delhi. We are the best seller of all Spy Audio Devices at retail and wholesale prices with free shipping. If you have any query related to Spy Audio Device. Contact at this number 9999332499 / 9999332099

    ReplyDelete
  17. Top Wireless Audio Spy Devices in Nehru Place. Spy Shop Online is the best seller in India. Offline and online is the sale available on weekend sale. Buy the latest sound recorder device for voice recording. Call at +91-9999332499, or +91-9999332099.

    ReplyDelete
  18. This comment has been removed by the author.

    ReplyDelete
  19. Spy shop online is the Very best company Which do all type of spy audio sale. And no other option is better than a wireless audio spy device. Currently there are so many great options in the market when you search online or Even offline. The reason behind the success and popularity of these devices is pretty Obvious. Contact at number 9999332499 | 9999332099

    ReplyDelete
  20. If You Looking for top-quality Spy Audio Devices Prices in Delhi affordable price? Look no further than our extensive collection of audio surveillance tools, now available at prices as low as ₹999. Our devices with impressive features such as long battery life, easy recording capability, and reliable storage options. To get more information, Contact 9999332099 | 9999332499

    ReplyDelete
  21. If you are looking for the Top Famous Audio Spy Devices in India. Now available at unbeatable prices during our Summer Sale 2023. Don't miss out on this limited-time offer and equip yourself with the best audio spy devices in India at discounted prices.

    ReplyDelete
  22. Introducing our Best Hidden Voice Recorder, the option for cash on delivery, you can rely on a hassle-free purchasing experience. Trust this top brand to provide you with the utmost security and convenience. Order Now 9999332099

    ReplyDelete
  23. Super sale on spy shop online. Best Hidden Voice Recorder in India presents the world's smallest voice recorder available at wholesale & retail prices with free shipping all over India. Order now: Contact at 9999332499 | 9999332099

    ReplyDelete
  24. Nice blog! I appreciate you offering this useful blog.
    Go to our website:Audio Production Services in Delhi

    ReplyDelete
  25. Thanks a lot for sharing!
    Buy Spy Gadgets Online with Free Demo. Visit Spy Shop Online to buy spy gadgets online, including security cameras and other cutting-edge gadgets. Find the best spy gadgets to keep your spaces safe and secure. Shop now and protect what matters most!

    ReplyDelete

Post a Comment

Popular posts from this blog

Android Audio Tutorial [Part Three] : AudioFlinger Introduction and Initialization

Android External Storage Support: Volume Daemon (vold) Architecture