[Stk] RtApiDummy: This class provides no functionality.
alpana jui
lpnjui at googlemail.com
Wed Sep 10 13:55:54 PDT 2008
Dear Gary and Steven;
Thank you very much for the advice.
I compiled RtAudio-4.0.4 and STK-4.3.1 using ./configure --with-core
and I used the preprocessor as atthched in the program:
/******************************************/
/*
audioprobe.cpp
by Gary P. Scavone, 2001
Probe audio system and prints device info.
*/
/******************************************/
#ifndef __MACOSX_CORE__
#define __MACOSX_CORE__
#endif
#include "RtAudio.h"
#include <iostream>
#include <map>
#include <CoreAudio/AudioHardware.h>
/*
typedef char MY_TYPE;
#define FORMAT RTAUDIO_SINT8
typedef signed short MY_TYPE;
#define FORMAT RTAUDIO_SINT16
typedef signed long MY_TYPE;
#define FORMAT RTAUDIO_SINT24
typedef signed long MY_TYPE;
#define FORMAT RTAUDIO_SINT32
*/
typedef float MY_TYPE;
#define FORMAT RTAUDIO_FLOAT32
/*
typedef double MY_TYPE;
#define FORMAT RTAUDIO_FLOAT64
*/
// Platform-dependent sleep routines.
#if defined( __WINDOWS_ASIO__ ) || defined( __WINDOWS_DS__ )
#include <windows.h>
#define SLEEP( milliseconds ) Sleep( (DWORD) milliseconds )
#else // Unix variants
#include <unistd.h>
#define SLEEP( milliseconds ) usleep( (unsigned long) (milliseconds * 1000.0) )
#endif
struct InputData {
MY_TYPE* buffer;
unsigned long bufferBytes;
unsigned long totalFrames;
unsigned long frameCounter;
unsigned int channels;
};
// Interleaved buffers
int input( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
double streamTime, RtAudioStreamStatus status, void *data )
{
InputData *iData = (InputData *) data;
// Simply copy the data to our allocated buffer.
unsigned int frames = nBufferFrames;
if ( iData->frameCounter + nBufferFrames > iData->totalFrames ) {
frames = iData->totalFrames - iData->frameCounter;
iData->bufferBytes = frames * iData->channels * sizeof( MY_TYPE );
}
unsigned long offset = iData->frameCounter * iData->channels;
memcpy( iData->buffer+offset, inputBuffer, iData->bufferBytes );
iData->frameCounter += frames;
if ( iData->frameCounter >= iData->totalFrames ) return 2;
return 0;
}
int main( int argc, char *argv[] )
{
unsigned int channels = 1, fs = 44100, bufferFrames, device = 0, offset = 0;
double time = 2.0;
FILE *fd;
RtAudio adc;
if ( adc.getDeviceCount() < 1 ) {
std::cout << "\nNo audio devices found!\n";
exit( 1 );
}
//
time = 3.0;
// Let RtAudio print messages to stderr.
adc.showWarnings( true );
// Set our stream parameters for input only.
bufferFrames = 512;
RtAudio::StreamParameters iParams;
iParams.deviceId = device;
iParams.nChannels = channels;
iParams.firstChannel = offset;
InputData data;
data.buffer = 0;
try {
adc.openStream( NULL, &iParams, FORMAT, fs, &bufferFrames, &input,
(void *)&data );
}
catch ( RtError& e ) {
std::cout << '\n' << e.getMessage() << '\n' << std::endl;
goto cleanup;
}
data.bufferBytes = bufferFrames * channels * sizeof( MY_TYPE );
data.totalFrames = (unsigned long) (fs * time);
data.frameCounter = 0;
data.channels = channels;
unsigned long totalBytes;
totalBytes = data.totalFrames * channels * sizeof( MY_TYPE );
// Allocate the entire data buffer before starting stream.
data.buffer = (MY_TYPE*) malloc( totalBytes );
if ( data.buffer == 0 ) {
std::cout << "Memory allocation error ... quitting!\n";
goto cleanup;
}
try {
adc.startStream();
}
catch ( RtError& e ) {
std::cout << '\n' << e.getMessage() << '\n' << std::endl;
goto cleanup;
}
std::cout << "\nRecording for " << time << " seconds ... writing file
'record.raw' (buffer frames = " << bufferFrames << ")." << std::endl;
while ( 1 ) {
SLEEP( 100 ); // wake every 100 ms to check if we're done
if ( adc.isStreamRunning() == false ) break;
}
// Now write the entire data to the file.
fd = fopen( "record.wav", "wb" );
fwrite( data.buffer, sizeof( MY_TYPE ), data.totalFrames * channels, fd );
fclose( fd );
cleanup:
if ( adc.isStreamOpen() ) adc.closeStream();
if ( data.buffer ) free( data.buffer );
return 0;
}
I tried audioprobe.cpp, some examples in the STK tutorial, also in my
task which I need to rewrite for spoken command interface for speech
feature extraction in our project. The preprocessor I add is as
follows:
But I have no success yet while trying this but the output is
RtApiDummy: This class provides no functionality.
RtApi::openStream: output device parameter value is invalid.
// __MACOSX_CORE__: OS X specific preprocessor
#ifndef __MACOSX_CORE__
#define __MACOSX_CORE__
#endif
#if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__) ||
defined(__WINDOWS_MM__)
#define __OS_WINDOWS__
#define __STK_REALTIME__
#elif defined(__LINUX_OSS__) || defined(__LINUX_ALSA__) ||
defined(__LINUX_JACK__)
#define __OS_LINUX__
#define __STK_REALTIME__
#elif defined(__IRIX_AL__)
#define __OS_IRIX__
#define __STK_REALTIME__
#elif defined(__MACOSX_CORE__)
#define __OS_MACOSX__
#define __STK_REALTIME__
#endif
#include <CoreAudio/AudioHardware.h>
_rec_status(false),
_adc(new RtAudio(RtAudio::MACOSX_CORE)),//_ASIO)),
_sampleRate(44100),//Hz
_bufferFrames(1024),//number of samples per cycle
_DCcoeffs ( *(new wxClientDC (panel_FT) ) ),
_scale_x (512), _scale_y(512), // dimension of panel_FT
_x ( new Signal), // needed for callbackfunction - RtAudio
_calls (0),//callback-counter
_cost (Entropy),
_costpar (0.1),
_fixed_analyze_size (8192),
_fb_counter (0),
_fixed_buffer( new real [_fixed_analyze_size] ),
_F (new FEATEXTR (*this, _fixed_analyze_size, 6U, 64U) )
{
assert(_adc);
assert(_x);
assert(_fixed_buffer);
_x->RtAudioInterface(_fixed_buffer, _fixed_analyze_size);
_COUT.open("/Users/Desktop/tuklwx/recordtestdata");
std::cout << _x << std::endl;
_adc-> getCurrentApi();
if ( _adc -> getDeviceCount() < 1 ) {
wxMessageBox ( _("No audio devices found!"));
button_rec -> Enable(false);
unsigned deviceId = 1;
_deviceinfo=_adc->getDeviceInfo(deviceId);// should be US-1641 for an ASIO api
_parameters.deviceId = deviceId;
_parameters.nChannels = 1;//_deviceinfo.inputChannels;//should be == 16
_parameters.firstChannel = 0;
//statusBar->SetStatusText(_deviceinfo.name, 1);
_adc-> getCurrentApi();
Unfortunately, I could not proceed further to start the next task
involved here while using AudioInterface. I do not how to solve this
problem. I will appreciate any recommendations that help me to
proceed.
Thank you and look forward to hearing from you,
Jui
On Wed, Sep 10, 2008 at 1:18 AM, alpana jui <lpnjui at googlemail.com> wrote:
> Dear Everybody,
>
>
> I tried to set MACOSX_CORE but I have the same output as attached
> in all the RtAudio tutorial examples.
>
> Compiled APIs:
> RtAudio Dummy
>
> RtApiDummy: This class provides no functionality.
>
>
> Current API: RtAudio Dummy
>
> Found 0 device(s) ...
>
>
> I need to read wav file and record some spoken command to read by
> RtAudio. But I could not proceed.
>
> Please help me and give me some hints to proceed.
>
> Thanks in advance,
> Jui
>
More information about the Stk
mailing list