[Stk] recording audio mac osx
Caitlin Sadowski
sadowski at apple.com
Mon Sep 10 11:35:19 PDT 2007
Hey,
I am attempting to write code which records 10 seconds (or else until
the enter key is pressed) of audio in coming from a 24-bit Edirol
and saves it as a WAV file. I have been using a callback function
since I am working on Mac OSX (and the blocking audio classes seem to
sometimes run into buffering problems on this OS).
The code I have written seems to work on my Macbook without the
Edirol, but when I try to use it in on my other computer (PPC G5),
with or without the Edirol, a file is recorded, but it is unplayable,
appears to be formatted incorrectly somehow, and shows up as having 0
channels. I am compiling the STK library files i reference in my
program for both ppc and intel chips.
I am missing something? There is not too much to the code (and it is
mostly based on the sample code from the tutorial) so I have included
it below. Am I using RtAudio with callbacks correctly? Any other
ideas on what is going wrong?
Thank you,
Caitlin Sadowski
static const Stk::StkFormat FILE_OUT_FORMAT = Stk::STK_SINT16;
int handleRead( void *outputBuffer, void *inputBuffer, unsigned int
nBufferFrames,
double streamTime, RtAudioStreamStatus status, void *outputFile )
{
unsigned int i, j;
StkFrames frame( 1, 2 ); //one frame with two channels
StkFloat *buffer = (StkFloat *) inputBuffer;
FileWvOut *output = (FileWvOut *)outputFile;
for ( i=0; i<nBufferFrames; i++ ) {
for ( j=0; j < NUMBER_OF_CHANNELS; j++ ) {
frame (0, j) = *buffer;
*buffer++;
}
output->tickFrame( frame );
}
return 0;
}
int recToFileCallback (string waveOutName, int length, int
sampleRate) {
Stk::showWarnings( true );
StkFrames frame( 1, NUMBER_OF_CHANNELS ); //one frame with two
channels
Stk::setSampleRate( sampleRate );
RtAudio adc;
FileWvOut output;
unsigned int bufferFrames = RT_BUFFER_SIZE; // sample frames, if we
need to specifiy
RtAudio::StreamParameters inParameters;
inParameters.deviceId = adc.getDefaultInputDevice();
inParameters.nChannels = 2;
inParameters.firstChannel = 0;
RtAudio::StreamOptions inOptions;
RtAudioFormat format = RTAUDIO_SINT24;
try {
output.openFile (waveOutName, NUMBER_OF_CHANNELS,
FileWrite::FILE_WAV, FILE_OUT_FORMAT);
adc.openStream( NULL, &inParameters, format, sampleRate,
&bufferFrames, &handleRead, (void *)(&output), &inOptions );
adc.startStream();
}
catch ( RtError& e ) {
e.printMessage();
exit( 0 );
}
char input;
std::cout << "\nPlaying ... press <enter> to quit.\n";
std::cin.get( input );
try {
adc.stopStream();
}
catch (RtError& e) {
e.printMessage();
}
if ( adc.isStreamOpen() ) adc.closeStream();
output.closeFile();
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/pipermail/stk/attachments/20070910/ff319ee5/attachment.html>
More information about the Stk
mailing list