Example #1
0
int main(int argc,char** argv)
{
Audio_IO audiostream;
float samplebuffer[FRAMESPERBUFFER * NROFCHANNELS];
unsigned long x=0;		// sample index
unsigned long bufptr=0;		// pointer into sample buffer
double l_freq=500.0;		// base frequency of left channel
double r_freq=850.0;		// base frequency of right channel
double l_amp=0.4;		// base amplitude of left channel
double r_amp=0.4;		// base amplitude of right channel
int output_device=0;

  audiostream.set_samplerate(SAMPLERATE);
  audiostream.set_nrofchannels(NROFCHANNELS);
  audiostream.set_framesperbuffer(FRAMESPERBUFFER);

  audiostream.initialise();
  audiostream.list_devices();
  cout << "Give output device number: ";
  cin >> output_device;
  audiostream.set_output_device(output_device);
  audiostream.start_server();

  double l_phase = 0;
  double r_phase = 0;

  do{
    for(bufptr=0; bufptr < FRAMESPERBUFFER*NROFCHANNELS; bufptr+=2)
    {
      // Fill a new buffer with samples
      samplebuffer[bufptr] = (float)(l_amp * sin(2.0*M_PI*l_phase) );
      l_phase += l_freq/SAMPLERATE;

      samplebuffer[bufptr+1] = (float)(r_amp * sin(2.0*M_PI*r_phase) );
      r_phase += r_freq/SAMPLERATE;
      x++;
    } // for

    // send buffer to Portaudio
    audiostream.write(samplebuffer);
  } while(x < (SAMPLERATE * NUM_SECONDS) );

  audiostream.finalise();

  return 0;
} // main()
Example #2
0
int main()
{

	Audio_IO audiostream;

	audiostream.set_mode(AUDIO_IO_READWRITE);
  audiostream.set_samplerate(SAMPLERATE); // constante aanmaken
  audiostream.set_nrofchannels(NOC);	// constante aanmaken
  audiostream.set_framesperbuffer(FPB); // constante aanmaken

  audiostream.initialise();
  audiostream.list_devices();

	int device;
	cout << "\nGive input device number: ";
  cin >> device;
  audiostream.set_input_device(device);

  cout << "Give output device number: ";
  cin >> device;
  audiostream.set_output_device(device);

  audiostream.start_server();

		Amplifier* amp;
		
		switch(MODE)
		{
			default: amp = new Amplifier();
			case 0: amp = new Amplifier();
			case 1: amp = new Tremolo();
			case 2: amp = new Bitcrusher();
		}

		while(true)
		{
			audiostream.read(amp->get_buffer());
			amp->process_samples();
			audiostream.write(amp->get_buffer());
		}

		audiostream.finalise();
	
		return 0;
} // main()