Initial import of CVS-v2_8_branch

This commit is contained in:
Fred Gleason
2014-08-12 15:13:02 -04:00
commit afd67c7af8
1508 changed files with 405304 additions and 0 deletions

50
utils/rdgen/Makefile.am Normal file
View File

@@ -0,0 +1,50 @@
## automake.am
##
## Automake.am for rivendell/utils/rdgen
##
## (C) Copyright 2002-2006 Fred Gleason <fredg@paravelsystems.com>
##
## $Id: Makefile.am,v 1.6.8.1 2012/11/29 01:37:38 cvs Exp $
##
## 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.
##
## Use automake to process this into a Makefile.in
AM_CPPFLAGS = -Wall -DPREFIX=\"$(prefix)\" -DQTDIR=\"@QT_DIR@\" @QT_CXXFLAGS@
INCLUDES = -I$(top_srcdir)/lib
LIBS = @QT_LIBS@ -L$(top_srcdir)/lib
MOC = @QT_MOC@
# The dependency for qt's Meta Object Compiler (moc)
moc_%.cpp: %.h
$(MOC) $< -o $@
bin_PROGRAMS = rdgen
dist_rdgen_SOURCES = rdgen.c\
wavlib.c wavlib.h
rdgen_LDADD = -lm
CLEANFILES = *~\
*.idb\
*ilk\
*.obj\
*.pdb\
*.qm\
moc_*
MAINTAINERCLEANFILES = *~\
Makefile.in\
moc_*

317
utils/rdgen/rdgen.c Normal file
View File

