[Stk] Two Questions About Mesh2D
Chris Share
cshare01@qub.ac.uk
Tue, 19 Jul 2005 15:43:07 +0100
Hi,
I'm interested in using Mesh2D for some research that I'm doing.
I have two questions regarding this class:
1. I've tried exciting the mesh with an impulse .wav file that I created
in Matlab. The response is written to a .wav file. This works OK however
the response seems to be overloaded. Here's my code:
#define SAMPLE_RATE 44100 /// The samplerate.
#define RUN_DURATION 1 /// The length of the output file (in seconds).
#define X_DIMENSION 10 /// X Dimension of the mesh (in nodes).
#define Y_DIMENSION 10 /// Y Dimension of the mesh (in nodes).
#define DECAY_FACTOR 0.5 /// Filter decay factor (range: 0.0 to 1.0).
#define INPUT_POS_X 0.5 /// X input position (range: 0.0 to 1.0).
#define INPUT_POS_Y 0.5 /// Y input position (range: 0.0 to 1.0).
/// Set the global sample rate.
Stk::setSampleRate(SAMPLE_RATE);
/// Declare the impulse file.
WvIn *impulse = 0;
/// Declare the output file.
WvOut *output = 0;
/// Declare the mesh.
Mesh2D *mesh2d = 0;
try
{
/// Define and open the impulse file.
impulse = new WvIn("impulse.wav", false, false);
/// Define and open a 16-bit, one-channel WAV formatted output file.
output = new WvOut("output.wav", 1, WvOut::WVOUT_WAV, Stk::STK_SINT16);
}
catch(StkError &)
{
/// Handle load error here.
TRACE("File Error");
return 0;
}
/// Create the mesh.
mesh2d = new Mesh2D(X_DIMENSION, Y_DIMENSION);
/// Set the filters' gain.
mesh2d->setDecay(DECAY_FACTOR);
/// Reset the mesh's internal state.
mesh2d->clear();
/// Set the input position. Value is between 0.0 and 1.0.
mesh2d->setInputPosition(INPUT_POS_X, INPUT_POS_Y);
/// Set the output position. Value is between 0.0 and 1.0.
/// Can't do this at the moment.
/// Excite the mesh.
/// Create the response and write the output to a .wav file.
int i;
for (i = 0; i < SAMPLE_RATE * RUN_DURATION; i++)
{
try
{
output->tick(mesh2d->tick(impulse->tick()));
}
catch (StkError &)
{
TRACE("Output Error");
return 0;
}
}
/// Delete the impulse and output file.
delete impulse;
delete output;
delete mesh2d;
Any idea why this is overloading?
2. I notice that there's a method called "noteOn" which can be used to
"impulse the mesh".
I've tried the following:
output->tick(mesh2d->tick(mesh2d->noteOn(440.0, 0.5)));
however I get the following error:
c:\Documents and Settings\Chris.LAPTOP\Desktop\Programming
Work\Waveguide\Waveguide_01\Waveguide_01Dlg.cpp(163) : error C2664:
'StkFloat Mesh2D::tick(StkFloat)' : cannot convert parameter 1 from
'void' to 'StkFloat'
Expressions of type void cannot be converted to other types
How is mesh2d->noteOn(...) meant to be used?
Cheers,
Chris