1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
/******************************************/
/*
Example program to record N channels of data
by Gary P. Scavone, 2000
NOTE: This program makes use of blocking audio
input/output routines. On systems where the
underlying audio API is based on a callback scheme
(Macintosh OS-X, Windows ASIO, and Linux JACK), these
routines are not fully robust (over/underruns can
happen with some frequency). See the STK tutorial
for example programs using callback schemes and/or
visit the RtAudio tutorial page
(http://music.mcgill.ca/~gary/rtaudio/) for more
information.
This program is currently written to read
from a realtime audio input device and to
write to a WAV output file. However, it
is simple to replace the FILE_TYPE specifier
to WvOut with another file type.
*/
/******************************************/
#include "RtWvIn.h"
#include "FileWvOut.h"
#include <cstdlib>
using namespace stk;
void usage( void ) {
// Error function in case of incorrect command-line
// argument specifications.
std::cout << "\nuseage: record N file time fs \n";
std::cout << " where N = number of channels,\n";
std::cout << " file = the .wav file to create,\n";
std::cout << " time = the amount of time to record (in seconds),\n";
std::cout << " and fs = the sample rate.\n\n";
exit( 0 );
}
int main( int argc, char *argv[] )
{
// minimal command-line checking
if ( argc != 5 ) usage();
Stk::showWarnings( true );
unsigned int channels = (unsigned int) atoi( argv[1] );
double sampleRate = atof( argv[4] );
double time = atof( argv[3] );
long samples, i;
StkFrames frame( 1, channels );
// Set the global sample rate.
Stk::setSampleRate( sampleRate );
// Initialize our WvIn/WvOut pointers.
RtWvIn *input = 0;
FileWvOut *output = 0;
// Open the realtime input device
try {
input = new RtWvIn( channels );
}
catch ( StkError & ) {
exit( 1 );
}
// Open the soundfile for output.
try {
output = new FileWvOut( argv[2], channels, FileWrite::FILE_WAV );
}
catch ( StkError & ) {
goto cleanup;
}
// Here's the runtime loop
samples = (long) ( time * Stk::sampleRate() );
for ( i=0; i<samples; i++ ) {
output->tick( input->tick( frame ) );
}
cleanup:
delete input;
delete output;
return 0;
}
|