📄 recplay.c
字号:
#include <stdio.h>#include <stdarg.h>#include <stdlib.h>#include <malloc.h>#include <string.h>#include <fcntl.h>#include <sys/stat.h>#include <linux/soundcard.h>#include "recplay.h"#include "def.h"#include "WAVfile.h"#include "DSPfile.h"/* * Play a series of WAV files: */intwavplay(char **argv) { WAVFILE *wfile; /* Opened wav file */ DSPFILE *dfile = NULL; /* Opened /dev/dsp device */ const char *Pathname; /* Pathname of the open WAV file */ if ( (Pathname = *argv) == NULL ) Pathname = "-"; /* Standard input */ else Pathname = *(argv++); /* Point to first pathname on command line */ /* * Play each Pathname: */ do { /* * Open the wav file for read, unless its stdin: */ if ( (wfile = WavOpenForRead(Pathname)) == NULL ) goto errxit; if ( (dfile = OpenDSP(wfile,O_WRONLY)) == NULL ) goto errxit; if ( PlayDSP(dfile,wfile) ) goto errxit; if ( CloseDSP(dfile) ) { /* Close /dev/dsp */ dfile = NULL; /* Mark it as closed */ goto errxit; } dfile = NULL; /* Mark it as closed */ if ( WavClose(wfile) ) /* Close the wav file */ wfile = NULL; /* Mark the file as closed */ wfile = NULL; /* Mark the file as closed */ } while ( (Pathname = *argv++) != NULL ); return 0; errxit: if ( wfile != NULL ) WavClose(wfile); /* Don't report errors here */ if ( dfile != NULL ) CloseDSP(dfile); /* Don't report errors here */ return -1;}/* * Record a WAV file: */intwavrecd(WavPlayOpts *wavopts,char *Pathname) { WAVFILE *wfile; /* Opened wav file */ DSPFILE *dfile = NULL; /* Opened /dev/dsp device */ UInt32 samples; /* The number of samples to record */ samples = (UInt32) wavopts->Seconds * (UInt32) wavopts->SamplingRate; /* * Open the wav file for read, unless its stdin: */ if ( (wfile = WavOpenForWrite(Pathname,wavopts->Channels, wavopts->SamplingRate,wavopts->DataBits,samples)) == NULL )goto errxit; if ( (dfile = OpenDSP(wfile,O_RDONLY)) == NULL ) goto errxit; if ( RecordDSP(dfile,wfile,samples) ) goto errxit; printf(" close record"); if ( CloseDSP(dfile) ) { /* Close /dev/dsp */ dfile = NULL; /* Mark it as closed */ goto errxit; } printf("record over!"); dfile = NULL; /* Mark it as closed */ WavClose(wfile); /* Close the wav file */ wfile = NULL; /* Mark the file as closed */ /* Indicate no open file now */ return 0; errxit: if ( wfile != NULL ) WavClose(wfile); if ( dfile != NULL ) CloseDSP(dfile); return -1;}/* $Source: /home/cvs/wavplay/recplay.c,v $ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -