pull/27/head
jnk 0le 2016-07-11 23:22:01 +02:00
rodzic 994d805596
commit 64f3664d88
13 zmienionych plików z 2029 dodań i 2287 usunięć

Wyświetl plik

@ -15,20 +15,22 @@
#include <math.h>
#include <sndfile.h>
#define ln(x) (log(x)/log(2.718281828459045235f))
#define BUFFER_LEN 1024*8
#define ln(x) (log(x)/log(2.718281828459045235f))
#define BUFFER_LEN 1024*8
int FileFreqTiming;
// Test program using SNDFILE
// see http://www.mega-nerd.com/libsndfile/api.html for API
void WriteTone(double Frequency,uint32_t Timing)
{
typedef struct {
typedef struct {
double Frequency;
uint32_t WaitForThisSample;
} samplerf_t;
samplerf_t RfSample;
RfSample.Frequency=Frequency;
RfSample.WaitForThisSample=Timing; //en 100 de nanosecond
//printf("Freq =%f Timing=%d\n",RfSample.Frequency,RfSample.WaitForThisSample);
@ -54,51 +56,48 @@ int main(int argc, char **argv) {
printf("Usage : %s in.wav [out.wav]\n", argv[0]);
return(1);
}
infilename = argv[1] ;
infilename = argv[1];
if( argc == 3 ) {
outfilename = argv[2] ;
outfilename = argv[2];
} else {
outfilename = (char *)malloc( 128 );
sprintf( outfilename, "%s", "out.ft");
}
if (! (infile = sf_open (infilename, SFM_READ, &sfinfo)))
{ /* Open failed so print an error message. */
printf ("Not able to open input file %s.\n", infilename) ;
printf ("Not able to open input file %s.\n", infilename);
/* Print the error message from libsndfile. */
puts (sf_strerror (NULL)) ;
return 1 ;
} ;
puts (sf_strerror (NULL));
return 1;
}
if( sfinfo.samplerate != 48000 ) {
printf("Input rate must be 48K.\n");
return 1 ;
return 1;
}
FileFreqTiming = open(outfilename, O_WRONLY|O_CREAT, 0644);
/** **/
printf ("Reading file : %s\n", infilename ) ;
printf ("Sample Rate : %d\n", sfinfo.samplerate) ;
printf ("Channels : %d\n", sfinfo.channels) ;
printf ("----------------------------------------\n") ;
printf ("Writing file : %s\n", outfilename ) ;
printf ("Reading file : %s\n", infilename );
printf ("Sample Rate : %d\n", sfinfo.samplerate);
printf ("Channels : %d\n", sfinfo.channels);
printf ("----------------------------------------\n");
printf ("Writing file : %s\n", outfilename );
/* While there are.frames in the input file, read them, process
/* While there are.frames in the input file, read them, process
** them and write them to the output file.
*/
while ((readcount = sf_readf_float(infile, data, BUFFER_LEN)))
{
nb_samples = readcount / sfinfo.channels ;
nb_samples = readcount / sfinfo.channels;
for( k=0 ; k < nb_samples ; k++ ) {
x = data[k*sfinfo.channels] ;
x = data[k*sfinfo.channels];
if( sfinfo.channels == 2 ) {
// stereo file, avg left + right
x += data[k*sfinfo.channels+1] ;
x /= 2 ;
x += data[k*sfinfo.channels+1];
x /= 2;
}
//printf("%f \n",x);
float FactAmplitude=2.0; // To be analyzed more deeply !
@ -106,19 +105,17 @@ int main(int argc, char **argv) {
double A = 87.7f; // compression parameter
double ampf=x/32767.0;
ampf = (fabs(ampf) < 1.0f/A) ? A*fabs(ampf)/(1.0f+ln(A)) : (1.0f+ln(A*fabs(ampf)))/(1.0f+ln(A)); //compand
x= (int)(round(ampf * 32767.0f)) ;
x= (int)(round(ampf * 32767.0f));
*/
WriteTone(x*32767*FactAmplitude,1e9/48000.0);
}
} ;
}
/* Close input and output files. */
sf_close (infile) ;
close(FileFreqTiming);
close(FileFreqTiming);
return 0;
return 0;
}

Wyświetl plik

