void
WindowingThread::OnInitialize( const SignalProperties& Input,
                               const SignalProperties& Output )
{
  size_t numSamples = Output.Elements();
  mBuffers.clear();
  mBuffers.resize( Channels().size(), DataVector( numSamples ) );
  mInputElements = Input.Elements();

  mDetrend = Parameter( "Detrend" );
  if( mDetrend == None )
    mDetrendBuffer.resize( 0 );
  else
    mDetrendBuffer.resize( numSamples );

  mWindowFunction = Parameter( "WindowFunction" );
  mWindow.resize( numSamples );
  Real phasePerSample = M_PI / numSamples;
  // Window coefficients: Rect Hamming Hann Blackman
  const Real a1[] = {    0,   0.46,  0.5, 0.5, },
             a2[] = {    0,   0,     0,   0.08 };
  for( size_t i = 0; i < numSamples; ++i )
    mWindow[i] = 1 - a1[mWindowFunction] - a2[mWindowFunction]
                   + a1[mWindowFunction] * cos( i * phasePerSample )
                   + a2[mWindowFunction] * cos( i * 2 * phasePerSample );
}
void
ARThread::OnPreflight( const SignalProperties& Input,
                             SignalProperties& Output ) const
{
  if( Input.Elements() < Parameter( "ModelOrder" ) )
    bcierr << "WindowLength parameter must be large enough"
           << " for the number of samples to exceed the model order"
           << endl;

  if( Parameter( "OutputType" ) == Coefficients )
  {
    Output = Input;
    Output.SetName( "AR Coefficients" );
    Output.SetElements( Parameter( "ModelOrder" ) );
    Output.ElementUnit().SetSymbol( "" )
                        .SetOffset( 0 )
                        .SetGain( 1 )
                        .SetRawMin( 0 )
                        .SetRawMax( Output.Elements() - 1 );
  }
  else
  {
    SpectrumThread::OnPreflight( Input, Output );
    Output.SetName( "AR " + Output.Name() );
  }
}
void
ARThread::OnInitialize( const SignalProperties& Input, const SignalProperties& Output )
{
  mMEMPredictor.SetModelOrder( Parameter( "ModelOrder" ) );
  mOutputType = Parameter( "OutputType" );
  if( mOutputType != Coefficients )
  {
    mTransferSpectrum.SetFirstBinCenter( Parameter( "FirstBinCenter" ).InHertz() / Input.SamplingRate() );
    mTransferSpectrum.SetBinWidth( Parameter( "BinWidth" ).InHertz() / Input.SamplingRate() );
    mTransferSpectrum.SetNumBins( Output.Elements() );
    mTransferSpectrum.SetEvaluationsPerBin( Parameter( "EvaluationsPerBin" ) );
    mSpectrum.resize( Output.Elements() );
  }
  mInput.resize( Input.Elements() );
}
示例#4
0
bool
SignalProperties::Accommodates( const SignalProperties& sp ) const
{
  if( sp.IsEmpty() )
    return true;
  if( IsEmpty() )
    return false;
  if( !SignalType::ConversionIsSafe( sp.Type(), Type() ) )
    return false;
  if( Elements() < sp.Elements() )
    return false;
  if( Elements() < sp.Elements() )
    return false;
  return true;
}
void
WindowingThread::OnPreflight( const SignalProperties& Input,
                                    SignalProperties& Output ) const
{
  Output = Input;
  double windowLength = Parameter( "WindowLength" ).InSampleBlocks();
  int numSamples = static_cast<int>( windowLength * Input.Elements() );
  if( numSamples < 0 )
  {
    bcierr << "WindowLength parameter must be >= 0" << endl;
    numSamples = 0;
  }
  Output.SetElements( numSamples )
        .SetIsStream( false )
        .ElementUnit().SetRawMin( 0 )
                      .SetRawMax( Output.Elements() - 1 );
}
void
FFTFilter::DetermineSignalProperties( SignalProperties& ioProperties, int inFFTType ) const
{
  int numChannels = Parameter( "FFTInputChannels" )->NumValues(),
      fftWindowLength = static_cast<int>( ioProperties.Elements() * Parameter( "FFTWindowLength" ).InSampleBlocks() );
  if( numChannels > 0 && fftWindowLength == 0 )
    bcierr << "FFTWindowLength must exceed a single sample's duration" << endl;
  double freqRange = ioProperties.SamplingRate() / 2.0;

  switch( inFFTType )
  {
    case eInput:
      break;

    case ePower:
    {
      ioProperties.SetName( "FFT Power Spectrum" )
                  .SetChannels( numChannels )
                  .SetElements( fftWindowLength / 2 + 1 );
      ioProperties.ElementUnit().SetOffset( 0.0 )
                                .SetGain( freqRange / ( ioProperties.Elements() - 1 ) )
                                .SetSymbol( "Hz" );
      double amplitude = ioProperties.ValueUnit().RawMax() - ioProperties.ValueUnit().RawMin();
      ioProperties.ValueUnit().SetRawMin( 0 )
                              .SetRawMax( amplitude * amplitude );
      ioProperties.ElementUnit().SetRawMin( 0 )
                                .SetRawMax( ioProperties.Elements() - 1 );
    } break;

    case eHalfcomplex:
      ioProperties.SetName( "FFT Coefficients" )
                  .SetChannels( numChannels )
                  .SetElements( fftWindowLength );
      ioProperties.ElementUnit().SetRawMin( 0 )
                                .SetRawMax( fftWindowLength - 1 )
                                .SetOffset( 0 )
                                .SetGain( 1 )
                                .SetSymbol( "" );
      break;

    default:
      throw std_logic_error( "Unknown value of FFT type" );
  }
}
void
CustomFIRFilter::Initialize( const SignalProperties& Input, const SignalProperties& /*Output*/ )
{
  mBuffer.clear();

  ParamRef FIRCoefficients = Parameter( "FIRCoefficients" );
  int filterLength = FIRCoefficients->NumValues();
  mFilter.resize( filterLength, 0.0 );
  for( int sample = 0; sample < filterLength; ++sample )
    mFilter[sample] = FIRCoefficients( sample );

  int bufferLength = filterLength + Input.Elements() - 1;
  mBuffer.resize( Input.Channels(), DataVector( 0.0, bufferLength ) );
}
void
AverageDisplay::Preflight( const SignalProperties& Input, SignalProperties& Output ) const
{
  PreflightCondition( Parameter( "AvgDisplayCh" )->NumColumns() >= 2 );
  for( int i = 0; i < Parameter( "AvgDisplayCh" )->NumRows(); ++i )
    PreflightCondition
    (
      Parameter( "AvgDisplayCh" )( i, 0 ) > 0
      && Parameter( "AvgDisplayCh" )( i, 0 ) <= Input.Channels()
    );
  PreflightCondition( Parameter( "SamplingRate" ) > 0 );
  PreflightCondition( Input.Elements() > 0 );
  State( "TargetCode" );
  Output = Input;
}
void
TSWFilter::Initialize( const SignalProperties& Input, const SignalProperties& )
{
  mBlockSize = Input.Elements();
  mBlocksInTrial = static_cast<unsigned int>( Parameter( "FeedbackEnd" ).InSampleBlocks() );
  mBufferOffset = mBlocksInTrial;
  mAvgBufferSize = mBufferOffset + mBlocksInTrial + 1;
  mAvgSpan = static_cast<unsigned int>( Parameter( "SWAvgSpan" ).InSampleBlocks() );

  mSWCh = Parameter( "SWInChList" )->NumValues();
  mSWInChList.resize( mSWCh );
  mSWOutChList.resize( mSWCh );
  mThresholdAmp.resize( mSWCh );
  for( int i = 0; i < mSWCh; ++i )
  {
    mSWInChList[ i ] = static_cast<int>( Parameter( "SWInChList" )( i ) - 1 );
    mSWOutChList[ i ] = static_cast<int>( Parameter( "SWOutChList" )( i ) - 1 );
    mThresholdAmp[ i ] = Parameter( "ThresholdAmp" )( i );
  }

  mAvgBlockBuffer = GenericSignal( mSWCh, mAvgBufferSize );
  for( int n = 0; n < mAvgBufferSize; n++ )
    for( int m = 0; m < mSWCh; m++ )
      mAvgBlockBuffer( m, n ) = 0;
  mMaxValue.clear();
  mMaxValue.resize( mSWCh, -inf );
  mMinValue.clear();
  mMinValue.resize( mSWCh, inf );

  mPosInBuffer = mBufferOffset - 1;

  // Tc-correction variables:
  double timeConstant = Parameter( "Tc" ).InSampleBlocks();
  if( timeConstant == 0 )
    mTcFactor = 0;
  else
    mTcFactor = 1.0 - ::exp( -timeConstant );
  mTcAk.clear();
  mTcAk.resize( mSWCh, 0 );

  mLastItiState = 0;
}
示例#10
0
void
FFTFilter::Preflight( const SignalProperties& Input, SignalProperties& Output ) const
{
  for( int i = 0; i < Parameter( "FFTInputChannels" )->NumValues(); ++i )
  {
    double channelIndex = Input.ChannelIndex( Parameter( "FFTInputChannels" )( i ) );
    if( channelIndex < 0 || channelIndex >= Input.Channels() )
      bcierr << "Invalid channel specification \""
             << Parameter( "FFTInputChannels" )( i )
             << "\" in FFTInputChannels, evaluates to "
             << channelIndex
             << endl;
  }

  bool fftRequired = ( int( Parameter( "FFTOutputSignal" ) ) != eInput
                       || int( Parameter( "VisualizeFFT" ) ) )
                     && ( Parameter( "FFTInputChannels" )->NumValues() > 0 );
  if( fftRequired )
  {
    if( mFFT.LibAvailable() )
    {
      RealFFT preflightFFT;
      int fftWindowLength =
        static_cast<int>( Input.Elements() * Parameter( "FFTWindowLength" ).InSampleBlocks() );
      if( !preflightFFT.Initialize( fftWindowLength ) )
        bcierr << "Requested parameters are not supported by FFT library" << endl;
    }
    else
      bcierr << "The FFT Filter could not find the " << mFFT.LibName() << " library."
             << endl;
  }

  if( int( Parameter( "VisualizeFFT" ) ) || int( Parameter( "FFTOutputSignal" ) ) == ePower )
  {
    SignalProperties temp( Input );
    DetermineSignalProperties( temp, ePower );
  }

  Output = Input;
  DetermineSignalProperties( Output, Parameter( "FFTOutputSignal" ) );
}
示例#11
0
void
P3TemporalFilter::Preflight( const SignalProperties& Input,
                             SignalProperties& Output ) const
{
    // Required states.
    State( "Running" );
    State( "StimulusCode" );
    State( "StimulusType" );
    OptionalState( "StimulusBegin" );

    float outputSamples = MeasurementUnits::ReadAsTime( Parameter( "EpochLength" ) );
    outputSamples *= Input.Elements();
    outputSamples = ::ceil( outputSamples );
    // Requested output signal properties.
    Output = Input;
    Output.SetChannels( Input.Channels() )
    .SetElements( outputSamples )
    .SetType( SignalType::float32 )
    .ElementUnit().SetRawMin( 0 )
    .SetRawMax( outputSamples - 1 );
}
示例#12
0
void
FFTFilter::DetermineSignalProperties( SignalProperties& ioProperties, int inFFTType ) const
{
  int numChannels = Parameter( "FFTInputChannels" )->NumValues(),
      fftWindowLength = Parameter( "SampleBlockSize" )
                        * MeasurementUnits::ReadAsTime( Parameter( "FFTWindowLength" ) );
  if( numChannels > 0 && fftWindowLength == 0 )
    bcierr << "FFTWindowLength must exceed a single sample's duration" << endl;

  switch( inFFTType )
  {
    case eInput:
      break;

    case ePower:
    {
      ioProperties.SetName( "FFT Power Spectrum" )
                  .SetChannels( numChannels )
                  .SetElements( fftWindowLength / 2 + 1 );
      float freqScale = Parameter( "SamplingRate" ) / 2.0 / ioProperties.Elements();
      ioProperties.ElementUnit().SetOffset( freqScale / 2 )
                                .SetGain( freqScale )
                                .SetSymbol( "Hz" );
      float amplitude = ioProperties.ValueUnit().RawMax() - ioProperties.ValueUnit().RawMin();
      ioProperties.ValueUnit().SetRawMin( 0 )
                              .SetRawMax( amplitude * amplitude );
    } break;

    case eHalfcomplex:
      ioProperties.SetName( "FFT Coefficients" )
                  .SetChannels( numChannels )
                  .SetElements( fftWindowLength );
      break;

    default:
      assert( false );
  }
}
示例#13
0
void
ARFilter::Preflight( const SignalProperties& Input,
                           SignalProperties& Output ) const
{
  // Parameter consistency checks.
  float windowLength = MeasurementUnits::ReadAsTime( Parameter( "WindowLength" ) );
  int samplesInWindow = windowLength * Parameter( "SampleBlockSize" );
  if( samplesInWindow < Parameter( "ModelOrder" ) )
    bcierr << "WindowLength parameter must be large enough"
           << " for the number of samples to exceed the model order"
           << endl;

  Output = Input;
  switch( int( Parameter( "OutputType" ) ) )
  {
    case SpectralAmplitude:
    case SpectralPower:
    {
      float firstBinCenter = MeasurementUnits::ReadAsFreq( Parameter( "FirstBinCenter" ) ),
            lastBinCenter = MeasurementUnits::ReadAsFreq( Parameter( "LastBinCenter" ) ),
            binWidth = MeasurementUnits::ReadAsFreq( Parameter( "BinWidth" ) );

      if( firstBinCenter > 0.5 || firstBinCenter < 0
          || lastBinCenter > 0.5 || lastBinCenter < 0 )
        bcierr << "FirstBinCenter and LastBinCenter must be greater zero and"
               << " less than half the sampling rate"
               << endl;
      if( firstBinCenter >= lastBinCenter )
        bcierr << "FirstBinCenter must be less than LastBinCenter" << endl;
      if( binWidth <= 0 )
        bcierr << "BinWidth must be greater zero" << endl;
      else
      {
        int numBins = ::floor( ( lastBinCenter - firstBinCenter + eps ) / binWidth + 1 );
        Output.SetElements( numBins );
      }
      Output.ElementUnit().SetOffset( firstBinCenter / binWidth )
                          .SetGain( binWidth * Parameter( "SamplingRate" ) )
                          .SetSymbol( "Hz" );
      Output.ValueUnit().SetRawMin( 0 );
      float inputAmplitude = Input.ValueUnit().RawMax() - Input.ValueUnit().RawMin(),
            whiteNoisePowerPerBin = inputAmplitude * inputAmplitude / binWidth / 10;
      switch( int( Parameter( "OutputType" ) ) )
      {
        case SpectralAmplitude:
          Output.SetName( "AR Amplitude Spectrum" );
          Output.ValueUnit().SetOffset( 0 )
                            .SetGain( 1e-6 )
                            .SetSymbol( "V/sqrt(Hz)" )
                            .SetRawMax( ::sqrt( whiteNoisePowerPerBin ) );
          break;

        case SpectralPower:
        {
          Output.SetName( "AR Power Spectrum" );
          Output.ValueUnit().SetOffset( 0 )
                            .SetGain( 1 )
                            .SetSymbol( "(muV)^2/Hz" )
                            .SetRawMax( whiteNoisePowerPerBin );
        } break;
      }
    } break;

    case ARCoefficients:
      Output.SetName( "AR Coefficients" );
      Output.SetElements( Parameter( "ModelOrder" ) );
      Output.ElementUnit().SetOffset( 0 )
                          .SetGain( 1 )
                          .SetSymbol( "" );
      Output.ValueUnit().SetOffset( 0 )
                        .SetGain( 1 )
                        .SetSymbol( "" )
                        .SetRawMin( -1 )
                        .SetRawMax( 1 );
      break;

    default:
      bcierr << "Unknown OutputType" << endl;
  }
  Output.ElementUnit().SetRawMin( 0 )
                      .SetRawMax( Output.Elements() - 1 );
}
示例#14
0
void
FFTFilter::Initialize( const SignalProperties& Input, const SignalProperties& Output )
{
  mFFTOutputSignal = ( eFFTOutputSignal )( int )Parameter( "FFTOutputSignal" );
  mFFTWindowLength = Parameter( "SampleBlockSize" )
                     * MeasurementUnits::ReadAsTime( Parameter( "FFTWindowLength" ) );
  mFFTWindow = ( eFFTWindow )( int )Parameter( "FFTWindow" );

  mFFTInputChannels.clear();
  mSpectra.clear();

  for( size_t i = 0; i < mVisualizations.size(); ++i )
    mVisualizations[ i ].Send( CfgID::Visible, false );
  mVisualizations.clear();
  mVisualizeFFT = int( Parameter( "VisualizeFFT" ) );
  if( mVisualizeFFT )
  {
    mVisProperties = Input;
    DetermineSignalProperties( mVisProperties, ePower );
  }
  for( int i = 0; i < Parameter( "FFTInputChannels" )->NumValues(); ++i )
  {
    mFFTInputChannels.push_back( Input.ChannelIndex( Parameter( "FFTInputChannels" )( i ) ) );
    mSpectra.push_back( GenericSignal( Output.Elements(), 1 ) );
    if( mVisualizeFFT )
    {
      ostringstream oss_i;
      oss_i << i + 1;
      mVisualizations.push_back( GenericVisualization( string( "FFT" ) + oss_i.str() ) );

      ostringstream oss_ch;
      oss_ch << "FFT for Ch ";
      if( Parameter( "FFTInputChannels" )->Labels().IsTrivial() )
        oss_ch << i + 1;
      else
        oss_ch << Parameter( "FFTInputChannels" )->Labels()[ i ];

      mVisualizations.back().Send( CfgID::WindowTitle, oss_ch.str().c_str() )
                            .Send( CfgID::GraphType, CfgID::Field2d )
                            .Send( mVisProperties )
                            .Send( CfgID::Visible, true );
    }
  }

  mWindow.clear();
  mWindow.resize( mFFTWindowLength, 1.0 );
  float phasePerSample = M_PI / float( mFFTWindowLength );
  // Window coefficients: None Hamming Hann Blackman
  const float a1[] = {    0,   0.46,   0.5, 0.5, },
              a2[] = {    0,   0,      0,   0.08 };

  for( int i = 0; i < mFFTWindowLength; ++i )
    mWindow[ i ] = 1.0 - a1[ mFFTWindow ] - a2[ mFFTWindow ]
                   + a1[ mFFTWindow ] * cos( float( i ) * phasePerSample )
                   + a2[ mFFTWindow ] * cos( float( i ) * 2 * phasePerSample );

  mValueBuffers.resize( mFFTInputChannels.size() );
  ResetValueBuffers( mFFTWindowLength );

  bool fftRequired = ( mVisualizeFFT || mFFTOutputSignal != eInput)
                     && mFFTInputChannels.size() > 0;
  if( !fftRequired )
  {
    mFFTInputChannels.clear();
    mSpectra.clear();
  }
  else
    mFFT.Initialize( mFFTWindowLength );
}
示例#15
0
void
LinearClassifier::Preflight( const SignalProperties& Input,
                                   SignalProperties& Output ) const
{
  // Determine the classifier matrix format:
  int controlSignalChannels = 0;
  const ParamRef& Classifier = Parameter( "Classifier" );
  if( Classifier->NumColumns() != 4 )
    bcierr << "Classifier parameter must have 4 columns "
           << "(input channel, input element, output channel, weight)"
           << endl;
  else
  {
    for( int row = 0; row < Classifier->NumRows(); ++row )
    {
      if( Classifier( row, 2 ) < 1 )
        bcierr << "Output channels must be positive integers"
               << endl;

      float ch = Input.ChannelIndex( Classifier( row, 0 ) );
      if( ch < 0 )
        bcierr << DescribeEntry( row, 0 )
               << " points to negative input index"
               << endl;
      else if( ::floor( ch ) > Input.Channels() )
        bcierr << "Channel specification in "
               << DescribeEntry( row, 0 )
               << " exceeds number of input channels"
               << endl;
      if( ::fmod( ch, 1.0f ) > 1e-2 )
        bciout << "Channel specification in physical units: "
               << DescribeEntry( row, 0 )
               << " does not exactly meet a single channel"
               << endl;

      float el = Input.ElementIndex( Classifier( row, 1 ) );
      if( el < 0 )
        bcierr << DescribeEntry( row, 1 )
               << " points to negative input index"
               << endl;
      if( ::floor( el ) > Input.Elements() )
        bcierr << "Element (bin) specification in "
               << DescribeEntry( row, 1 )
               << " exceeds number of input elements"
               << endl;
      if( ::fmod( el, 1.0f ) > 1e-2 )
        bciout << "Element (bin) specification in physical units: "
               << DescribeEntry( row, 1 )
               << " does not exactly meet a single element"
               << endl;

      int outputChannel =  Classifier( row, 2 );
      controlSignalChannels = max( controlSignalChannels, outputChannel );
    }
  }
  // Requested output signal properties.
  Output = SignalProperties( controlSignalChannels, 1, Input.Type() );
  // Output description.
  Output.ChannelUnit() = Input.ChannelUnit();
  Output.ValueUnit().SetRawMin( Input.ValueUnit().RawMin() )
                    .SetRawMax( Input.ValueUnit().RawMax() );

  float secsPerBlock = Parameter( "SampleBlockSize" ) / Parameter( "SamplingRate" );
  Output.ElementUnit().SetOffset( 0 ).SetGain( secsPerBlock ).SetSymbol( "s" );
  int visualizationTime = Output.ElementUnit().PhysicalToRaw( "15s" );
  Output.ElementUnit().SetRawMin( 0 ).SetRawMax( visualizationTime - 1 );
}
示例#16
0
void
FFTFilter::Initialize( const SignalProperties& Input, const SignalProperties& /*Output*/ )
{
  mFFTOutputSignal = ( eFFTOutputSignal )( int )Parameter( "FFTOutputSignal" );
  mFFTWindowLength = static_cast<int>( Input.Elements() * Parameter( "FFTWindowLength" ).InSampleBlocks() );
  mFFTWindow = ( eFFTWindow )( int )Parameter( "FFTWindow" );

  mFFTInputChannels.clear();

  for( size_t i = 0; i < mVisualizations.size(); ++i )
    mVisualizations[ i ].Send( CfgID::Visible, false );
  mVisualizations.clear();
  mVisualizeFFT = int( Parameter( "VisualizeFFT" ) );
  if( mVisualizeFFT || mFFTOutputSignal == ePower )
  {
    mVisProperties = Input;
    DetermineSignalProperties( mVisProperties, ePower );
    PhysicalUnit elementUnit = mVisProperties.ElementUnit();
    mVisProperties.SetChannels( mVisProperties.Elements() );
    for( int i = 0; i < mVisProperties.Channels(); ++i )
      mVisProperties.ChannelLabels()[i] = elementUnit.RawToPhysical( mVisProperties.Channels() - i - 1 );
    mVisProperties.SetElements( 1 );
    mVisProperties.ElementUnit() = Input.ElementUnit();
    mVisProperties.ElementUnit().SetGain( mVisProperties.ElementUnit().Gain() * Input.Elements() );
    mPowerSpectrum = GenericSignal( mVisProperties );
  }
  for( int i = 0; i < Parameter( "FFTInputChannels" )->NumValues(); ++i )
  {
    size_t ch = static_cast<size_t>( Input.ChannelIndex( Parameter( "FFTInputChannels" )( i ) ) );
    mFFTInputChannels.push_back( ch );
    if( mVisualizeFFT )
    {
      ostringstream oss_i;
      oss_i << i + 1;
      mVisualizations.push_back( GenericVisualization( string( "FFT" ) + oss_i.str() ) );

      ostringstream oss_ch;
      oss_ch << "FFT for Ch ";
      if( Input.ChannelLabels().IsTrivial() )
        oss_ch << i + 1;
      else
        oss_ch << Input.ChannelLabels()[ch];

      mVisualizations.back().Send( mVisProperties )
                            .Send( CfgID::WindowTitle, oss_ch.str().c_str() )
                            .Send( CfgID::GraphType, CfgID::Field2d )
                            .Send( CfgID::Visible, true );
    }
  }

  mWindow.clear();
  mWindow.resize( mFFTWindowLength, 1.0 );
  float phasePerSample = static_cast<float>( M_PI ) / static_cast<float>( mFFTWindowLength );
  // Window coefficients: None Hamming Hann Blackman
  const float a1[] = {    0,   0.46f,  0.5f, 0.5f, },
              a2[] = {    0,   0,      0,    0.08f };

  for( int i = 0; i < mFFTWindowLength; ++i )
    mWindow[ i ] = 1.0f - a1[ mFFTWindow ] - a2[ mFFTWindow ]
                   + a1[ mFFTWindow ] * cos( static_cast<float>( i ) * phasePerSample )
                   + a2[ mFFTWindow ] * cos( static_cast<float>( i ) * 2.0f * phasePerSample );

  mValueBuffers.resize( mFFTInputChannels.size() );
  ResetValueBuffers( mFFTWindowLength );

  bool fftRequired = ( mVisualizeFFT || mFFTOutputSignal != eInput)
                     && mFFTInputChannels.size() > 0;
  if( !fftRequired )
    mFFTInputChannels.clear();
  else
    mFFT.Initialize( mFFTWindowLength );
}
void
Normalizer::Initialize( const SignalProperties& Input,
                        const SignalProperties& /*Output*/ )
{
  mOffsets.clear();
  mGains.clear();

  delete mpUpdateTrigger;
  mpUpdateTrigger = NULL;

  mBufferConditions.clear();
  mDataBuffers.clear();

  ParamRef Adaptation = Parameter( "Adaptation" ),
           NormalizerOffsets = Parameter( "NormalizerOffsets" ),
           NormalizerGains = Parameter( "NormalizerGains" );

  mAdaptation.clear();
  mDoAdapt = false;
  for( int channel = 0; channel < Input.Channels(); ++channel )
  {
    mOffsets.push_back( NormalizerOffsets( channel ) );
    mGains.push_back( NormalizerGains( channel ) );
    mAdaptation.push_back( int( Adaptation( channel ) ) );
    mDoAdapt |= ( Adaptation( channel ) != none );
  }
  if( mDoAdapt )
  {
    string UpdateTrigger = Parameter( "UpdateTrigger" );
    if( !UpdateTrigger.empty() )
      mpUpdateTrigger = new Expression( UpdateTrigger );

    size_t bufferSize = static_cast<size_t>( Parameter( "BufferLength" ).InSampleBlocks() * Input.Elements() );
    ParamRef BufferConditions = Parameter( "BufferConditions" );
    mBufferConditions.resize( BufferConditions->NumColumns() );
    for( int col = 0; col < BufferConditions->NumColumns(); ++col )
      for( int row = 0; row < BufferConditions->NumRows(); ++row )
        mBufferConditions[ col ].push_back( Expression( BufferConditions( row, col ) ) );
    mDataBuffers.resize(
      BufferConditions->NumColumns(),
      vector<RingBuffer>( BufferConditions->NumRows(), RingBuffer( bufferSize ) )
    );
    bcidbg << "Allocated " << mDataBuffers.size()
           << "x" << ( mDataBuffers.empty() ? 0 : mDataBuffers[ 0 ].size() )
           << " data buffers of size " << bufferSize << "."
           << endl;
  }
}
示例#18
0
MatlabEngine::DoubleMatrix::DoubleMatrix( const SignalProperties& inProperties )
    : vector<vector<double> >( 1, vector<double>( 2 ) )
{
    ( *this )[ 0 ][ 0 ] = inProperties.Channels();
    ( *this )[ 0 ][ 1 ] = inProperties.Elements();
}