2005-12-22 11:40:53 -05:00
|
|
|
#include <stdio.h>
|
2006-01-09 16:30:35 -05:00
|
|
|
#include <portaudio.h>
|
2006-09-06 14:09:05 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
void fivehz_();
|
|
|
|
void fivehztx_();
|
|
|
|
void addnoise_(short int *n);
|
2005-12-22 11:40:53 -05:00
|
|
|
|
|
|
|
// Definition of structure pointing to the audio data
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
double *Tsec;
|
|
|
|
double *tbuf;
|
|
|
|
int *iwrite;
|
|
|
|
int *ibuf;
|
|
|
|
int *TxOK;
|
|
|
|
int *ndebug;
|
|
|
|
int *ndsec;
|
|
|
|
int *Transmitting;
|
|
|
|
int *nwave;
|
|
|
|
int *nmode;
|
|
|
|
int *trperiod;
|
|
|
|
int nbuflen;
|
|
|
|
int nfs;
|
|
|
|
short *y1;
|
|
|
|
short *y2;
|
|
|
|
short *iwave;
|
|
|
|
}
|
|
|
|
paTestData;
|
|
|
|
|
|
|
|
typedef struct _SYSTEMTIME
|
|
|
|
{
|
|
|
|
short Year;
|
|
|
|
short Month;
|
|
|
|
short DayOfWeek;
|
|
|
|
short Day;
|
|
|
|
short Hour;
|
|
|
|
short Minute;
|
|
|
|
short Second;
|
|
|
|
short Millisecond;
|
|
|
|
} SYSTEMTIME;
|
|
|
|
|
2006-01-09 16:30:35 -05:00
|
|
|
#ifdef Win32
|
2005-12-22 11:40:53 -05:00
|
|
|
extern void __stdcall GetSystemTime(SYSTEMTIME *st);
|
2006-01-09 16:30:35 -05:00
|
|
|
#else
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
void GetSystemTime(SYSTEMTIME *st){
|
|
|
|
struct timeval tmptimeofday;
|
|
|
|
struct tm tmptmtime;
|
|
|
|
gettimeofday(&tmptimeofday,NULL);
|
2006-09-23 17:01:09 -04:00
|
|
|
gmtime_r((const time_t *)&tmptimeofday.tv_sec,&tmptmtime);
|
2006-01-09 16:30:35 -05:00
|
|
|
st->Year = (short)tmptmtime.tm_year;
|
|
|
|
st->Month = (short)tmptmtime.tm_year;
|
|
|
|
st->DayOfWeek = (short)tmptmtime.tm_wday;
|
|
|
|
st->Day = (short)tmptmtime.tm_mday;
|
|
|
|
st->Hour = (short)tmptmtime.tm_hour;
|
|
|
|
st->Minute = (short)tmptmtime.tm_min;
|
|
|
|
st->Second = (short)tmptmtime.tm_sec;
|
|
|
|
st->Millisecond = (short)(tmptimeofday.tv_usec/1000);
|
|
|
|
}
|
|
|
|
#endif
|
2005-12-22 11:40:53 -05:00
|
|
|
|
|
|
|
// Output callback routine:
|
|
|
|
static int SoundOut( void *inputBuffer, void *outputBuffer,
|
|
|
|
unsigned long framesPerBuffer,
|
|
|
|
const PaStreamCallbackTimeInfo* timeInfo,
|
|
|
|
PaStreamCallbackFlags statusFlags,
|
|
|
|
void *userData )
|
|
|
|
{
|
|
|
|
paTestData *data = (paTestData*)userData;
|
|
|
|
short *wptr = (short*)outputBuffer;
|
|
|
|
unsigned int i,n;
|
2006-01-13 20:46:20 -05:00
|
|
|
static short int n2;
|
2005-12-22 11:40:53 -05:00
|
|
|
static int n0;
|
|
|
|
static int ia=0;
|
|
|
|
static int ib=0;
|
|
|
|
static int ic=0;
|
|
|
|
static int TxOKz=0;
|
|
|
|
static double stime0=86400.0;
|
|
|
|
int nsec;
|
|
|
|
double stime;
|
|
|
|
SYSTEMTIME st;
|
|
|
|
|
|
|
|
// Get System time
|
|
|
|
GetSystemTime(&st);
|
|
|
|
nsec = (int) (st.Hour*3600.0 + st.Minute*60.0 + st.Second);
|
|
|
|
stime = nsec + st.Millisecond*0.001 + *data->ndsec*0.1;
|
|
|
|
*data->Tsec = stime;
|
|
|
|
nsec=(int)stime;
|
|
|
|
|
|
|
|
if(*data->TxOK && (!TxOKz)) {
|
|
|
|
n=nsec/(*data->trperiod);
|
|
|
|
// ic = (int)(stime - *data->trperiod*n) * data->nfs/framesPerBuffer;
|
|
|
|
// ic = framesPerBuffer*ic;
|
|
|
|
ic = (int)(stime - *data->trperiod*n) * data->nfs;
|
|
|
|
ic = ic % *data->nwave;
|
|
|
|
}
|
|
|
|
|
|
|
|
TxOKz=*data->TxOK;
|
|
|
|
*data->Transmitting=*data->TxOK;
|
|
|
|
|
2006-01-15 21:02:46 -05:00
|
|
|
if(*data->TxOK) {
|
|
|
|
for(i=0 ; i<framesPerBuffer; i++ ) {
|
2006-01-13 20:46:20 -05:00
|
|
|
n2=data->iwave[ic];
|
|
|
|
addnoise_(&n2);
|
|
|
|
*wptr++ = n2; //left
|
|
|
|
*wptr++ = n2; //right
|
2005-12-22 11:40:53 -05:00
|
|
|
ic++;
|
|
|
|
if(ic>=*data->nwave) {
|
2006-01-16 11:39:11 -05:00
|
|
|
if(*data->nmode==2) {
|
2005-12-22 11:40:53 -05:00
|
|
|
*data->TxOK=0;
|
2006-01-16 11:39:11 -05:00
|
|
|
ic--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ic = ic % *data->nwave; //Wrap buffer pointer if necessary
|
2005-12-22 11:40:53 -05:00
|
|
|
}
|
|
|
|
}
|
2006-01-15 21:02:46 -05:00
|
|
|
} else {
|
2006-01-16 11:39:11 -05:00
|
|
|
memset((void*)outputBuffer, 0, 2*sizeof(short)*framesPerBuffer);
|
2005-12-22 11:40:53 -05:00
|
|
|
}
|
2007-01-09 12:46:02 -05:00
|
|
|
fivehz_(); //Call fortran routine
|
2005-12-22 11:40:53 -05:00
|
|
|
fivehztx_(); //Call fortran routine
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
int jtaudio_(int *ndevin, int *ndevout, short y1[], short y2[],
|
|
|
|
int *nbuflen, int *iwrite, short iwave[],
|
|
|
|
int *nwave, int *nfsample, int *nsamperbuf,
|
|
|
|
int *TRPeriod, int *TxOK, int *ndebug,
|
|
|
|
int *Transmitting, double *Tsec, int *ngo, int *nmode,
|
|
|
|
double tbuf[], int *ibuf, int *ndsec)
|
|
|
|
{
|
|
|
|
paTestData data;
|
|
|
|
PaStream *outstream;
|
|
|
|
PaStreamParameters outputParameters;
|
|
|
|
|
2006-09-06 14:09:05 -04:00
|
|
|
int nfs,ndin,ndout;
|
2005-12-22 11:40:53 -05:00
|
|
|
PaError err1,err2,err2a,err3,err3a;
|
|
|
|
double dnfs;
|
|
|
|
|
|
|
|
data.Tsec = Tsec;
|
|
|
|
data.tbuf = tbuf;
|
|
|
|
data.iwrite = iwrite;
|
|
|
|
data.ibuf = ibuf;
|
|
|
|
data.TxOK = TxOK;
|
|
|
|
data.ndebug = ndebug;
|
|
|
|
data.ndsec = ndsec;
|
|
|
|
data.Transmitting = Transmitting;
|
|
|
|
data.y1 = y1;
|
|
|
|
data.y2 = y2;
|
|
|
|
data.nbuflen = *nbuflen;
|
|
|
|
data.nmode = nmode;
|
|
|
|
data.nwave = nwave;
|
|
|
|
data.iwave = iwave;
|
|
|
|
data.nfs = *nfsample;
|
|
|
|
data.trperiod = TRPeriod;
|
|
|
|
|
|
|
|
nfs=*nfsample;
|
|
|
|
err1=Pa_Initialize(); // Initialize PortAudio
|
|
|
|
if(err1) {
|
|
|
|
printf("Error initializing PortAudio.\n");
|
|
|
|
printf("%s\n",Pa_GetErrorText(err1));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
ndin=*ndevin;
|
|
|
|
ndout=*ndevout;
|
|
|
|
dnfs=(double)nfs;
|
2007-01-09 12:08:45 -05:00
|
|
|
printf("Opening device %d for output.\n",ndout);
|
2005-12-22 11:40:53 -05:00
|
|
|
|
|
|
|
outputParameters.device=*ndevout;
|
|
|
|
outputParameters.channelCount=2;
|
|
|
|
outputParameters.sampleFormat=paInt16;
|
2006-01-06 11:06:57 -05:00
|
|
|
outputParameters.suggestedLatency=1.0;
|
2005-12-22 11:40:53 -05:00
|
|
|
outputParameters.hostApiSpecificStreamInfo=NULL;
|
|
|
|
err2a=Pa_OpenStream(
|
|
|
|
&outstream, //address of stream
|
|
|
|
NULL,
|
|
|
|
&outputParameters,
|
|
|
|
dnfs, //Sample rate
|
|
|
|
2048, //Frames per buffer
|
|
|
|
paNoFlag,
|
|
|
|
SoundOut, //Callback routine
|
|
|
|
&data); //address of data structure
|
|
|
|
if(err2a) {
|
|
|
|
printf("Error opening Audio stream for output.\n");
|
|
|
|
printf("%s\n",Pa_GetErrorText(err2a));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
err3a=Pa_StartStream(outstream); //Start output stream
|
|
|
|
if(err3a) {
|
|
|
|
printf("Error starting output Audio stream\n");
|
|
|
|
printf("%s\n",Pa_GetErrorText(err3a));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2007-01-09 12:08:45 -05:00
|
|
|
printf("Audio output stream running normally.\n******************************************************************\n");
|
2005-12-22 11:40:53 -05:00
|
|
|
|
2007-01-09 12:08:45 -05:00
|
|
|
while(Pa_IsStreamActive(outstream)) {
|
2005-12-22 11:40:53 -05:00
|
|
|
if(*ngo==0) goto StopStream;
|
|
|
|
Pa_Sleep(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
StopStream:
|
|
|
|
Pa_AbortStream(outstream); // Abort stream
|
|
|
|
Pa_CloseStream(outstream); // Close stream, we're done.
|
|
|
|
Pa_Terminate();
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
error:
|
2007-01-09 12:08:45 -05:00
|
|
|
printf("%d %f %d %d %d\n",ndout,dnfs,err1,err2a,err3a);
|
2005-12-22 11:40:53 -05:00
|
|
|
Pa_Terminate();
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int padevsub_(int *numdev, int *ndefin, int *ndefout,
|
|
|
|
int nchin[], int nchout[])
|
|
|
|
{
|
2006-09-06 14:09:05 -04:00
|
|
|
int i;
|
2005-12-22 11:40:53 -05:00
|
|
|
int numDevices;
|
|
|
|
const PaDeviceInfo *pdi;
|
|
|
|
PaError err;
|
2006-09-06 14:09:05 -04:00
|
|
|
// PaHostApiInfo *hostapi;
|
2005-12-22 11:40:53 -05:00
|
|
|
|
|
|
|
Pa_Initialize();
|
|
|
|
|
|
|
|
// numDevices = Pa_CountDevices();
|
|
|
|
numDevices = Pa_GetDeviceCount();
|
|
|
|
*numdev=numDevices;
|
|
|
|
if( numDevices < 0 ) {
|
|
|
|
err = numDevices;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-12 12:57:41 -05:00
|
|
|
printf("\nAudio Output Device Name\n");
|
|
|
|
printf("Device Channels\n");
|
|
|
|
printf("----------------------------------------------------------\n");
|
2005-12-22 11:40:53 -05:00
|
|
|
|
|
|
|
for( i=0; i<numDevices; i++ ) {
|
|
|
|
pdi = Pa_GetDeviceInfo( i );
|
|
|
|
if(i == Pa_GetDefaultInputDevice()) *ndefin=i;
|
|
|
|
if(i == Pa_GetDefaultOutputDevice()) *ndefout=i;
|
|
|
|
nchin[i]=pdi->maxInputChannels;
|
|
|
|
nchout[i]=pdi->maxOutputChannels;
|
2007-01-12 12:57:41 -05:00
|
|
|
if(nchin[i]>0)
|
|
|
|
printf(" %2d %2d %s\n",i,nchout[i],pdi->name);
|
2005-12-22 11:40:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Pa_Terminate();
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
Pa_Terminate();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|