bitwav.cpp
上传用户:jtjnyq9001
上传日期:2014-11-21
资源大小:3974k
文件大小:3k
源码类别:

3G开发

开发平台:

Visual C++

  1. //
  2. //  File = bitwav.cpp
  3. //
  4. #include <stdlib.h>
  5. #include <fstream>
  6. #include "parmfile.h"
  7. #include "bitwav.h"
  8. #include "model_graph.h"
  9. //#include "uni_rand.h"
  10. extern ParmFile *ParmInput;
  11. //======================================================
  12. BitsToWave::BitsToWave( char* instance_name,
  13.                         PracSimModel* outer_model,
  14.                         Signal<bit_t>* in_sig,
  15.                         Signal<float>* out_sig,
  16.                         Signal<bit_t>* bit_clock_out )
  17.                 :PracSimModel(instance_name,
  18.                               outer_model)
  19. {
  20.   MODEL_NAME(BitsToWave);
  21.   ENABLE_MULTIRATE;
  22.   //---------------------------------------
  23.   //  Read model config parms
  24.   OPEN_PARM_BLOCK;
  25.   GET_DOUBLE_PARM( Pulse_Duration );
  26.   GET_DOUBLE_PARM( Delay_To_First_Edge );
  27.   GET_DOUBLE_PARM( Lo_Val );
  28.   GET_DOUBLE_PARM( Hi_Val );
  29.   GET_FLOAT_PARM( Samps_Per_Bit );
  30.   //--------------------------------------
  31.   //  Connect input and output signals
  32.   In_Sig = in_sig;
  33.   Out_Sig = out_sig;
  34.   Bit_Clock_Out = bit_clock_out;
  35.   MAKE_OUTPUT( Out_Sig );
  36.   MAKE_OUTPUT( Bit_Clock_Out );
  37.   MAKE_INPUT( In_Sig );
  38.   double resamp_rate = double(Samps_Per_Bit);
  39.   // one sample per bit at input
  40.   SET_SAMP_INTVL( In_Sig, Pulse_Duration)
  41.   CHANGE_RATE( In_Sig, Out_Sig, resamp_rate );
  42.   CHANGE_RATE( In_Sig, Bit_Clock_Out, resamp_rate );
  43.   }
  44. //======================================
  45. BitsToWave::~BitsToWave( void ){ };
  46. //=======================================
  47. void BitsToWave::Initialize(void)
  48. {
  49.   //------------------
  50.   Last_Bit_Val = 0.0;
  51.   double samp_intvl = Out_Sig->GetSampIntvl();
  52.   Samps_In_Curr_Bit = (Pulse_Duration - Delay_To_First_Edge)
  53.                       /samp_intvl - 1.0;
  54.   Out_Avg_Block_Size = Out_Sig->GetBlockSize();
  55.   In_Avg_Block_Size = In_Sig->GetBlockSize();
  56.   Samps_Per_Bit = float(Out_Avg_Block_Size)/In_Avg_Block_Size;
  57. }
  58. //=======================================================
  59. int BitsToWave::Execute()
  60. {
  61.   float last_bit_val;
  62.   double samps_in_curr_bit, samps_per_bit;
  63.   float lo_val, hi_val;
  64.   int next_bit_val;
  65.   float *waveform_out;
  66.   bit_t *bits_in;
  67.   bit_t *bit_clock_out_ptr;
  68.   int is;
  69.   int in_block_size;
  70.   int out_block_size;
  71.   last_bit_val = Last_Bit_Val;
  72.   samps_in_curr_bit = Samps_In_Curr_Bit;
  73.   samps_per_bit = Samps_Per_Bit;
  74.   lo_val = Lo_Val;
  75.   hi_val = Hi_Val;
  76.   waveform_out = GET_OUTPUT_PTR( Out_Sig );
  77.   bit_clock_out_ptr = GET_OUTPUT_PTR( Bit_Clock_Out );
  78.   bits_in = GET_INPUT_PTR( In_Sig );
  79.   in_block_size = In_Sig->GetValidBlockSize();
  80.   out_block_size = int(samps_per_bit * in_block_size);
  81.   Out_Sig->SetValidBlockSize(out_block_size);
  82.   Bit_Clock_Out->SetValidBlockSize(out_block_size);
  83.   for (is=0; is<out_block_size; is++)
  84.     {
  85.     samps_in_curr_bit++;
  86.     if(samps_in_curr_bit >= samps_per_bit)
  87.       {
  88.       next_bit_val = *bits_in++;
  89.       if(next_bit_val == 0)
  90.         last_bit_val = lo_val;
  91.       else
  92.         last_bit_val = hi_val;
  93.       samps_in_curr_bit -= samps_per_bit;
  94.       }
  95.     *waveform_out++ = last_bit_val;
  96.     //*waveform_out++ = is;
  97.     if(samps_in_curr_bit+1 >= samps_per_bit)
  98.       {
  99.       *bit_clock_out_ptr++ = 1;
  100.       }
  101.     else
  102.       {
  103.       *bit_clock_out_ptr++ = 0;
  104.       }
  105.     }
  106.   Last_Bit_Val = last_bit_val;
  107.   Samps_In_Curr_Bit = samps_in_curr_bit;
  108.   return(_MES_AOK);
  109. }