[Stk] RtAudio Interface to capture real time data
alpana jui
lpnjui at googlemail.com
Sat Aug 30 12:02:00 PDT 2008
Dear Gary,
I am using my colleauge code written for real time voice command
recording for a project but I could not compile this. I try to debug this
but the message was:
/Users/asr/P21/recMain.h:39: error: 'RtAudioStreamStatus' has not been
declared
/Users/P21/recMain.h:61: error: 'StreamParameters' in class 'RtAudio' does
not name a type
/Users/P21/recMain.h:84: error: 'DeviceInfo' in class 'RtAudio' does not
name a type
/Users/P21/RtAudioInterface.cpp:17: error: 'RtAudioStreamStatus' has not
been declared
Process terminated with status 1 (0 minutes, 1 seconds)
I attached the program if you could please provide your advice and kind help
what has been wrong here for using this RtAudio for recording some audio
command.
#include "recMain.h"
#include "SILTT.h"
#include "names_P21.h"
using namespace P21;
#include <iostream>
#include "FEATEXTR.h"
/*********************************************************************
*********************************************************************
global C-style callbackfunction
*********************************************************************
**********************************************************************/
int RtAudioInterface( void *outputBuffer,
void *inputBuffer,
unsigned int nBufferFrames,
double streamTime,
RtAudioStreamStatus status,
void *callbackdata )
{
recFrame* gui= static_cast<recFrame*>(callbackdata);
#if wxUSE_STATUSBAR
{
if ( status ){
// (gui->statusBar)->SetStatusText(
wxMessageBox(_("Streamoverflow detected"));//,0);
}
wxString t; t<<_("Time: ")<<streamTime<<_("\t|#: ")<<(gui->_calls);
(gui->statusBar)->SetStatusText(t,0);
}
#endif
// sonst speichere "alles" im zwischenspeicher
// :::::::::::::::::::_calls<32 &&
_fb_counter<_fixed_analyze_size:::::::::::::::::::::::::::::::::::
real* buffer=static_cast<real*>(inputBuffer);
if(nBufferFrames!=1024){ wxString t; t<<nBufferFrames; wxMessageBox(t);}
for(unsigned k=0;k<1024;k+=4,++(gui->_fb_counter))
gui->_fixed_buffer[gui->_fb_counter]=(buffer[k]+
buffer[k+1]*2.0+
buffer[k+2]*2.0+
buffer[k+3] )/6.0;
++(gui->_calls);
if( (gui->_calls<32) ) return 0;//speichere zwischen für calls=1,2,...,32
// hier _calls==32 (und größer)
// d.h. 32*(1024/4)=8192 reele daten gesammelt bis jetzt
// setzte gui->calls wieder auf null:
(gui->_calls)=0;
(gui->_fb_counter)=0;
// hier sollte die analyse dann starten
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/* mache folgende überlegung
---- für US-1641 ------- :
Samplingfrequenz: 44100 Hz (entspricht in etwa 4/3* 2^15 Hz)
höchste Pufferlänge (bei einem Mikro) 2^10 Samples
wir nehmen NUR jeden 4-ten Punkt aus dem Puffer (-> Samplingfrequenz
geht runter auf
4/3* 2^13 Hz)
und schreiben ergebnis in ein zwischenspeicher:
_fixed_buffer[0,...,2^13-1]
--- damit der ganze zwischenspeicher (nicht mehr und nicht weniger)
ausgenutzt wird,
benutzen wir die variable (gui->calls), die in diesem fall nicht größer
als 2^5 sein darf:
nBufferFrames=2^10 ----> 2^8 werden abgespeichert in _fixed_buffer, das
alles 2^5 mal, also
insgesamt 2^(8+5)
*/
//wxString t; t<<_("calls ")<<(gui->_calls)<<_("\n fb_counter:
")<<(gui->_fb_counter); gui->statusBar->SetStatusText(t,1);
//wxMessageBox(_("do analyze...\n"));
//(gui->_deviceinfo).name
// .sampleRates.size() --> .sampleRates[0,...]
//
Signal* _x=(gui->_x);
// this is already done in the recFrame-constructor:
//"_x->RtAudioInterface( gui->_fixed_buffer, gui->_fixed_analyze_size
);"
//=> gui->_fixed_analyze_size == _x->size()
SILTT analysis(static_cast<Signal&>(*_x), gui->_cost, gui->_costpar,
0.0);
analysis.dct(*_x);
FEATEXTR& F = *(gui->_F);
F.compute(analysis);
F.frequency().draw(analysis);
wxString shift,bbsize, costval,par;
shift<<analysis.shift(); bbsize<<analysis.bbsize();
costval<<analysis.cost();
gui->m_staticTextShiftIndex->SetLabel(shift);
gui->m_staticTextBBSize->SetLabel(bbsize);
gui->m_staticTextCostValue->SetLabel(costval);
par<<_("cost=")<<(gui->_costpar)<<_(" Freq:")<<(gui->_sampleRate)<<_("
buff= ")<<(gui->_bufferFrames)<<_(" F=")<<(gui->_cost)
;//<<_(" µ=")<<meanfreq;
(gui->statusBar)->SetStatusText(par,1);
return 0;
/*******************************************************************************
********************************************************************************
********************************************************************************
*******************************************************************************/
//compute a 2D (freq vs time) representation from analysis.dct-coeffs
// _bufferFrames==x.size() , x is a Signal-object
//analysis.show_dct();
// set switch to _dct -- used in SILTT::operator[](index i)
real* dct= analysis.get_add_dct();//*(analysis[0]);
//analysis.show_bbnodes();
P21::index* node=analysis.get_add_bbnodes();//*(analysis[0]);
unsigned char g; // gray-code index: 0-255
//compute max(dct)///////////////////////
real maxdct=fabs(dct[0]); /////
for(P21::index i=1;i<_x->size();++i) /////
if(maxdct<fabs( dct[i])) /////
maxdct=fabs( dct[i]); /////
/////////////////////////////////////////
P21::index dt, df;
wxString tmp;
// clear plot-area:
gui->_DCcoeffs.SetBrush(wxColour(0,0,0));(gui->_DCcoeffs).DrawRectangle(
0,0,
2*gui->_scale_x,2*gui->_scale_y);
P21::index nxbox, nybox, b;
depth d;
if(analysis.bbsize()==1)
{//plot a graph
for(P21::index x=0;x<_x->size();++x)
gui->_DCcoeffs.DrawPoint(static_cast<wxCoord>(600+10*dct[x]),static_cast<wxCoord>(600
- 20-x/10));
dt=gui->_scale_x;
df=1;//gui->_scale_y;
for(P21::index i=0, y=gui->_scale_y;i<512||y>0;--y) // for each
frequency-entry in a packet
{
g=static_cast<unsigned char>(ceil( 255*dct[++i]/maxdct ));
gui->_DCcoeffs.SetBrush(recFrame::GRAYMAP[ g ] );
gui->_DCcoeffs.SetPen(recFrame::GRAYMAP[ g ] );
gui->_DCcoeffs.DrawRectangle( 10,560-i,gui->_scale_x,1);
}
return 0; // be carefull!!! every resetting of any variable, like
_calls, should have been done before this step
}
for(P21::index t=10, i=0, p=0;p<analysis.bbsize();++p,t+=dt)// for each
best-basis packet
{//plot a plane
// d=floor(log2(node))
d=P21::_log2(node[p]); if(static_cast<P21::index>(1<<d)!= node[p]) --d;
nxbox=(1<<d); // <=> 2^d
// number of boxes in frequency(y)-direction <=> same as packetlength of
node(p)
nybox=( (gui->_fixed_analyze_size)>>d);// <=> N/2^d
//b=node[p]-nxbox;
//dt=static_cast<index>((
static_cast<double>(nxbox/(gui->_bufferFrames))*(gui->_scale_x) ));
dt=static_cast<P21::index>( (gui->_scale_x)/nxbox );
// if(dt==0) continue;
//df=static_cast<index>((
static_cast<double>(nybox/(gui->_bufferFrames))*(gui->_scale_y) ));
df=static_cast<P21::index>( (gui->_scale_y)/nybox );
// if(df==0) continue;
if(dt==0)// || df==0) // both should be non-zero
{
wxString s;
s<<_("nxBox=");
s<<nxbox<<_(" nyBox=");
s<<nybox<<_("\n [node,d,b]=");
s<<node[p]<<_(", ");
s<<d<<_(", ");
s<<b;
wxMessageBox(s);
continue;
}
P21::index K=1;
if( nybox>(gui->_scale_y) )
{
df=1;
K=nybox/(gui->_scale_y);
//wxString par; par<<_("K=")<<K;
// (gui->statusBar)->SetStatusText(par,1);
continue;
}
//plote zeitliche partitionierung:
gui->_DCcoeffs.SetBrush(*wxRED_BRUSH);
gui->_DCcoeffs.DrawRectangle( t,0,dt,10);
//for(index f=10+(gui->_scale_y),y=0;y<nybox+1;++y,f-=df) // for each
frequency-entry in a packet
for(P21::index y=0,f=gui->_scale_y-df+100;y<nybox;++y,f-=df) // for each
frequency-entry in a packet
{
if(K==1){
g=static_cast<unsigned char>(ceil( 255.0*dct[++i]/maxdct) );
}else{
real s=0;
for(P21::index j=0;j<K;++j) s+=dct[++i];
g=static_cast<unsigned char>(ceil( 255.0/K*s/maxdct ));
}
gui->_DCcoeffs.SetBrush(recFrame::GRAYMAP[ g ] );
gui->_DCcoeffs.SetPen(recFrame::GRAYMAP[ g ] );
gui->_DCcoeffs.DrawRectangle( t,f,dt,df);
}
}
return 0;
}
The other recMain.h file is also attached for your kind help:
/***************************************************************
* Name: recMain.h
* Purpose: Defines Application Frame
* Author: P21-UNI KL ()
* Created: 2008-02-21
* Copyright: P21-UNI KL ()
* License:
**************************************************************/
#ifndef RECMAIN_H
#define RECMAIN_H
#include <wx/wx.h>
#include "recApp.h"
#include "GUIFrame.h"
/***********/
#include "RtAudio.h"
#include<cassert>
#include "names_P21.h"
#include "Signal.h"
#include "FEATEXTR.h"
/***********/
#include <fstream>
class recFrame: public GUIFrame
{
friend class FEATEXTR;
public:
recFrame(wxFrame *frame);
~recFrame();
// declare CallBackFunction as friend
// in order to access GUI-handles
friend int RtAudioInterface( void *outputBuffer,
void *inputBuffer,
unsigned int nBufferFrames,
double streamTime,
RtAudioStreamStatus status,
void *callbackdata );
//const bool dct2matrix(const SILTT&);
private:
virtual void OnClose(wxCloseEvent& event);
virtual void OnQuit(wxCommandEvent& event);
virtual void OnAbout(wxCommandEvent& event);
virtual void OnRecord(wxCommandEvent& event
);//wxEVT_COMMAND_BUTTON_CLICKED &event)
virtual void OnChangeBufferSize(wxCommandEvent&
event);//wxEVT_COMMAND_CHOICE_SELECTED
virtual void OnChoiceOf_Freq( wxCommandEvent& event);
//wxEVT_COMMAND_CHOICE_SELECTED
virtual void OnEnter_CostPar( wxCommandEvent& event);
virtual void OnChoiceOf_CostFunc( wxCommandEvent& event);
//virtual void showCoeffs( wxMouseEvent& event );
virtual void paint( wxMouseEvent& event);
bool _rec_status; // true=now recording, false=awaiting further
commands
RtAudio::StreamParameters _parameters;
enum CONTROL{START_STREAM=40,STOP_STREAM,OPEN_STREAM,CLOSE_STREAM};
void _stream(CONTROL);
RtAudio* _adc;
unsigned _sampleRate, _bufferFrames;
wxClientDC& _DCcoeffs; // show DCT-coeffs
// some Brushes and Pens ???
static const wxColour GRAYMAP[256];
//static const wxCoord PLOTORIGIN;
P21::index _scale_x, _scale_y;
Signal* _x; // use empty constructor !!! that's the interface !!!
P21::index _calls; // counter for RtAudio-callbackfunction
Cost _cost;
real _costpar;
std::ofstream _COUT;
unsigned _fixed_analyze_size, _fb_counter;//
_fb_counter=0,...,_fixed_analyze_size-1
real* _fixed_buffer;
RtAudio::DeviceInfo _deviceinfo;
FEATEXTR* _F;
};
#endif // RECMAIN_H
Thank you very much for your valuable time adn advice.
With sincere thanks,
Jui
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ccrma-mail.stanford.edu/pipermail/stk/attachments/20080830/561c1ca9/attachment-0001.html
More information about the Stk
mailing list