@ -40,33 +40,30 @@ void playtone(double Amplitude,uint32_t Timing);
void loop()
{
int i;
for ( i = 0;i<58;++i)
{
modulate(dcfBits[i]);
}
int i;
for (i = 0; i<58; ++i)
{
modulate(dcfBits[i]);
}
}
void DCF_BITS(int Minuten, int Stunden)
{
int i;
//MINUTE
int i;
//MINUTE
if (Minuten > 39)
if (Minuten > 39)
{
MinutenBits[6] = 1;
Minuten -= 40;
}
if (Minuten > 19)
if (Minuten > 19)
{
MinutenBits[5] = 1;
Minuten -= 20;
}
if (Minuten > 9)
if (Minuten > 9)
{
MinutenBits[4] = 1;
Minuten -= 10;
@ -85,188 +82,171 @@ void DCF_BITS(int Minuten, int Stunden)
MinutenBits[i] = false;
}
}
for ( i = 0; i < anzahlMinutenBits; ++i)
{
dcfBits[offsetMinutenBits + i] = MinutenBits[i];
}
{
dcfBits[offsetMinutenBits + i] = MinutenBits[i];
}
//Stunde
if (Stunden > 19)
if (Stunden > 19)
{
StundenBits[5] = 1;
Stunden -= 20;
}
if (Stunden > 9)
if (Stunden > 9)
{
StundenBits[4] = 1;
Stunden -= 10;
}
for ( i = 0; i < 4; ++i)
{
//MinutenBits[i] = (Minuten & (1 << i)) ? true : false;
if ((Stunden & (1 << i)) > 0)
{
StundenBits[i] = true;
}
else
{
StundenBits[i] = false;
}
}
for ( i = 0; i < 4; ++i)
{
//MinutenBits[i] = (Minuten & (1 << i)) ? true : false;
for ( i = 0; i < anzahlStundenBits; ++i)
{
dcfBits[offsetStundenBits + i] = StundenBits[i];
}
if ((Stunden & (1 << i)) > 0)
{
StundenBits[i] = true;
}
else
{
StundenBits[i] = false;
}
}
/*for (int n = 0; n < 6; ++n)
{
for ( i = 0; i < anzahlStundenBits; ++i)
{
dcfBits[offsetStundenBits + i] = StundenBits[i];
}
/*for (int n = 0; n < 6; ++n)
{
}*/
////////////////////////////
{
parity += dcfBits[21];
parity += dcfBits[22];
parity += dcfBits[23];
parity += dcfBits[24];
parity += dcfBits[25];
parity += dcfBits[26];
parity += dcfBits[27];
if (parity % 2 == 0)
{
dcfBits[28] = 0;
}
else
{
dcfBits[28] = 1;
}
parity = 0;
}
////////////////////////////
{
parity += dcfBits[29];
parity += dcfBits[30];
parity += dcfBits[31];
parity += dcfBits[32];
parity += dcfBits[33];
parity += dcfBits[34];
if (parity % 2 == 0)
{
dcfBits[35] = 0;
}
else
{
dcfBits[35] = 1;
}
parity = 0;
}
/////////////////////////////
{
parity += dcfBits[36];
parity += dcfBits[37];
parity += dcfBits[38];
parity += dcfBits[39];
parity += dcfBits[40];
parity += dcfBits[41];
parity += dcfBits[42];
parity += dcfBits[43];
parity += dcfBits[44];
parity += dcfBits[45];
parity += dcfBits[46];
parity += dcfBits[47];
parity += dcfBits[48];
parity += dcfBits[49];
parity += dcfBits[50];
parity += dcfBits[51];
parity += dcfBits[52];
parity += dcfBits[53];
parity += dcfBits[54];
parity += dcfBits[55];
parity += dcfBits[56];
parity += dcfBits[57];
if (parity % 2 == 0)
{
dcfBits[58] = 0;
}
else
{
dcfBits[58] = 1;
}
parity = 0;
}
}*/
////////////////////////////
{
parity += dcfBits[21];
parity += dcfBits[22];
parity += dcfBits[23];
parity += dcfBits[24];
parity += dcfBits[25];
parity += dcfBits[26];
parity += dcfBits[27];
//dcfBits[28] = parity % 2; ???
if (parity % 2 == 0)
{
dcfBits[28] = 0;
}
else
{
dcfBits[28] = 1;
}
parity = 0;
}
////////////////////////////
{
parity += dcfBits[29];
parity += dcfBits[30];
parity += dcfBits[31];
parity += dcfBits[32];
parity += dcfBits[33];
parity += dcfBits[34];
if (parity % 2 == 0)
{
dcfBits[35] = 0;
}
else
{
dcfBits[35] = 1;
}
parity = 0;
}
/////////////////////////////
{
parity += dcfBits[36];
parity += dcfBits[37];
parity += dcfBits[38];
parity += dcfBits[39];
parity += dcfBits[40];
parity += dcfBits[41];
parity += dcfBits[42];
parity += dcfBits[43];
parity += dcfBits[44];
parity += dcfBits[45];
parity += dcfBits[46];
parity += dcfBits[47];
parity += dcfBits[48];
parity += dcfBits[49];
parity += dcfBits[50];
parity += dcfBits[51];
parity += dcfBits[52];
parity += dcfBits[53];
parity += dcfBits[54];
parity += dcfBits[55];
parity += dcfBits[56];
parity += dcfBits[57];
if (parity % 2 == 0)
{
dcfBits[58] = 0;
}
else
{
dcfBits[58] = 1;
}
parity = 0;
}
}
void modulate(byte b)
{
if (b == 0)
{
playtone(32667/8,100e6);
playtone(32767,900e6);
}
else
{
playtone(32767/8,200e6);
playtone(32767,800e6);
}
if (b == 0)
{
playtone(32667/8,100e6);
playtone(32767,900e6);
}
else
{
playtone(32767/8,200e6);
playtone(32767,800e6);
}
}
void playtone(double Amplitude,uint32_t Timing)
{
typedef struct {
double Amplitude;
uint32_t WaitForThisSample;
} samplerf_t;
samplerf_t RfSample;
RfSample.Amplitude=Amplitude;
RfSample.WaitForThisSample=Timing; //en 100 de nanosecond
printf("%f %d\n",Amplitude,Timing);
if (write(FileFreqTiming,&RfSample,sizeof(samplerf_t)) != sizeof(samplerf_t)) {
if (write(FileFreqTiming, &RfSample, sizeof(samplerf_t)) != sizeof(samplerf_t)) {
fprintf(stderr, "Unable to write sample\n");
}
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
if (argc > 1) {
if (argc > 1)
{
char *sFileFreqTiming=(char *)argv[1];
FileFreqTiming = open(argv[1], O_WRONLY|O_CREAT, 0644);
FileFreqTiming = open(argv[1], O_WRONLY|O_CREAT, 0644);
DCF_BITS(7,59);
loop();
playtone(0,1000e6);//last second
close(FileFreqTiming);
}
else
{
printf("usage : pidfc77 dcfpatern.bin\n");
exit(0);
}
}
else
{
printf("usage : pidfc77 dcfpatern.bin\n");
exit(0);
}
return 0;
return 0;
}

Wyświetl plik

@ -13,70 +13,68 @@
#include <fcntl.h>
#include <sys/mman.h>
#include <sndfile.h>
#define BUFFER_LEN 1024*8
int FileFreqTiming;
// Test program using SNDFILE
// see http://www.mega-nerd.com/libsndfile/api.html for API
void WriteTone(double Frequency,uint32_t Timing)
{
typedef struct {
typedef struct {
double Frequency;
uint32_t WaitForThisSample;
} samplerf_t;
samplerf_t RfSample;
RfSample.Frequency=Frequency;
RfSample.WaitForThisSample=Timing; //en 100 de nanosecond
//printf("Freq =%f Timing=%d\n",RfSample.Frequency,RfSample.WaitForThisSample);
if (write(FileFreqTiming,&RfSample,sizeof(samplerf_t)) != sizeof(samplerf_t)) {
if (write(FileFreqTiming, &RfSample, sizeof(samplerf_t)) != sizeof(samplerf_t)) {
fprintf(stderr, "Unable to write sample\n");
}
}
int main(int argc, char **argv) {
float data [2*BUFFER_LEN] ;
float data_filtered[2*BUFFER_LEN] ; // we generate complex I/Q samples
SNDFILE *infile, *outfile ;
SF_INFO sfinfo ;
int main(int argc, char **argv)
{
float data [2*BUFFER_LEN];
float data_filtered[2*BUFFER_LEN]; // we generate complex I/Q samples
SNDFILE *infile, *outfile;
SF_INFO sfinfo;
int readcount, nb_samples ;
char *infilename ;
char *outfilename ;
int k ;
float x ;
int readcount, nb_samples;
char *infilename;
char *outfilename;
int k;
float x;
if( argc < 2 ) {
printf("Usage : %s in.wav [out.wav]\n", argv[0]);
return(1);
}
infilename = argv[1] ;
infilename = argv[1];
if( argc == 3 ) {
outfilename = argv[2] ;
outfilename = argv[2];
} else {
outfilename = (char *)malloc( 128 );
sprintf( outfilename, "%s", "out.ft");
}
if (! (infile = sf_open (infilename, SFM_READ, &sfinfo)))
{ /* Open failed so print an error message. */
printf ("Not able to open input file %s.\n", infilename) ;
printf ("Not able to open input file %s.\n", infilename);
/* Print the error message from libsndfile. */
puts (sf_strerror (NULL)) ;
return 1 ;
} ;
puts (sf_strerror (NULL));
return 1;
}
if( sfinfo.samplerate != 48000 ) {
printf("Input rate must be 48K.\n");
return 1 ;
return 1;
}
FileFreqTiming = open(outfilename, O_WRONLY|O_CREAT, 0644);
/** **/
printf ("Reading file : %s\n", infilename ) ;
printf ("Sample Rate : %d\n", sfinfo.samplerate) ;
@ -84,9 +82,7 @@ int main(int argc, char **argv) {
printf ("----------------------------------------\n") ;
printf ("Writing file : %s\n", outfilename ) ;
/* While there are.frames in the input file, read them, process
/* While there are.frames in the input file, read them, process
** them and write them to the output file.
*/
int Excursion=6000;
@ -102,16 +98,12 @@ int main(int argc, char **argv) {
}
//printf("%f \n",x);
WriteTone(x*Excursion*2.0,1e9/48000.0);
}
} ;
}
/* Close input and output files. */
sf_close (infile) ;
close(FileFreqTiming);
close(FileFreqTiming);
return 0;
return 0;
}

Wyświetl plik

@ -78,111 +78,111 @@ typedef struct fsq_varicode
const Varicode code_table[] =
{
{' ', {00, 00}}, // space
{'!', {11, 30}},
{'"', {12, 30}},
{'#', {13, 30}},
{'$', {14, 30}},
{'%', {15, 30}},
{'&', {16, 30}},
{'\'', {17, 30}},
{'(', {18, 30}},
{')', {19, 30}},
{'*', {20, 30}},
{'+', {21, 30}},
{',', {27, 29}},
{'-', {22, 30}},
{'.', {27, 00}},
{'/', {23, 30}},
{'0', {10, 30}},
{'1', {01, 30}},
{'2', {02, 30}},
{'3', {03, 30}},
{'4', {04, 30}},
{'5', {05, 30}},
{'6', {06, 30}},
{'7', {07, 30}},
{'8', {8, 30}},
{'9', {9, 30}},
{':', {24, 30}},
{';', {25, 30}},
{'<', {26, 30}},
{'=', {00, 31}},
{'>', {27, 30}},
{'?', {28, 29}},
{'@', {00, 29}},
{'A', {01, 29}},
{'B', {02, 29}},
{'C', {03, 29}},
{'D', {04, 29}},
{'E', {05, 29}},
{'F', {06, 29}},
{'G', {07, 29}},
{'H', {8, 29}},
{'I', {9, 29}},
{'J', {10, 29}},
{'K', {11, 29}},
{'L', {12, 29}},
{'M', {13, 29}},
{'N', {14, 29}},
{'O', {15, 29}},
{'P', {16, 29}},
{'Q', {17, 29}},
{'R', {18, 29}},
{'S', {19, 29}},
{'T', {20, 29}},
{'U', {21, 29}},
{'V', {22, 29}},
{'W', {23, 29}},
{'X', {24, 29}},
{'Y', {25, 29}},
{'Z', {26, 29}},
{'[', {01, 31}},
{'\\', {02, 31}},
{']', {03, 31}},
{'^', {04, 31}},
{'_', {05, 31}},
{'`', {9, 31}},
{'a', {01, 00}},
{'b', {02, 00}},
{'c', {03, 00}},
{'d', {04, 00}},
{'e', {05, 00}},
{'f', {06, 00}},
{'g', {07, 00}},
{'h', {8, 00}},
{'i', {9, 00}},
{'j', {10, 00}},
{'k', {11, 00}},
{'l', {12, 00}},
{'m', {13, 00}},
{'n', {14, 00}},
{'o', {15, 00}},
{'p', {16, 00}},
{'q', {17, 00}},
{'r', {18, 00}},
{'s', {19, 00}},
{'t', {20, 00}},
{'u', {21, 00}},
{'v', {22, 00}},
{'w', {23, 00}},
{'x', {24, 00}},
{'y', {25, 00}},
{'z', {26, 00}},
{'{', {06, 31}},
{'|', {07, 31}},
{'}', {8, 31}},
{'~', {00, 30}},
{127, {28, 31}}, // DEL
{13, {28, 00}}, // CR
{10, {28, 00}}, // LF
{0, {28, 30}}, // IDLE
{241, {10, 31}}, // plus/minus
{246, {11, 31}}, // division sign
{248, {12, 31}}, // degrees sign
{158, {13, 31}}, // multiply sign
{156, {14, 31}}, // pound sterling sign
{8, {27, 31}} // BS
{' ', {00, 00}}, // space
{'!', {11, 30}},
{'"', {12, 30}},
{'#', {13, 30}},
{'$', {14, 30}},
{'%', {15, 30}},
{'&', {16, 30}},
{'\'', {17, 30}},
{'(', {18, 30}},
{')', {19, 30}},
{'*', {20, 30}},
{'+', {21, 30}},
{',', {27, 29}},
{'-', {22, 30}},
{'.', {27, 00}},
{'/', {23, 30}},
{'0', {10, 30}},
{'1', {01, 30}},
{'2', {02, 30}},
{'3', {03, 30}},
{'4', {04, 30}},
{'5', {05, 30}},
{'6', {06, 30}},
{'7', {07, 30}},
{'8', {8, 30}},
{'9', {9, 30}},
{':', {24, 30}},
{';', {25, 30}},
{'<', {26, 30}},
{'=', {00, 31}},
{'>', {27, 30}},
{'?', {28, 29}},
{'@', {00, 29}},
{'A', {01, 29}},
{'B', {02, 29}},
{'C', {03, 29}},
{'D', {04, 29}},
{'E', {05, 29}},
{'F', {06, 29}},
{'G', {07, 29}},
{'H', {8, 29}},
{'I', {9, 29}},
{'J', {10, 29}},
{'K', {11, 29}},
{'L', {12, 29}},
{'M', {13, 29}},
{'N', {14, 29}},
{'O', {15, 29}},
{'P', {16, 29}},
{'Q', {17, 29}},
{'R', {18, 29}},
{'S', {19, 29}},
{'T', {20, 29}},
{'U', {21, 29}},
{'V', {22, 29}},
{'W', {23, 29}},
{'X', {24, 29}},
{'Y', {25, 29}},
{'Z', {26, 29}},
{'[', {01, 31}},
{'\\', {02, 31}},
{']', {03, 31}},
{'^', {04, 31}},
{'_', {05, 31}},
{'`', {9, 31}},
{'a', {01, 00}},
{'b', {02, 00}},
{'c', {03, 00}},
{'d', {04, 00}},
{'e', {05, 00}},
{'f', {06, 00}},
{'g', {07, 00}},
{'h', {8, 00}},
{'i', {9, 00}},
{'j', {10, 00}},
{'k', {11, 00}},
{'l', {12, 00}},
{'m', {13, 00}},
{'n', {14, 00}},
{'o', {15, 00}},
{'p', {16, 00}},
{'q', {17, 00}},
{'r', {18, 00}},
{'s', {19, 00}},
{'t', {20, 00}},
{'u', {21, 00}},
{'v', {22, 00}},
{'w', {23, 00}},
{'x', {24, 00}},
{'y', {25, 00}},
{'z', {26, 00}},
{'{', {06, 31}},
{'|', {07, 31}},
{'}', {8, 31}},
{'~', {00, 30}},
{127, {28, 31}}, // DEL
{13, {28, 00}}, // CR
{10, {28, 00}}, // LF
{0, {28, 30}}, // IDLE
{241, {10, 31}}, // plus/minus
{246, {11, 31}}, // division sign
{248, {12, 31}}, // degrees sign
{158, {13, 31}}, // multiply sign
{156, {14, 31}}, // pound sterling sign
{8, {27, 31}} // BS
};
void encode_tone(uint8_t tone);
@ -206,17 +206,16 @@ void encode_tone(uint8_t tone);
void WriteTone(double Frequency,uint32_t Timing)
{
typedef struct {
typedef struct {
double Frequency;
uint32_t WaitForThisSample;
} samplerf_t;
samplerf_t RfSample;
RfSample.Frequency=Frequency;
RfSample.WaitForThisSample=Timing*1000L; //en 100 de nanosecond
//printf("Freq =%f Timing=%d\n",RfSample.Frequency,RfSample.WaitForThisSample);
if (write(FileFreqTiming,&RfSample,sizeof(samplerf_t)) != sizeof(samplerf_t)) {
if (write(FileFreqTiming, &RfSample,sizeof(samplerf_t)) != sizeof(samplerf_t)) {
fprintf(stderr, "Unable to write sample\n");
}
@ -224,165 +223,157 @@ typedef struct {
void encode_char(int ch)
{
uint8_t i, fch, vcode1, vcode2;
uint8_t i, fch, vcode1, vcode2;
for(i = 0; i < NGLYPHS; i++)
{
// Check each element of the varicode table to see if we've found the
// character we're trying to send.
fch = code_table[i].ch;
if(fch == ch)
{
// Found the character, now fetch the varicode chars
vcode1 = code_table[i].var[0];
vcode2 = code_table[i].var[1];
// Transmit the appropriate tone per a varicode char
if(vcode2 == 0)
{
// If the 2nd varicode char is a 0 in the table,
// we are transmitting a lowercase character, and thus
// only transmit one tone for this character.
for(i = 0; i < NGLYPHS; i++)
{
// Check each element of the varicode table to see if we've found the
// character we're trying to send.
fch = code_table[i].ch;
// Generate tone
encode_tone(vcode1);
}
else
{
// If the 2nd varicode char is anything other than 0 in
// the table, then we need to transmit both
if(fch == ch)
{
// Found the character, now fetch the varicode chars
vcode1 = code_table[i].var[0];
vcode2 = code_table[i].var[1];
// Transmit the appropriate tone per a varicode char
if(vcode2 == 0)
{
// If the 2nd varicode char is a 0 in the table,
// we are transmitting a lowercase character, and thus
// only transmit one tone for this character.
// Generate tone
encode_tone(vcode1);
}
else
{
// If the 2nd varicode char is anything other than 0 in
// the table, then we need to transmit both
// Generate 1st tone
encode_tone(vcode1);
// Generate 2nd tone
encode_tone(vcode2);
}
break; // We've found and transmitted the char,
// so exit the for loop
}
}
// Generate 1st tone
encode_tone(vcode1);
// Generate 2nd tone
encode_tone(vcode2);
}
break; // We've found and transmitted the char,
// so exit the for loop
}
}
}
void encode_tone(uint8_t tone)
{
cur_tone = ((cur_tone + tone + 1) % 33);
//printf("Current tone =%d\n",cur_tone);
WriteTone(1000 + (cur_tone * TONE_SPACING*0.001),500000L);
//TO DO FREQUENCY PI si5351.set_freq((freq * 100) + (cur_tone * TONE_SPACING), 0, SI5351_CLK0);
cur_tone = ((cur_tone + tone + 1) % 33);
//printf("Current tone =%d\n",cur_tone);
WriteTone(1000 + (cur_tone * TONE_SPACING*0.001),500000L);
//TO DO FREQUENCY PI si5351.set_freq((freq * 100) + (cur_tone * TONE_SPACING), 0, SI5351_CLK0);
}
// Loop through the string, transmitting one character at a time.
void encode(char *str)
{
// Reset the tone to 0 and turn on the output
cur_tone = 0;
/*
si5351.output_enable(SI5351_CLK0, 1);
digitalWrite(LED_PIN, HIGH);
// Reset the tone to 0 and turn on the output
cur_tone = 0;
/*
si5351.output_enable(SI5351_CLK0, 1);
digitalWrite(LED_PIN, HIGH);
*/
//Serial.println("=======");
// Transmit BOT
//noInterrupts();
encode_char(' '); // Send a space for the dummy character
//Do wait
// Send another space
encode_char(' ');
//Do wait
// Now send LF
encode_char(10);
//Do wait
// Now do the rest of the message
while (*str != '\0')
{
encode_char(*str++);
}
// Turn off the output
//si5351.output_enable(SI5351_CLK0, 0);
//digitalWrite(LED_PIN, LOW);
//Serial.println("=======");
// Transmit BOT
//noInterrupts();
encode_char(' '); // Send a space for the dummy character
//Do wait
// Send another space
encode_char(' ');
//Do wait
// Now send LF
encode_char(10);
//Do wait
// Now do the rest of the message
while (*str != '\0')
{
encode_char(*str++);
}
// Turn off the output
//si5351.output_enable(SI5351_CLK0, 0);
//digitalWrite(LED_PIN, LOW);
}
static void init_crc8(void)
{
int i,j;
uint8_t crc;
int i,j;
uint8_t crc;
for(i = 0; i < 256; i++)
{
crc = i;
for(j = 0; j < 8; j++)
{
crc = (crc << 1) ^ ((crc & 0x80) ? 0x07 : 0);
}
crc8_table[i] = crc & 0xFF;
}
for(i = 0; i < 256; i++)
{
crc = i;
for(j = 0; j < 8; j++)
{
crc = (crc << 1) ^ ((crc & 0x80) ? 0x07 : 0);
}
crc8_table[i] = crc & 0xFF;
}
}
uint8_t crc8(char * text)
{
uint8_t crc='\0';
uint8_t ch;
int i;
for(i = 0; i < strlen(text); i++)
{
ch = text[i];
crc = crc8_table[(crc) ^ ch];
crc &= 0xFF;
}
uint8_t crc='\0';
uint8_t ch;
int i;
for(i = 0; i < strlen(text); i++)
{
ch = text[i];
crc = crc8_table[(crc) ^ ch];
crc &= 0xFF;
}
return crc;
return crc;
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
char *sText;
if (argc > 2) {
if (argc > 2)
{
sText=(char *)argv[1];
//FileText = open(argv[1], O_RDONLY);
//FileText = open(argv[1], O_RDONLY);
char *sFileFreqTiming=(char *)argv[2];
FileFreqTiming = open(argv[2], O_WRONLY|O_CREAT, 0644);
}
else
{
printf("usage : pifsq StringToTransmit file.ft\n");
exit(0);
}
FileFreqTiming = open(argv[2], O_WRONLY|O_CREAT, 0644);
}
else
{
printf("usage : pifsq StringToTransmit file.ft\n");
exit(0);
}
// Initialize the CRC table
init_crc8();
// Initialize the CRC table
init_crc8();
// Generate the CRC for the callsign
callsign_crc = crc8(callsign);
// Generate the CRC for the callsign
callsign_crc = crc8(callsign);
// We are building a directed message here, but you can do whatever.
// So apparently, FSQ very specifically needs " \b " in
// directed mode to indicate EOT. A single backspace won't do it.
sprintf(tx_buffer, "%s:%02x%s%s", callsign, callsign_crc,sText," \b ");
encode(tx_buffer);
int i;
for(i=0;i<10;i++)
{
WriteTone(0,500000L);
}
close(FileFreqTiming);
// We are building a directed message here, but you can do whatever.
// So apparently, FSQ very specifically needs " \b " in
// directed mode to indicate EOT. A single backspace won't do it.
sprintf(tx_buffer, "%s:%02x%s%s", callsign, callsign_crc,sText," \b ");
encode(tx_buffer);
int i;
for(i=0;i<10;i++)
{
WriteTone(0,500000L);
}
close(FileFreqTiming);
}

Wyświetl plik

@ -4,7 +4,8 @@
#include "RpiDma.h"
#include "RpiGpio.h"
static int compareInts(const void* first, const void* second) {
static int compareInts(const void* first, const void* second)
{
const int firstInt = *((int*)first);
const int secondInt = *((int*)second);
if (firstInt < secondInt) {
@ -16,7 +17,6 @@ static int compareInts(const void* first, const void* second) {
return 1;
}
char InitDma(void *FunctionTerminate, int* skipSignals)
{
DMA_CHANNEL=4;
@ -31,13 +31,13 @@ char InitDma(void *FunctionTerminate, int* skipSignals)
{
if(line[0]=='3')
{
printf("Wheezy\n");
DMA_CHANNEL=DMA_CHANNEL_WHEEZY;
printf("Wheezy\n");
DMA_CHANNEL=DMA_CHANNEL_WHEEZY;
}
if(line[0]=='4')
{
printf("Jessie\n");
printf("Jessie\n");
DMA_CHANNEL=DMA_CHANNEL_JESSIE;
}
@ -99,23 +99,17 @@ char InitDma(void *FunctionTerminate, int* skipSignals)
virtbase = (uint8_t *)((uint32_t *)mbox.virt_addr);
//printf("virtbase %p\n", virtbase);
return(1);
}
uint32_t
mem_virt_to_phys(volatile void *virt)
uint32_t mem_virt_to_phys(volatile void *virt)
{
//MBOX METHOD
uint32_t offset = (uint8_t *)virt - mbox.virt_addr;
return mbox.bus_addr + offset;
}
uint32_t
mem_phys_to_virt(volatile uint32_t phys)
uint32_t mem_phys_to_virt(volatile uint32_t phys)
{
//MBOX METHOD
uint32_t offset=phys-mbox.bus_addr;
uint32_t result=(uint32_t)((uint8_t *)mbox.virt_addr+offset);

Wyświetl plik

@ -28,22 +28,18 @@ uint32_t mem_phys_to_virt(volatile uint32_t phys);
#define NUM_CBS_MAIN ((NUM_SAMPLES_MAX * CBS_SIZE_BY_SAMPLE))
#define NUM_CBS (NUM_CBS_MAIN)
#define BCM2708_DMA_SRC_IGNOR (1<<11)
#define BCM2708_DMA_SRC_INC (1<<8)
#define BCM2708_DMA_DST_IGNOR (1<<7)
#define BCM2708_DMA_NO_WIDE_BURSTS (1<<26)
#define BCM2708_DMA_WAIT_RESP (1<<3)
#define BCM2708_DMA_D_DREQ (1<<6)
#define BCM2708_DMA_PER_MAP(x) ((x)<<16)
#define BCM2708_DMA_END (1<<1)
#define BCM2708_DMA_RESET (1<<31)
#define BCM2708_DMA_INT (1<<2)
#define DMA_CS (0x00/4)
#define DMA_CONBLK_AD (0x04/4)
#define DMA_DEBUG (0x20/4)
@ -122,11 +118,8 @@ struct control_data_s {
uint32_t SharedFrequency2;
uint32_t DmaPwmfControlRegister;
uint32_t SharedFrequencyTab[100];
};
struct control_data_s *ctl;
#endif

Wyświetl plik

@ -38,7 +38,6 @@ char InitGpio()
pad_gpios_reg = map_peripheral(PADS_GPIO, PADS_GPIO_LEN);
return 1;
}
void * map_peripheral(uint32_t base, uint32_t len)
@ -68,31 +67,31 @@ int gpioSetMode(unsigned gpio, unsigned mode)
//*************************************************************************************************************
#ifndef TRUE
#define TRUE (1==1)
#define FALSE (1==2)
#define TRUE (1==1) // (rand() % 2)
#define FALSE (1==2) // (rand() % 2)
#endif
static int piModel2 = FALSE ;
const char *piModelNames [7] =
{
"Unknown",
"Model A",
"Model B",
"Model B+",
"Compute Module",
"Model A+",
"Model 2", // Quad Core
} ;
"Unknown",
"Model A",
"Model B",
"Model B+",
"Compute Module",
"Model A+",
"Model 2", // Quad Core
};
const char *piRevisionNames [5] =
{
"Unknown",
"1",
"1.1",
"1.2",
"2",
} ;
"Unknown",
"1",
"1.1",
"1.2",
"2",
};
const char *piMakerNames [5] =
{
@ -101,7 +100,7 @@ const char *piMakerNames [5] =
"Sony",
"Qusda",
"MBest",
} ;
};
// Pi model types and version numbers
@ -169,82 +168,79 @@ const char *piMakerNames [5] =
static void piBoardRevOops (const char *why)
{
fprintf (stderr, "piBoardRev: Unable to determine board revision from /proc/cpuinfo\n") ;
fprintf (stderr, " -> %s\n", why) ;
fprintf (stderr, " -> You may want to check:\n") ;
fprintf (stderr, " -> http://www.raspberrypi.org/phpBB3/viewtopic.php?p=184410#p184410\n") ;
exit (EXIT_FAILURE) ;
fprintf (stderr, "piBoardRev: Unable to determine board revision from /proc/cpuinfo\n");
fprintf (stderr, " -> %s\n", why);
fprintf (stderr, " -> You may want to check:\n");
fprintf (stderr, " -> http://www.raspberrypi.org/phpBB3/viewtopic.php?p=184410#p184410\n");
exit (EXIT_FAILURE);
}
int piBoardRev (void)
{
FILE *cpuFd ;
char line [120] ;
char *c ;
static int boardRev = -1 ;
FILE *cpuFd;
char line [120];
char *c;
static int boardRev = -1;
if (boardRev != -1) // No point checking twice
return boardRev ;
if (boardRev != -1) // No point checking twice
return boardRev;
if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL)
piBoardRevOops ("Unable to open /proc/cpuinfo") ;
if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL)
piBoardRevOops ("Unable to open /proc/cpuinfo");
// Start by looking for the Architecture, then we can look for a B2 revision....
while (fgets (line, 120, cpuFd) != NULL)
if (strncmp (line, "Hardware", 8) == 0)
break ;
while (fgets (line, 120, cpuFd) != NULL)
if (strncmp (line, "Hardware", 8) == 0)
break ;
if (strncmp (line, "Hardware", 8) != 0)
piBoardRevOops ("No \"Hardware\" line");
if (strncmp (line, "Hardware", 8) != 0)
piBoardRevOops ("No \"Hardware\" line") ;
// See if it's BCM2708 or BCM2709
// See if it's BCM2708 or BCM2709
if (strstr (line, "BCM2709") != NULL)
piModel2 = TRUE ;
else if (strstr (line, "BCM2708") == NULL)
{
fprintf (stderr, "Unable to determine hardware version. I see: %s,\n", line) ;
fprintf (stderr, " - expecting BCM2708 or BCM2709. Please report this to projects@drogon.net\n") ;
exit (EXIT_FAILURE) ;
}
if (strstr (line, "BCM2709") != NULL)
piModel2 = TRUE ;
else if (strstr (line, "BCM2708") == NULL)
{
fprintf (stderr, "Unable to determine hardware version. I see: %s,\n", line);
fprintf (stderr, " - expecting BCM2708 or BCM2709. Please report this to projects@drogon.net\n");
exit (EXIT_FAILURE);
}
// Now do the rest of it as before
rewind (cpuFd) ;
rewind (cpuFd) ;
while (fgets (line, 120, cpuFd) != NULL)
if (strncmp (line, "Revision", 8) == 0)
break ;
while (fgets (line, 120, cpuFd) != NULL)
if (strncmp (line, "Revision", 8) == 0)
break ;
fclose (cpuFd) ;
fclose (cpuFd) ;
if (strncmp (line, "Revision", 8) != 0)
piBoardRevOops ("No \"Revision\" line") ;
if (strncmp (line, "Revision", 8) != 0)
piBoardRevOops ("No \"Revision\" line");
// Chomp trailing CR/NL
// Chomp trailing CR/NL
for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c)
*c = 0 ;
//if (wiringPiDebug)
//printf ("piboardRev: Revision string: %s\n", line) ;
for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c)
*c = 0 ;
//if (wiringPiDebug)
//printf ("piboardRev: Revision string: %s\n", line);
// Scan to first digit
for (c = line ; *c ; ++c)
if (isdigit (*c))
break ;
if (!isdigit (*c))
piBoardRevOops ("No numeric revision string") ;
for (c = line ; *c ; ++c)
if (isdigit (*c))
break;
if (!isdigit (*c))
piBoardRevOops ("No numeric revision string");
// Make sure its long enough
if (strlen (c) < 4)
piBoardRevOops ("Bogus \"Revision\" line (too small)") ;
if (strlen (c) < 4)
piBoardRevOops ("Bogus \"Revision\" line (too small)");
// If you have overvolted the Pi, then it appears that the revision
// has 100000 added to it!
@ -257,21 +253,16 @@ int piBoardRev (void)
// Isolate last 4 characters:
c = c + strlen (c) - 4 ;
c = c + strlen (c) - 4;
if ( (strcmp (c, "0002") == 0) || (strcmp (c, "0003") == 0))
boardRev = 1;
else
boardRev = 2;
if ( (strcmp (c, "0002") == 0) || (strcmp (c, "0003") == 0))
boardRev = 1 ;
else
boardRev = 2 ;
return boardRev ;
return boardRev;
}
/*
* piBoardId:
* Do more digging into the board revision string as above, but return
@ -292,93 +283,93 @@ int piBoardRev (void)
void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted)
{
FILE *cpuFd ;
char line [120] ;
char *c ;
FILE *cpuFd;
char line [120];
char *c;
// Will deal with the properly later on - for now, lets just get it going...
// unsigned int modelNum ;
(void)piBoardRev () ; // Call this first to make sure all's OK. Don't care about the result.
(void)piBoardRev () ; // Call this first to make sure all's OK. Don't care about the result.
if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL)
piBoardRevOops ("Unable to open /proc/cpuinfo") ;
if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL)
piBoardRevOops ("Unable to open /proc/cpuinfo");
while (fgets (line, 120, cpuFd) != NULL)
if (strncmp (line, "Revision", 8) == 0)
break ;
while (fgets (line, 120, cpuFd) != NULL)
if (strncmp (line, "Revision", 8) == 0)
break;
fclose (cpuFd) ;
fclose (cpuFd);
if (strncmp (line, "Revision", 8) != 0)
piBoardRevOops ("No \"Revision\" line") ;
if (strncmp (line, "Revision", 8) != 0)
piBoardRevOops ("No \"Revision\" line");
// Chomp trailing CR/NL
for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c)
*c = 0 ;
for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c)
*c = 0;
//if (wiringPiDebug)
//printf ("piboardId: Revision string: %s\n", line) ;
if (piModel2)
{
if (piModel2)
{
// Scan to the colon
for (c = line ; *c ; ++c)
if (*c == ':')
break ;
for (c = line ; *c ; ++c)
if (*c == ':')
break;
if (*c != ':')
piBoardRevOops ("Bogus \"Revision\" line") ;
if (*c != ':')
piBoardRevOops ("Bogus \"Revision\" line");
// modelNum = (unsigned int)strtol (++c, NULL, 16) ; // Hex number with no leading 0x
*model = PI_MODEL_2 ;
*rev = PI_VERSION_1_1 ;
*mem = 1024 ;
*maker = PI_MAKER_SONY ;
}
else
{
*model = PI_MODEL_2;
*rev = PI_VERSION_1_1;
*mem = 1024;
*maker = PI_MAKER_SONY;
}
else
{
// Scan to first digit
for (c = line ; *c ; ++c)
if (isdigit (*c))
break ;
for (c = line ; *c ; ++c)
if (isdigit (*c))
break;
// Make sure its long enough
if (strlen (c) < 4)
piBoardRevOops ("Bogus \"Revision\" line") ;
if (strlen (c) < 4)
piBoardRevOops ("Bogus \"Revision\" line");
// If longer than 4, we'll assume it's been overvolted
*overVolted = strlen (c) > 4 ;
*overVolted = strlen (c) > 4;
// Extract last 4 characters:
c = c + strlen (c) - 4 ;
c = c + strlen (c) - 4;
// Fill out the replys as appropriate
/**/ if (strcmp (c, "0002") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0003") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_1 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0004") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0005") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_QISDA ; }
else if (strcmp (c, "0006") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0007") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0008") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; ; }
else if (strcmp (c, "0009") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_QISDA ; }
else if (strcmp (c, "000d") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "000e") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "000f") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0010") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0011") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0012") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0013") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_MBEST ; }
else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; }
}
/**/ if (strcmp (c, "0002") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0003") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_1 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0004") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0005") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_QISDA ; }
else if (strcmp (c, "0006") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0007") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0008") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; ; }
else if (strcmp (c, "0009") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_QISDA ; }
else if (strcmp (c, "000d") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "000e") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "000f") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0010") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0011") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0012") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0013") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_MBEST ; }
else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; }
}
}

