Version 4.2.1

This commit is contained in:
Gary Scavone
2009-03-24 23:02:14 -04:00
committed by Stephen Sinclair
parent a6381b9d38
commit 2cbce2d8bd
275 changed files with 8949 additions and 6906 deletions

View File

@@ -6,14 +6,14 @@
By default, the program will write an
N channel WAV file. However, it is
simple to change the file type argument
in the WvOut constructor.
in the FileWvOut constructor.
By Gary P. Scavone, 2000 - 2002.
*/
/******************************************/
#include "WaveLoop.h"
#include "WvOut.h"
#include "SineWave.h"
#include "FileWvOut.h"
#include <stdlib.h>
void usage(void) {
@@ -31,7 +31,6 @@ int
main(int argc, char *argv[])
{
float base_freq = 220.0;
int samples;
int i;
// Minimal command-line checking.
@@ -41,55 +40,47 @@ main(int argc, char *argv[])
double time = atof(argv[3]);
double srate = atof(argv[4]);
// Initialize our object and data pointers.
WvOut *output = 0;
StkFloat *vector = 0;
WaveLoop **oscs = (WaveLoop **) malloc( channels * sizeof(WaveLoop *) );
// Create our object instances.
FileWvOut output;
SineWave **oscs = (SineWave **) malloc( channels * sizeof(SineWave *) );
for (i=0; i<channels; i++) oscs[i] = 0;
// If you want to change the default sample rate (set in Stk.h), do
// it before instantiating any objects!!
Stk::setSampleRate( srate );
// Define and load the rawwave file(s) ... the path is critical.
try {
for (i=0; i<channels; i++)
oscs[i] = new WaveLoop( "../../rawwaves/sinewave.raw", true );
}
catch (StkError &) {
goto cleanup;
}
// Define the sinewaves.
for (i=0; i<channels; i++)
oscs[i] = new SineWave;
// Set oscillator frequency(ies) here ... somewhat random.
for (i=0; i<channels; i++)
oscs[i]->setFrequency( base_freq + i*(45.0) );
// Define and open the soundfile for output. Other file
// format options include: WVOUT_SND, WVOUT_AIF, WVOUT_MAT,
// and WVOUT_RAW. Other data type options include:
// STK_SINT8, STK_SINT32, StkFloat32, and StkFloat64.
long nFrames = (long) ( time * Stk::sampleRate() );
StkFrames frames( nFrames, channels );
// Open the soundfile for output. Other file format options
// include: FILE_SND, FILE_AIF, FILE_MAT, and FILE_RAW. Other data
// type options include: STK_SINT8, STK_SINT32, StkFloat32, and
// StkFloat64.
try {
output = new WvOut( argv[2], channels, WvOut::WVOUT_WAV, Stk::STK_SINT16 );
output.openFile( argv[2], channels, FileWrite::FILE_WAV, Stk::STK_SINT16 );
}
catch (StkError &) {
goto cleanup;
}
// Here's the runtime loop
samples = (int) ( time * Stk::sampleRate() );
vector = (StkFloat *) new StkFloat[channels];
for ( i=0; i<samples; i++ ) {
for (int j=0; j<channels; j++) {
vector[j] = oscs[j]->tick();
}
output->tickFrame(vector);
}
// Here's the runtime code ... no loop
for ( i=0; i<channels; i++)
oscs[i]->tick( frames, i );
output.tickFrame( frames );
cleanup:
for (i=0; i<channels; i++)
for ( i=0; i<channels; i++ )
delete oscs[i];
free(oscs);
delete [] vector;
delete output;
return 0;
}