#include <stdio.h>
#include <linux/ioctl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/soundcard.h>
#include <stdlib.h>

#define BUF_SIZE 22050*10
int main(int argcchar **argvchar **envp) {
        int audio_fd;  
        struct {
                unsigned char data[2];
        } audio_buffer[BUF_SIZE];
        if ((audio_fd = open("/dev/dsp"O_RDONLY0)) == -1) {
                perror("/dev/dsp");  
                exit(0);
        } 
        {
                //Setting compression
                int format=AFMT_S16_LE;
                if (ioctl(audio_fdSNDCTL_DSP_SETFMT, &format)==-1) {
                        perror("SNDCTL_DSP_SETFMT");  
                        exit(-2);
                }  
                if (format != AFMT_S16_LE) {  
                        fprintf(stderr"Can't set compression format\n");
                        exit(-1);
                } 
        }
        {
                //Setting channels
                int stereo = 0;
                if (ioctl(audio_fdSNDCTL_DSP_STEREO, &stereo)==-1) {
                        perror("SNDCTL_DSP_STEREO");
                        exit(-3);
                }

                if (stereo != 0) {
                        fprintf(stderr"Can't set to mono\n");
                        exit(-4);
                }
        }
        {
                //Setting speed
                int speed = 22050;
                if (ioctl(audio_fdSNDCTL_DSP_SPEED, &speed)==-1) {
                        perror("SNDCTL_DSP_SPEED");  
                        exit(-4);
                }  
                 
                 if (speed != 22050) {
                        fprintf(stderr"Can't set speed\n");
                        exit(-5);
                }
        }
        while(1) {
                int len;  
                if ((len = read(audio_fdaudio_bufferBUF_SIZE)) == -1) {  
                        perror("audio read");  
                        exit(-9);  
                } 
        }
        return 0;
}