@@ -0,0 +1,317 @@
/* rdgen.c
*
* A WAV file generator for test tones
*
* (C) Copyright 1997-2003 Fred Gleason <fredg@paravelsystems.com>
*
* $Id: rdgen.c,v 1.4 2010/07/29 19:32:40 cvs Exp $
*
* 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 <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <sys/soundcard.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <math.h>
#include <time.h>
#include <wavlib.h>
#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] <wavfile>\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;i<argc-1;i++) {
dMatch=0;
if(strcmp(argv[i],"-v")==0) { /* Version */
printf("wavgen v");
printf(VERNUM);
printf("\n");
exit(0);
}
if(strcmp(argv[i],"-d")==0) { /* Debug Mode */
dMatch=1;
dDebug=1;
}
if(strcmp(argv[i],"-f")==0) { /* Frequency */
dMatch=1;
if(sscanf(argv[++i],"%f",&fFreq)!=1) {
printf("wavgen: invalid frequency\n");
exit(1);
}
}
if(strcmp(argv[i],"-l")==0) { /* Level */
dMatch=1;
if(sscanf(argv[++i],"%f",&fLevel)!=1) {
printf("wavgen: invalid level\n");
exit(1);
}
fLevel=-fLevel;
}
if(strcmp(argv[i],"-t")==0) { /* Time */
dMatch=1;
if(sscanf(argv[++i],"%d",&dTime)!=1) {
printf("wavgen: invalid time interval\n");
exit(1);
}
}
if(strcmp(argv[i],"-c")==0) { /* Channel */
dMatch=1;
if(sscanf(argv[++i],"%s",sChan)!=1) {
printf("wavgen: invalid time interval\n");
exit(1);
}
if(strcasecmp(sChan,"both")==0) {
dChan=0;
}
else {
if(strcasecmp(sChan,"left")==0) {
dChan=1;
}
else {
if(strcasecmp(sChan,"right")==0) {
dChan=2;
}
else {
printf("wavgen: invalid channel\n");
exit(1);
}
}
}
}
if(strcmp(argv[i],"-p")==0) { /* Phase */
dMatch=1;
if(sscanf(argv[++i],"%s",sPhase)!=1) {
printf("wavgen: invalid phase setting\n");
exit(1);
}
if(strcasecmp(sPhase,"norm")==0) {
dPhase=0;
}
else {
if(strcasecmp(sPhase,"rev")==0) {
dPhase=1;
}
else {
printf("wavgen: invalid phase setting\n");
exit(1);
}
}
}
if(dMatch==0) {
printf("wavgen: invalid option\n");
exit(1);
}
if(dTime==0) {
printf("wavgen: missing time argument\n");
exit(1);
}
}
/* Convert db to ratio */
fRatio=pow(10,(fLevel/20));
/* Set audio characteristics */
wavHeader.wFormatTag=WAVE_FORMAT_PCM;
wavHeader.wChannels=2;
wavHeader.dwSamplesPerSec=SAMPLE_RATE;
wavHeader.dwAvgBytesPerSec=SAMPLE_RATE*(SAMPLE_SIZE/8)*2;
wavHeader.wBlockAlign=SAMPLE_SIZE/4;
wavHeader.wBitsPerSample=SAMPLE_SIZE;
/* Open the wav file */
hFilename=CreateWav(sFilename,&wavHeader);
if(hFilename<0) {
printf("wavgen: can't open wav file\n");
exit(1);
}
/* Display Settings (if requested) */
if(dDebug==1) {
printf("--Audio Generator Settings--\n");
printf("Frequency: %5.0f Hz\n",fFreq);
printf("Level: %3.1f dB\n",fLevel);
printf("Channel(s): ");
switch(dChan) {
case 0:
printf("BOTH\n");
break;
case 1:
printf("LEFT\n");
break;
case 2:
printf("RIGHT\n");
break;
}
printf("Phasing: ");
switch(dPhase) {
case 0:
printf("NORMAL\n");
break;
case 1:
printf("REVERSE\n");
break;
}
printf("Effective Sample Rate: %d samples/sec\n",dSampleRate);
}
/* Setup time data */
time(&tmTimestamp);
tmTime=tmTimestamp;
if(dTime>0) {
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<dTotalBytes) {
i=0;
for(ldCount=ldTimeline;ldCount<ldLimit;ldCount++) {
fAngle=2*PI*ldCount*fFreq/SAMPLE_RATE;
if(dChan==0 || dChan==1) {
cBuffer[i++]=fGain*sin(fAngle)+128;
}
else {
cBuffer[i++]=128;
}
if(dChan==0 || dChan==2) {
if(dPhase==0) {
cBuffer[i++]=fGain*sin(fAngle)+128;
}
else {
cBuffer[i++]=-fGain*sin(fAngle)+128;
}
}
else {
cBuffer[i++]=128;
}
}
write(hFilename,cBuffer,BUFFER_SIZE);
dBytes+=BUFFER_SIZE;
ldLimit+=(BUFFER_SIZE/2);
ldTimeline+=(BUFFER_SIZE/2);
time(&tmTime);
}
break;
case 16:
fGain=32767*fRatio;
ldTimeline=0;
ldLimit=BUFFER_SIZE/4;
while(dBytes<dTotalBytes) {
i=0;
for(ldCount=ldTimeline;ldCount<ldLimit;ldCount++) {
fAngle=2*PI*ldCount*fFreq/SAMPLE_RATE;
dSample=fGain*sin(fAngle);
if(dChan==0 || dChan==1) {
cBuffer[i++]=0xFF&dSample;
cBuffer[i++]=(0xFF&(dSample>>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);
}

1187
utils/rdgen/wavlib.c Normal file

File diff suppressed because it is too large Load Diff

172
utils/rdgen/wavlib.h Normal file
View File

@@ -0,0 +1,172 @@
/* wavlib.h
*
* A C Library for abstracting WAV files
*
* (C) Copyright 1997,1999-2003 Fred Gleason <fredg@paravelsystems.com>
*
* $Id: wavlib.h,v 1.4 2007/02/14 21:59:12 fredg Exp $
*
* 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.
*
*/
/*
* The package version number
*/
#define VERNUM "2.4.2"
#ifndef _UNISTD_H
#include <unistd.h>
#endif
#ifndef _TIME_H
#include <sys/time.h>
#endif
#ifndef PI
#define PI 3.1415928
#endif
#define AUDIO_BUFFER 32768
/*
* Some basic values
*/
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
/*
* Aliases for backward compatibility. Use of these names is deprecated.
*/
#define PlayWav PlayWavFile
#define RecWav RecWavFile
#define SoundConfig SoundConfigFile
/* Data Structures */
struct wavHeader {
unsigned short wFormatTag; /* Format Category */
unsigned short wChannels; /* Number of Audio Channels */
int dwSamplesPerSec; /* Samples/sec/channel */
int dwAvgBytesPerSec; /* Average Bytes per Second Overall */
unsigned short wBlockAlign; /* Data Block Size */
unsigned short wBitsPerSample; /* Sample Size */
int dwWaveDataSize; /* Data Chunk Length */
unsigned dwFileSize; /* Number of Audio Samples */
time_t tWavLength; /* Length of Audio in seconds */
};
struct wavChunk {
char sName[5]; /* Chunk Name */
off_t oOffset; /* Offset to start of chunk */
off_t oSize; /* Size of chunk */
};
struct wavProcess {
double dfThreshold; /* Audio Detect Threshold, in in dBd */
int dSenseTimeout; /* Audio Detect Timeout, in secs */
double dfNormalLevel; /* Normalize Level, in dBd */
};
#define LIST_SIZE 256
struct wavList {
/* STANDARD SCHEME */ /* BDCST SCHEME */
char sIcrd[LIST_SIZE]; /* Creation Date */ /* Not Present */
char sIart[LIST_SIZE]; /* Original Artist */ /* Advertiser */
char sIcmt[LIST_SIZE]; /* Comments */ /* Comments */
char sIcop[LIST_SIZE]; /* Copyright */ /* Agency */
char sIeng[LIST_SIZE]; /* Engineer */ /* Producer */
char sIgnr[LIST_SIZE]; /* Genre */ /* Start Date */
char sIkey[LIST_SIZE]; /* Key Words */ /* End Date */
char sImed[LIST_SIZE]; /* Original Medium */ /* ???? */
char sInam[LIST_SIZE]; /* Name */ /* Outcue */
char sIsft[LIST_SIZE]; /* Software Package */ /* Account Exec. */
char sIsrc[LIST_SIZE]; /* Source Supplier */ /* Category */
char sItch[LIST_SIZE]; /* Digitizer */ /* Talent */
char sIsbj[LIST_SIZE]; /* Subject */ /* Copy */
char sIsrf[LIST_SIZE]; /* Digitization Source */ /* ???? */
};
/*
* Function Prototypes
*
* API Entry Points
*/
extern int IsWav(int);
extern int OpenWav(char *,struct wavHeader *);
extern int CreateWav(char *,struct wavHeader *);
extern int FixWav(int,unsigned,unsigned);
extern int FindChunk(int,struct wavChunk *);
extern int GetNextChunk(int,struct wavChunk *);
extern int GetListChunk(int,struct wavList *);
extern int SetDspDesc(int,struct wavHeader *);
extern int PlayWavFile(char *,char *,unsigned);
extern int PlayWavDesc(char *,int,unsigned);
extern int PlayWavOffsetDesc(char *,int,int,unsigned);
extern int RecWavFile(char *,char *,unsigned,unsigned short,unsigned,
unsigned short,unsigned);
extern int RecordWavFile(char *,char *,int,struct wavHeader *,
struct wavProcess *,unsigned);
extern int RecWavDesc(char *,int,unsigned,unsigned short,unsigned,
unsigned short,unsigned);
extern int RecordWavDesc(char *,int,int,struct wavHeader *,
struct wavProcess *,unsigned);
extern double DbToLinear(double);
extern double LinearToDb(double);
extern int GetMixerCat(char *,int,unsigned);
extern int Pattern(int,char *);
extern int SoundConfigFile(char *,int,int);
extern int SoundConfigDesc(int,int,int);
extern ssize_t WriteSword(int,unsigned);
extern ssize_t WriteDword(int,unsigned);
extern int TailTrim(char *,int);
extern int TruncWav(int,struct wavHeader *,struct wavChunk *,unsigned);
/*
* Signal Handlers
*/
extern void SigStopWav(int);
extern void SigPauseWav(int);
extern void SigResumeWav(int);
/* Microsoft WAVE Format Categories */
#define WAVE_FORMAT_PCM 0x0001
#define IBM_FORMAT_MULAW 0x0101
#define IBM_FORMAT_ALAW 0x0102
#define IBM_FORMAT_ADPCM 0x0103
/*
* Option Values
*
* WAVLIB_TEST will cause the function to do everything it ordinarily
* would except actually play the file. Useful for testing to see if
* a particular format is supported by a device.
*/
#define WAVLIB_TEST 0x40000000
/*
* WAVLIB_PAUSEABLE enables audio to be paused by sending SIGUSR1 to the
* process and then resumed by sending SIGUSR2.
*/
#define WAVLIB_PAUSEABLE 0x20000000