コード例 #1
0
ファイル: flock.cpp プロジェクト: cutun/kazoo
void Flock::set_harmony (size_t voice, const Vector<float> & selection)
{
  ASSERT_LT(voice, voice_count());

  float selection_decay = expf(-rhythm().min_freq());
  Vector<float> pitch_mass = m_pitch_masses.block(m_harmony.size, voice);
  accumulate_step(selection_decay, pitch_mass, selection);
}
コード例 #2
0
ファイル: trhythm.cpp プロジェクト: SeeLook/nootka
void Trhythm::split(TrhythmList& twoRhythms) const {
  if (rhythm() == e_none || rhythm() == e_sixteenth)
    return; // nothing to split

  if (hasDot()) {
      twoRhythms << Trhythm(rhythm(), isRest(), false) // no triplet for sure
                << Trhythm(static_cast<Erhythm>(rhythm() + 1), isRest());
          // Also when there is a dot, for sure it is not lowest possible rhythm, so we may add 1 to rhythm value to obtain its half
  } else {
      Trhythm half(static_cast<Erhythm>(rhythm() + 1), isRest(), false, isTriplet());
      twoRhythms << half << half;
  }
  if (!isRest() && twoRhythms.size() == 2) {
    twoRhythms.first().setStemDown(stemDown());
    twoRhythms.last().setStemDown(stemDown());
  }
}
コード例 #3
0
ファイル: swarmfunctions.c プロジェクト: Jiffer/servo-wall
// --------------------------------------------------------------------------------------------
float rhythm_control3()	//Frequency Modulation
{
	static int timestep = 0;
	float stp, tim, dtim = 2.0 * PI / 30.0;	// 1cycle = 30 sec
	
	tim = (float)timestep * dtim;
	stp = 0.2;

	if(rhythm_on)
	{
		timestep++;
		rhythm_on = false;
	}

	return rhythm(stp);
}
コード例 #4
0
ファイル: swarmfunctions.c プロジェクト: Jiffer/servo-wall
// --------------------------------------------------------------------------------------------
float rhythm_control1()	//Amplitude Modulation
{
	static int timestep = 0;
	float tim, dtim = 2.0 * PI / 30.0;		// 1cycle = 30 sec
	
	tim = (float)timestep * dtim;
	global_amp = sin(tim) * sin(tim);
	if(global_amp < 0.1) global_amp = 0.1; // to avoid complete stop

	if(rhythm_on)
	{
		timestep++;
		rhythm_on = false;
	}

	return global_amp * rhythm(0.6);
}
コード例 #5
0
Tset keypress(Tset vars)
{
	// Declare an integer variable assign the value of the users key press to it.
	int input;
	input = getch();

	/*
	 * Use a switch to check if the key pressed corresponds to any control keys and if
	 * so edit the approriate variable.
	 */

	switch(input)
	{
		case '1':
		{
			vars.instl_velocity = 0;			
			break;
		}
		case 'q':
		{
			vars.instc_velocity = 0;
			break;
		}
		case 'a':
		{
			vars.instb_velocity = 0;
			break;
		}
		case 'z':
		{
			vars.drum_vel = 0;
			break;
		}
		case '3':
		{
			vars.instl_velocity += 5;
			break;
		}
		case 'e':
		{
			vars.instc_velocity += 5;
			break;
		}
		case 'd':
		{
			vars.instb_velocity += 5;
			break;
		}
		case 'c':
		{
			vars.drum_vel += 5;
			break;
		}
		
		/*
		 * In cases where velocity is decreased check that the decreased value does not go
		 * negative before decreasing the variable.
		 */

		case '2':
		{
			if(vars.instl_velocity - 5 > 0)
			vars.instl_velocity -= 5;
			break;
		}
		case 'w':
		{
			if(vars.instc_velocity - 5 > 0)
			vars.instc_velocity -= 5;
			break;
		}
		case 's':
		{
			if(vars.instb_velocity - 5 > 0)
			vars.instb_velocity -= 5;
			break;
		}
		case 'x':
		{
			if(vars.drum_vel - 5 > 0)
			vars.drum_vel -= 5;
			break;
		}

		// Set the instruments velocitys to be at a standard value declared in the header file
		case '4':
		{
			vars.instl_velocity = LEAD;
			break;
		}
		case 'r':
		{
			vars.instc_velocity = CHORD;
			break;
		}
		case 'f':
		{
			vars.instb_velocity = BASS;
			fflush(stdin);
			break;
		}
		case 'v':
		{
			vars.drum_vel = DRUM;
			break;
		}

		/*
		 * In cases where tempo is decreased check that the decreased value does not go negative
		 * before decreasing the variable.
		 */

		case 'o':
		{
			if(vars.tempo - 2 > 0)
			vars.tempo--;
			break;
		}
		case 'i':
		{
			vars.tempo ++;
			break;
		}

		// This sets the variable loop to 1, stopping the main loop and terminating the program.
		case ' ':
		{
			vars.loop = 1;
			break;
		}
		case '5':
		{

			/*
			 * When changing the instrument the variable scroll checks which instrument
			 * is currently playing, changes it to the next instrument and adds 1 to scroll.
			 * At the last instrument scroll is reset and so as the key 5 is repeatedly pressed
			 * its cycles through the possible instruments.
			 */

			switch(vars.instl_scroll)
			{						
				case 0:
				{
					program_change(1, 5);
					vars.instl_scroll++;
					break;
				}
				case 1:
				{
					program_change(1, 31);
					vars.instl_scroll++;
					break;
				}
				case 2:
				{
					program_change(1, 27);
					vars.instl_scroll++;
					break;
				}
				case 3:
				{
					program_change(1, 67);
					vars.instl_scroll++;
					break;
				}
				case 4:
				{
					program_change(1, 10);
					vars.instl_scroll = 5;
					break;
				}
				case 5:
				{
					program_change(1, 115);
					vars.instl_scroll = 0;
					break;
				}
			}
			break;
		}
		case 't':
		{
			switch(vars.instc_scroll)
			{						
				case 0:
				{
					program_change(2, 5);
					vars.instc_scroll++;
					break;
				}
				case 1:
				{
					program_change(2, 27);
					vars.instc_scroll++;
					break;
				}
				case 2:
				{
					program_change(2, 29 );
					vars.instc_scroll = 0;
					break;
				}						
			}
			break;
		}
		case 'g':
		{
			switch(vars.instb_scroll)
			{						
				case 0:
				{
					program_change(3, 33);
					vars.instb_scroll++;
					break;
				}
				case 1:
				{
					program_change(3, 34);
					vars.instb_scroll = 0;
					break;
				}						
			}
			break;
		}
		case 'l':
		{
			vars.key++;
			break;
		}
		case 'k':
		{
			vars.key--;
			break;
		}
		
		/*
		 * Here the user has chosen to restart the program so turn off all midi notes,
		 * clear the screen and print a message. Calls the user input functions
		 * again and display the user input messages.
		 */

		case 8:
		{
			midi_note(vars.oldlead, 1, 0);
			midi_note(vars.key, 1, 0);
			midi_note(vars.oldbass, 3, 0);
			midi_note(vars.key, 3, 0);
			midi_note(vars.key, 2, 0);
			midi_note(vars.key + 7, 2, 0);
			midi_note(vars.key + 9, 2, 0);
			midi_note(vars.key + 10, 2, 0);
			midi_note(vars.key + 12, 2, 0);
			midi_note(vars.key + 15, 2, 0);
			midi_note(vars.key + 16, 2, 0);

			system ("cls");

			printf("Starting again...\n\nRe-enter values:\n\n");

			vars.rhythm = rhythm();	
			vars.key  = pitch();
			vars.tempo = speed();
			vars = input_instrument(vars);	
			vars.loop = 0;
			vars.time = 0;
			vars.count = 0;
			vars.luck = 0;
			vars.shift = 0;

			messages( vars);
			break;
		}
		
		/*
		 * Here the user is changing the rhythm so set the key back to its original value,
		 * reset shift, time and count and set the variable rhythm to the approriate value.
		 */

		case '8':
		{
			vars.key = vars.original;
			vars.shift = 0;
			vars.rhythm = 1;
			vars.time = 0;
			vars.count = 0;
			break;
		}
		case '9':
		{
			vars.key = vars.original;
			vars.shift = 0;
			vars.rhythm = 2;
			vars.time = 0;
			vars.count = 0;
			break;
		}
		case '0':
		{
			vars.key = vars.original;
			vars.shift = 0;
			vars.rhythm = 3;
			vars.time = 0;
			vars.count = 0;
			break;
		}
	}

	fflush(stdin);	// Clear the standard input memory

	return(vars);	// Return the altered vars
}
コード例 #6
0
int main(int argc, char** argv) {

  if (argc != 2)
    return Usage(std::string(argv[0]));

  // Initialize logging.
  const bool log_to_file = false;

  if (log_to_file) {

    const int nb_rolling_logfiles = 2;
    const int max_logfile_size = 1000000;
    plog::init(plog::verbose, "wave_propagator.log", max_logfile_size, nb_rolling_logfiles);

  } else {

    static plog::ColorConsoleAppender<plog::TxtFormatter> console_appender;
    plog::init(plog::verbose, &console_appender);

  }

  LOG_INFO << "**** 2D/3D wave propagator in heterogeneous media ****\n";

  char const* const parameter_filename_c = argv[1];
  const std::string parameter_filename = std::string(parameter_filename_c);

  RectilinearGrid3D propagation_grid;
  MultiDimensionalStorage4D variable_storage;
  MathematicalParser math_parser;
  std::vector<OutputEvent> output_events;
  TimeloopManager timeloop_manager;
  WaveSolverOptions wave_solver_options = WaveSolverOptions();;

  LOG_INFO << "Reading parameter file \"" << parameter_filename << "\"...";

  std::ifstream parameter_file(parameter_filename.c_str(), std::ifstream::in);
  const int nx_padding = 10;

  ParseParameterFile(nx_padding, &parameter_file, &propagation_grid, 
                     &variable_storage, &math_parser, &output_events,
                     &timeloop_manager, &wave_solver_options);

  parameter_file.close();

  math_parser.PrintConstants();

  const int nb_iter = timeloop_manager.nb_iter();

  // Variables information (hardcoded for now, in variable_definitions.hpp).
  const int nb_variables = variable::NB_VARIABLES;
  
  std::stringstream var_name_msg;

  var_name_msg << "List of variables: [";
  for (int ivar = 0; ivar < nb_variables; ++ivar)
    var_name_msg << " " << variable::VARIABLE_NAMES[ivar];
  var_name_msg << " ]\n";

  LOG_DEBUG << var_name_msg.str();

  const RealT dx = propagation_grid.dx_fast();
  const RealT dy = propagation_grid.dx_medium();
  const RealT dz = propagation_grid.dx_slow();

  RealT* pressure_0 = variable_storage.RawDataSlowDimension(variable::PRESSURE_0);
  RealT* pressure_1 = variable_storage.RawDataSlowDimension(variable::PRESSURE_1);
  RealT* laplace_p = variable_storage.RawDataSlowDimension(variable::LAPLACE_PRESSURE);
  RealT* velocity = variable_storage.RawDataSlowDimension(variable::VELOCITY);

  // Init output events.
  for (auto it = output_events.begin(); it != output_events.end(); ++it)
    it->Create(nb_iter, variable_storage, propagation_grid);

  RealT* sponge_fast = VectorRawData<RealT>(wave_solver_options.sponge_fast());
  RealT* sponge_medium = VectorRawData<RealT>(wave_solver_options.sponge_medium());
  RealT* sponge_slow = VectorRawData<RealT>(wave_solver_options.sponge_slow());

  std::ofstream sponge_fast_out("sponge_fast.txt", std::ofstream::out);
  std::ofstream sponge_medium_out("sponge_medium.txt", std::ofstream::out);
  std::ofstream sponge_slow_out("sponge_slow.txt", std::ofstream::out);

  wave_solver_options.DumpAllSponges(&sponge_fast_out,
                                     &sponge_medium_out,
                                     &sponge_slow_out);

  sponge_fast_out.close();
  sponge_medium_out.close();
  sponge_slow_out.close();

  const RealT dt = timeloop_manager.dt();
  RealT t = 0.0;

  // Main time loop. All numerics (except time step computation) is in
  // here.
  for (int iter = 0; iter < timeloop_manager.nb_iter(); ++iter) {

    t += dt;
    math_parser.AddConstant("t", t);

    const int stencil_radius = 1;

    const int n_fast = variable_storage.dimensions().at(0);
    const int n_fast_padding = variable_storage.padding_fast();
    const int n_medium = variable_storage.dimensions().at(1);
    const int n_slow = variable_storage.dimensions().at(2);

    timer_start = Timer::Now();

    // Apply sponge.
    ApplySpongeLayer_0(n_fast, n_fast_padding, n_medium, n_slow,
                       sponge_fast, sponge_medium, sponge_slow, 
                       pressure_1);

    ComputeLaplacian_0(n_fast, n_fast_padding, n_medium, n_slow,
                       stencil_radius, dx, dy, dz, 
                       pressure_0, laplace_p);
     
    // Advance pressure.
    AdvanceWavePressure_0(n_fast, n_fast_padding, n_medium, n_slow, 
                          stencil_radius, dt,
                          velocity, laplace_p, pressure_0, pressure_1);

    // Apply sponge.
    ApplySpongeLayer_0(n_fast, n_fast_padding, n_medium, n_slow,
                       sponge_fast, sponge_medium, sponge_slow, 
                       pressure_1);

    timer_stop = Timer::Now();
    
    timings_numerics.push_back(Timer::DiffTime(timer_start, timer_stop));

    for (auto it = output_events.begin(); it != output_events.end(); ++it) {

      const bool event_happens = 
        ((iter % it->rhythm() == 0) && (it->rhythm() >= 0)) ||
        ((iter == timeloop_manager.nb_iter() - 1) && (it->rhythm() == - 1));

      if (event_happens) {

        it->Execute(iter, propagation_grid, &math_parser, &variable_storage);

      }
    }

    // Exchange pressure arrays.
    std::swap(pressure_0, pressure_1);

  }

  // Variables cleanup.
  variable_storage.DeAllocate();

  for (auto it = output_events.begin(); it != output_events.end(); ++it)
    it->Destroy();

  const RealT minimum_time = 
    *std::min_element(timings_numerics.begin(), timings_numerics.end());
  assert(0.0 < minimum_time);

  const size_t nb_grid_points = 
    propagation_grid.n_fast() * propagation_grid.n_medium() * propagation_grid.n_slow();

  LOG_INFO << "****************************************";
  std::cout << "\n";
  Timer::PrintTimings(timings_numerics, "            Wave propagation", &std::cout);
  std::cout << "            Wave propagation : " 
            << std::scientific << (RealT)nb_grid_points / (minimum_time * 1.0e-3)
            << " grid updates per second";
  std::cout << "\n";
  std::cout << "\n";
  LOG_INFO << "****************************************";

  return 0;
}