⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contin_delay_t.cpp

📁 无线通信仿真C++使用模型配套代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  //*DebugFile << "sum2 = " << sum2 << endl;

}

//=======================================
template< class T >
int ContinuousDelay<T>::Execute()
{
  T *start_of_buffer, *end_of_buffer;
  T *read_ptr, *write_ptr;
  T input_samp, *input_signal_ptr;
  T output_samp, *output_signal_ptr;
  T left_samp, right_samp;
  T sum;
  int num_sidelobes;
  int max_buf_len;
  int is, block_size;
  double samp_intvl;
  float *sinc_val;
  float interp_weight, one_minus_weight;

  // collect plotting data for signals in current 
  // block-synchronous enclave before incrementing 
  // to next enclave
  SigPlot.CollectData();
  EnclaveNumber++;
  *DebugFile << "moved to Enclave " << EnclaveNumber << endl;

  //-----------------------------------------
  // Get pointers for input and output signals
  
  output_signal_ptr = GET_OUTPUT_PTR(Out_Sig);
  input_signal_ptr = GET_INPUT_PTR(In_Sig);

  block_size = In_Sig->GetValidBlockSize();
  Out_Sig->SetValidBlockSize(block_size);

  //------------------------------------------------
  //  Do actions peculiar to each delay mode

  switch (Delay_Mode)
    {
    //- - - - - - - - - - - - - - - - - - - - - - 
    case DELAY_MODE_NONE:
      {
      for(is=0; is<Block_Size; is++)
        {
        input_samp = *input_signal_ptr++;
        *output_signal_ptr++ =input_samp;
        }
      return(_MES_AOK);
      }
    //- - - - - - - - - - - - - - - - - - - - - - 
    case DELAY_MODE_FIXED:
      {
      break;
      }
    //- - - - - - - - - - - - - - - - - - - - - - 
    case DELAY_MODE_GATED:
      {
      //  If delay change is NOT enabled, get out of switch.
      //  If delay change IS enabled, fall through to next case
      //  and get new value for Active_Delay.

      if( Delay_Change_Enabled->GetValue() == false )
        {
        break;
        }
      }
    //- - - - - - - - - - - - - - - - - - - - - - 
    case DELAY_MODE_DYNAMIC:
      {
      Active_Delay = New_Delay->GetValue();
      double active_delay_in_samps = Active_Delay/Samp_Intvl;
      Active_Buffer_Len = 1 + int(floor(active_delay_in_samps));
      Interp_Weight = active_delay_in_samps - floor(active_delay_in_samps);
      if(Interp_Weight > 0.999999) Interp_Weight = 1.0;
      if(Interp_Weight < 0.000001) Interp_Weight = 0.0;
      One_Minus_Weight = 1.0 - Interp_Weight;

      Read_Ptr = Write_Ptr - Active_Buffer_Len;
      if(Read_Ptr < Start_Of_Buffer) Read_Ptr += Max_Buffer_Len;

      break;
      }
    } // end of switch on Delay_Mode

  //------------------------------------------------
  //  copy frequently used items into local storage

  block_size = Block_Size;
  samp_intvl = Samp_Intvl;
  read_ptr = Read_Ptr;
  write_ptr = Write_Ptr;
  start_of_buffer = Start_Of_Buffer;
  end_of_buffer = End_Of_Buffer;
  interp_weight = Interp_Weight;
  one_minus_weight = One_Minus_Weight;
  sinc_val = Sinc_Val;

  //-----------------------------------------------------
  // if active delay is zero, just copy input to output

  if(Active_Delay == 0)
    {
    for(is=0; is<block_size; is++)
      {
      input_samp = *input_signal_ptr++;
      *output_signal_ptr++ =input_samp;
      }
    return(_MES_AOK);
    }

  //---------------------------------------------------
  //  error condition if active delay exceeds max delay

  if(Active_Delay > Max_Delay)
    {
    ostrstream temp_stream;
    temp_stream << "Active_Delay (" << Active_Delay
                 << ") is greater than Max_Delay ("
                 << Max_Delay << ")." << ends;
    char *message = temp_stream.str();
    PsModelError(FATAL, message);
    delete []message;

    }

  //----------------------------------------------------------------
  // if the number of blocks already loaded into buffer is less than 
  // the offset between the input enclave and output enclave, then
  // the current input block needs to be loaded into buffer 

  if(Num_Blocks_Skipped < Blocks_Of_Offset)
    {
    for(is=0; is<block_size; is++)
      {
      input_samp = *input_signal_ptr++;
      *write_ptr++ = input_samp;
      }
    if(write_ptr > end_of_buffer) write_ptr = start_of_buffer;
    Num_Blocks_Skipped++;
    }

  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  // if the number of blocks already loaded into the buffer equals 
  // or exceeds the offset between the input enclave and output enclave,
  // then everything is ready for normal operation

  else
    {
    Return_Status = _MES_AOK;
    New_Pass_Number++;
    //--------------------------------------------------
    //  normal sample processing

    switch (Interp_Mode)
      {
      case INTERP_MODE_LINEAR:
        for(is=0; is<block_size; is++)
          {
          input_samp = *input_signal_ptr++;

          //---------------------------------------------------------------
          // get samps that bracket desired time instant from delay buffer
    
          left_samp = *read_ptr++;
          if(read_ptr > end_of_buffer) read_ptr = start_of_buffer;
          if(Active_Delay < Samp_Intvl)
            right_samp = input_samp;
          else
            right_samp = *read_ptr;

          //------------------------------------------
          // do interpolation to get output value

          output_samp = interp_weight*left_samp + one_minus_weight*right_samp;

          //------------------------------------
          // put input sample into delay buffer

          *write_ptr++ = input_samp;
          if(write_ptr > end_of_buffer) write_ptr = start_of_buffer;

          *output_signal_ptr++ =output_samp;
          }
        break;
      case INTERP_MODE_SINC:
        num_sidelobes = Num_Sidelobes;
        max_buf_len = Max_Buffer_Len;
        for(is=0; is<block_size; is++)
          {
          input_samp = *input_signal_ptr++;
          //read_ptr = start_of_buffer + is + max_buf_len - Offset_Sum_Start_To_Out_Samp - 1;
          //read_ptr = start_of_buffer + is + max_buf_len - Offset_Sum_Start_To_Out_Samp;
          //if( read_ptr < start_of_buffer) read_ptr += max_buf_len;
          //if( read_ptr > end_of_buffer) read_ptr -= max_buf_len;
          read_ptr = Read_Ptr_Start;
          Read_Ptr_Start++;
          if(Read_Ptr_Start > end_of_buffer) Read_Ptr_Start = start_of_buffer;

          sum = 0.0;
          //*DebugFile << *read_ptr << " makes ";
          for(int sum_idx=0; sum_idx< 2*Num_Sidelobes; sum_idx++)
            {
            sum += (*read_ptr) * sinc_val[sum_idx];
            read_ptr++;
            if(read_ptr > end_of_buffer) read_ptr = start_of_buffer;
            }

          //*DebugFile << sum << " put " << (void*)output_signal_ptr << endl;
          //------------------------------------
          // put input sample into delay buffer

          *write_ptr++ = input_samp;
          if(write_ptr > end_of_buffer) 
          {
              write_ptr = start_of_buffer;
              //*DebugFile << "write wrap " << is << endl;
           }

          *output_signal_ptr++ = sum;
          }
        break;
    default:
      ostrstream temp_stream;
      temp_stream << "Requested interpolation mode is not supported"
                   << ends;
      char *message = temp_stream.str();
      PsModelError(FATAL, message);
      delete []message;
    } // end of switch om Interp_Mode
   }
//   *(output_signal_ptr-1)=50.0;

  PassNumber = New_Pass_Number;
  Read_Ptr = read_ptr;
  Write_Ptr = write_ptr;
  return(Return_Status);
}
template ContinuousDelay< int >;
template ContinuousDelay< float >;
template ContinuousDelay< std::complex<float> >;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -