Android system development (9)-Prepare for audio and port ALSA

Source: Internet
Author: User

1. Development of the audio kernel, including the codec driver, CPU sound driver, and kernel ALSA driver,
This is completely embedded Linux development content. skip this step. Make sure these parts are correct.

2, download the latest alsa-lib-1.0.23 and alsa-utils-1.0.23 from ALSA Official Website
Http://www.alsa-project.org
ALSA-lib is based on the kernel ALSA driver. It encapsulates operations on the kernel ALSA interface into the libasound library.
ALSA-utils is a toolkit that controls the underlying ALSA Driver Based on ALSA-lib, including tools such as aplay, amixer, and control.
ALSA's system architecture is as follows:
ALSA Application
|
ALSA-utils
|
ALSA-lib
|
ALSA-driver
The ALSA-driver has been integrated into the Linux kernel. the Alsa application directly calls the Alsa-utils toolkit tool to control the underlying driver and operate the sound card.

3, create an ALSA directory under the vendor/ardent/Merlin directory, and then download the alsa-lib-1.0.23 and alsa-utils-1.0.23
Decompress the package to the Alsa directory, and change the unzipped folder version to ALSA-lib and ALSA-utils.

4. Add the following content to the file vendor/ardent/MERLIN/androidboard. mk:
Rochelle path: = $ (local_path)
Include $ (l_path)/ALSA/mdroid. mk

5. Create the mdroid. mk file in the vendor/ardent/MERLIN/ALSA directory. The content is as follows:
Local_path: = $ (call my-DIR)
Include $ (clear_vars)
Alsa_path: = $ (local_path)
Include $ (alsa_path)/ALSA-lib/mdroid. mk
Include $ (alsa_path)/ALSA-utils/mdroid. mk

6. Create the mdroid. mk file in the directory vendor/ardent/MERLIN/ALSA-Lib. The content is as follows:
Local_path: = $ (call my-DIR)
Include $ (clear_vars)
Include $ (local_path)/src/mdroid. mk

7. Create the mdroid. mk file in the directory vendor/ardent/MERLIN/ALSA-lib/src.

Note: ALSA-lib has a lot of compilation content. We can first compile ALSA-lib as a normal Linux library. After compilation, we can find the lo file.
Find the C files to be compiled and use make install to find the libraries and other files to be copied in the specified directory. Code
Many of them are not required. Currently, no detailed processing is performed. The contents in the Alsa-lib/modules/mixer/simple directory are compiled into several other
Dynamic library (smixer-ac97, smixer-hda.so, smixer-sbase.so), content under the Alsa-lib/aserver directory compiled into aserver,
These two parts are not used, so they are not added to the android compilation system.

8. Find a directory and compile ALSA-lib as a normal Linux library. The config. h file will be generated under the include directory, and the file will be copied
The content of config. h under the vendor/ardent/MERLIN/ALSA-lib/include directory is modified as follows:
# Define aload_device_directory "/dev/snd"
# Define alsa_config_dir "/etc"
# Define alsa_device_directory "/dev/snd /"
// # Define have_wordexp_h 1
// # Define versioned_symbols

9. Modify the Alsa-lib/include/global. h file and delete the following content:
# If! Defined (_ posix_c_source )&&! Defined (_ posix_source)
Struct timeval {
Time_t TV _sec;/* seconds */
Long TV _usec;/* microseconds */
};

Struct timespec {
Time_t TV _sec;/* seconds */
Long TV _nsec;/* nanoseconds */
};
# Endif

10.
# Include <sys/SHM. h>
Change
# Include <Linux/SHM. h>
Similar
# Include <sys/SEM. h>
Change
# Include <Linux/SEM. h>

11. Modify ALSA-lib/src/alisp. C and add the following content at the end of the obj_type_str function:
Return NULL;

12. Compile ALSA-lib into the ctl_symbols_list.c file and
Copy the pcm_symbols_list.c file generated under the Alsa-lib/src/PCM directory to the corresponding location of ALSA-Lib in Android.

13. Modify the Alsa-lib/src/PCM/pcm_direct.c file and delete the following content:
Union semun {
Int val;/* value for setval */
Struct semid_ds * Buf;/* buffer for ipc_stat, ipc_set */
Unsigned short * array;/* array for getall, setall */
Struct seminfo * _ Buf;/* buffer for ipc_info (Linux specific )*/
};

14. Find all ALSA-lib source code files to ensure
# Before include <Linux/SHM. h>
# Include <stdlib. h>
If you do not have one, the system reports an error saying size_t is not defined.

15. Modify the Alsa-lib/src/PCM/pcm_ladspa.c file and set
* Strrchr (labellocale, '.') = * LC-> decimal_point;
Change
* Strrchr (labellocale, '.') = ".";
Block the following content:
// Lc = localeconv ();
This is because the C library used by Android is bionic. Unlike the Standard C library, the lconv struct definition in the locale. h file is different.

16. Modify the snd_pcm_mmap function in the Alsa-lib/src/PCM/pcm_mmap.c file and copy the content of the snd_pcm_area_shm branch under the switch (I-> type) statement.
Block, modify the snd_pcm_munmap function in the file, and block the snd_pcm_area_shm branch content under the switch (I-> type) statement.

17. Search all the files in the Alsa-lib/src directory, search for the calls of four functions, including shmctl, shmget, shmat, and shmdt, and delete the called places.
This is mainly because the android bionic libc library does not support system v ipc. You can see the details from the file. System v ipc through sharing
The gnu c library corresponds to the/usr/include/sys/SHM. h file of the Linux PC shared memory header file. In this file, you can see
Declaration of four functions, including shmctl, shmget, shmat, and shmdt. The bionic libc library also has the same header file in the android source code directory
Bionic/libc/kernel/common/Linux directory, but the content in the file does not have the Declaration of the above four functions. The modification made above 16 is also based on this reason.

