Programming audio device instances in Linux

Source: Internet
Author: User
In the Linux operating system, program the audio device instance-Linux general technology-Linux programming and kernel information. The following is a detailed description. Programming for sound devices in Linux is much simpler than most people think. Generally, our commonly used sound devices are internal speakers and sound cards. They all correspond to one or more device files in the/dev directory. We open them like opening common files, use the ioctl () function to set some parameters and then perform write operations on these opened special files.

Because these files are not common files, we cannot use ansi c (Standard C) fopen, fclose, and so on to operate files, instead, you should use the system file I/O processing functions (open, read, write, lseek, and close) to process these device files. Ioctl () is perhaps the most complex function in Linux. It can control the attributes of various files. In Linux sound device programming, the most important thing is to use this function to correctly set necessary parameters.

The following two examples illustrate how to implement voice programming in Linux. Because this type of programming involves the reading and writing of system devices, you often need to have the root permission. If you fail to correctly execute the following example after compiling, first, check whether you are not authorized to manipulate a device.

Programming the internal speaker is part of the console, so the corresponding device file is/dev/console. The variable KIOCSOUND is declared in the header file/usr/include/linux/kd. h. The ioctl function can be used to control the speaker's voice. The usage rules are as follows:
QUOTE:

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.