Example #1
0
void BarkBands::setup(){
  LOUDIA_DEBUG("BARKBANDS: Setting up...");

  // In some cases the first boundary is set to 0
  MatrixXR startFreqs(25, 1);
  startFreqs << 20, 100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480, 1720, 2000, 2320, 2700, 3150, 3700, 4400, 5300, 6400, 7700, 9500, 12000, 15500;

  MatrixXR centerFreqs(24, 1);
  centerFreqs << 60, 150, 250, 350, 450, 570, 700, 840, 1000, 1170, 1370, 1600, 1850, 2150, 2500, 2900, 3400, 4000, 4800, 5800, 7000, 8500, 10500, 13500;
  
  MatrixXI startBins = ((startFreqs.block(_lowBand, 0, _highBand - _lowBand + 2, 1) / _sampleRate) * _fftSize).cast<int>();
  
  std::vector<MatrixXR> weights;
  for (int i = 0; i < startBins.rows() - 1; i++) {
    MatrixXR bandWeights = MatrixXR::Ones(startBins(i+1) - startBins(i), 1);
    weights.push_back(bandWeights);
  }

  _bands.setStartsWeights(startBins.block(0, 0, _highBand - _lowBand + 1, 1), weights);

  LOUDIA_DEBUG("BARKBANDS: Finished set up...");
}
IGL_INLINE void igl::peal_outer_hull_layers(
  const Eigen::PlainObjectBase<DerivedV > & V,
  const Eigen::PlainObjectBase<DerivedF > & F,
  Eigen::PlainObjectBase<Derivedodd > & odd,
  Eigen::PlainObjectBase<Derivedflip > & flip)
{
  using namespace Eigen;
  using namespace std;
  typedef typename DerivedF::Index Index;
  typedef Matrix<typename DerivedF::Scalar,Dynamic,DerivedF::ColsAtCompileTime> MatrixXF;
  typedef Matrix<Index,Dynamic,1> MatrixXI;
  typedef Matrix<typename Derivedflip::Scalar,Dynamic,Derivedflip::ColsAtCompileTime> MatrixXflip;
  const Index m = F.rows();
#ifdef IGL_PEAL_OUTER_HULL_LAYERS_DEBUG
  cout<<"peal outer hull layers..."<<endl;
#endif

#ifdef IGL_PEAL_OUTER_HULL_LAYERS_DEBUG
  cout<<"resize output ..."<<endl;
#endif
  // keep track of iteration parity and whether flipped in hull
  MatrixXF Fr = F;
  odd.resize(m,1);
  flip.resize(m,1);
  // Keep track of index map
  MatrixXI IM = MatrixXI::LinSpaced(m,0,m-1);
  // This is O(n * layers)
  bool odd_iter = true;
  MatrixXI P(m,1);
  Index iter = 0;
  while(Fr.size() > 0)
  {
    assert(Fr.rows() == IM.rows());
    // Compute outer hull of current Fr
    MatrixXF Fo;
    MatrixXI Jo;
    MatrixXflip flipr;
#ifdef IGL_PEAL_OUTER_HULL_LAYERS_DEBUG
  cout<<"calling outer hull..."<<endl;
  writePLY("outer-hull-input.ply",V,Fr);
#endif
    outer_hull(V,Fr,Fo,Jo,flipr);
#ifdef IGL_PEAL_OUTER_HULL_LAYERS_DEBUG
  cout<<"reindex, flip..."<<endl;
#endif
    assert(Fo.rows() == Jo.rows());
    // all faces in Fo of Fr
    vector<bool> in_outer(Fr.rows(),false);
    for(Index g = 0;g<Jo.rows();g++)
    {
      odd(IM(Jo(g))) = odd_iter;
      P(IM(Jo(g))) = iter;
      in_outer[Jo(g)] = true;
      flip(IM(Jo(g))) = flipr(Jo(g));
    }
    // Fr = Fr - Fo
    // update IM
    MatrixXF prev_Fr = Fr;
    MatrixXI prev_IM = IM;
    Fr.resize(prev_Fr.rows() - Fo.rows(),F.cols());
    IM.resize(Fr.rows());
    {
      Index g = 0;
      for(Index f = 0;f<prev_Fr.rows();f++)
      {
        if(!in_outer[f])
        {
          Fr.row(g) = prev_Fr.row(f);
          IM(g) = prev_IM(f);
          g++;
        }
      }
    }
    odd_iter = !odd_iter;
    iter++;
  }
}