/* rdgen.c * * A WAV file generator for test tones * * (C) Copyright 1997-2003,2016 Fred Gleason * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define BUFFER_SIZE 16384 #define SAMPLE_RATE 48000 #define SAMPLE_SIZE 16 #define USAGE "rdgen [-f freq][-l level][-c left|right|both][-p now|rev][-t secs][-v] \n" int main(int argc,char *argv[]) { int i; int hFilename; unsigned char cBuffer[BUFFER_SIZE]; float fFreq=1000; float fLevel=0; float fRatio; int dChan=0; /* 0=Both, 1=Left, 2=Right */ char sChan[10]; int dPhase=0; /* 0=Normal, 1=Reverse */ char sPhase[10]; int dTime=0; int dMatch=0; int dDebug=0; int dSampleRate=0; char sFilename[128]; /* Name of audio device */ float fGain; float fAngle; unsigned long ldCount,ldTimeline=0,ldLimit=BUFFER_SIZE; short int dSample; time_t tmTimestamp,tmTime; struct wavHeader wavHeader; unsigned dBytes=0,dTotalBytes; if(argc<2) { printf(USAGE); exit(0); } if(argc==2) { if(strcmp(argv[1],"-v")==0) { printf("wavgen v"); printf(VERNUM); printf("\n"); exit(0); } } /* Get device name */ if(sscanf(argv[argc-1],"%s",sFilename)!=1) { printf("wavgen: invalid file anem\n"); exit(1); } /* Get options */ for(i=1;i0) { tmTimestamp+=dTime; } else { tmTimestamp--; } /* Output audio */ dTotalBytes=wavHeader.dwAvgBytesPerSec*dTime; switch(SAMPLE_SIZE) { case 8: fGain=127*fRatio; ldTimeline=0; ldLimit=BUFFER_SIZE/2; while(dBytes>8)); } else { cBuffer[i++]=0; cBuffer[i++]=0; } if(dChan==0 || dChan==2) { if(dPhase==1) { dSample=-dSample; } cBuffer[i++]=0xFF&dSample; cBuffer[i++]=(0xFF&(dSample>>8)); } else { cBuffer[i++]=0; cBuffer[i++]=0; } } write(hFilename,cBuffer,BUFFER_SIZE); dBytes+=BUFFER_SIZE; ldLimit+=(BUFFER_SIZE/4); ldTimeline+=(BUFFER_SIZE/4); time(&tmTime); } break; } /* close files and finish */ FixWav(hFilename,dBytes/wavHeader.wBlockAlign,dBytes); close(hFilename); exit(0); }