mirror of
https://github.com/thestk/stk
synced 2026-04-23 07:48:36 +00:00
Version 4.2.0
This commit is contained in:
committed by
Stephen Sinclair
parent
cf06b7598b
commit
a6381b9d38
@@ -13,90 +13,101 @@
|
||||
Stanford, bearing the names of Karplus and/or
|
||||
Strong.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
#include "Drone.h"
|
||||
|
||||
Drone :: Drone(MY_FLOAT lowestFrequency)
|
||||
Drone :: Drone(StkFloat lowestFrequency)
|
||||
{
|
||||
length = (long) (Stk::sampleRate() / lowestFrequency + 1);
|
||||
loopGain = (MY_FLOAT) 0.999;
|
||||
delayLine = new DelayA( (MY_FLOAT)(length / 2.0), length );
|
||||
loopFilter = new OneZero;
|
||||
noise = new Noise;
|
||||
envelope = new ADSR();
|
||||
envelope->setAllTimes(2.0, 0.5, 0.0, 0.5);
|
||||
length_ = (unsigned long) (Stk::sampleRate() / lowestFrequency + 1);
|
||||
loopGain_ = 0.999;
|
||||
delayLine_.setMaximumDelay( length_ );
|
||||
delayLine_.setDelay( 0.5 * length_ );
|
||||
envelope_.setAllTimes( 2.0, 0.5, 0.0, 0.5 );
|
||||
this->clear();
|
||||
}
|
||||
|
||||
Drone :: ~Drone()
|
||||
{
|
||||
delete delayLine;
|
||||
delete loopFilter;
|
||||
delete envelope;
|
||||
delete noise;
|
||||
}
|
||||
|
||||
void Drone :: clear()
|
||||
{
|
||||
delayLine->clear();
|
||||
loopFilter->clear();
|
||||
delayLine_.clear();
|
||||
loopFilter_.clear();
|
||||
}
|
||||
|
||||
void Drone :: setFrequency(MY_FLOAT frequency)
|
||||
void Drone :: setFrequency(StkFloat frequency)
|
||||
{
|
||||
MY_FLOAT freakency = frequency;
|
||||
StkFloat freakency = frequency;
|
||||
if ( frequency <= 0.0 ) {
|
||||
std::cerr << "Drone: setFrequency parameter is less than or equal to zero!" << std::endl;
|
||||
errorString_ << "Drone::setFrequency: parameter is less than or equal to zero!";
|
||||
handleError( StkError::WARNING );
|
||||
freakency = 220.0;
|
||||
}
|
||||
|
||||
// Delay = length - approximate filter delay.
|
||||
MY_FLOAT delay = (Stk::sampleRate() / freakency) - (MY_FLOAT) 0.5;
|
||||
if (delay <= 0.0) delay = 0.3;
|
||||
else if (delay > length) delay = length;
|
||||
delayLine->setDelay(delay);
|
||||
loopGain = 0.997 + (freakency * 0.000002);
|
||||
if ( loopGain >= 1.0 ) loopGain = (MY_FLOAT) 0.99999;
|
||||
StkFloat delay = (Stk::sampleRate() / freakency) - 0.5;
|
||||
if ( delay <= 0.0 )
|
||||
delay = 0.3;
|
||||
else if (delay > length_)
|
||||
delay = length_;
|
||||
delayLine_.setDelay( delay );
|
||||
loopGain_ = 0.997 + (freakency * 0.000002);
|
||||
if ( loopGain_ >= 1.0 ) loopGain_ = 0.99999;
|
||||
}
|
||||
|
||||
void Drone :: pluck(MY_FLOAT amplitude)
|
||||
void Drone :: pluck(StkFloat amplitude)
|
||||
{
|
||||
envelope->keyOn();
|
||||
envelope_.keyOn();
|
||||
}
|
||||
|
||||
void Drone :: noteOn(MY_FLOAT frequency, MY_FLOAT amplitude)
|
||||
void Drone :: noteOn(StkFloat frequency, StkFloat amplitude)
|
||||
{
|
||||
this->setFrequency(frequency);
|
||||
this->pluck(amplitude);
|
||||
this->setFrequency( frequency );
|
||||
this->pluck( amplitude );
|
||||
|
||||
#if defined(_STK_DEBUG_)
|
||||
std::cerr << "Drone: NoteOn frequency = " << frequency << ", amplitude = " << amplitude << std::endl;
|
||||
errorString_ << "Drone::NoteOn: frequency = " << frequency << ", amplitude = " << amplitude << ".";
|
||||
handleError( StkError::DEBUG_WARNING );
|
||||
#endif
|
||||
}
|
||||
|
||||
void Drone :: noteOff(MY_FLOAT amplitude)
|
||||
void Drone :: noteOff(StkFloat amplitude)
|
||||
{
|
||||
loopGain = (MY_FLOAT) 1.0 - amplitude;
|
||||
if ( loopGain < 0.0 ) {
|
||||
std::cerr << "Drone: noteOff amplitude greater than 1.0!" << std::endl;
|
||||
loopGain = 0.0;
|
||||
loopGain_ = 1.0 - amplitude;
|
||||
if ( loopGain_ < 0.0 ) {
|
||||
errorString_ << "Drone::noteOff: amplitude is greater than 1.0 ... setting to 1.0!";
|
||||
handleError( StkError::WARNING );
|
||||
loopGain_ = 0.0;
|
||||
}
|
||||
else if ( loopGain > 1.0 ) {
|
||||
std::cerr << "Drone: noteOff amplitude less than or zero!" << std::endl;
|
||||
loopGain = (MY_FLOAT) 0.99999;
|
||||
else if ( loopGain_ > 1.0 ) {
|
||||
errorString_ << "Drone::noteOff: amplitude is < 0.0 ... setting to 0.0!";
|
||||
handleError( StkError::WARNING );
|
||||
loopGain_ = 0.99999;
|
||||
}
|
||||
|
||||
#if defined(_STK_DEBUG_)
|
||||
std::cerr << "Drone: NoteOff amplitude = " << amplitude << std::endl;
|
||||
errorString_ << "Drone::noteOff: amplitude = " << amplitude << ".";
|
||||
handleError( StkError::DEBUG_WARNING );
|
||||
#endif
|
||||
}
|
||||
|
||||
MY_FLOAT Drone :: tick()
|
||||
StkFloat Drone :: tick()
|
||||
{
|
||||
// Here's the whole inner loop of the instrument!!
|
||||
lastOutput = delayLine->tick( loopFilter->tick( delayLine->lastOut() * loopGain ) + (0.005 * envelope->tick() * noise->tick()));
|
||||
return lastOutput;
|
||||
lastOutput_ = delayLine_.tick( loopFilter_.tick( delayLine_.lastOut() * loopGain_ ) + (0.005 * envelope_.tick() * noise_.tick()));
|
||||
return lastOutput_;
|
||||
}
|
||||
|
||||
StkFloat *Drone :: tick(StkFloat *vector, unsigned int vectorSize)
|
||||
{
|
||||
return Instrmnt::tick( vector, vectorSize );
|
||||
}
|
||||
|
||||
StkFrames& Drone :: tick( StkFrames& frames, unsigned int channel )
|
||||
{
|
||||
return Instrmnt::tick( frames, channel );
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
Stanford, bearing the names of Karplus and/or
|
||||
Strong.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
#if !defined(__DRONE_H)
|
||||
#define __DRONE_H
|
||||
#ifndef STK_DRONE_H
|
||||
#define STK_DRONE_H
|
||||
|
||||
#include "Instrmnt.h"
|
||||
#include "DelayA.h"
|
||||
@@ -30,7 +30,7 @@ class Drone : public Instrmnt
|
||||
{
|
||||
public:
|
||||
//! Class constructor, taking the lowest desired playing frequency.
|
||||
Drone(MY_FLOAT lowestFrequency);
|
||||
Drone( StkFloat lowestFrequency = 20 );
|
||||
|
||||
//! Class destructor.
|
||||
~Drone();
|
||||
@@ -39,27 +39,39 @@ class Drone : public Instrmnt
|
||||
void clear();
|
||||
|
||||
//! Set instrument parameters for a particular frequency.
|
||||
virtual void setFrequency(MY_FLOAT frequency);
|
||||
virtual void setFrequency(StkFloat frequency);
|
||||
|
||||
//! Pluck the string with the given amplitude using the current frequency.
|
||||
void pluck(MY_FLOAT amplitude);
|
||||
void pluck(StkFloat amplitude);
|
||||
|
||||
//! Start a note with the given frequency and amplitude.
|
||||
virtual void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
|
||||
virtual void noteOn(StkFloat frequency, StkFloat amplitude);
|
||||
|
||||
//! Stop a note with the given amplitude (speed of decay).
|
||||
virtual void noteOff(MY_FLOAT amplitude);
|
||||
virtual void noteOff(StkFloat amplitude);
|
||||
|
||||
//! Compute one output sample.
|
||||
virtual MY_FLOAT tick();
|
||||
virtual StkFloat tick();
|
||||
|
||||
//! Computer \e vectorSize outputs and return them in \e vector.
|
||||
virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
|
||||
|
||||
//! Fill a channel of the StkFrames object with computed outputs.
|
||||
/*!
|
||||
The \c channel argument should be one or greater (the first
|
||||
channel is specified by 1). An StkError will be thrown if the \c
|
||||
channel argument is zero or it is greater than the number of
|
||||
channels in the StkFrames object.
|
||||
*/
|
||||
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
|
||||
|
||||
protected:
|
||||
DelayA *delayLine;
|
||||
OneZero *loopFilter;
|
||||
ADSR *envelope;
|
||||
Noise *noise;
|
||||
long length;
|
||||
MY_FLOAT loopGain;
|
||||
DelayA delayLine_;
|
||||
OneZero loopFilter_;
|
||||
ADSR envelope_;
|
||||
Noise noise_;
|
||||
StkFloat loopGain_;
|
||||
unsigned long length_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@ SRC_PATH = ../../src
|
||||
OBJECT_PATH = @object_path@
|
||||
vpath %.o $(OBJECT_PATH)
|
||||
|
||||
OBJECTS = Stk.o Envelope.o ADSR.o Noise.o \
|
||||
OBJECTS = Stk.o Generator.o Noise.o Envelope.o ADSR.o \
|
||||
Filter.o DelayA.o Delay.o \
|
||||
OnePole.o OneZero.o SKINI.o \
|
||||
OnePole.o OneZero.o Skini.o \
|
||||
Tabla.o Instrmnt.o Sitar.o \
|
||||
Drone.o VoicDrum.o WvOut.o WvIn.o \
|
||||
Reverb.o JCRev.o Messager.o
|
||||
Effect.o JCRev.o Messager.o
|
||||
|
||||
INCLUDE = @include@
|
||||
ifeq ($(strip $(INCLUDE)), )
|
||||
@@ -29,9 +29,8 @@ LIBRARY += @frameworks@
|
||||
|
||||
REALTIME = @realtime@
|
||||
ifeq ($(REALTIME),yes)
|
||||
OBJECTS += RtMidi.o RtAudio.o RtWvOut.o Thread.o Socket.o
|
||||
OBJECTS += RtMidi.o RtAudio.o RtWvOut.o Thread.o Mutex.o Socket.o
|
||||
DEFS += @audio_apis@
|
||||
DEFS += @midiator@
|
||||
endif
|
||||
|
||||
RAWWAVES = @rawwaves@
|
||||
@@ -48,6 +47,9 @@ all : $(PROGRAMS)
|
||||
ragamat: ragamat.cpp $(OBJECTS)
|
||||
$(CC) $(CFLAGS) $(DEFS) -o ragamat ragamat.cpp $(OBJECT_PATH)/*.o $(LIBRARY)
|
||||
|
||||
libragamat: ragamat.cpp Tabla.cpp Drone.cpp VoicDrum.cpp
|
||||
$(CC) $(CFLAGS) $(DEFS) -o ragamat Tabla.cpp Drone.cpp VoicDrum.cpp ragamat.cpp -L../../src $(LIBRARY) -lstk
|
||||
|
||||
$(OBJECTS) : Stk.h
|
||||
|
||||
clean :
|
||||
|
||||
1
projects/ragamatic/Raga
Executable file
1
projects/ragamatic/Raga
Executable file
@@ -0,0 +1 @@
|
||||
wish < tcl/Raga.tcl | ./ragamat -ip
|
||||
@@ -1 +1 @@
|
||||
wish < tcl/Raga.tcl | ./ragamat -ip
|
||||
wish < tcl/Raga.tcl | ragamat -ip
|
||||
|
||||
@@ -8,48 +8,49 @@
|
||||
at 22050 Hz, but will be appropriately
|
||||
interpolated for other sample rates. You can
|
||||
specify the maximum polyphony (maximum number
|
||||
of simultaneous voices) via a #define in the
|
||||
Drummer.h.
|
||||
of simultaneous voices) in Drummer.h.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
#include "Tabla.h"
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
Tabla :: Tabla() : Instrmnt()
|
||||
{
|
||||
for (int i=0; i<TABLA_POLYPHONY; i++) {
|
||||
filters[i] = new OnePole;
|
||||
sounding[i] = -1;
|
||||
for ( int i=0; i<TABLA_POLYPHONY; i++ ) {
|
||||
filters_[i] = new OnePole;
|
||||
sounding_[i] = -1;
|
||||
}
|
||||
|
||||
// This counts the number of sounding voices.
|
||||
nSounding = 0;
|
||||
nSounding_ = 0;
|
||||
}
|
||||
|
||||
Tabla :: ~Tabla()
|
||||
{
|
||||
int i;
|
||||
for ( i=0; i<nSounding-1; i++ ) delete waves[i];
|
||||
for ( i=0; i<TABLA_POLYPHONY; i++ ) delete filters[i];
|
||||
for ( i=0; i<nSounding_; i++ ) delete waves_[i];
|
||||
for ( i=0; i<TABLA_POLYPHONY; i++ ) delete filters_[i];
|
||||
}
|
||||
|
||||
void Tabla :: noteOn(MY_FLOAT instrument, MY_FLOAT amplitude)
|
||||
void Tabla :: noteOn(StkFloat instrument, StkFloat amplitude)
|
||||
{
|
||||
#if defined(_STK_DEBUG_)
|
||||
std::cerr << "Tabla: NoteOn instrument = " << instrument << ", amplitude = " << amplitude << std::endl;
|
||||
errorString_ << "Tabla::noteOn: instrument = " << instrument << ", amplitude = " << amplitude << '.';
|
||||
handleError( StkError::DEBUG_WARNING );
|
||||
#endif
|
||||
|
||||
MY_FLOAT gain = amplitude;
|
||||
StkFloat gain = amplitude;
|
||||
if ( amplitude > 1.0 ) {
|
||||
std::cerr << "Tabla: noteOn amplitude parameter is greater than 1.0!" << std::endl;
|
||||
errorString_ << "Tabla::noteOn: amplitude parameter is greater than 1.0 ... setting to 1.0.";
|
||||
handleError( StkError::WARNING );
|
||||
gain = 1.0;
|
||||
}
|
||||
else if ( amplitude < 0.0 ) {
|
||||
std::cerr << "Tabla: noteOn amplitude parameter is less than 0.0!" << std::endl;
|
||||
errorString_ << "Tabla::noteOn: amplitude parameter is less than 0.0 ... doing nothing.";
|
||||
handleError( StkError::WARNING );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -71,91 +72,99 @@ void Tabla :: noteOn(MY_FLOAT instrument, MY_FLOAT amplitude)
|
||||
"DrTak2.raw"
|
||||
};
|
||||
|
||||
int noteNum = ((int) instrument) % 16;
|
||||
int noteNum = ( (int) instrument ) % 16;
|
||||
|
||||
// Check first to see if there's already one like this sounding.
|
||||
int i, waveIndex = -1;
|
||||
for (i=0; i<TABLA_POLYPHONY; i++) {
|
||||
if (sounding[i] == noteNum) waveIndex = i;
|
||||
for ( i=0; i<TABLA_POLYPHONY; i++ ) {
|
||||
if ( sounding_[i] == noteNum ) waveIndex = i;
|
||||
}
|
||||
|
||||
if ( waveIndex >= 0 ) {
|
||||
// Reset this sound.
|
||||
waves[waveIndex]->reset();
|
||||
filters[waveIndex]->setPole((MY_FLOAT) 0.999 - (gain * 0.6));
|
||||
filters[waveIndex]->setGain(gain);
|
||||
waves_[waveIndex]->reset();
|
||||
filters_[waveIndex]->setPole( 0.999 - (gain * 0.6) );
|
||||
filters_[waveIndex]->setGain( gain );
|
||||
}
|
||||
else {
|
||||
if (nSounding == TABLA_POLYPHONY) {
|
||||
if ( nSounding_ == TABLA_POLYPHONY ) {
|
||||
// If we're already at maximum polyphony, then preempt the oldest voice.
|
||||
delete waves[0];
|
||||
filters[0]->clear();
|
||||
WvIn *tempWv = waves[0];
|
||||
OnePole *tempFilt = filters[0];
|
||||
delete waves_[0];
|
||||
filters_[0]->clear();
|
||||
OnePole *tempFilt = filters_[0];
|
||||
// Re-order the list.
|
||||
for (i=0; i<TABLA_POLYPHONY-1; i++) {
|
||||
waves[i] = waves[i+1];
|
||||
filters[i] = filters[i+1];
|
||||
for ( i=0; i<TABLA_POLYPHONY-1; i++ ) {
|
||||
waves_[i] = waves_[i+1];
|
||||
filters_[i] = filters_[i+1];
|
||||
}
|
||||
waves[TABLA_POLYPHONY-1] = tempWv;
|
||||
filters[TABLA_POLYPHONY-1] = tempFilt;
|
||||
waves_[TABLA_POLYPHONY-1] = 0;
|
||||
filters_[TABLA_POLYPHONY-1] = tempFilt;
|
||||
}
|
||||
else
|
||||
nSounding += 1;
|
||||
nSounding_ += 1;
|
||||
|
||||
sounding[nSounding-1] = noteNum;
|
||||
// Concatenate the STK RAWWAVE_PATH to the rawwave file
|
||||
char path[128];
|
||||
strcpy(path, "rawwaves/");
|
||||
strcat(path, tablaWaves[noteNum]);
|
||||
waves[nSounding-1] = new WvIn(path, TRUE);
|
||||
waves[nSounding-1]->normalize(0.4);
|
||||
filters[nSounding-1]->setPole((MY_FLOAT) 0.999 - (gain * 0.6) );
|
||||
filters[nSounding-1]->setGain( gain );
|
||||
sounding_[nSounding_-1] = noteNum;
|
||||
// Concatenate the rawwave path to the file name.
|
||||
waves_[nSounding_-1] = new WvIn( (std::string("rawwaves/") + tablaWaves[noteNum]).c_str(), true );
|
||||
waves_[nSounding_-1]->normalize(0.4);
|
||||
if ( Stk::sampleRate() != 22050.0 )
|
||||
waves_[nSounding_-1]->setRate( 22050.0 / Stk::sampleRate() );
|
||||
filters_[nSounding_-1]->setPole( 0.999 - (gain * 0.6) );
|
||||
filters_[nSounding_-1]->setGain( gain );
|
||||
}
|
||||
|
||||
#if defined(_STK_DEBUG_)
|
||||
std::cerr << "Number Sounding = " << nSounding << std::endl;
|
||||
for (i=0; i<nSounding; i++) std::cerr << sounding[i] << " ";
|
||||
std::cerr << "\n";
|
||||
errorString_ << "Tabla::noteOn: number sounding = " << nSounding_ << '\n';
|
||||
for (i=0; i<nSounding_; i++) errorString_ << sounding_[i] << " ";
|
||||
errorString_ << '\n';
|
||||
handleError( StkError::DEBUG_WARNING );
|
||||
#endif
|
||||
}
|
||||
|
||||
void Tabla :: noteOff(MY_FLOAT amplitude)
|
||||
void Tabla :: noteOff(StkFloat amplitude)
|
||||
{
|
||||
// Set all sounding wave filter gains low.
|
||||
int i = 0;
|
||||
while(i < nSounding) {
|
||||
filters[i++]->setGain( amplitude * 0.01 );
|
||||
}
|
||||
while ( i < nSounding_ )
|
||||
filters_[i++]->setGain( amplitude * 0.01 );
|
||||
}
|
||||
|
||||
MY_FLOAT Tabla :: tick()
|
||||
StkFloat Tabla :: tick()
|
||||
{
|
||||
MY_FLOAT output = 0.0;
|
||||
OnePole *tempFilt;
|
||||
|
||||
int j, i = 0;
|
||||
while (i < nSounding) {
|
||||
if ( waves[i]->isFinished() ) {
|
||||
delete waves[i];
|
||||
tempFilt = filters[i];
|
||||
lastOutput_ = 0.0;
|
||||
while ( i < nSounding_ ) {
|
||||
if ( waves_[i]->isFinished() ) {
|
||||
delete waves_[i];
|
||||
tempFilt = filters_[i];
|
||||
// Re-order the list.
|
||||
for (j=i; j<nSounding-1; j++) {
|
||||
sounding[j] = sounding[j+1];
|
||||
waves[j] = waves[j+1];
|
||||
filters[j] = filters[j+1];
|
||||
for ( j=i; j<nSounding_-1; j++ ) {
|
||||
sounding_[j] = sounding_[j+1];
|
||||
waves_[j] = waves_[j+1];
|
||||
filters_[j] = filters_[j+1];
|
||||
}
|
||||
filters[j] = tempFilt;
|
||||
filters[j]->clear();
|
||||
sounding[j] = -1;
|
||||
nSounding -= 1;
|
||||
filters_[j] = tempFilt;
|
||||
filters_[j]->clear();
|
||||
sounding_[j] = -1;
|
||||
nSounding_ -= 1;
|
||||
i -= 1;
|
||||
}
|
||||
else
|
||||
output += filters[i]->tick( waves[i]->tick() );
|
||||
lastOutput_ += filters_[i]->tick( waves_[i]->tick() );
|
||||
i++;
|
||||
}
|
||||
|
||||
return output;
|
||||
return lastOutput_;
|
||||
}
|
||||
|
||||
StkFloat *Tabla :: tick(StkFloat *vector, unsigned int vectorSize)
|
||||
{
|
||||
return Instrmnt::tick( vector, vectorSize );
|
||||
}
|
||||
|
||||
StkFrames& Tabla :: tick( StkFrames& frames, unsigned int channel )
|
||||
{
|
||||
return Instrmnt::tick( frames, channel );
|
||||
}
|
||||
|
||||
@@ -8,22 +8,21 @@
|
||||
at 22050 Hz, but will be appropriately
|
||||
interpolated for other sample rates. You can
|
||||
specify the maximum polyphony (maximum number
|
||||
of simultaneous voices) via a #define in the
|
||||
Drummer.h.
|
||||
of simultaneous voices) in Drummer.h.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
#if !defined(__TABLA_H)
|
||||
#define __TABLA_H
|
||||
#ifndef STK_TABLA_H
|
||||
#define STK_TABLA_H
|
||||
|
||||
#include "Instrmnt.h"
|
||||
#include "WvIn.h"
|
||||
#include "OnePole.h"
|
||||
|
||||
#define TABLA_NUMWAVES 15
|
||||
#define TABLA_POLYPHONY 4
|
||||
const int TABLA_NUMWAVES = 15;
|
||||
const int TABLA_POLYPHONY = 4;
|
||||
|
||||
class Tabla : public Instrmnt
|
||||
{
|
||||
@@ -35,19 +34,31 @@ class Tabla : public Instrmnt
|
||||
~Tabla();
|
||||
|
||||
//! Start a note with the given drum type and amplitude.
|
||||
void noteOn(MY_FLOAT instrument, MY_FLOAT amplitude);
|
||||
void noteOn(StkFloat instrument, StkFloat amplitude);
|
||||
|
||||
//! Stop a note with the given amplitude (speed of decay).
|
||||
void noteOff(MY_FLOAT amplitude);
|
||||
void noteOff(StkFloat amplitude);
|
||||
|
||||
//! Compute one output sample.
|
||||
MY_FLOAT tick();
|
||||
StkFloat tick();
|
||||
|
||||
//! Computer \e vectorSize outputs and return them in \e vector.
|
||||
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
|
||||
|
||||
//! Fill a channel of the StkFrames object with computed outputs.
|
||||
/*!
|
||||
The \c channel argument should be one or greater (the first
|
||||
channel is specified by 1). An StkError will be thrown if the \c
|
||||
channel argument is zero or it is greater than the number of
|
||||
channels in the StkFrames object.
|
||||
*/
|
||||
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
|
||||
|
||||
protected:
|
||||
WvIn *waves[TABLA_POLYPHONY];
|
||||
OnePole *filters[TABLA_POLYPHONY];
|
||||
int sounding[TABLA_POLYPHONY];
|
||||
int nSounding;
|
||||
WvIn *waves_[TABLA_POLYPHONY];
|
||||
OnePole *filters_[TABLA_POLYPHONY];
|
||||
int sounding_[TABLA_POLYPHONY];
|
||||
int nSounding_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -8,48 +8,49 @@
|
||||
at 22050 Hz, but will be appropriately
|
||||
interpolated for other sample rates. You can
|
||||
specify the maximum polyphony (maximum number
|
||||
of simultaneous voices) via a #define in the
|
||||
Drummer.h.
|
||||
of simultaneous voices) in Drummer.h.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
#include "VoicDrum.h"
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
VoicDrum :: VoicDrum() : Instrmnt()
|
||||
{
|
||||
for (int i=0; i<VOICE_POLYPHONY; i++) {
|
||||
filters[i] = new OnePole;
|
||||
sounding[i] = -1;
|
||||
for ( int i=0; i<VOICE_POLYPHONY; i++ ) {
|
||||
filters_[i] = new OnePole;
|
||||
sounding_[i] = -1;
|
||||
}
|
||||
|
||||
// This counts the number of sounding voices.
|
||||
nSounding = 0;
|
||||
nSounding_ = 0;
|
||||
}
|
||||
|
||||
VoicDrum :: ~VoicDrum()
|
||||
{
|
||||
int i;
|
||||
for ( i=0; i<nSounding-1; i++ ) delete waves[i];
|
||||
for ( i=0; i<VOICE_POLYPHONY; i++ ) delete filters[i];
|
||||
for ( i=0; i<nSounding_; i++ ) delete waves_[i];
|
||||
for ( i=0; i<VOICE_POLYPHONY; i++ ) delete filters_[i];
|
||||
}
|
||||
|
||||
void VoicDrum :: noteOn(MY_FLOAT instrument, MY_FLOAT amplitude)
|
||||
void VoicDrum :: noteOn( StkFloat instrument, StkFloat amplitude )
|
||||
{
|
||||
#if defined(_STK_DEBUG_)
|
||||
std::cerr << "VoicDrum: NoteOn instrument = " << instrument << ", amplitude = " << amplitude << std::endl;
|
||||
errorString_ << "VoicDrum::noteOn: instrument = " << instrument << ", amplitude = " << amplitude << '.';
|
||||
handleError( StkError::DEBUG_WARNING );
|
||||
#endif
|
||||
|
||||
MY_FLOAT gain = amplitude;
|
||||
StkFloat gain = amplitude;
|
||||
if ( amplitude > 1.0 ) {
|
||||
std::cerr << "VoicDrum: noteOn amplitude parameter is greater than 1.0!" << std::endl;
|
||||
errorString_ << "VoicDrum::noteOn: amplitude parameter is greater than 1.0 ... setting to 1.0.";
|
||||
handleError( StkError::WARNING );
|
||||
gain = 1.0;
|
||||
}
|
||||
else if ( amplitude < 0.0 ) {
|
||||
std::cerr << "VoicDrum: noteOn amplitude parameter is less than 0.0!" << std::endl;
|
||||
errorString_ << "VoicDrum::noteOn: amplitude parameter is less than 0.0 ... doing nothing.";
|
||||
handleError( StkError::WARNING );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -68,91 +69,98 @@ void VoicDrum :: noteOn(MY_FLOAT instrument, MY_FLOAT amplitude)
|
||||
"tak4.raw"
|
||||
};
|
||||
|
||||
int noteNum = ((int) instrument) % 11;
|
||||
int noteNum = ( (int) instrument ) % 11;
|
||||
|
||||
// Check first to see if there's already one like this sounding.
|
||||
int i, waveIndex = -1;
|
||||
for (i=0; i<VOICE_POLYPHONY; i++) {
|
||||
if (sounding[i] == noteNum) waveIndex = i;
|
||||
for ( i=0; i<VOICE_POLYPHONY; i++ ) {
|
||||
if ( sounding_[i] == noteNum ) waveIndex = i;
|
||||
}
|
||||
|
||||
if ( waveIndex >= 0 ) {
|
||||
// Reset this sound.
|
||||
waves[waveIndex]->reset();
|
||||
filters[waveIndex]->setPole((MY_FLOAT) 0.999 - (gain * 0.6));
|
||||
filters[waveIndex]->setGain(gain);
|
||||
waves_[waveIndex]->reset();
|
||||
filters_[waveIndex]->setPole( 0.999 - (gain * 0.6) );
|
||||
filters_[waveIndex]->setGain( gain );
|
||||
}
|
||||
else {
|
||||
if (nSounding == VOICE_POLYPHONY) {
|
||||
if ( nSounding_ == VOICE_POLYPHONY ) {
|
||||
// If we're already at maximum polyphony, then preempt the oldest voice.
|
||||
delete waves[0];
|
||||
filters[0]->clear();
|
||||
WvIn *tempWv = waves[0];
|
||||
OnePole *tempFilt = filters[0];
|
||||
delete waves_[0];
|
||||
filters_[0]->clear();
|
||||
OnePole *tempFilt = filters_[0];
|
||||
// Re-order the list.
|
||||
for (i=0; i<VOICE_POLYPHONY-1; i++) {
|
||||
waves[i] = waves[i+1];
|
||||
filters[i] = filters[i+1];
|
||||
for ( i=0; i<VOICE_POLYPHONY-1; i++ ) {
|
||||
waves_[i] = waves_[i+1];
|
||||
filters_[i] = filters_[i+1];
|
||||
}
|
||||
waves[VOICE_POLYPHONY-1] = tempWv;
|
||||
filters[VOICE_POLYPHONY-1] = tempFilt;
|
||||
waves_[VOICE_POLYPHONY-1] = 0;
|
||||
filters_[VOICE_POLYPHONY-1] = tempFilt;
|
||||
}
|
||||
else
|
||||
nSounding += 1;
|
||||
nSounding_ += 1;
|
||||
|
||||
sounding[nSounding-1] = noteNum;
|
||||
// Concatenate the STK RAWWAVE_PATH to the rawwave file
|
||||
char path[128];
|
||||
strcpy(path, "rawwaves/");
|
||||
strcat(path, voiceNames[noteNum]);
|
||||
waves[nSounding-1] = new WvIn(path, TRUE);
|
||||
waves[nSounding-1]->normalize(0.4);
|
||||
filters[nSounding-1]->setPole((MY_FLOAT) 0.999 - (gain * 0.6) );
|
||||
filters[nSounding-1]->setGain( gain );
|
||||
sounding_[nSounding_-1] = noteNum;
|
||||
// Concatenate the rawwave path to the file name.
|
||||
waves_[nSounding_-1] = new WvIn( (std::string("rawwaves/") + voiceNames[noteNum]).c_str(), true );
|
||||
waves_[nSounding_-1]->normalize(0.4);
|
||||
if (Stk::sampleRate() != 22050.0)
|
||||
waves_[nSounding_-1]->setRate( 22050.0 / Stk::sampleRate() );
|
||||
filters_[nSounding_-1]->setPole( 0.999 - (gain * 0.6) );
|
||||
filters_[nSounding_-1]->setGain( gain );
|
||||
}
|
||||
|
||||
#if defined(_STK_DEBUG_)
|
||||
std::cerr << "Number Sounding = " << nSounding << std::endl;
|
||||
for (i=0; i<nSounding; i++) std::cerr << sounding[i] << " ";
|
||||
std::cerr << "\n";
|
||||
errorString_ << "VoicDrum::noteOn: number sounding = " << nSounding_ << '\n';
|
||||
for (i=0; i<nSounding_; i++) errorString_ << sounding_[i] << " ";
|
||||
errorString_ << '\n';
|
||||
handleError( StkError::DEBUG_WARNING );
|
||||
#endif
|
||||
}
|
||||
|
||||
void VoicDrum :: noteOff(MY_FLOAT amplitude)
|
||||
void VoicDrum :: noteOff(StkFloat amplitude)
|
||||
{
|
||||
// Set all sounding wave filter gains low.
|
||||
int i = 0;
|
||||
while(i < nSounding) {
|
||||
filters[i++]->setGain( amplitude * 0.01 );
|
||||
}
|
||||
while ( i < nSounding_ ) filters_[i++]->setGain( amplitude * 0.01 );
|
||||
}
|
||||
|
||||
MY_FLOAT VoicDrum :: tick()
|
||||
StkFloat VoicDrum :: tick()
|
||||
{
|
||||
MY_FLOAT output = 0.0;
|
||||
OnePole *tempFilt;
|
||||
|
||||
int j, i = 0;
|
||||
while (i < nSounding) {
|
||||
if ( waves[i]->isFinished() ) {
|
||||
delete waves[i];
|
||||
tempFilt = filters[i];
|
||||
lastOutput_ = 0.0;
|
||||
while ( i < nSounding_ ) {
|
||||
if ( waves_[i]->isFinished() ) {
|
||||
delete waves_[i];
|
||||
tempFilt = filters_[i];
|
||||
// Re-order the list.
|
||||
for (j=i; j<nSounding-1; j++) {
|
||||
sounding[j] = sounding[j+1];
|
||||
waves[j] = waves[j+1];
|
||||
filters[j] = filters[j+1];
|
||||
for ( j=i; j<nSounding_-1; j++ ) {
|
||||
sounding_[j] = sounding_[j+1];
|
||||
waves_[j] = waves_[j+1];
|
||||
filters_[j] = filters_[j+1];
|
||||
}
|
||||
filters[j] = tempFilt;
|
||||
filters[j]->clear();
|
||||
sounding[j] = -1;
|
||||
nSounding -= 1;
|
||||
filters_[j] = tempFilt;
|
||||
filters_[j]->clear();
|
||||
sounding_[j] = -1;
|
||||
nSounding_ -= 1;
|
||||
i -= 1;
|
||||
}
|
||||
else
|
||||
output += filters[i]->tick( waves[i]->tick() );
|
||||
lastOutput_ += filters_[i]->tick( waves_[i]->tick() );
|
||||
i++;
|
||||
}
|
||||
|
||||
return output;
|
||||
return lastOutput_;
|
||||
}
|
||||
|
||||
StkFloat *VoicDrum :: tick(StkFloat *vector, unsigned int vectorSize)
|
||||
{
|
||||
return Instrmnt::tick( vector, vectorSize );
|
||||
}
|
||||
|
||||
StkFrames& VoicDrum :: tick( StkFrames& frames, unsigned int channel )
|
||||
{
|
||||
return Instrmnt::tick( frames, channel );
|
||||
}
|
||||
|
||||
@@ -8,22 +8,21 @@
|
||||
at 22050 Hz, but will be appropriately
|
||||
interpolated for other sample rates. You can
|
||||
specify the maximum polyphony (maximum number
|
||||
of simultaneous voices) via a #define in the
|
||||
Drummer.h.
|
||||
of simultaneous voices) in Drummer.h.
|
||||
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
|
||||
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
|
||||
*/
|
||||
/***************************************************/
|
||||
|
||||
#if !defined(__VOICDRUM_H)
|
||||
#define __VOICDRUM_H
|
||||
#ifndef STK_VOICDRUM_H
|
||||
#define STK_VOICDRUM_H
|
||||
|
||||
#include "Instrmnt.h"
|
||||
#include "WvIn.h"
|
||||
#include "OnePole.h"
|
||||
|
||||
#define VOICE_NUMWAVES 11
|
||||
#define VOICE_POLYPHONY 4
|
||||
const int VOICE_NUMWAVES = 11;
|
||||
const int VOICE_POLYPHONY = 4;
|
||||
|
||||
class VoicDrum : public Instrmnt
|
||||
{
|
||||
@@ -35,19 +34,31 @@ class VoicDrum : public Instrmnt
|
||||
~VoicDrum();
|
||||
|
||||
//! Start a note with the given drum type and amplitude.
|
||||
void noteOn(MY_FLOAT instrument, MY_FLOAT amplitude);
|
||||
void noteOn(StkFloat instrument, StkFloat amplitude);
|
||||
|
||||
//! Stop a note with the given amplitude (speed of decay).
|
||||
void noteOff(MY_FLOAT amplitude);
|
||||
void noteOff(StkFloat amplitude);
|
||||
|
||||
//! Compute one output sample.
|
||||
MY_FLOAT tick();
|
||||
StkFloat tick();
|
||||
|
||||
//! Computer \e vectorSize outputs and return them in \e vector.
|
||||
StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
|
||||
|
||||
//! Fill a channel of the StkFrames object with computed outputs.
|
||||
/*!
|
||||
The \c channel argument should be one or greater (the first
|
||||
channel is specified by 1). An StkError will be thrown if the \c
|
||||
channel argument is zero or it is greater than the number of
|
||||
channels in the StkFrames object.
|
||||
*/
|
||||
StkFrames& tick( StkFrames& frames, unsigned int channel = 1 );
|
||||
|
||||
protected:
|
||||
WvIn *waves[VOICE_POLYPHONY];
|
||||
OnePole *filters[VOICE_POLYPHONY];
|
||||
int sounding[VOICE_POLYPHONY];
|
||||
int nSounding;
|
||||
WvIn *waves_[VOICE_POLYPHONY];
|
||||
OnePole *filters_[VOICE_POLYPHONY];
|
||||
int sounding_[VOICE_POLYPHONY];
|
||||
int nSounding_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,272 +1,342 @@
|
||||
/************** Test Main Program Individual Voice *********************/
|
||||
|
||||
#include "RtWvOut.h"
|
||||
#include "SKINI.msg"
|
||||
#include "Instrmnt.h"
|
||||
#include "Reverb.h"
|
||||
#include "JCRev.h"
|
||||
#include "Drone.h"
|
||||
#include "Sitar.h"
|
||||
#include "Tabla.h"
|
||||
#include "VoicDrum.h"
|
||||
|
||||
// The input control handler.
|
||||
#include "Messager.h"
|
||||
#include "RtAudio.h"
|
||||
|
||||
MY_FLOAT float_random(MY_FLOAT max) // Return random float between 0.0 and max
|
||||
#include <signal.h>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#if !defined(__OS_WINDOWS__) // Windoze bogosity for VC++ 6.0
|
||||
using std::min;
|
||||
#endif
|
||||
|
||||
StkFloat float_random(StkFloat max) // Return random float between 0.0 and max
|
||||
{
|
||||
MY_FLOAT temp = (MY_FLOAT) (max * rand() / (RAND_MAX + 1.0) );
|
||||
StkFloat temp = (StkFloat) (max * rand() / (RAND_MAX + 1.0) );
|
||||
return temp;
|
||||
}
|
||||
|
||||
void usage(void) {
|
||||
/* Error function in case of incorrect command-line argument specifications */
|
||||
printf("\nuseage: ragamat flags \n");
|
||||
printf(" where flag = -s RATE to specify a sample rate,\n");
|
||||
printf(" flag = -ip for realtime SKINI input by pipe\n");
|
||||
printf(" (won't work under Win95/98),\n");
|
||||
printf(" and flag = -is <port> for realtime SKINI input by socket.\n");
|
||||
// Error function in case of incorrect command-line argument specifications.
|
||||
std::cout << "\nuseage: ragamat flags \n";
|
||||
std::cout << " where flag = -s RATE to specify a sample rate,\n";
|
||||
std::cout << " flag = -ip for realtime SKINI input by pipe\n";
|
||||
std::cout << " (won't work under Win95/98),\n";
|
||||
std::cout << " and flag = -is <port> for realtime SKINI input by socket.\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
bool done;
|
||||
RtWvOut *output;
|
||||
Instrmnt *drones[3];
|
||||
Instrmnt *sitar;
|
||||
Instrmnt *voicDrums;
|
||||
Instrmnt *tabla;
|
||||
Reverb *reverbs[2];
|
||||
SKINI *score;
|
||||
Messager *messager;
|
||||
MY_FLOAT t60 = 4.0; // in seconds
|
||||
bool done;
|
||||
static void finish(int ignore){ done = true; }
|
||||
|
||||
MY_FLOAT drone_prob = 0.01, note_prob = 0.0;
|
||||
MY_FLOAT drum_prob = 0.0, voic_prob = 0.0;
|
||||
MY_FLOAT droneFreqs[3] = {55.0,82.5,220.0};
|
||||
int tempo = 3000;
|
||||
int counter = 3000;
|
||||
int key = 0;
|
||||
int ragaStep, ragaPoint = 6, voicNote;
|
||||
int ragaUp[2][13] = {{57, 60, 62, 64, 65, 68, 69, 71, 72, 76, 77, 81},
|
||||
{52, 54, 55, 57, 59, 60, 63, 64, 66, 67, 71, 72}};
|
||||
int ragaDown[2][13] = {{57, 60, 62, 64, 65, 67, 69, 71, 72, 76, 79, 81},
|
||||
{48, 52, 53, 55, 57, 59, 60, 64, 66, 68, 70, 72}};
|
||||
// The TickData structure holds all the class instances and data that
|
||||
// are shared by the various processing functions.
|
||||
struct TickData {
|
||||
JCRev reverbs[2];
|
||||
Drone drones[3];
|
||||
Sitar sitar;
|
||||
VoicDrum voicDrums;
|
||||
Tabla tabla;
|
||||
Messager messager;
|
||||
Skini::Message message;
|
||||
StkFloat lastSample;
|
||||
StkFloat t60;
|
||||
int counter;
|
||||
bool settling;
|
||||
bool haveMessage;
|
||||
StkFloat droneChance, noteChance;
|
||||
StkFloat drumChance, voiceChance;
|
||||
int tempo;
|
||||
int chanceCounter;
|
||||
int key;
|
||||
int ragaStep;
|
||||
int ragaPoint;
|
||||
int endPhase;
|
||||
StkFloat rateScaler;
|
||||
|
||||
// Default constructor.
|
||||
TickData()
|
||||
: t60(4.0), counter(0),
|
||||
settling( false ), haveMessage( false ), droneChance(0.01), noteChance(0.01),
|
||||
drumChance(0.0), voiceChance(0.0), tempo(3000), chanceCounter(3000), key(0), ragaPoint(6), endPhase(0) {}
|
||||
};
|
||||
|
||||
// Raga key numbers and drone frequencies.
|
||||
const int ragaUp[2][13] = {{57, 60, 62, 64, 65, 68, 69, 71, 72, 76, 77, 81},
|
||||
{52, 54, 55, 57, 59, 60, 63, 64, 66, 67, 71, 72}};
|
||||
|
||||
const int ragaDown[2][13] = {{57, 60, 62, 64, 65, 67, 69, 71, 72, 76, 79, 81},
|
||||
{48, 52, 53, 55, 57, 59, 60, 64, 66, 68, 70, 72}};
|
||||
|
||||
StkFloat droneFreqs[3] = { 55.0, 82.5, 220.0 };
|
||||
|
||||
#define DELTA_CONTROL_TICKS 64 // default sample frames between control input checks
|
||||
|
||||
// The processMessage() function encapsulates the handling of control
|
||||
// messages. It can be easily relocated within a program structure
|
||||
// depending on the desired scheduling scheme.
|
||||
void processMessage( TickData* data )
|
||||
{
|
||||
register unsigned int value1 = data->message.intValues[0];
|
||||
register StkFloat value2 = data->message.floatValues[1];
|
||||
register StkFloat temp = value2 * ONE_OVER_128;
|
||||
|
||||
switch( data->message.type ) {
|
||||
|
||||
case __SK_Exit_:
|
||||
if ( data->settling == false ) goto settle;
|
||||
if ( data->endPhase < 5 ) return;
|
||||
done = true;
|
||||
return;
|
||||
|
||||
case __SK_ControlChange_:
|
||||
|
||||
switch ( value1 ) {
|
||||
|
||||
case 1:
|
||||
data->droneChance = temp;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
data->noteChance = temp;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
data->voiceChance = temp;
|
||||
break;
|
||||
|
||||
case 7:
|
||||
data->tempo = (int) (11025 - value2 * 70.0 );
|
||||
break;
|
||||
|
||||
case 11:
|
||||
data->drumChance = temp;
|
||||
break;
|
||||
|
||||
case 64:
|
||||
if ( value2 == 0.0 ) {
|
||||
data->key = 1;
|
||||
droneFreqs[0] = 55.0;
|
||||
droneFreqs[1] = 82.5;
|
||||
droneFreqs[2] = 220.0;
|
||||
}
|
||||
else {
|
||||
data->key = 0;
|
||||
droneFreqs[0] = 82.5;
|
||||
droneFreqs[1] = 123.5;
|
||||
droneFreqs[2] = 330.0;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
} // end of type switch
|
||||
|
||||
data->haveMessage = false;
|
||||
return;
|
||||
|
||||
settle:
|
||||
// Exit and program change messages are preceeded with a short settling period.
|
||||
data->counter = (int) (data->t60 * Stk::sampleRate());
|
||||
data->drones[1].noteOn( droneFreqs[1], 0.1 );
|
||||
data->settling = true;
|
||||
std::cout << "What Need Have I for This?\n";
|
||||
}
|
||||
|
||||
// The tick() function handles sample computation and scheduling of
|
||||
// control updates. It will be called automatically by RtAudio when
|
||||
// the system needs a new buffer of audio samples.
|
||||
int tick(char *buffer, int bufferSize, void *dataPointer)
|
||||
{
|
||||
TickData *data = (TickData *) dataPointer;
|
||||
register StkFloat temp, outs[2], *samples = (StkFloat *) buffer;
|
||||
int i, voiceNote, counter, nTicks = bufferSize;
|
||||
|
||||
while ( nTicks > 0 && !done ) {
|
||||
|
||||
if ( !data->haveMessage ) {
|
||||
data->messager.popMessage( data->message );
|
||||
if ( data->message.type > 0 ) {
|
||||
data->counter = (long) (data->message.time * Stk::sampleRate());
|
||||
data->haveMessage = true;
|
||||
}
|
||||
else
|
||||
data->counter = DELTA_CONTROL_TICKS;
|
||||
}
|
||||
|
||||
counter = min( nTicks, data->counter );
|
||||
data->counter -= counter;
|
||||
for ( i=0; i<counter; i++ ) {
|
||||
outs[0] = data->reverbs[0].tick( data->drones[0].tick() + data->drones[2].tick()
|
||||
+ data->sitar.tick() );
|
||||
outs[1] = data->reverbs[1].tick( 1.5 * data->drones[1].tick() + 0.5 * data->voicDrums.tick()
|
||||
+ 0.5 * data->tabla.tick() );
|
||||
// Mix a little left to right and back.
|
||||
*samples++ = outs[0] + 0.3 * outs[1];
|
||||
*samples++ = outs[1] + 0.3 * outs[0];
|
||||
nTicks--;
|
||||
|
||||
// Do a bunch of random controls unless settling down to end.
|
||||
if ( data->settling ) {
|
||||
if ( data->counter == 0 ) {
|
||||
if ( data->endPhase++ == 0 ) {
|
||||
data->counter = (int) (data->t60 * Stk::sampleRate());
|
||||
data->drones[2].noteOn( droneFreqs[2], 0.1 );
|
||||
std::cout << "What Need Have I for This?\n";
|
||||
}
|
||||
else if ( data->endPhase == 1 ) {
|
||||
data->counter = (int) (data->t60 * Stk::sampleRate());
|
||||
data->drones[0].noteOn( droneFreqs[0], 0.1 );
|
||||
std::cout << "RagaMatic finished ... \n";
|
||||
}
|
||||
else if ( data->endPhase == 2 ) {
|
||||
data->counter = (int) (data->t60 * Stk::sampleRate());
|
||||
std::cout << "All is Bliss ...\n";
|
||||
}
|
||||
else if ( data->endPhase == 3 ) {
|
||||
std::cout << "All is Bliss ...\n";
|
||||
data->counter = (int) (data->t60 * Stk::sampleRate());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
data->chanceCounter--;
|
||||
if (data->chanceCounter == 0) {
|
||||
data->chanceCounter = (int) ( data->tempo / data->rateScaler );
|
||||
if ( float_random(1.0) < data->droneChance )
|
||||
data->drones[0].noteOn( droneFreqs[0], 0.1 );
|
||||
if ( float_random(1.0) < data->droneChance )
|
||||
data->drones[1].noteOn( droneFreqs[1], 0.1 );
|
||||
if ( float_random(1.0) < data->droneChance )
|
||||
data->drones[2].noteOn( droneFreqs[2], 0.1 );
|
||||
if ( float_random(1.0) < data->noteChance ) {
|
||||
temp = float_random(1.0);
|
||||
if ( temp < 0.1) data->ragaStep = 0;
|
||||
else if (temp < 0.5) data->ragaStep = 1;
|
||||
else data->ragaStep = -1;
|
||||
data->ragaPoint += data->ragaStep;
|
||||
if ( data->ragaPoint < 0 )
|
||||
data->ragaPoint -= ( 2 * data->ragaStep );
|
||||
if ( data->ragaPoint > 11 ) data->ragaPoint = 11;
|
||||
if ( data->ragaStep > 0 )
|
||||
data->sitar.noteOn( Midi2Pitch[ragaUp[data->key][data->ragaPoint]],
|
||||
0.05 + float_random(0.3) );
|
||||
else
|
||||
data->sitar.noteOn( Midi2Pitch[ragaDown[data->key][data->ragaPoint]],
|
||||
0.05 + float_random(0.3) );
|
||||
}
|
||||
if ( float_random(1.0) < data->voiceChance ) {
|
||||
voiceNote = (int) float_random(11);
|
||||
data->voicDrums.noteOn( voiceNote, 0.3 + (0.4 * data->drumChance) +
|
||||
float_random(0.3 * data->voiceChance));
|
||||
}
|
||||
if ( float_random(1.0) < data->drumChance ) {
|
||||
voiceNote = (int) float_random(TABLA_NUMWAVES);
|
||||
data->tabla.noteOn( voiceNote, 0.2 + (0.2 * data->drumChance) +
|
||||
float_random(0.6 * data->drumChance));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( nTicks == 0 ) break;
|
||||
|
||||
// Process control messages.
|
||||
if ( data->haveMessage ) processMessage( data );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
TickData data;
|
||||
RtAudio *dac = 0;
|
||||
int i;
|
||||
|
||||
if (argc < 2 || argc > 6) usage();
|
||||
|
||||
// If you want to change the default sample rate (set in Stk.h), do
|
||||
// it before instantiating any objects! If the sample rate is
|
||||
// specified in the command line, it will override this setting.
|
||||
Stk::setSampleRate(22050.0);
|
||||
Stk::setSampleRate( 44100.0 );
|
||||
|
||||
if (argc < 2 || argc > 6) usage();
|
||||
|
||||
int port = -1;
|
||||
int i, controlMask = 0;
|
||||
// Parse the command-line arguments.
|
||||
unsigned int port = 2001;
|
||||
for ( i=1; i<argc; i++ ) {
|
||||
if (!strcmp(argv[i],"-is") ) {
|
||||
controlMask |= STK_SOCKET;
|
||||
if (i+1 < argc && argv[i+1][0] != '-' ) port = atoi(argv[++i]);
|
||||
if ( !strcmp( argv[i], "-is" ) ) {
|
||||
if ( i+1 < argc && argv[i+1][0] != '-' ) port = atoi(argv[++i]);
|
||||
data.messager.startSocketInput( port );
|
||||
}
|
||||
else if (!strcmp(argv[i],"-ip") )
|
||||
controlMask |= STK_PIPE;
|
||||
else if (!strcmp(argv[i],"-s") && (i+1 < argc) && argv[i+1][0] != '-')
|
||||
else if (!strcmp( argv[i], "-ip" ) )
|
||||
data.messager.startStdInput();
|
||||
else if ( !strcmp( argv[i], "-s" ) && ( i+1 < argc ) && argv[i+1][0] != '-')
|
||||
Stk::setSampleRate( atoi(argv[++i]) );
|
||||
else
|
||||
usage();
|
||||
}
|
||||
|
||||
|
||||
// Allocate the dac here.
|
||||
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
|
||||
int bufferSize = RT_BUFFER_SIZE;
|
||||
try {
|
||||
output = new RtWvOut(2);
|
||||
|
||||
// Instantiate the input message controller.
|
||||
if ( controlMask & STK_SOCKET && port >= 0 )
|
||||
messager = new Messager( controlMask, port );
|
||||
else
|
||||
messager = new Messager( controlMask );
|
||||
dac = new RtAudio(0, 2, 0, 0, format, (int)Stk::sampleRate(), &bufferSize, 4);
|
||||
}
|
||||
catch (StkError &) {
|
||||
exit(0);
|
||||
catch (RtError& error) {
|
||||
error.printMessage();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
drones[0] = new Drone(50.0);
|
||||
drones[1] = new Drone(50.0);
|
||||
drones[2] = new Drone(50.0);
|
||||
sitar = new Sitar(50.0);
|
||||
voicDrums = new VoicDrum();
|
||||
tabla = new Tabla();
|
||||
data.reverbs[0].setT60( data.t60 );
|
||||
data.reverbs[0].setEffectMix( 0.5 );
|
||||
data.reverbs[1].setT60( 2.0 );
|
||||
data.reverbs[1].setEffectMix( 0.2 );
|
||||
|
||||
score = new SKINI();
|
||||
reverbs[0] = new JCRev(t60);
|
||||
reverbs[0]->setEffectMix(0.5);
|
||||
reverbs[1] = new JCRev(2.0);
|
||||
reverbs[1]->setEffectMix(0.2);
|
||||
data.drones[0].noteOn( droneFreqs[0], 0.1 );
|
||||
data.drones[1].noteOn( droneFreqs[1], 0.1 );
|
||||
data.drones[2].noteOn( droneFreqs[2], 0.1 );
|
||||
|
||||
drones[0]->noteOn(droneFreqs[0],0.1);
|
||||
drones[1]->noteOn(droneFreqs[1],0.1);
|
||||
drones[2]->noteOn(droneFreqs[2],0.1);
|
||||
data.rateScaler = 22050.0 / Stk::sampleRate();
|
||||
|
||||
MY_FLOAT outSamples[2];
|
||||
for (i=0;i<Stk::sampleRate();i++) { /* warm everybody up a little */
|
||||
outSamples[0] = reverbs[0]->tick(drones[0]->tick() + drones[2]->tick());
|
||||
outSamples[1] = reverbs[1]->tick(1.5 * drones[1]->tick());
|
||||
output->tickFrame(outSamples);
|
||||
// Install an interrupt handler function.
|
||||
(void) signal( SIGINT, finish );
|
||||
|
||||
// If realtime output, set our callback function and start the dac.
|
||||
try {
|
||||
dac->setStreamCallback( &tick, (void *)&data );
|
||||
dac->startStream();
|
||||
}
|
||||
catch (RtError &error) {
|
||||
error.printMessage();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// The runtime loop begins here:
|
||||
done = FALSE;
|
||||
MY_FLOAT rateScaler = 22050.0 / Stk::sampleRate();
|
||||
int nTicks, type;
|
||||
MY_FLOAT temp, byte2, byte3;
|
||||
while (!done) {
|
||||
|
||||
type = messager->nextMessage();
|
||||
if (type < 0)
|
||||
done = TRUE;
|
||||
|
||||
nTicks = messager->getDelta();
|
||||
|
||||
for (i=0; i<nTicks; i++) {
|
||||
outSamples[0] = reverbs[0]->tick(drones[0]->tick() + drones[2]->tick()
|
||||
+ sitar->tick());
|
||||
outSamples[1] = reverbs[1]->tick(1.5 * drones[1]->tick() + 0.5 * voicDrums->tick()
|
||||
+ 0.5 * tabla->tick());
|
||||
// mix a little left to right and back
|
||||
temp = outSamples[0];
|
||||
outSamples[0] += 0.3 * outSamples[1];
|
||||
outSamples[1] += 0.3 * temp;
|
||||
output->tickFrame(outSamples);
|
||||
|
||||
counter -= 1;
|
||||
if (counter == 0) {
|
||||
counter = (int) (tempo / rateScaler);
|
||||
if (float_random(1.0) < drone_prob)
|
||||
drones[0]->noteOn(droneFreqs[0], 0.1);
|
||||
if (float_random(1.0) < drone_prob)
|
||||
drones[1]->noteOn(droneFreqs[1], 0.1);
|
||||
if (float_random(1.0) < drone_prob)
|
||||
drones[2]->noteOn(droneFreqs[2], 0.1);
|
||||
if (float_random(1.0) < note_prob) {
|
||||
if ((temp = float_random(1.0)) < 0.1)
|
||||
ragaStep = 0;
|
||||
else if (temp < 0.5)
|
||||
ragaStep = 1;
|
||||
else
|
||||
ragaStep = -1;
|
||||
ragaPoint += ragaStep;
|
||||
if (ragaPoint < 0)
|
||||
ragaPoint -= (2*ragaStep);
|
||||
if (ragaPoint > 11)
|
||||
ragaPoint = 11;
|
||||
if (ragaStep > 0)
|
||||
sitar->noteOn(Midi2Pitch[ragaUp[key][ragaPoint]],
|
||||
0.05 + float_random(0.3));
|
||||
else
|
||||
sitar->noteOn(Midi2Pitch[ragaDown[key][ragaPoint]],
|
||||
0.05 + float_random(0.3));
|
||||
}
|
||||
if (float_random(1.0) < voic_prob) {
|
||||
voicNote = (int) float_random(11);
|
||||
voicDrums->noteOn(voicNote, 0.3 + (0.4 * drum_prob) +
|
||||
float_random(0.3 * voic_prob));
|
||||
}
|
||||
if (float_random(1.0) < drum_prob) {
|
||||
voicNote = (int) float_random(TABLA_NUMWAVES);
|
||||
tabla->noteOn(voicNote, 0.2 + (0.2 * drum_prob) +
|
||||
float_random(0.6 * drum_prob));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( type > 0 ) {
|
||||
// parse the input control message
|
||||
|
||||
byte2 = messager->getByteTwo();
|
||||
byte3 = messager->getByteThree();
|
||||
|
||||
switch(type) {
|
||||
|
||||
case __SK_ControlChange_:
|
||||
if (byte2 == 1) {
|
||||
drone_prob = byte3 * ONE_OVER_128;
|
||||
}
|
||||
else if (byte2 == 2) {
|
||||
note_prob = byte3 * ONE_OVER_128;
|
||||
}
|
||||
else if (byte2 == 4) {
|
||||
voic_prob = byte3 * ONE_OVER_128;
|
||||
}
|
||||
else if (byte2 == 11) {
|
||||
drum_prob = byte3 * ONE_OVER_128;
|
||||
}
|
||||
else if (byte2 == 7) {
|
||||
tempo = (int) (11025 - (byte3 * 70));
|
||||
}
|
||||
else if (byte2 == 64) {
|
||||
if (byte3 == 0) {
|
||||
key = 1;
|
||||
droneFreqs[0] = 55.0;
|
||||
droneFreqs[1] = 82.5;
|
||||
droneFreqs[2] = 220.0;
|
||||
}
|
||||
else {
|
||||
key = 0;
|
||||
droneFreqs[0] = 82.5;
|
||||
droneFreqs[1] = 123.5;
|
||||
droneFreqs[2] = 330.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Setup finished.
|
||||
while ( !done ) {
|
||||
// Periodically check "done" status.
|
||||
Stk::sleep( 50 );
|
||||
}
|
||||
|
||||
nTicks = (long) (t60 * Stk::sampleRate());
|
||||
|
||||
printf("What Need Have I for This?\n");
|
||||
drones[1]->noteOn(droneFreqs[1],0.1);
|
||||
for (i=0; i<nTicks; i++) { // Calm down a little
|
||||
outSamples[0] = reverbs[0]->tick(drones[0]->tick() + drones[2]->tick());
|
||||
outSamples[1] = reverbs[1]->tick(1.5 * drones[1]->tick());
|
||||
output->tickFrame(outSamples);
|
||||
// Shut down the output stream.
|
||||
try {
|
||||
dac->cancelStreamCallback();
|
||||
dac->closeStream();
|
||||
}
|
||||
printf("What Need Have I for This?\n");
|
||||
drones[2]->noteOn(droneFreqs[2],0.1);
|
||||
for (i=0; i<nTicks; i++) { // and a little more
|
||||
outSamples[0] = reverbs[0]->tick(drones[0]->tick() + drones[2]->tick());
|
||||
outSamples[1] = reverbs[1]->tick(1.5 * drones[1]->tick());
|
||||
output->tickFrame(outSamples);
|
||||
}
|
||||
printf("RagaMatic finished ... \n");
|
||||
drones[0]->noteOn(droneFreqs[0],0.1);
|
||||
for (i=0; i<nTicks; i++) { // almost ready to think about ending
|
||||
outSamples[0] = reverbs[0]->tick(drones[0]->tick() + drones[2]->tick());
|
||||
outSamples[1] = reverbs[1]->tick(1.5 * drones[1]->tick());
|
||||
output->tickFrame(outSamples);
|
||||
}
|
||||
printf("All is Bliss ...\n");
|
||||
for (i=0; i<nTicks; i++) { // nearly finished now
|
||||
outSamples[0] = reverbs[0]->tick(drones[0]->tick() + drones[2]->tick());
|
||||
outSamples[1] = reverbs[1]->tick(1.5 * drones[1]->tick());
|
||||
output->tickFrame(outSamples);
|
||||
}
|
||||
printf("All is Bliss ...\n");
|
||||
for (i=0; i<nTicks; i++) { // all is bliss....
|
||||
outSamples[0] = reverbs[0]->tick(drones[0]->tick() + drones[2]->tick());
|
||||
outSamples[1] = reverbs[1]->tick(1.5 * drones[1]->tick());
|
||||
output->tickFrame(outSamples);
|
||||
catch (RtError& error) {
|
||||
error.printMessage();
|
||||
}
|
||||
|
||||
delete output;
|
||||
delete score;
|
||||
delete drones[0];
|
||||
delete drones[1];
|
||||
delete drones[2];
|
||||
delete sitar;
|
||||
delete tabla;
|
||||
delete voicDrums;
|
||||
delete reverbs[0];
|
||||
delete reverbs[1];
|
||||
delete messager;
|
||||
cleanup:
|
||||
|
||||
delete dac;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ RSC=rc.exe
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /D "__LITTLE_ENDIAN__" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_MM__" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
@@ -66,7 +66,7 @@ LINK32=link.exe
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /D "__LITTLE_ENDIAN__" /YX /FD /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_MM__" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
@@ -124,6 +124,14 @@ SOURCE=.\Drone.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\Effect.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\Effect.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\Envelope.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -140,6 +148,14 @@ SOURCE=..\..\include\Filter.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\Generator.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\Generator.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\Instrmnt.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -164,6 +180,14 @@ SOURCE=..\..\include\Messager.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\Mutex.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\Mutex.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\Noise.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -192,14 +216,6 @@ SOURCE=.\ragamat.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\Reverb.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\Reverb.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\RtAudio.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -216,14 +232,6 @@ SOURCE=..\..\include\RtMidi.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\RtWvOut.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\RtWvOut.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\Sitar.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
Reference in New Issue
Block a user