From 42515954456d89ddd1a815a8df0f5c8b8d9daddf Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Tue, 14 Jun 2022 20:05:13 +0000 Subject: [PATCH] - fixed problems git-svn-id: http://moon:8086/svn/software/trunk/libsrc/cpp@970 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- radio/tests/interpolation/farrow/test.cpp | 78 ++++++++++++++++++++--- 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/radio/tests/interpolation/farrow/test.cpp b/radio/tests/interpolation/farrow/test.cpp index 2a3906d..59f9e46 100644 --- a/radio/tests/interpolation/farrow/test.cpp +++ b/radio/tests/interpolation/farrow/test.cpp @@ -11,7 +11,7 @@ using namespace std; using namespace Radio; -CVec wavLoad(const char *pName) +CVec wavLoad(const char *pName, WAVEHEADER &format) { WAV wav; WavOpen(&wav, pName); @@ -38,10 +38,45 @@ CVec wavLoad(const char *pName) } remain -= numRead; } + format = wav.m_Format; + WavClose(&wav); return res; } +void wavSave(const char *pName, WAVEHEADER const &format, CVec &iq) +{ + WAV wav; + WavCreate(&wav, pName, FILETYPE_WAV, &format); + + const size_t BLOCK_SIZE = 65536; + int16_t *pWavInterleaved = (int16_t*)malloc(BLOCK_SIZE*wav.m_nChannels*sizeof(int16_t)); + + float *pWav[2]; + + pWav[0] = (float*)malloc(BLOCK_SIZE*sizeof(float)); + pWav[1] = (float*)malloc(BLOCK_SIZE*sizeof(float)); + + size_t remain = iq.size(); + size_t k=0; + while(remain) + { + size_t size = std::min(remain, BLOCK_SIZE); + for (int j=0; j < size; j++) + { + pWav[0][j] = iq[k].real(); + pWav[1][j] = iq[k].imag(); + k++; + } + WavIlvdFloat(&wav, pWav, pWavInterleaved, size); + WavWrite(&wav, pWavInterleaved, size); + + remain -= size; + } + WavClose(&wav); + +} + const radio_float_t STR_GAIN_LEAD_AQU = (radio_float_t)4.00E-4; // 2E-3 const radio_float_t STR_GAIN_LAG_AQU = (radio_float_t)0.50E-6; // 5E-7 const radio_float_t STR_GAIN_LEAD_TRK = (radio_float_t)4.00E-6; // 8E-4 @@ -55,7 +90,10 @@ void test() farrow.load("/home/jens/farrow_coeff.dat"); // Setup IQ data - CVec iq = wavLoad("m2_12k_12k_i_q.wav"); + WAVEHEADER header; +// CVec iq_in = wavLoad("m2_12k_12k_i_q_short.wav", header); + CVec iq_in = wavLoad("sine.wav", header); + CVec iq_out(4*iq_in.size()); // Loop-Filter lead_lag_filter_t loop_filter_str; @@ -70,20 +108,42 @@ void test() radio_float_t vc=0; radio_float_t vd=0; - for (size_t n = 0; n < iq.size(); n++) + ComplexScalar iq_ip; + size_t k=0; + size_t n=0; + size_t remain = iq_in.size(); + const size_t BLOCKSIZE=1024; + while(remain) { + size_t size = std::min(BLOCKSIZE, remain); // @2 x symbolrate - vc = LeadLagProcess(&loop_filter_str, &str_loopfilter_coeff, vd); - // Matched filtering and interpolation - ComplexScalar iq_ip = farrow.process_new(iq[n], vc); + size_t numFed = farrow.feed(&iq_in.data()[n], size); + n += numFed; + remain -= numFed; - // Symbol timing recovery - vd = STRGardnerProcess(&m_SymbolTimingRevovery, toCpx(iq_ip)); - cout << "Vd = " << vd << ", Vc = " << vc << endl; + farrow.process_new(0.25); + while(farrow.getOutputBuffer().len()) + { + size_t size = std::min(BLOCKSIZE, farrow.getOutputBuffer().len()); + for (size_t i=0; i < size; i++) + { + iq_out[k++] = farrow.getOutputBuffer().readAt(0); + } + } + + if (false) + { + // Symbol timing recovery + vd = STRGardnerProcess(&m_SymbolTimingRevovery, toCpx(iq_ip)); + vc = LeadLagProcess(&loop_filter_str, &str_loopfilter_coeff, vd); + // cout << "Vd = " << vd << ", Vc = " << vc << endl; + } } + wavSave("out.wav", header, iq_out); + cout << "End of program" << endl; }