Wyświetl plik

@ -14,14 +14,14 @@ char InitGpio(void);
void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted);
int model;
uint32_t mem_flag;
uint32_t mem_flag;
volatile uint32_t *pwm_reg;
volatile uint32_t *clk_reg;
volatile uint32_t *dma_reg;
volatile uint32_t *clk_reg;
volatile uint32_t *dma_reg;
volatile uint32_t *gpio_reg;
volatile uint32_t *pcm_reg;
volatile uint32_t *pad_gpios_reg;
volatile uint32_t *pcm_reg;
volatile uint32_t *pad_gpios_reg;
void * map_peripheral(uint32_t base, uint32_t len);
int gpioSetMode(unsigned gpio, unsigned mode);

Plik diff jest za duży Load Diff

Wyświetl plik

@ -3,8 +3,8 @@
//*************************************************************************************************************
#ifndef TRUE
#define TRUE (1==1)
#define FALSE (1==2)
#define TRUE (1==1) // (rand() % 2)
#define FALSE (1==2) // (rand() % 2)
#endif
@ -12,32 +12,32 @@ static int piModel2 = FALSE ;
const char *piModelNames [7] =
{
"Unknown",
"Model A",
"Model B",
"Model B+",
"Compute Module",
"Model A+",
"Model 2", // Quad Core
} ;
"Unknown",
"Model A",
"Model B",
"Model B+",
"Compute Module",
"Model A+",
"Model 2", // Quad Core
};
const char *piRevisionNames [5] =
{
"Unknown",
"1",
"1.1",
"1.2",
"2",
} ;
"Unknown",
"1",
"1.1",
"1.2",
"2",
};
const char *piMakerNames [5] =
{
"Unknown",
"Egoman",
"Sony",
"Qusda",
"MBest",
} ;
"Unknown",
"Egoman",
"Sony",
"Qusda",
"MBest",
};
// Pi model types and version numbers
@ -105,82 +105,81 @@ const char *piMakerNames [5] =
static void piBoardRevOops (const char *why)
{
fprintf (stderr, "piBoardRev: Unable to determine board revision from /proc/cpuinfo\n") ;
fprintf (stderr, " -> %s\n", why) ;
fprintf (stderr, " -> You may want to check:\n") ;
fprintf (stderr, " -> http://www.raspberrypi.org/phpBB3/viewtopic.php?p=184410#p184410\n") ;
exit (EXIT_FAILURE) ;
fprintf (stderr, "piBoardRev: Unable to determine board revision from /proc/cpuinfo\n");
fprintf (stderr, " -> %s\n", why);
fprintf (stderr, " -> You may want to check:\n");
fprintf (stderr, " -> http://www.raspberrypi.org/phpBB3/viewtopic.php?p=184410#p184410\n");
exit (EXIT_FAILURE);
}
int piBoardRev (void)
{
FILE *cpuFd ;
char line [120] ;
char *c ;
static int boardRev = -1 ;
FILE *cpuFd;
char line [120];
char *c;
static int boardRev = -1;
if (boardRev != -1) // No point checking twice
return boardRev ;
if (boardRev != -1) // No point checking twice
return boardRev;
if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL)
piBoardRevOops ("Unable to open /proc/cpuinfo") ;
if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL)
piBoardRevOops ("Unable to open /proc/cpuinfo");
// Start by looking for the Architecture, then we can look for a B2 revision....
while (fgets (line, 120, cpuFd) != NULL)
if (strncmp (line, "Hardware", 8) == 0)
break ;
while (fgets (line, 120, cpuFd) != NULL)
if (strncmp (line, "Hardware", 8) == 0)
break;
if (strncmp (line, "Hardware", 8) != 0)
piBoardRevOops ("No \"Hardware\" line") ;
if (strncmp (line, "Hardware", 8) != 0)
piBoardRevOops ("No \"Hardware\" line");
// See if it's BCM2708 or BCM2709
if (strstr (line, "BCM2709") != NULL)
piModel2 = TRUE ;
else if (strstr (line, "BCM2708") == NULL)
{
fprintf (stderr, "Unable to determine hardware version. I see: %s,\n", line) ;
fprintf (stderr, " - expecting BCM2708 or BCM2709. Please report this to projects@drogon.net\n") ;
exit (EXIT_FAILURE) ;
}
if (strstr (line, "BCM2709") != NULL)
piModel2 = TRUE ;
else if (strstr (line, "BCM2708") == NULL)
{
fprintf (stderr, "Unable to determine hardware version. I see: %s,\n", line);
fprintf (stderr, " - expecting BCM2708 or BCM2709. Please report this to projects@drogon.net\n");
exit (EXIT_FAILURE);
}
// Now do the rest of it as before
rewind (cpuFd) ;
rewind (cpuFd);
while (fgets (line, 120, cpuFd) != NULL)
if (strncmp (line, "Revision", 8) == 0)
break ;
while (fgets (line, 120, cpuFd) != NULL)
if (strncmp (line, "Revision", 8) == 0)
break;
fclose (cpuFd) ;
fclose (cpuFd);
if (strncmp (line, "Revision", 8) != 0)
piBoardRevOops ("No \"Revision\" line") ;
if (strncmp (line, "Revision", 8) != 0)
piBoardRevOops ("No \"Revision\" line");
// Chomp trailing CR/NL
for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c)
*c = 0 ;
for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c)
*c = 0;
//if (wiringPiDebug)
printf ("piboardRev: Revision string: %s\n", line) ;
//if (wiringPiDebug)
printf ("piboardRev: Revision string: %s\n", line);
// Scan to first digit
for (c = line ; *c ; ++c)
if (isdigit (*c))
break ;
for (c = line ; *c ; ++c)
if (isdigit (*c))
break;
if (!isdigit (*c))
piBoardRevOops ("No numeric revision string") ;
if (!isdigit (*c))
piBoardRevOops ("No numeric revision string");
// Make sure its long enough
if (strlen (c) < 4)
piBoardRevOops ("Bogus \"Revision\" line (too small)") ;
if (strlen (c) < 4)
piBoardRevOops ("Bogus \"Revision\" line (too small)");
// If you have overvolted the Pi, then it appears that the revision
// has 100000 added to it!
@ -188,23 +187,21 @@ int piBoardRev (void)
// (force_turbo || current_limit_override || temp_limit>85) && over_voltage>0
//if (wiringPiDebug)
if (strlen (c) != 4)
printf ("piboardRev: This Pi has/is (force_turbo || current_limit_override || temp_limit>85) && over_voltage>0\n") ;
if (strlen (c) != 4)
printf ("piboardRev: This Pi has/is (force_turbo || current_limit_override || temp_limit>85) && over_voltage>0\n");
// Isolate last 4 characters:
c = c + strlen (c) - 4 ;
c = c + strlen (c) - 4;
if ( (strcmp (c, "0002") == 0) || (strcmp (c, "0003") == 0))
boardRev = 1 ;
else
boardRev = 2 ;
if ( (strcmp (c, "0002") == 0) || (strcmp (c, "0003") == 0))
boardRev = 1;
else
boardRev = 2;
return boardRev ;
return boardRev;
}
@ -228,94 +225,93 @@ int piBoardRev (void)
void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted)
{
FILE *cpuFd ;
char line [120] ;
char *c ;
FILE *cpuFd ;
char line [120] ;
char *c ;
// Will deal with the properly later on - for now, lets just get it going...
// unsigned int modelNum ;
// unsigned int modelNum;
(void)piBoardRev () ; // Call this first to make sure all's OK. Don't care about the result.
(void)piBoardRev (); // Call this first to make sure all's OK. Don't care about the result.
if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL)
piBoardRevOops ("Unable to open /proc/cpuinfo") ;
if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL)
piBoardRevOops ("Unable to open /proc/cpuinfo");
while (fgets (line, 120, cpuFd) != NULL)
if (strncmp (line, "Revision", 8) == 0)
break ;
while (fgets (line, 120, cpuFd) != NULL)
if (strncmp (line, "Revision", 8) == 0)
break;
fclose (cpuFd) ;
fclose (cpuFd);
if (strncmp (line, "Revision", 8) != 0)
piBoardRevOops ("No \"Revision\" line") ;
if (strncmp (line, "Revision", 8) != 0)
piBoardRevOops ("No \"Revision\" line");
// Chomp trailing CR/NL
for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c)
*c = 0 ;
for (c = &line [strlen (line) - 1] ; (*c == '\n') || (*c == '\r') ; --c)
*c = 0;
//if (wiringPiDebug)
printf ("piboardId: Revision string: %s\n", line) ;
if (piModel2)
{
//if (wiringPiDebug)
printf ("piboardId: Revision string: %s\n", line)
if (piModel2)
{
// Scan to the colon
for (c = line ; *c ; ++c)
if (*c == ':')
break ;
for (c = line ; *c ; ++c)
if (*c == ':')
break;
if (*c != ':')
piBoardRevOops ("Bogus \"Revision\" line") ;
if (*c != ':')
piBoardRevOops ("Bogus \"Revision\" line") ;
// modelNum = (unsigned int)strtol (++c, NULL, 16) ; // Hex number with no leading 0x
// modelNum = (unsigned int)strtol (++c, NULL, 16) ; // Hex number with no leading 0x
*model = PI_MODEL_2 ;
*rev = PI_VERSION_1_1 ;
*mem = 1024 ;
*maker = PI_MAKER_SONY ;
}
else
{
*model = PI_MODEL_2;
*rev = PI_VERSION_1_1;
*mem = 1024;
*maker = PI_MAKER_SONY;
}
else
{
// Scan to first digit
for (c = line ; *c ; ++c)
if (isdigit (*c))
break ;
for (c = line ; *c ; ++c)
if (isdigit (*c))
break;
// Make sure its long enough
if (strlen (c) < 4)
piBoardRevOops ("Bogus \"Revision\" line") ;
if (strlen (c) < 4)
piBoardRevOops ("Bogus \"Revision\" line");
// If longer than 4, we'll assume it's been overvolted
*overVolted = strlen (c) > 4 ;
*overVolted = strlen (c) > 4;
// Extract last 4 characters:
c = c + strlen (c) - 4 ;
c = c + strlen (c) - 4;
// Fill out the replys as appropriate
/**/ if (strcmp (c, "0002") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0003") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_1 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0004") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0005") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_QISDA ; }
else if (strcmp (c, "0006") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0007") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0008") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; ; }
else if (strcmp (c, "0009") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_QISDA ; }
else if (strcmp (c, "000d") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "000e") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "000f") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0010") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0011") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0012") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0013") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_MBEST ; }
else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; }
}
/**/ if (strcmp (c, "0002") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0003") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_1 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0004") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0005") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_QISDA ; }
else if (strcmp (c, "0006") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0007") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0008") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; ; }
else if (strcmp (c, "0009") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_QISDA ; }
else if (strcmp (c, "000d") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "000e") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "000f") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0010") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0011") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0012") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0013") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_MBEST ; }
else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; }
}
}

