📄 dsp.c
字号:
/* * dsp.c * * Copyright (C) Vivien Chappelier - 2000 * * This file is part of fame, a free MPEG encoder. * * fame is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * fame is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * */#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <fcntl.h>#include <linux/soundcard.h>#include <sys/time.h>#include <sys/ioctl.h>#include <sys/mman.h>#include <pthread.h>#include "types.h"#include "dsp.h"input_dsp_context_t *dsp_init(void){ int format; int caps; audio_buf_info info; int i; input_dsp_context_t *dsp; dsp = (input_dsp_context_t *) malloc(sizeof(input_dsp_context_t)); if((dsp->fd = open("/dev/dsp", O_RDONLY)) < 0) { perror("/dev/dsp"); free(dsp); return(NULL); } /* Reset he DSP */ if(ioctl(dsp->fd, SNDCTL_DSP_RESET, 0) < 0) { perror("SNDCTL_DSP_RESET"); } /* Set 16 bit signed audio format */ i = AFMT_S16_LE; if(ioctl(dsp->fd, SNDCTL_DSP_SETFMT, &i) < 0) { perror("SNDCTL_DSP_SETFMT"); free(dsp); return(NULL); } /* Set mono */ i = 0; if(ioctl(dsp->fd, SNDCTL_DSP_STEREO, &i) < 0) { perror("SNDCTL_DSP_STEREO"); free(dsp); return(NULL); } /* Set frequency */ i = 44100; if(ioctl(dsp->fd, SNDCTL_DSP_SPEED, &i) < 0) { perror("SNDCTL_DSP_SPEED"); free(dsp); return(NULL); } return(dsp);}void dsp_close(input_dsp_context_t *dsp){ close(dsp->fd);}int dsp_read(input_dsp_context_t *dsp, void *buffer, int size) { return(read(dsp->fd, buffer, size));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -