Ejemplo n.º 1
0
/********************* TASKS ***********************/
void task_every_row(void) 
{
  static int song_count = 0;
  static int ui_count = 0;
  can_rx_dispatch_all();  
  hb_beat();          
  mcu_led_update(); 
  msimu_update();
  error_update();
  can_tx2(); // transmit all the can ids

  if (button_pushed(4))	{
    ui_count++;
    if (ui_count == 100){
      sync_led_on = !sync_led_on;
      ui_count = 0;
    }
  }
  
	if(sync_led_on) {ui_sync_led_flash();}
  else {ui_sync_led_off();}

  //update the song if it's playing
  song_update();   
}
Ejemplo n.º 2
0
void update_handler( void )
{
    static  int     pulse_area;
    static  int     pulse_mobile;
    static  int     pulse_violence;
    static  int     pulse_point;
    static  int	    pulse_music;

    if ( --pulse_area     <= 0 )
    {
	pulse_area	= PULSE_AREA;
	/* number_range( PULSE_AREA / 2, 3 * PULSE_AREA / 2 ); */
	area_update	( );
    }

    if ( --pulse_music	  <= 0 )
    {
	pulse_music	= PULSE_MUSIC;
	song_update();
    }

    if ( --pulse_mobile   <= 0 )
    {
	pulse_mobile	= PULSE_MOBILE;
	mobile_update	( );
    }

    if ( --pulse_violence <= 0 )
    {
	pulse_violence	= PULSE_VIOLENCE;
	violence_update	( );
    }

    if ( --pulse_point    <= 0 )
    {
	wiznet("TICK!",NULL,NULL,WIZ_TICKS,0,0);
	pulse_point     = PULSE_TICK;
/* number_range( PULSE_TICK / 2, 3 * PULSE_TICK / 2 ); */
	weather_update	( );
	char_update	( );
	obj_update	( );
    }

    aggr_update( );
    tail_chain( );
    return;
}
Ejemplo n.º 3
0
// export thread
static DWORD __stdcall export_rendering_thread(void *parameter) {
  const int samples_per_sec = 44100;
  uint progress = 0;

  WAVEFORMATEX  wfxInput;
  ZeroMemory( &wfxInput, sizeof(wfxInput));
  wfxInput.wFormatTag = WAVE_FORMAT_PCM;
  wfxInput.nSamplesPerSec = samples_per_sec;
  wfxInput.wBitsPerSample =  16; 
  wfxInput.nChannels = 2;
  wfxInput.nBlockAlign = wfxInput.nChannels * (wfxInput.wBitsPerSample / 8);
  wfxInput.nAvgBytesPerSec = wfxInput.nBlockAlign * wfxInput.nSamplesPerSec;

  HRESULT hr;
  CWaveFile wavFile;

  hr = wavFile.Open((char*)parameter, &wfxInput, WAVEFILE_WRITE);
  if (FAILED(hr)) {
    goto done;
  }


  // stop playing
  song_stop_playback();

  // skip 5 seconds
  for (int samples = samples_per_sec * 5; samples > 0; samples -= 32) {
    float temp_buffer[2][32];

    // update song
    song_update(1000.0 * (double)32 / (double)samples_per_sec);

    // update effect
    vsti_update_config((float)samples_per_sec, 32);

    // call vsti process func
    vsti_process(temp_buffer[0], temp_buffer[1], 32);
  }

  song_start_playback();

  for (;;) {
    const int samples = 32;

    float temp_buffer[2][samples];
    short output_buffer[2 * samples];

    // update song
    song_update(1000.0 * (double)samples / (double)samples_per_sec);

    // update effect
    vsti_update_config((float)samples_per_sec, samples);

    // call vsti process func
    vsti_process(temp_buffer[0], temp_buffer[1], samples);

    short* output = output_buffer;
    float volume = config_get_output_volume() / 100.0;
    for (int i = 0; i < samples; i++) {
      float l = 
      output[0] = convertSample(temp_buffer[0][i] * 32767.0f * volume);
      output[1] = convertSample(temp_buffer[1][i] * 32767.0f * volume);
      output += 2;
    }

    UINT sizeWrote = 0;
    hr = wavFile.Write(sizeof(output_buffer), (BYTE*)output_buffer, &sizeWrote);

    if (!song_is_playing())
      break;

    if (!gui_is_exporting())
      break;

    uint new_progress = 100 * song_get_time() / song_get_length();
    if (new_progress != progress) {
      progress = new_progress;
      gui_update_export_progress(progress);
    }
  }

done:
  song_stop_playback();
  gui_close_export_progress();
  wavFile.Close();
  return hr;
}
Ejemplo n.º 4
0
// playing thread
static DWORD __stdcall dsound_play_thread(void *param) {
  // primary buffer caps
  DSBCAPS caps;
  caps.dwSize = sizeof(caps);
  primary_buffer->GetCaps(&caps);

  // primary buffer format
  WAVEFORMATEX format;
  primary_buffer->GetFormat(&format, sizeof(format), NULL);

  // timer resolustion
  timeBeginPeriod(1);

  // temp buffer for vsti process
  float output_buffer[2][4096];

  // data write posision
  int write_position = 0;

  // start playing primary buffer
  primary_buffer->Play(0, 0, DSBPLAY_LOOPING);

  while (dsound_thread) {
    DWORD play_pos, write_pos;

    // get current position
    primary_buffer->GetCurrentPosition(&play_pos, &write_pos);

    // size left in buffer to write.
    int data_buffer_size = (caps.dwBufferBytes + write_position - write_pos) % caps.dwBufferBytes;

    // write buffer size
    int write_buffer_size = buffer_size * format.nBlockAlign;

    // size left in buffer
    int write_size = write_buffer_size - data_buffer_size;

    // maybe data buffer is underflowed.
    if (write_size < 0) {
      write_size = (caps.dwBufferBytes + write_pos + write_buffer_size - write_position) % caps.dwBufferBytes;
    }

    // write data at least 32 samles
    if (write_size >= 32 * format.nBlockAlign) {
      //printf("%8d, %8d, %8d, %8d, %8d\n", timeGetTime(),  (caps.dwBufferBytes + write_position + write_size - write_pos) % caps.dwBufferBytes, write_pos, write_size, write_buffer_size);

      // samples
      uint samples = write_size / format.nBlockAlign;

      if (export_rendering()) {
        memset(output_buffer[0], 0, samples * sizeof(float));
        memset(output_buffer[1], 0, samples * sizeof(float));
      } else   {
        // update
        song_update(1000.0 * (double)samples / (double)format.nSamplesPerSec);

        // call vsti process func
        vsti_update_config((float)format.nSamplesPerSec, 4096);
        vsti_process(output_buffer[0], output_buffer[1], samples);
      }

      // lock primary buffer
      void  *ptr1, *ptr2;
      DWORD size1, size2;
      HRESULT hr = primary_buffer->Lock(write_position, write_size, &ptr1, &size1, &ptr2, &size2, 0);

      // device lost, restore and try again
      if (DSERR_BUFFERLOST == hr) {
        primary_buffer->Restore();
        hr = primary_buffer->Lock(write_position, write_size, &ptr1, &size1, &ptr2, &size2, 0);
      }

      // lock succeeded
      if (SUCCEEDED(hr)) {
        float *left = output_buffer[0];
        float *right = output_buffer[1];

        uint samples1 = size1 / format.nBlockAlign;
        uint samples2 = size2 / format.nBlockAlign;

        if (ptr1) write_buffer((short *)ptr1, left, right, samples1);
        if (ptr2) write_buffer((short *)ptr2, left + samples1, right + samples1, samples2);

        hr = primary_buffer->Unlock(ptr1, size1, ptr2, size2);

        write_position = (write_position + write_size) % caps.dwBufferBytes;
      }

    } else   {
      Sleep(1);
    }
  }

  // stop sound buffer
  primary_buffer->Stop();

  // timer resolustion
  timeEndPeriod(10);

  return 0;
}