18. According to the conclusions of 16 and 17, due to the lack of System v ipc functions caused by bionic libc, the related functions in the Alsa library cannot be implemented normally, so the best
To avoid unnecessary errors, do not compile the relevant parts. Delete some files from compilation and modify the Alsa-lib/src/mdroid. mk file.
ALSA-lib/src/control/control_shm.c
ALSA-lib/src/PCM/pcm_direct.c
ALSA-lib/src/PCM/pcm_dmix.c
ALSA-lib/src/PCM/pcm_d316.c
ALSA-lib/src/PCM/pcm_dsnoop.c
ALSA-lib/src/PCM/pcm_ladspa.c
ALSA-lib/src/PCM/pcm_shm.c
ALSA-lib/src/shmarea. c
After these modules are deleted, the ctl_symbols_list.c file under the Alsa-lib/src/control directory and
Delete the relevant content in the pcm_symbols_list.c file under the Alsa-lib/src/PCM directory. Otherwise, the compilation will fail.

19. The final function to be implemented is to copy the configuration file of ALSA-Lib. In the Alsa-lib/src/conf directory, the copy operation is performed in ALSA-lib/src/mdroid. MK implementation,
The final mdroid. mk file content is as follows:
Local_path: = $ (call my-DIR)
Include $ (clear_vars)
Local_src_files: =/
Async. c Conf. c confmisc. c dlmisc. c error. c input. c/
Names. c output. c socket. c userfile. c/
Alisp/alisp. c/
Control/cards. c control/control. c control/control_ext.c/
Control/control_hsf-c control/control_symbols.c/
Control/hcontrol. c control/namehint. c control/setup. c control/TLV. c/
Hwdep/hwdep. c hwdep/hwdep_h1_c hwdep/hwdep_symbols.c/
Mixer/bag. c mixer/mixer. c mixer/simple. c mixer/simple_abst.c mixer/simple_none.c/
PCM/Atomic. c PCM/interval. c PCM/mask. c PCM/PCM. c PCM/pcm_adpcm.c/
PCM/pcm_alaw.c PCM/pcm_asym.c PCM/pcm_copy.c PCM/pcm_empty.c/
PCM/pcm_extplug.c PCM/pcm_file.c PCM/pcm_generic.c PCM/pcm_hooks.c/
PCM/pcm_h1_c PCM/pcm_iec958.c PCM/pcm_ioplug.c/
PCM/pcm_lfloat.c PCM/pcm_linear.c PCM/pcm_meter.c PCM/pcm_misc.c/
PCM/pcm_mmap.c PCM/pcm_mmap_emul.c PCM/pcm_mulaw.c PCM/pcm_multi.c/
PCM/pcm_null.c PCM/pcm_params.c PCM/pcm_plug.c PCM/pcm_plugin.c/
PCM/pcm_rate.c PCM/pcm_rate_linear.c PCM/pcm_route.c PCM/pcm_rou.c/
PCM/pcm_simple.c PCM/pcm_softvol.c PCM/pcm_symbols.c/
Rawmidi/rawmidi. c rawmidi/rawmidi_hsf-c rawmidi/rawmidi_symbols.c/
Rawmidi/rawmidi_virt.c/
SEQ/seq. c seq/seq_event.c seq/seq_h1_c seq/seqmid. c/
SEQ/seq_midi_event.c seq/seq_old.c seq/seq_symbols.c/
Timer/Timer. c Timer/timer_h1_c Timer/timer_query.c/
Timer/timer_query_hsf-c Timer/timer_symbols.c

Local_c_includes + =/
$ (Local_path)/../include

Local_shared_libraries: = libdl

Local_arm_mode: = arm

Local_prelink_module: = false
Local_module: = libasound
Include $ (build_shared_library)

Target_alsa_conf_dir: = $ (target_out)/usr/share/ALSA
Local_alsa_conf_dir: = $ (local_path)/Conf

Copy_from: =/
ALSA. CONF/
PCM/dsnoop. CONF/
PCM/MODEM. CONF/
PCM/DPL. CONF/
PCM/Default. CONF/
PCM/surround51.conf/
PCM/surround41.conf/
PCM/surround50.conf/
PCM/dmix. CONF/
PCM/center_lfe.conf/
PCM/surround40.conf/
PCM/side. CONF/
PCM/iec958.conf/
PCM/rear. CONF/
PCM/surround71.conf/
PCM/front. CONF/
Cards/aliases. conf

Copy_to: = $ (addprefix $ (target_alsa_conf_dir)/, $ (copy_from ))
Copy_from: = $ (addprefix $ (local_alsa_conf_dir)/, $ (copy_from ))

$ (Copy_to): $ (target_alsa_conf_dir)/%: $ (local_alsa_conf_dir)/% | $ (ACP)
$ (Transform-prebuilt-to-target)

All_prebuilt + = $ (copy_to)

20. The porting method of ALSA-utils is similar. We will not introduce it here. The above process is just a try of porting the Open Source library in Android,
In fact, ALSA code already exists on the Google server and can be downloaded directly. The download method is as follows:
Git clone git: // android.git.kernel.org/platform/external/alsa-lib.git
Git clone git: // android.git.kernel.org/platform/external/alsa-utils.git
Copy the downloaded ALSA-lib and ALSA-utils parts to the vendor/ardent/MERLIN/ALSA directory.
The 4 and 5 sections can be slightly modified.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.