コード例 #1
0
ファイル: pcm_vdownmix.c プロジェクト: Boshin/workspace
static snd_pcm_sframes_t
vdownmix_transfer(snd_pcm_extplug_t *ext,
		  const snd_pcm_channel_area_t *dst_areas,
		  snd_pcm_uframes_t dst_offset,
		  const snd_pcm_channel_area_t *src_areas,
		  snd_pcm_uframes_t src_offset,
		  snd_pcm_uframes_t size)
{
	snd_pcm_vdownmix_t *mix = (snd_pcm_vdownmix_t *)ext;
	short *src[mix->channels], *ptr[2];
	unsigned int src_step[mix->channels], step[2];
	int i, ch, curpos, p, idx;
	int acc[2];
	int fr;

	ptr[0] = area_addr(dst_areas, dst_offset);
	step[0] = area_step(dst_areas) / 2;
	ptr[1] = area_addr(dst_areas + 1, dst_offset);
	step[1] = area_step(dst_areas + 1) / 2;
	for (ch = 0; ch < mix->channels; ch++) {
		const snd_pcm_channel_area_t *src_area = &src_areas[ch];
		src[ch] = area_addr(src_area, src_offset);
		src_step[ch] = area_step(src_area) / 2;
	}
	curpos = mix->curpos;
	fr = size;
	while (fr--) {
		acc[0] = acc[1] = 0;
		for (ch = 0; ch < mix->channels; ch++) {
			mix->rbuf[curpos][ch] = *src[ch];
			for (idx = 0; idx < 2; idx++) {
				int f = tap_index[ch][idx];
				const struct vdownmix_filter *filter;
				filter = &tap_filters[f];
				for (i = 0; i < filter->taps; i++) {
					p = (curpos + RINGBUF_SIZE - filter->tap[i].delay)
						& RINGBUF_MASK;
					acc[idx] += mix->rbuf[p][ch] * filter->tap[i].weight;
				}
			}
			src[ch] += src_step[ch];
		}
		for (idx = 0; idx < 2; idx++) {
			acc[idx] >>= 14;
			if (acc[idx] < -32768)
				*ptr[idx] = -32768;
			else if (acc[idx] > 32767)
				*ptr[idx] = 32767;
			else
				*ptr[idx] = acc[idx];
			ptr[idx] += step[idx];
		}
		curpos = (curpos + 1) & RINGBUF_MASK;
	}
	mix->curpos = curpos;
	return size;
}
コード例 #2
0
void GridManager::InitCells() {
  GasVector& gases = Config::vGas;
  double min_mass = 100.0;
  double max_mass = 0.0;
  std::for_each(gases.begin(), gases.end(), [&](Gas* gas) {
    const double& m = gas->getMass();
    min_mass = std::min(m, min_mass);
    max_mass = std::max(m, max_mass);
  });
  double max_impulse = GetSolver()->GetImpulse()->getMaxImpulse();

  // Set parameters
  Vector2d cell_size = Config::vCellSize;	// in mm
  cell_size /= 1e3;	// in m
  cell_size /= Config::l_normalize;	// normalized
  Vector3d area_step(cell_size.x(), cell_size.y(), 0.1);

  // decreasing time step if needed
  double time_step = min_mass * std::min(area_step.x(), area_step.y()) / max_impulse;
  //Config::dTimestep = std::min(Config::dTimestep, time_step);
  Config::dTimestep = time_step;

  //std::cout << "Time step: " << Config::dTimestep << " s" << std::endl;
  std::cout << "Time step: " << Config::dTimestep * Config::tau_normalize << " s" << std::endl;


  const Vector3i& grid_size = Config::vGridSize;
  for (int x = 0; x < grid_size.x(); x++) {
    for (int y = 0; y < grid_size.y(); y++) {
      for (int z = 0; z < grid_size.z(); z++) {
        Vector2i v_p(x, y);
        if (grid_->GetInitCell(v_p)->m_eType == sep::EMPTY_CELL)
          continue;

        Cell* p_cell = grid_->GetInitCell(v_p)->m_pCell;
        InitCellData* p_init_cell = grid_->GetInitCell(v_p);

        const GasesConfigsMap& init_conds = p_init_cell->m_mInitConds;
        for (auto val : init_conds) {
          const int& gas_number = val.first;
          if (gas_number >= Config::iGasesNumber)
            continue;
          const CellConfig& cond = val.second;
          p_cell->setParameters(
            cond.pressure,
            cond.T,
            area_step,
            gas_number,
            cond.locked_axes
            );
          p_cell->setBoundaryType(
            cond.boundary_cond,
            cond.boundary_T,
            cond.boundary_stream,
            cond.boundary_pressure,
            gas_number
            );
        }
        p_cell->Init(this);
      }
    }
  }
}