Programming of audio device files in Linux

Source: Internet
Author: User
Tags usleep

1. Audio Device Files in Linux

/Dev/console: The device file related to the speaker.

 

/Dev/DSP: The device file related to the DSP on the sound card device. It provides digital sampling and digital recording functions. The sound card device converts analog and digital signals through DSP. Writing data to the device activates the digital-to-analog converter on the sound card to play the audio. Reading data from the device activates Analog-to-analog conversion on the Sound Card for recording.

 

/Dev/Audio: similar to/dev/DSP. The encoding method is Mu-Law.

 

/Dev/mixer: The software interface of the mixer in the sound card. It is used to combine or overlay multiple sound signals. The programming of the mixer includes how to set the gain and how to switch between different audio sources.

 

/Dev/sequencer: it is used to support the wave table synthesizer in The Sound Card and is mainly used in computer music software.

 

2. Instance

Example 1: Enable speaker

# Include <stdio. h> <br/> # include <stdlib. h> <br/> # include <unistd. h> <br/> # include <sys/types. h> <br/> # include <sys/STAT. h> <br/> # include <fcntl. h> <br/> # include <sys/IOCTL. h> <br/> # include <Linux/KD. h> </P> <p> # define speaker_device "/dev/console" </P> <p> int main (INT argc, char * argv []) <br/>{< br/> int FD; <br/> int freq; </P> <p> If (argc! = 2) <br/>{< br/> printf ("Usage: % s frequence/N", argv [0]); <br/> return 1; <br/>}</P> <p> freq = atoi (argv [1]); <br/> If (freq <= 0 | freq> 10000) <br/> {<br/> printf ("the frequence must be in the range from 0 to 10000. /n "); <br/> return 1; <br/>}</P> <p> FD = open (speaker_device, o_wronly ); </P> <p> If (FD =-1) <br/> {<br/> perror ("connot open device. /n "); <br/> return 1; <br/>}</P> <p> int I; <br/> int CNT; <br/> for (I = 0; I <1000; ++ I) <br/>{< br/> int set_freq = 1190000/freq; <br/> IOCTL (FD, kiocsound, set_freq); <br/> usleep (200); <br/> IOCTL (FD, kiocsound, 0 ); <br/> usleep (100); <br/>}< br/> return 0; <br/>}< br/>

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.