예제 #1
0
파일: sound.cpp 프로젝트: IcooN/OpenEmu
static void RedoVolume(void)
{
 apu.output(zebuf.center(), zebuf.left(), zebuf.right());
 //apu.volume(0.15);
 apu.volume(0.25);
 FMSynth.volume(1.00);
}
예제 #2
0
// Quick test of functions
int main()
{
	Blip_Buffer buf;
	Blip_Synth<blip_low_quality,20> synth;
	
	// Setup buffer
	buf.clock_rate( 44100 );
	if ( buf.set_sample_rate( 44100 ) )
		return 1;
	synth.output( &buf );
	synth.volume( 0.5 );
	
	// Add wave that goes from 0 to 50% to -50%
	synth.update( 4,  10 );
	synth.update( 8, -10 );
	buf.end_frame( 30 );
	
	// Read samples as this type
	typedef float sample_t; // floating-point
	//typedef unsigned short sample_t; // unsigned 16-bit
	//typedef unsigned char sample_t; // unsigned 8-bit
	
	// Read and display samples
	const int max_samples = 30;
	sample_t samples [max_samples];
	int count = read_samples( buf, samples, max_samples );
	
	for ( int i = buf.output_latency() + 1; i < count; i++ )
		printf( "%.2f,", (double) samples [i] );
	printf( "\n" );
	
	return 0;
}
예제 #3
0
int main()
{
	long sample_rate = 44100;
	
	// Sample rate sets how many samples are generated per second
	if ( buf.set_sample_rate( sample_rate ) )
		return 1; // out of memory
	buf.bass_freq( 0 ); // keep waveforms perfectly flat
	
	// Setup synth
	synth.output( &buf );
	synth.volume( 0.50 );
	
	while ( !button_pressed() )
	{
		// Mouse sets clock rate, higher to the right. The higher the clock
		// rate, the more packed the waveform becomes.
		long rate = sample_rate * (mouse_x() * 10 + 1);
		
		// Clock rate sets how many time units there are per second
		buf.clock_rate( rate );
		
		// Generate random waveform, with each transition spaced 50 clocks apart.
		srand( 1 );
		buf.clear();
		for ( int time = 0; time < 500; time += 50 )
			synth.update( time, rand() % 20 - 10 );
		
		buf.end_frame( 600 );
		
		show_buffer_unscaled( buf );
	}
	
	return 0;
}
예제 #4
0
int main () {
  if (!alureInitDevice(NULL, NULL)) {
    std::fprintf(stderr, "Failed to open OpenAL device: %s\n", alureGetErrorString());
    return 1;
  }

  alGenSources(1, &src);
  if (alGetError() != AL_NO_ERROR) {
    std::fprintf(stderr, "Failed to create OpenAL source!\n");
    alureShutdownDevice();
    return 1;
  }

  // Seeting Blip Buffer

  synth.treble_eq( -18.0f );

  synth.volume (0.80);
  synth.output (&blipbuf);

  // Init Blip Buffer with a buffer of 250ms (second paramter is time in ms)
  if ( blipbuf.set_sample_rate( SR, 1000 / 4 ) ) {
    std::fprintf(stderr, "Failed to create Blip Buffer! Our of Memory\n");
    alureShutdownDevice();
    return 1;
  }
  blipbuf.clock_rate( blipbuf.sample_rate() );
  blipbuf.bass_freq(300); // Equalization like a TV speaker

  stream = alureCreateStreamFromCallback (StreamCB, nullptr, AL_FORMAT_MONO16, SR, SR/2, 0, nullptr);

  if(!stream) {
    std::fprintf(stderr, "Error creating stream! %s\n",  alureGetErrorString());
    alDeleteSources(1, &src);

    alureShutdownDevice();
    return 1;
  }

  if (!alurePlaySourceStream(src, stream, 4, 0, eos_callback, NULL)) {
    std::fprintf(stderr, "Failed to play stream: %s\n", alureGetErrorString());
    isdone = 1;
  }

  alureUpdateInterval(0.005f); // Should be a independint thread  playing the stream

  while(!isdone) {
    freq -= 1;
    if (freq < 1) {
      freq = 600;
    }

    alureSleep(0.02f);
  }
  alureStopSource(src, AL_FALSE);

  alDeleteSources(1, &src);
  alureDestroyStream(stream, 0, NULL);

  alureShutdownDevice();
  return 0;
}