예제 #1
0
파일: play.cpp 프로젝트: johnty/stk
// This tick() function handles sample computation only.  It will be
// called automatically when the system needs a new buffer of audio
// samples.
int tick( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
         double streamTime, RtAudioStreamStatus status, void *userData )
{
  FileWvIn *input = (FileWvIn *) userData;
  register StkFloat *samples = (StkFloat *) outputBuffer;

  input->tick( frames );
  for ( unsigned int i=0; i<frames.size(); i++ )
    *samples++ = frames[i];

  //if ( input->isFinished() ) {
  if ( false ) {
    done = true;
    return 1;
  }
  else
    return 0;
}
예제 #2
0
int main( int argc, char* argv[] )
{
	cout << "*** Arguments ***" << endl;
	for ( int a = 0; a < argc; a++ )
		cout <<  a << " : " << argv[a] << endl;
	if ( argc == 1 ) return 1;
	string ifname = string( argv[1] );
	FileWvIn filewvin = FileWvIn( ifname, false, true );
	//size_t pos = ifname.rfind("/");
	//string dirname = ifname.substr(0, pos);
	size_t extpos = ifname.rfind(".wav");
	string basename = ifname.substr(0, extpos);
	for ( unsigned int i=0; i<filewvin.channelsOut(); i++ )
	{
		string ofname = basename +  "-" + to_string(i) + ".wav";
		FileWvOut filewvout = FileWvOut( ofname );
		cout << "channel " << i << endl;
		vector<StkFloat> data;
		unsigned int sn = 0;
		int mod = 0;
		float delta = 0.0f;
		float max = 0.0f;
		float corrected;
		filewvin.reset();
		StkFloat previous;
		StkFloat value = filewvin.tick(i);
		//~ filewvout.tick( previous );
		while ( not( filewvin.isFinished() ) )
		{
			//~ cout << "value : " << value << endl;
			corrected = value + mod;
			data.push_back( corrected );
			if ( abs( corrected ) > max ) max = abs( corrected );
			previous = value;
			sn++;
			value = filewvin.tick(i);
			delta = value - previous;
			if ( delta > 1.7 )
			{
				if ( mod == 0 ) mod = -2;
				else mod = 0;
				cout << sn <<  " | value : " << value << " | delta : " << delta << endl;
			}
			else if ( delta < -1.7 )
			{
				if ( mod == 0 ) mod = 2;
				else mod = 0;
				cout << sn <<  " | value : " << value << " | delta : " << delta << endl;
			}
			
		}
		cout << "maximum amp : " << max << endl;
		for ( vector<StkFloat>::iterator f=data.begin(); f != data.end(); f++ )
			filewvout.tick( *f / max );
		filewvout.closeFile();
	}
	filewvin.closeFile();
	return 0;
}
예제 #3
0
파일: play.cpp 프로젝트: darylposnett/stk
// This tick() function handles sample computation only.  It will be
// called automatically when the system needs a new buffer of audio
// samples.
int tick( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
         double streamTime, RtAudioStreamStatus status, void *userData )
{
  FileWvIn *input = (FileWvIn *) userData;
  StkFloat *samples = (StkFloat *) outputBuffer;

  input->tick( frames );

  for ( unsigned int i=0; i<frames.size(); i++ ) {
    *samples++ = frames[i];
    if ( input->channelsOut() == 1 ) *samples++ = frames[i]; // play mono files in stereo
  }
  
  if ( input->isFinished() ) {
    done = true;
    return 1;
  }
  else
    return 0;
}
예제 #4
0
파일: inetOut.cpp 프로젝트: Ahbee/stk
int main( int argc, char *argv[] )
{
  // Minimal command-line checking.
  if ( argc < 3 || argc > 4 ) usage();

  FileWvIn input;
  InetWvOut output;

  // Load the file.
  try {
    input.openFile( (char *)argv[1] );
  }
  catch ( StkError & ) {
    exit( 1 );
  }

  // Set the global STK sample rate to the file rate.
  Stk::setSampleRate( input.getFileRate() );

  // Set input read rate.
  double rate = 1.0;
  if ( argc == 4 ) rate = atof( argv[3] );
  input.setRate( rate );

  // Find out how many channels we have.
  int channels = input.channelsOut();
  StkFrames frames( 4096, channels );

  // Attempt to connect to the socket server.
  try {
    //output.connect( 2006, Socket::PROTO_UDP, (char *)argv[2], channels, Stk::STK_SINT16 );
    output.connect( 2006, Socket::PROTO_TCP, (char *)argv[2], channels, Stk::STK_SINT16 );
  }
  catch ( StkError & ) {
    exit( 1 );
  }

  // Here's the runtime loop
  while ( !input.isFinished() )
    output.tick( input.tick( frames ) );

  return 0;
}
예제 #5
0
파일: play.cpp 프로젝트: johnty/stk
int main(int argc, char *argv[])
{
  // Minimal command-line checking.
  if ( argc < 3 || argc > 4 ) usage();

  // Set the global sample rate before creating class instances.
  Stk::setSampleRate( (StkFloat) atof( argv[2] ) );

  // Initialize our WvIn and RtAudio pointers.
  RtAudio dac;
  FileWvIn input;
  FileLoop inputLoop;

  // Try to load the soundfile.
  try {
    input.openFile( argv[1] );
	inputLoop.openFile( argv[1] );
  }
  catch ( StkError & ) {
    exit( 1 );
  }

  // Set input read rate based on the default STK sample rate.
  double rate = 1.0;
  rate = input.getFileRate() / Stk::sampleRate();
  rate = inputLoop.getFileRate() / Stk::sampleRate();
  if ( argc == 4 ) rate *= atof( argv[3] );
  input.setRate( rate );

  input.ignoreSampleRateChange();

  // Find out how many channels we have.
  int channels = input.channelsOut();

  // Figure out how many bytes in an StkFloat and setup the RtAudio stream.
  RtAudio::StreamParameters parameters;
  parameters.deviceId = dac.getDefaultOutputDevice();
  parameters.nChannels = channels;
  RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
  unsigned int bufferFrames = RT_BUFFER_SIZE;
  try {
    dac.openStream( &parameters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&inputLoop );
  }
  catch ( RtAudioError &error ) {
    error.printMessage();
    goto cleanup;
  }

  // Install an interrupt handler function.
	(void) signal(SIGINT, finish);

  // Resize the StkFrames object appropriately.
  frames.resize( bufferFrames, channels );

  try {
    dac.startStream();
  }
  catch ( RtAudioError &error ) {
    error.printMessage();
    goto cleanup;
  }

  // Block waiting until callback signals done.
  while ( !done )
    Stk::sleep( 100 );
  
  // By returning a non-zero value in the callback above, the stream
  // is automatically stopped.  But we should still close it.
  try {
    dac.closeStream();
  }
  catch ( RtAudioError &error ) {
    error.printMessage();
  }

 cleanup:
  return 0;
}