Wyświetl plik

@ -34,56 +34,56 @@
#include "ssb_gen.h"
struct FIR {
float *coeffs ;
int filterLength ;
float *delay_line ;
float *coeffs;
int filterLength;
float *delay_line;
};
typedef struct _cpx {
float re ;
float im ;
} TYPECPX ;
float re;
float im;
} TYPECPX;
struct cFIR {
float *coeffs ;
int filterLength ;
TYPECPX *delay_line ;
float rms ;
float *coeffs;
int filterLength;
TYPECPX *delay_line;
float rms;
};
#define ALPHA_DC_REMOVE (0.999)
struct FIR* audio_fir ;
struct FIR* hilbert ;
struct FIR* delay ;
struct cFIR* interpolateIQ ;
struct FIR* audio_fir;
struct FIR* hilbert;
struct FIR* delay;
struct cFIR* interpolateIQ;
// Create a FIR struct, used to store a copy of coeffs and delay line
// in : coeffs_len = coeff tab length
// double *coeff_tab = pointer to the coefficients
// out: a struct FIR
struct FIR* init_fir( int coeffs_len, float *coeff_tab ) {
struct FIR *result ;
int i ;
struct FIR* init_fir( int coeffs_len, float *coeff_tab )
{
struct FIR *result;
int i;
// alloc and init buffers
result = (struct FIR *)malloc( sizeof( struct FIR ));
result->filterLength = coeffs_len ;
result->filterLength = coeffs_len;
result->coeffs = (float*)malloc( coeffs_len * sizeof( float));
result->delay_line = (float*)malloc( coeffs_len * sizeof( float));
// copy coeffs to struct
for( i=0 ; i < coeffs_len ; i++ ) {
result->delay_line[i] = 0.0 ;
result->coeffs[i] = coeff_tab[i] ;
result->delay_line[i] = 0.0;
result->coeffs[i] = coeff_tab[i];
}
return( result );
}
// init a complex in -> complex out fir with real coeffs
struct cFIR* init_cfir( int coeffs_len, float *coeff_tab ) {
struct cFIR *result ;
int i ;
struct cFIR* init_cfir( int coeffs_len, float *coeff_tab )
{
struct cFIR *result;
int i;
// alloc and init buffers
result = (struct cFIR *)malloc( sizeof( struct cFIR ));
result->filterLength = coeffs_len ;
@ -91,113 +91,118 @@ struct cFIR* init_cfir( int coeffs_len, float *coeff_tab ) {
result->delay_line = (TYPECPX*)malloc( coeffs_len * sizeof( TYPECPX));
// copy coeffs to struct
for( i=0 ; i < coeffs_len ; i++ ) {
result->delay_line[i].re = 0.0 ;
result->delay_line[i].im = 0.0 ;
result->coeffs[i] = coeff_tab[i] ;
result->delay_line[i].re = 0.0;
result->delay_line[i].im = 0.0;
result->coeffs[i] = coeff_tab[i];
}
return( result );
}
float fir_filt( struct FIR* f, float in ) {
int i ;
float acc ;
float *pt_coeffs ;
float *pt_sample ;
int L ;
float fir_filt( struct FIR* f, float in )
{
int i;
float acc;
float *pt_coeffs;
float *pt_sample;
int L;
// shift input left for one sample
L = f->filterLength ;
L = f->filterLength;
for( i=0 ; i < L - 1 ; i++ ) {
f->delay_line[i] = f->delay_line[i+1] ;
f->delay_line[i] = f->delay_line[i+1];
}
// add new sample to the end of delay line
f->delay_line[ L - 1 ] = in ;
f->delay_line[ L - 1 ] = in;
acc = 0 ;
pt_sample = f->delay_line ;
pt_coeffs = f->coeffs ;
pt_sample = f->delay_line;
pt_coeffs = f->coeffs;
// do the compute loop
for( i=0 ; i < L ; i++ ) {
acc += (*pt_sample) * (*pt_coeffs );
pt_sample++ ;
pt_coeffs++ ;
pt_sample++;
pt_coeffs++;
}
return( acc );
}
// same but we filter a complex number at input, out is a complex
TYPECPX cfir_filt( struct cFIR* f, TYPECPX in ) {
int i ;
TYPECPX acc ;
float *pt_coeffs, rms ;
TYPECPX *pt_sample ;
int L ;
TYPECPX cfir_filt( struct cFIR* f, TYPECPX in )
{
int i;
TYPECPX acc;
float *pt_coeffs, rms;
TYPECPX *pt_sample;
int L;
// shift input left for one sample
L = f->filterLength ;
for( i=0 ; i < L - 1 ; i++ ) {
f->delay_line[i] = f->delay_line[i+1] ;
L = f->filterLength;
for( i=0 ; i < L - 1 ; i++ ){
f->delay_line[i] = f->delay_line[i+1];
}
// add new sample to the end of delay line
f->delay_line[ L - 1 ] = in ;
acc.re = acc.im = 0 ;
pt_sample = f->delay_line ;
pt_coeffs = f->coeffs ;
f->delay_line[ L - 1 ] = in;
acc.re = acc.im = 0;
pt_sample = f->delay_line;
pt_coeffs = f->coeffs;
// do the compute loop
rms = 0 ;
rms = 0;
for( i=0 ; i < L ; i++ ) {
acc.re += (pt_sample->re) * (*pt_coeffs );
acc.im += (pt_sample->im) * (*pt_coeffs );
rms += (pt_sample->re)*(pt_sample->re) + (pt_sample->im)*(pt_sample->im) ;
pt_sample++ ;
pt_coeffs++ ;
rms += (pt_sample->re)*(pt_sample->re) + (pt_sample->im)*(pt_sample->im);
pt_sample++;
pt_coeffs++;
}
f->rms = sqrt( rms / L ) ;
f->rms = sqrt( rms / L );
return( acc );
}
TYPECPX m_Osc1 ;
double m_OscCos, m_OscSin ;
int nco_enabled ;
TYPECPX m_Osc1;
double m_OscCos, m_OscSin;
int nco_enabled;
#define B_SIZE (512)
#define COMP_ATTAK ( exp(-1/48.0)) /* 0.1 ms */
#define COMP_RELEASE (exp(-1/(30*480.0))) /* 300 ms */
#define threshold (.25)
void ssb(float in, int USB, float* out_I, float* out_Q) {
static float y_n1 = 0 ;
static float x_n1 = 0 ;
float y, Imix, Qmix, OscGn ;
static float I=0 ;
static float Q=0 ;
static int OL = 3 ;
void ssb(float in, int USB, float* out_I, float* out_Q)
{
static float y_n1 = 0;
static float x_n1 = 0;
float y, Imix, Qmix, OscGn;
static float I=0;
static float Q=0;
static int OL = 3;
// RingBuffer management
static int b_start = 0 ;
static int b_end = 0 ;
static float elems[B_SIZE] ; // power of 2, approx 1ms at 48KHz
static int first = B_SIZE ; // this says how many samples we wait before audio processing
static float env = 0 ;
float rms, theta, gain ;
static int b_start = 0;
static int b_end = 0;
static float elems[B_SIZE]; // power of 2, approx 1ms at 48KHz
static int first = B_SIZE; // this says how many samples we wait before audio processing
static float env = 0;
float rms, theta, gain;
//---------------------------
int i ;
int i;
TYPECPX dtmp, Osc, IQ;
OL++ ;
OL = OL % 4 ;
//---------- lowpass filter audio input
OL++;
OL = OL % 4;
//---------- lowpass filter audio input
// suppress DC, high pass filter
// y[n] = x[n] - x[n-1] + alpha * y[n-1]
y = in - x_n1 + ALPHA_DC_REMOVE*y_n1 ;
x_n1 = in ;
y_n1 = y ;
y = in - x_n1 + ALPHA_DC_REMOVE*y_n1;
x_n1 = in;
y_n1 = y;
// low pass filter y to keep only audio band
y = fir_filt( audio_fir, y );
#define AUDIO_COMPRESSOR
#ifdef AUDIO_COMPRESSOR
//----------- audio compressor
//--- code inspired from http://www.musicdsp.org/showone.php?id=169
#define AUDIO_COMPRESSOR //???
#ifdef AUDIO_COMPRESSOR //???
//----------- audio compressor
//--- code inspired from http://www.musicdsp.org/showone.php?id=169
// store in our ring buffer
if( b_end != (b_start ^ B_SIZE )) { // ring buffer not full
elems[b_end & (B_SIZE-1)] = y ; // append at the end
elems[b_end & (B_SIZE-1)] = y; // append at the end
if( b_end == (b_start ^ B_SIZE )) {
b_start = (b_start+1)&(2*B_SIZE-1);
@ -206,22 +211,22 @@ void ssb(float in, int USB, float* out_I, float* out_Q) {
}
// wait to have at least 2ms before starting
if( first > 0 ) {
first-- ;
*out_I = 0 ;
*out_Q = 0 ;
return ;
first--;
*out_I = 0;
*out_Q = 0;
return;
}
// compute RMS power in buffer
rms = 0 ;
rms = 0;
for( i=0 ; i < B_SIZE ; i++ ) {
rms += elems[i] * elems[i] ;
rms += elems[i] * elems[i];
}
rms = sqrt( rms / B_SIZE );
theta = rms > env ? COMP_ATTAK : COMP_RELEASE ;
env = (1-theta) * rms + theta * env ;
gain = 1 ;
theta = rms > env ? COMP_ATTAK : COMP_RELEASE;
env = (1-theta) * rms + theta * env;
gain = 1;
if( env > threshold ) {
gain = 1 - (env - threshold) ;
gain = 1 - (env - threshold);
}
// retrieve the oldest sample
y = elems[b_start&(B_SIZE-1)];
@ -242,10 +247,10 @@ void ssb(float in, int USB, float* out_I, float* out_Q) {
Q = fir_filt( hilbert, y );
}
IQ.re = I ;
IQ.im = USB * Q ;
IQ.re = I;
IQ.im = USB * Q;
// interpolation by 4
dtmp = cfir_filt( interpolateIQ, IQ ) ;
dtmp = cfir_filt( interpolateIQ, IQ );
// shift in freq if enabled (see ssb_init )
if( nco_enabled ) {
// our SSB signal is now centered at 0
@ -258,314 +263,314 @@ void ssb(float in, int USB, float* out_I, float* out_Q) {
//Cpx multiply by shift OL
Imix = ((dtmp.re * Osc.re) - (dtmp.im * Osc.im));
Qmix = ((dtmp.re * Osc.im) + (dtmp.im * Osc.re));
*out_I = Imix ;
*out_Q = Qmix ;
*out_I = Imix;
*out_Q = Qmix;
} else {
*out_I = dtmp.re ;
*out_Q = dtmp.im ;
*out_I = dtmp.re;
*out_Q = dtmp.im;
}
}
#define K_PI (3.14159265358979323846)
#define SAMPLE_RATE (48000.0f)
void ssb_init( float shift_carrier) {
double m_NcoInc ;
float a[83] ;
float b[89] ;
float c[89] ;
void ssb_init( float shift_carrier)
{
double m_NcoInc;
float a[83];
float b[89];
float c[89];
/*
* Kaiser Window FIR Filter
* Passband: 0.0 - 3000.0 Hz
* Order: 83
* Transition band: 3000.0 Hz
* Stopband attenuation: 80.0 dB
*/
a[0] = -1.7250879E-5f;
a[1] = -4.0276995E-5f;
a[2] = -5.6314686E-5f;
a[3] = -4.0164417E-5f;
a[4] = 3.0053454E-5f;
a[5] = 1.5370155E-4f;
a[6] = 2.9180944E-4f;
a[7] = 3.6717512E-4f;
a[8] = 2.8903902E-4f;
a[9] = 3.1934875E-11f;
a[10] = -4.716546E-4f;
a[11] = -9.818495E-4f;
a[12] = -0.001290066f;
a[13] = -0.0011395542f;
a[14] = -3.8172887E-4f;
a[15] = 9.0173044E-4f;
a[16] = 0.0023420234f;
a[17] = 0.003344623f;
a[18] = 0.003282209f;
a[19] = 0.0017731993f;
a[20] = -0.0010558856f;
a[21] = -0.004450674f;
a[22] = -0.0071515352f;
a[23] = -0.007778209f;
a[24] = -0.0053855875f;
a[25] = -2.6561373E-10f;
a[26] = 0.0070972904f;
a[27] = 0.013526209f;
a[28] = 0.016455514f;
a[29] = 0.013607533f;
a[30] = 0.0043148645f;
a[31] = -0.009761283f;
a[32] = -0.02458954f;
a[33] = -0.03455451f;
a[34] = -0.033946108f;
a[35] = -0.018758629f;
a[36] = 0.011756961f;
a[37] = 0.054329403f;
a[38] = 0.10202855f;
a[39] = 0.14574805f;
a[40] = 0.17644218f;
a[41] = 0.18748334f;
a[42] = 0.17644218f;
a[43] = 0.14574805f;
a[44] = 0.10202855f;
a[45] = 0.054329403f;
a[46] = 0.011756961f;
a[47] = -0.018758629f;
a[48] = -0.033946108f;
a[49] = -0.03455451f;
a[50] = -0.02458954f;
a[51] = -0.009761283f;
a[52] = 0.0043148645f;
a[53] = 0.013607533f;
a[54] = 0.016455514f;
a[55] = 0.013526209f;
a[56] = 0.0070972904f;
a[57] = -2.6561373E-10f;
a[58] = -0.0053855875f;
a[59] = -0.007778209f;
a[60] = -0.0071515352f;
a[61] = -0.004450674f;
a[62] = -0.0010558856f;
a[63] = 0.0017731993f;
a[64] = 0.003282209f;
a[65] = 0.003344623f;
a[66] = 0.0023420234f;
a[67] = 9.0173044E-4f;
a[68] = -3.8172887E-4f;
a[69] = -0.0011395542f;
a[70] = -0.001290066f;
a[71] = -9.818495E-4f;
a[72] = -4.716546E-4f;
a[73] = 3.1934875E-11f;
a[74] = 2.8903902E-4f;
a[75] = 3.6717512E-4f;
a[76] = 2.9180944E-4f;
a[77] = 1.5370155E-4f;
a[78] = 3.0053454E-5f;
a[79] = -4.0164417E-5f;
a[80] = -5.6314686E-5f;
a[81] = -4.0276995E-5f;
a[82] = -1.7250879E-5f;
* Kaiser Window FIR Filter
* Passband: 0.0 - 3000.0 Hz
* Order: 83
* Transition band: 3000.0 Hz
* Stopband attenuation: 80.0 dB
*/
a[0] = -1.7250879E-5f;
a[1] = -4.0276995E-5f;
a[2] = -5.6314686E-5f;
a[3] = -4.0164417E-5f;
a[4] = 3.0053454E-5f;
a[5] = 1.5370155E-4f;
a[6] = 2.9180944E-4f;
a[7] = 3.6717512E-4f;
a[8] = 2.8903902E-4f;
a[9] = 3.1934875E-11f;
a[10] = -4.716546E-4f;
a[11] = -9.818495E-4f;
a[12] = -0.001290066f;
a[13] = -0.0011395542f;
a[14] = -3.8172887E-4f;
a[15] = 9.0173044E-4f;
a[16] = 0.0023420234f;
a[17] = 0.003344623f;
a[18] = 0.003282209f;
a[19] = 0.0017731993f;
a[20] = -0.0010558856f;
a[21] = -0.004450674f;
a[22] = -0.0071515352f;
a[23] = -0.007778209f;
a[24] = -0.0053855875f;
a[25] = -2.6561373E-10f;
a[26] = 0.0070972904f;
a[27] = 0.013526209f;
a[28] = 0.016455514f;
a[29] = 0.013607533f;
a[30] = 0.0043148645f;
a[31] = -0.009761283f;
a[32] = -0.02458954f;
a[33] = -0.03455451f;
a[34] = -0.033946108f;
a[35] = -0.018758629f;
a[36] = 0.011756961f;
a[37] = 0.054329403f;
a[38] = 0.10202855f;
a[39] = 0.14574805f;
a[40] = 0.17644218f;
a[41] = 0.18748334f;
a[42] = 0.17644218f;
a[43] = 0.14574805f;
a[44] = 0.10202855f;
a[45] = 0.054329403f;
a[46] = 0.011756961f;
a[47] = -0.018758629f;
a[48] = -0.033946108f;
a[49] = -0.03455451f;
a[50] = -0.02458954f;
a[51] = -0.009761283f;
a[52] = 0.0043148645f;
a[53] = 0.013607533f;
a[54] = 0.016455514f;
a[55] = 0.013526209f;
a[56] = 0.0070972904f;
a[57] = -2.6561373E-10f;
a[58] = -0.0053855875f;
a[59] = -0.007778209f;
a[60] = -0.0071515352f;
a[61] = -0.004450674f;
a[62] = -0.0010558856f;
a[63] = 0.0017731993f;
a[64] = 0.003282209f;
a[65] = 0.003344623f;
a[66] = 0.0023420234f;
a[67] = 9.0173044E-4f;
a[68] = -3.8172887E-4f;
a[69] = -0.0011395542f;
a[70] = -0.001290066f;
a[71] = -9.818495E-4f;
a[72] = -4.716546E-4f;
a[73] = 3.1934875E-11f;
a[74] = 2.8903902E-4f;
a[75] = 3.6717512E-4f;
a[76] = 2.9180944E-4f;
a[77] = 1.5370155E-4f;
a[78] = 3.0053454E-5f;
a[79] = -4.0164417E-5f;
a[80] = -5.6314686E-5f;
a[81] = -4.0276995E-5f;
a[82] = -1.7250879E-5f;
/*
* Kaiser Window FIR Filter
* Passband: 0.0 - 1350.0 Hz
* modulation freq: 1650Hz
* Order: 88
* Transition band: 500.0 Hz
* Stopband attenuation: 60.0 dB
*/
/*
* Kaiser Window FIR Filter
* Passband: 0.0 - 1350.0 Hz
* modulation freq: 1650Hz
* Order: 88
* Transition band: 500.0 Hz
* Stopband attenuation: 60.0 dB
*/
b[0] = -2.081541E-4f;
b[1] = -3.5587244E-4f;
b[2] = -5.237722E-5f;
b[3] = -1.00883444E-4f;
b[4] = -8.27162E-4f;
b[5] = -7.391658E-4f;
b[6] = 9.386093E-5f;
b[7] = -6.221307E-4f;
b[8] = -0.0019506976f;
b[9] = -8.508009E-4f;
b[10] = 2.8596455E-4f;
b[11] = -0.002028003f;
b[12] = -0.003321186f;
b[13] = -2.7830937E-4f;
b[14] = 2.7148606E-9f;
b[15] = -0.004654892f;
b[16] = -0.0041854046f;
b[17] = 0.001115112f;
b[18] = -0.0017027275f;
b[19] = -0.008291345f;
b[20] = -0.0034240147f;
b[21] = 0.0027767413f;
b[22] = -0.005873899f;
b[23] = -0.011811939f;
b[24] = -2.075215E-8f;
b[25] = 0.003209243f;
b[26] = -0.0131212445f;
b[27] = -0.013072912f;
b[28] = 0.0064319638f;
b[29] = 1.0081245E-8f;
b[30] = -0.023050211f;
b[31] = -0.009034872f;
b[32] = 0.015074444f;
b[33] = -0.010180626f;
b[34] = -0.034043692f;
b[35] = 0.004729156f;
b[36] = 0.024004854f;
b[37] = -0.033643555f;
b[38] = -0.043601833f;
b[39] = 0.04075407f;
b[40] = 0.03076061f;
b[41] = -0.10492244f;
b[42] = -0.049181364f;
b[43] = 0.30635652f;
b[44] = 0.5324795f;
b[45] = 0.30635652f;
b[46] = -0.049181364f;
b[47] = -0.10492244f;
b[48] = 0.03076061f;
b[49] = 0.04075407f;
b[50] = -0.043601833f;
b[51] = -0.033643555f;
b[52] = 0.024004854f;
b[53] = 0.004729156f;
b[54] = -0.034043692f;
b[55] = -0.010180626f;
b[56] = 0.015074444f;
b[57] = -0.009034872f;
b[58] = -0.023050211f;
b[59] = 1.0081245E-8f;
b[60] = 0.0064319638f;
b[61] = -0.013072912f;
b[62] = -0.0131212445f;
b[63] = 0.003209243f;
b[64] = -2.075215E-8f;
b[65] = -0.011811939f;
b[66] = -0.005873899f;
b[67] = 0.0027767413f;
b[68] = -0.0034240147f;
b[69] = -0.008291345f;
b[70] = -0.0017027275f;
b[71] = 0.001115112f;
b[72] = -0.0041854046f;
b[73] = -0.004654892f;
b[74] = 2.7148606E-9f;
b[75] = -2.7830937E-4f;
b[76] = -0.003321186f;
b[77] = -0.002028003f;
b[78] = 2.8596455E-4f;
b[79] = -8.508009E-4f;
b[80] = -0.0019506976f;
b[81] = -6.221307E-4f;
b[82] = 9.386093E-5f;
b[83] = -7.391658E-4f;
b[84] = -8.27162E-4f;
b[85] = -1.00883444E-4f;
b[86] = -5.237722E-5f;
b[87] = -3.5587244E-4f;
b[88] = -2.081541E-4f;
b[0] = -2.081541E-4f;
b[1] = -3.5587244E-4f;
b[2] = -5.237722E-5f;
b[3] = -1.00883444E-4f;
b[4] = -8.27162E-4f;
b[5] = -7.391658E-4f;
b[6] = 9.386093E-5f;
b[7] = -6.221307E-4f;
b[8] = -0.0019506976f;
b[9] = -8.508009E-4f;
b[10] = 2.8596455E-4f;
b[11] = -0.002028003f;
b[12] = -0.003321186f;
b[13] = -2.7830937E-4f;
b[14] = 2.7148606E-9f;
b[15] = -0.004654892f;
b[16] = -0.0041854046f;
b[17] = 0.001115112f;
b[18] = -0.0017027275f;
b[19] = -0.008291345f;
b[20] = -0.0034240147f;
b[21] = 0.0027767413f;
b[22] = -0.005873899f;
b[23] = -0.011811939f;
b[24] = -2.075215E-8f;
b[25] = 0.003209243f;
b[26] = -0.0131212445f;
b[27] = -0.013072912f;
b[28] = 0.0064319638f;
b[29] = 1.0081245E-8f;
b[30] = -0.023050211f;
b[31] = -0.009034872f;
b[32] = 0.015074444f;
b[33] = -0.010180626f;
b[34] = -0.034043692f;
b[35] = 0.004729156f;
b[36] = 0.024004854f;
b[37] = -0.033643555f;
b[38] = -0.043601833f;
b[39] = 0.04075407f;
b[40] = 0.03076061f;
b[41] = -0.10492244f;
b[42] = -0.049181364f;
b[43] = 0.30635652f;
b[44] = 0.5324795f;
b[45] = 0.30635652f;
b[46] = -0.049181364f;
b[47] = -0.10492244f;
b[48] = 0.03076061f;
b[49] = 0.04075407f;
b[50] = -0.043601833f;
b[51] = -0.033643555f;
b[52] = 0.024004854f;
b[53] = 0.004729156f;
b[54] = -0.034043692f;
b[55] = -0.010180626f;
b[56] = 0.015074444f;
b[57] = -0.009034872f;
b[58] = -0.023050211f;
b[59] = 1.0081245E-8f;
b[60] = 0.0064319638f;
b[61] = -0.013072912f;
b[62] = -0.0131212445f;
b[63] = 0.003209243f;
b[64] = -2.075215E-8f;
b[65] = -0.011811939f;
b[66] = -0.005873899f;
b[67] = 0.0027767413f;
b[68] = -0.0034240147f;
b[69] = -0.008291345f;
b[70] = -0.0017027275f;
b[71] = 0.001115112f;
b[72] = -0.0041854046f;
b[73] = -0.004654892f;
b[74] = 2.7148606E-9f;
b[75] = -2.7830937E-4f;
b[76] = -0.003321186f;
b[77] = -0.002028003f;
b[78] = 2.8596455E-4f;
b[79] = -8.508009E-4f;
b[80] = -0.0019506976f;
b[81] = -6.221307E-4f;
b[82] = 9.386093E-5f;
b[83] = -7.391658E-4f;
b[84] = -8.27162E-4f;
b[85] = -1.00883444E-4f;
b[86] = -5.237722E-5f;
b[87] = -3.5587244E-4f;
b[88] = -2.081541E-4f;
/*
* Kaiser Window FIR Filter
*
* Filter type: Q-filter
* Passband: 0.0 - 1350.0 Hz
* modulation freq: 1650Hz
* with +90 degree pahse shift
* Order: 88
* Transition band: 500.0 Hz
* Stopband attenuation: 60.0 dB
*/
/*
* Kaiser Window FIR Filter
*
* Filter type: Q-filter
* Passband: 0.0 - 1350.0 Hz
* modulation freq: 1650Hz
* with +90 degree pahse shift
* Order: 88
* Transition band: 500.0 Hz
* Stopband attenuation: 60.0 dB
*/
c[0] = 6.767926E-5f;
c[1] = -2.1822347E-4f;
c[2] = -3.3091355E-4f;
c[3] = 1.1819744E-4f;
c[4] = 2.1773627E-9f;
c[5] = -8.6602167E-4f;
c[6] = -5.9300865E-4f;
c[7] = 3.814961E-4f;
c[8] = -6.342388E-4f;
c[9] = -0.00205537f;
c[10] = -5.616135E-4f;
c[11] = 4.8721067E-4f;
c[12] = -0.002414588f;
c[13] = -0.003538588f;
c[14] = -2.7166707E-9f;
c[15] = -3.665928E-4f;
c[16] = -0.0057645175f;
c[17] = -0.004647882f;
c[18] = 8.681589E-4f;
c[19] = -0.0034366683f;
c[20] = -0.010545009f;
c[21] = -0.0045342376f;
c[22] = 9.309649E-4f;
c[23] = -0.01009504f;
c[24] = -0.015788108f;
c[25] = -0.0027427748f;
c[26] = -0.0020795742f;
c[27] = -0.021347176f;
c[28] = -0.019808702f;
c[29] = -4.1785704E-9f;
c[30] = -0.011752444f;
c[31] = -0.037658f;
c[32] = -0.020762002f;
c[33] = 8.017756E-4f;
c[34] = -0.03406628f;
c[35] = -0.060129803f;
c[36] = -0.01745214f;
c[37] = -0.008082453f;
c[38] = -0.08563026f;
c[39] = -0.09845453f;
c[40] = -0.010001372f;
c[41] = -0.06433928f;
c[42] = -0.31072536f;
c[43] = -0.35893586f;
c[44] = 0.0f;
c[45] = 0.35893586f;
c[46] = 0.31072536f;
c[47] = 0.06433928f;
c[48] = 0.010001372f;
c[49] = 0.09845453f;
c[50] = 0.08563026f;
c[51] = 0.008082453f;
c[52] = 0.01745214f;
c[53] = 0.060129803f;
c[54] = 0.03406628f;
c[55] = -8.017756E-4f;
c[56] = 0.020762002f;
c[57] = 0.037658f;
c[58] = 0.011752444f;
c[59] = 4.1785704E-9f;
c[60] = 0.019808702f;
c[61] = 0.021347176f;
c[62] = 0.0020795742f;
c[63] = 0.0027427748f;
c[64] = 0.015788108f;
c[65] = 0.01009504f;
c[66] = -9.309649E-4f;
c[67] = 0.0045342376f;
c[68] = 0.010545009f;
c[69] = 0.0034366683f;
c[70] = -8.681589E-4f;
c[71] = 0.004647882f;
c[72] = 0.0057645175f;
c[73] = 3.665928E-4f;
c[74] = 2.7166707E-9f;
c[75] = 0.003538588f;
c[76] = 0.002414588f;
c[77] = -4.8721067E-4f;
c[78] = 5.616135E-4f;
c[79] = 0.00205537f;
c[80] = 6.342388E-4f;
c[81] = -3.814961E-4f;
c[82] = 5.9300865E-4f;
c[83] = 8.6602167E-4f;
c[84] = -2.1773627E-9f;
c[85] = -1.1819744E-4f;
c[86] = 3.3091355E-4f;
c[87] = 2.1822347E-4f;
c[88] = -6.767926E-5f;
c[0] = 6.767926E-5f;
c[1] = -2.1822347E-4f;
c[2] = -3.3091355E-4f;
c[3] = 1.1819744E-4f;
c[4] = 2.1773627E-9f;
c[5] = -8.6602167E-4f;
c[6] = -5.9300865E-4f;
c[7] = 3.814961E-4f;
c[8] = -6.342388E-4f;
c[9] = -0.00205537f;
c[10] = -5.616135E-4f;
c[11] = 4.8721067E-4f;
c[12] = -0.002414588f;
c[13] = -0.003538588f;
c[14] = -2.7166707E-9f;
c[15] = -3.665928E-4f;
c[16] = -0.0057645175f;
c[17] = -0.004647882f;
c[18] = 8.681589E-4f;
c[19] = -0.0034366683f;
c[20] = -0.010545009f;
c[21] = -0.0045342376f;
c[22] = 9.309649E-4f;
c[23] = -0.01009504f;
c[24] = -0.015788108f;
c[25] = -0.0027427748f;
c[26] = -0.0020795742f;
c[27] = -0.021347176f;
c[28] = -0.019808702f;
c[29] = -4.1785704E-9f;
c[30] = -0.011752444f;
c[31] = -0.037658f;
c[32] = -0.020762002f;
c[33] = 8.017756E-4f;
c[34] = -0.03406628f;
c[35] = -0.060129803f;
c[36] = -0.01745214f;
c[37] = -0.008082453f;
c[38] = -0.08563026f;
c[39] = -0.09845453f;
c[40] = -0.010001372f;
c[41] = -0.06433928f;
c[42] = -0.31072536f;
c[43] = -0.35893586f;
c[44] = 0.0f;
c[45] = 0.35893586f;
c[46] = 0.31072536f;
c[47] = 0.06433928f;
c[48] = 0.010001372f;
c[49] = 0.09845453f;
c[50] = 0.08563026f;
c[51] = 0.008082453f;
c[52] = 0.01745214f;
c[53] = 0.060129803f;
c[54] = 0.03406628f;
c[55] = -8.017756E-4f;
c[56] = 0.020762002f;
c[57] = 0.037658f;
c[58] = 0.011752444f;
c[59] = 4.1785704E-9f;
c[60] = 0.019808702f;
c[61] = 0.021347176f;
c[62] = 0.0020795742f;
c[63] = 0.0027427748f;
c[64] = 0.015788108f;
c[65] = 0.01009504f;
c[66] = -9.309649E-4f;
c[67] = 0.0045342376f;
c[68] = 0.010545009f;
c[69] = 0.0034366683f;
c[70] = -8.681589E-4f;
c[71] = 0.004647882f;
c[72] = 0.0057645175f;
c[73] = 3.665928E-4f;
c[74] = 2.7166707E-9f;
c[75] = 0.003538588f;
c[76] = 0.002414588f;
c[77] = -4.8721067E-4f;
c[78] = 5.616135E-4f;
c[79] = 0.00205537f;
c[80] = 6.342388E-4f;
c[81] = -3.814961E-4f;
c[82] = 5.9300865E-4f;
c[83] = 8.6602167E-4f;
c[84] = -2.1773627E-9f;
c[85] = -1.1819744E-4f;
c[86] = 3.3091355E-4f;
c[87] = 2.1822347E-4f;
c[88] = -6.767926E-5f;
audio_fir = init_fir( 83, a );
hilbert = init_fir( 89, c );
@ -579,6 +584,6 @@ void ssb_init( float shift_carrier) {
m_Osc1.re = 1.0; //initialize unit vector that will get rotated
m_Osc1.im = 0.0;
nco_enabled = 1 ;
nco_enabled = 1;
}
}

Wyświetl plik

@ -12,93 +12,94 @@
// Test program using SNDFILE
// see http://www.mega-nerd.com/libsndfile/api.html for API
int main(int argc, char **argv) {
float data [2*BUFFER_LEN] ;
float data_filtered[2*BUFFER_LEN] ; // we generate complex I/Q samples
SNDFILE *infile, *outfile ;
SF_INFO sfinfo ;
SF_INFO sf_out ;
int readcount, nb_samples ;
char *infilename ;
char *outfilename ;
int k ;
float x,I,Q ;
int main(int argc, char **argv)
{
float data [2*BUFFER_LEN];
float data_filtered[2*BUFFER_LEN]; // we generate complex I/Q samples
SNDFILE *infile, *outfile;
SF_INFO sfinfo;
SF_INFO sf_out;
int readcount, nb_samples;
char *infilename;
char *outfilename;
int k;
float x,I,Q;
if( argc < 2 ) {
printf("Usage : %s in.wav [out.wav]\n", argv[0]);
return(1);
}
infilename = argv[1] ;
infilename = argv[1];
if( argc == 3 ) {
outfilename = argv[2] ;
outfilename = argv[2];
} else {
outfilename = (char *)malloc( 128 );
sprintf( outfilename, "%s", "out.wav");
}
if (! (infile = sf_open (infilename, SFM_READ, &sfinfo)))
{ /* Open failed so print an error message. */
printf ("Not able to open input file %s.\n", infilename) ;
/* Print the error message from libsndfile. */
puts (sf_strerror (NULL)) ;
return 1 ;
} ;
if (! (infile = sf_open (infilename, SFM_READ, &sfinfo)))
{
/* Open failed so print an error message. */
printf ("Not able to open input file %s.\n", infilename);
/* Print the error message from libsndfile. */
puts (sf_strerror (NULL));
return 1;
}
if( sfinfo.samplerate != 48000 ) {
printf("Input rate must be 48K.\n");
return 1 ;
return 1;
}
memcpy( (void *)&sf_out, (void *)&sfinfo, sizeof( SF_INFO ));
sf_out.channels = 2 ;
//sf_out.samplerate = sfinfo.samplerate/3 ;
/* Open the output file. */
if (! (outfile = sf_open (outfilename, SFM_WRITE, &sf_out)))
{ printf ("Not able to open output file %s.\n", outfilename) ;
puts (sf_strerror (NULL)) ;
return 1 ;
} ;
sf_out.channels = 2;
//sf_out.samplerate = sfinfo.samplerate/3;
/* Open the output file. */
if (! (outfile = sf_open (outfilename, SFM_WRITE, &sf_out)))
{
printf ("Not able to open output file %s.\n", outfilename);
puts (sf_strerror (NULL));
return 1;
}
/** **/
printf ("Reading file : %s\n", infilename ) ;
printf ("Sample Rate : %d\n", sfinfo.samplerate) ;
printf ("Channels : %d\n", sfinfo.channels) ;
printf ("----------------------------------------\n") ;
printf ("Writing file : %s\n", outfilename ) ;
printf ("Channels : %d\n", sf_out.channels) ;
printf ("Reading file : %s\n", infilename );
printf ("Sample Rate : %d\n", sfinfo.samplerate);
printf ("Channels : %d\n", sfinfo.channels);
printf ("----------------------------------------\n");
printf ("Writing file : %s\n", outfilename );
printf ("Channels : %d\n", sf_out.channels);
// la porteuse SSB est décalée de +1K
ssb_init( 1000 );
/* While there are.frames in the input file, read them, process
** them and write them to the output file.
*/
while ((readcount = sf_readf_float(infile, data, BUFFER_LEN)))
{
nb_samples = readcount / sfinfo.channels ;
/* While there are.frames in the input file, read them, process
** them and write them to the output file.
*/
while ((readcount = sf_readf_float(infile, data, BUFFER_LEN)))
{
nb_samples = readcount / sfinfo.channels;
for( k=0 ; k < nb_samples ; k++ ) {
x = data[k*sfinfo.channels] ;
x = data[k*sfinfo.channels];
if( sfinfo.channels == 2 ) {
// stereo file, avg left + right
x += data[k*sfinfo.channels+1] ;
x /= 2 ;
x += data[k*sfinfo.channels+1];
x /= 2;
}
// voir ssb_gen.h, mettre MODULE_SSB_LSB pour LSB module
ssb( x, MODULE_SSB_USB , &I, &Q );
data_filtered[2*k ] = I ; //I and Q seems to be between 0 and 0.5
data_filtered[2*k+1] = Q ;
data_filtered[2*k ] = I; //I and Q seems to be between 0 and 0.5
data_filtered[2*k+1] = Q;
/* // FOR COMPRESSOR *2
data_filtered[2*k ] = I * 2; //I and Q seems to be between 0 and 0.5
data_filtered[2*k+1] = Q * 2;
*/
}
sf_write_float(outfile, data_filtered, 2*nb_samples ) ;
} ;
sf_write_float(outfile, data_filtered, 2*nb_samples );
}
/* Close input and output files. */
sf_close (infile) ;
sf_close (outfile) ;
sf_close (infile);
sf_close (outfile);
return 0;
}

Wyświetl plik

@ -20,77 +20,74 @@ static double GlobalTuningFrequency=00000.0;
void playtone(double Frequency,uint32_t Timing)
{
typedef struct {
double Frequency;
uint32_t WaitForThisSample;
} samplerf_t;
samplerf_t RfSample;
RfSample.Frequency=GlobalTuningFrequency+Frequency;
RfSample.WaitForThisSample=Timing*100L; //en 100 de nanosecond
//printf("Freq =%f Timing=%d\n",RfSample.Frequency,RfSample.WaitForThisSample);
if (write(FileFreqTiming,&RfSample,sizeof(samplerf_t)) != sizeof(samplerf_t)) {
fprintf(stderr, "Unable to write sample");
}
}
void addvisheader()
{
printf( "Adding VIS header to audio data.\n" ) ;
// bit of silence
playtone( 0 , 5000000) ;
// attention tones
playtone( 1900 , 100000 ) ; // you forgot this one
playtone( 1500 , 1000000) ;
playtone( 1900 , 1000000) ;
playtone( 1500 , 1000000) ;
playtone( 2300 , 1000000) ;
playtone( 1500 , 1000000) ;
playtone( 2300 , 1000000) ;
playtone( 1500 , 1000000) ;
// VIS lead, break, mid, start
playtone( 1900 , 3000000) ;
playtone( 1200 , 100000) ;
// playtone( 1500 , 300000 ) ;
playtone( 1900 , 3000000) ;
playtone( 1200 , 300000) ;
// VIS data bits (Martin 1)
playtone( 1300 , 300000) ;
playtone( 1300 , 300000) ;
playtone( 1100 , 300000) ;
playtone( 1100 , 300000) ;
playtone( 1300 , 300000) ;
playtone( 1100 , 300000) ;
playtone( 1300 , 300000 ) ;
playtone( 1100 , 300000 ) ;
// VIS stop
playtone( 1200 , 300000 ) ;
printf( "Done adding VIS header to audio data.\n" ) ;
printf( "Adding VIS header to audio data.\n" ) ;
// bit of silence
playtone( 0 , 5000000) ;
// attention tones
playtone( 1900 , 100000 ) ; // you forgot this one
playtone( 1500 , 1000000) ;
playtone( 1900 , 1000000) ;
playtone( 1500 , 1000000) ;
playtone( 2300 , 1000000) ;
playtone( 1500 , 1000000) ;
playtone( 2300 , 1000000) ;
playtone( 1500 , 1000000) ;
// VIS lead, break, mid, start
playtone( 1900 , 3000000) ;
playtone( 1200 , 100000) ;
//playtone( 1500 , 300000 ) ;
playtone( 1900 , 3000000) ;
playtone( 1200 , 300000) ;
// VIS data bits (Martin 1)
playtone( 1300 , 300000) ;
playtone( 1300 , 300000) ;
playtone( 1100 , 300000) ;
playtone( 1100 , 300000) ;
playtone( 1300 , 300000) ;
playtone( 1100 , 300000) ;
playtone( 1300 , 300000 ) ;
playtone( 1100 , 300000 ) ;
// VIS stop
playtone( 1200 , 300000 ) ;
printf( "Done adding VIS header to audio data.\n" ) ;
} // end addvisheader
void addvistrailer ()
{
printf( "Adding VIS trailer to audio data.\n" ) ;
playtone( 2300 , 3000000 ) ;
playtone( 1200 , 100000 ) ;
playtone( 2300 , 1000000 ) ;
playtone( 1200 , 300000 ) ;
// bit of silence
playtone( 0 , 5000000 ) ;
printf( "Done adding VIS trailer to audio data.\n" ) ;
printf( "Adding VIS trailer to audio data.\n" ) ;
playtone( 2300 , 3000000 ) ;
playtone( 1200 , 100000 ) ;
playtone( 2300 , 1000000 ) ;
playtone( 1200 , 300000 ) ;
// bit of silence
playtone( 0 , 5000000 ) ;
printf( "Done adding VIS trailer to audio data.\n" ) ;
}
void ProcessMartin1()
@ -98,78 +95,70 @@ void ProcessMartin1()
static uint32_t FrequencyMartin1[3]={1200,1500,1500};
static uint32_t TimingMartin1[3]={48720,5720,4576};
int EndOfPicture=0;
int NbRead=0;
int VIS=1;
static unsigned char Line[320*3];
int Row;
int Row;
addvisheader();
addvistrailer();
while(EndOfPicture==0)
{
NbRead=read(FilePicture,Line,320*3);
if(NbRead!=320*3) EndOfPicture=1;
//MARTIN 1 Implementation
//Horizontal SYNC
playtone((double)FrequencyMartin1[0],TimingMartin1[0]);
//Separator Tone
playtone((double)FrequencyMartin1[1],TimingMartin1[1]);
addvisheader();
addvistrailer();
while(EndOfPicture==0)
{
NbRead=read(FilePicture,Line,320*3);
if(NbRead!=320*3) EndOfPicture=1;
//MARTIN 1 Implementation
//Horizontal SYNC
playtone((double)FrequencyMartin1[0],TimingMartin1[0]);
//Separator Tone
playtone((double)FrequencyMartin1[1],TimingMartin1[1]);
for(Row=0;Row<320;Row++)
{
playtone((double)FrequencyMartin1[1]+Line[Row*3+1]*800/256,TimingMartin1[2]);
}
playtone((double)FrequencyMartin1[1],TimingMartin1[1]);
for(Row=0;Row<320;Row++)
{
playtone((double)FrequencyMartin1[1]+Line[Row*3+1]*800/256,TimingMartin1[2]);
}
playtone((double)FrequencyMartin1[1],TimingMartin1[1]);
//Blue
for(Row=0;Row<320;Row++)
{
playtone((double)FrequencyMartin1[1]+Line[Row*3+2]*800/256,TimingMartin1[2]);
}
playtone((double)FrequencyMartin1[1],TimingMartin1[1]);
//Blue
for(Row=0;Row<320;Row++)
{
playtone((double)FrequencyMartin1[1]+Line[Row*3+2]*800/256,TimingMartin1[2]);
}
playtone((double)FrequencyMartin1[1],TimingMartin1[1]);
//Red
for(Row=0;Row<320;Row++)
{
playtone((double)FrequencyMartin1[1]+Line[Row*3]*800/256,TimingMartin1[2]);
}
playtone((double)FrequencyMartin1[1],TimingMartin1[1]);
}
//Red
for(Row=0;Row<320;Row++)
{
playtone((double)FrequencyMartin1[1]+Line[Row*3]*800/256,TimingMartin1[2]);
}
playtone((double)FrequencyMartin1[1],TimingMartin1[1]);
}
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
if (argc > 2) {
if (argc > 2)
{
char *sFilePicture=(char *)argv[1];
FilePicture = open(argv[1], O_RDONLY);
char *sFileFreqTiming=(char *)argv[2];
FileFreqTiming = open(argv[2], O_WRONLY|O_CREAT, 0644);
}
else
{
printf("usage : pisstv picture.rgb outputfreq.bin\n");
exit(0);
}
FilePicture = open(argv[1], O_RDONLY);
ProcessMartin1();
close(FilePicture);
close(FileFreqTiming);
return 0;
char *sFileFreqTiming=(char *)argv[2];
FileFreqTiming = open(argv[2], O_WRONLY|O_CREAT, 0644);
}
else
{
printf("usage : pisstv picture.rgb outputfreq.bin\n");
exit(0);
}
ProcessMartin1();
close(FilePicture);
close(FileFreqTiming);
return 0;
}