Ejemplo n.º 1
0
int rec_raw (int margin_dB, int chans, int fs, char *nameFile, bool*flagParar, int *clipping, int device)
{
 
  int i = 0, j = 0;
  int buffer_size;
  int dummy;
  
  int clipping_threshold = (int)((double)INT_MAX/pow(10, ((double)margin_dB/(double)20)) );
      
  MY_TYPE *buffer;

  RtAudio *audio = 0;

  char nomFichEGG[MAXPATH];
  strcpy(nomFichEGG,nameFile);
  flhPonerExtension(nomFichEGG,".egg.wav");

  char nomFichMicro[MAXPATH];
  strcpy(nomFichMicro,nameFile);
  flhPonerExtension(nomFichMicro,".ch1.wav");

  /*Implemetación con libnsnd*/

  SNDFILE *fdTOT;
  SNDFILE *fdEGG;
  SNDFILE *fdMicro;

  SF_INFO SfInfoTot, SfInfoEGG, SfInfoMicro;

  SfInfoTot.samplerate = fs;
  SfInfoTot.channels   = chans;
  SfInfoTot.format     = SF_FORMAT_WAV | SF_FORMAT_PCM_24 | SF_ENDIAN_LITTLE;

  SfInfoEGG.samplerate = fs;
  SfInfoEGG.channels   = 1;
  SfInfoEGG.format     = SF_FORMAT_WAV | SF_FORMAT_PCM_16 | SF_ENDIAN_LITTLE;

  SfInfoMicro.samplerate = fs;
  SfInfoMicro.channels   = 1;
  SfInfoMicro.format     = SF_FORMAT_WAV | SF_FORMAT_PCM_16 | SF_ENDIAN_LITTLE;

  fdTOT   = sf_open (nameFile, SFM_WRITE, &SfInfoTot);
  fdEGG   = sf_open (nomFichEGG, SFM_WRITE, &SfInfoEGG);
  fdMicro = sf_open (nomFichMicro, SFM_WRITE, &SfInfoMicro);

  /*Implemetación con libnsnd*/
 (*clipping) = 0;

  buffer_size = TAM_BUFF_AUDIO;
  try {
    audio = new RtAudio(0, 0, device, chans,
		FORMAT, fs, &buffer_size, MAX_NUM_CHANNELS, 
#ifdef __WINDOWS_DS__
		RtAudio::WINDOWS_DS
#elif defined(__WINDOWS_ASIO__)
		RtAudio::WINDOWS_ASIO
#endif
		);

  }
  catch (RtError &error) {
    error.printMessage();
    exit(EXIT_FAILURE);
  }

  try {
    buffer = (MY_TYPE *) audio->getStreamBuffer();
    audio->startStream();
  }
  catch (RtError &error) {
    error.printMessage();
    goto cleanup;
  }

/********* GRABAMOS ************/
/*******************************/

  while (1) {
 
    if (*flagParar==false) 
	{
      try {
        audio->tickStream();
      }
      catch (RtError &error) {
        error.printMessage();
        goto cleanup;
      }


	  //Grabamos los ocho canales
	  sf_count_t counts = buffer_size;
	  counts = sf_writef_int  (fdTOT, buffer, counts);

	  for (int i=0; i < buffer_size; i++)
	  {
		  dummy = INT_MAX;

		  if ((dummy=abs(buffer[i*chans+canalMicro])) > clipping_threshold)
		  {
			  (*clipping)++;
			//dummy = CLIPPING_THRESHOLD;
		  }
	
		  counts = sf_writef_int  (fdEGG, &buffer[i*chans+canalEGG], 1);
		  counts = sf_writef_int  (fdMicro, &buffer[i*chans+canalMicro], 1);
	  }
	
/*	  EnterCriticalSection(&CriticalSection); 

	  for (i = 0, j = 0; i < buffer_size; i += chans, j++)
	  {
		  muestraOSC_GLOTO[j]   = buffer[i*chans + canalEGG];
		  muestraOSC_CHANNEL[j] = buffer[i*chans + canalMicro];
	  }

	  LeaveCriticalSection (&CriticalSection);
*/
	}
    else
	{

      try {
        audio->tickStream();
      }
      catch (RtError &error) {
        error.printMessage();
        goto cleanup;
      }

      break;
	}

  }//end while
  
  
  try {
    audio->stopStream();
  }
  catch (RtError &error) {
    error.printMessage();
  }

 cleanup:
  audio->closeStream();
  delete audio;

  sf_close (fdTOT);
  sf_close (fdEGG);
  sf_close (fdMicro);

  return 0;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
  int chans, fs, buffer_size, count, device = 0;
  long counter = 0;
  MY_TYPE *buffer;
  char *file;
  FILE *fd;
  RtAudio *audio;

  // minimal command-line checking
  if (argc != 4 && argc != 5 ) usage();

  chans = (int) atoi(argv[1]);
  fs = (int) atoi(argv[2]);
  file = argv[3];
  if ( argc == 5 )
    device = (int) atoi(argv[4]);

  fd = fopen(file,"rb");
  if (!fd) {
    std::cout << "can't find file!\n";
    exit(0);
  }

  // Open the realtime output device
  buffer_size = 512;
  try {
    audio = new RtAudio(device, chans, 0, 0,
                        FORMAT, fs, &buffer_size, 2);
  }
  catch (RtError &error) {
    fclose(fd);
    error.printMessage();
    exit(EXIT_FAILURE);
  }

  try {
    buffer = (MY_TYPE *) audio->getStreamBuffer();
    audio->startStream();
  }
  catch (RtError &error) {
    error.printMessage();
    goto cleanup;
  }

  while (1) {
    count = fread(buffer, chans * sizeof(MY_TYPE), buffer_size, fd);

    if (count == buffer_size) {
      try {
        audio->tickStream();
      }
      catch (RtError &error) {
        error.printMessage();
        goto cleanup;
      }
    }
    else
      break;
        
    counter += buffer_size;
  }

  try {
    audio->stopStream();
  }
  catch (RtError &error) {
    error.printMessage();
  }

 cleanup:
  audio->closeStream();
  delete audio;
  fclose(fd);

  return 0;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
  int chans, fs, buffer_size, device = 0;
  long frames, counter = 0;
  MY_TYPE *buffer;
  RtAudio *audio;

  // minimal command-line checking
  if (argc != 3 && argc != 4 ) usage();

  chans = (int) atoi(argv[1]);
  fs = (int) atoi(argv[2]);
  if ( argc == 4 )
    device = (int) atoi(argv[3]);

  // Open the realtime output device
  buffer_size = 512;
  try {
    audio = new RtAudio(device, chans, device, chans,
                        FORMAT, fs, &buffer_size, 8);
  }
  catch (RtError &error) {
    error.printMessage();
    exit(EXIT_FAILURE);
  }

  frames = (long) (fs * TIME);

  try {
    buffer = (MY_TYPE *) audio->getStreamBuffer();
    audio->startStream();
  }
  catch (RtError &error) {
    error.printMessage();
    goto cleanup;
  }

  std::cout << "\nRunning for " << TIME << " seconds ... fragment_size = " << buffer_size << std::endl;
  while (counter < frames) {

    try {
      audio->tickStream();
    }
    catch (RtError &error) {
      error.printMessage();
      goto cleanup;
    }
    counter += buffer_size;
  }

  try {
    audio->stopStream();
  }
  catch (RtError &error) {
    error.printMessage();
  }

 cleanup:
  audio->closeStream();
  delete audio;

  return 0;
}