tick() );
+ }
+
+ tempDouble3 = message.floatValues[1] * NORM_MIDI;
+ if ( message.type == __SK_NoteOn_ ) {
+ if ( tempDouble3 == 0.0 ) {
+ tempDouble3 = 0.5;
+ instrument->noteOff( tempDouble3 );
}
- tempDouble3 = score->getByteThree();
- if (score->getType()== __SK_NoteOn_ ) {
- tempDouble3 *= NORM_MIDI;
- if (score->getByteThree() == 0) {
- tempDouble3 = 0.5;
- instrument->noteOff(tempDouble3);
- }
- else {
- tempLong = (int) score->getByteTwo();
- tempDouble2 = Midi2Pitch[tempLong];
- instrument->noteOn(tempDouble2,tempDouble3);
- }
+ else {
+ tempLong = message.intValues[0];
+ tempDouble2 = Midi2Pitch[tempLong];
+ instrument->noteOn( tempDouble2, tempDouble3 );
}
- else if (score->getType() == __SK_NoteOff_) {
- tempDouble3 *= NORM_MIDI;
- instrument->noteOff(tempDouble3);
- }
- else if (score->getType() == __SK_ControlChange_) {
- tempLong = score->getByteTwoInt();
- instrument->controlChange(tempLong,temp3.0);
- }
- score->nextMessage();
+ }
+ else if ( message.type == __SK_NoteOff_ ) {
+ instrument->noteOff( tempDouble3 );
+ }
+ else if ( message.type == __SK_ControlChange_ ) {
+ tempLong = message.intValues[0];
+ instrument->controlChange( tempLong, tempDouble3 );
+ }
}
\endcode
-When the score (SKINI object) object is created from the filename in argv[1], the first valid command line is read from the file and parsed.
+When a SKINI score is passed to a Skini object using the Skini::setFile() function, valid messages are read from the file and returned using the Skini::nextMessage() function.
-The score->getType() retrieves the messageType. If this is -1, there are no more valid messages in the file and the synthesis loop terminates. Otherwise, the message type is returned.
+A Skini::Message structure contains all the information parsed from a single SKINI message. A returned message type of zero indicates either an invalid message or the end of a scorefile.
-getDelta() retrieves the deltaTime until the current message should occur. If this is greater than 0, synthesis occurs until the deltaTime has elapsed. If deltaTime is less than zero, the time is interpreted as absolute time and the output device is queried as to what time it is now. That is used to form a deltaTime, and if it's positive we synthesize. If it's negative, we print an error and pretend this never happened and we hang around hoping to eventually catch up.
+The "time" member of a Skini::Message is the deltaTime until the current message should occur. If this is greater than 0, synthesis occurs until the deltaTime has elapsed. If deltaTime is less than zero, the time is interpreted as absolute time and the output device is queried as to what time it is now. That is used to form a deltaTime, and if it's positive we synthesize. If it's negative, we print an error, pretend this never happened and we hang around hoping to eventually catch up.
The rest of the code sorts out message types NoteOn, NoteOff (including NoteOn with velocity 0), and ControlChange. The code implicitly takes into account the integer type of the control number, but all other data is treated as double float.
-The last line reads and parses the next message in the file.
-
-*/
\ No newline at end of file
+*/
diff --git a/doc/doxygen/system.txt b/doc/doxygen/system.txt
index cf4b7e9..408c88f 100644
--- a/doc/doxygen/system.txt
+++ b/doc/doxygen/system.txt
@@ -2,23 +2,24 @@
General:
-- A MIDI interface to use MIDI input controls. (NOTE: This may be built into the soundcard on your computer.)
+- A MIDI interface to use MIDI input/output controls. (NOTE: This may be built into the soundcard on your computer.)
- Tcl/Tk version 8.0 or higher to use the simple Tcl/Tk GUIs provided with the STK distribution (available free over the WWW for all supported realtime platforms).
Linux (specific):
- A soundcard to use realtime audio input/output capabilities. In order to use the effects project, the soundcard and drivers must support full duplex mode.
-- OSS or ALSA device drivers for realtime sound output and MIDI input.
+- ALSA device drivers and library for realtime sound and MIDI input/output. OSS device drivers can be used for audio input/output, but MIDI support requires the ALSA library to compile.
Macintosh OS X (specific):
-- A C++ compiler does not ship by default with OS X. It is necessary to download the Developer Kit from the Apple WWW site in order to compile STK.
-- IMPORTANT:The internal Macintosh audio hardware typically supports a sample rate of 44100 Hz only. Therefore, it is necessary to either specify this rate as a command-line option to the STK example programs or to change the default sample rate inside the Stk.h file before compilation. In addition, the RT_BUFFER_SIZE, specified in Stk.h, could be increased (to a higher power of two) for more robust performance.
-- The tcl/tk interpreter does not ship by default with OS X, but must be downloaded from the internet. The latest Tcl/Tk Aqua distribution (http://www.apple.com/downloads/macosx/unix_open_source/tcltk.html) has been successfully tested on a 10.2 system. The default installation will place a link to the wish interpretor at /usr/bin/wish.
+
- A C++ compiler does install by default with OS X. It is necessary to download the Developer Kit from the Apple WWW site in order to compile STK or load it from the installation CD-ROM.
+- IMPORTANT:The internal Macintosh audio hardware typically supports a sample rate of 44100 Hz only. The default STK sample rate is now 44100 Hz, but there may be programs which change that value before execution. Check the program code if you have sample rate conflicts. Many of the example project programs allow the sample rate to be specified via the command line.
+- If you experience frequent audio input/output "glitches", try increasing the RT_BUFFER_SIZE specified in Stk.h.
+- The tcl/tk interpreter does not ship by default with OS X, but must be downloaded from the internet. The latest Tcl/Tk Aqua distribution (http://www.apple.com/downloads/macosx/unix_open_source/tcltk.html) has been successfully tested on 10.2 and 10.3 systems. The default installation will place a link to the wish interpretor at /usr/bin/wish.
-Initial tests have shown somewhat poor response between changes made in the tcl/tk script and the resulting audio updates. It is possible to connect a tcl/tk interface to an STK program via a socket connection. However, the tcl/tk interpreter does not appear to properly close the socket connection during disconnection. It is therefore necessary to type "Exit" in the STK program terminal window to properly exit the STK program.
+It appears that socket support in Tcl/Tk uses the Nagle algorithm, which produces poor response between changes made in the tcl/tk script and the resulting audio updates. Note that this is only a problem when using a socket connection from a Tcl/Tk script.
@@ -37,4 +38,4 @@ Initial tests have shown somewhat poor response between changes made in the tcl/
-*/
\ No newline at end of file
+*/
diff --git a/doc/doxygen/tutorial.txt b/doc/doxygen/tutorial.txt
index 1ff0089..0123b85 100644
--- a/doc/doxygen/tutorial.txt
+++ b/doc/doxygen/tutorial.txt
@@ -1,23 +1,26 @@
/*! \page tutorial Tutorial
-The Synthesis ToolKit is a set of C++ classes. In order to go beyond the simple example programs we provide, it is necessary to know some basics about programming in C or C++. STK's "target audience" includes people who:
+The Synthesis ToolKit is a set of C++ classes. In order to go beyond the simple example programs we provide, it is necessary to know some basics about programming in C and C++. STK's "target audience" includes people who:
- want to create audio DSP and/or synthesis programs
-- want to save some time by using our unit generators and input/output routines
+- want to use our unit generators and input/output routines rather than code their own
- want to learn about synthesis and processing algorithms
-- wish to teach real-time synthesis and processing, and wish to use some of our classes and examples
+- wish to teach real-time synthesis and processing and wish to use some of our classes and examples
Most ToolKit programmers will likely end up writing a class or two for their own particular needs, but this task is typically simplified by making use of pre-existing STK classes (filters, oscillators, etc.).
The following tutorial chapters describe many of the fundamental ToolKit concepts and classes. All tutorial programs are included in the projects/examples directory.
+-# \ref fundamentals
-# \ref hello
-# \ref compile
+-# \ref filtering
-# \ref realtime
+-# \ref crealtime
-# \ref instruments
-# \ref controlin
-# \ref multichannel
-# \ref polyvoices
-*/
\ No newline at end of file
+*/
diff --git a/doc/doxygen/usage.txt b/doc/doxygen/usage.txt
index 7905cc0..8723671 100644
--- a/doc/doxygen/usage.txt
+++ b/doc/doxygen/usage.txt
@@ -21,7 +21,7 @@ The top level distribution contains the following directories:
The include directory contains the header files for all the STK unit generator and algorithm classes.
-
The rawwaves directory contains various raw, monophonic, 16-bit, big-endian soundfiles used with the STK classes.
+
The rawwaves directory contains various raw, monophonic, 16-bit, big-endian, 22050 Hz soundfiles used with the STK classes.
The doc directory contains documentation about STK.
@@ -37,13 +37,13 @@ This release of STK comes with four separate "project" directories:
The ragamatic project is just cool. Fire it up and be enlightened.
- The examples project contains several simple programs which demonstrate audio input/output, as well as the use of the audio internet streaming classes.
+ The examples project contains several simple programs which demonstrate audio input/output, including the audio internet streaming classes, as well as most of the tutorial programs.
\section compiling Compiling:
-- Windows95/98/2000/XP: Realtime support is available using either DirectSound or ASIO audio drivers. For DirectSound support, use the __WINDOWS_DS__ preprocessor definition and link with the dsound.lib, winmm.lib, and Wsock32.lib libraries. For ASIO support, use the __WINDOWS_ASIO__ preprocessor definition, include all the files in the src/asio/ directory (i.e. asio.h,cpp, asiodrivers.h,cpp, ...), and link with the winmm.lib, and Wsock32.lib libraries. In addition, the __LITTLE_ENDIAN__ preprocessor definition is necessary for all Windows systems. A distribution of the release is available with precompiled binaries (using DirectSound) for all the projects. In order for these binaries to function properly, your system must have the DirectX 5.0 (or higher) runtime libraries installed (available from Microsoft). Further, the effects project requires that your soundcard and drivers provide full duplex mode capabilities. Visual C++ 6.0 project files are provided in each project directory as well should you wish to compile your own binaries. It is important to link with the non-debug libraries when compiling "release" program versions and debug libraries when compiling "debug" program versions.
+- Windows95/98/2000/XP: Realtime support is available using either DirectSound or ASIO audio drivers. For DirectSound support, use the __WINDOWS_DS__ preprocessor definition and link with the dsound.lib, winmm.lib, and Wsock32.lib libraries. For ASIO support, use the __WINDOWS_ASIO__ preprocessor definition, include all the files in the src/asio/ directory (i.e. asio.h,cpp, asiodrivers.h,cpp, ...), and link with the winmm.lib, and Wsock32.lib libraries. In addition, the __LITTLE_ENDIAN__ and __WINDOWS_MM__ preprocessor definitions are necessary for all Windows systems (RtMidi uses the Windows MultiMedia MIDI API). A distribution of the release is available with precompiled binaries (using DirectSound) for all the projects. In order for these binaries to function properly, your system must have the DirectX 5.0 (or higher) runtime libraries installed (available from Microsoft). Further, the effects project requires that your soundcard and drivers provide full duplex mode capabilities. Visual C++ 6.0 project files are provided in each project directory as well should you wish to compile your own binaries. It is important to link with the non-debug libraries when compiling "release" program versions and debug libraries when compiling "debug" program versions.
- WindowsNT: DirectX support for NT is inadequate, so it is not possible to use STK under WindowsNT with realtime DirectX support. It may be possible to use STK under WindowsNT with realtime ASIO support, though this has not been tested.
@@ -53,11 +53,12 @@ Several options can be supplied to the configure script to customize th
- --disable-realtime to only compile generic non-realtime classes
- --enable-debug to enable various debug output
-- --enable-midiator to enable native MS-124W MIDI support (linux only)
-- --with-alsa to choose native ALSA API support (linux only)
+- --with-alsa to choose native ALSA API support (default, linux only)
+- --with-jack to choose native JACK API support (linux only)
+- --with-oss to choose native OSS audio API support (linux only, no native OSS MIDI support)
-In addition, it is possible to specify the location of the STK rawwaves and the STK include path as follows:
+Note that it is possible to specify as many of the "--with-" options as desired to compile multi-API support. In addition, it is possible to specify the location of the STK rawwaves and the STK include path as follows:
\code
./configure RAWWAVE_PATH="/home/gary/rawwaves/"
./configure INCLUDE_PATH="/home/gary/include/"
@@ -68,13 +69,13 @@ For novice STK users, the default configuration should be adequate.
For those who wish to create their own system-specific Makefiles:
-- Linux: Realtime support is enabled with either the __LINUX_OSS__ or __LINUX_ALSA__ preprocessor definitions, which are used to select the underlying audio/MIDI system API. Realtime programs must also link with the pthread library. When using the ALSA API, it is also necessary to link with the asound library. In addition, the __LITTLE_ENDIAN__ preprocessor definition is necessary if compiling on a little-endian system. Special support exists under Linux for the MIDIator serial MIDI device, enabled using the __MIDIATOR__ preprocessor definition (together with either the __LINUX_ALSA__ or __LINUX_OSS__ definitions). See the README-Linux file for further system configuration information.
+- Linux: Realtime audio support is enabled with either the __LINUX_ALSA__, __LINUX_JACK__, and/or __LINUX_OSS__ preprocessor definitions, which are used to select the underlying audio system API(s). Because the ALSA library is now integrated into the standard Linux kernel, it is the default audio/MIDI API with STK versions 4.2 and higher. The __LINUX_ALSASEQ__ preprocessor definition must be included for MIDI support. Note that native OSS MIDI support no longer exists in RtMidi. If the __LINUX_OSS__ preprocessor definition is specified, only OSS audio support will be compiled and RtMidi will still be compiled using the ALSA API (assuming the __LINUX_ALSASEQ__ definition is defined). For this reason, STK now requires the asound library for realtime support. Realtime programs must also link with the pthread library. In addition, the __LITTLE_ENDIAN__ preprocessor definition is necessary if compiling on a little-endian system. See the README-Linux file for further system configuration information.
- Macintosh OS X: Realtime support is enabled with the __MACOSX_CORE__ preprocessor definitions, which incorporates the CoreAudio audio/MIDI API. Realtime programs must also link with the pthread library and the CoreAudio, CoreMIDI, and CoreFoundation frameworks. See the README-MacOSX file for further system configuration information.
-- SGI: Realtime support is enabled with the __IRIX_AL__ preprocessor definition and linkage with the audio, md, and pthread libraries. STK 4.0 (and higher) is confirmed to compile using CC version 7.30. There may be problems with old compiler versions.
+- SGI: Realtime audio and MIDI support is enabled with the __IRIX_AL__ and __IRIX_MD__ preprocessor definitions and linkage with the audio, md, and pthread libraries. STK 4.0 (and higher) is confirmed to compile using CC version 7.30. There may be problems with old compiler versions.
-- Generic (non-realtime): Most STK classes are operating system independent and can be compiled using any current C++ compiler. STK assumes big-endian host byte order by default, so if your system is little-endian (i.e. Intel processor), you must provide the __LITTLE_ENDIAN__ preprocessor definition to your compiler. The demo project will compile without realtime support, allowing the use of SKINI scorefiles for input control and output to a variety of soundfile formats. The following classes cannot be used without realtime support: RtAudio, RtWvIn, RtWvOut, RtDuplex, RtMidi, Socket, Thread, TcpWvIn, TcpWvOut. Because of this, it is not possible to compile the effects, ragamatic, and most of the examples projects for non-realtime use.
+- Generic (non-realtime): Most STK classes are operating system independent and can be compiled using any current C++ compiler. STK assumes big-endian host byte order by default, so if your system is little-endian (i.e. Intel processor), you must provide the __LITTLE_ENDIAN__ preprocessor definition to your compiler. The demo project will compile without realtime support, allowing the use of SKINI scorefiles for input control and output to a variety of soundfile formats. The following classes cannot be used without realtime support: RtAudio, RtWvIn, RtWvOut, RtDuplex, RtMidi, Socket, Thread, Mutex, TcpWvIn, TcpWvOut. Because of this, it is not possible to compile the effects, ragamatic, and most of the examples projects for non-realtime use.
@@ -132,16 +133,10 @@ See the information above with respect to compiling STK for non-realtime use.
In non-realtime mode, it is assumed that input control messages are provided from a SKINI scorefile and that audio output is written to a soundfile (.snd, .wav, .aif, .mat, .raw). A number of SKINI scorefiles are provided in the scores directory of the demo project. Assuming a successful compilation of the demo program, typing:
\code
-cat scores/bookert.ski | demo BeeThree -ow myfile.wav
+demo BeeThree -ow myfile.wav -if scores/bookert.ski
\endcode
-or (on WindowsXX and/or Unix)
-
-\code
-demo BeeThree -ow myfile.wav < scores\bookert.ski
-\endcode
-
-from the demo directory will play the scorefile bookert.ski using the STK BeeThree instrument and write the resulting audio data to a WAV formatted soundfile called "myfile.wav". Typing demo without any arguments will provide a full program usage description.
+from the demo directory will play the scorefile bookert.ski using the STK BeeThree instrument and write the resulting audio data to a WAV formatted soundfile called "myfile.wav" (note that you may need to append ./ to the program name if your default shell setup is not set to look in the current directory). Typing demo without any arguments will provide a full program usage description.
\section rt Demo: Realtime Use
@@ -157,27 +152,22 @@ demo instrument flags
where instruments include those described above and flags can be any or all of:
- -or for realtime audio output,
-- -ow for WAV soundfile output,
-- -os for SND (AU) soundfile output,
-- -om for MAT-file output,
+- -ow \ for WAV soundfile output,
+- -os \ for SND (AU) soundfile output,
+- -om \ for MAT-file output,
+- -if \ for a SKINI formatted control file,
- -ip for realtime SKINI control input via piping,
-- -is > for realtime SKINI control input via socketing (with an optional port number),
-- -im for MIDI control input
-- -s RATE to specify a sample rate
+- -is \ for realtime SKINI control input via socketing (with an optional port number),
+- -im \ for MIDI control input (with optional port, -1 = virtual port where possible),
+- -s RATE to specify a sample rate,
- -n NUMBER to specify multivoice polyphony
-The <-ip> and <-is> flags must be used when piping or socketing realtime SKINI control data to an STK program. The <-im> flag must be used to read MIDI control input from your MIDI port. Note that you can use all three input types simultaneously.
+The -ip and -is flags must be used when piping or socketing realtime SKINI control data to an STK program. The -im flag must be used to read MIDI control input from your MIDI port. Note that you can use all three input types simultaneously.
Assuming a successful compilation of the demo program, typing:
\code
-cat scores/bookert.ski | demo BeeThree -or
-\endcode
-
-or (on WindowsXX and/or Unix)
-
-\code
-demo BeeThree -or < scores\bookert.ski
+demo BeeThree -or -if scores/bookert.ski
\endcode
from the demo directory will play the scorefile bookert.ski using the STK BeeThree instrument and stream the resulting audio data in realtime to the audio output channel of your computer. Typing demo without any arguments will provide a full program usage description.
@@ -209,6 +199,7 @@ On all supported realtime platforms, you can direct realtime MIDI input to the S
demo Clarinet -or -im
\endcode
+This will attempt to use the default MIDI port for input. An optional MIDI port number can be specified after the -im flag. Valid MIDI ports are numbered from 0 (default) and higher. On Linux and Macintosh OS-X systems, it is possible to open a virtual MIDI input port (which other software applications can connect to) by specifying a port identifier of -1.
\section polyphony Polyphony:
diff --git a/include/ADSR.h b/include/ADSR.h
index 3d3cb61..f9e0e4b 100644
--- a/include/ADSR.h
+++ b/include/ADSR.h
@@ -11,12 +11,12 @@
envelope value reaches 0.0 in the
ADSR::RELEASE state.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__ADSR_H)
-#define __ADSR_H
+#ifndef STK_ADSR_H
+#define STK_ADSR_H
#include "Envelope.h"
@@ -40,49 +40,58 @@ class ADSR : public Envelope
void keyOff(void);
//! Set the attack rate.
- void setAttackRate(MY_FLOAT aRate);
+ void setAttackRate(StkFloat rate);
//! Set the decay rate.
- void setDecayRate(MY_FLOAT aRate);
+ void setDecayRate(StkFloat rate);
//! Set the sustain level.
- void setSustainLevel(MY_FLOAT aLevel);
+ void setSustainLevel(StkFloat level);
//! Set the release rate.
- void setReleaseRate(MY_FLOAT aRate);
+ void setReleaseRate(StkFloat rate);
//! Set the attack rate based on a time duration.
- void setAttackTime(MY_FLOAT aTime);
+ void setAttackTime(StkFloat time);
//! Set the decay rate based on a time duration.
- void setDecayTime(MY_FLOAT aTime);
+ void setDecayTime(StkFloat time);
//! Set the release rate based on a time duration.
- void setReleaseTime(MY_FLOAT aTime);
+ void setReleaseTime(StkFloat time);
- //! Set sustain level and attack, decay, and release state rates based on time durations.
- void setAllTimes(MY_FLOAT aTime, MY_FLOAT dTime, MY_FLOAT sLevel, MY_FLOAT rTime);
+ //! Set sustain level and attach, decay, and release time durations.
+ void setAllTimes(StkFloat aTime, StkFloat dTime, StkFloat sLevel, StkFloat rTime);
//! Set the target value.
- void setTarget(MY_FLOAT aTarget);
+ void setTarget(StkFloat target);
//! Return the current envelope \e state (ATTACK, DECAY, SUSTAIN, RELEASE, DONE).
int getState(void) const;
//! Set to state = ADSR::SUSTAIN with current and target values of \e aValue.
- void setValue(MY_FLOAT aValue);
+ void setValue(StkFloat value);
//! Return one envelope output value.
- MY_FLOAT tick(void);
+ StkFloat tick(void);
- //! Return \e vectorSize envelope outputs in \e vector.
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ //! Compute \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:
- MY_FLOAT attackRate;
- MY_FLOAT decayRate;
- MY_FLOAT sustainLevel;
- MY_FLOAT releaseRate;
+ StkFloat attackRate_;
+ StkFloat decayRate_;
+ StkFloat sustainLevel_;
+ StkFloat releaseRate_;
};
#endif
diff --git a/include/Asymp.h b/include/Asymp.h
new file mode 100644
index 0000000..fd708e0
--- /dev/null
+++ b/include/Asymp.h
@@ -0,0 +1,84 @@
+/***************************************************/
+/*! \class Asymp
+ \brief STK asymptotic curve envelope class
+
+ This class implements a simple envelope generator
+ which asymptotically approaches a target value.
+ The algorithm used is of the form:
+
+ x[n] = a x[n-1] + (1-a) target,
+
+ where a = exp(-T/tau), T is the sample period, and
+ tau is a time constant. The user can set the time
+ constant (default value = 0.3) and target value.
+ Theoretically, this recursion never reaches its
+ target, though the calculations in this class are
+ stopped when the current value gets within a small
+ threshold value of the target (at which time the
+ current value is set to the target). It responds
+ to \e keyOn and \e keyOff messages by ramping to
+ 1.0 on keyOn and to 0.0 on keyOff.
+
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
+*/
+/***************************************************/
+
+#ifndef STK_ASYMP_H
+#define STK_ASYMP_H
+
+#include "Envelope.h"
+
+const StkFloat TARGET_THRESHOLD = 0.000001;
+
+class Asymp : public Envelope
+{
+ public:
+
+ //! Default constructor.
+ Asymp(void);
+
+ //! Class destructor.
+ ~Asymp(void);
+
+ //! Set target = 1.
+ void keyOn(void);
+
+ //! Set target = 0.
+ void keyOff(void);
+
+ //! Set the asymptotic rate via the time factor \e tau (must be > 0).
+ /*!
+ The rate is computed as described above. The value of \e tau
+ must be greater than zero. Values of \e tau close to zero produce
+ fast approach rates, while values greater than 1.0 produce rather
+ slow rates.
+ */
+ void setTau(StkFloat tau);
+
+ //! Set the asymptotic rate based on a time duration (must be > 0).
+ void setTime(StkFloat time);
+
+ //! Set the target value.
+ void setTarget(StkFloat target);
+
+ //! Return one envelope output value.
+ StkFloat tick(void);
+
+ //! Compute \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:
+ StkFloat factor_;
+ StkFloat constant_;
+};
+
+#endif
diff --git a/include/BandedWG.h b/include/BandedWG.h
index 68b457b..1c613e1 100644
--- a/include/BandedWG.h
+++ b/include/BandedWG.h
@@ -24,19 +24,19 @@
- Glass Harmonica = 2
- Tibetan Bowl = 3
- by Georg Essl, 1999 - 2002.
+ by Georg Essl, 1999 - 2004.
Modified for Stk 4.0 by Gary Scavone.
*/
/***************************************************/
-#if !defined(__BANDEDWG_H)
-#define __BANDEDWG_H
+#ifndef STK_BANDEDWG_H
+#define STK_BANDEDWG_H
-#define MAX_BANDED_MODES 20
+const int MAX_BANDED_MODES = 20;
#include "Instrmnt.h"
#include "DelayL.h"
-#include "BowTabl.h"
+#include "BowTable.h"
#include "ADSR.h"
#include "BiQuad.h"
@@ -53,59 +53,71 @@ class BandedWG : public Instrmnt
void clear();
//! Set strike position (0.0 - 1.0).
- void setStrikePosition(MY_FLOAT position);
+ void setStrikePosition(StkFloat position);
//! Select a preset.
void setPreset(int preset);
//! Set instrument parameters for a particular frequency.
- void setFrequency(MY_FLOAT frequency);
+ void setFrequency(StkFloat frequency);
//! Apply bow velocity/pressure to instrument with given amplitude and rate of increase.
- void startBowing(MY_FLOAT amplitude, MY_FLOAT rate);
+ void startBowing(StkFloat amplitude, StkFloat rate);
//! Decrease bow velocity/breath pressure with given rate of decrease.
- void stopBowing(MY_FLOAT rate);
+ void stopBowing(StkFloat rate);
//! Pluck the instrument with given amplitude.
- void pluck(MY_FLOAT amp);
+ void pluck(StkFloat amp);
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
protected:
- bool doPluck;
- bool trackVelocity;
- int nModes;
- int presetModes;
- BowTabl *bowTabl;
- ADSR *adsr;
- BiQuad *bandpass;
- DelayL *delay;
- MY_FLOAT maxVelocity;
- MY_FLOAT modes[MAX_BANDED_MODES];
- MY_FLOAT freakency;
- MY_FLOAT baseGain;
- MY_FLOAT gains[MAX_BANDED_MODES];
- MY_FLOAT basegains[MAX_BANDED_MODES];
- MY_FLOAT excitation[MAX_BANDED_MODES];
- MY_FLOAT integrationConstant;
- MY_FLOAT velocityInput;
- MY_FLOAT bowVelocity;
- MY_FLOAT bowTarget;
- MY_FLOAT bowPosition;
- MY_FLOAT strikeAmp;
- int strikePosition;
+ bool doPluck_;
+ bool trackVelocity_;
+ int nModes_;
+ int presetModes_;
+ BowTable bowTable_;
+ ADSR adsr_;
+ BiQuad bandpass_[MAX_BANDED_MODES];
+ DelayL delay_[MAX_BANDED_MODES];
+ StkFloat maxVelocity_;
+ StkFloat modes_[MAX_BANDED_MODES];
+ StkFloat frequency_;
+ StkFloat baseGain_;
+ StkFloat gains_[MAX_BANDED_MODES];
+ StkFloat basegains_[MAX_BANDED_MODES];
+ StkFloat excitation_[MAX_BANDED_MODES];
+ StkFloat integrationConstant_;
+ StkFloat velocityInput_;
+ StkFloat bowVelocity_;
+ StkFloat bowTarget_;
+ StkFloat bowPosition_;
+ StkFloat strikeAmp_;
+ int strikePosition_;
};
diff --git a/include/BeeThree.h b/include/BeeThree.h
index f8a1d3f..c71148f 100644
--- a/include/BeeThree.h
+++ b/include/BeeThree.h
@@ -28,12 +28,12 @@
type who should worry about this (making
money) worry away.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__BEETHREE_H)
-#define __BEETHREE_H
+#ifndef STK_BEETHREE_H
+#define STK_BEETHREE_H
#include "FM.h"
@@ -41,16 +41,31 @@ class BeeThree : public FM
{
public:
//! Class constructor.
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
BeeThree();
//! Class destructor.
~BeeThree();
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
};
#endif
diff --git a/include/BiQuad.h b/include/BiQuad.h
index c936094..4d5803c 100644
--- a/include/BiQuad.h
+++ b/include/BiQuad.h
@@ -8,12 +8,12 @@
frequency response while maintaining a constant
filter gain.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__BIQUAD_H)
-#define __BIQUAD_H
+#ifndef STK_BIQUAD_H
+#define STK_BIQUAD_H
#include "Filter.h"
@@ -31,19 +31,19 @@ public:
void clear(void);
//! Set the b[0] coefficient value.
- void setB0(MY_FLOAT b0);
+ void setB0(StkFloat b0);
//! Set the b[1] coefficient value.
- void setB1(MY_FLOAT b1);
+ void setB1(StkFloat b1);
//! Set the b[2] coefficient value.
- void setB2(MY_FLOAT b2);
+ void setB2(StkFloat b2);
//! Set the a[1] coefficient value.
- void setA1(MY_FLOAT a1);
+ void setA1(StkFloat a1);
//! Set the a[2] coefficient value.
- void setA2(MY_FLOAT a2);
+ void setA2(StkFloat a2);
//! Sets the filter coefficients for a resonance at \e frequency (in Hz).
/*!
@@ -57,7 +57,7 @@ public:
frequency. The closer the poles are to the unit-circle (\e radius
close to one), the narrower the resulting resonance width.
*/
- void setResonance(MY_FLOAT frequency, MY_FLOAT radius, bool normalize = FALSE);
+ void setResonance(StkFloat frequency, StkFloat radius, bool normalize = false);
//! Set the filter coefficients for a notch at \e frequency (in Hz).
/*!
@@ -66,7 +66,7 @@ public:
and \e radius from the z-plane origin. No filter normalization
is attempted.
*/
- void setNotch(MY_FLOAT frequency, MY_FLOAT radius);
+ void setNotch(StkFloat frequency, StkFloat radius);
//! Sets the filter zeroes for equal resonance gain.
/*!
@@ -82,19 +82,28 @@ public:
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
- void setGain(MY_FLOAT theGain);
+ void setGain(StkFloat gain);
//! Return the current filter gain.
- MY_FLOAT getGain(void) const;
+ StkFloat getGain(void) const;
//! Return the last computed output value.
- MY_FLOAT lastOut(void) const;
+ StkFloat lastOut(void) const;
//! Input one sample to the filter and return one output.
- MY_FLOAT tick(MY_FLOAT sample);
+ virtual StkFloat tick(StkFloat sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
+
+ //! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding 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 );
};
#endif
diff --git a/include/BlowBotl.h b/include/BlowBotl.h
index f30ffdf..16d8ab2 100644
--- a/include/BlowBotl.h
+++ b/include/BlowBotl.h
@@ -12,15 +12,15 @@
- Vibrato Gain = 1
- Volume = 128
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__BOTTLE_H)
-#define __BOTTLE_H
+#ifndef STK_BLOWBOTL_H
+#define STK_BLOWBOTL_H
#include "Instrmnt.h"
-#include "JetTabl.h"
+#include "JetTable.h"
#include "BiQuad.h"
#include "PoleZero.h"
#include "Noise.h"
@@ -31,6 +31,9 @@ class BlowBotl : public Instrmnt
{
public:
//! Class constructor.
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
BlowBotl();
//! Class destructor.
@@ -40,37 +43,49 @@ class BlowBotl : public Instrmnt
void clear();
//! Set instrument parameters for a particular frequency.
- void setFrequency(MY_FLOAT frequency);
+ void setFrequency(StkFloat frequency);
//! Apply breath velocity to instrument with given amplitude and rate of increase.
- void startBlowing(MY_FLOAT amplitude, MY_FLOAT rate);
+ void startBlowing(StkFloat amplitude, StkFloat rate);
//! Decrease breath velocity with given rate of decrease.
- void stopBlowing(MY_FLOAT rate);
+ void stopBlowing(StkFloat rate);
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
protected:
- JetTabl *jetTable;
- BiQuad *resonator;
- PoleZero *dcBlock;
- Noise *noise;
- ADSR *adsr;
- WaveLoop *vibrato;
- MY_FLOAT maxPressure;
- MY_FLOAT noiseGain;
- MY_FLOAT vibratoGain;
- MY_FLOAT outputGain;
+ JetTable jetTable_;
+ BiQuad resonator_;
+ PoleZero dcBlock_;
+ Noise noise_;
+ ADSR adsr_;
+ WaveLoop *vibrato_;
+ StkFloat maxPressure_;
+ StkFloat noiseGain_;
+ StkFloat vibratoGain_;
+ StkFloat outputGain_;
};
diff --git a/include/BlowHole.h b/include/BlowHole.h
index 682fcad..83e36dd 100644
--- a/include/BlowHole.h
+++ b/include/BlowHole.h
@@ -29,16 +29,16 @@
- Register State = 1
- Breath Pressure = 128
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__BLOWHOLE_H)
-#define __BLOWHOLE_H
+#ifndef STK_BLOWHOLE_H
+#define STK_BLOWHOLE_H
#include "Instrmnt.h"
#include "DelayL.h"
-#include "ReedTabl.h"
+#include "ReedTable.h"
#include "OneZero.h"
#include "PoleZero.h"
#include "Envelope.h"
@@ -49,7 +49,10 @@ class BlowHole : public Instrmnt
{
public:
//! Class constructor.
- BlowHole(MY_FLOAT lowestFrequency);
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
+ BlowHole(StkFloat lowestFrequency);
//! Class destructor.
~BlowHole();
@@ -58,50 +61,60 @@ class BlowHole : public Instrmnt
void clear();
//! Set instrument parameters for a particular frequency.
- void setFrequency(MY_FLOAT frequency);
+ void setFrequency(StkFloat frequency);
//! Set the tonehole state (0.0 = closed, 1.0 = fully open).
- void setTonehole(MY_FLOAT newValue);
+ void setTonehole(StkFloat newValue);
//! Set the register hole state (0.0 = closed, 1.0 = fully open).
- void setVent(MY_FLOAT newValue);
+ void setVent(StkFloat newValue);
//! Apply breath pressure to instrument with given amplitude and rate of increase.
- void startBlowing(MY_FLOAT amplitude, MY_FLOAT rate);
+ void startBlowing(StkFloat amplitude, StkFloat rate);
//! Decrease breath pressure with given rate of decrease.
- void stopBlowing(MY_FLOAT rate);
+ void stopBlowing(StkFloat rate);
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
protected:
- DelayL *delays[3];
- ReedTabl *reedTable;
- OneZero *filter;
- PoleZero *tonehole;
- PoleZero *vent;
- Envelope *envelope;
- Noise *noise;
- WaveLoop *vibrato;
- long length;
- MY_FLOAT scatter;
- MY_FLOAT th_coeff;
- MY_FLOAT r_th;
- MY_FLOAT rh_coeff;
- MY_FLOAT rh_gain;
- MY_FLOAT outputGain;
- MY_FLOAT noiseGain;
- MY_FLOAT vibratoGain;
+ DelayL delays_[3];
+ ReedTable reedTable_;
+ OneZero filter_;
+ PoleZero tonehole_;
+ PoleZero vent_;
+ Envelope envelope_;
+ Noise noise_;
+ WaveLoop *vibrato_;
+ unsigned long length_;
+ StkFloat scatter_;
+ StkFloat thCoeff_;
+ StkFloat rhGain_;
+ StkFloat outputGain_;
+ StkFloat noiseGain_;
+ StkFloat vibratoGain_;
};
diff --git a/include/BowTabl.h b/include/BowTabl.h
deleted file mode 100644
index 7886e09..0000000
--- a/include/BowTabl.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/***************************************************/
-/*! \class BowTabl
- \brief STK bowed string table class.
-
- This class implements a simple bowed string
- non-linear function, as described by Smith (1986).
-
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
-*/
-/***************************************************/
-
-#if !defined(__BOWTABL_H)
-#define __BOWTABL_H
-
-#include "Stk.h"
-
-class BowTabl : public Stk
-{
-public:
- //! Default constructor.
- BowTabl();
-
- //! Class destructor.
- ~BowTabl();
-
- //! Set the table offset value.
- /*!
- The table offset is a bias which controls the
- symmetry of the friction. If you want the
- friction to vary with direction, use a non-zero
- value for the offset. The default value is zero.
- */
- void setOffset(MY_FLOAT aValue);
-
- //! Set the table slope value.
- /*!
- The table slope controls the width of the friction
- pulse, which is related to bow force.
- */
- void setSlope(MY_FLOAT aValue);
-
- //! Return the last output value.
- MY_FLOAT lastOut(void) const;
-
- //! Return the function value for \e input.
- /*!
- The function input represents differential
- string-to-bow velocity.
- */
- MY_FLOAT tick(const MY_FLOAT input);
-
- //! Take \e vectorSize inputs and return the corresponding function values in \e vector.
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
-
-protected:
- MY_FLOAT offSet;
- MY_FLOAT slope;
- MY_FLOAT lastOutput;
-
-};
-
-#endif
diff --git a/include/BowTable.h b/include/BowTable.h
new file mode 100644
index 0000000..7c61708
--- /dev/null
+++ b/include/BowTable.h
@@ -0,0 +1,67 @@
+/***************************************************/
+/*! \class BowTable
+ \brief STK bowed string table class.
+
+ This class implements a simple bowed string
+ non-linear function, as described by Smith (1986).
+
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
+*/
+/***************************************************/
+
+#ifndef STK_BOWTABL_H
+#define STK_BOWTABL_H
+
+#include "Function.h"
+
+class BowTable : public Function
+{
+public:
+ //! Default constructor.
+ BowTable();
+
+ //! Class destructor.
+ ~BowTable();
+
+ //! Set the table offset value.
+ /*!
+ The table offset is a bias which controls the
+ symmetry of the friction. If you want the
+ friction to vary with direction, use a non-zero
+ value for the offset. The default value is zero.
+ */
+ void setOffset(StkFloat offset);
+
+ //! Set the table slope value.
+ /*!
+ The table slope controls the width of the friction
+ pulse, which is related to bow force.
+ */
+ void setSlope(StkFloat slope);
+
+ //! Return the function value for \e input.
+ /*!
+ The function input represents differential
+ string-to-bow velocity.
+ */
+ StkFloat tick( StkFloat input);
+
+ //! Take \e vectorSize inputs from \e vector and replace them with corresponding outputs.
+ StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
+
+ //! Take a channel of the StkFrames object as inputs to the function and replace with corresponding 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:
+ StkFloat offset_;
+ StkFloat slope_;
+
+};
+
+#endif
diff --git a/include/Bowed.h b/include/Bowed.h
index e393d97..2392b14 100644
--- a/include/Bowed.h
+++ b/include/Bowed.h
@@ -17,16 +17,16 @@
- Vibrato Gain = 1
- Volume = 128
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__BOWED_H)
-#define __BOWED_H
+#ifndef STK_BOWED_H
+#define STK_BOWED_H
#include "Instrmnt.h"
#include "DelayL.h"
-#include "BowTabl.h"
+#include "BowTable.h"
#include "OnePole.h"
#include "BiQuad.h"
#include "WaveLoop.h"
@@ -36,7 +36,7 @@ class Bowed : public Instrmnt
{
public:
//! Class constructor, taking the lowest desired playing frequency.
- Bowed(MY_FLOAT lowestFrequency);
+ Bowed(StkFloat lowestFrequency);
//! Class destructor.
~Bowed();
@@ -45,41 +45,53 @@ class Bowed : public Instrmnt
void clear();
//! Set instrument parameters for a particular frequency.
- void setFrequency(MY_FLOAT frequency);
+ void setFrequency(StkFloat frequency);
//! Set vibrato gain.
- void setVibrato(MY_FLOAT gain);
+ void setVibrato(StkFloat gain);
//! Apply breath pressure to instrument with given amplitude and rate of increase.
- void startBowing(MY_FLOAT amplitude, MY_FLOAT rate);
+ void startBowing(StkFloat amplitude, StkFloat rate);
//! Decrease breath pressure with given rate of decrease.
- void stopBowing(MY_FLOAT rate);
+ void stopBowing(StkFloat rate);
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
protected:
- DelayL *neckDelay;
- DelayL *bridgeDelay;
- BowTabl *bowTable;
- OnePole *stringFilter;
- BiQuad *bodyFilter;
- WaveLoop *vibrato;
- ADSR *adsr;
- MY_FLOAT maxVelocity;
- MY_FLOAT baseDelay;
- MY_FLOAT vibratoGain;
- MY_FLOAT betaRatio;
+ DelayL neckDelay_;
+ DelayL bridgeDelay_;
+ BowTable bowTable_;
+ OnePole stringFilter_;
+ BiQuad bodyFilter_;
+ WaveLoop *vibrato_;
+ ADSR adsr_;
+ StkFloat maxVelocity_;
+ StkFloat baseDelay_;
+ StkFloat vibratoGain_;
+ StkFloat betaRatio_;
};
diff --git a/include/Brass.h b/include/Brass.h
index 4c59036..7d03039 100644
--- a/include/Brass.h
+++ b/include/Brass.h
@@ -16,12 +16,12 @@
- Vibrato Gain = 1
- Volume = 128
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__BRASS_H)
-#define __BRASS_H
+#ifndef STK_BRASS_H
+#define STK_BRASS_H
#include "Instrmnt.h"
#include "DelayA.h"
@@ -34,7 +34,10 @@ class Brass: public Instrmnt
{
public:
//! Class constructor, taking the lowest desired playing frequency.
- Brass(MY_FLOAT lowestFrequency);
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
+ Brass(StkFloat lowestFrequency);
//! Class destructor.
~Brass();
@@ -43,40 +46,52 @@ class Brass: public Instrmnt
void clear();
//! Set instrument parameters for a particular frequency.
- void setFrequency(MY_FLOAT frequency);
+ void setFrequency(StkFloat frequency);
//! Set the lips frequency.
- void setLip(MY_FLOAT frequency);
+ void setLip(StkFloat frequency);
//! Apply breath pressure to instrument with given amplitude and rate of increase.
- void startBlowing(MY_FLOAT amplitude,MY_FLOAT rate);
+ void startBlowing(StkFloat amplitude, StkFloat rate);
//! Decrease breath pressure with given rate of decrease.
- void stopBlowing(MY_FLOAT rate);
+ void stopBlowing(StkFloat rate);
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
protected:
- DelayA *delayLine;
- BiQuad *lipFilter;
- PoleZero *dcBlock;
- ADSR *adsr;
- WaveLoop *vibrato;
- long length;
- MY_FLOAT lipTarget;
- MY_FLOAT slideTarget;
- MY_FLOAT vibratoGain;
- MY_FLOAT maxPressure;
+ DelayA delayLine_;
+ BiQuad lipFilter_;
+ PoleZero dcBlock_;
+ ADSR adsr_;
+ WaveLoop *vibrato_;
+ unsigned long length_;
+ StkFloat lipTarget_;
+ StkFloat slideTarget_;
+ StkFloat vibratoGain_;
+ StkFloat maxPressure_;
};
diff --git a/include/Chorus.h b/include/Chorus.h
index feadbcb..a4daaea 100644
--- a/include/Chorus.h
+++ b/include/Chorus.h
@@ -4,22 +4,25 @@
This class implements a chorus effect.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__CHORUS_H)
-#define __CHORUS_H
+#ifndef STK_CHORUS_H
+#define STK_CHORUS_H
-#include "Stk.h"
+#include "Effect.h"
#include "DelayL.h"
#include "WaveLoop.h"
-class Chorus : public Stk
+class Chorus : public Effect
{
public:
- //! Class constructor, taking the longest desired delay length.
- Chorus(MY_FLOAT baseDelay);
+ //! Class constructor, taking the median desired delay length.
+ /*!
+ An StkError can be thrown if the rawwave path is incorrect.
+ */
+ Chorus( StkFloat baseDelay = 6000 );
//! Class destructor.
~Chorus();
@@ -28,36 +31,31 @@ class Chorus : public Stk
void clear();
//! Set modulation depth.
- void setModDepth(MY_FLOAT depth);
+ void setModDepth(StkFloat depth);
//! Set modulation frequency.
- void setModFrequency(MY_FLOAT frequency);
-
- //! Set the mixture of input and processed levels in the output (0.0 = input only, 1.0 = processed only).
- void setEffectMix(MY_FLOAT mix);
-
- //! Return the last output value.
- MY_FLOAT lastOut() const;
-
- //! Return the last left output value.
- MY_FLOAT lastOutLeft() const;
-
- //! Return the last right output value.
- MY_FLOAT lastOutRight() const;
+ void setModFrequency(StkFloat frequency);
//! Compute one output sample.
- MY_FLOAT tick(MY_FLOAT input);
+ StkFloat tick(StkFloat input);
//! Take \e vectorSize inputs, compute the same number of outputs and return them in \e vector.
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
+
+ //! Take a channel of the StkFrames object as inputs to the effect and replace with corresponding 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:
- DelayL *delayLine[2];
- WaveLoop *mods[2];
- MY_FLOAT baseLength;
- MY_FLOAT modDepth;
- MY_FLOAT lastOutput[2];
- MY_FLOAT effectMix;
+ DelayL delayLine_[2];
+ WaveLoop *mods_[2];
+ StkFloat baseLength_;
+ StkFloat modDepth_;
};
diff --git a/include/Clarinet.h b/include/Clarinet.h
index cc60108..9aaac2c 100644
--- a/include/Clarinet.h
+++ b/include/Clarinet.h
@@ -18,16 +18,16 @@
- Vibrato Gain = 1
- Breath Pressure = 128
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__CLARINET_H)
-#define __CLARINET_H
+#ifndef STK_CLARINET_H
+#define STK_CLARINET_H
#include "Instrmnt.h"
#include "DelayL.h"
-#include "ReedTabl.h"
+#include "ReedTable.h"
#include "OneZero.h"
#include "Envelope.h"
#include "Noise.h"
@@ -37,7 +37,10 @@ class Clarinet : public Instrmnt
{
public:
//! Class constructor, taking the lowest desired playing frequency.
- Clarinet(MY_FLOAT lowestFrequency);
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
+ Clarinet(StkFloat lowestFrequency);
//! Class destructor.
~Clarinet();
@@ -46,37 +49,49 @@ class Clarinet : public Instrmnt
void clear();
//! Set instrument parameters for a particular frequency.
- void setFrequency(MY_FLOAT frequency);
+ void setFrequency(StkFloat frequency);
//! Apply breath pressure to instrument with given amplitude and rate of increase.
- void startBlowing(MY_FLOAT amplitude, MY_FLOAT rate);
+ void startBlowing(StkFloat amplitude, StkFloat rate);
//! Decrease breath pressure with given rate of decrease.
- void stopBlowing(MY_FLOAT rate);
+ void stopBlowing(StkFloat rate);
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
protected:
- DelayL *delayLine;
- ReedTabl *reedTable;
- OneZero *filter;
- Envelope *envelope;
- Noise *noise;
- WaveLoop *vibrato;
- long length;
- MY_FLOAT outputGain;
- MY_FLOAT noiseGain;
- MY_FLOAT vibratoGain;
+ DelayL delayLine_;
+ ReedTable reedTable_;
+ OneZero filter_;
+ Envelope envelope_;
+ Noise noise_;
+ WaveLoop *vibrato_;
+ long length_;
+ StkFloat outputGain_;
+ StkFloat noiseGain_;
+ StkFloat vibratoGain_;
};
diff --git a/include/Delay.h b/include/Delay.h
index 84dcff0..7ef8cbc 100644
--- a/include/Delay.h
+++ b/include/Delay.h
@@ -14,12 +14,12 @@
used in fixed delay-length applications, such
as for reverberation.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__DELAY_H)
-#define __DELAY_H
+#ifndef STK_DELAY_H
+#define STK_DELAY_H
#include "Filter.h"
@@ -31,7 +31,12 @@ public:
Delay();
//! Overloaded constructor which specifies the current and maximum delay-line lengths.
- Delay(long theDelay, long maxDelay);
+ /*!
+ An StkError will be thrown if the delay parameter is less than
+ zero, the maximum delay parameter is less than one, or the delay
+ parameter is greater than the maxDelay value.
+ */
+ Delay(unsigned long delay, unsigned long maxDelay);
//! Class destructor.
virtual ~Delay();
@@ -39,17 +44,27 @@ public:
//! Clears the internal state of the delay line.
void clear();
+ //! Set the maximum delay-line length.
+ /*!
+ This method should generally only be used during initial setup
+ of the delay line. If it is used between calls to the tick()
+ function, without a call to clear(), a signal discontinuity will
+ likely occur. If the current maximum length is greater than the
+ new length, no change will be made.
+ */
+ void setMaximumDelay(unsigned long delay);
+
//! Set the delay-line length.
/*!
The valid range for \e theDelay is from 0 to the maximum delay-line length.
*/
- void setDelay(long theDelay);
+ void setDelay(unsigned long delay);
//! Return the current delay-line length.
- long getDelay(void) const;
+ unsigned long getDelay(void) const;
//! Calculate and return the signal energy in the delay-line.
- MY_FLOAT energy(void) const;
+ StkFloat energy(void) const;
//! Return the value at \e tapDelay samples from the delay-line input.
/*!
@@ -57,28 +72,36 @@ public:
relative to the last input value (i.e., a tapDelay of zero returns
the last input value).
*/
- MY_FLOAT contentsAt(unsigned long tapDelay) const;
+ StkFloat contentsAt(unsigned long tapDelay);
//! Return the last computed output value.
- MY_FLOAT lastOut(void) const;
+ StkFloat lastOut(void) const;
//! Return the value which will be output by the next call to tick().
/*!
This method is valid only for delay settings greater than zero!
*/
- virtual MY_FLOAT nextOut(void) const;
+ virtual StkFloat nextOut(void);
- //! Input one sample to the delay-line and return one output.
- virtual MY_FLOAT tick(MY_FLOAT sample);
+ //! Input one sample to the delayline and return one output.
+ virtual StkFloat tick(StkFloat sample);
- //! Input \e vectorSize samples to the delay-line and return an equal number of outputs in \e vector.
- virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ //! Input \e vectorSize samples to the delayline and return an equal number of outputs in \e vector.
+ virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
+
+ //! Take a channel of the StkFrames object as inputs to the delayline and replace with corresponding 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:
- long inPoint;
- long outPoint;
- long length;
- MY_FLOAT delay;
+ unsigned long inPoint_;
+ unsigned long outPoint_;
+ StkFloat delay_;
};
#endif
diff --git a/include/DelayA.h b/include/DelayA.h
index 224273f..9ef6a0b 100644
--- a/include/DelayA.h
+++ b/include/DelayA.h
@@ -18,12 +18,12 @@
response, the minimum delay possible in this
implementation is limited to a value of 0.5.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__DelayA_h)
-#define __DelayA_h
+#ifndef STK_DELAYA_H
+#define STK_DELAYA_H
#include "Delay.h"
@@ -35,8 +35,12 @@ public:
DelayA();
//! Overloaded constructor which specifies the current and maximum delay-line lengths.
-
- DelayA(MY_FLOAT theDelay, long maxDelay);
+ /*!
+ An StkError will be thrown if the delay parameter is less than
+ zero, the maximum delay parameter is less than one, or the delay
+ parameter is greater than the maxDelay value.
+ */
+ DelayA(StkFloat delay, unsigned long maxDelay);
//! Class destructor.
~DelayA();
@@ -48,26 +52,38 @@ public:
/*!
The valid range for \e theDelay is from 0.5 to the maximum delay-line length.
*/
- void setDelay(MY_FLOAT theDelay);
+ void setDelay(StkFloat delay);
//! Return the current delay-line length.
- MY_FLOAT getDelay(void);
+ StkFloat getDelay(void);
//! Return the value which will be output by the next call to tick().
/*!
This method is valid only for delay settings greater than zero!
*/
- MY_FLOAT nextOut(void);
+ StkFloat nextOut(void);
- //! Input one sample to the delay-line and return one output.
- MY_FLOAT tick(MY_FLOAT sample);
+ //! Input one sample to the delayline and return one output.
+ StkFloat tick(StkFloat sample);
+
+ //! Input \e vectorSize samples to the delayline and return an equal number of outputs in \e vector.
+ virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
+
+ //! Take a channel of the StkFrames object as inputs to the delayline and replace with corresponding 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:
- MY_FLOAT alpha;
- MY_FLOAT coeff;
- MY_FLOAT apInput;
- MY_FLOAT nextOutput;
- bool doNextOut;
+ StkFloat alpha_;
+ StkFloat coeff_;
+ StkFloat apInput_;
+ StkFloat nextOutput_;
+ bool doNextOut_;
};
#endif
diff --git a/include/DelayL.h b/include/DelayL.h
index 6169b13..722a7da 100644
--- a/include/DelayL.h
+++ b/include/DelayL.h
@@ -18,12 +18,12 @@
order Lagrange interpolators can typically
improve (minimize) this attenuation characteristic.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__DELAYL_H)
-#define __DELAYL_H
+#ifndef STK_DELAYL_H
+#define STK_DELAYL_H
#include "Delay.h"
@@ -35,8 +35,12 @@ public:
DelayL();
//! Overloaded constructor which specifies the current and maximum delay-line lengths.
-
- DelayL(MY_FLOAT theDelay, long maxDelay);
+ /*!
+ An StkError will be thrown if the delay parameter is less than
+ zero, the maximum delay parameter is less than one, or the delay
+ parameter is greater than the maxDelay value.
+ */
+ DelayL(StkFloat delay, unsigned long maxDelay);
//! Class destructor.
~DelayL();
@@ -45,25 +49,37 @@ public:
/*!
The valid range for \e theDelay is from 0 to the maximum delay-line length.
*/
- void setDelay(MY_FLOAT theDelay);
+ void setDelay(StkFloat delay);
//! Return the current delay-line length.
- MY_FLOAT getDelay(void) const;
+ StkFloat getDelay(void) const;
//! Return the value which will be output by the next call to tick().
/*!
This method is valid only for delay settings greater than zero!
*/
- MY_FLOAT nextOut(void);
+ StkFloat nextOut(void);
//! Input one sample to the delay-line and return one output.
- MY_FLOAT tick(MY_FLOAT sample);
+ StkFloat tick(StkFloat sample);
+
+ //! Input \e vectorSize samples to the delay-line and return an equal number of outputs in \e vector.
+ virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
+
+ //! Take a channel of the StkFrames object as inputs to the delayline and replace with corresponding 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:
- MY_FLOAT alpha;
- MY_FLOAT omAlpha;
- MY_FLOAT nextOutput;
- bool doNextOut;
+ StkFloat alpha_;
+ StkFloat omAlpha_;
+ StkFloat nextOutput_;
+ bool doNextOut_;
};
#endif
diff --git a/include/Drummer.h b/include/Drummer.h
index 5cd66e3..b081ae8 100644
--- a/include/Drummer.h
+++ b/include/Drummer.h
@@ -11,24 +11,27 @@
of simultaneous voices) via a #define in the
Drummer.h.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__DRUMMER_H)
-#define __DRUMMER_H
+#ifndef STK_DRUMMER_H
+#define STK_DRUMMER_H
#include "Instrmnt.h"
#include "WvIn.h"
#include "OnePole.h"
-#define DRUM_NUMWAVES 11
-#define DRUM_POLYPHONY 4
+const int DRUM_NUMWAVES = 11;
+const int DRUM_POLYPHONY = 4;
class Drummer : public Instrmnt
{
public:
//! Class constructor.
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
Drummer();
//! Class destructor.
@@ -37,23 +40,35 @@ class Drummer : public Instrmnt
//! Start a note with the given drum type and amplitude.
/*!
Use general MIDI drum instrument numbers, converted to
- frequency values as if MIDI note numbers, to select a
- particular instrument.
+ frequency values as if MIDI note numbers, to select a particular
+ instrument. An StkError will be thrown if the rawwave path is
+ incorrectly set.
*/
- 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[DRUM_POLYPHONY];
- OnePole *filters[DRUM_POLYPHONY];
- int sounding[DRUM_POLYPHONY];
- int nSounding;
-
+ WvIn *waves_[DRUM_POLYPHONY];
+ OnePole *filters_[DRUM_POLYPHONY];
+ int sounding_[DRUM_POLYPHONY];
+ int nSounding_;
};
#endif
diff --git a/include/Echo.h b/include/Echo.h
index 62740e7..57d7f11 100644
--- a/include/Echo.h
+++ b/include/Echo.h
@@ -2,23 +2,26 @@
/*! \class Echo
\brief STK echo effect class.
- This class implements a echo effect.
+ This class implements an echo effect.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__ECHO_H)
-#define __ECHO_H
+#ifndef STK_ECHO_H
+#define STK_ECHO_H
-#include "Stk.h"
+#include "Effect.h"
#include "Delay.h"
-class Echo : public Stk
+class Echo : public Effect
{
public:
- //! Class constructor, taking the longest desired delay length.
- Echo(MY_FLOAT longestDelay);
+ //! Class constructor, taking the longest desired delay length (one second default value).
+ /*!
+ The default delay value is set to 1/2 the maximum delay length.
+ */
+ Echo( unsigned long maximumDelay = (unsigned long) Stk::sampleRate() );
//! Class destructor.
~Echo();
@@ -26,26 +29,30 @@ class Echo : public Stk
//! Reset and clear all internal state.
void clear();
+ //! Set the maximum delay line length in samples.
+ void setMaximumDelay( unsigned long delay );
+
//! Set the delay line length in samples.
- void setDelay(MY_FLOAT delay);
-
- //! Set the mixture of input and processed levels in the output (0.0 = input only, 1.0 = processed only).
- void setEffectMix(MY_FLOAT mix);
-
- //! Return the last output value.
- MY_FLOAT lastOut() const;
+ void setDelay( unsigned long delay );
//! Compute one output sample.
- MY_FLOAT tick(MY_FLOAT input);
+ StkFloat tick(StkFloat input);
- //! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ //! Take \e vectorSize inputs, compute the same number of outputs and return them in \e vector.
+ StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
+
+ //! Take a channel of the StkFrames object as inputs to the effect and replace with corresponding 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:
- Delay *delayLine;
- long length;
- MY_FLOAT lastOutput;
- MY_FLOAT effectMix;
+ Delay delayLine_;
+ unsigned long length_;
};
diff --git a/include/Effect.h b/include/Effect.h
new file mode 100644
index 0000000..60d40e9
--- /dev/null
+++ b/include/Effect.h
@@ -0,0 +1,67 @@
+/***************************************************/
+/*! \class Effect
+ \brief STK abstract effects parent class.
+
+ This class provides common functionality for
+ STK effects subclasses.
+
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
+*/
+/***************************************************/
+
+#include "Stk.h"
+
+#ifndef STK_EFFECT_H
+#define STK_EFFECT_H
+
+class Effect : public Stk
+{
+ public:
+ //! Class constructor.
+ Effect();
+
+ //! Class destructor.
+ virtual ~Effect();
+
+ //! Reset and clear all internal state.
+ virtual void clear() = 0;
+
+ //! Set the mixture of input and "effected" levels in the output (0.0 = input only, 1.0 = reverb only).
+ void setEffectMix(StkFloat mix);
+
+ //! Return the last output value.
+ StkFloat lastOut() const;
+
+ //! Return the last left output value.
+ StkFloat lastOutLeft() const;
+
+ //! Return the last right output value.
+ StkFloat lastOutRight() const;
+
+ //! Abstract tick function ... must be implemented in subclasses.
+ virtual StkFloat tick( StkFloat input ) = 0;
+
+ //! Take \e vectorSize inputs, compute the same number of outputs and return them in \e vector.
+ virtual StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
+
+ //! Take a channel of the StkFrames object as inputs to the effect and replace with corresponding 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:
+
+ // Returns true if argument value is prime.
+ bool isPrime( int number );
+
+ StkFloat lastOutput_[2];
+ StkFloat effectMix_;
+
+};
+
+#endif
+
diff --git a/include/Envelope.h b/include/Envelope.h
index a1abbf7..dc5b2c7 100644
--- a/include/Envelope.h
+++ b/include/Envelope.h
@@ -9,16 +9,16 @@
\e keyOff messages, ramping to 1.0 on
keyOn and to 0.0 on keyOff.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__ENVELOPE_H)
-#define __ENVELOPE_H
+#ifndef STK_ENVELOPE_H
+#define STK_ENVELOPE_H
-#include "Stk.h"
+#include "Generator.h"
-class Envelope : public Stk
+class Envelope : public Generator
{
public:
@@ -35,34 +35,40 @@ class Envelope : public Stk
virtual void keyOff(void);
//! Set the \e rate.
- void setRate(MY_FLOAT aRate);
+ void setRate(StkFloat rate);
//! Set the \e rate based on a time duration.
- void setTime(MY_FLOAT aTime);
+ void setTime(StkFloat time);
//! Set the target value.
- virtual void setTarget(MY_FLOAT aTarget);
+ virtual void setTarget(StkFloat target);
//! Set current and target values to \e aValue.
- virtual void setValue(MY_FLOAT aValue);
+ virtual void setValue(StkFloat value);
//! Return the current envelope \e state (0 = at target, 1 otherwise).
virtual int getState(void) const;
//! Return one envelope output value.
- virtual MY_FLOAT tick(void);
+ virtual StkFloat tick(void);
- //! Return \e vectorSize envelope outputs in \e vector.
- virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ //! Compute \e vectorSize outputs and return them in \e vector.
+ virtual StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
- //! Return the last computed output value.
- MY_FLOAT lastOut(void) const;
+ //! 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:
- MY_FLOAT value;
- MY_FLOAT target;
- MY_FLOAT rate;
- int state;
+ StkFloat value_;
+ StkFloat target_;
+ StkFloat rate_;
+ int state_;
};
#endif
diff --git a/include/FM.h b/include/FM.h
index f912fca..d09d2fa 100644
--- a/include/FM.h
+++ b/include/FM.h
@@ -19,12 +19,12 @@
type who should worry about this (making
money) worry away.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__FM_H)
-#define __FM_H
+#ifndef STK_FM_H
+#define STK_FM_H
#include "Instrmnt.h"
#include "ADSR.h"
@@ -35,7 +35,10 @@ class FM : public Instrmnt
{
public:
//! Class constructor, taking the number of wave/envelope operators to control.
- FM( int operators = 4 );
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
+ FM( unsigned int operators = 4 );
//! Class destructor.
virtual ~FM();
@@ -47,25 +50,25 @@ class FM : public Instrmnt
void loadWaves(const char **filenames);
//! Set instrument parameters for a particular frequency.
- virtual void setFrequency(MY_FLOAT frequency);
+ virtual void setFrequency(StkFloat frequency);
//! Set the frequency ratio for the specified wave.
- void setRatio(int waveIndex, MY_FLOAT ratio);
+ void setRatio(unsigned int waveIndex, StkFloat ratio);
//! Set the gain for the specified wave.
- void setGain(int waveIndex, MY_FLOAT gain);
+ void setGain(unsigned int waveIndex, StkFloat gain);
//! Set the modulation speed in Hz.
- void setModulationSpeed(MY_FLOAT mSpeed);
+ void setModulationSpeed(StkFloat mSpeed);
//! Set the modulation depth.
- void setModulationDepth(MY_FLOAT mDepth);
+ void setModulationDepth(StkFloat mDepth);
//! Set the value of control1.
- void setControl1(MY_FLOAT cVal);
+ void setControl1(StkFloat cVal);
//! Set the value of control1.
- void setControl2(MY_FLOAT cVal);
+ void setControl2(StkFloat cVal);
//! Start envelopes toward "on" targets.
void keyOn();
@@ -74,29 +77,41 @@ class FM : public Instrmnt
void keyOff();
//! Stop a note with the given amplitude (speed of decay).
- void noteOff(MY_FLOAT amplitude);
+ void noteOff(StkFloat amplitude);
//! Pure virtual function ... must be defined in subclasses.
- virtual MY_FLOAT tick() = 0;
+ virtual StkFloat tick() = 0;
+
+ //! Computer \e vectorSize outputs and return them in \e vector.
+ virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize) = 0;
+
+ //! 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 ) = 0;
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- virtual void controlChange(int number, MY_FLOAT value);
+ virtual void controlChange(int number, StkFloat value);
protected:
- ADSR **adsr;
- WaveLoop **waves;
- WaveLoop *vibrato;
- TwoZero *twozero;
- int nOperators;
- MY_FLOAT baseFrequency;
- MY_FLOAT *ratios;
- MY_FLOAT *gains;
- MY_FLOAT modDepth;
- MY_FLOAT control1;
- MY_FLOAT control2;
- MY_FLOAT __FM_gains[100];
- MY_FLOAT __FM_susLevels[16];
- MY_FLOAT __FM_attTimes[32];
+ std::vector adsr_;
+ std::vector waves_;
+ WaveLoop *vibrato_;
+ TwoZero twozero_;
+ unsigned int nOperators_;
+ StkFloat baseFrequency_;
+ std::vector ratios_;
+ std::vector gains_;
+ StkFloat modDepth_;
+ StkFloat control1_;
+ StkFloat control2_;
+ StkFloat fmGains_[100];
+ StkFloat fmSusLevels_[16];
+ StkFloat fmAttTimes_[32];
};
diff --git a/include/FMVoices.h b/include/FMVoices.h
index 9c5b3c7..e771e3d 100644
--- a/include/FMVoices.h
+++ b/include/FMVoices.h
@@ -26,12 +26,12 @@
type who should worry about this (making
money) worry away.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__FMVOICES_H)
-#define __FMVOICES_H
+#ifndef STK_FMVOICES_H
+#define STK_FMVOICES_H
#include "FM.h"
@@ -39,27 +39,42 @@ class FMVoices : public FM
{
public:
//! Class constructor.
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
FMVoices();
//! Class destructor.
~FMVoices();
//! Set instrument parameters for a particular frequency.
- virtual void setFrequency(MY_FLOAT frequency);
+ virtual void setFrequency(StkFloat frequency);
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- virtual void controlChange(int number, MY_FLOAT value);
+ virtual void controlChange(int number, StkFloat value);
protected:
- int currentVowel;
- MY_FLOAT tilt[3];
- MY_FLOAT mods[3];
+ int currentVowel_;
+ StkFloat tilt_[3];
+ StkFloat mods_[3];
};
#endif
diff --git a/include/Filter.h b/include/Filter.h
index cb9fd5a..365acec 100644
--- a/include/Filter.h
+++ b/include/Filter.h
@@ -23,14 +23,16 @@
results in one extra multiply per computed sample,
but allows easy control of the overall filter gain.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__FILTER_H)
-#define __FILTER_H
+#ifndef STK_FILTER_H
+#define STK_FILTER_H
#include "Stk.h"
+#include
+#include
class Filter : public Stk
{
@@ -40,72 +42,81 @@ public:
//! Overloaded constructor which takes filter coefficients.
/*!
- An StkError can be thrown if either \e nb or \e na is less than
- one, or if the a[0] coefficient is equal to zero.
+ An StkError can be thrown if either of the coefficient vector
+ sizes is zero, or if the a[0] coefficient is equal to zero.
*/
- Filter(int nb, MY_FLOAT *bCoefficients, int na, MY_FLOAT *aCoefficients);
+ Filter( std::vector &bCoefficients, std::vector &aCoefficients );
//! Class destructor.
virtual ~Filter(void);
- //! Clears all internal states of the filter.
+ //! Sets all internal states of the filter to zero.
void clear(void);
//! Set filter coefficients.
/*!
- An StkError can be thrown if either \e nb or \e na is less than
- one, or if the a[0] coefficient is equal to zero. If a[0] is not
- equal to 1, the filter coeffcients are normalized by a[0].
+ An StkError can be thrown if either of the coefficient vector
+ sizes is zero, or if the a[0] coefficient is equal to zero. If
+ a[0] is not equal to 1, the filter coeffcients are normalized by
+ a[0]. The internal state of the filter is cleared.
*/
- void setCoefficients(int nb, MY_FLOAT *bCoefficients, int na, MY_FLOAT *aCoefficients);
+ void setCoefficients( std::vector &bCoefficients, std::vector &aCoefficients );
//! Set numerator coefficients.
/*!
- An StkError can be thrown if \e nb is less than one. Any
- previously set denominator coefficients are left unaffected.
- Note that the default constructor sets the single denominator
- coefficient a[0] to 1.0.
+ An StkError can be thrown if coefficient vector is empty. Any
+ previously set denominator coefficients are left unaffected. Note
+ that the default constructor sets the single denominator
+ coefficient a[0] to 1.0. The internal state of the filter is
+ cleared.
*/
- void setNumerator(int nb, MY_FLOAT *bCoefficients);
+ void setNumerator( std::vector &bCoefficients );
//! Set denominator coefficients.
/*!
- An StkError can be thrown if \e na is less than one or if the
- a[0] coefficient is equal to zero. Previously set numerator
- coefficients are unaffected unless a[0] is not equal to 1, in
- which case all coeffcients are normalized by a[0]. Note that the
- default constructor sets the single numerator coefficient b[0]
- to 1.0.
+ An StkError can be thrown if the coefficient vector is empty or
+ if the a[0] coefficient is equal to zero. Previously set
+ numerator coefficients are unaffected unless a[0] is not equal to
+ 1, in which case all coeffcients are normalized by a[0]. Note
+ that the default constructor sets the single numerator coefficient
+ b[0] to 1.0. The internal state of the filter is cleared.
*/
- void setDenominator(int na, MY_FLOAT *aCoefficients);
+ void setDenominator( std::vector &aCoefficients );
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
- virtual void setGain(MY_FLOAT theGain);
+ virtual void setGain(StkFloat gain);
//! Return the current filter gain.
- virtual MY_FLOAT getGain(void) const;
+ virtual StkFloat getGain(void) const;
//! Return the last computed output value.
- virtual MY_FLOAT lastOut(void) const;
+ virtual StkFloat lastOut(void) const;
//! Input one sample to the filter and return one output.
- virtual MY_FLOAT tick(MY_FLOAT sample);
+ virtual StkFloat tick(StkFloat sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
- virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
+
+ //! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding 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:
- MY_FLOAT gain;
- int nB;
- int nA;
- MY_FLOAT *b;
- MY_FLOAT *a;
- MY_FLOAT *outputs;
- MY_FLOAT *inputs;
+ StkFloat gain_;
+ std::vector b_;
+ std::vector a_;
+ std::vector outputs_;
+ std::vector inputs_;
};
diff --git a/include/Flute.h b/include/Flute.h
index 93becad..abe3bf1 100644
--- a/include/Flute.h
+++ b/include/Flute.h
@@ -18,15 +18,15 @@
- Vibrato Gain = 1
- Breath Pressure = 128
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__FLUTE_H)
-#define __FLUTE_H
+#ifndef STK_FLUTE_H
+#define STK_FLUTE_H
#include "Instrmnt.h"
-#include "JetTabl.h"
+#include "JetTable.h"
#include "DelayL.h"
#include "OnePole.h"
#include "PoleZero.h"
@@ -38,7 +38,10 @@ class Flute : public Instrmnt
{
public:
//! Class constructor, taking the lowest desired playing frequency.
- Flute(MY_FLOAT lowestFrequency);
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
+ Flute(StkFloat lowestFrequency);
//! Class destructor.
~Flute();
@@ -47,53 +50,65 @@ class Flute : public Instrmnt
void clear();
//! Set instrument parameters for a particular frequency.
- void setFrequency(MY_FLOAT frequency);
+ void setFrequency(StkFloat frequency);
//! Set the reflection coefficient for the jet delay (-1.0 - 1.0).
- void setJetReflection(MY_FLOAT coefficient);
+ void setJetReflection(StkFloat coefficient);
//! Set the reflection coefficient for the air column delay (-1.0 - 1.0).
- void setEndReflection(MY_FLOAT coefficient);
+ void setEndReflection(StkFloat coefficient);
//! Set the length of the jet delay in terms of a ratio of jet delay to air column delay lengths.
- void setJetDelay(MY_FLOAT aRatio);
+ void setJetDelay(StkFloat aRatio);
//! Apply breath velocity to instrument with given amplitude and rate of increase.
- void startBlowing(MY_FLOAT amplitude, MY_FLOAT rate);
+ void startBlowing(StkFloat amplitude, StkFloat rate);
//! Decrease breath velocity with given rate of decrease.
- void stopBlowing(MY_FLOAT rate);
+ void stopBlowing(StkFloat rate);
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
protected:
- DelayL *jetDelay;
- DelayL *boreDelay;
- JetTabl *jetTable;
- OnePole *filter;
- PoleZero *dcBlock;
- Noise *noise;
- ADSR *adsr;
- WaveLoop *vibrato;
- long length;
- MY_FLOAT lastFrequency;
- MY_FLOAT maxPressure;
- MY_FLOAT jetReflection;
- MY_FLOAT endReflection;
- MY_FLOAT noiseGain;
- MY_FLOAT vibratoGain;
- MY_FLOAT outputGain;
- MY_FLOAT jetRatio;
+ DelayL jetDelay_;
+ DelayL boreDelay_;
+ JetTable jetTable_;
+ OnePole filter_;
+ PoleZero dcBlock_;
+ Noise noise_;
+ ADSR adsr_;
+ WaveLoop *vibrato_;
+ unsigned long length_;
+ StkFloat lastFrequency_;
+ StkFloat maxPressure_;
+ StkFloat jetReflection_;
+ StkFloat endReflection_;
+ StkFloat noiseGain_;
+ StkFloat vibratoGain_;
+ StkFloat outputGain_;
+ StkFloat jetRatio_;
};
diff --git a/include/FormSwep.h b/include/FormSwep.h
index fd1e718..332a8f7 100644
--- a/include/FormSwep.h
+++ b/include/FormSwep.h
@@ -8,12 +8,12 @@
It provides methods for controlling the sweep
rate and target frequency.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__FORMSWEP_H)
-#define __FORMSWEP_H
+#ifndef STK_FORMSWEP_H
+#define STK_FORMSWEP_H
#include "BiQuad.h"
@@ -39,13 +39,13 @@ class FormSwep : public BiQuad
the unit-circle (\e radius close to one), the narrower the
resulting resonance width.
*/
- void setResonance(MY_FLOAT aFrequency, MY_FLOAT aRadius);
+ void setResonance(StkFloat frequency, StkFloat radius);
//! Set both the current and target resonance parameters.
- void setStates(MY_FLOAT aFrequency, MY_FLOAT aRadius, MY_FLOAT aGain = 1.0);
+ void setStates(StkFloat frequency, StkFloat radius, StkFloat gain = 1.0);
//! Set target resonance parameters.
- void setTargets(MY_FLOAT aFrequency, MY_FLOAT aRadius, MY_FLOAT aGain = 1.0);
+ void setTargets(StkFloat frequency, StkFloat radius, StkFloat gain = 1.0);
//! Set the sweep rate (between 0.0 - 1.0).
/*!
@@ -56,7 +56,7 @@ class FormSwep : public BiQuad
target values. A sweep rate of 0.0 will produce no
change in resonance parameters.
*/
- void setSweepRate(MY_FLOAT aRate);
+ void setSweepRate(StkFloat rate);
//! Set the sweep rate in terms of a time value in seconds.
/*!
@@ -64,29 +64,38 @@ class FormSwep : public BiQuad
given time for the formant parameters to reach
their target values.
*/
- void setSweepTime(MY_FLOAT aTime);
+ void setSweepTime(StkFloat time);
//! Input one sample to the filter and return one output.
- MY_FLOAT tick(MY_FLOAT sample);
+ StkFloat tick(StkFloat sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
+
+ //! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding 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:
- bool dirty;
- MY_FLOAT frequency;
- MY_FLOAT radius;
- MY_FLOAT startFrequency;
- MY_FLOAT startRadius;
- MY_FLOAT startGain;
- MY_FLOAT targetFrequency;
- MY_FLOAT targetRadius;
- MY_FLOAT targetGain;
- MY_FLOAT deltaFrequency;
- MY_FLOAT deltaRadius;
- MY_FLOAT deltaGain;
- MY_FLOAT sweepState;
- MY_FLOAT sweepRate;
+ bool dirty_;
+ StkFloat frequency_;
+ StkFloat radius_;
+ StkFloat startFrequency_;
+ StkFloat startRadius_;
+ StkFloat startGain_;
+ StkFloat targetFrequency_;
+ StkFloat targetRadius_;
+ StkFloat targetGain_;
+ StkFloat deltaFrequency_;
+ StkFloat deltaRadius_;
+ StkFloat deltaGain_;
+ StkFloat sweepState_;
+ StkFloat sweepRate_;
};
diff --git a/include/Function.h b/include/Function.h
new file mode 100644
index 0000000..c58f822
--- /dev/null
+++ b/include/Function.h
@@ -0,0 +1,52 @@
+/***************************************************/
+/*! \class Function
+ \brief STK abstract function parent class.
+
+ This class provides common functionality for STK classes which
+ implement tables or other types of input to output function
+ mappings.
+
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
+*/
+/***************************************************/
+
+#include "Stk.h"
+
+#ifndef STK_FUNCTION_H
+#define STK_FUNCTION_H
+
+class Function : public Stk
+{
+ public:
+ //! Class constructor.
+ Function();
+
+ //! Class destructor.
+ virtual ~Function();
+
+ //! Return the last output value.
+ virtual StkFloat lastOut() const { return lastOutput_; };
+
+ //! Abstract tick function ... must be implemented in subclasses.
+ virtual StkFloat tick( StkFloat input ) = 0;
+
+ //! Take \e vectorSize inputs from \e vector and replace them with corresponding outputs.
+ virtual StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
+
+ //! Take a channel of the StkFrames object as inputs to the function and replace with corresponding 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:
+
+ StkFloat lastOutput_;
+
+};
+
+#endif
+
diff --git a/include/Generator.h b/include/Generator.h
new file mode 100644
index 0000000..212f355
--- /dev/null
+++ b/include/Generator.h
@@ -0,0 +1,51 @@
+/***************************************************/
+/*! \class Generator
+ \brief STK abstract unit generator parent class.
+
+ This class provides common functionality for
+ STK unit generator source subclasses.
+
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
+*/
+/***************************************************/
+
+#ifndef STK_GENERATOR_H
+#define STK_GENERATOR_H
+
+#include "Stk.h"
+
+class Generator : public Stk
+{
+ public:
+ //! Class constructor.
+ Generator();
+
+ //! Class destructor.
+ virtual ~Generator();
+
+ //! Return the last output value.
+ virtual StkFloat lastOut() const { return lastOutput_; };
+
+ //! Abstract tick function ... must be implemented in subclasses.
+ virtual StkFloat tick( void ) = 0;
+
+ //! Compute \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:
+
+ StkFloat lastOutput_;
+
+};
+
+#endif
+
diff --git a/include/HevyMetl.h b/include/HevyMetl.h
index 3876a65..1495cd5 100644
--- a/include/HevyMetl.h
+++ b/include/HevyMetl.h
@@ -24,12 +24,12 @@
type who should worry about this (making
money) worry away.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__HEVYMETL_H)
-#define __HEVYMETL_H
+#ifndef STK_HEVYMETL_H
+#define STK_HEVYMETL_H
#include "FM.h"
@@ -37,16 +37,31 @@ class HevyMetl : public FM
{
public:
//! Class constructor.
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
HevyMetl();
//! Class destructor.
~HevyMetl();
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
};
#endif
diff --git a/include/Instrmnt.h b/include/Instrmnt.h
index e954baf..e710e33 100644
--- a/include/Instrmnt.h
+++ b/include/Instrmnt.h
@@ -5,15 +5,14 @@
This class provides a common interface for
all STK instruments.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__INSTRMNT_H)
-#define __INSTRMNT_H
+#ifndef STK_INSTRMNT_H
+#define STK_INSTRMNT_H
#include "Stk.h"
-#include
class Instrmnt : public Stk
{
@@ -25,34 +24,43 @@ class Instrmnt : public Stk
virtual ~Instrmnt();
//! Start a note with the given frequency and amplitude.
- virtual void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude) = 0;
+ virtual void noteOn(StkFloat frequency, StkFloat amplitude) = 0;
//! Stop a note with the given amplitude (speed of decay).
- virtual void noteOff(MY_FLOAT amplitude) = 0;
+ virtual void noteOff(StkFloat amplitude) = 0;
//! Set instrument parameters for a particular frequency.
- virtual void setFrequency(MY_FLOAT frequency);
+ virtual void setFrequency(StkFloat frequency);
//! Return the last output value.
- MY_FLOAT lastOut() const;
+ StkFloat lastOut() const;
//! Return the last left output value.
- MY_FLOAT lastOutLeft() const;
+ StkFloat lastOutLeft() const;
//! Return the last right output value.
- MY_FLOAT lastOutRight() const;
+ StkFloat lastOutRight() const;
//! Compute one output sample.
- virtual MY_FLOAT tick() = 0;
+ virtual StkFloat tick() = 0;
//! Computer \e vectorSize outputs and return them in \e vector.
- virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
-
+ 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 );
+
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- virtual void controlChange(int number, MY_FLOAT value);
+ virtual void controlChange(int number, StkFloat value);
protected:
- MY_FLOAT lastOutput;
+ StkFloat lastOutput_;
};
diff --git a/include/JCRev.h b/include/JCRev.h
index 5ef1bb5..312002c 100644
--- a/include/JCRev.h
+++ b/include/JCRev.h
@@ -10,21 +10,21 @@
filters, and two decorrelation delay lines in
parallel at the output.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__JCREV_H)
-#define __JCREV_H
+#ifndef STK_JCREV_H
+#define STK_JCREV_H
-#include "Reverb.h"
+#include "Effect.h"
#include "Delay.h"
-class JCRev : public Reverb
+class JCRev : public Effect
{
public:
- //! Class constructor taking a T60 decay time argument.
- JCRev(MY_FLOAT T60);
+ //! Class constructor taking a T60 decay time argument (one second default value).
+ JCRev( StkFloat T60 = 1.0 );
//! Class destructor.
~JCRev();
@@ -32,16 +32,31 @@ class JCRev : public Reverb
//! Reset and clear all internal state.
void clear();
+ //! Set the reverberation T60 decay time.
+ void setT60( StkFloat T60 );
+
//! Compute one output sample.
- MY_FLOAT tick(MY_FLOAT input);
+ StkFloat tick(StkFloat input);
+
+ //! Take \e vectorSize inputs, compute the same number of outputs and return them in \e vector.
+ StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
+
+ //! Take a channel of the StkFrames object as inputs to the effect and replace with corresponding 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:
- Delay *allpassDelays[3];
- Delay *combDelays[4];
- Delay *outLeftDelay;
- Delay *outRightDelay;
- MY_FLOAT allpassCoefficient;
- MY_FLOAT combCoefficient[4];
+ Delay allpassDelays_[3];
+ Delay combDelays_[4];
+ Delay outLeftDelay_;
+ Delay outRightDelay_;
+ StkFloat allpassCoefficient_;
+ StkFloat combCoefficient_[4];
};
diff --git a/include/JetTabl.h b/include/JetTabl.h
deleted file mode 100644
index 0698b3c..0000000
--- a/include/JetTabl.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/***************************************************/
-/*! \class JetTabl
- \brief STK jet table class.
-
- This class implements a flue jet non-linear
- function, computed by a polynomial calculation.
- Contrary to the name, this is not a "table".
-
- Consult Fletcher and Rossing, Karjalainen,
- Cook, and others for more information.
-
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
-*/
-/***************************************************/
-
-#if !defined(__JETTABL_H)
-#define __JETTABL_H
-
-#include "Stk.h"
-
-class JetTabl : public Stk
-{
-public:
- //! Default constructor.
- JetTabl();
-
- //! Class destructor.
- ~JetTabl();
-
- //! Return the last output value.
- MY_FLOAT lastOut() const;
-
- //! Return the function value for \e input.
- MY_FLOAT tick(MY_FLOAT input);
-
- //! Take \e vectorSize inputs and return the corresponding function values in \e vector.
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
-
-protected:
- MY_FLOAT lastOutput;
-
-};
-
-#endif
diff --git a/include/JetTable.h b/include/JetTable.h
new file mode 100644
index 0000000..15c9515
--- /dev/null
+++ b/include/JetTable.h
@@ -0,0 +1,49 @@
+/***************************************************/
+/*! \class JetTable
+ \brief STK jet table class.
+
+ This class implements a flue jet non-linear
+ function, computed by a polynomial calculation.
+ Contrary to the name, this is not a "table".
+
+ Consult Fletcher and Rossing, Karjalainen,
+ Cook, and others for more information.
+
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
+*/
+/***************************************************/
+
+#ifndef STK_JETTABL_H
+#define STK_JETTABL_H
+
+#include "Function.h"
+
+class JetTable : public Function
+{
+public:
+ //! Default constructor.
+ JetTable();
+
+ //! Class destructor.
+ ~JetTable();
+
+ //! Return the function value for \e input.
+ StkFloat tick(StkFloat input);
+
+ //! Take \e vectorSize inputs from \e vector and replace them with corresponding outputs.
+ StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
+
+ //! Take a channel of the StkFrames object as inputs to the function and replace with corresponding 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:
+
+};
+
+#endif
diff --git a/include/Mandolin.h b/include/Mandolin.h
index 06f041a..f628612 100644
--- a/include/Mandolin.h
+++ b/include/Mandolin.h
@@ -23,12 +23,12 @@
- String Detuning = 1
- Microphone Position = 128
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__MANDOLIN_H)
-#define __MANDOLIN_H
+#ifndef STK_MANDOLIN_H
+#define STK_MANDOLIN_H
#include "PluckTwo.h"
#include "WvIn.h"
@@ -37,35 +37,46 @@ class Mandolin : public PluckTwo
{
public:
//! Class constructor, taking the lowest desired playing frequency.
- Mandolin(MY_FLOAT lowestFrequency);
+ Mandolin(StkFloat lowestFrequency);
//! Class destructor.
- virtual ~Mandolin();
+ ~Mandolin();
//! Pluck the strings with the given amplitude (0.0 - 1.0) using the current frequency.
- void pluck(MY_FLOAT amplitude);
+ void pluck(StkFloat amplitude);
//! Pluck the strings with the given amplitude (0.0 - 1.0) and position (0.0 - 1.0).
- void pluck(MY_FLOAT amplitude,MY_FLOAT position);
+ void pluck(StkFloat amplitude,StkFloat position);
//! Start a note with the given frequency and amplitude (0.0 - 1.0).
- virtual void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, StkFloat amplitude);
//! Set the body size (a value of 1.0 produces the "default" size).
- void setBodySize(MY_FLOAT size);
+ void setBodySize(StkFloat size);
//! Compute one output sample.
- virtual 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- virtual void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
protected:
- WvIn *soundfile[12];
- MY_FLOAT directBody;
- int mic;
- long dampTime;
- bool waveDone;
+ WvIn *soundfile_[12];
+ int mic_;
+ long dampTime_;
+ bool waveDone_;
};
#endif
diff --git a/include/Mesh2D.h b/include/Mesh2D.h
index 1237b48..43ac3b1 100644
--- a/include/Mesh2D.h
+++ b/include/Mesh2D.h
@@ -24,14 +24,14 @@
*/
/***************************************************/
-#if !defined(__MESH2D_H)
-#define __MESH2D_H
+#ifndef STK_MESH2D_H
+#define STK_MESH2D_H
#include "Instrmnt.h"
#include "OnePole.h"
-#define NXMAX ((short)(12))
-#define NYMAX ((short)(12))
+const short NXMAX = 12;
+const short NYMAX = 12;
class Mesh2D : public Instrmnt
{
@@ -52,54 +52,64 @@ class Mesh2D : public Instrmnt
void setNY(short lenY);
//! Set the x, y input position on a 0.0 - 1.0 scale.
- void setInputPosition(MY_FLOAT xFactor, MY_FLOAT yFactor);
+ void setInputPosition(StkFloat xFactor, StkFloat yFactor);
//! Set the loss filters gains (0.0 - 1.0).
- void setDecay(MY_FLOAT decayFactor);
+ void setDecay(StkFloat decayFactor);
//! Impulse the mesh with the given amplitude (frequency ignored).
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, StkFloat amplitude);
//! Stop a note with the given amplitude (speed of decay) ... currently ignored.
- void noteOff(MY_FLOAT amplitude);
+ void noteOff(StkFloat amplitude);
//! Calculate and return the signal energy stored in the mesh.
- MY_FLOAT energy();
+ StkFloat energy();
//! Compute one output sample, without adding energy to the mesh.
- MY_FLOAT tick();
+ StkFloat tick();
//! Input a sample to the mesh and compute one output sample.
- MY_FLOAT tick(MY_FLOAT input);
+ StkFloat tick(StkFloat input);
+
+ //! 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
protected:
- MY_FLOAT tick0();
- MY_FLOAT tick1();
+ StkFloat tick0();
+ StkFloat tick1();
void clearMesh();
- short NX, NY;
- short xInput, yInput;
- OnePole *filterX[NXMAX];
- OnePole *filterY[NYMAX];
- MY_FLOAT v[NXMAX-1][NYMAX-1]; // junction velocities
- MY_FLOAT vxp[NXMAX][NYMAX]; // positive-x velocity wave
- MY_FLOAT vxm[NXMAX][NYMAX]; // negative-x velocity wave
- MY_FLOAT vyp[NXMAX][NYMAX]; // positive-y velocity wave
- MY_FLOAT vym[NXMAX][NYMAX]; // negative-y velocity wave
+ short NX_, NY_;
+ short xInput_, yInput_;
+ OnePole filterX_[NXMAX];
+ OnePole filterY_[NYMAX];
+ StkFloat v_[NXMAX-1][NYMAX-1]; // junction velocities
+ StkFloat vxp_[NXMAX][NYMAX]; // positive-x velocity wave
+ StkFloat vxm_[NXMAX][NYMAX]; // negative-x velocity wave
+ StkFloat vyp_[NXMAX][NYMAX]; // positive-y velocity wave
+ StkFloat vym_[NXMAX][NYMAX]; // negative-y velocity wave
// Alternate buffers
- MY_FLOAT vxp1[NXMAX][NYMAX]; // positive-x velocity wave
- MY_FLOAT vxm1[NXMAX][NYMAX]; // negative-x velocity wave
- MY_FLOAT vyp1[NXMAX][NYMAX]; // positive-y velocity wave
- MY_FLOAT vym1[NXMAX][NYMAX]; // negative-y velocity wave
-
- int counter; // time in samples
-
+ StkFloat vxp1_[NXMAX][NYMAX]; // positive-x velocity wave
+ StkFloat vxm1_[NXMAX][NYMAX]; // negative-x velocity wave
+ StkFloat vyp1_[NXMAX][NYMAX]; // positive-y velocity wave
+ StkFloat vym1_[NXMAX][NYMAX]; // negative-y velocity wave
+ int counter_; // time in samples
};
#endif
diff --git a/include/Messager.h b/include/Messager.h
index c71429c..8d37b5b 100644
--- a/include/Messager.h
+++ b/include/Messager.h
@@ -2,146 +2,165 @@
/*! \class Messager
\brief STK input control message parser.
- This class reads and parses control messages
- from a variety of sources, such as a MIDI
- port, scorefile, socket connection, or pipe.
- MIDI messages are retrieved using the RtMidi
- class. All other input sources (scorefile,
- socket, or pipe) are assumed to provide SKINI
- formatted messages.
+ This class reads and parses control messages from a variety of
+ sources, such as a scorefile, MIDI port, socket connection, or
+ stdin. MIDI messages are retrieved using the RtMidi class. All
+ other input sources (scorefile, socket, or stdin) are assumed to
+ provide SKINI formatted messages. This class can be compiled with
+ generic, non-realtime support, in which case only scorefile
+ reading is possible.
- For each call to nextMessage(), the active
- input sources are queried to see if a new
- control message is available.
+ The various \e realtime message acquisition mechanisms (from MIDI,
+ socket, or stdin) take place asynchronously, filling the message
+ queue. A call to popMessage() will pop the next available control
+ message from the queue and return it via the referenced Message
+ structure. When a \e non-realtime scorefile is set, it is not
+ possible to start reading realtime input messages (from MIDI,
+ socket, or stdin). Likewise, it is not possible to read from a
+ scorefile when a realtime input mechanism is running.
- This class is primarily for use in STK main()
- event loops.
+ When MIDI input is started, input is also automatically read from
+ stdin. This allows for program termination via the terminal
+ window. An __SK_Exit_ message is pushed onto the stack whenever
+ an "exit" or "Exit" message is received from stdin or when all
+ socket connections close and no stdin thread is running.
- One of the original goals in creating this
- class was to simplify the message acquisition
- process by removing all threads. If the
- windoze select() function behaved just like
- the unix one, that would have been possible.
- Since it does not (it can't be used to poll
- STDIN), I am using a thread to acquire
- messages from STDIN, which sends these
- messages via a socket connection to the
- message socket server. Perhaps in the future,
- it will be possible to simplify things.
+ This class is primarily for use in STK example programs but it is
+ generic enough to work in many other contexts.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__MESSAGER_H)
-#define __MESSSAGER_H
+#ifndef STK_MESSAGER_H
+#define STK_MESSAGER_H
#include "Stk.h"
-#include "SKINI.h"
+#include "Skini.h"
+#include
-#define MESSAGE_LENGTH 128
-#define MAX_MESSAGES 25
-#define STK_MIDI 0x0001
-#define STK_PIPE 0x0002
-#define STK_SOCKET 0x0004
+const int DEFAULT_QUEUE_LIMIT = 200;
#if defined(__STK_REALTIME__)
+#include "Mutex.h"
#include "Thread.h"
#include "Socket.h"
#include "RtMidi.h"
extern "C" THREAD_RETURN THREAD_TYPE stdinHandler(void * ptr);
-#if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__))
- #include
- #include
-#endif
+extern "C" THREAD_RETURN THREAD_TYPE socketHandler(void * ptr);
#endif // __STK_REALTIME__
class Messager : public Stk
{
public:
- //! Constructor performs initialization based on an input mask and an optional socket port.
- /*!
- The default constructor is set to read input from a SKINI
- scorefile. The flags STK_MIDI, STK_PIPE, and STK_SOCKET can be
- OR'ed together in any combination for multiple "realtime" input
- source parsing. An optional socket port number can be specified
- for use when the STK_SOCKET flag is set. For realtime input
- types, an StkError can be thrown during instantiation.
- */
- Messager(int inputMask = 0, int port = 2001);
+
+ // This structure is used to share data among the various realtime
+ // messager threads. It must be public.
+ struct MessagerData {
+ Skini skini;
+ std::queue queue;
+ unsigned int queueLimit;
+ int sources;
+
+#if defined(__STK_REALTIME__)
+ Mutex mutex;
+ RtMidiIn *midi;
+ Socket *socket;
+ std::vector fd;
+ fd_set mask;
+#endif
+
+ // Default constructor.
+ MessagerData()
+ :queueLimit(0), sources(0) {}
+ };
+
+ //! Default constructor.
+ Messager();
//! Class destructor.
~Messager();
- //! Check for a new input message and return the message type.
+ //! Pop the next message from the queue and write it to the referenced message structure.
/*!
- Return type values greater than zero represent valid messages.
- If an input scorefile has been completely read or all realtime
- input sources have closed, a negative value is returned. If the
- return type is zero, no valid messages are present.
+ Invalid messages (or an empty queue) are indicated by type
+ values of zero, in which case all other message structure values
+ are undefined. The user MUST verify the returned message type is
+ valid before reading other message values.
*/
- long nextMessage(void);
+ void popMessage( Skini::Message& message );
- //! Set the delta time (in samples) returned between valid realtime messages. This setting has no affect for scorefile messages.
- void setRtDelta(long nSamples);
+ //! Push the referenced message onto the message stack.
+ void pushMessage( Skini::Message& message );
- //! Return the current message "delta time" in samples.
- long getDelta(void) const;
+ //! Specify a SKINI formatted scorefile from which messages should be read.
+ /*!
+ A return value of \c true indicates the call was successful. A
+ return value of \c false can occur if the file is not found,
+ cannot be opened, another file is currently still open, or if a
+ realtime input mechanism is running. Scorefile input is
+ considered to be a non-realtime control mechanism that cannot run
+ concurrently with realtime input.
+ */
+ bool setScoreFile( const char* filename );
- //! Return the current message type.
- long getType() const;
+#if defined(__STK_REALTIME__)
+ //! Initiate the "realtime" retreival from stdin of control messages into the queue.
+ /*!
+ This function initiates a thread for asynchronous retrieval of
+ SKINI formatted messages from stdin. A return value of \c true
+ indicates the call was successful. A return value of \c false can
+ occur if a scorefile is being read, a stdin thread is already
+ running, or a thread error occurs during startup. Stdin input is
+ considered to be a realtime control mechanism that cannot run
+ concurrently with non-realtime scorefile input.
+ */
+ bool startStdInput();
- //! Return the byte two value for the current message.
- MY_FLOAT getByteTwo() const;
+ //! Start a socket server, accept connections, and read "realtime" control messages into the message queue.
+ /*!
+ This function creates a socket server on the optional port
+ (default = 2001) and starts a thread for asynchronous retrieval of
+ SKINI formatted messages from socket connections. A return value
+ of \c true indicates the call was successful. A return value of
+ \c false can occur if a scorefile is being read, a socket thread
+ is already running, or an error occurs during the socket server
+ or thread initialization stages. Socket input is considered to be
+ a realtime control mechanism that cannot run concurrently with
+ non-realtime scorefile input.
+ */
+ bool startSocketInput( int port=2001 );
- //! Return the byte three value for the current message.
- MY_FLOAT getByteThree() const;
+ //! Start MIDI input, with optional device and port identifiers.
+ /*!
+ This function creates an RtMidiIn instance for MIDI input. The
+ RtMidiIn class invokes a local callback function to read incoming
+ messages into the queue. If \c port = -1, RtMidiIn will open a
+ virtual port to which other software applications can connect (OS
+ X and Linux only). A return value of \c true indicates the call
+ was successful. A return value of \c false can occur if a
+ scorefile is being read, MIDI input is already running, or an
+ error occurs during RtMidiIn construction. Midi input is
+ considered to be a realtime control mechanism that cannot run
+ concurrently with non-realtime scorefile input.
+ */
+ bool startMidiInput( int port=0 );
- //! Return the channel number for the current message.
- long getChannel() const;
+#endif
protected:
- SKINI *skini;
- long type;
- long channel;
- MY_FLOAT byte2;
- MY_FLOAT byte3;
- int sources;
- long delta;
- long rtDelta;
- char message[MAX_MESSAGES][MESSAGE_LENGTH];
- unsigned int messageIndex;
- int nMessages;
+ MessagerData data_;
#if defined(__STK_REALTIME__)
-
- // Check MIDI source for new messages.
- bool midiMessage(void);
-
- // Check socket sources for new messages.
- bool socketMessage(void);
-
- // Receive and parse socket data.
- bool readSocket(int fd);
-
- RtMidi *midi;
- Thread *thread;
- Socket *soket;
-
- unsigned int nSockets;
- fd_set mask;
- int maxfd;
- int pipefd;
- int fd[16];
- char error[256];
-
-#endif // __STK_REALTIME__
+ Thread stdinThread_;
+ Thread socketThread_;
+#endif
};
-#endif // defined(__MESSAGER_H)
+#endif
diff --git a/include/MidiFileIn.h b/include/MidiFileIn.h
new file mode 100644
index 0000000..b687b65
--- /dev/null
+++ b/include/MidiFileIn.h
@@ -0,0 +1,131 @@
+/**********************************************************************/
+/*! \class MidiFileIn
+ \brief A standard MIDI file reading/parsing class.
+
+ This class can be used to read events from a standard MIDI file.
+ Event bytes are copied to a C++ vector and must be subsequently
+ interpreted by the user. The function getNextMidiEvent() skips
+ meta and sysex events, returning only MIDI channel messages.
+ Event delta-times are returned in the form of "ticks" and a
+ function is provided to determine the current "seconds per tick".
+ Tempo changes are internally tracked by the class and reflected in
+ the values returned by the function getTickSeconds().
+
+ by Gary P. Scavone, 2003.
+*/
+/**********************************************************************/
+
+#ifndef STK_MIDIFILEIN_H
+#define STK_MIDIFILEIN_H
+
+#include "Stk.h"
+#include
+#include
+#include
+#include
+
+class MidiFileIn : public Stk
+{
+ public:
+ //! Default constructor.
+ /*!
+ If an error occurs while opening or parsing the file header, an
+ StkError exception will be thrown.
+ */
+ MidiFileIn( std::string fileName );
+
+ //! Class destructor.
+ ~MidiFileIn();
+
+ //! Return the MIDI file format (0, 1, or 2).
+ int getFileFormat() const;
+
+ //! Return the number of tracks in the MIDI file.
+ unsigned int getNumberOfTracks() const;
+
+ //! Return the MIDI file division value from the file header.
+ /*!
+ Note that this value must be "parsed" in accordance with the
+ MIDI File Specification. In particular, if the MSB is set, the
+ file uses time-code representations for delta-time values.
+ */
+ int getDivision() const;
+
+ //! Move the specified track event reader to the beginning of its track.
+ /*!
+ The relevant track tempo value is reset as well. If an invalid
+ track number is specified, an StkError exception will be thrown.
+ */
+ void rewindTrack( unsigned int track = 0 );
+
+ //! Get the current value, in seconds, of delta-time ticks for the specified track.
+ /*!
+ This value can change as events are read (via "Set Tempo"
+ Meta-Events). Therefore, one should call this function after
+ every call to getNextEvent() or getNextMidiEvent(). If an
+ invalid track number is specified, an StkError exception will be
+ thrown.
+ */
+ double getTickSeconds( unsigned int track = 0 );
+
+ //! Fill the user-provided vector with the next event in the specified track and return the event delta-time in ticks.
+ /*!
+ MIDI File events consist of a delta time and a sequence of event
+ bytes. This function returns the delta-time value and writes
+ the subsequent event bytes directly to the event vector. The
+ user must parse the event bytes in accordance with the MIDI File
+ Specification. All returned MIDI channel events are complete
+ ... a status byte is provided even when running status is used
+ in the file. If the track has reached its end, no bytes will be
+ written and the event vector size will be zero. If an invalid
+ track number is specified or an error occurs while reading the
+ file, an StkError exception will be thrown.
+ */
+ unsigned long getNextEvent( std::vector *event, unsigned int track = 0 );
+
+ //! Fill the user-provided vector with the next MIDI channel event in the specified track and return the event delta time in ticks.
+ /*!
+ All returned MIDI events are complete ... a status byte is
+ provided even when running status is used in the file. Meta and
+ sysex events in the track are skipped though "Set Tempo" events
+ are properly parsed for use by the getTickSeconds() function.
+ If the track has reached its end, no bytes will be written and
+ the event vector size will be zero. If an invalid track number
+ is specified or an error occurs while reading the file, an
+ StkError exception will be thrown.
+ */
+ unsigned long getNextMidiEvent( std::vector *midiEvent, unsigned int track = 0 );
+
+ protected:
+
+ // This protected class function is used for reading variable-length
+ // MIDI file values. It is assumed that this function is called with
+ // the file read pointer positioned at the start of a
+ // variable-length value. The function returns true if the value is
+ // successfully parsed. Otherwise, it returns false.
+ bool readVariableLength( unsigned long *value );
+
+ std::ifstream file_;
+ unsigned int nTracks_;
+ int format_;
+ int division_;
+ bool usingTimeCode_;
+ std::vector tickSeconds_;
+ std::vector trackPointers_;
+ std::vector trackOffsets_;
+ std::vector trackLengths_;
+ std::vector trackStatus_;
+
+ // This structure and the following variables are used to save and
+ // keep track of a format 1 tempo map (and the initial tickSeconds
+ // parameter for formats 0 and 2).
+ struct TempoChange {
+ unsigned long count;
+ double tickSeconds;
+ };
+ std::vector tempoEvents_;
+ std::vector trackCounters_;
+ std::vector trackTempoIndex_;
+};
+
+#endif
diff --git a/include/Modal.h b/include/Modal.h
index cca8e78..413ed58 100644
--- a/include/Modal.h
+++ b/include/Modal.h
@@ -7,12 +7,12 @@
(non-sweeping BiQuad filters), where N is set
during instantiation.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__MODAL_H)
-#define __MODAL_H
+#ifndef STK_MODAL_H
+#define STK_MODAL_H
#include "Instrmnt.h"
#include "Envelope.h"
@@ -24,7 +24,10 @@ class Modal : public Instrmnt
{
public:
//! Class constructor, taking the desired number of modes to create.
- Modal( int modes = 4 );
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
+ Modal( unsigned int modes = 4 );
//! Class destructor.
virtual ~Modal();
@@ -33,54 +36,67 @@ public:
void clear();
//! Set instrument parameters for a particular frequency.
- virtual void setFrequency(MY_FLOAT frequency);
+ virtual void setFrequency(StkFloat frequency);
//! Set the ratio and radius for a specified mode filter.
- void setRatioAndRadius(int modeIndex, MY_FLOAT ratio, MY_FLOAT radius);
+ void setRatioAndRadius(unsigned int modeIndex, StkFloat ratio, StkFloat radius);
//! Set the master gain.
- void setMasterGain(MY_FLOAT aGain);
+ void setMasterGain(StkFloat aGain);
//! Set the direct gain.
- void setDirectGain(MY_FLOAT aGain);
+ void setDirectGain(StkFloat aGain);
//! Set the gain for a specified mode filter.
- void setModeGain(int modeIndex, MY_FLOAT gain);
+ void setModeGain(unsigned int modeIndex, StkFloat gain);
//! Initiate a strike with the given amplitude (0.0 - 1.0).
- virtual void strike(MY_FLOAT amplitude);
+ virtual void strike(StkFloat amplitude);
//! Damp modes with a given decay factor (0.0 - 1.0).
- void damp(MY_FLOAT amplitude);
+ void damp(StkFloat amplitude);
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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.
- 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- virtual void controlChange(int number, MY_FLOAT value) = 0;
+ virtual void controlChange(int number, StkFloat value) = 0;
protected:
- Envelope *envelope;
- WvIn *wave;
- BiQuad **filters;
- OnePole *onepole;
- WaveLoop *vibrato;
- int nModes;
- MY_FLOAT vibratoGain;
- MY_FLOAT masterGain;
- MY_FLOAT directGain;
- MY_FLOAT stickHardness;
- MY_FLOAT strikePosition;
- MY_FLOAT baseFrequency;
- MY_FLOAT *ratios;
- MY_FLOAT *radii;
+ Envelope envelope_;
+ WvIn *wave_;
+ BiQuad **filters_;
+ OnePole onepole_;
+ WaveLoop *vibrato_;
+ unsigned int nModes_;
+ std::vector ratios_;
+ std::vector radii_;
+
+ StkFloat vibratoGain_;
+ StkFloat masterGain_;
+ StkFloat directGain_;
+ StkFloat stickHardness_;
+ StkFloat strikePosition_;
+ StkFloat baseFrequency_;
};
#endif
diff --git a/include/ModalBar.h b/include/ModalBar.h
index 343c0fe..56677fa 100644
--- a/include/ModalBar.h
+++ b/include/ModalBar.h
@@ -9,8 +9,9 @@
Control Change Numbers:
- Stick Hardness = 2
- Stick Position = 4
- - Vibrato Gain = 11
- - Vibrato Frequency = 7
+ - Vibrato Gain = 1
+ - Vibrato Frequency = 11
+ - Direct Stick Mix = 8
- Volume = 128
- Modal Presets = 16
- Marimba = 0
@@ -23,12 +24,12 @@
- Two Fixed = 7
- Clump = 8
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__MODALBAR_H)
-#define __MODALBAR_H
+#ifndef STK_MODALBAR_H
+#define STK_MODALBAR_H
#include "Modal.h"
@@ -42,19 +43,19 @@ public:
~ModalBar();
//! Set stick hardness (0.0 - 1.0).
- void setStickHardness(MY_FLOAT hardness);
+ void setStickHardness(StkFloat hardness);
//! Set stick position (0.0 - 1.0).
- void setStrikePosition(MY_FLOAT position);
+ void setStrikePosition(StkFloat position);
//! Select a bar preset (currently modulo 9).
void setPreset(int preset);
//! Set the modulation (vibrato) depth.
- void setModulationDepth(MY_FLOAT mDepth);
+ void setModulationDepth(StkFloat mDepth);
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
};
#endif
diff --git a/include/Modulate.h b/include/Modulate.h
index 11bf660..092c0a0 100644
--- a/include/Modulate.h
+++ b/include/Modulate.h
@@ -6,22 +6,25 @@
modulations to give a nice, natural human
modulation function.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__MODULATE_H)
-#define __MODULATE_H
+#ifndef STK_MODULATE_H
+#define STK_MODULATE_H
-#include "Stk.h"
+#include "Generator.h"
#include "WaveLoop.h"
#include "SubNoise.h"
#include "OnePole.h"
-class Modulate : public Stk
+class Modulate : public Generator
{
public:
//! Class constructor.
+ /*!
+ An StkError can be thrown if the rawwave path is incorrect.
+ */
Modulate();
//! Class destructor.
@@ -31,30 +34,35 @@ class Modulate : public Stk
void reset();
//! Set the periodic (vibrato) rate or frequency in Hz.
- void setVibratoRate(MY_FLOAT aRate);
+ void setVibratoRate(StkFloat rate);
//! Set the periodic (vibrato) gain.
- void setVibratoGain(MY_FLOAT aGain);
+ void setVibratoGain(StkFloat gain);
//! Set the random modulation gain.
- void setRandomGain(MY_FLOAT aGain);
+ void setRandomGain(StkFloat gain);
//! Compute one output sample.
- MY_FLOAT tick();
+ StkFloat tick();
- //! Return \e vectorSize outputs in \e vector.
- virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ //! Compute \e vectorSize outputs and return them in \e vector.
+ StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
- //! Return the last computed output value.
- MY_FLOAT lastOut() const;
+ //! 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:
- WaveLoop *vibrato;
- SubNoise *noise;
- OnePole *filter;
- MY_FLOAT vibratoGain;
- MY_FLOAT randomGain;
- MY_FLOAT lastOutput;
+ WaveLoop *vibrato_;
+ SubNoise noise_;
+ OnePole filter_;
+ StkFloat vibratoGain_;
+ StkFloat randomGain_;
};
diff --git a/include/Moog.h b/include/Moog.h
index 252b02e..e7bcbf2 100644
--- a/include/Moog.h
+++ b/include/Moog.h
@@ -14,12 +14,12 @@
- Vibrato Gain = 1
- Gain = 128
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__MOOG_H)
-#define __MOOG_H
+#ifndef STK_MOOG_H
+#define STK_MOOG_H
#include "Sampler.h"
#include "FormSwep.h"
@@ -28,34 +28,49 @@ class Moog : public Sampler
{
public:
//! Class constructor.
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
Moog();
//! Class destructor.
~Moog();
//! Set instrument parameters for a particular frequency.
- virtual void setFrequency(MY_FLOAT frequency);
+ void setFrequency(StkFloat frequency);
//! Start a note with the given frequency and amplitude.
- virtual void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, StkFloat amplitude);
//! Set the modulation (vibrato) speed in Hz.
- void setModulationSpeed(MY_FLOAT mSpeed);
+ void setModulationSpeed(StkFloat mSpeed);
//! Set the modulation (vibrato) depth.
- void setModulationDepth(MY_FLOAT mDepth);
+ void setModulationDepth(StkFloat mDepth);
//! Compute one output sample.
- virtual 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- virtual void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
protected:
- FormSwep *filters[2];
- MY_FLOAT modDepth;
- MY_FLOAT filterQ;
- MY_FLOAT filterRate;
+ FormSwep filters_[2];
+ StkFloat modDepth_;
+ StkFloat filterQ_;
+ StkFloat filterRate_;
};
diff --git a/include/Mutex.h b/include/Mutex.h
new file mode 100644
index 0000000..e072718
--- /dev/null
+++ b/include/Mutex.h
@@ -0,0 +1,70 @@
+/***************************************************/
+/*! \class Mutex
+ \brief STK mutex class.
+
+ This class provides a uniform interface for
+ cross-platform mutex use. On Linux and IRIX
+ systems, the pthread library is used. Under
+ Windows, critical sections are used.
+
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
+*/
+/***************************************************/
+
+#ifndef STK_MUTEX_H
+#define STK_MUTEX_H
+
+#include "Stk.h"
+
+#if (defined(__OS_IRIX__) || defined(__OS_LINUX__) || defined(__OS_MACOSX__))
+
+ #include
+ typedef pthread_mutex_t MUTEX;
+ typedef pthread_cond_t CONDITION;
+
+#elif defined(__OS_WINDOWS__)
+
+ #include
+ #include
+ typedef CRITICAL_SECTION MUTEX;
+ typedef HANDLE CONDITION;
+
+#endif
+
+class Mutex : public Stk
+{
+ public:
+ //! Default constructor.
+ Mutex();
+
+ //! Class destructor.
+ ~Mutex();
+
+ //! Lock the mutex.
+ void lock(void);
+
+ //! Unlock the mutex.
+ void unlock(void);
+
+ //! Wait indefinitely on the mutex condition variable.
+ /*!
+ The mutex must be locked before calling this function, and then
+ subsequently unlocked after this function returns.
+ */
+ void wait(void);
+
+ //! Signal the condition variable.
+ /*!
+ The mutex must be locked before calling this function, and then
+ subsequently unlocked after this function returns.
+ */
+ void signal(void);
+
+ protected:
+
+ MUTEX mutex_;
+ CONDITION condition_;
+
+};
+
+#endif
diff --git a/include/NRev.h b/include/NRev.h
index 0ae0ddc..731688b 100644
--- a/include/NRev.h
+++ b/include/NRev.h
@@ -12,21 +12,21 @@
filters in parallel with corresponding right
and left outputs.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__NREV_H)
-#define __NREV_H
+#ifndef STK_NREV_H
+#define STK_NREV_H
-#include "Reverb.h"
+#include "Effect.h"
#include "Delay.h"
-class NRev : public Reverb
+class NRev : public Effect
{
public:
- //! Class constructor taking a T60 decay time argument.
- NRev(MY_FLOAT T60);
+ //! Class constructor taking a T60 decay time argument (one second default value).
+ NRev( StkFloat T60 = 1.0 );
//! Class destructor.
~NRev();
@@ -34,15 +34,30 @@ class NRev : public Reverb
//! Reset and clear all internal state.
void clear();
+ //! Set the reverberation T60 decay time.
+ void setT60( StkFloat T60 );
+
//! Compute one output sample.
- MY_FLOAT tick(MY_FLOAT input);
+ StkFloat tick(StkFloat input);
+
+ //! Take \e vectorSize inputs, compute the same number of outputs and return them in \e vector.
+ StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
+
+ //! Take a channel of the StkFrames object as inputs to the effect and replace with corresponding 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:
- Delay *allpassDelays[8];
- Delay *combDelays[6];
- MY_FLOAT allpassCoefficient;
- MY_FLOAT combCoefficient[6];
- MY_FLOAT lowpassState;
+ Delay allpassDelays_[8];
+ Delay combDelays_[6];
+ StkFloat allpassCoefficient_;
+ StkFloat combCoefficient_[6];
+ StkFloat lowpassState_;
};
diff --git a/include/Noise.h b/include/Noise.h
index 326b881..881b49d 100644
--- a/include/Noise.h
+++ b/include/Noise.h
@@ -6,16 +6,16 @@
C rand() function. The quality of the rand()
function varies from one OS to another.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__NOISE_H)
-#define __NOISE_H
+#ifndef STK_NOISE_H
+#define STK_NOISE_H
-#include "Stk.h"
+#include "Generator.h"
-class Noise : public Stk
+class Noise : public Generator
{
public:
@@ -40,17 +40,21 @@ public:
void setSeed( unsigned int seed = 0 );
//! Return a random number between -1.0 and 1.0 using rand().
- virtual MY_FLOAT tick();
+ virtual StkFloat tick();
- //! Return \e vectorSize random numbers between -1.0 and 1.0 in \e vector.
- virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ //! Compute \e vectorSize outputs and return them in \e vector.
+ virtual StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
- //! Return the last computed value.
- MY_FLOAT lastOut() const;
+ //! 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:
-
- MY_FLOAT lastOutput;
+protected:
};
diff --git a/include/OnePole.h b/include/OnePole.h
index 7aa72ac..2252ca4 100644
--- a/include/OnePole.h
+++ b/include/OnePole.h
@@ -8,12 +8,12 @@
the real axis of the z-plane while maintaining
a constant peak filter gain.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__ONEPOLE_H)
-#define __ONEPOLE_H
+#ifndef STK_ONEPOLE_H
+#define STK_ONEPOLE_H
#include "Filter.h"
@@ -25,7 +25,7 @@ public:
OnePole();
//! Overloaded constructor which sets the pole position during instantiation.
- OnePole(MY_FLOAT thePole);
+ OnePole(StkFloat thePole);
//! Class destructor.
~OnePole();
@@ -34,10 +34,10 @@ public:
void clear(void);
//! Set the b[0] coefficient value.
- void setB0(MY_FLOAT b0);
+ void setB0(StkFloat b0);
//! Set the a[1] coefficient value.
- void setA1(MY_FLOAT a1);
+ void setA1(StkFloat a1);
//! Set the pole position in the z-plane.
/*!
@@ -47,26 +47,36 @@ public:
pole value produces a high-pass filter. This method does not
affect the filter \e gain value.
*/
- void setPole(MY_FLOAT thePole);
+ void setPole(StkFloat thePole);
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
- void setGain(MY_FLOAT theGain);
+ void setGain(StkFloat gain);
//! Return the current filter gain.
- MY_FLOAT getGain(void) const;
+ StkFloat getGain(void) const;
//! Return the last computed output value.
- MY_FLOAT lastOut(void) const;
+ StkFloat lastOut(void) const;
//! Input one sample to the filter and return one output.
- MY_FLOAT tick(MY_FLOAT sample);
+ StkFloat tick(StkFloat sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
+
+ //! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding 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 );
+
};
#endif
diff --git a/include/OneZero.h b/include/OneZero.h
index 0ee129f..92d69b0 100644
--- a/include/OneZero.h
+++ b/include/OneZero.h
@@ -8,12 +8,12 @@
along the real axis of the z-plane while
maintaining a constant filter gain.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__ONEZERO_H)
-#define __ONEZERO_H
+#ifndef STK_ONEZERO_H
+#define STK_ONEZERO_H
#include "Filter.h"
@@ -25,7 +25,7 @@ class OneZero : protected Filter
OneZero();
//! Overloaded constructor which sets the zero position during instantiation.
- OneZero(MY_FLOAT theZero);
+ OneZero(StkFloat theZero);
//! Class destructor.
~OneZero();
@@ -34,10 +34,10 @@ class OneZero : protected Filter
void clear(void);
//! Set the b[0] coefficient value.
- void setB0(MY_FLOAT b0);
+ void setB0(StkFloat b0);
//! Set the b[1] coefficient value.
- void setB1(MY_FLOAT b1);
+ void setB1(StkFloat b1);
//! Set the zero position in the z-plane.
/*!
@@ -47,26 +47,36 @@ class OneZero : protected Filter
negative zero value produces a low-pass filter. This method does
not affect the filter \e gain value.
*/
- void setZero(MY_FLOAT theZero);
+ void setZero(StkFloat theZero);
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
- void setGain(MY_FLOAT theGain);
+ void setGain(StkFloat gain);
//! Return the current filter gain.
- MY_FLOAT getGain(void) const;
+ StkFloat getGain(void) const;
//! Return the last computed output value.
- MY_FLOAT lastOut(void) const;
+ StkFloat lastOut(void) const;
//! Input one sample to the filter and return one output.
- MY_FLOAT tick(MY_FLOAT sample);
+ StkFloat tick(StkFloat sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
+
+ //! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding 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 );
+
};
#endif
diff --git a/include/PRCRev.h b/include/PRCRev.h
index 8e3d262..568e353 100644
--- a/include/PRCRev.h
+++ b/include/PRCRev.h
@@ -10,21 +10,21 @@
two series allpass units and two parallel comb
filters.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__PRCREV_H)
-#define __PRCREV_H
+#ifndef STK_PRCREV_H
+#define STK_PRCREV_H
-#include "Reverb.h"
+#include "Effect.h"
#include "Delay.h"
-class PRCRev : public Reverb
+class PRCRev : public Effect
{
public:
- //! Class constructor taking a T60 decay time argument.
- PRCRev(MY_FLOAT T60);
+ //! Class constructor taking a T60 decay time argument (one second default value).
+ PRCRev( StkFloat T60 = 1.0 );
//! Class destructor.
~PRCRev();
@@ -32,14 +32,29 @@ public:
//! Reset and clear all internal state.
void clear();
+ //! Set the reverberation T60 decay time.
+ void setT60( StkFloat T60 );
+
//! Compute one output sample.
- MY_FLOAT tick(MY_FLOAT input);
+ StkFloat tick(StkFloat input);
+
+ //! Take \e vectorSize inputs, compute the same number of outputs and return them in \e vector.
+ StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
+
+ //! Take a channel of the StkFrames object as inputs to the effect and replace with corresponding 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:
- Delay *allpassDelays[2];
- Delay *combDelays[2];
- MY_FLOAT allpassCoefficient;
- MY_FLOAT combCoefficient[2];
+ Delay allpassDelays_[2];
+ Delay combDelays_[2];
+ StkFloat allpassCoefficient_;
+ StkFloat combCoefficient_[2];
};
diff --git a/include/PercFlut.h b/include/PercFlut.h
index 204eaf7..7eb0ccb 100644
--- a/include/PercFlut.h
+++ b/include/PercFlut.h
@@ -22,12 +22,12 @@
type who should worry about this (making
money) worry away.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__PERCFLUT_H)
-#define __PERCFLUT_H
+#ifndef STK_PERCFLUT_H
+#define STK_PERCFLUT_H
#include "FM.h"
@@ -35,19 +35,34 @@ class PercFlut : public FM
{
public:
//! Class constructor.
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
PercFlut();
//! Class destructor.
~PercFlut();
//! Set instrument parameters for a particular frequency.
- void setFrequency(MY_FLOAT frequency);
+ void setFrequency(StkFloat frequency);
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
};
#endif
diff --git a/include/Phonemes.h b/include/Phonemes.h
index 63d8bde..0dd0463 100644
--- a/include/Phonemes.h
+++ b/include/Phonemes.h
@@ -6,16 +6,16 @@
set of 32 static phoneme formant parameters
and provide access to those values.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__PHONEMES_H)
-#define __PHONEMES_H
+#ifndef STK_PHONEMES_H
+#define STK_PHONEMES_H
#include "Stk.h"
-class Phonemes
+class Phonemes : public Stk
{
public:
@@ -26,26 +26,25 @@ public:
static const char *name( unsigned int index );
//! Returns the voiced component gain for the given phoneme index (0-31).
- static MY_FLOAT voiceGain( unsigned int index );
+ static StkFloat voiceGain( unsigned int index );
//! Returns the unvoiced component gain for the given phoneme index (0-31).
- static MY_FLOAT noiseGain( unsigned int index );
+ static StkFloat noiseGain( unsigned int index );
//! Returns the formant frequency for the given phoneme index (0-31) and partial (0-3).
- static MY_FLOAT formantFrequency( unsigned int index, unsigned int partial );
+ static StkFloat formantFrequency( unsigned int index, unsigned int partial );
//! Returns the formant radius for the given phoneme index (0-31) and partial (0-3).
- static MY_FLOAT formantRadius( unsigned int index, unsigned int partial );
+ static StkFloat formantRadius( unsigned int index, unsigned int partial );
//! Returns the formant gain for the given phoneme index (0-31) and partial (0-3).
- static MY_FLOAT formantGain( unsigned int index, unsigned int partial );
+ static StkFloat formantGain( unsigned int index, unsigned int partial );
private:
static const char phonemeNames[][4];
- static const MY_FLOAT phonemeGains[][2];
- static const MY_FLOAT phonemeParameters[][4][3];
-
+ static const StkFloat phonemeGains[][2];
+ static const StkFloat phonemeParameters[][4][3];
};
#endif
diff --git a/include/PitShift.h b/include/PitShift.h
index 6cf8ad4..78bd410 100644
--- a/include/PitShift.h
+++ b/include/PitShift.h
@@ -5,17 +5,17 @@
This class implements a simple pitch shifter
using delay lines.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__PITSHIFT_H)
-#define __PITSHIFT_H
+#ifndef STK_PITSHIFT_H
+#define STK_PITSHIFT_H
-#include "Stk.h"
+#include "Effect.h"
#include "DelayL.h"
-class PitShift : public Stk
+class PitShift : public Effect
{
public:
//! Class constructor.
@@ -28,27 +28,30 @@ class PitShift : public Stk
void clear();
//! Set the pitch shift factor (1.0 produces no shift).
- void setShift(MY_FLOAT shift);
-
- //! Set the mixture of input and processed levels in the output (0.0 = input only, 1.0 = processed only).
- void setEffectMix(MY_FLOAT mix);
-
- //! Return the last output value.
- MY_FLOAT lastOut() const;
+ void setShift(StkFloat shift);
//! Compute one output sample.
- MY_FLOAT tick(MY_FLOAT input);
+ StkFloat tick(StkFloat input);
- //! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ //! Take \e vectorSize inputs, compute the same number of outputs and return them in \e vector.
+ StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
+
+ //! Take a channel of the StkFrames object as inputs to the effect and replace with corresponding 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:
- DelayL *delayLine[2];
- MY_FLOAT lastOutput;
- MY_FLOAT delay[2];
- MY_FLOAT env[2];
- MY_FLOAT effectMix;
- MY_FLOAT rate;
+ DelayL delayLine_[2];
+ StkFloat delay_[2];
+ StkFloat env_[2];
+ StkFloat rate_;
+ unsigned long delayLength;
+ unsigned long halfLength;
};
diff --git a/include/PluckTwo.h b/include/PluckTwo.h
index 4e7a2b4..49fc955 100644
--- a/include/PluckTwo.h
+++ b/include/PluckTwo.h
@@ -14,12 +14,12 @@
use possibly subject to patents held by
Stanford University, Yamaha, and others.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__PLUCKTWO_H)
-#define __PLUCKTWO_H
+#ifndef STK_PLUCKTWO_H
+#define STK_PLUCKTWO_H
#include "Instrmnt.h"
#include "DelayL.h"
@@ -30,7 +30,7 @@ class PluckTwo : public Instrmnt
{
public:
//! Class constructor, taking the lowest desired playing frequency.
- PluckTwo(MY_FLOAT lowestFrequency);
+ PluckTwo(StkFloat lowestFrequency);
//! Class destructor.
virtual ~PluckTwo();
@@ -39,16 +39,16 @@ class PluckTwo : public Instrmnt
void clear();
//! Set instrument parameters for a particular frequency.
- virtual void setFrequency(MY_FLOAT frequency);
+ virtual void setFrequency(StkFloat frequency);
//! Detune the two strings by the given factor. A value of 1.0 produces unison strings.
- void setDetune(MY_FLOAT detune);
+ void setDetune(StkFloat detune);
//! Efficient combined setting of frequency and detuning.
- void setFreqAndDetune(MY_FLOAT frequency, MY_FLOAT detune);
+ void setFreqAndDetune(StkFloat frequency, StkFloat detune);
//! Set the pluck or "excitation" position along the string (0.0 - 1.0).
- void setPluckPosition(MY_FLOAT position);
+ void setPluckPosition(StkFloat position);
//! Set the base loop gain.
/*!
@@ -56,28 +56,41 @@ class PluckTwo : public Instrmnt
Because of high-frequency loop filter roll-off, higher
frequency settings have greater loop gains.
*/
- void setBaseLoopGain(MY_FLOAT aGain);
+ void setBaseLoopGain(StkFloat aGain);
//! Stop a note with the given amplitude (speed of decay).
- virtual void noteOff(MY_FLOAT amplitude);
+ virtual void noteOff(StkFloat amplitude);
//! Virtual (abstract) tick function is implemented by subclasses.
- virtual MY_FLOAT tick() = 0;
+ virtual StkFloat tick() = 0;
- protected:
- DelayA *delayLine;
- DelayA *delayLine2;
- DelayL *combDelay;
- OneZero *filter;
- OneZero *filter2;
- long length;
- MY_FLOAT loopGain;
- MY_FLOAT baseLoopGain;
- MY_FLOAT lastFrequency;
- MY_FLOAT lastLength;
- MY_FLOAT detuning;
- MY_FLOAT pluckAmplitude;
- MY_FLOAT pluckPosition;
+ //! Computer \e vectorSize outputs and return them in \e vector.
+ virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize) = 0;
+
+ //! 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 ) = 0;
+
+ protected:
+ DelayA delayLine_;
+ DelayA delayLine2_;
+ DelayL combDelay_;
+ OneZero filter_;
+ OneZero filter2_;
+
+ unsigned long length_;
+ StkFloat loopGain_;
+ StkFloat baseLoopGain_;
+ StkFloat lastFrequency_;
+ StkFloat lastLength_;
+ StkFloat detuning_;
+ StkFloat pluckAmplitude_;
+ StkFloat pluckPosition_;
};
diff --git a/include/Plucked.h b/include/Plucked.h
index 57e6af1..57290db 100644
--- a/include/Plucked.h
+++ b/include/Plucked.h
@@ -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(__PLUCKED_H)
-#define __PLUCKED_H
+#ifndef STK_PLUCKED_H
+#define STK_PLUCKED_H
#include "Instrmnt.h"
#include "DelayA.h"
@@ -30,7 +30,7 @@ class Plucked : public Instrmnt
{
public:
//! Class constructor, taking the lowest desired playing frequency.
- Plucked(MY_FLOAT lowestFrequency);
+ Plucked(StkFloat lowestFrequency);
//! Class destructor.
~Plucked();
@@ -39,27 +39,39 @@ class Plucked : 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;
- OnePole *pickFilter;
- Noise *noise;
- long length;
- MY_FLOAT loopGain;
+ DelayA delayLine_;
+ OneZero loopFilter_;
+ OnePole pickFilter_;
+ Noise noise_;
+ StkFloat loopGain_;
+ unsigned long length_;
};
diff --git a/include/PoleZero.h b/include/PoleZero.h
index e3e0593..ba35e6d 100644
--- a/include/PoleZero.h
+++ b/include/PoleZero.h
@@ -8,12 +8,12 @@
filter with a given coefficient. Another
method is provided to create a DC blocking filter.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__POLEZERO_H)
-#define __POLEZERO_H
+#ifndef STK_POLEZERO_H
+#define STK_POLEZERO_H
#include "Filter.h"
@@ -31,13 +31,13 @@ class PoleZero : protected Filter
void clear(void);
//! Set the b[0] coefficient value.
- void setB0(MY_FLOAT b0);
+ void setB0(StkFloat b0);
//! Set the b[1] coefficient value.
- void setB1(MY_FLOAT b1);
+ void setB1(StkFloat b1);
//! Set the a[1] coefficient value.
- void setA1(MY_FLOAT a1);
+ void setA1(StkFloat a1);
//! Set the filter for allpass behavior using \e coefficient.
/*!
@@ -45,7 +45,7 @@ class PoleZero : protected Filter
which has unity gain at all frequencies. Note that the \e
coefficient magnitude must be less than one to maintain stability.
*/
- void setAllpass(MY_FLOAT coefficient);
+ void setAllpass(StkFloat coefficient);
//! Create a DC blocking filter with the given pole position in the z-plane.
/*!
@@ -54,26 +54,36 @@ class PoleZero : protected Filter
close to one to minimize low-frequency attenuation.
*/
- void setBlockZero(MY_FLOAT thePole = 0.99);
+ void setBlockZero(StkFloat thePole = 0.99);
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
- void setGain(MY_FLOAT theGain);
+ void setGain(StkFloat gain);
//! Return the current filter gain.
- MY_FLOAT getGain(void) const;
+ StkFloat getGain(void) const;
//! Return the last computed output value.
- MY_FLOAT lastOut(void) const;
+ StkFloat lastOut(void) const;
//! Input one sample to the filter and return one output.
- MY_FLOAT tick(MY_FLOAT sample);
+ StkFloat tick(StkFloat sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
+
+ //! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding 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 );
+
};
#endif
diff --git a/include/ReedTabl.h b/include/ReedTable.h
similarity index 55%
rename from include/ReedTabl.h
rename to include/ReedTable.h
index e6f97a5..c090bd3 100644
--- a/include/ReedTabl.h
+++ b/include/ReedTable.h
@@ -1,5 +1,5 @@
/***************************************************/
-/*! \class ReedTabl
+/*! \class ReedTable
\brief STK reed table class.
This class implements a simple one breakpoint,
@@ -13,23 +13,23 @@
Smith (1986), Hirschman, Cook, Scavone, and
others for more information.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__REEDTABL_H)
-#define __REEDTABL_H
+#ifndef STK_REEDTABLE_H
+#define STK_REEDTABLE_H
-#include "Stk.h"
+#include "Function.h"
-class ReedTabl : public Stk
+class ReedTable : public Function
{
public:
//! Default constructor.
- ReedTabl();
+ ReedTable();
//! Class destructor.
- ~ReedTabl();
+ ~ReedTable();
//! Set the table offset value.
/*!
@@ -37,7 +37,7 @@ public:
of the initial reed tip opening (a greater offset
represents a smaller opening).
*/
- void setOffset(MY_FLOAT aValue);
+ void setOffset(StkFloat offset);
//! Set the table slope value.
/*!
@@ -45,25 +45,30 @@ public:
stiffness (a greater slope represents a harder
reed).
*/
- void setSlope(MY_FLOAT aValue);
-
- //! Return the last output value.
- MY_FLOAT lastOut() const;
+ void setSlope(StkFloat slope);
//! Return the function value for \e input.
/*!
The function input represents the differential
pressure across the reeds.
*/
- MY_FLOAT tick(MY_FLOAT input);
+ StkFloat tick(StkFloat input);
- //! Take \e vectorSize inputs and return the corresponding function values in \e vector.
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ //! Take \e vectorSize inputs from \e vector and replace them with corresponding outputs.
+ StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
+
+ //! Take a channel of the StkFrames object as inputs to the function and replace with corresponding 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:
- MY_FLOAT offSet;
- MY_FLOAT slope;
- MY_FLOAT lastOutput;
+ StkFloat offset_;
+ StkFloat slope_;
};
diff --git a/include/Resonate.h b/include/Resonate.h
index 6b35f2e..8922a9d 100644
--- a/include/Resonate.h
+++ b/include/Resonate.h
@@ -13,12 +13,12 @@
- Zero Radii = 1
- Envelope Gain = 128
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__RESONATE_H)
-#define __RESONATE_H
+#ifndef STK_RESONATE_H
+#define STK_RESONATE_H
#include "Instrmnt.h"
#include "ADSR.h"
@@ -38,10 +38,10 @@ class Resonate : public Instrmnt
void clear();
//! Set the filter for a resonance at the given frequency (Hz) and radius.
- void setResonance(MY_FLOAT frequency, MY_FLOAT radius);
+ void setResonance(StkFloat frequency, StkFloat radius);
//! Set the filter for a notch at the given frequency (Hz) and radius.
- void setNotch(MY_FLOAT frequency, MY_FLOAT radius);
+ void setNotch(StkFloat frequency, StkFloat radius);
//! Set the filter zero coefficients for contant resonance gain.
void setEqualGainZeroes();
@@ -53,25 +53,37 @@ class Resonate : public Instrmnt
void keyOff();
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- virtual void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
protected:
- ADSR *adsr;
- BiQuad *filter;
- Noise *noise;
- MY_FLOAT poleFrequency;
- MY_FLOAT poleRadius;
- MY_FLOAT zeroFrequency;
- MY_FLOAT zeroRadius;
+ ADSR adsr_;
+ BiQuad filter_;
+ Noise noise_;
+ StkFloat poleFrequency_;
+ StkFloat poleRadius_;
+ StkFloat zeroFrequency_;
+ StkFloat zeroRadius_;
};
diff --git a/include/Reverb.h b/include/Reverb.h
deleted file mode 100644
index 0f996d7..0000000
--- a/include/Reverb.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/***************************************************/
-/*! \class Reverb
- \brief STK abstract reverberator parent class.
-
- This class provides common functionality for
- STK reverberator subclasses.
-
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
-*/
-/***************************************************/
-
-#include "Stk.h"
-
-#if !defined(__REVERB_H)
-#define __REVERB_H
-
-class Reverb : public Stk
-{
- public:
- //! Class constructor.
- Reverb();
-
- //! Class destructor.
- virtual ~Reverb();
-
- //! Reset and clear all internal state.
- virtual void clear() = 0;
-
- //! Set the mixture of input and "reverberated" levels in the output (0.0 = input only, 1.0 = reverb only).
- void setEffectMix(MY_FLOAT mix);
-
- //! Return the last output value.
- MY_FLOAT lastOut() const;
-
- //! Return the last left output value.
- MY_FLOAT lastOutLeft() const;
-
- //! Return the last right output value.
- MY_FLOAT lastOutRight() const;
-
- //! Abstract tick function ... must be implemented in subclasses.
- virtual MY_FLOAT tick(MY_FLOAT input) = 0;
-
- //! Take \e vectorSize inputs, compute the same number of outputs and return them in \e vector.
- virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
-
- protected:
-
- // Returns true if argument value is prime.
- bool isPrime(int number);
-
- MY_FLOAT lastOutput[2];
- MY_FLOAT effectMix;
-
-};
-
-#endif // defined(__REVERB_H)
-
diff --git a/include/Rhodey.h b/include/Rhodey.h
index 1e22fb0..05f7b51 100644
--- a/include/Rhodey.h
+++ b/include/Rhodey.h
@@ -26,12 +26,12 @@
type who should worry about this (making
money) worry away.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__RHODEY_H)
-#define __RHODEY_H
+#ifndef STK_RHODEY_H
+#define STK_RHODEY_H
#include "FM.h"
@@ -39,19 +39,34 @@ class Rhodey : public FM
{
public:
//! Class constructor.
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
Rhodey();
//! Class destructor.
~Rhodey();
//! Set instrument parameters for a particular frequency.
- void setFrequency(MY_FLOAT frequency);
+ void setFrequency(StkFloat frequency);
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
};
#endif
diff --git a/include/RtAudio.h b/include/RtAudio.h
index fa2d494..98fce3e 100644
--- a/include/RtAudio.h
+++ b/include/RtAudio.h
@@ -9,7 +9,7 @@
RtAudio WWW site: http://music.mcgill.ca/~gary/rtaudio/
- RtAudio: a realtime audio i/o C++ class
+ RtAudio: realtime audio i/o C++ classes
Copyright (c) 2001-2004 Gary P. Scavone
Permission is hereby granted, free of charge, to any person
@@ -37,7 +37,7 @@
*/
/************************************************************************/
-// RtAudio: Version 3.0.1, 22 March 2004
+// RtAudio: Version 3.0.2, pre-release for STK 4.2.0
#ifndef __RTAUDIO_H
#define __RTAUDIO_H
@@ -127,17 +127,27 @@ class RtApi
{
public:
+ enum StreamState {
+ STREAM_STOPPED,
+ STREAM_RUNNING
+ };
+
RtApi();
virtual ~RtApi();
void openStream( int outputDevice, int outputChannels,
int inputDevice, int inputChannels,
RtAudioFormat format, int sampleRate,
int *bufferSize, int numberOfBuffers );
+ void openStream( int outputDevice, int outputChannels,
+ int inputDevice, int inputChannels,
+ RtAudioFormat format, int sampleRate,
+ int *bufferSize, int *numberOfBuffers );
virtual void setStreamCallback( RtAudioCallback callback, void *userData ) = 0;
virtual void cancelStreamCallback() = 0;
int getDeviceCount(void);
RtAudioDeviceInfo getDeviceInfo( int device );
char * const getStreamBuffer();
+ RtApi::StreamState getStreamState() const;
virtual void tickStream() = 0;
virtual void closeStream();
virtual void startStream() = 0;
@@ -158,9 +168,13 @@ protected:
UNINITIALIZED = -75
};
- enum StreamState {
- STREAM_STOPPED,
- STREAM_RUNNING
+ // A protected structure used for buffer conversion.
+ struct ConvertInfo {
+ int channels;
+ int inJump, outJump;
+ RtAudioFormat inFormat, outFormat;
+ std::vector inOffset;
+ std::vector outOffset;
};
// A protected structure for audio streams.
@@ -183,10 +197,10 @@ protected:
RtAudioFormat deviceFormat[2]; // Playback and record, respectively.
StreamMutex mutex;
CallbackInfo callbackInfo;
+ ConvertInfo convertInfo[2];
RtApiStream()
:apiHandle(0), userBuffer(0), deviceBuffer(0) {}
- // mode(UNINITIALIZED), state(STREAM_STOPPED),
};
// A protected device structure for audio devices.
@@ -217,7 +231,7 @@ protected:
typedef float Float32;
typedef double Float64;
- char message_[256];
+ char message_[1024];
int nDevices_;
std::vector devices_;
RtApiStream stream_;
@@ -281,7 +295,7 @@ protected:
Protected method used to perform format, channel number, and/or interleaving
conversions between the user and device buffers.
*/
- void convertStreamBuffer( StreamMode mode );
+ void convertBuffer( char *outBuffer, char *inBuffer, ConvertInfo &info );
//! Protected common method used to perform byte-swapping on buffers.
void byteSwapBuffer( char *buffer, int samples, RtAudioFormat format );
@@ -350,6 +364,20 @@ public:
RtAudioFormat format, int sampleRate,
int *bufferSize, int numberOfBuffers, RtAudioApi api=UNSPECIFIED );
+ //! An overloaded constructor which opens a stream and also returns \c numberOfBuffers parameter via pointer argument.
+ /*!
+ See the previous constructor call for details. This overloaded
+ version differs only in that it takes a pointer argument for the
+ \c numberOfBuffers parameter and returns the value used by the
+ audio device (which may be different from that requested). Note
+ that the \c numberofBuffers parameter is not used with the Linux
+ Jack, Macintosh CoreAudio, and Windows ASIO APIs.
+ */
+ RtAudio( int outputDevice, int outputChannels,
+ int inputDevice, int inputChannels,
+ RtAudioFormat format, int sampleRate,
+ int *bufferSize, int *numberOfBuffers, RtAudioApi api=UNSPECIFIED );
+
//! The destructor.
/*!
Stops and closes an open stream and devices and deallocates
@@ -389,6 +417,20 @@ public:
RtAudioFormat format, int sampleRate,
int *bufferSize, int numberOfBuffers );
+ //! A public method for opening a stream and also returning \c numberOfBuffers parameter via pointer argument.
+ /*!
+ See the previous function call for details. This overloaded
+ version differs only in that it takes a pointer argument for the
+ \c numberOfBuffers parameter and returns the value used by the
+ audio device (which may be different from that requested). Note
+ that the \c numberofBuffers parameter is not used with the Linux
+ Jack, Macintosh CoreAudio, and Windows ASIO APIs.
+ */
+ void openStream( int outputDevice, int outputChannels,
+ int inputDevice, int inputChannels,
+ RtAudioFormat format, int sampleRate,
+ int *bufferSize, int *numberOfBuffers );
+
//! A public method which sets a user-defined callback function for a given stream.
/*!
This method assigns a callback function to a previously opened
diff --git a/include/RtDuplex.h b/include/RtDuplex.h
index 1dd3fe8..c43a790 100644
--- a/include/RtDuplex.h
+++ b/include/RtDuplex.h
@@ -1,28 +1,35 @@
/***************************************************/
/*! \class RtDuplex
- \brief STK realtime audio input/output class.
+ \brief STK realtime audio (blocking) input/output class.
This class provides a simplified interface to
RtAudio for realtime audio input/output. It
- is also possible to achieve duplex operation
- using separate RtWvIn and RtWvOut classes, but
- this class ensures better input/output
- syncronization.
+ may also be possible to achieve duplex
+ operation using separate RtWvIn and RtWvOut
+ classes, but this class ensures better
+ input/output synchronization.
+
+ Because this class makes use of RtAudio's
+ blocking input/output routines, its
+ performance is less robust on systems where
+ the audio API is callback-based (Macintosh
+ CoreAudio and Windows ASIO).
RtDuplex supports multi-channel data in
interleaved format. It is important to
distinguish the tick() methods, which output
- single samples to all channels in a sample frame
- and return samples produced by averaging across
- sample frames, from the tickFrame() methods, which
- take/return pointers to multi-channel sample frames.
+ single samples to all channels in a sample
+ frame and return samples produced by averaging
+ across sample frames, from the tickFrame()
+ methods, which take/return pointers to
+ multi-channel sample frames.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__RTDUPLEX_H)
-#define __RTDUPLEX_H
+#ifndef STK_RTDUPLEX_H
+#define STK_RTDUPLEX_H
#include "Stk.h"
#include "RtAudio.h"
@@ -42,7 +49,7 @@ public:
is defined in Stk.h. An StkError will be thrown if an error
occurs duing instantiation.
*/
- RtDuplex(int nChannels = 1, MY_FLOAT sampleRate = Stk::sampleRate(), int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 2);
+ RtDuplex(int nChannels = 1, StkFloat sampleRate = Stk::sampleRate(), int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 2);
//! Class destructor.
~RtDuplex();
@@ -60,34 +67,53 @@ public:
void stop(void);
//! Return the average across the last output sample frame.
- MY_FLOAT lastOut(void) const;
+ StkFloat lastOut(void) const;
//! Output a single sample to all channels in a sample frame and return the average across one new input sample frame of data.
/*!
An StkError will be thrown if an error occurs during input/output.
*/
- MY_FLOAT tick(const MY_FLOAT sample);
+ StkFloat tick(const StkFloat sample);
- //! Output each sample in \vector to all channels per frame and return averaged input sample frames of new data in \e vector.
+ //! Output each sample in \e vector to all channels per frame and return averaged input sample frames of new data in \e vector.
/*!
An StkError will be thrown if an error occurs during input/output.
*/
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
+
+ //! Output a channel of the StkFrames object to all channels and replace with averaged sample frames of input.
+ /*!
+ The \c channel argument should be one or greater (the first
+ channel is specified by 1). An StkError will be thrown if an
+ error occurs during input/outpu or 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 );
//! Return a pointer to the last output sample frame.
- const MY_FLOAT *lastFrame(void) const;
+ const StkFloat *lastFrame(void) const;
//! Output sample \e frames from \e frameVector and return new input frames in \e frameVector.
/*!
An StkError will be thrown if an error occurs during input/output.
*/
- MY_FLOAT *tickFrame(MY_FLOAT *frameVector, unsigned int frames = 1);
+ StkFloat *tickFrame(StkFloat *frameVector, unsigned int frames = 1);
+
+ //! Output the StkFrames data and replace with new input frames.
+ /*!
+ An StkError will be thrown if an error occurs during
+ input/output or if there is an incompatability between the number
+ of channels in the RtDuplex object and that in the StkFrames
+ object.
+ */
+ StkFrames& tickFrame( StkFrames& frames );
protected:
RtAudio *audio_;
- MY_FLOAT *data_;
- MY_FLOAT *lastOutput_;
+ StkFloat *data_;
+ StkFloat *lastOutput_;
int bufferSize_;
bool stopped_;
long counter_;
diff --git a/include/RtError.h b/include/RtError.h
index 465cd75..cb1283d 100644
--- a/include/RtError.h
+++ b/include/RtError.h
@@ -39,7 +39,7 @@ protected:
public:
//! The constructor.
- RtError(const std::string& message, Type type = RtError::UNSPECIFIED) : message_(message), type_(type){}
+ RtError(const std::string& message, Type type = RtError::UNSPECIFIED) : message_(message), type_(type) {}
//! The destructor.
virtual ~RtError(void) {};
diff --git a/include/RtMidi.h b/include/RtMidi.h
index cd52cf5..c33bd40 100644
--- a/include/RtMidi.h
+++ b/include/RtMidi.h
@@ -1,80 +1,282 @@
-/***************************************************/
+/**********************************************************************/
/*! \class RtMidi
- \brief STK realtime MIDI class.
+ \brief An abstract base class for realtime MIDI input/output.
- At the moment, this object only handles MIDI
- input, though MIDI output code can go here
- when someone decides they need it (and writes
- it).
+ This class implements some common functionality for the realtime
+ MIDI input/output subclasses RtMidiIn and RtMidiOut.
- This object opens a MIDI input device and
- parses MIDI messages into a MIDI buffer. Time
- stamp info is converted to a delta-time
- value. MIDI data is stored as MY_FLOAT to
- conform with SKINI. System exclusive messages
- are currently ignored.
+ RtMidi WWW site: http://music.mcgill.ca/~gary/rtmidi/
- An optional argument to the constructor can be
- used to specify a device or card. When no
- argument is given, a default device is opened.
- If a device argument fails, a list of available
- devices is printed to allow selection by the user.
+ RtMidi: realtime MIDI i/o C++ classes
+ Copyright (c) 2003-2004 Gary P. Scavone
- This code is based in part on work of Perry
- Cook (SGI), Paul Leonard (Linux), the
- RoseGarden team (Linux), and Bill Putnam
- (Windows).
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation files
+ (the "Software"), to deal in the Software without restriction,
+ including without limitation the rights to use, copy, modify, merge,
+ publish, distribute, sublicense, and/or sell copies of the Software,
+ and to permit persons to whom the Software is furnished to do so,
+ subject to the following conditions:
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ Any person wishing to distribute modifications to the Software is
+ requested to send the modifications to the original developer so that
+ they can be incorporated into the canonical version.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-/***************************************************/
+/**********************************************************************/
-#if !defined(__RTMIDI_H)
-#define __RTMIDI_H
+// RtMidi: Version 1.0.2, 21 September 2004
-#include "Stk.h"
+#ifndef RTMIDI_H
+#define RTMIDI_H
-class RtMidi : public Stk
+#include "RtError.h"
+#include
+
+class RtMidi
+{
+ protected:
+
+ RtMidi();
+
+ virtual ~RtMidi() {};
+
+ // A basic error reporting function for internal use in the RtMidi
+ // subclasses. The behavior of this function can be modified to
+ // suit specific needs.
+ void error( RtError::Type type );
+
+ virtual void openPort( unsigned int portNumber = 0 ) = 0;
+
+ void *apiData_;
+ bool connected_;
+ std::string errorString_;
+};
+
+/**********************************************************************/
+/*! \class RtMidiIn
+ \brief A realtime MIDI input class.
+
+ This class provides a common, platform-independent API for
+ realtime MIDI input. It allows access to a single MIDI input
+ port. Incoming MIDI messages are either saved to a queue for
+ retrieval using the getMessage() function or immediately passed to
+ a user-specified callback function. Create multiple instances of
+ this class to connect to more than one MIDI device at the same
+ time. With the OS-X and Linux ALSA MIDI APIs, it is also possible
+ to open a virtual input port to which other MIDI software clients
+ can connect.
+
+ by Gary P. Scavone, 2003-2004.
+*/
+/**********************************************************************/
+
+#include
+#include
+
+class RtMidiIn : public RtMidi
{
public:
- //! Default constructor with optional device argument.
- RtMidi(int device = 0);
- //! Class destructor.
- ~RtMidi();
+ //! User callback function type definition.
+ typedef void (*RtMidiCallback)( double timeStamp, std::vector *message, void *userData);
- //! Print out the current message values.
- void printMessage(void) const;
-
- //! Check for and parse a new MIDI message in the queue, returning its type.
+ //! Default constructor.
/*!
- If a new message is found, the return value is greater than zero.
+ An exception will be thrown if a MIDI system initialization error occurs.
*/
- int nextMessage(void);
+ RtMidiIn();
- //! Return the current message type.
- int getType() const;
+ //! If a MIDI connection is still open, it will be closed by the destructor.
+ ~RtMidiIn();
- //! Return the current message channel value.
- int getChannel() const;
+ //! Open a MIDI input connection.
+ /*!
+ An optional port number greater than 0 can be specified.
+ Otherwise, the default or first port found is opened.
+ */
+ void openPort( unsigned int portNumber = 0 );
- //! Return the current message byte two value.
- MY_FLOAT getByteTwo() const;
+ //! Create a virtual input port to allow software connections (OS X and ALSA only).
+ /*!
+ This function creates a virtual MIDI input port to which other
+ software applications can connect. This type of functionality
+ is currently only supported by the Macintosh OS-X and Linux ALSA
+ APIs (the function does nothing for the other APIs).
+ */
+ void openVirtualPort();
- //! Return the current message byte three value.
- MY_FLOAT getByteThree() const;
+ //! Set a callback function to be invoked for incoming MIDI messages.
+ /*!
+ The callback function will be called whenever an incoming MIDI
+ message is received. While not absolutely necessary, it is best
+ to set the callback function before opening a MIDI port to avoid
+ leaving some messages in the queue.
+ */
+ void setCallback( RtMidiCallback callback, void *userData = 0 );
- //! Return the current message delta time value in seconds.
- MY_FLOAT getDeltaTime() const;
+ //! Cancel use of the current callback function (if one exists).
+ /*!
+ Subsequent incoming MIDI messages will be written to the queue
+ and can be retrieved with the \e getMessage function.
+ */
+ void cancelCallback();
- protected:
- int messageType;
- int channel;
- float byteTwo;
- float byteThree;
- MY_FLOAT deltaTime;
- int readIndex;
+ //! Close an open MIDI connection (if one exists).
+ void closePort( void );
+
+ //! Return the number of available MIDI input ports.
+ unsigned int getPortCount();
+
+ //! Return a string identifier for the specified MIDI input port number.
+ /*!
+ An exception is thrown if an invalid port specifier is provided.
+ */
+ std::string getPortName( unsigned int portNumber = 0 );
+
+ //! Set the maximum number of MIDI messages to be saved in the queue.
+ /*!
+ If the queue size limit is reached, incoming messages will be
+ ignored. The default limit is 1024.
+ */
+ void setQueueSizeLimit( unsigned int queueSize );
+
+ //! Specify whether certain MIDI message types should be queued or ignored during input.
+ /*!
+ By default, MIDI timing and active sensing messages are ignored
+ during message input because of their relative high data rates.
+ MIDI sysex messages are ignored by default as well. Variable
+ values of "true" imply that the respective message type will be
+ ignored.
+ */
+ void ignoreTypes( bool midiSysex = true, bool midiTime = true, bool midiSense = true );
+
+ //! Fill the user-provided vector with the data bytes for the next available MIDI message in the input queue and return the event delta-time in seconds.
+ /*!
+ This function returns immediately whether a new message is
+ available or not. A valid message is indicated by a non-zero
+ vector size. An exception is thrown if an error occurs during
+ message retrieval or an input connection was not previously
+ established.
+ */
+ double getMessage( std::vector *message );
+
+ // A MIDI structure used internally by the class to store incoming
+ // messages. Each message represents one and only one MIDI message.
+ struct MidiMessage {
+ std::vector bytes;
+ double timeStamp;
+
+ // Default constructor.
+ MidiMessage()
+ :bytes(3), timeStamp(0.0) {}
+ };
+
+ // The RtMidiInData structure is used to pass private class data to
+ // the MIDI input handling function or thread.
+ struct RtMidiInData {
+ std::queue queue;
+ unsigned int queueLimit;
+ unsigned char ignoreFlags;
+ bool doInput;
+ bool firstMessage;
+ void *apiData;
+ bool usingCallback;
+ void *userCallback;
+ void *userData;
+
+ // Default constructor.
+ RtMidiInData()
+ : queueLimit(1024), ignoreFlags(7), doInput(false), firstMessage(true),
+ apiData(0), usingCallback(false), userCallback(0), userData(0) {}
+ };
+
+ private:
+
+ void initialize( void );
+ RtMidiInData inputData_;
};
+/**********************************************************************/
+/*! \class RtMidiOut
+ \brief A realtime MIDI output class.
+
+ This class provides a common, platform-independent API for MIDI
+ output. It allows one to probe available MIDI output ports, to
+ connect to one such port, and to send MIDI bytes immediately over
+ the connection. Create multiple instances of this class to
+ connect to more than one MIDI device at the same time.
+
+ by Gary P. Scavone, 2003-2004.
+*/
+/**********************************************************************/
+
+class RtMidiOut : public RtMidi
+{
+ public:
+
+ //! Default constructor.
+ /*!
+ An exception will be thrown if a MIDI system initialization error occurs.
+ */
+ RtMidiOut();
+
+ //! The destructor closes any open MIDI connections.
+ ~RtMidiOut();
+
+ //! Open a MIDI output connection.
+ /*!
+ An optional port number greater than 0 can be specified.
+ Otherwise, the default or first port found is opened. An
+ exception is thrown if an error occurs while attempting to make
+ the port connection.
+ */
+ void openPort( unsigned int portNumber = 0 );
+
+ //! Close an open MIDI connection (if one exists).
+ void closePort();
+
+ //! Create a virtual output port to allow software connections (OS X and ALSA only).
+ /*!
+ This function creates a virtual MIDI output port to which other
+ software applications can connect. This type of functionality
+ is currently only supported by the Macintosh OS-X and Linux ALSA
+ APIs (the function does nothing with the other APIs). An
+ exception is thrown if an error occurs while attempting to create
+ the virtual port.
+ */
+ void openVirtualPort();
+
+ //! Return the number of available MIDI output ports.
+ unsigned int getPortCount();
+
+ //! Return a string identifier for the specified MIDI port type and number.
+ /*!
+ An exception is thrown if an invalid port specifier is provided.
+ */
+ std::string getPortName( unsigned int portNumber );
+
+ //! Immediately send a single message out an open MIDI output port.
+ /*!
+ An exception is thrown if an error occurs during output or an
+ output connection was not previously established.
+ */
+ void sendMessage( std::vector *message );
+
+ private:
+
+ void initialize( void );
+};
+
#endif
diff --git a/include/RtWvIn.h b/include/RtWvIn.h
index 5fa9195..26c25a6 100644
--- a/include/RtWvIn.h
+++ b/include/RtWvIn.h
@@ -1,10 +1,14 @@
/***************************************************/
/*! \class RtWvIn
- \brief STK realtime audio input class.
+ \brief STK realtime audio (blocking) input class.
This class provides a simplified interface to
RtAudio for realtime audio input. It is a
- protected subclass of WvIn.
+ protected subclass of WvIn. Because this
+ class makes use of RtAudio's blocking output
+ routines, its performance is less robust on
+ systems where the audio API is callback-based
+ (Macintosh CoreAudio and Windows ASIO).
RtWvIn supports multi-channel data in
interleaved format. It is important to
@@ -15,14 +19,13 @@
For single-channel data, these methods return
equivalent values.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__RTWVIN_H)
-#define __RTWVIN_H
+#ifndef STK_RTWVIN_H
+#define STK_RTWVIN_H
-#include "Stk.h"
#include "WvIn.h"
#include "RtAudio.h"
@@ -41,7 +44,7 @@ public:
is defined in Stk.h. An StkError will be thrown if an error
occurs duing instantiation.
*/
- RtWvIn(int nChannels = 1, MY_FLOAT sampleRate = Stk::sampleRate(), int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 2);
+ RtWvIn(int nChannels = 1, StkFloat sampleRate = Stk::sampleRate(), int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 2);
//! Class destructor.
~RtWvIn();
@@ -59,34 +62,51 @@ public:
void stop(void);
//! Return the average across the last output sample frame.
- MY_FLOAT lastOut(void) const;
+ StkFloat lastOut(void) const;
//! Read out the average across one sample frame of data.
/*!
An StkError will be thrown if an error occurs during input.
*/
- MY_FLOAT tick(void);
+ StkFloat tick(void);
//! Read out vectorSize averaged sample frames of data in \e vector.
/*!
An StkError will be thrown if an error occurs during input.
*/
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
+
+ //! Fill a channel of the StkFrames object with averaged sample frames.
+ /*!
+ The \c channel argument should be one or greater (the first
+ channel is specified by 1). An StkError will be thrown if an
+ error occurs during input or 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 );
//! Return a pointer to the last output sample frame.
- const MY_FLOAT *lastFrame(void) const;
+ const StkFloat *lastFrame(void) const;
//! Return a pointer to the next sample frame of data.
/*!
An StkError will be thrown if an error occurs during input.
*/
- const MY_FLOAT *tickFrame(void);
+ const StkFloat *tickFrame(void);
//! Read out sample \e frames of data to \e frameVector.
/*!
An StkError will be thrown if an error occurs during input.
*/
- MY_FLOAT *tickFrame(MY_FLOAT *frameVector, unsigned int frames);
+ StkFloat *tickFrame(StkFloat *frameVector, unsigned int frames);
+
+ //! Fill the StkFrames object with sample frames of data and return the same reference.
+ /*!
+ An StkError will be thrown if an error occurs during input or
+ there is an incompatability between the number of channels in the
+ RtWvIn object and that in the StkFrames object.
+ */
+ StkFrames& tickFrame( StkFrames& frames );
protected:
diff --git a/include/RtWvOut.h b/include/RtWvOut.h
index 16e1b56..3668706 100644
--- a/include/RtWvOut.h
+++ b/include/RtWvOut.h
@@ -1,10 +1,14 @@
/***************************************************/
/*! \class RtWvOut
- \brief STK realtime audio output class.
+ \brief STK realtime audio (blocking) output class.
This class provides a simplified interface to
RtAudio for realtime audio output. It is a
- protected subclass of WvOut.
+ protected subclass of WvOut. Because this
+ class makes use of RtAudio's blocking output
+ routines, its performance is less robust on
+ systems where the audio API is callback-based
+ (Macintosh CoreAudio and Windows ASIO).
RtWvOut supports multi-channel data in
interleaved format. It is important to
@@ -14,16 +18,15 @@
takes a pointer to multi-channel sample
frame data.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__RTWVOUT_H)
-#define __RTWVOUT_H
+#ifndef STK_RTWVOUT_H
+#define STK_RTWVOUT_H
#include "WvOut.h"
#include "RtAudio.h"
-#include "Thread.h"
class RtWvOut : protected WvOut
{
@@ -41,7 +44,7 @@ class RtWvOut : protected WvOut
is defined in Stk.h. An StkError will be thrown if an error
occurs duing instantiation.
*/
- RtWvOut(unsigned int nChannels = 1, MY_FLOAT sampleRate = Stk::sampleRate(), int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 4 );
+ RtWvOut(unsigned int nChannels = 1, StkFloat sampleRate = Stk::sampleRate(), int device = 0, int bufferFrames = RT_BUFFER_SIZE, int nBuffers = 4 );
//! Class destructor.
~RtWvOut();
@@ -62,32 +65,50 @@ class RtWvOut : protected WvOut
unsigned long getFrames( void ) const;
//! Return the number of seconds of data output.
- MY_FLOAT getTime( void ) const;
+ StkFloat getTime( void ) const;
//! Output a single sample to all channels in a sample frame.
/*!
An StkError will be thrown if an error occurs during output.
*/
- void tick(const MY_FLOAT sample);
+ void tick( const StkFloat sample );
//! Output each sample in \e vector to all channels in \e vectorSize sample frames.
/*!
An StkError will be thrown if an error occurs during output.
*/
- void tick(const MY_FLOAT *vector, unsigned int vectorSize);
+ void tick( const StkFloat *vector, unsigned int vectorSize );
+
+ //! Output a channel of the StkFrames object to all channels of the RtWvOut object.
+ /*!
+ The \c channel argument should be one or greater (the first
+ channel is specified by 1). An StkError will be thrown if an
+ error occurs during output or the \c channel argument is zero or
+ it is greater than the number of channels in the StkFrames object.
+ */
+ void tick( const StkFrames& frames, unsigned int channel = 1 );
//! Output the \e frameVector of sample frames of the given length.
/*!
An StkError will be thrown if an error occurs during output.
*/
- void tickFrame(const MY_FLOAT *frameVector, unsigned int frames = 1);
+ void tickFrame( const StkFloat *frameVector, unsigned int frames = 1 );
+
+ //! Output the StkFrames data to the RtWvOut object.
+ /*!
+ An StkError will be thrown if an error occurs during output or
+ if there is an incompatability between the number of channels in
+ the WvOut object and that in the StkFrames object.
+ */
+ void tickFrame( const StkFrames& frames );
protected:
- RtAudio *audio_;
+ RtAudio *audio_;
+ StkFloat *dataPtr_;
bool stopped_;
int bufferSize_;
};
-#endif // defined(__RTWVOUT_H)
+#endif
diff --git a/include/SKINI.h b/include/SKINI.h
deleted file mode 100644
index 138fd4c..0000000
--- a/include/SKINI.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/***************************************************/
-/*! \class SKINI
- \brief STK SKINI parsing class
-
- This class parses SKINI formatted text
- messages. It can be used to parse individual
- messages or it can be passed an entire file.
- The file specification is Perry's and his
- alone, but it's all text so it shouldn't be to
- hard to figure out.
-
- SKINI (Synthesis toolKit Instrument Network
- Interface) is like MIDI, but allows for
- floating-point control changes, note numbers,
- etc. The following example causes a sharp
- middle C to be played with a velocity of 111.132:
-
- \code
- noteOn 60.01 111.13
- \endcode
-
- \sa \ref skini
-
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
-*/
-/***************************************************/
-
-#if !defined(__SKINI_H)
-#define __SKINI_H
-
-#include "Stk.h"
-#include
-
-class SKINI : public Stk
-{
- public:
- //! Default constructor used for parsing messages received externally.
- SKINI();
-
- //! Overloaded constructor taking a SKINI formatted scorefile.
- SKINI(char *fileName);
-
- //! Class destructor
- ~SKINI();
-
- //! Attempt to parse the given string, returning the message type.
- /*!
- A type value equal to zero indicates an invalid message.
- */
- long parseThis(char* aString);
-
- //! Parse the next message (if a file is loaded) and return the message type.
- /*!
- A negative value is returned when the file end is reached.
- */
- long nextMessage();
-
- //! Return the current message type.
- long getType() const;
-
- //! Return the current message channel value.
- long getChannel() const;
-
- //! Return the current message delta time value (in seconds).
- MY_FLOAT getDelta() const;
-
- //! Return the current message byte two value.
- MY_FLOAT getByteTwo() const;
-
- //! Return the current message byte three value.
- MY_FLOAT getByteThree() const;
-
- //! Return the current message byte two value (integer).
- long getByteTwoInt() const;
-
- //! Return the current message byte three value (integer).
- long getByteThreeInt() const;
-
- //! Return remainder string after parsing.
- const char* getRemainderString();
-
- //! Return the message type as a string.
- const char* getMessageTypeString();
-
- //! Return the SKINI type string for the given type value.
- const char* whatsThisType(long type);
-
- //! Return the SKINI controller string for the given controller number.
- const char* whatsThisController(long number);
-
- protected:
-
- FILE *myFile;
- long messageType;
- char msgTypeString[64];
- long channel;
- MY_FLOAT deltaTime;
- MY_FLOAT byteTwo;
- MY_FLOAT byteThree;
- long byteTwoInt;
- long byteThreeInt;
- char remainderString[1024];
- char whatString[1024];
-};
-
-static const double Midi2Pitch[129] = {
-8.18,8.66,9.18,9.72,10.30,10.91,11.56,12.25,
-12.98,13.75,14.57,15.43,16.35,17.32,18.35,19.45,
-20.60,21.83,23.12,24.50,25.96,27.50,29.14,30.87,
-32.70,34.65,36.71,38.89,41.20,43.65,46.25,49.00,
-51.91,55.00,58.27,61.74,65.41,69.30,73.42,77.78,
-82.41,87.31,92.50,98.00,103.83,110.00,116.54,123.47,
-130.81,138.59,146.83,155.56,164.81,174.61,185.00,196.00,
-207.65,220.00,233.08,246.94,261.63,277.18,293.66,311.13,
-329.63,349.23,369.99,392.00,415.30,440.00,466.16,493.88,
-523.25,554.37,587.33,622.25,659.26,698.46,739.99,783.99,
-830.61,880.00,932.33,987.77,1046.50,1108.73,1174.66,1244.51,
-1318.51,1396.91,1479.98,1567.98,1661.22,1760.00,1864.66,1975.53,
-2093.00,2217.46,2349.32,2489.02,2637.02,2793.83,2959.96,3135.96,
-3322.44,3520.00,3729.31,3951.07,4186.01,4434.92,4698.64,4978.03,
-5274.04,5587.65,5919.91,6271.93,6644.88,7040.00,7458.62,7902.13,
-8372.02,8869.84,9397.27,9956.06,10548.08,11175.30,11839.82,12543.85,
-13289.75};
-
-#endif
-
-
diff --git a/include/SKINI.msg b/include/SKINI.msg
index 1ec95db..72bacf1 100644
--- a/include/SKINI.msg
+++ b/include/SKINI.msg
@@ -3,22 +3,25 @@
Definition of SKINI Message Types and Special Symbols
Synthesis toolKit Instrument Network Interface
- These symbols should have the form __SK__
+ These symbols should have the form:
- Where is the string used in the SKINI stream.
+ \c __SK__
- by Perry R. Cook, 1995 - 2002.
+ where is the string used in the SKINI stream.
+
+ by Perry R. Cook, 1995 - 2004.
*/
/*********************************************************/
-/***** MIDI COMPATIBLE MESSAGES *****/
-/***** Status Bytes Have Channel=0 **/
+#define NOPE -32767
+#define YEP 1
+#define SK_DBL -32766
+#define SK_INT -32765
+#define SK_STR -32764
+#define __SK_Exit_ 999
-#define NOPE -32767
-#define YEP 1
-#define SK_DBL -32766
-#define SK_INT -32765
-#define SK_STR -32764
+/***** MIDI COMPATIBLE MESSAGES *****/
+/*** (Status bytes for channel=0) ***/
#define __SK_NoteOff_ 128
#define __SK_NoteOn_ 144
diff --git a/include/SKINI.tbl b/include/SKINI.tbl
index f12be83..e2a1877 100644
--- a/include/SKINI.tbl
+++ b/include/SKINI.tbl
@@ -1,128 +1,128 @@
#include "SKINI.msg"
-#define __SK_MaxMsgTypes_ 128
+#define __SK_MaxMsgTypes_ 80
-struct SKINISpec { char messageString[32];
+struct SkiniSpec { char messageString[32];
long type;
long data2;
long data3;
};
-/* SEE COMMENT BLOCK AT BOTTOM FOR FIELDS AND USES */
-/* MessageString ,type, ch?, data2 , data3 */
+/* SEE COMMENT BLOCK AT BOTTOM FOR FIELDS AND USES */
+/* MessageString , type, data2, data3 */
-struct SKINISpec skini_msgs[__SK_MaxMsgTypes_] =
+struct SkiniSpec skini_msgs[__SK_MaxMsgTypes_] =
{
- {"NoteOff" , __SK_NoteOff_, SK_DBL, SK_DBL},
- {"NoteOn" , __SK_NoteOn_, SK_DBL, SK_DBL},
- {"PolyPressure" , __SK_PolyPressure_, SK_DBL, SK_DBL},
- {"ControlChange" , __SK_ControlChange_, SK_INT, SK_DBL},
- {"ProgramChange" , __SK_ProgramChange_, SK_DBL, SK_DBL},
- {"AfterTouch" , __SK_AfterTouch_, SK_DBL, NOPE},
- {"ChannelPressure" ,__SK_ChannelPressure_, SK_DBL, NOPE},
- {"PitchWheel" , __SK_PitchWheel_, SK_DBL, NOPE},
- {"PitchBend" , __SK_PitchBend_, SK_DBL, NOPE},
- {"PitchChange" , __SK_PitchChange_, SK_DBL, NOPE},
-
- {"Clock" , __SK_Clock_, NOPE, NOPE},
- {"Undefined" , 249, NOPE, NOPE},
- {"SongStart" , __SK_SongStart_, NOPE, NOPE},
- {"Continue" , __SK_Continue_, NOPE, NOPE},
- {"SongStop" , __SK_SongStop_, NOPE, NOPE},
- {"Undefined" , 253, NOPE, NOPE},
- {"ActiveSensing" , __SK_ActiveSensing_, NOPE, NOPE},
- {"SystemReset" , __SK_SystemReset_, NOPE, NOPE},
-
- {"Volume" , __SK_ControlChange_, __SK_Volume_ , SK_DBL},
- {"ModWheel" , __SK_ControlChange_, __SK_ModWheel_ , SK_DBL},
- {"Modulation" , __SK_ControlChange_, __SK_Modulation_ , SK_DBL},
- {"Breath" , __SK_ControlChange_, __SK_Breath_ , SK_DBL},
- {"FootControl" , __SK_ControlChange_, __SK_FootControl_ , SK_DBL},
- {"Portamento" , __SK_ControlChange_, __SK_Portamento_ , SK_DBL},
- {"Balance" , __SK_ControlChange_, __SK_Balance_ , SK_DBL},
- {"Pan" , __SK_ControlChange_, __SK_Pan_ , SK_DBL},
- {"Sustain" , __SK_ControlChange_, __SK_Sustain_ , SK_DBL},
- {"Damper" , __SK_ControlChange_, __SK_Damper_ , SK_DBL},
- {"Expression" , __SK_ControlChange_, __SK_Expression_ , SK_DBL},
-
- {"NoiseLevel" , __SK_ControlChange_, __SK_NoiseLevel_ , SK_DBL},
- {"PickPosition" , __SK_ControlChange_, __SK_PickPosition_ , SK_DBL},
- {"StringDamping" , __SK_ControlChange_, __SK_StringDamping_ , SK_DBL},
- {"StringDetune" , __SK_ControlChange_, __SK_StringDetune_ , SK_DBL},
- {"BodySize" , __SK_ControlChange_, __SK_BodySize_ , SK_DBL},
- {"BowPressure" , __SK_ControlChange_, __SK_BowPressure_ , SK_DBL},
- {"BowPosition" , __SK_ControlChange_, __SK_BowPosition_ , SK_DBL},
- {"BowBeta" , __SK_ControlChange_, __SK_BowBeta_ , SK_DBL},
+ {"NoteOff" , __SK_NoteOff_, SK_DBL, SK_DBL},
+ {"NoteOn" , __SK_NoteOn_, SK_DBL, SK_DBL},
+ {"PolyPressure" , __SK_PolyPressure_, SK_DBL, SK_DBL},
+ {"ControlChange" , __SK_ControlChange_, SK_INT, SK_DBL},
+ {"ProgramChange" , __SK_ProgramChange_, SK_DBL, NOPE},
+ {"AfterTouch" , __SK_AfterTouch_, SK_DBL, NOPE},
+ {"ChannelPressure" ,__SK_ChannelPressure_, SK_DBL, NOPE},
+ {"PitchWheel" , __SK_PitchWheel_, SK_DBL, NOPE},
+ {"PitchBend" , __SK_PitchBend_, SK_DBL, NOPE},
+ {"PitchChange" , __SK_PitchChange_, SK_DBL, NOPE},
+
+ {"Clock" , __SK_Clock_, NOPE, NOPE},
+ {"Undefined" , 249, NOPE, NOPE},
+ {"SongStart" , __SK_SongStart_, NOPE, NOPE},
+ {"Continue" , __SK_Continue_, NOPE, NOPE},
+ {"SongStop" , __SK_SongStop_, NOPE, NOPE},
+ {"Undefined" , 253, NOPE, NOPE},
+ {"ActiveSensing" , __SK_ActiveSensing_, NOPE, NOPE},
+ {"SystemReset" , __SK_SystemReset_, NOPE, NOPE},
+
+ {"Volume" , __SK_ControlChange_, __SK_Volume_ , SK_DBL},
+ {"ModWheel" , __SK_ControlChange_, __SK_ModWheel_ , SK_DBL},
+ {"Modulation" , __SK_ControlChange_, __SK_Modulation_ , SK_DBL},
+ {"Breath" , __SK_ControlChange_, __SK_Breath_ , SK_DBL},
+ {"FootControl" , __SK_ControlChange_, __SK_FootControl_ , SK_DBL},
+ {"Portamento" , __SK_ControlChange_, __SK_Portamento_ , SK_DBL},
+ {"Balance" , __SK_ControlChange_, __SK_Balance_ , SK_DBL},
+ {"Pan" , __SK_ControlChange_, __SK_Pan_ , SK_DBL},
+ {"Sustain" , __SK_ControlChange_, __SK_Sustain_ , SK_DBL},
+ {"Damper" , __SK_ControlChange_, __SK_Damper_ , SK_DBL},
+ {"Expression" , __SK_ControlChange_, __SK_Expression_ , SK_DBL},
+
+ {"NoiseLevel" , __SK_ControlChange_, __SK_NoiseLevel_ , SK_DBL},
+ {"PickPosition" , __SK_ControlChange_, __SK_PickPosition_ , SK_DBL},
+ {"StringDamping" , __SK_ControlChange_, __SK_StringDamping_ , SK_DBL},
+ {"StringDetune" , __SK_ControlChange_, __SK_StringDetune_ , SK_DBL},
+ {"BodySize" , __SK_ControlChange_, __SK_BodySize_ , SK_DBL},
+ {"BowPressure" , __SK_ControlChange_, __SK_BowPressure_ , SK_DBL},
+ {"BowPosition" , __SK_ControlChange_, __SK_BowPosition_ , SK_DBL},
+ {"BowBeta" , __SK_ControlChange_, __SK_BowBeta_ , SK_DBL},
- {"ReedStiffness" , __SK_ControlChange_, __SK_ReedStiffness_ , SK_DBL},
- {"ReedRestPos" , __SK_ControlChange_, __SK_ReedRestPos_ , SK_DBL},
- {"FluteEmbouchure" , __SK_ControlChange_, __SK_FluteEmbouchure_, SK_DBL},
- {"LipTension" , __SK_ControlChange_, __SK_LipTension_ , SK_DBL},
- {"StrikePosition" , __SK_ControlChange_, __SK_StrikePosition_, SK_DBL},
- {"StickHardness" , __SK_ControlChange_, __SK_StickHardness_ , SK_DBL},
+ {"ReedStiffness" , __SK_ControlChange_, __SK_ReedStiffness_ , SK_DBL},
+ {"ReedRestPos" , __SK_ControlChange_, __SK_ReedRestPos_ , SK_DBL},
+ {"FluteEmbouchure" , __SK_ControlChange_, __SK_FluteEmbouchure_ , SK_DBL},
+ {"LipTension" , __SK_ControlChange_, __SK_LipTension_ , SK_DBL},
+ {"StrikePosition" , __SK_ControlChange_, __SK_StrikePosition_ , SK_DBL},
+ {"StickHardness" , __SK_ControlChange_, __SK_StickHardness_ , SK_DBL},
- {"TrillDepth" , __SK_ControlChange_, __SK_TrillDepth_ , SK_DBL},
- {"TrillSpeed" , __SK_ControlChange_, __SK_TrillSpeed_ , SK_DBL},
+ {"TrillDepth" , __SK_ControlChange_, __SK_TrillDepth_ , SK_DBL},
+ {"TrillSpeed" , __SK_ControlChange_, __SK_TrillSpeed_ , SK_DBL},
- {"Strumming" , __SK_ControlChange_, __SK_Strumming_ , 127 },
- {"NotStrumming" , __SK_ControlChange_, __SK_Strumming_ , 0 },
+ {"Strumming" , __SK_ControlChange_, __SK_Strumming_ , 127 },
+ {"NotStrumming" , __SK_ControlChange_, __SK_Strumming_ , 0 },
- {"PlayerSkill" , __SK_ControlChange_, __SK_PlayerSkill_ , SK_DBL},
+ {"PlayerSkill" , __SK_ControlChange_, __SK_PlayerSkill_ , SK_DBL},
- {"Chord" , __SK_Chord_ , SK_DBL , SK_STR },
- {"ChordOff" , __SK_ChordOff_ , SK_DBL , NOPE },
+ {"Chord" , __SK_Chord_ , SK_DBL, SK_STR},
+ {"ChordOff" , __SK_ChordOff_ , SK_DBL, NOPE},
- {"ShakerInst" , __SK_ControlChange_, __SK_ShakerInst_ , SK_DBL},
- {"Maraca" , __SK_ControlChange_, __SK_ShakerInst_ , 0 },
- {"Sekere" , __SK_ControlChange_, __SK_ShakerInst_ , 1 },
- {"Cabasa" , __SK_ControlChange_, __SK_ShakerInst_ , 2 },
- {"Bamboo" , __SK_ControlChange_, __SK_ShakerInst_ , 3 },
- {"Waterdrp" , __SK_ControlChange_, __SK_ShakerInst_ , 4 },
- {"Tambourn" , __SK_ControlChange_, __SK_ShakerInst_ , 5 },
- {"Sleighbl" , __SK_ControlChange_, __SK_ShakerInst_ , 6 },
- {"Guiro" , __SK_ControlChange_, __SK_ShakerInst_ , 7 },
+ {"ShakerInst" , __SK_ControlChange_, __SK_ShakerInst_ , SK_DBL},
+ {"Maraca" , __SK_ControlChange_, __SK_ShakerInst_ , 0 },
+ {"Sekere" , __SK_ControlChange_, __SK_ShakerInst_ , 1 },
+ {"Cabasa" , __SK_ControlChange_, __SK_ShakerInst_ , 2 },
+ {"Bamboo" , __SK_ControlChange_, __SK_ShakerInst_ , 3 },
+ {"Waterdrp" , __SK_ControlChange_, __SK_ShakerInst_ , 4 },
+ {"Tambourn" , __SK_ControlChange_, __SK_ShakerInst_ , 5 },
+ {"Sleighbl" , __SK_ControlChange_, __SK_ShakerInst_ , 6 },
+ {"Guiro" , __SK_ControlChange_, __SK_ShakerInst_ , 7 },
- {"OpenFile" , 256, SK_STR , NOPE},
- {"SetPath" , 257, SK_STR , NOPE},
+ {"OpenFile" , 256, SK_STR, NOPE},
+ {"SetPath" , 257, SK_STR, NOPE},
- {"FilePath" , __SK_SINGER_FilePath_, SK_STR , NOPE},
- {"Frequency" , __SK_SINGER_Frequency_, SK_STR , NOPE},
- {"NoteName" , __SK_SINGER_NoteName_, SK_STR , NOPE},
- {"VocalShape" , __SK_SINGER_Shape_ , SK_STR , NOPE},
- {"Glottis" , __SK_SINGER_Glot_ , SK_STR , NOPE},
- {"VoicedUnVoiced" , __SK_SINGER_VoicedUnVoiced_, SK_DBL , SK_STR},
- {"Synthesize" , __SK_SINGER_Synthesize_, SK_STR , NOPE},
- {"Silence" , __SK_SINGER_Silence_, SK_STR , NOPE},
- {"VibratoAmt" , __SK_ControlChange_ ,__SK_SINGER_VibratoAmt_,SK_DBL},
- {"RndVibAmt" , __SK_SINGER_RndVibAmt_ ,SK_STR, NOPE},
- {"VibFreq" , __SK_ControlChange_ ,__SK_SINGER_VibFreq_ ,SK_DBL}
+ {"FilePath" , __SK_SINGER_FilePath_ , SK_STR, NOPE},
+ {"Frequency" , __SK_SINGER_Frequency_ , SK_STR, NOPE},
+ {"NoteName" , __SK_SINGER_NoteName_ , SK_STR, NOPE},
+ {"VocalShape" , __SK_SINGER_Shape_ , SK_STR, NOPE},
+ {"Glottis" , __SK_SINGER_Glot_ , SK_STR, NOPE},
+ {"VoicedUnVoiced" , __SK_SINGER_VoicedUnVoiced_, SK_DBL, SK_STR},
+ {"Synthesize" , __SK_SINGER_Synthesize_ , SK_STR, NOPE},
+ {"Silence" , __SK_SINGER_Silence_ , SK_STR, NOPE},
+ {"RndVibAmt" , __SK_SINGER_RndVibAmt_ , SK_STR, NOPE},
+ {"VibratoAmt" , __SK_ControlChange_ ,__SK_SINGER_VibratoAmt_,SK_DBL},
+ {"VibFreq" , __SK_ControlChange_ ,__SK_SINGER_VibFreq_ ,SK_DBL}
};
/** FORMAT: *************************************************************/
/* */
-/* MessageStr$ ,type, data2, data3, */
+/* MessageStr$ , type, data2, data3, */
/* */
/* type is the message type sent back from the SKINI line parser. */
/* data is either */
/* NOPE : field not used, specifically, there aren't going */
/* to be any more fields on this line. So if there */
-/* is is NOPE in data2, data3 won't even be checked */
+/* is NOPE in data2, data3 won't even be checked */
/* SK_INT : byte (actually scanned as 32 bit signed integer) */
-/* If it's a MIDI data field which is required to */
-/* be an integer, like a controller number, it's */
-/* 0-127. Otherwise) get creative with SK_INTs */
+/* If it's a MIDI data field which is required to */
+/* be an integer, like a controller number, it's */
+/* 0-127. Otherwise, get creative with SK_INTs. */
/* SK_DBL : double precision floating point. SKINI uses these */
/* in the MIDI context for note numbers with micro */
/* tuning, velocities, controller values, etc. */
/* SK_STR : only valid in final field. This allows (nearly) */
/* arbitrary message types to be supported by simply */
/* scanning the string to EndOfLine and then passing */
-/* it to a more intellegent handler. For example, */
+/* it to a more intelligent handler. For example, */
/* MIDI SYSEX (system exclusive) messages of up to */
-/* 256bytes can be read as space-delimited integers */
-/* into the 1K SK_STR buffer. Longer bulk dumps, */
+/* 256 bytes can be read as space-delimited integers */
+/* into the SK_STR buffer. Longer bulk dumps, */
/* soundfiles, etc. should be handled as a new */
/* message type pointing to a FileName stored in the */
/* SK_STR field, or as a new type of multi-line */
diff --git a/include/Sampler.h b/include/Sampler.h
index d3e4b23..edd3f09 100644
--- a/include/Sampler.h
+++ b/include/Sampler.h
@@ -2,15 +2,15 @@
/*! \class Sampler
\brief STK sampling synthesis abstract base class.
- This instrument contains up to 5 attack waves,
- 5 looped waves, and an ADSR envelope.
+ This instrument provides an ADSR envelope, a one-pole filter, and
+ structures for an arbitrary number of attack and loop waves.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__SAMPLER_H)
-#define __SAMPLER_H
+#ifndef STK_SAMPLER_H
+#define STK_SAMPLER_H
#include "Instrmnt.h"
#include "ADSR.h"
@@ -31,7 +31,7 @@ class Sampler : public Instrmnt
void clear();
//! Set instrument parameters for a particular frequency.
- virtual void setFrequency(MY_FLOAT frequency) = 0;
+ virtual void setFrequency(StkFloat frequency) = 0;
//! Initiate the envelopes with a key-on event and reset the attack waves.
void keyOn();
@@ -40,25 +40,36 @@ class Sampler : public Instrmnt
void keyOff();
//! 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() = 0;
+
+ //! Computer \e vectorSize outputs and return them in \e vector.
+ virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize) = 0;
+
+ //! 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 ) = 0;
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- virtual void controlChange(int number, MY_FLOAT value) = 0;
+ virtual void controlChange(int number, StkFloat value) = 0;
protected:
- ADSR *adsr;
- WvIn *attacks[5];
- WaveLoop *loops[5];
- OnePole *filter;
- MY_FLOAT baseFrequency;
- MY_FLOAT attackRatios[5];
- MY_FLOAT loopRatios[5];
- MY_FLOAT attackGain;
- MY_FLOAT loopGain;
- int whichOne;
+ ADSR adsr_;
+ std::vector attacks_;
+ std::vector loops_;
+ OnePole filter_;
+ StkFloat baseFrequency_;
+ std::vector attackRatios_;
+ std::vector loopRatios_;
+ StkFloat attackGain_;
+ StkFloat loopGain_;
};
diff --git a/include/Saxofony.h b/include/Saxofony.h
index 0b64e01..ef9e046 100644
--- a/include/Saxofony.h
+++ b/include/Saxofony.h
@@ -31,16 +31,16 @@
- Vibrato Gain = 1
- Breath Pressure = 128
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__SAXOFONY_H)
-#define __SAXOFONY_H
+#ifndef STK_SAXOFONY_H
+#define STK_SAXOFONY_H
#include "Instrmnt.h"
#include "DelayL.h"
-#include "ReedTabl.h"
+#include "ReedTable.h"
#include "OneZero.h"
#include "Envelope.h"
#include "Noise.h"
@@ -50,7 +50,10 @@ class Saxofony : public Instrmnt
{
public:
//! Class constructor, taking the lowest desired playing frequency.
- Saxofony(MY_FLOAT lowestFrequency);
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
+ Saxofony(StkFloat lowestFrequency);
//! Class destructor.
~Saxofony();
@@ -59,41 +62,53 @@ class Saxofony : public Instrmnt
void clear();
//! Set instrument parameters for a particular frequency.
- void setFrequency(MY_FLOAT frequency);
+ void setFrequency(StkFloat frequency);
//! Set the "blowing" position between the air column terminations (0.0 - 1.0).
- void setBlowPosition(MY_FLOAT aPosition);
+ void setBlowPosition(StkFloat aPosition);
//! Apply breath pressure to instrument with given amplitude and rate of increase.
- void startBlowing(MY_FLOAT amplitude, MY_FLOAT rate);
+ void startBlowing(StkFloat amplitude, StkFloat rate);
//! Decrease breath pressure with given rate of decrease.
- void stopBlowing(MY_FLOAT rate);
+ void stopBlowing(StkFloat rate);
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
protected:
- DelayL *delays[2];
- ReedTabl *reedTable;
- OneZero *filter;
- Envelope *envelope;
- Noise *noise;
- WaveLoop *vibrato;
- long length;
- MY_FLOAT outputGain;
- MY_FLOAT noiseGain;
- MY_FLOAT vibratoGain;
- MY_FLOAT position;
+ DelayL delays_[2];
+ ReedTable reedTable_;
+ OneZero filter_;
+ Envelope envelope_;
+ Noise noise_;
+ WaveLoop *vibrato_;
+ unsigned long length_;
+ StkFloat outputGain_;
+ StkFloat noiseGain_;
+ StkFloat vibratoGain_;
+ StkFloat position_;
};
diff --git a/include/Shakers.h b/include/Shakers.h
index 4802692..91f6025 100644
--- a/include/Shakers.h
+++ b/include/Shakers.h
@@ -48,17 +48,17 @@
- Little Rocks = 21
- Tuned Bamboo Chimes = 22
- by Perry R. Cook, 1996 - 1999.
+ by Perry R. Cook, 1996 - 2004.
*/
/***************************************************/
-#if !defined(__SHAKERS_H)
-#define __SHAKERS_H
+#ifndef STK_SHAKERS_H
+#define STK_SHAKERS_H
#include "Instrmnt.h"
-#define MAX_FREQS 8
-#define NUM_INSTR 24
+const int MAX_FREQS = 8;
+const int NUM_INSTR = 24;
class Shakers : public Instrmnt
{
@@ -74,54 +74,65 @@ class Shakers : public Instrmnt
Use the instrument numbers above, converted to frequency values
as if MIDI note numbers, to select a particular instrument.
*/
- virtual void noteOn(MY_FLOAT instrument, MY_FLOAT amplitude);
+ void noteOn(StkFloat instrument, StkFloat amplitude);
//! Stop a note with the given amplitude (speed of decay).
- virtual 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- virtual void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
protected:
int setupName(char* instr);
int setupNum(int inst);
- int setFreqAndReson(int which, MY_FLOAT freq, MY_FLOAT reson);
- void setDecays(MY_FLOAT sndDecay, MY_FLOAT sysDecay);
- void setFinalZs(MY_FLOAT z0, MY_FLOAT z1, MY_FLOAT z2);
- MY_FLOAT wuter_tick();
- MY_FLOAT tbamb_tick();
- MY_FLOAT ratchet_tick();
+ int setFreqAndReson(int which, StkFloat freq, StkFloat reson);
+ void setDecays(StkFloat sndDecay, StkFloat sysDecay);
+ void setFinalZs(StkFloat z0, StkFloat z1, StkFloat z2);
+ StkFloat wuter_tick();
+ StkFloat tbamb_tick();
+ StkFloat ratchet_tick();
- int instType;
- int ratchetPos, lastRatchetPos;
- MY_FLOAT shakeEnergy;
- MY_FLOAT inputs[MAX_FREQS];
- MY_FLOAT outputs[MAX_FREQS][2];
- MY_FLOAT coeffs[MAX_FREQS][2];
- MY_FLOAT sndLevel;
- MY_FLOAT baseGain;
- MY_FLOAT gains[MAX_FREQS];
- int nFreqs;
- MY_FLOAT t_center_freqs[MAX_FREQS];
- MY_FLOAT center_freqs[MAX_FREQS];
- MY_FLOAT resons[MAX_FREQS];
- MY_FLOAT freq_rand[MAX_FREQS];
- int freqalloc[MAX_FREQS];
- MY_FLOAT soundDecay;
- MY_FLOAT systemDecay;
- MY_FLOAT nObjects;
- MY_FLOAT collLikely;
- MY_FLOAT totalEnergy;
- MY_FLOAT ratchet,ratchetDelta;
- MY_FLOAT finalZ[3];
- MY_FLOAT finalZCoeffs[3];
- MY_FLOAT defObjs[NUM_INSTR];
- MY_FLOAT defDecays[NUM_INSTR];
- MY_FLOAT decayScale[NUM_INSTR];
+ int instType_;
+ int ratchetPos_, lastRatchetPos_;
+ StkFloat shakeEnergy_;
+ StkFloat inputs_[MAX_FREQS];
+ StkFloat outputs_[MAX_FREQS][2];
+ StkFloat coeffs_[MAX_FREQS][2];
+ StkFloat sndLevel_;
+ StkFloat baseGain_;
+ StkFloat gains_[MAX_FREQS];
+ int nFreqs_;
+ StkFloat t_center_freqs_[MAX_FREQS];
+ StkFloat center_freqs_[MAX_FREQS];
+ StkFloat resons_[MAX_FREQS];
+ StkFloat freq_rand_[MAX_FREQS];
+ int freqalloc_[MAX_FREQS];
+ StkFloat soundDecay_;
+ StkFloat systemDecay_;
+ StkFloat nObjects_;
+ StkFloat totalEnergy_;
+ StkFloat ratchet_, ratchetDelta_;
+ StkFloat finalZ_[3];
+ StkFloat finalZCoeffs_[3];
+ StkFloat defObjs_[NUM_INSTR];
+ StkFloat defDecays_[NUM_INSTR];
+ StkFloat decayScale_[NUM_INSTR];
};
diff --git a/include/Simple.h b/include/Simple.h
index 2834e44..bde74da 100644
--- a/include/Simple.h
+++ b/include/Simple.h
@@ -13,12 +13,12 @@
- Envelope Rate = 11
- Gain = 128
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__SIMPLE_H)
-#define __SIMPLE_H
+#ifndef STK_SIMPLE_H
+#define STK_SIMPLE_H
#include "Instrmnt.h"
#include "ADSR.h"
@@ -31,16 +31,19 @@ class Simple : public Instrmnt
{
public:
//! Class constructor.
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
Simple();
//! Class destructor.
- virtual ~Simple();
+ ~Simple();
//! Clear internal states.
void clear();
//! Set instrument parameters for a particular frequency.
- virtual void setFrequency(MY_FLOAT frequency);
+ void setFrequency(StkFloat frequency);
//! Start envelope toward "on" target.
void keyOn();
@@ -49,25 +52,37 @@ class Simple : public Instrmnt
void keyOff();
//! Start a note with the given frequency and amplitude.
- virtual void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, StkFloat amplitude);
//! Stop a note with the given amplitude (speed of decay).
- virtual void noteOff(MY_FLOAT amplitude);
+ void noteOff(StkFloat amplitude);
//! Compute one output sample.
- virtual 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- virtual void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
protected:
- ADSR *adsr;
- WaveLoop *loop;
- OnePole *filter;
- BiQuad *biquad;
- Noise *noise;
- MY_FLOAT baseFrequency;
- MY_FLOAT loopGain;
+ ADSR adsr_;
+ WaveLoop *loop_;
+ OnePole filter_;
+ BiQuad biquad_;
+ Noise noise_;
+ StkFloat baseFrequency_;
+ StkFloat loopGain_;
};
diff --git a/include/SingWave.h b/include/SingWave.h
index d1ae1ed..17a47bb 100644
--- a/include/SingWave.h
+++ b/include/SingWave.h
@@ -9,26 +9,26 @@
from pitch shifting. It will be used as an
excitation source for other instruments.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__SINGWAVE_H)
-#define __SINGWAVE_H
+#ifndef STK_SINGWAVE_H
+#define STK_SINGWAVE_H
#include "WaveLoop.h"
#include "Modulate.h"
#include "Envelope.h"
-class SingWave : public Stk
+class SingWave : public Generator
{
public:
//! Class constructor taking filename argument.
/*!
An StkError will be thrown if the file is not found, its format is
- unknown, or a read error occurs.
+ unknown, a read error occurs, or the rawwave path is incorrectly set.
*/
- SingWave(const char *fileName, bool raw=FALSE);
+ SingWave( std::string fileName, bool raw=false);
//! Class destructor.
~SingWave();
@@ -40,28 +40,28 @@ class SingWave : public Stk
void normalize();
//! Normalize the file to a maximum of \e +- peak.
- void normalize(MY_FLOAT peak);
+ void normalize(StkFloat peak);
//! Set instrument parameters for a particular frequency.
- void setFrequency(MY_FLOAT frequency);
+ void setFrequency(StkFloat frequency);
//! Set the vibrato frequency in Hz.
- void setVibratoRate(MY_FLOAT aRate);
+ void setVibratoRate(StkFloat rate);
//! Set the vibrato gain.
- void setVibratoGain(MY_FLOAT gain);
+ void setVibratoGain(StkFloat gain);
//! Set the random-ness amount.
- void setRandomGain(MY_FLOAT gain);
+ void setRandomGain(StkFloat gain);
//! Set the sweep rate.
- void setSweepRate(MY_FLOAT aRate);
+ void setSweepRate(StkFloat rate);
//! Set the gain rate.
- void setGainRate(MY_FLOAT aRate);
+ void setGainRate(StkFloat rate);
//! Set the gain target value.
- void setGainTarget(MY_FLOAT target);
+ void setGainTarget(StkFloat target);
//! Start a note.
void noteOn();
@@ -69,21 +69,29 @@ class SingWave : public Stk
//! Stop a note.
void noteOff();
- //! Return the last output value.
- MY_FLOAT lastOut();
-
//! Compute one output sample.
- MY_FLOAT tick();
+ StkFloat tick();
+
+ //! Compute \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:
- WaveLoop *wave;
- Modulate *modulator;
- Envelope *envelope;
- Envelope *pitchEnvelope;
- MY_FLOAT rate;
- MY_FLOAT sweepRate;
- MY_FLOAT lastOutput;
+ WaveLoop *wave_;
+ Modulate *modulator_;
+ Envelope envelope_;
+ Envelope pitchEnvelope_;
+ StkFloat rate_;
+ StkFloat sweepRate_;
};
diff --git a/include/Sitar.h b/include/Sitar.h
index cb84216..6fc6242 100644
--- a/include/Sitar.h
+++ b/include/Sitar.h
@@ -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(__SITAR_H)
-#define __SITAR_H
+#ifndef STK_SITAR_H
+#define STK_SITAR_H
#include "Instrmnt.h"
#include "DelayA.h"
@@ -30,7 +30,7 @@ class Sitar : public Instrmnt
{
public:
//! Class constructor, taking the lowest desired playing frequency.
- Sitar(MY_FLOAT lowestFrequency);
+ Sitar( StkFloat lowestFrequency = 20 );
//! Class destructor.
~Sitar();
@@ -39,30 +39,42 @@ class Sitar : public Instrmnt
void clear();
//! Set instrument parameters for a particular frequency.
- void setFrequency(MY_FLOAT frequency);
+ 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.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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:
- DelayA *delayLine;
- OneZero *loopFilter;
- Noise *noise;
- ADSR *envelope;
- long length;
- MY_FLOAT loopGain;
- MY_FLOAT amGain;
- MY_FLOAT delay;
- MY_FLOAT targetDelay;
+ DelayA delayLine_;
+ OneZero loopFilter_;
+ Noise noise_;
+ ADSR envelope_;
+
+ StkFloat loopGain_;
+ StkFloat amGain_;
+ StkFloat delay_;
+ StkFloat targetDelay_;
};
diff --git a/include/Skini.h b/include/Skini.h
new file mode 100644
index 0000000..d80399f
--- /dev/null
+++ b/include/Skini.h
@@ -0,0 +1,117 @@
+/***************************************************/
+/*! \class Skini
+ \brief STK SKINI parsing class
+
+ This class parses SKINI formatted text
+ messages. It can be used to parse individual
+ messages or it can be passed an entire file.
+ The SKINI specification is Perry's and his
+ alone, but it's all text so it shouldn't be too
+ hard to figure out.
+
+ SKINI (Synthesis toolKit Instrument Network
+ Interface) is like MIDI, but allows for
+ floating-point control changes, note numbers,
+ etc. The following example causes a sharp
+ middle C to be played with a velocity of 111.132:
+
+ \code
+ noteOn 60.01 111.132
+ \endcode
+
+ \sa \ref skini
+
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
+*/
+/***************************************************/
+
+#ifndef STK_SKINI_H
+#define STK_SKINI_H
+
+#include "Stk.h"
+#include
+#include
+#include
+
+class Skini : public Stk
+{
+ public:
+
+ //! A message structure to store and pass parsed SKINI messages.
+ struct Message {
+ long type; /*!< The message type, as defined in SKINI.msg. */
+ long channel; /*!< The message channel (not limited to 16!). */
+ StkFloat time; /*!< The message time stamp in seconds (delta or absolute). */
+ std::vector floatValues; /*!< The message values read as floats (values are type-specific). */
+ std::vector intValues; /*!< The message values read as ints (number and values are type-specific). */
+ std::string remainder; /*!< Any remaining message data, read as ascii text. */
+
+ // Default constructor.
+ Message()
+ :type(0), channel(0), time(0.0), floatValues(2), intValues(2) {}
+ };
+
+ //! Default constructor.
+ Skini();
+
+ //! Class destructor
+ ~Skini();
+
+ //! Set a SKINI formatted file for reading.
+ /*!
+ If the file is successfully opened, this function returns \e
+ true. Otherwise, \e false is returned.
+ */
+ bool setFile( std::string fileName );
+
+ //! Parse the next file message (if a file is loaded) and return the message type.
+ /*!
+ This function skips over lines in a file which cannot be
+ parsed. A type value equal to zero in the referenced message
+ structure (and the returned value) indicates the file end is
+ reached or no file is open for reading.
+ */
+ long nextMessage( Skini::Message& message );
+
+ //! Attempt to parse the given string and returning the message type.
+ /*!
+ A type value equal to zero in the referenced message structure
+ indicates an invalid message.
+ */
+ long parseString( std::string& line, Skini::Message& message );
+
+ //! Return the SKINI type string for the given type value.
+ static std::string whatsThisType(long type);
+
+ //! Return the SKINI controller string for the given controller number.
+ static std::string whatsThisController(long number);
+
+ protected:
+
+ void tokenize( const std::string& str, std::vector& tokens, const std::string& delimiters );
+
+ std::ifstream file_;
+};
+
+static const double Midi2Pitch[129] = {
+8.18,8.66,9.18,9.72,10.30,10.91,11.56,12.25,
+12.98,13.75,14.57,15.43,16.35,17.32,18.35,19.45,
+20.60,21.83,23.12,24.50,25.96,27.50,29.14,30.87,
+32.70,34.65,36.71,38.89,41.20,43.65,46.25,49.00,
+51.91,55.00,58.27,61.74,65.41,69.30,73.42,77.78,
+82.41,87.31,92.50,98.00,103.83,110.00,116.54,123.47,
+130.81,138.59,146.83,155.56,164.81,174.61,185.00,196.00,
+207.65,220.00,233.08,246.94,261.63,277.18,293.66,311.13,
+329.63,349.23,369.99,392.00,415.30,440.00,466.16,493.88,
+523.25,554.37,587.33,622.25,659.26,698.46,739.99,783.99,
+830.61,880.00,932.33,987.77,1046.50,1108.73,1174.66,1244.51,
+1318.51,1396.91,1479.98,1567.98,1661.22,1760.00,1864.66,1975.53,
+2093.00,2217.46,2349.32,2489.02,2637.02,2793.83,2959.96,3135.96,
+3322.44,3520.00,3729.31,3951.07,4186.01,4434.92,4698.64,4978.03,
+5274.04,5587.65,5919.91,6271.93,6644.88,7040.00,7458.62,7902.13,
+8372.02,8869.84,9397.27,9956.06,10548.08,11175.30,11839.82,12543.85,
+13289.75};
+
+#endif
+
+
diff --git a/include/Socket.h b/include/Socket.h
index 79f0fba..9b780c1 100644
--- a/include/Socket.h
+++ b/include/Socket.h
@@ -14,12 +14,12 @@
less than or equal to zero indicate a closed
or lost connection or the occurence of an error.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__SOCKET_H)
-#define __SOCKET_H
+#ifndef STK_SOCKET_H
+#define STK_SOCKET_H
#include "Stk.h"
@@ -56,7 +56,7 @@ class Socket : public Stk
void close( void );
//! Return the server/client socket descriptor.
- int socket( void ) const;
+ int id( void ) const;
//! Return the server/client port number.
int port( void ) const;
@@ -76,7 +76,7 @@ class Socket : public Stk
//! Close the socket with the given descriptor.
static void close( int socket );
- //! Returns TRUE is the socket descriptor is valid.
+ //! Returns true if the socket descriptor is valid.
static bool isValid( int socket );
//! Write a buffer over the socket connection. Returns the number of bytes written or -1 if an error occurs.
@@ -93,11 +93,10 @@ class Socket : public Stk
protected:
- char msg[256];
- int soket;
- int poort;
- bool server;
+ int soket_;
+ int port_;
+ bool server_;
};
-#endif // defined(__SOCKET_H)
+#endif // defined(STK_SOCKET_H)
diff --git a/include/Sphere.h b/include/Sphere.h
index 5e87c48..d399165 100644
--- a/include/Sphere.h
+++ b/include/Sphere.h
@@ -5,66 +5,67 @@
This class implements a spherical ball with
radius, mass, position, and velocity parameters.
- by Perry R. Cook, 1995 - 2002.
+ by Perry R. Cook, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__SPHERE_H)
-#define __SPHERE_H
+#ifndef STK_SPHERE_H
+#define STK_SPHERE_H
+#include "Stk.h"
#include "Vector3D.h"
-class Sphere
+class Sphere : public Stk
{
public:
//! Constructor taking an initial radius value.
- Sphere(double initRadius);
+ Sphere(StkFloat radius = 1.0 );
//! Class destructor.
~Sphere();
//! Set the 3D center position of the sphere.
- void setPosition(double anX, double aY, double aZ);
+ void setPosition(StkFloat x, StkFloat y, StkFloat z);
//! Set the 3D velocity of the sphere.
- void setVelocity(double anX, double aY, double aZ);
+ void setVelocity(StkFloat x, StkFloat y, StkFloat z);
//! Set the radius of the sphere.
- void setRadius(double aRadius);
+ void setRadius(StkFloat radius);
//! Set the mass of the sphere.
- void setMass(double aMass);
+ void setMass(StkFloat mass);
//! Get the current position of the sphere as a 3D vector.
Vector3D* getPosition();
//! Get the relative position of the given point to the sphere as a 3D vector.
- Vector3D* getRelativePosition(Vector3D *aPosition);
+ Vector3D* getRelativePosition(Vector3D *position);
//! Set the velcoity of the sphere as a 3D vector.
- double getVelocity(Vector3D* aVelocity);
+ StkFloat getVelocity(Vector3D* velocity);
//! Returns the distance from the sphere boundary to the given position (< 0 if inside).
- double isInside(Vector3D *aPosition);
+ StkFloat isInside(Vector3D *position);
//! Get the current sphere radius.
- double getRadius();
+ StkFloat getRadius();
//! Get the current sphere mass.
- double getMass();
+ StkFloat getMass();
//! Increase the current sphere velocity by the given 3D components.
- void addVelocity(double anX, double aY, double aZ);
+ void addVelocity(StkFloat x, StkFloat y, StkFloat z);
//! Move the sphere for the given time increment.
- void tick(double timeIncrement);
+ void tick(StkFloat timeIncrement);
private:
- Vector3D *myPosition;
- Vector3D *myVelocity;
- Vector3D workingVector;
- double myRadius;
- double myMass;
+ Vector3D position_;
+ Vector3D velocity_;
+ Vector3D workingVector_;
+ StkFloat radius_;
+ StkFloat mass_;
};
#endif
diff --git a/include/StifKarp.h b/include/StifKarp.h
index eb4d5ba..769aeac 100644
--- a/include/StifKarp.h
+++ b/include/StifKarp.h
@@ -17,12 +17,12 @@
- String Sustain = 11
- String Stretch = 1
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__StifKarp_h)
-#define __StifKarp_h
+#ifndef STK_STIFKARP_H
+#define STK_STIFKARP_H
#include "Instrmnt.h"
#include "DelayL.h"
@@ -35,7 +35,7 @@ class StifKarp : public Instrmnt
{
public:
//! Class constructor, taking the lowest desired playing frequency.
- StifKarp(MY_FLOAT lowestFrequency);
+ StifKarp(StkFloat lowestFrequency);
//! Class destructor.
~StifKarp();
@@ -44,13 +44,13 @@ class StifKarp : public Instrmnt
void clear();
//! Set instrument parameters for a particular frequency.
- void setFrequency(MY_FLOAT frequency);
+ void setFrequency(StkFloat frequency);
//! Set the stretch "factor" of the string (0.0 - 1.0).
- void setStretch(MY_FLOAT stretch);
+ void setStretch(StkFloat stretch);
//! Set the pluck or "excitation" position along the string (0.0 - 1.0).
- void setPickupPosition(MY_FLOAT position);
+ void setPickupPosition(StkFloat position);
//! Set the base loop gain.
/*!
@@ -58,37 +58,50 @@ class StifKarp : public Instrmnt
Because of high-frequency loop filter roll-off, higher
frequency settings have greater loop gains.
*/
- void setBaseLoopGain(MY_FLOAT aGain);
+ void setBaseLoopGain(StkFloat aGain);
//! 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.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
protected:
- DelayA *delayLine;
- DelayL *combDelay;
- OneZero *filter;
- Noise *noise;
- BiQuad *biQuad[4];
- long length;
- MY_FLOAT loopGain;
- MY_FLOAT baseLoopGain;
- MY_FLOAT lastFrequency;
- MY_FLOAT lastLength;
- MY_FLOAT stretching;
- MY_FLOAT pluckAmplitude;
- MY_FLOAT pickupPosition;
+ DelayA delayLine_;
+ DelayL combDelay_;
+ OneZero filter_;
+ Noise noise_;
+ BiQuad biquad_[4];
+
+ unsigned long length_;
+ StkFloat loopGain_;
+ StkFloat baseLoopGain_;
+ StkFloat lastFrequency_;
+ StkFloat lastLength_;
+ StkFloat stretching_;
+ StkFloat pluckAmplitude_;
+ StkFloat pickupPosition_;
};
diff --git a/include/Stk.h b/include/Stk.h
index 43c36ed..c15c2b6 100644
--- a/include/Stk.h
+++ b/include/Stk.h
@@ -8,30 +8,36 @@
this class provides error handling and
byte-swapping functions.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__STK_H)
-#define __STK_H
+#ifndef STK_STK_H
+#define STK_STK_H
#include
+#include
+#include
+#include
// Most data in STK is passed and calculated with the
// following user-definable floating-point type. You
// can change this to "float" if you prefer or perhaps
// a "long double" in the future.
-typedef double MY_FLOAT;
+typedef double StkFloat;
+
+// The "MY_FLOAT" type was deprecated in STK
+// versions higher than 4.1.3 and replaced with the variable
+// "StkFloat".
+#if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__)
+ typedef StkFloat MY_FLOAT;
+ #pragma deprecated(MY_FLOAT)
+#elif defined(__GXX__)
+ typedef StkFloat MY_FLOAT __attribute__ ((deprecated));
+#else
+ typedef StkFloat MY_FLOAT; // temporary
+#endif
-// The "MY_FLOAT" type will be deprecated in STK
-// versions higher than 4.1.2 and replaced with the variable
-// "StkFloat".
-//typedef double StkFloat;
-//#if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__)
-// #pragma deprecated(MY_FLOAT)
-//#else
-// typedef StkFloat MY_FLOAT __attribute__ ((deprecated));
-//#endif
//! STK error handling class.
/*!
@@ -42,7 +48,8 @@ typedef double MY_FLOAT;
class StkError
{
public:
- enum TYPE {
+ enum Type {
+ STATUS,
WARNING,
DEBUG_WARNING,
FUNCTION_ARGUMENT,
@@ -58,24 +65,27 @@ public:
};
protected:
- char message[256];
- TYPE type;
+ std::string message_;
+ Type type_;
public:
//! The constructor.
- StkError(const char *p, TYPE tipe = StkError::UNSPECIFIED);
+ StkError(const std::string& message, Type type = StkError::UNSPECIFIED) : message_(message), type_(type) {}
//! The destructor.
- virtual ~StkError(void);
+ virtual ~StkError(void) {};
- //! Prints "thrown" error message to stdout.
- virtual void printMessage(void);
+ //! Prints thrown error message to stderr.
+ virtual void printMessage(void) { std::cerr << '\n' << message_ << "\n\n"; }
- //! Returns the "thrown" error message TYPE.
- virtual const TYPE& getType(void) { return type; }
+ //! Returns the thrown error message type.
+ virtual const Type& getType(void) { return type_; }
- //! Returns the "thrown" error message string.
- virtual const char *getMessage(void) const { return message; }
+ //! Returns the thrown error message string.
+ virtual const std::string& getMessage(void) { return message_; }
+
+ //! Returns the thrown error message as a C string.
+ virtual const char *getMessageCString(void) { return message_.c_str(); }
};
@@ -83,15 +93,16 @@ class Stk
{
public:
- typedef unsigned long STK_FORMAT;
- static const STK_FORMAT STK_SINT8; /*!< -128 to +127 */
- static const STK_FORMAT STK_SINT16; /*!< -32768 to +32767 */
- static const STK_FORMAT STK_SINT32; /*!< -2147483648 to +2147483647. */
- static const STK_FORMAT MY_FLOAT32; /*!< Normalized between plus/minus 1.0. */
- static const STK_FORMAT MY_FLOAT64; /*!< Normalized between plus/minus 1.0. */
+ typedef unsigned long StkFormat;
+ static const StkFormat STK_SINT8; /*!< -128 to +127 */
+ static const StkFormat STK_SINT16; /*!< -32768 to +32767 */
+ static const StkFormat STK_SINT24; /*!< Upper 3 bytes of 32-bit signed integer. */
+ static const StkFormat STK_SINT32; /*!< -2147483648 to +2147483647. */
+ static const StkFormat STK_FLOAT32; /*!< Normalized between plus/minus 1.0. */
+ static const StkFormat STK_FLOAT64; /*!< Normalized between plus/minus 1.0. */
//! Static method which returns the current STK sample rate.
- static MY_FLOAT sampleRate(void);
+ static StkFloat sampleRate(void) { return srate_; }
//! Static method which sets the STK sample rate.
/*!
@@ -102,13 +113,13 @@ public:
is different from the default rate, it is imperative that it be
set \e BEFORE STK objects are instantiated.
*/
- static void setSampleRate(MY_FLOAT newRate);
+ static void setSampleRate(StkFloat rate) { if (rate > 0.0) srate_ = rate; }
//! Static method which returns the current rawwave path.
- static std::string rawwavePath(void);
+ static std::string rawwavePath(void) { return rawwavepath_; }
//! Static method which sets the STK rawwave path.
- static void setRawwavePath(std::string newPath);
+ static void setRawwavePath(std::string path);
//! Static method which byte-swaps a 16-bit data type.
static void swap16(unsigned char *ptr);
@@ -122,41 +133,119 @@ public:
//! Static cross-platform method to sleep for a number of milliseconds.
static void sleep(unsigned long milliseconds);
+ //! Static function for error reporting and handling using c-strings.
+ static void handleError( const char *message, StkError::Type type );
+
+ //! Static function for error reporting and handling using c++ strings.
+ static void handleError( std::string message, StkError::Type type );
+
private:
- static MY_FLOAT srate;
- static std::string rawwavepath;
+ static StkFloat srate_;
+ static std::string rawwavepath_;
protected:
+ std::ostringstream errorString_;
+
//! Default constructor.
Stk(void);
//! Class destructor.
virtual ~Stk(void);
- //! Function for error reporting and handling.
- static void handleError( const char *message, StkError::TYPE type );
+ //! Internal function for error reporting which assumes message in \c errorString_ variable.
+ void handleError( StkError::Type type );
+};
+
+
+/***************************************************/
+/*! \class StkFrames
+ \brief An STK class to handle vectorized audio data.
+
+ This class can hold single- or multi-channel audio data in either
+ interleaved or non-interleaved formats. The data type is always
+ StkFloat.
+
+ Possible future improvements in this class could include static
+ functions to inter- or de-interleave the data and to convert to
+ and return other data types.
+
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
+*/
+/***************************************************/
+
+class StkFrames
+{
+public:
+
+ //! The default constructor initializes the frame data structure to size zero.
+ StkFrames( unsigned int nFrames = 0, unsigned int nChannels = 1, bool interleaved = true );
+
+ //! Overloaded constructor which initializes the frame data to the specified size with \c value.
+ StkFrames( const StkFloat& value, unsigned int nFrames, unsigned int nChannels, bool interleaved = true );
+
+ //! Subscript operator which returns a reference to element \c n of self.
+ /*!
+ The result can be used as an lvalue . This reference is valid
+ until the resize function is called or the array is destroyed. The
+ index \c n must be between 0 and size less one. No range checking
+ is performed.
+ */
+ StkFloat& operator[]( size_t n ) { return data_[n]; };
+
+ //! Subscript operator which returns the value at element \c n of self.
+ /*!
+ The index \c n must be between 0 and size less one. No range
+ checking is performed.
+ */
+ StkFloat operator[]( size_t n ) const { return data_[n]; };
+
+ //! Returns the total number of audio samples represented by the object.
+ size_t size() const { return size_; };
+
+ //! Resize self to represent the specified number of channels and frames.
+ /*!
+ Changes the size of self based on the number of frames and
+ channels, and assigns \c value to every element.
+ */
+ void resize( unsigned int nFrames, unsigned int nChannels = 1, StkFloat value = 0.0 );
+
+ //! Return the number of channels represented by the data.
+ unsigned int channels( void ) const { return nChannels_; };
+
+ //! Return the number of sample frames represented by the data.
+ unsigned int frames( void ) const { return nFrames_; };
+
+ //! Returns \c true if the data is in interleaved format, \c false if the data is non-interleaved.
+ bool interleaved( void ) const { return interleaved_; };
+
+ //! Set the flag to indicate whether the internal data is in interleaved (\c true) or non-interleaved (\c false) format.
+ void setInterleaved( bool isInterleaved ) { interleaved_ = isInterleaved; };
+
+private:
+ std::valarray data_;
+ unsigned int nFrames_;
+ unsigned int nChannels_;
+ size_t size_;
+ bool interleaved_;
};
+
// Here are a few other useful typedefs.
typedef signed short SINT16;
typedef signed int SINT32;
typedef float FLOAT32;
typedef double FLOAT64;
-// Boolean values
-#define FALSE 0
-#define TRUE 1
-
// The default sampling rate.
-#define SRATE (MY_FLOAT) 44100.0
+const StkFloat SRATE = 44100.0;
// The default real-time audio input and output buffer size. If
// clicks are occuring in the input and/or output sound stream, a
// larger buffer size may help. Larger buffer sizes, however, produce
// more latency.
-#define RT_BUFFER_SIZE 512
+const unsigned int RT_BUFFER_SIZE = 512;
// The default rawwave path value is set with the preprocessor
// definition RAWWAVE_PATH. This can be specified as an argument to
@@ -171,10 +260,9 @@ typedef double FLOAT64;
#define RAWWAVE_PATH "../../rawwaves/"
#endif
-#define PI (MY_FLOAT) 3.14159265359
-#define TWO_PI (MY_FLOAT) (MY_FLOAT) (2 * PI)
-
-#define ONE_OVER_128 (MY_FLOAT) 0.0078125
+const StkFloat PI = 3.14159265359;
+const StkFloat TWO_PI = 2 * PI;
+const StkFloat ONE_OVER_128 = 0.0078125;
#if defined(__WINDOWS_DS__) || defined(__WINDOWS_ASIO__)
#define __OS_WINDOWS__
diff --git a/include/SubNoise.h b/include/SubNoise.h
index 73c70e5..8f517cc 100644
--- a/include/SubNoise.h
+++ b/include/SubNoise.h
@@ -6,12 +6,12 @@
using the C rand() function. The quality of the
rand() function varies from one OS to another.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__SUBNOISE_H)
-#define __SUBNOISE_H
+#ifndef STK_SUBNOISE_H
+#define STK_SUBNOISE_H
#include "Noise.h"
@@ -32,11 +32,23 @@ class SubNoise : public Noise
void setRate(int subRate);
//! Return a sub-sampled random number between -1.0 and 1.0.
- MY_FLOAT tick();
+ StkFloat tick();
+
+ //! Compute \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:
- int counter;
- int rate;
+ int counter_;
+ int rate_;
};
diff --git a/include/Table.h b/include/Table.h
index f777bc5..a35da3c 100644
--- a/include/Table.h
+++ b/include/Table.h
@@ -10,20 +10,24 @@
An StkError will be thrown if the table file
is not found.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__TABLE_H)
-#define __TABLE_H
+#ifndef STK_TABLE_H
+#define STK_TABLE_H
-#include "Stk.h"
+#include "Function.h"
-class Table : public Stk
+class Table : public Function
{
public:
- //! Constructor loads the data from \e fileName.
- Table(char *fileName);
+ //! The constructor loads the data from \e fileName.
+ /*!
+ An StkError will be thrown in the file cannot be found or
+ opened.
+ */
+ Table( std::string fileName );
//! Class destructor.
~Table();
@@ -31,23 +35,28 @@ public:
//! Return the number of elements in the table.
long getLength() const;
- //! Return the last output value.
- MY_FLOAT lastOut() const;
-
//! Return the table value at position \e index.
/*!
Linear interpolation is performed if \e index is
fractional.
*/
- MY_FLOAT tick(MY_FLOAT index);
+ StkFloat tick(StkFloat index);
- //! Take \e vectorSize index positions and return the corresponding table values in \e vector.
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ //! Take \e vectorSize inputs from \e vector and replace them with corresponding outputs.
+ StkFloat *tick( StkFloat *vector, unsigned int vectorSize );
+
+ //! Take a channel of the StkFrames object as inputs to the function and replace with corresponding 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:
- long length;
- MY_FLOAT *data;
- MY_FLOAT lastOutput;
+ long length_;
+ std::valarray data_;
};
diff --git a/include/TcpWvIn.h b/include/TcpWvIn.h
index 979d8df..0766487 100644
--- a/include/TcpWvIn.h
+++ b/include/TcpWvIn.h
@@ -20,18 +20,19 @@
for a single remote connection. The default
data type for the incoming stream is signed
16-bit integers, though any of the defined
- STK_FORMATs are permissible.
+ StkFormats are permissible.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__TCPWVIN_H)
-#define __TCPWVIN_H
+#ifndef STK_TCPWVIN_H
+#define STK_TCPWVIN_H
#include "WvIn.h"
#include "Socket.h"
#include "Thread.h"
+#include "Mutex.h"
typedef struct {
bool finished;
@@ -54,32 +55,49 @@ public:
/*!
An StkError will be thrown a socket error or an invalid function argument.
*/
- void listen(unsigned int nChannels = 1, Stk::STK_FORMAT format = STK_SINT16);
+ void listen(unsigned int nChannels = 1, Stk::StkFormat format = STK_SINT16);
- //! Returns TRUE is an input connection exists or input data remains in the queue.
+ //! Returns true is an input connection exists or input data remains in the queue.
/*!
- This method will not return FALSE after an input connection has been closed until
+ This method will not return false after an input connection has been closed until
all buffered input data has been read out.
*/
bool isConnected(void);
//! Return the average across the last output sample frame.
- MY_FLOAT lastOut(void) const;
+ StkFloat lastOut(void) const;
//! Read out the average across one sample frame of data.
- MY_FLOAT tick(void);
+ StkFloat tick(void);
//! Read out vectorSize averaged sample frames of data in \e vector.
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
+
+ //! Fill a channel of the StkFrames object with averaged sample frames.
+ /*!
+ 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 );
//! Return a pointer to the last output sample frame.
- const MY_FLOAT *lastFrame(void) const;
+ const StkFloat *lastFrame(void) const;
//! Return a pointer to the next sample frame of data.
- const MY_FLOAT *tickFrame(void);
+ const StkFloat *tickFrame(void);
//! Read out sample \e frames of data to \e frameVector.
- MY_FLOAT *tickFrame(MY_FLOAT *frameVector, unsigned int frames);
+ StkFloat *tickFrame(StkFloat *frameVector, unsigned int frames);
+
+ //! Fill the StkFrames object with sample frames of data and return the same reference.
+ /*!
+ An StkError will be thrown if there is an incompatability
+ between the number of channels in the TcpWvIn object and that in
+ the StkFrames object.
+ */
+ StkFrames& tickFrame( StkFrames& frames );
// Called by the thread routine to receive data via the socket connection
// and fill the socket buffer. This is not intended for general use but
@@ -94,19 +112,19 @@ protected:
// Read buffered socket data into the data buffer ... will block if none available.
int readData( void );
- Socket *soket;
- Thread *thread;
- Mutex mutex;
- char *buffer;
- long bufferBytes;
- long bytesFilled;
- long writePoint;
- long readPoint;
- long counter;
- int dataSize;
- bool connected;
- int fd;
- thread_info threadInfo;
+ Socket *soket_;
+ Thread *thread_;
+ Mutex mutex_;
+ char *buffer_;
+ long bufferBytes_;
+ long bytesFilled_;
+ long writePoint_;
+ long readPoint_;
+ long counter_;
+ int dataSize_;
+ bool connected_;
+ int fd_;
+ thread_info threadInfo_;
};
diff --git a/include/TcpWvOut.h b/include/TcpWvOut.h
index 437d3d9..57f5b64 100644
--- a/include/TcpWvOut.h
+++ b/include/TcpWvOut.h
@@ -19,14 +19,14 @@
port and IP address of which must be specified
as constructor arguments. The default data
type is signed 16-bit integers but any of the
- defined STK_FORMATs are permissible.
+ defined StkFormats are permissible.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__TCPWVOUT_H)
-#define __TCPWVOUT_H
+#ifndef STK_TCPWVOUT_H
+#define STK_TCPWVOUT_H
#include "WvOut.h"
#include "Socket.h"
@@ -41,7 +41,7 @@ class TcpWvOut : protected WvOut
/*!
An StkError is thrown if a socket error occurs or an invalid argument is specified.
*/
- TcpWvOut(int port, const char *hostname = "localhost", unsigned int nChannels = 1, Stk::STK_FORMAT format = STK_SINT16);
+ TcpWvOut(int port, const char *hostname = "localhost", unsigned int nChannels = 1, Stk::StkFormat format = STK_SINT16);
//! Class destructor.
~TcpWvOut();
@@ -50,7 +50,7 @@ class TcpWvOut : protected WvOut
/*!
An StkError is thrown if a socket error occurs or an invalid argument is specified.
*/
- void connect(int port, const char *hostname = "localhost", unsigned int nChannels = 1, Stk::STK_FORMAT format = STK_SINT16);
+ void connect(int port, const char *hostname = "localhost", unsigned int nChannels = 1, Stk::StkFormat format = STK_SINT16);
//! If a connection is open, write out remaining samples in the queue and then disconnect.
void disconnect(void);
@@ -59,35 +59,51 @@ class TcpWvOut : protected WvOut
unsigned long getFrames( void ) const;
//! Return the number of seconds of data output.
- MY_FLOAT getTime( void ) const;
+ StkFloat getTime( void ) const;
//! Output a single sample to all channels in a sample frame.
/*!
An StkError is thrown if a socket write error occurs.
*/
- void tick(MY_FLOAT sample);
+ void tick( const StkFloat sample );
//! Output each sample in \e vector to all channels in \e vectorSize sample frames.
/*!
An StkError is thrown if a socket write error occurs.
*/
- void tick(const MY_FLOAT *vector, unsigned int vectorSize);
+ void tick( const StkFloat *vector, unsigned int vectorSize );
+
+ //! Output a channel of the StkFrames object to all channels of the TcpWvOut object.
+ /*!
+ The \c channel argument should be one or greater (the first
+ channel is specified by 1). An StkError will be thrown if a
+ socket write error occurs or the \c channel argument is zero or it
+ is greater than the number of channels in the StkFrames object.
+ */
+ void tick( const StkFrames& frames, unsigned int channel = 1 );
//! Output the \e frameVector of sample frames of the given length.
/*!
An StkError is thrown if a socket write error occurs.
*/
- void tickFrame(const MY_FLOAT *frameVector, unsigned int frames = 1);
+ void tickFrame( const StkFloat *frameVector, unsigned int frames = 1 );
+
+ //! Output the StkFrames data to the TcpWvOut object.
+ /*!
+ An StkError will be thrown if a socket write error occurs or if
+ there is an incompatability between the number of channels in the
+ TcpWvOut object and that in the StkFrames object.
+ */
+ virtual void tickFrame( const StkFrames& frames );
protected:
// Write a buffer of length \e frames via the socket connection.
void writeData( unsigned long frames );
- char msg[256];
- char *buffer;
- Socket *soket;
- int dataSize;
+ char *buffer_;
+ Socket *soket_;
+ int dataSize_;
};
-#endif // defined(__TCPWVOUT_H)
+#endif
diff --git a/include/Thread.h b/include/Thread.h
index a1fee0c..9336bcc 100644
--- a/include/Thread.h
+++ b/include/Thread.h
@@ -2,17 +2,26 @@
/*! \class Thread
\brief STK thread class.
- This class provides a uniform interface for
- cross-platform threads. On unix systems,
- the pthread library is used. Under Windows,
- the C runtime threadex functions are used.
+ This class provides a uniform interface for cross-platform
+ threads. On unix systems, the pthread library is used. Under
+ Windows, the C runtime threadex functions are used.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ Each instance of the Thread class can be used to control a single
+ thread process. Routines are provided to signal cancelation
+ and/or joining with a thread, though it is not possible for this
+ class to know the running status of a thread once it is started.
+
+ For cross-platform compatability, thread functions should be
+ declared as follows:
+
+ THREAD_RETURN THREAD_TYPE thread_function(void *ptr)
+
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__THREAD_H)
-#define __THREAD_H
+#ifndef STK_THREAD_H
+#define STK_THREAD_H
#include "Stk.h"
@@ -23,7 +32,6 @@
typedef pthread_t THREAD_HANDLE;
typedef void * THREAD_RETURN;
typedef void * (*THREAD_FUNCTION)(void *);
- typedef pthread_mutex_t MUTEX;
#elif defined(__OS_WINDOWS__)
@@ -33,7 +41,6 @@
typedef unsigned long THREAD_HANDLE;
typedef unsigned THREAD_RETURN;
typedef unsigned (__stdcall *THREAD_FUNCTION)(void *);
- typedef CRITICAL_SECTION MUTEX;
#endif
@@ -43,53 +50,45 @@ class Thread : public Stk
//! Default constructor.
Thread();
- //! The class destructor waits indefinitely for the thread to end before returning.
+ //! The class destructor does not attempt to cancel or join a thread.
~Thread();
- //! Begin execution of the thread \e routine. Upon success, TRUE is returned.
+ //! Begin execution of the thread \e routine. Upon success, true is returned.
/*!
- The thread routine can be passed an argument via \e ptr. If
- the thread cannot be created, the return value is FALSE.
+ A data pointer can be supplied to the thread routine via the
+ optional \e ptr argument. If the thread cannot be created, the
+ return value is false.
*/
bool start( THREAD_FUNCTION routine, void * ptr = NULL );
- //! Wait the specified number of milliseconds for the thread to terminate. Return TRUE on success.
+ //! Signal cancellation of a thread routine, returning \e true on success.
/*!
- If the specified time value is negative, the function will
- block indefinitely. Otherwise, the function will block up to a
- maximum of the specified time. A return value of FALSE indicates
- the thread did not terminate within the specified time limit.
+ This function only signals thread cancellation. It does not
+ wait to verify actual routine termination. A \e true return value
+ only signifies that the cancellation signal was properly executed,
+ not thread cancellation. A thread routine may need to make use of
+ the testCancel() function to specify a cancellation point.
*/
- bool wait( long milliseconds = -1 );
+ bool cancel(void);
- //! Test for a thread cancellation request.
- static void test(void);
+ //! Block the calling routine indefinitely until the thread terminates.
+ /*!
+ This function suspends execution of the calling routine until the thread has terminated. It will return immediately if the thread was already terminated. A \e true return value signifies successful termination. A \e false return value indicates a problem with the wait call.
+ */
+ bool wait(void);
+
+ //! Create a cancellation point within a thread routine.
+ /*!
+ This function call checks for thread cancellation, allowing the
+ thread to be terminated if a cancellation request was previously
+ signaled.
+ */
+ void testCancel(void);
protected:
- THREAD_HANDLE thread;
+ THREAD_HANDLE thread_;
};
-class Mutex : public Stk
-{
- public:
- //! Default constructor.
- Mutex();
-
- //! Class destructor.
- ~Mutex();
-
- //! Lock the mutex.
- void lock(void);
-
- //! Unlock the mutex.
- void unlock(void);
-
- protected:
-
- MUTEX mutex;
-
-};
-
-#endif // defined(__THREAD_H)
+#endif
diff --git a/include/TubeBell.h b/include/TubeBell.h
index de203af..206a97a 100644
--- a/include/TubeBell.h
+++ b/include/TubeBell.h
@@ -26,12 +26,12 @@
type who should worry about this (making
money) worry away.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__TUBEBELL_H)
-#define __TUBEBELL_H
+#ifndef STK_TUBEBELL_H
+#define STK_TUBEBELL_H
#include "FM.h"
@@ -39,16 +39,31 @@ class TubeBell : public FM
{
public:
//! Class constructor.
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
TubeBell();
//! Class destructor.
~TubeBell();
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
};
#endif
diff --git a/include/TwoPole.h b/include/TwoPole.h
index f825541..9d15d06 100644
--- a/include/TwoPole.h
+++ b/include/TwoPole.h
@@ -8,12 +8,12 @@
frequency response while maintaining a nearly
constant filter gain.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__TWOPOLE_H)
-#define __TWOPOLE_H
+#ifndef STK_TWOPOLE_H
+#define STK_TWOPOLE_H
#include "Filter.h"
@@ -31,13 +31,13 @@ class TwoPole : protected Filter
void clear(void);
//! Set the b[0] coefficient value.
- void setB0(MY_FLOAT b0);
+ void setB0(StkFloat b0);
//! Set the a[1] coefficient value.
- void setA1(MY_FLOAT a1);
+ void setA1(StkFloat a1);
//! Set the a[2] coefficient value.
- void setA2(MY_FLOAT a2);
+ void setA2(StkFloat a2);
//! Sets the filter coefficients for a resonance at \e frequency (in Hz).
/*!
@@ -53,26 +53,35 @@ class TwoPole : protected Filter
An unstable filter will result for \e radius >= 1.0. For a better
resonance filter, use a BiQuad filter. \sa BiQuad filter class
*/
- void setResonance(MY_FLOAT frequency, MY_FLOAT radius, bool normalize = FALSE);
+ void setResonance(StkFloat frequency, StkFloat radius, bool normalize = false);
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
- void setGain(MY_FLOAT theGain);
+ void setGain(StkFloat gain);
//! Return the current filter gain.
- MY_FLOAT getGain(void) const;
+ StkFloat getGain(void) const;
//! Return the last computed output value.
- MY_FLOAT lastOut(void) const;
+ StkFloat lastOut(void) const;
//! Input one sample to the filter and return one output.
- MY_FLOAT tick(MY_FLOAT sample);
+ StkFloat tick(StkFloat sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
+
+ //! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding 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 );
};
#endif
diff --git a/include/TwoZero.h b/include/TwoZero.h
index 1449bc7..605772a 100644
--- a/include/TwoZero.h
+++ b/include/TwoZero.h
@@ -8,12 +8,12 @@
frequency response while maintaining a
constant filter gain.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__TWOZERO_H)
-#define __TWOZERO_H
+#ifndef STK_TWOZERO_H
+#define STK_TWOZERO_H
#include "Filter.h"
@@ -30,13 +30,13 @@ class TwoZero : protected Filter
void clear(void);
//! Set the b[0] coefficient value.
- void setB0(MY_FLOAT b0);
+ void setB0(StkFloat b0);
//! Set the b[1] coefficient value.
- void setB1(MY_FLOAT b1);
+ void setB1(StkFloat b1);
//! Set the b[2] coefficient value.
- void setB2(MY_FLOAT b2);
+ void setB2(StkFloat b2);
//! Sets the filter coefficients for a "notch" at \e frequency (in Hz).
/*!
@@ -49,26 +49,35 @@ class TwoZero : protected Filter
frequency. The closer the zeros are to the unit-circle (\e radius
close to or equal to one), the narrower the resulting notch width.
*/
- void setNotch(MY_FLOAT frequency, MY_FLOAT radius);
+ void setNotch(StkFloat frequency, StkFloat radius);
//! Set the filter gain.
/*!
The gain is applied at the filter input and does not affect the
coefficient values. The default gain value is 1.0.
*/
- void setGain(MY_FLOAT theGain);
+ void setGain(StkFloat gain);
//! Return the current filter gain.
- MY_FLOAT getGain(void) const;
+ StkFloat getGain(void) const;
//! Return the last computed output value.
- MY_FLOAT lastOut(void) const;
+ StkFloat lastOut(void) const;
//! Input one sample to the filter and return one output.
- MY_FLOAT tick(MY_FLOAT sample);
+ StkFloat tick(StkFloat sample);
//! Input \e vectorSize samples to the filter and return an equal number of outputs in \e vector.
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
+
+ //! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding 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 );
};
#endif
diff --git a/include/Vector3D.h b/include/Vector3D.h
index c031962..db0373a 100644
--- a/include/Vector3D.h
+++ b/include/Vector3D.h
@@ -4,50 +4,53 @@
This class implements a three-dimensional vector.
- by Perry R. Cook, 1995 - 2002.
+ by Perry R. Cook, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__VECTOR3D_H)
-#define __VECTOR3D_H
+#ifndef STK_VECTOR3D_H
+#define STK_VECTOR3D_H
-class Vector3D {
+#include "Stk.h"
+
+class Vector3D : public Stk
+{
public:
//! Default constructor taking optional initial X, Y, and Z values.
- Vector3D(double initX=0.0, double initY=0.0, double initZ=0.0);
+ Vector3D(StkFloat initX=0.0, StkFloat initY=0.0, StkFloat initZ=0.0);
//! Class destructor.
~Vector3D();
//! Get the current X value.
- double getX();
+ StkFloat getX();
//! Get the current Y value.
- double getY();
+ StkFloat getY();
//! Get the current Z value.
- double getZ();
+ StkFloat getZ();
//! Calculate the vector length.
- double getLength();
+ StkFloat getLength();
//! Set the X, Y, and Z values simultaniously.
- void setXYZ(double anX, double aY, double aZ);
+ void setXYZ(StkFloat x, StkFloat y, StkFloat z);
//! Set the X value.
- void setX(double aval);
+ void setX(StkFloat x);
//! Set the Y value.
- void setY(double aval);
+ void setY(StkFloat y);
//! Set the Z value.
- void setZ(double aval);
+ void setZ(StkFloat z);
protected:
- double myX;
- double myY;
- double myZ;
+ StkFloat myX_;
+ StkFloat myY_;
+ StkFloat myZ_;
};
#endif
diff --git a/include/VoicForm.h b/include/VoicForm.h
index 45cc622..f183a19 100644
--- a/include/VoicForm.h
+++ b/include/VoicForm.h
@@ -21,12 +21,12 @@
- Vibrato Gain = 1
- Loudness (Spectral Tilt) = 128
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__VOICFORM_H)
-#define __VOICFORM_H
+#ifndef STK_VOICFORM_H
+#define STK_VOICFORM_H
#include "Instrmnt.h"
#include "Envelope.h"
@@ -39,7 +39,10 @@
class VoicForm : public Instrmnt
{
public:
- //! Class constructor, taking the lowest desired playing frequency.
+ //! Class constructor.
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
VoicForm();
//! Class destructor.
@@ -49,22 +52,22 @@ class VoicForm : public Instrmnt
void clear();
//! Set instrument parameters for a particular frequency.
- void setFrequency(MY_FLOAT frequency);
+ void setFrequency(StkFloat frequency);
- //! Set instrument parameters for the given phoneme. Returns FALSE if phoneme not found.
+ //! Set instrument parameters for the given phoneme. Returns false if phoneme not found.
bool setPhoneme(const char* phoneme);
//! Set the voiced component gain.
- void setVoiced(MY_FLOAT vGain);
+ void setVoiced(StkFloat vGain);
//! Set the unvoiced component gain.
- void setUnVoiced(MY_FLOAT nGain);
+ void setUnVoiced(StkFloat nGain);
//! Set the sweep rate for a particular formant filter (0-3).
- void setFilterSweepRate(int whichOne, MY_FLOAT rate);
+ void setFilterSweepRate(unsigned int whichOne, StkFloat rate);
//! Set voiced component pitch sweep rate.
- void setPitchSweepRate(MY_FLOAT rate);
+ void setPitchSweepRate(StkFloat rate);
//! Start the voice.
void speak();
@@ -73,24 +76,36 @@ class VoicForm : public Instrmnt
void quiet();
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
protected:
- SingWave *voiced;
- Noise *noise;
- Envelope *noiseEnv;
- FormSwep *filters[4];
- OnePole *onepole;
- OneZero *onezero;
+ SingWave *voiced_;
+ Noise noise_;
+ Envelope noiseEnv_;
+ FormSwep filters_[4];
+ OnePole onepole_;
+ OneZero onezero_;
};
diff --git a/include/Voicer.h b/include/Voicer.h
index 76912c0..48a90bc 100644
--- a/include/Voicer.h
+++ b/include/Voicer.h
@@ -25,21 +25,21 @@
an ensemble. Alternately, control changes can
be sent to all voices on a given channel.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__VOICER_H)
-#define __VOICER_H
+#ifndef STK_VOICER_H
+#define STK_VOICER_H
-#include "Stk.h"
#include "Instrmnt.h"
+#include
class Voicer : public Stk
{
public:
- //! Class constructor taking the maximum number of instruments to control and an optional note decay time (in seconds).
- Voicer( int maxInstruments, MY_FLOAT decayTime=0.2 );
+ //! Class constructor taking an optional note decay time (in seconds).
+ Voicer( StkFloat decayTime=0.2 );
//! Class destructor.
~Voicer();
@@ -68,81 +68,93 @@ public:
found for a specified non-zero channel value, the function returns
-1. The amplitude value should be in the range 0.0 - 128.0.
*/
- long noteOn( MY_FLOAT noteNumber, MY_FLOAT amplitude, int channel=0 );
+ long noteOn( StkFloat noteNumber, StkFloat amplitude, int channel=0 );
//! Send a noteOff to all voices having the given noteNumber and optional channel (default channel = 0).
/*!
The amplitude value should be in the range 0.0 - 128.0.
*/
- void noteOff( MY_FLOAT noteNumber, MY_FLOAT amplitude, int channel=0 );
+ void noteOff( StkFloat noteNumber, StkFloat amplitude, int channel=0 );
//! Send a noteOff to the voice with the given note tag.
/*!
The amplitude value should be in the range 0.0 - 128.0.
*/
- void noteOff( long tag, MY_FLOAT amplitude );
+ void noteOff( long tag, StkFloat amplitude );
//! Send a frequency update message to all voices assigned to the optional channel argument (default channel = 0).
/*!
The \e noteNumber argument corresponds to a MIDI note number, though it is a floating-point value and can range beyond the normal 0-127 range.
*/
- void setFrequency( MY_FLOAT noteNumber, int channel=0 );
+ void setFrequency( StkFloat noteNumber, int channel=0 );
//! Send a frequency update message to the voice with the given note tag.
/*!
The \e noteNumber argument corresponds to a MIDI note number, though it is a floating-point value and can range beyond the normal 0-127 range.
*/
- void setFrequency( long tag, MY_FLOAT noteNumber );
+ void setFrequency( long tag, StkFloat noteNumber );
//! Send a pitchBend message to all voices assigned to the optional channel argument (default channel = 0).
- void pitchBend( MY_FLOAT value, int channel=0 );
+ void pitchBend( StkFloat value, int channel=0 );
//! Send a pitchBend message to the voice with the given note tag.
- void pitchBend( long tag, MY_FLOAT value );
+ void pitchBend( long tag, StkFloat value );
//! Send a controlChange to all instruments assigned to the optional channel argument (default channel = 0).
- void controlChange( int number, MY_FLOAT value, int channel=0 );
+ void controlChange( int number, StkFloat value, int channel=0 );
//! Send a controlChange to the voice with the given note tag.
- void controlChange( long tag, int number, MY_FLOAT value );
+ void controlChange( long tag, int number, StkFloat value );
//! Send a noteOff message to all existing voices.
void silence( void );
//! Mix the output for all sounding voices.
- MY_FLOAT tick();
+ StkFloat tick();
//! Compute \e vectorSize output mixes and return them in \e vector.
- MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ 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 );
//! Return the last output value.
- MY_FLOAT lastOut() const;
+ StkFloat lastOut() const;
//! Return the last left output value.
- MY_FLOAT lastOutLeft() const;
+ StkFloat lastOutLeft() const;
//! Return the last right output value.
- MY_FLOAT lastOutRight() const;
+ StkFloat lastOutRight() const;
protected:
- typedef struct {
+ struct Voice {
Instrmnt *instrument;
long tag;
- MY_FLOAT noteNumber;
- MY_FLOAT frequency;
+ StkFloat noteNumber;
+ StkFloat frequency;
int sounding;
int channel;
- } Voice;
- int nVoices;
- int maxVoices;
- Voice *voices;
- long tags;
- int muteTime;
- MY_FLOAT lastOutput;
- MY_FLOAT lastOutputLeft;
- MY_FLOAT lastOutputRight;
+ // Default constructor.
+ Voice()
+ :instrument(0), tag(0), noteNumber(-1.0), frequency(0.0),
+ sounding(0), channel(0) {}
+ };
+
+ std::vector voices_;
+ long tags_;
+ int muteTime_;
+ StkFloat lastOutput_;
+ StkFloat lastOutputLeft_;
+ StkFloat lastOutputRight_;
};
#endif
diff --git a/include/WaveLoop.h b/include/WaveLoop.h
index 6a67e7f..8576af1 100644
--- a/include/WaveLoop.h
+++ b/include/WaveLoop.h
@@ -14,21 +14,20 @@
For single-channel data, these methods return
equivalent values.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__WAVELOOP_H)
-#define __WAVELOOP_H
+#ifndef STK_WAVELOOP_H
+#define STK_WAVELOOP_H
#include "WvIn.h"
-#include
class WaveLoop : public WvIn
{
public:
//! Class constructor.
- WaveLoop( const char *fileName, bool raw = FALSE );
+ WaveLoop( std::string fileName, bool raw = false );
//! Class destructor.
virtual ~WaveLoop();
@@ -40,10 +39,10 @@ public:
corresponds to file cycles per second. The frequency can be
negative, in which case the loop is read in reverse order.
*/
- void setFrequency(MY_FLOAT aFrequency);
+ void setFrequency(StkFloat frequency);
//! Increment the read pointer by \e aTime samples, modulo file size.
- void addTime(MY_FLOAT aTime);
+ void addTime(StkFloat time);
//! Increment current read pointer by \e anAngle, relative to a looping frequency.
/*!
@@ -51,7 +50,7 @@ public:
size and the current Stk::sampleRate. The \e anAngle value
is a multiple of file size.
*/
- void addPhase(MY_FLOAT anAngle);
+ void addPhase(StkFloat angle);
//! Add a phase offset to the current read pointer.
/*!
@@ -59,18 +58,33 @@ public:
size and the current Stk::sampleRate. The \e anAngle value
is a multiple of file size.
*/
- void addPhaseOffset(MY_FLOAT anAngle);
+ void addPhaseOffset(StkFloat angle);
//! Return a pointer to the next sample frame of data.
- const MY_FLOAT *tickFrame(void);
+ const StkFloat *tickFrame(void);
+
+ //! Read out sample \e frames of data to \e frameVector.
+ /*!
+ An StkError will be thrown if a file is read incrementally and a read error occurs.
+ */
+ StkFloat *tickFrame(StkFloat *frameVector, unsigned int frames);
+
+ //! Fill the StkFrames object with sample frames of data and return the same reference.
+ /*!
+ An StkError will be thrown if a file is read incrementally and
+ a read error occurs or there is an incompatability between the
+ number of channels in the RtWvIn object and that in the StkFrames
+ object.
+ */
+ StkFrames& tickFrame( StkFrames& frames );
protected:
// Read file data.
void readData(unsigned long index);
- MY_FLOAT phaseOffset;
+ StkFloat phaseOffset_;
};
-#endif // defined(__WAVELOOP_H)
+#endif
diff --git a/include/Whistle.h b/include/Whistle.h
index 4bfec59..b788f6c 100644
--- a/include/Whistle.h
+++ b/include/Whistle.h
@@ -12,12 +12,12 @@
- Blowing Frequency Modulation = 2
- Volume = 128
- by Perry R. Cook 1996 - 2002.
+ by Perry R. Cook 1996 - 2004.
*/
/***************************************************/
-#if !defined(__WHISTLE_H)
-#define __WHISTLE_H
+#ifndef STK_WHISTLE_H
+#define STK_WHISTLE_H
#include "Instrmnt.h"
#include "Sphere.h"
@@ -31,6 +31,9 @@ class Whistle : public Instrmnt
{
public:
//! Class constructor.
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
Whistle();
//! Class destructor.
@@ -40,46 +43,58 @@ public:
void clear();
//! Set instrument parameters for a particular frequency.
- void setFrequency(MY_FLOAT frequency);
+ void setFrequency(StkFloat frequency);
//! Apply breath velocity to instrument with given amplitude and rate of increase.
- void startBlowing(MY_FLOAT amplitude, MY_FLOAT rate);
+ void startBlowing(StkFloat amplitude, StkFloat rate);
//! Decrease breath velocity with given rate of decrease.
- void stopBlowing(MY_FLOAT rate);
+ void stopBlowing(StkFloat rate);
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
- void controlChange(int number, MY_FLOAT value);
+ void controlChange(int number, StkFloat value);
protected:
- Vector3D *tempVectorP;
- Vector3D *tempVector;
- OnePole onepole;
- Noise noise;
- Envelope envelope;
- Sphere *can; // Declare a Spherical "can".
- Sphere *pea, *bumper; // One spherical "pea", and a spherical "bumper".
- WaveLoop *sine;
+ Vector3D *tempVectorP_;
+ Vector3D tempVector_;
+ OnePole onepole_;
+ Noise noise_;
+ Envelope envelope_;
+ Sphere can_; // Declare a Spherical "can".
+ Sphere pea_, bumper_; // One spherical "pea", and a spherical "bumper".
- MY_FLOAT baseFrequency;
- MY_FLOAT maxPressure;
- MY_FLOAT noiseGain;
- MY_FLOAT fippleFreqMod;
- MY_FLOAT fippleGainMod;
- MY_FLOAT blowFreqMod;
- MY_FLOAT tickSize;
- MY_FLOAT canLoss;
- int subSample, subSampCount;
+ WaveLoop *sine_;
+
+ StkFloat baseFrequency_;
+ StkFloat noiseGain_;
+ StkFloat fippleFreqMod_;
+ StkFloat fippleGainMod_;
+ StkFloat blowFreqMod_;
+ StkFloat tickSize_;
+ StkFloat canLoss_;
+ int subSample_, subSampCount_;
};
#endif
diff --git a/include/Wurley.h b/include/Wurley.h
index 1b3ee97..b5a0e47 100644
--- a/include/Wurley.h
+++ b/include/Wurley.h
@@ -26,12 +26,12 @@
type who should worry about this (making
money) worry away.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__WURLEY_H)
-#define __WURLEY_H
+#ifndef STK_WURLEY_H
+#define STK_WURLEY_H
#include "FM.h"
@@ -39,19 +39,34 @@ class Wurley : public FM
{
public:
//! Class constructor.
+ /*!
+ An StkError will be thrown if the rawwave path is incorrectly set.
+ */
Wurley();
//! Class destructor.
~Wurley();
//! Set instrument parameters for a particular frequency.
- void setFrequency(MY_FLOAT frequency);
+ void setFrequency(StkFloat frequency);
//! Start a note with the given frequency and amplitude.
- void noteOn(MY_FLOAT frequency, MY_FLOAT amplitude);
+ void noteOn(StkFloat frequency, 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 );
};
#endif
diff --git a/include/WvIn.h b/include/WvIn.h
index ba3d3c3..d60e21d 100644
--- a/include/WvIn.h
+++ b/include/WvIn.h
@@ -10,44 +10,49 @@
subsequent output. Linear interpolation is
used for fractional "read rates".
- WvIn supports multi-channel data in interleaved
- format. It is important to distinguish the
- tick() methods, which return samples produced
- by averaging across sample frames, from the
- tickFrame() methods, which return pointers to
- multi-channel sample frames. For single-channel
- data, these methods return equivalent values.
+ WvIn supports multi-channel data in
+ interleaved format. It is important to
+ distinguish the tick() methods, which return
+ samples produced by averaging across sample
+ frames, from the tickFrame() methods, which
+ return pointers to multi-channel sample
+ frames. For single-channel data, these
+ methods return equivalent values.
- Small files are completely read into local memory
- during instantiation. Large files are read
- incrementally from disk. The file size threshold
- and the increment size values are defined in
- WvIn.h.
+ Small files are completely read into local
+ memory during instantiation. Large files are
+ read incrementally from disk. The file size
+ threshold and the increment size values are
+ defined in WvIn.h.
+
+ When the end of a file is reached, subsequent
+ calls to the tick() functions return the data
+ values at the end of the file.
WvIn currently supports WAV, AIFF, SND (AU),
MAT-file (Matlab), and STK RAW file formats.
Signed integer (8-, 16-, and 32-bit) and floating-
point (32- and 64-bit) data types are supported.
- Uncompressed data types are not supported. If
- using MAT-files, data should be saved in an array
- with each data channel filling a matrix row.
+ Compressed data types are not supported. If using
+ MAT-files, data should be saved in an array with
+ each data channel filling a matrix row. The sample
+ rate for MAT-files is assumed to be 44100 Hz.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__WVIN_H)
-#define __WVIN_H
+#ifndef STK_WVIN_H
+#define STK_WVIN_H
// Files larger than CHUNK_THRESHOLD will be copied into memory
// in CHUNK_SIZE increments, rather than completely loaded into
// a buffer at once.
-#define CHUNK_THRESHOLD 5000000 // 5 Mb
-#define CHUNK_SIZE 1024 // sample frames
+const unsigned long CHUNK_THRESHOLD = 5000000; // 5 Mb
+const long CHUNK_SIZE = 1024; // sample frames
#include "Stk.h"
-#include
class WvIn : public Stk
{
@@ -60,7 +65,7 @@ public:
An StkError will be thrown if the file is not found, its format is
unknown, or a read error occurs.
*/
- WvIn( const char *fileName, bool raw = FALSE, bool doNormalize = TRUE );
+ WvIn( std::string fileName, bool raw = false, bool doNormalize = true );
//! Class destructor.
virtual ~WvIn();
@@ -70,7 +75,7 @@ public:
An StkError will be thrown if the file is not found, its format is
unknown, or a read error occurs.
*/
- void openFile( const char *fileName, bool raw = FALSE, bool doNormalize = TRUE );
+ void openFile( std::string fileName, bool raw = false, bool doNormalize = true );
//! If a file is open, close it.
void closeFile(void);
@@ -94,7 +99,7 @@ public:
(\e peak/maximum). For incrementally loaded files with floating-
point data types, direct scaling by \e peak is performed.
*/
- void normalize(MY_FLOAT peak);
+ void normalize(StkFloat peak);
//! Return the file size in sample frames.
unsigned long getSize(void) const;
@@ -108,7 +113,7 @@ public:
their headers. STK RAW files have a sample rate of 22050 Hz
by definition. MAT-files are assumed to have a rate of 44100 Hz.
*/
- MY_FLOAT getFileRate(void) const;
+ StkFloat getFileRate(void) const;
//! Query whether reading is complete.
bool isFinished(void) const;
@@ -117,10 +122,10 @@ public:
/*!
If the rate value is negative, the data is read in reverse order.
*/
- void setRate(MY_FLOAT aRate);
+ void setRate(StkFloat aRate);
//! Increment the read pointer by \e aTime samples.
- virtual void addTime(MY_FLOAT aTime);
+ virtual void addTime(StkFloat aTime);
//! Turn linear interpolation on/off.
/*!
@@ -132,34 +137,53 @@ public:
void setInterpolate(bool doInterpolate);
//! Return the average across the last output sample frame.
- virtual MY_FLOAT lastOut(void) const;
+ virtual StkFloat lastOut(void) const;
//! Read out the average across one sample frame of data.
/*!
An StkError will be thrown if a file is read incrementally and a read error occurs.
*/
- virtual MY_FLOAT tick(void);
+ virtual StkFloat tick(void);
//! Read out vectorSize averaged sample frames of data in \e vector.
/*!
An StkError will be thrown if a file is read incrementally and a read error occurs.
*/
- virtual MY_FLOAT *tick(MY_FLOAT *vector, unsigned int vectorSize);
+ virtual StkFloat *tick(StkFloat *vector, unsigned int vectorSize);
+
+ //! Fill a channel of the StkFrames object with averaged sample frames.
+ /*!
+ The \c channel argument should be one or greater (the first
+ channel is specified by 1). An StkError will be thrown if a file
+ is read incrementally and a read error occurs or 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 );
//! Return a pointer to the last output sample frame.
- virtual const MY_FLOAT *lastFrame(void) const;
+ virtual const StkFloat *lastFrame(void) const;
//! Return a pointer to the next sample frame of data.
/*!
An StkError will be thrown if a file is read incrementally and a read error occurs.
*/
- virtual const MY_FLOAT *tickFrame(void);
+ virtual const StkFloat *tickFrame(void);
//! Read out sample \e frames of data to \e frameVector.
/*!
An StkError will be thrown if a file is read incrementally and a read error occurs.
*/
- virtual MY_FLOAT *tickFrame(MY_FLOAT *frameVector, unsigned int frames);
+ virtual StkFloat *tickFrame(StkFloat *frameVector, unsigned int frames);
+
+ //! Fill the StkFrames object with sample frames of data and return the same reference.
+ /*!
+ An StkError will be thrown if a file is read incrementally and
+ a read error occurs or if there is an incompatability between the
+ number of channels in the WvIn object and that in the StkFrames
+ object.
+ */
+ virtual StkFrames& tickFrame( StkFrames& frames );
protected:
@@ -184,24 +208,23 @@ protected:
// Get MAT-file header information.
bool getMatInfo( const char *fileName );
- char msg[256];
- FILE *fd;
- MY_FLOAT *data;
- MY_FLOAT *lastOutput;
- bool chunking;
- bool finished;
- bool interpolate;
- bool byteswap;
- unsigned long fileSize;
- unsigned long bufferSize;
- unsigned long dataOffset;
- unsigned int channels;
- long chunkPointer;
- STK_FORMAT dataType;
- MY_FLOAT fileRate;
- MY_FLOAT gain;
- MY_FLOAT time;
- MY_FLOAT rate;
+ FILE *fd_;
+ StkFloat *data_;
+ StkFloat *lastOutputs_;
+ bool chunking_;
+ bool finished_;
+ bool interpolate_;
+ bool byteswap_;
+ unsigned long fileSize_;
+ unsigned long bufferSize_;
+ unsigned long dataOffset_;
+ unsigned int channels_;
+ long chunkPointer_;
+ StkFormat dataType_;
+ StkFloat fileRate_;
+ StkFloat gain_;
+ StkFloat time_;
+ StkFloat rate_;
};
-#endif // defined(__WVIN_H)
+#endif
diff --git a/include/WvOut.h b/include/WvOut.h
index 407bc63..815e8cb 100644
--- a/include/WvOut.h
+++ b/include/WvOut.h
@@ -14,32 +14,31 @@
tickFrame() method, which takes a pointer
to multi-channel sample frame data.
- WvOut currently supports WAV, AIFF, AIFC, SND
- (AU), MAT-file (Matlab), and STK RAW file
- formats. Signed integer (8-, 16-, and 32-bit)
- and floating- point (32- and 64-bit) data types
- are supported. STK RAW files use 16-bit
- integers by definition. MAT-files will always
- be written as 64-bit floats. If a data type
- specification does not match the specified file
- type, the data type will automatically be
- modified. Uncompressed data types are not
- supported.
+ WvOut currently supports uncompressed WAV,
+ AIFF, AIFC, SND (AU), MAT-file (Matlab), and
+ STK RAW file formats. Signed integer (8-,
+ 16-, and 32-bit) and floating- point (32- and
+ 64-bit) data types are supported. STK RAW
+ files use 16-bit integers by definition.
+ MAT-files will always be written as 64-bit
+ floats. If a data type specification does not
+ match the specified file type, the data type
+ will automatically be modified. Compressed
+ data types are not supported.
Currently, WvOut is non-interpolating and the
output rate is always Stk::sampleRate().
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
-#if !defined(__WVOUT_H)
-#define __WVOUT_H
+#ifndef STK_WVOUT_H
+#define STK_WVOUT_H
#include "Stk.h"
-#include
-#define BUFFER_SIZE 1024 // sample frames
+const unsigned long BUFFER_SIZE = 1024; // sample frames
class WvOut : public Stk
{
@@ -60,7 +59,7 @@ class WvOut : public Stk
/*!
An StkError is thrown for invalid argument values or if an error occurs when initializing the output file.
*/
- WvOut( const char *fileName, unsigned int nChannels = 1, FILE_TYPE type = WVOUT_WAV, Stk::STK_FORMAT format = STK_SINT16 );
+ WvOut( const char *fileName, unsigned int nChannels = 1, FILE_TYPE type = WVOUT_WAV, Stk::StkFormat format = STK_SINT16 );
//! Class destructor.
virtual ~WvOut();
@@ -70,7 +69,7 @@ class WvOut : public Stk
An StkError is thrown for invalid argument values or if an error occurs when initializing the output file.
*/
void openFile( const char *fileName, unsigned int nChannels = 1,
- WvOut::FILE_TYPE type = WVOUT_WAV, Stk::STK_FORMAT format = STK_SINT16 );
+ WvOut::FILE_TYPE type = WVOUT_WAV, Stk::StkFormat format = STK_SINT16 );
//! If a file is open, write out samples in the queue and then close it.
void closeFile( void );
@@ -79,25 +78,48 @@ class WvOut : public Stk
unsigned long getFrames( void ) const;
//! Return the number of seconds of data output.
- MY_FLOAT getTime( void ) const;
+ StkFloat getTime( void ) const;
+
+ //! Returns \c true if clipping has been detected during output since instantiation or the last reset.
+ bool getClipStatus( void ) { return clipping_; };
+
+ //! Reset the clipping status to \c false.
+ void resetClipStatus( void ) { clipping_ = false; };
//! Output a single sample to all channels in a sample frame.
/*!
An StkError is thrown if a file write error occurs.
*/
- virtual void tick(const MY_FLOAT sample);
+ virtual void tick(const StkFloat sample);
//! Output each sample in \e vector to all channels in \e vectorSize sample frames.
/*!
An StkError is thrown if a file write error occurs.
*/
- virtual void tick(const MY_FLOAT *vector, unsigned int vectorSize);
+ virtual void tick( const StkFloat *vector, unsigned int vectorSize );
+
+ //! Output a channel of the StkFrames object to all channels of the WvOut object.
+ /*!
+ The \c channel argument should be one or greater (the first
+ channel is specified by 1). An StkError will be thrown if a file
+ write error occurs or the \c channel argument is zero or it is
+ greater than the number of channels in the StkFrames object.
+ */
+ virtual void tick( const StkFrames& frames, unsigned int channel = 1 );
//! Output the \e frameVector of sample frames of the given length.
/*!
An StkError is thrown if a file write error occurs.
*/
- virtual void tickFrame(const MY_FLOAT *frameVector, unsigned int frames = 1);
+ virtual void tickFrame( const StkFloat *frameVector, unsigned int frames = 1);
+
+ //! Output the StkFrames data to the WvOut object.
+ /*!
+ An StkError will be thrown if a file write error occurs or if
+ there is an incompatability between the number of channels in the
+ WvOut object and that in the StkFrames object.
+ */
+ virtual void tickFrame( const StkFrames& frames );
protected:
@@ -107,6 +129,9 @@ class WvOut : public Stk
// Write data to output file;
virtual void writeData( unsigned long frames );
+ // Check for sample clipping and clamp.
+ void clipTest( StkFloat& sample );
+
// Write STK RAW file header.
bool setRawFile( const char *fileName );
@@ -134,16 +159,16 @@ class WvOut : public Stk
// Close MAT-file, updating the header.
void closeMatFile( void );
- char msg[256];
- FILE *fd;
- MY_FLOAT *data;
- FILE_TYPE fileType;
- STK_FORMAT dataType;
- bool byteswap;
- unsigned int channels;
- unsigned long counter;
- unsigned long totalCount;
+ FILE *fd_;
+ std::valarray data_;
+ FILE_TYPE fileType_;
+ StkFormat dataType_;
+ unsigned int channels_;
+ unsigned long counter_;
+ unsigned long totalCount_;
+ bool byteswap_;
+ bool clipping_;
};
-#endif // defined(__WVOUT_H)
+#endif
diff --git a/projects/demo/Drums b/projects/demo/Drums
new file mode 100755
index 0000000..31f2f5c
--- /dev/null
+++ b/projects/demo/Drums
@@ -0,0 +1 @@
+wish < tcl/Drums.tcl | ./demo Drummer -or -ip
\ No newline at end of file
diff --git a/projects/demo/Makefile.in b/projects/demo/Makefile.in
index c5fbcdd..ac5d4e5 100644
--- a/projects/demo/Makefile.in
+++ b/projects/demo/Makefile.in
@@ -6,14 +6,14 @@ SRC_PATH = ../../src
OBJECT_PATH = @object_path@
vpath %.o $(OBJECT_PATH)
-OBJECTS = Stk.o Noise.o SubNoise.o Envelope.o ADSR.o \
+OBJECTS = Stk.o Generator.o Noise.o SubNoise.o Envelope.o ADSR.o \
+ Modulate.o SingWave.o \
WvIn.o WaveLoop.o WvOut.o \
Filter.o OneZero.o OnePole.o PoleZero.o TwoZero.o \
BiQuad.o FormSwep.o Delay.o DelayL.o DelayA.o \
- ReedTabl.o JetTabl.o BowTabl.o \
- Reverb.o PRCRev.o \
- Modulate.o SingWave.o Voicer.o \
- Vector3D.o Sphere.o \
+ Function.o ReedTable.o JetTable.o BowTable.o \
+ Effect.o PRCRev.o \
+ Voicer.o Vector3D.o Sphere.o \
\
Instrmnt.o Clarinet.o BlowHole.o Saxofony.o Flute.o Brass.o BlowBotl.o \
Bowed.o Plucked.o StifKarp.o Sitar.o PluckTwo.o Mandolin.o Mesh2D.o \
@@ -21,7 +21,7 @@ OBJECTS = Stk.o Noise.o SubNoise.o Envelope.o ADSR.o \
Sampler.o Moog.o Simple.o Drummer.o Shakers.o \
Modal.o ModalBar.o BandedWG.o Resonate.o VoicForm.o Phonemes.o Whistle.o \
\
- Messager.o SKINI.o utilities.o
+ Messager.o Skini.o utilities.o
INCLUDE = @include@
ifeq ($(strip $(INCLUDE)), )
@@ -39,9 +39,8 @@ LIBRARY += @frameworks@
REALTIME = @realtime@
ifeq ($(REALTIME),yes)
- OBJECTS += RtMidi.o RtAudio.o RtWvOut.o Thread.o Socket.o
+ OBJECTS += RtMidi.o RtAudio.o Thread.o Mutex.o Socket.o
DEFS += @audio_apis@
- DEFS += @midiator@
endif
RAWWAVES = @rawwaves@
@@ -58,8 +57,14 @@ all : $(PROGRAMS)
demo: demo.cpp $(OBJECTS)
$(CC) $(CFLAGS) $(DEFS) -o demo demo.cpp $(OBJECT_PATH)/*.o $(LIBRARY)
-Md2Skini: Md2Skini.cpp Stk.o RtMidi.o Thread.o Socket.o
- $(CC) $(CFLAGS) $(DEFS) -o Md2Skini Md2Skini.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/RtMidi.o $(OBJECT_PATH)/Thread.o $(OBJECT_PATH)/Socket.o $(LIBRARY)
+libdemo: demo.cpp
+ $(CC) $(CFLAGS) $(DEFS) -o demo utilities.cpp demo.cpp -L../../src $(LIBRARY) -lstk
+
+Md2Skini: Md2Skini.cpp Stk.o RtMidi.o
+ $(CC) $(CFLAGS) $(DEFS) -o Md2Skini Md2Skini.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/RtMidi.o $(LIBRARY)
+
+libMd2Skini: Md2Skini.cpp
+ $(CC) $(CFLAGS) $(DEFS) -o Md2Skini Md2Skini.cpp -L../../src $(LIBRARY) -lstk
$(OBJECTS) : Stk.h
diff --git a/projects/demo/Md2Skini.cpp b/projects/demo/Md2Skini.cpp
index 147f561..f16c087 100644
--- a/projects/demo/Md2Skini.cpp
+++ b/projects/demo/Md2Skini.cpp
@@ -6,71 +6,171 @@
(via the RtMidi class), parses it, and turns it
into SKINI messages.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
#include "RtMidi.h"
-#include "Thread.h"
-#include "Socket.h"
#include "SKINI.msg"
#include
-#include
-#include
-
-// Exit thread declaration.
-extern "C" THREAD_RETURN THREAD_TYPE stdinMonitor(void * ptr);
+#include
+#include
void usage(void) {
- printf("\nuseage: Md2Skini \n\n");
- printf(" With no arguments, Md2Skini converts MIDI input to SKINI\n");
- printf(" format and sends the output directly to stdout.\n");
- printf(" With flag = -s , the output is sent over a socket\n");
- printf(" connection (port 2001) to the optional hostname (default = localhost).\n");
- printf(" With flag = -f , the output stream is simultaneously\n");
- printf(" written to the file specified by the optional \n");
- printf(" (default = test.ski).\n\n");
+ std::cout << "\nuseage: Md2Skini \n\n";
+ std::cout << " With no arguments, Md2Skini converts MIDI input to SKINI\n";
+ std::cout << " format and sends the output directly to stdout.\n";
+ std::cout << " With flag = -f , the output stream is simultaneously\n";
+ std::cout << " written to the file specified by the optional \n";
+ std::cout << " (default = test.ski).\n";
+ std::cout << " A MIDI input port can be specified with flag = -p portNumber.\n" << std::endl;
exit(0);
}
-int main(int argc,char *argv[])
+void midiCallback( double deltatime, std::vector< unsigned char > *bytes, void *userData )
{
- bool done = false, firstMessage = true, writeFile = false, useSocket = false;
- FILE *file = NULL;
- char fileName[256];
- char hostName[128];
- RtMidi *rtmidi = 0;
- Socket *soket = 0;
- Thread *thread = 0;
+ if ( bytes->size() < 2 ) return;
- if ( argc>5 ) {
- usage();
+ // Parse the MIDI bytes ... only keep MIDI channel messages.
+ if ( bytes->at(0) > 239 ) return;
+
+ register long type = bytes->at(0) & 0xF0;
+ register long channel = bytes->at(0) & 0x0F;
+ register long databyte1 = bytes->at(1);
+ register long databyte2 = 0;
+ if ( ( type != 0xC0 ) && ( type != 0xD0 ) ) {
+ if ( bytes->size() < 3 ) return;
+ databyte2 = bytes->at(2);
}
+ std::string typeName;
+ switch( type ) {
+ case __SK_NoteOn_:
+ if ( databyte2 == 0 ) {
+ typeName = "NoteOff\t\t";
+ databyte2 = 64;
+ }
+ else typeName = "NoteOn\t\t";
+ break;
+
+ case __SK_NoteOff_:
+ typeName = "NoteOff\t\t";
+ break;
+
+ case __SK_PolyPressure_:
+ typeName = "PolyPressure\t";
+ break;
+
+ case __SK_ProgramChange_:
+ typeName = "ProgramChange\t";
+ break;
+
+ case __SK_ChannelPressure_:
+ typeName = "ChannelPressure\t";
+ break;
+
+ case __SK_PitchBend_:
+ typeName = "PitchBend\t";
+ break;
+
+ case __SK_ControlChange_:
+
+ switch( databyte1 ) {
+ case __SK_PitchChange_:
+ typeName = "PitchChange\t";
+ break;
+
+ case __SK_Volume_:
+ typeName = "Volume\t";
+ break;
+
+ case __SK_ModWheel_:
+ typeName = "ModWheel\t";
+ break;
+
+ case __SK_Breath_:
+ typeName = "Breath\t\t";
+ break;
+
+ case __SK_FootControl_:
+ typeName = "FootControl\t";
+ break;
+
+ case __SK_Portamento_:
+ typeName = "Portamento\t";
+ break;
+
+ case __SK_Balance_:
+ typeName = "Balance\t";
+ break;
+
+ case __SK_Pan_:
+ typeName = "Pan\t\t";
+ break;
+
+ case __SK_Sustain_:
+ typeName = "Sustain\t";
+ break;
+
+ case __SK_Expression_:
+ typeName = "Expression\t";
+ break;
+
+ default:
+ typeName = "ControlChange\t";
+ break;
+ }
+
+ default:
+ typeName = "Unknown\t";
+ }
+
+ FILE *file = (FILE *) userData;
+ if ( type == 0xC0 || type == 0xD0 || type == 0xE0 ) { // program change, channel pressure, or pitchbend
+ fprintf( stdout, "%s %.3f %d %.1f\n", typeName.c_str(), 0.0, channel, (float)databyte1 );
+ if ( file != NULL )
+ fprintf( file, "%s %.3f %d %.1f\n", typeName.c_str(), deltatime, channel, (float)databyte1 );
+ }
+ else if ( type == 0xB0 ) { // control change
+ fprintf( stdout, "%s %.3f %d %.1f\n", typeName.c_str(), 0.0, channel, (float)databyte2 );
+ if ( file != NULL )
+ fprintf( file, "%s %.3f %d %.1f\n", typeName.c_str(), deltatime, channel, (float)databyte2 );
+ }
+ else { // noteon, noteoff, aftertouch, and unknown
+ fprintf( stdout, "%s %.3f %d %.1f %.1f\n", typeName.c_str(), 0.0, channel, (float)databyte1, (float)databyte2 );
+ if ( file != NULL )
+ fprintf( file, "%s %.3f %d %.1f %.1f\n", typeName.c_str(), deltatime, channel, (float)databyte1, (float)databyte2 );
+ }
+}
+
+int main( int argc,char *argv[] )
+{
+ FILE *file = NULL;
+ std::string fileName;
+ RtMidiIn *midiin = 0;
+ unsigned int port = 0;
+
+ if ( argc > 5 ) usage();
+
// Parse the command-line arguments.
int i = 1;
- while (i < argc) {
+ while ( i < argc ) {
if (argv[i][0] == '-') {
switch(argv[i][1]) {
- case 's':
- if ((i+1 < argc) && argv[i+1][0] != '-') {
- i++;
- strncpy(hostName, argv[i], 128);
- }
- else strcpy(hostName, "localhost");
- useSocket = true;
- break;
-
case 'f':
- if ((i+1 < argc) && argv[i+1][0] != '-') {
+ if ( (i+1 < argc) && argv[i+1][0] != '-' ) {
i++;
- strncpy(fileName, argv[i], 252);
- if ( strstr(fileName,".ski") == NULL ) strcat(fileName, ".ski");
+ fileName = argv[i];
+ if ( fileName.find( ".ski" ) == std::string::npos ) fileName.append( ".ski" );
}
- else strcpy(fileName, "test.ski");
- file = fopen(fileName,"wb");
- writeFile = true;
+ else fileName = "test.ski";
+ file = fopen( fileName.c_str(), "wb" );
+ break;
+
+ case 'p':
+ if ( i++ >= argc) usage();
+ port = (unsigned int) atoi( argv[i] );
break;
default:
@@ -82,234 +182,51 @@ int main(int argc,char *argv[])
i++;
}
- MY_FLOAT dt=0.0;
try {
- rtmidi = new RtMidi();
+ midiin = new RtMidiIn();
}
- catch (StkError &) {
- exit(0);
+ catch (RtError &error) {
+ error.printMessage();
+ if ( file != NULL ) fclose( file );
+ exit(EXIT_FAILURE);
}
- // If using sockets, setup the client socket
- if (useSocket) {
- try {
- soket = new Socket( 2001, hostName );
- }
- catch (StkError &) {
- exit(0);
- }
+ // Check available ports vs. specified.
+ unsigned int nPorts = midiin->getPortCount();
+ if ( nPorts == 0 ) {
+ std::cout << "No MIDI ports available!\n";
+ goto cleanup;
}
-
- // Start the "exit" thread.
- thread = new Thread();
- if ( !thread->start( (THREAD_FUNCTION)&stdinMonitor, (void *) &done ) ) {
- fprintf(stderr, "Unable to create exit thread ... aborting.\n");
+ else if ( port >= nPorts ) {
+ std::cout << "Invalid port specifier!\n";
goto cleanup;
}
- // Write SKINI messages to buffer 's'. This is the easiest way to
- // allow this single executable to work for both socketing and
- // printf's to stdout.
- char s[128];
- int channel, j;
- MY_FLOAT byte2, byte3;
- while ( !done ) {
- if (rtmidi->nextMessage() > 0) {
- byte3 = rtmidi->getByteThree();
- byte2 = rtmidi->getByteTwo();
- channel = rtmidi->getChannel();
- if (writeFile) dt = rtmidi->getDeltaTime();
- if (firstMessage) { // first MIDI message time stamp is meaningless
- dt = 0.0;
- firstMessage = false;
- }
-
- switch(rtmidi->getType()) {
- case __SK_NoteOn_:
- if (byte3 < 1.0) {
- sprintf(s,"NoteOff\t\t%.3f %d %.1f %.1f\n",0.0,channel,byte2,64.0);
- if (writeFile) {
- fprintf(file,"NoteOff\t\t%.3f %d %.1f %.1f\n",dt,channel,byte2,64.0);
- }
- } else {
- sprintf(s,"NoteOn\t\t%.3f %d %.1f %.1f\n",0.0,channel,byte2,byte3);
- if (writeFile) {
- fprintf(file,"NoteOn\t\t%.3f %d %.1f %.1f\n",dt,channel,byte2,byte3);
- }
- }
- break;
-
- case __SK_NoteOff_:
- if (byte3 < 2.0) byte3 = 64.0;
- sprintf(s,"NoteOff\t\t%.3f %d %.1f %.1f\n",0.0,channel,byte2,byte3);
- if (writeFile) {
- fprintf(file,"NoteOff\t\t%.3f %d %.1f %.1f\n",dt,channel,byte2,byte3);
- }
- break;
-
- case __SK_PolyPressure_:
- sprintf(s,"PolyPressure\t%.3f %d %.1f %.1f\n",0.0,channel,byte2,byte3);
- if (writeFile) {
- fprintf(file,"PolyPressure\t%.3f %d %.1f %.1f\n",dt,channel,byte2,byte3);
- }
- break;
-
- case __SK_ControlChange_:
- j = (int) byte2;
- switch(j) {
- case __SK_PitchChange_:
- sprintf(s,"PitchChange\t%.3f %d %.1f\n",0.0,channel,byte3);
- if (writeFile) {
- fprintf(file,"PitchChange\t%.3f %d %.1f\n",dt,channel,byte3);
- }
- break;
- case __SK_Volume_:
- sprintf(s,"Volume\t%.3f %d %.1f\n",0.0,channel,byte3);
- if (writeFile) {
- fprintf(file,"Volume\t%.3f %d %.1f\n",dt,channel,byte3);
- }
- break;
- case __SK_ModWheel_:
- sprintf(s,"ModWheel\t%.3f %d %.1f\n",0.0,channel,byte3);
- if (writeFile) {
- fprintf(file,"ModWheel\t%.3f %d %.1f\n",dt,channel,byte3);
- }
- break;
- case __SK_Breath_:
- sprintf(s,"Breath\t\t%.3f %d %.1f\n",0.0,channel,byte3);
- if (writeFile) {
- fprintf(file,"Breath\t\t%.3f %d %.1f\n",dt,channel,byte3);
- }
- break;
- case __SK_FootControl_:
- sprintf(s,"FootControl\t%.3f %d %.1f\n",0.0,channel,byte3);
- if (writeFile) {
- fprintf(file,"FootControl\t%.3f %d %.1f\n",dt,channel,byte3);
- }
- break;
- case __SK_Portamento_:
- sprintf(s,"Portamento\t%.3f %d %.1f\n",0.0,channel,byte3);
- if (writeFile) {
- fprintf(file,"Portamento\t%.3f %d %.1f\n",dt,channel,byte3);
- }
- break;
- case __SK_Balance_:
- sprintf(s,"Balance\t%.3f %d %.1f\n",0.0,channel,byte3);
- if (writeFile) {
- fprintf(file,"Balance\t%.3f %d %.1f\n",dt,channel,byte3);
- }
- break;
- case __SK_Pan_:
- sprintf(s,"Pan\t\t%.3f %d %.1f\n",0.0,channel,byte3);
- if (writeFile) {
- fprintf(file,"Pan\t\t%.3f %d %.1f\n",dt,channel,byte3);
- }
- break;
- case __SK_Sustain_:
- sprintf(s,"Sustain\t%.3f %d %.1f\n",0.0,channel,byte3);
- if (writeFile) {
- fprintf(file,"Sustain\t%.3f %d %.1f\n",dt,channel,byte3);
- }
- break;
- case __SK_Expression_:
- sprintf(s,"Expression\t%.3f %d %.1f\n",0.0,channel,byte3);
- if (writeFile) {
- fprintf(file,"Expression\t%.3f %d %.1f\n",dt,channel,byte3);
- }
- break;
- default:
- sprintf(s,"ControlChange\t%.3f %d %d %.1f\n",0.0,channel,j,byte3);
- if (writeFile) {
- fprintf(file,"ControlChange\t%.3f %d %d %.1f\n",dt,channel,j,byte3);
- }
- break;
- }
- break;
-
- case __SK_ProgramChange_:
- j = (int) byte2;
- sprintf(s,"ProgramChange\t%.3f %d %d\n",0.0,channel,j);
- if (writeFile) {
- fprintf(file,"ProgramChange\t%.3f %d %d\n",dt,channel,j);
- }
- break;
-
- case __SK_ChannelPressure_:
- sprintf(s,"ChannelPressure\t%.3f %d %.1f\n",0.0,channel,byte2);
- if (writeFile) {
- fprintf(file,"ChannelPressure\t%.3f %d %.1f\n",dt,channel,byte2);
- }
- break;
-
- case __SK_PitchBend_:
- sprintf(s,"PitchBend\t%.3f %d %f\n",0.0,channel,byte2);
- if (writeFile) {
- fprintf(file,"PitchBend\t%.3f %d %f\n",dt,channel,byte2);
- }
- break;
-
- default:
- sprintf(s,"// Unknown\t%.3f %d %f %f\n",0.0,channel,byte2,byte3);
- if (writeFile) {
- fprintf(file,"// Unknown\t\t%.3f %d %f %f\n",dt,channel,byte2,byte3);
- }
- break;
- }
-
- if (useSocket) {
- if ( soket->writeBuffer( s, strlen(s), 0 ) < 0 ) {
- fprintf(stderr,"Socket connection failed ... aborting.\n");
- goto cleanup;
- }
- }
- else {
- printf("%s", s);
- fflush(stdout);
- }
- memset(s, 0, sizeof(s));
- } else {
- // Sleep for 10 milliseconds
- Stk::sleep( 10 );
- }
+ // Open the port.
+ try {
+ midiin->openPort( port );
+ }
+ catch (RtError &error) {
+ error.printMessage();
+ goto cleanup;
}
- sprintf(s, "Exiting Md2Skini process ... bye!\n");
- if (useSocket)
- soket->writeBuffer( s, strlen(s), 0 );
- else {
- printf("%s", s);
- fflush(stdout);
- }
+ // Set our callback function. This should be done immediately after
+ // opening the port to avoid having incoming messages written to the
+ // queue instead of sent to the callback function.
+ midiin->setCallback( &midiCallback, file );
- if (writeFile) {
- printf("Wrote SKINI output to file %s.\n", fileName);
- fclose(file);
- }
+ // We'll ignore sysex, timing, and active sensing messages.
+ midiin->ignoreTypes( true, true, true );
+
+ std::cout << "\nReading MIDI input ... press to quit.\n";
+ char input;
+ std::cin.get(input);
cleanup:
- done = true;
- delete rtmidi;
- delete soket;
- delete thread;
+ delete midiin;
+ if ( file != NULL ) fclose( file );
- return 0;
-}
-
-THREAD_RETURN THREAD_TYPE stdinMonitor(void * ptr)
-{
- bool *done = (bool *) ptr;
- char inputString[128];
- printf("Type 'Exit' to quit.\n");
- while ( !*done ) {
- fgets(inputString, 128, stdin);
- if (inputString[3] == 't' && inputString[1] == 'x'
- && inputString[2] == 'i' && inputString[0] == 'E') {
- *done = true;
- }
- else {
- printf(inputString);
- fflush(stdout);
- }
- }
+ std::cout << "Md2Skini finished ... bye!" << std::endl;
return 0;
}
diff --git a/projects/demo/Md2Skini.dsp b/projects/demo/Md2Skini.dsp
index 98867fa..3ab2734 100644
--- a/projects/demo/Md2Skini.dsp
+++ b/projects/demo/Md2Skini.dsp
@@ -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 /Od /I "../../include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /Od /I "../../include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /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 /GZ /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS__" /D "__WINDOWS_MM__" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
@@ -99,16 +99,8 @@ SOURCE=..\..\src\SKINI.cpp
# End Source File
# Begin Source File
-SOURCE=..\..\src\Socket.cpp
-# End Source File
-# Begin Source File
-
SOURCE=..\..\src\Stk.cpp
# End Source File
-# Begin Source File
-
-SOURCE=..\..\src\Thread.cpp
-# End Source File
# End Group
# Begin Group "Header Files"
@@ -123,16 +115,8 @@ SOURCE=..\..\include\SKINI.h
# End Source File
# Begin Source File
-SOURCE=..\..\include\Socket.h
-# End Source File
-# Begin Source File
-
SOURCE=..\..\include\Stk.h
# End Source File
-# Begin Source File
-
-SOURCE=..\..\include\Thread.h
-# End Source File
# End Group
# Begin Group "Resource Files"
diff --git a/projects/demo/Modal b/projects/demo/Modal
new file mode 100755
index 0000000..474234b
--- /dev/null
+++ b/projects/demo/Modal
@@ -0,0 +1 @@
+wish < tcl/Modal.tcl | ./demo ModalBar -or -ip
\ No newline at end of file
diff --git a/projects/demo/Modal.bat b/projects/demo/Modal.bat
index 474234b..09d16b9 100755
--- a/projects/demo/Modal.bat
+++ b/projects/demo/Modal.bat
@@ -1 +1 @@
-wish < tcl/Modal.tcl | ./demo ModalBar -or -ip
\ No newline at end of file
+wish < tcl/Modal.tcl | demo ModalBar -or -ip
\ No newline at end of file
diff --git a/projects/demo/Physical b/projects/demo/Physical
new file mode 100755
index 0000000..f0e74fd
--- /dev/null
+++ b/projects/demo/Physical
@@ -0,0 +1 @@
+wish < tcl/Physical.tcl | ./demo Clarinet -or -ip
\ No newline at end of file
diff --git a/projects/demo/Physical.bat b/projects/demo/Physical.bat
index f0e74fd..ed11db8 100755
--- a/projects/demo/Physical.bat
+++ b/projects/demo/Physical.bat
@@ -1 +1 @@
-wish < tcl/Physical.tcl | ./demo Clarinet -or -ip
\ No newline at end of file
+wish < tcl/Physical.tcl | demo Clarinet -or -ip
\ No newline at end of file
diff --git a/projects/demo/Shakers b/projects/demo/Shakers
new file mode 100755
index 0000000..7ac5fd2
--- /dev/null
+++ b/projects/demo/Shakers
@@ -0,0 +1 @@
+wish < tcl/Shakers.tcl | ./demo Shakers -or -ip
\ No newline at end of file
diff --git a/projects/demo/StkDemo b/projects/demo/StkDemo
new file mode 100755
index 0000000..2670636
--- /dev/null
+++ b/projects/demo/StkDemo
@@ -0,0 +1 @@
+wish < tcl/Demo.tcl | ./demo Clarinet -or -ip
diff --git a/projects/demo/StkDemo.bat b/projects/demo/StkDemo.bat
index 2a6ee42..c0d025e 100755
--- a/projects/demo/StkDemo.bat
+++ b/projects/demo/StkDemo.bat
@@ -1 +1 @@
-wish < tcl/Demo.tcl | ./demo Clarinet -or -ip
\ No newline at end of file
+wish < tcl/Demo.tcl | demo Clarinet -or -ip
diff --git a/projects/demo/Voice b/projects/demo/Voice
new file mode 100755
index 0000000..ecd3085
--- /dev/null
+++ b/projects/demo/Voice
@@ -0,0 +1 @@
+wish < tcl/Voice.tcl | ./demo FMVoices -or -ip
\ No newline at end of file
diff --git a/projects/demo/Voice.bat b/projects/demo/Voice.bat
index ecd3085..9714b58 100755
--- a/projects/demo/Voice.bat
+++ b/projects/demo/Voice.bat
@@ -1 +1 @@
-wish < tcl/Voice.tcl | ./demo FMVoices -or -ip
\ No newline at end of file
+wish < tcl/Voice.tcl | demo FMVoices -or -ip
\ No newline at end of file
diff --git a/projects/demo/demo.cpp b/projects/demo/demo.cpp
index 2a0d2c0..9ee9fbb 100644
--- a/projects/demo/demo.cpp
+++ b/projects/demo/demo.cpp
@@ -1,35 +1,193 @@
// demo.cpp
//
-// An example STK program for voice playback and control.
+// An example STK program that allows voice playback and control of
+// most of the STK instruments.
#include "SKINI.msg"
#include "WvOut.h"
#include "Instrmnt.h"
#include "PRCRev.h"
#include "Voicer.h"
+#include "Skini.h"
+
+#if defined(__STK_REALTIME__)
+ #include "RtAudio.h"
+ #include "Mutex.h"
+#endif
// Miscellaneous command-line parsing and instrument allocation
// functions are defined in utilites.cpp ... specific to this program.
#include "utilities.h"
-#include
#include
-#include
#include
+#include
+#if !defined(__OS_WINDOWS__) // Windoze bogosity for VC++ 6.0
+ using std::min;
+#endif
bool done;
static void finish(int ignore){ done = true; }
-int main(int argc, char *argv[])
+// The TickData structure holds all the class instances and data that
+// are shared by the various processing functions.
+struct TickData {
+ WvOut **wvout;
+ Instrmnt **instrument;
+ Voicer *voicer;
+ Effect *reverb;
+ Messager messager;
+ Skini::Message message;
+ StkFloat volume;
+ StkFloat t60;
+ unsigned int nWvOuts;
+ int nVoices;
+ int currentVoice;
+ int channels;
+ int counter;
+ bool realtime;
+ bool settling;
+ bool haveMessage;
+
+ // Default constructor.
+ TickData()
+ : wvout(0), instrument(0), voicer(0), reverb(0), volume(1.0), t60(1.0),
+ nWvOuts(0), nVoices(1), currentVoice(0), channels(2), counter(0),
+ realtime( false ), settling( false ), haveMessage( false ) {}
+};
+
+#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 )
{
- Instrmnt **instrument = 0;
- WvOut **output = 0;
- Messager *messager = 0;
- Reverb *reverb = 0;
- Voicer *voicer = 0;
- int i, nVoices = 1;
- MY_FLOAT volume = 1.0;
- MY_FLOAT t60 = 1.0; // in seconds
+ register StkFloat value1 = data->message.floatValues[0];
+ register StkFloat value2 = data->message.floatValues[1];
+
+ switch( data->message.type ) {
+
+ case __SK_Exit_:
+ if ( data->settling == false ) goto settle;
+ done = true;
+ return;
+
+ case __SK_NoteOn_:
+ if ( value2 == 0.0 ) // velocity is zero ... really a NoteOff
+ data->voicer->noteOff( value1, 64.0 );
+ else // a NoteOn
+ data->voicer->noteOn( value1, value2 );
+ break;
+
+ case __SK_NoteOff_:
+ data->voicer->noteOff( value1, value2 );
+ break;
+
+ case __SK_ControlChange_:
+ if (value1 == 44.0)
+ data->reverb->setEffectMix(value2 * ONE_OVER_128);
+ else if (value1 == 7.0)
+ data->volume = value2 * ONE_OVER_128;
+ else if (value1 == 49.0)
+ data->voicer->setFrequency( value2 );
+ else
+ data->voicer->controlChange( (int) value1, value2 );
+ break;
+
+ case __SK_AfterTouch_:
+ data->voicer->controlChange( 128, value1 );
+ break;
+
+ case __SK_PitchChange_:
+ data->voicer->setFrequency( value1 );
+ break;
+
+ case __SK_PitchBend_:
+ data->voicer->pitchBend( value1 );
+ break;
+
+ case __SK_Volume_:
+ data->volume = value1 * ONE_OVER_128;
+ break;
+
+ case __SK_ProgramChange_:
+ if ( data->currentVoice == (int) value1 ) break;
+
+ // Two-stage program change process.
+ if ( data->settling == false ) goto settle;
+
+ // Stage 2: delete and reallocate new voice(s)
+ for ( int i=0; inVoices; i++ ) {
+ data->voicer->removeInstrument( data->instrument[i] );
+ delete data->instrument[i];
+ data->currentVoice = voiceByNumber( (int)value1, &data->instrument[i] );
+ if ( data->currentVoice < 0 )
+ data->currentVoice = voiceByNumber( 0, &data->instrument[i] );
+ data->voicer->addInstrument( data->instrument[i] );
+ data->settling = false;
+ }
+
+ } // end of switch
+
+ data->haveMessage = false;
+ return;
+
+ settle:
+ // Exit and program change messages are preceeded with a short settling period.
+ data->voicer->silence();
+ data->counter = (int) (0.3 * data->t60 * Stk::sampleRate());
+ data->settling = true;
+}
+
+
+// The tick() function handles sample computation and scheduling of
+// control updates. If doing realtime audio output, it will be called
+// automatically when the system needs a new buffer of audio samples.
+int tick(char *buffer, int bufferSize, void *dataPointer)
+{
+ TickData *data = (TickData *) dataPointer;
+ register StkFloat sample, *samples = (StkFloat *) buffer;
+ int 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 ( int i=0; ivolume * data->reverb->tick( data->voicer->tick() );
+ for ( unsigned int j=0; jnWvOuts; j++ ) data->wvout[j]->tick(sample);
+ if ( data->realtime )
+ for ( int k=0; kchannels; k++ ) *samples++ = sample;
+ nTicks--;
+ }
+ if ( nTicks == 0 ) break;
+
+ // Process control messages.
+ if ( data->haveMessage ) processMessage( data );
+ }
+
+ return 0;
+}
+
+int main( int argc, char *argv[] )
+{
+ TickData data;
+ int i;
+
+#if defined(__STK_REALTIME__)
+ RtAudio *dac = 0;
+#endif
// If you want to change the default sample rate (set in Stk.h), do
// it before instantiating any objects! If the sample rate is
@@ -38,151 +196,110 @@ int main(int argc, char *argv[])
// Check the command-line arguments for errors and to determine
// the number of WvOut objects to be instantiated (in utilities.cpp).
- int nOutputs = checkArgs(argc, argv);
- output = (WvOut **) calloc(nOutputs, sizeof(WvOut *));
+ data.nWvOuts = checkArgs(argc, argv);
+ data.wvout = (WvOut **) calloc(data.nWvOuts, sizeof(WvOut *));
// Instantiate the instrument(s) type from the command-line argument
// (in utilities.cpp).
- nVoices = countVoices(argc, argv);
- instrument = (Instrmnt **) calloc(nVoices, sizeof(Instrmnt *));
- int voice = voiceByName(argv[1], &instrument[0]);
- if ( voice < 0 ) {
- free( output );
- free( instrument );
+ data.nVoices = countVoices(argc, argv);
+ data.instrument = (Instrmnt **) calloc(data.nVoices, sizeof(Instrmnt *));
+ data.currentVoice = voiceByName(argv[1], &data.instrument[0]);
+ if ( data.currentVoice < 0 ) {
+ free( data.wvout );
+ free( data.instrument );
usage(argv[0]);
}
// If there was no error allocating the first voice, we should be fine for more.
- for ( i=1; iaddInstrument( instrument[i] );
+ data.voicer = (Voicer *) new Voicer( data.nVoices );
+ for ( i=0; iaddInstrument( data.instrument[i] );
// Parse the command-line flags, instantiate WvOut objects, and
// instantiate the input message controller (in utilities.cpp).
try {
- parseArgs(argc, argv, output, &messager);
+ data.realtime = parseArgs(argc, argv, data.wvout, data.messager);
}
catch (StkError &) {
goto cleanup;
}
- // Set the number of ticks between realtime messages (default =
- // RT_BUFFER_SIZE).
- messager->setRtDelta( 64 );
+ // If realtime output, allocate the dac here.
+#if defined(__STK_REALTIME__)
+ if ( data.realtime ) {
+ RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
+ int bufferSize = RT_BUFFER_SIZE;
+ try {
+ dac = new RtAudio(0, data.channels, 0, 0, format, (int)Stk::sampleRate(), &bufferSize, 4);
+ }
+ catch (RtError& error) {
+ error.printMessage();
+ goto cleanup;
+ }
+ }
+#endif
// Set the reverb parameters.
- reverb = new PRCRev( t60 );
- reverb->setEffectMix(0.2);
+ data.reverb = new PRCRev( data.t60 );
+ data.reverb->setEffectMix(0.2);
// Install an interrupt handler function.
(void) signal(SIGINT, finish);
- // The runtime loop begins here:
- done = FALSE;
- int nTicks, type, j;
- MY_FLOAT byte2, byte3, sample;
- while (!done) {
-
- // Look for new messages and return a delta time (in samples).
- type = messager->nextMessage();
- if (type < 0)
- done = TRUE;
-
- nTicks = messager->getDelta();
- for ( i=0; itick( voicer->tick() );
- for ( j=0; jtick(sample);
+ // If realtime output, set our callback function and start the dac.
+#if defined(__STK_REALTIME__)
+ if ( data.realtime ) {
+ try {
+ dac->setStreamCallback(&tick, (void *)&data);
+ dac->startStream();
}
-
- if ( type > 0 ) {
- // Process the new control message.
- byte2 = messager->getByteTwo();
- byte3 = messager->getByteThree();
-
- switch(type) {
-
- case __SK_NoteOn_:
- if (byte3 == 0.0) // velocity is zero ... really a NoteOff
- voicer->noteOff( byte2, 64.0 );
- else // a NoteOn
- voicer->noteOn( byte2, byte3 );
- break;
-
- case __SK_NoteOff_:
- voicer->noteOff( byte2, byte3 );
- break;
-
- case __SK_ControlChange_:
- if (byte2 == 44.0)
- reverb->setEffectMix(byte3 * ONE_OVER_128);
- else if (byte2 == 7.0)
- volume = byte3 * ONE_OVER_128;
- else if (byte2 == 49.0)
- voicer->setFrequency( byte3 );
- else
- voicer->controlChange( (int) byte2, byte3 );
- break;
-
- case __SK_AfterTouch_:
- voicer->controlChange( 128, byte2 );
- break;
-
- case __SK_PitchChange_:
- voicer->setFrequency( byte2 );
- break;
-
- case __SK_PitchBend_:
- voicer->pitchBend( byte2 );
- break;
-
- case __SK_Volume_:
- volume = byte2 * ONE_OVER_128;
- break;
-
- case __SK_ProgramChange_:
- if ( voice != (int) byte2 ) {
- voicer->silence();
- // Let the instrument(s) settle a bit.
- for ( i=0; i<4096; i++ ) {
- sample = reverb->tick( voicer->tick() );
- for ( j=0; jtick(sample);
- }
- for ( i=0; iremoveInstrument( instrument[i] );
- delete instrument[i];
- voice = voiceByNumber( (int)byte2, &instrument[i] );
- if ( voice < 0 )
- voice = voiceByNumber( 0, &instrument[i] );
- voicer->addInstrument( instrument[i] );
- }
- }
- }
+ catch (RtError &error) {
+ error.printMessage();
+ goto cleanup;
}
}
+#endif
- // Let the reverb settle a bit.
- nTicks = (long) (t60 * Stk::sampleRate());
- for ( i=0; itick( voicer->tick() );
- for ( j=0; jtick(sample);
+ // Setup finished.
+ while ( !done ) {
+#if defined(__STK_REALTIME__)
+ if ( data.realtime )
+ // Periodically check "done" status.
+ Stk::sleep( 200 );
+ else
+#endif
+ // Call the "tick" function to process data.
+ tick( NULL, 256, (void *)&data );
}
+ // Shut down the callback and output stream.
+#if defined(__STK_REALTIME__)
+ try {
+ dac->cancelStreamCallback();
+ dac->closeStream();
+ }
+ catch (RtError& error) {
+ error.printMessage();
+ }
+#endif
+
cleanup:
- for ( i=0; i900 } {
+ if { $patchnum<700 || ($patchnum>900 && $patchnum<2500) || $patchnum>=2600 } {
puts $outID [format "AfterTouch 0.0 1 %3.2f" $value]
flush $outID
}
diff --git a/projects/demo/utilities.cpp b/projects/demo/utilities.cpp
index 80d7974..676613e 100644
--- a/projects/demo/utilities.cpp
+++ b/projects/demo/utilities.cpp
@@ -36,10 +36,6 @@
#include "Resonate.h"
#include "Whistle.h"
-#if defined(__STK_REALTIME__)
- #include "RtWvOut.h"
-#endif
-
#define NUM_INSTS 28
// The order of the following list is important. The location of a particular
@@ -123,12 +119,13 @@ void usage(char *function) {
printf(" -os for .snd audio output file,\n");
printf(" -om for .mat audio output file,\n");
printf(" -oa for .aif audio output file,\n");
+ printf(" -if to read control input from SKINI file,\n");
#if defined(__STK_REALTIME__)
printf(" -or for realtime audio output,\n");
printf(" -ip for realtime control input by pipe,\n");
printf(" (won't work under Win95/98),\n");
printf(" -is for realtime control input by socket,\n");
- printf(" -im for realtime control input by MIDI,\n");
+ printf(" -im for realtime control input by MIDI (virtual port = 0, default = 1),\n");
#endif
printf(" and Instrument = one of these:\n");
for (i=0;i 17) usage(args[0]);
+ if (numArgs < 3 || numArgs > 22) usage(args[0]);
while (i < numArgs) {
if (args[i][0] == '-') {
if (args[i][1] == 'o') {
- if ( (args[i][2] == 'r') || (args[i][2] == 's') ||
- (args[i][2] == 'w') || (args[i][2] == 'm')
- || (args[i][2] == 'a') )
- numOutputs++;
+ if ( args[i][2] == 'r' ) realtime = true;
+ if ( (args[i][2] == 's') || (args[i][2] == 'w') ||
+ (args[i][2] == 'm') || (args[i][2] == 'a') )
+ nWvOuts++;
flags[0][j] = 'o';
flags[1][j++] = args[i][2];
}
else if (args[i][1] == 'i') {
if ( (args[i][2] != 's') && (args[i][2] != 'p') &&
- (args[i][2] != 'm') ) usage(args[0]);
+ (args[i][2] != 'm') && (args[i][2] != 'f') ) usage(args[0]);
flags[0][j] = 'i';
flags[1][j++] = args[i][2];
}
@@ -196,9 +194,9 @@ int checkArgs(int numArgs, char *args[])
}
// Make sure we have at least one output type
- if (numOutputs < 1) usage(args[0]);
+ if ( nWvOuts < 1 && !realtime ) usage(args[0]);
- return numOutputs;
+ return nWvOuts;
}
int countVoices(int nArgs, char *args[])
@@ -218,20 +216,24 @@ int countVoices(int nArgs, char *args[])
return nInstruments;
}
-void parseArgs(int numArgs, char *args[], WvOut **output, Messager **messager)
+bool parseArgs(int numArgs, char *args[], WvOut **output, Messager& messager)
{
int i = 2, j = 0;
- int inputMask = 0;
- int port = -1;
+ bool realtime = false;
char fileName[256];
while (i < numArgs) {
if ( (args[i][0] == '-') && (args[i][1] == 'i') ) {
switch(args[i][2]) {
+ case 'f':
+ strcpy(fileName,args[++i]);
+ if ( !messager.setScoreFile( fileName ) ) usage(args[0]);
+ break;
+
case 'p':
#if defined(__STK_REALTIME__)
- inputMask |= STK_PIPE;
+ if ( !messager.startStdInput() ) usage(args[0]);
break;
#else
usage(args[0]);
@@ -239,10 +241,12 @@ void parseArgs(int numArgs, char *args[], WvOut **output, Messager **messager)
case 's':
#if defined(__STK_REALTIME__)
- inputMask |= STK_SOCKET;
// Check for an optional socket port argument.
- if ((i+1 < numArgs) && args[i+1][0] != '-')
- port = atoi(args[++i]);
+ if ((i+1 < numArgs) && args[i+1][0] != '-') {
+ int port = atoi(args[++i]);
+ if ( !messager.startSocketInput( port ) ) usage(args[0]);
+ }
+ else if ( !messager.startSocketInput() ) usage(args[0]);
break;
#else
usage(args[0]);
@@ -250,7 +254,12 @@ void parseArgs(int numArgs, char *args[], WvOut **output, Messager **messager)
case 'm':
#if defined(__STK_REALTIME__)
- inputMask |= STK_MIDI;
+ // Check for an optional MIDI port argument.
+ if ((i+1 < numArgs) && args[i+1][0] != '-') {
+ int port = atoi(args[++i]);
+ if ( !messager.startMidiInput( port-1 ) ) usage(args[0]);
+ }
+ else if ( !messager.startMidiInput() ) usage(args[0]);
break;
#else
usage(args[0]);
@@ -266,8 +275,7 @@ void parseArgs(int numArgs, char *args[], WvOut **output, Messager **messager)
case 'r':
#if defined(__STK_REALTIME__)
- output[j] = (WvOut *) new RtWvOut(2);
- j++;
+ realtime = true;
break;
#else
usage(args[0]);
@@ -321,10 +329,5 @@ void parseArgs(int numArgs, char *args[], WvOut **output, Messager **messager)
i++;
}
- // Instantiate the messager.
- if ( inputMask & STK_SOCKET && port >= 0 )
- *messager = new Messager( inputMask, port );
- else
- *messager = new Messager( inputMask );
-
+ return realtime;
}
diff --git a/projects/demo/utilities.h b/projects/demo/utilities.h
index dabe4db..d868494 100644
--- a/projects/demo/utilities.h
+++ b/projects/demo/utilities.h
@@ -16,4 +16,4 @@ int checkArgs(int numArgs, char *args[]);
int countVoices(int nArgs, char *args[]);
-void parseArgs(int numArgs, char *args[], WvOut **output, Messager **messager);
+bool parseArgs(int numArgs, char *args[], WvOut **output, Messager& messager);
diff --git a/projects/effects/Effects b/projects/effects/Effects
new file mode 100755
index 0000000..f67da04
--- /dev/null
+++ b/projects/effects/Effects
@@ -0,0 +1 @@
+wish < tcl/Effects.tcl | ./effects -ip
diff --git a/projects/effects/Effects.bat b/projects/effects/Effects.bat
index f67da04..8d3a494 100755
--- a/projects/effects/Effects.bat
+++ b/projects/effects/Effects.bat
@@ -1 +1 @@
-wish < tcl/Effects.tcl | ./effects -ip
+wish < tcl/Effects.tcl | effects -ip
diff --git a/projects/effects/Makefile.in b/projects/effects/Makefile.in
index d09c6f4..25ec474 100644
--- a/projects/effects/Makefile.in
+++ b/projects/effects/Makefile.in
@@ -6,11 +6,11 @@ SRC_PATH = ../../src
OBJECT_PATH = @object_path@
vpath %.o $(OBJECT_PATH)
-OBJECTS = Stk.o Reverb.o PRCRev.o JCRev.o \
- NRev.o Delay.o Filter.o \
- SKINI.o Envelope.o Echo.o \
- PitShift.o DelayL.o Chorus.o \
- WvIn.o WaveLoop.o Messager.o
+OBJECTS = Stk.o Generator.o Envelope.o \
+ Filter.o Delay.o DelayL.o \
+ Effect.o Echo.o PitShift.o Chorus.o \
+ PRCRev.o JCRev.o NRev.o \
+ WvIn.o WaveLoop.o Skini.o Messager.o
INCLUDE = @include@
ifeq ($(strip $(INCLUDE)), )
@@ -28,9 +28,8 @@ LIBRARY += @frameworks@
REALTIME = @realtime@
ifeq ($(REALTIME),yes)
- OBJECTS += RtMidi.o RtAudio.o RtDuplex.o Thread.o Socket.o
+ OBJECTS += RtMidi.o RtAudio.o Thread.o Mutex.o Socket.o
DEFS += @audio_apis@
- DEFS += @midiator@
endif
RAWWAVES = @rawwaves@
@@ -47,6 +46,9 @@ all : $(PROGRAMS)
effects: effects.cpp $(OBJECTS)
$(CC) $(CFLAGS) $(DEFS) -o effects effects.cpp $(OBJECT_PATH)/*.o $(LIBRARY)
+libeffects: effects.cpp
+ $(CC) $(CFLAGS) $(DEFS) -o effects effects.cpp -L../../src $(LIBRARY) -lstk
+
$(OBJECTS) : Stk.h
clean :
diff --git a/projects/effects/effects.cpp b/projects/effects/effects.cpp
index 630948f..310678f 100644
--- a/projects/effects/effects.cpp
+++ b/projects/effects/effects.cpp
@@ -1,7 +1,6 @@
/************** Effects Program *********************/
-#include "RtDuplex.h"
-#include "SKINI.h"
+#include "Skini.h"
#include "SKINI.msg"
#include "Envelope.h"
#include "PRCRev.h"
@@ -10,183 +9,256 @@
#include "Echo.h"
#include "PitShift.h"
#include "Chorus.h"
-
-// The input control handler.
#include "Messager.h"
+#include "RtAudio.h"
+
+#include
+#include
+#include
+#if !defined(__OS_WINDOWS__) // Windoze bogosity for VC++ 6.0
+ using std::min;
+#endif
void usage(void) {
- /* Error function in case of incorrect command-line argument specifications */
- printf("\nuseage: effects 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 for realtime SKINI input by socket.\n");
+ // Error function in case of incorrect command-line argument specifications
+ std::cout << "\nuseage: effects 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 for realtime SKINI input by socket.\n";
exit(0);
}
-int main(int argc,char *argv[])
+bool done;
+static void finish(int ignore){ done = true; }
+
+// The TickData structure holds all the class instances and data that
+// are shared by the various processing functions.
+struct TickData {
+ Effect *effect;
+ PRCRev prcrev;
+ JCRev jcrev;
+ NRev nrev;
+ Echo echo;
+ PitShift shifter;
+ Chorus chorus;
+ Envelope envelope;
+ Messager messager;
+ Skini::Message message;
+ StkFloat lastSample;
+ StkFloat t60;
+ int counter;
+ bool settling;
+ bool haveMessage;
+
+ // Default constructor.
+ TickData()
+ : effect(0), t60(1.0), counter(0),
+ settling( false ), haveMessage( false ) {}
+};
+
+#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;
+ done = true;
+ return;
+
+ case __SK_NoteOn_:
+ if ( value2 == 0.0 ) // velocity is zero ... really a NoteOff
+ data->envelope.setTarget( 0.0 );
+ else // a NoteOn
+ data->envelope.setTarget( 1.0 );
+ break;
+
+ case __SK_NoteOff_:
+ data->envelope.setTarget( 0.0 );
+ break;
+
+ case __SK_ControlChange_:
+ // Change all effect values so they are "synched" to the interface.
+ switch ( value1 ) {
+
+ case 20: { // effect type change
+ int type = data->message.intValues[1];
+ if ( type == 0 )
+ data->effect = &(data->echo);
+ else if ( type == 1 )
+ data->effect = &(data->shifter);
+ else if ( type == 2 )
+ data->effect = &(data->chorus);
+ else if ( type == 3 )
+ data->effect = &(data->prcrev);
+ else if ( type == 4 )
+ data->effect = &(data->jcrev);
+ else if ( type == 5 )
+ data->effect = &(data->nrev);
+ break;
+ }
+
+ case 22: // effect parameter change 1
+ data->echo.setDelay( (unsigned long) (temp * Stk::sampleRate() * 0.95) );
+ // data->shifter.setShift( temp * 3 + 0.25);
+ data->shifter.setShift( 1.4 * temp + 0.3);
+ data->chorus.setModFrequency( temp );
+ data->prcrev.setT60( temp * 10.0 );
+ data->jcrev.setT60( temp * 10.0 );
+ data->nrev.setT60( temp * 10.0 );
+ break;
+
+ case 23: // effect parameter change 2
+ data->chorus.setModDepth( temp * 0.2 );
+ break;
+
+ case 44: // effect mix
+ data->echo.setEffectMix( temp );
+ data->shifter.setEffectMix( temp );
+ data->chorus.setEffectMix( temp );
+ data->prcrev.setEffectMix( temp );
+ data->jcrev.setEffectMix( temp );
+ data->nrev.setEffectMix( temp );
+ 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->envelope.setTarget( 0.0 );
+ data->counter = (int) (0.3 * data->t60 * Stk::sampleRate());
+ data->settling = true;
+}
+
+// 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 sample, *samples = (StkFloat *) buffer;
+ int i, 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; ienvelope.tick() * data->effect->tick( *samples );
+ *samples++ = sample; // two channels interleaved
+ *samples++ = sample;
+ nTicks--;
+ }
+ if ( nTicks == 0 ) break;
+
+ // Process control messages.
+ if ( data->haveMessage ) processMessage( data );
+ }
+
+ return 0;
+}
+
+
+int main( int argc, char *argv[] )
+{
+ TickData data;
+ RtAudio *adac = 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 );
- int port = -1;
- int controlMask = 0;
- for (int k=1; k= 0 )
- messager = new Messager( controlMask, port );
- else
- messager = new Messager( controlMask );
+ adac = new RtAudio(0, 2, 0, 2, format, (int)Stk::sampleRate(), &bufferSize, 4);
}
- catch (StkError &) {
+ catch (RtError& error) {
+ error.printMessage();
goto cleanup;
}
- // The runtime loop begins here:
- long i, nTicks;
- int type;
- lastSample = 0.0;
- inSample = 0.0;
- MY_FLOAT byte2, byte3;
- done = FALSE;
- while (!done) {
+ data.envelope.setRate( 0.001 );
+ data.effect = &(data.echo);
- // Look for new messages and return a delta time (in samples).
- type = messager->nextMessage();
- if (type < 0)
- done = TRUE;
+ // Install an interrupt handler function.
+ (void) signal( SIGINT, finish );
- nTicks = messager->getDelta();
-
- for (i=0; itick(envelope->tick() * echo->tick(lastSample));
- else if (effect == 1)
- inSample = inout->tick(envelope->tick() * shifter->tick(lastSample));
- else if (effect == 2)
- inSample = inout->tick(envelope->tick() * chorus->tick(lastSample));
- else if (effect == 3)
- inSample = inout->tick(envelope->tick() * prcrev->tick(lastSample));
- else if (effect == 4)
- inSample = inout->tick(envelope->tick() * jcrev->tick(lastSample));
- else if (effect == 5)
- inSample = inout->tick(envelope->tick() * nrev->tick(lastSample));
- lastSample = inSample;
- }
-
- if (type > 0) {
- // parse the input control message
-
- byte2 = messager->getByteTwo();
- byte3 = messager->getByteThree();
-
- switch(type) {
-
- case __SK_NoteOn_:
- if (byte3 == 0) { // velocity is zero ... really a NoteOff
- envelope->setRate(0.001);
- envelope->setTarget(0.0);
- }
- else { // really a NoteOn
- envelope->setRate(0.001);
- envelope->setTarget(1.0);
- }
- break;
-
- case __SK_NoteOff_:
- envelope->setRate(0.001);
- envelope->setTarget(0.0);
- break;
-
- case __SK_ControlChange_:
- if (byte2 == 20) effect = (int) byte3; // effect change
- else if (byte2 == 44) { // effects mix
- echo->setEffectMix(byte3*ONE_OVER_128);
- shifter->setEffectMix(byte3*ONE_OVER_128);
- chorus->setEffectMix(byte3*ONE_OVER_128);
- prcrev->setEffectMix(byte3*ONE_OVER_128);
- jcrev->setEffectMix(byte3*ONE_OVER_128);
- nrev->setEffectMix(byte3*ONE_OVER_128);
- }
- else if (byte2 == 22) { // effect1 parameter change
- echo->setDelay(byte3*ONE_OVER_128*Stk::sampleRate()*0.95);
- shifter->setShift(byte3*ONE_OVER_128*3 + 0.25);
- chorus->setModFrequency(byte3*ONE_OVER_128);
- }
- else if (byte2 == 23) { // effect1 parameter change
- chorus->setModDepth(byte3*ONE_OVER_128*0.2);
- }
- break;
- }
- }
+ // If realtime output, set our callback function and start the dac.
+ try {
+ adac->setStreamCallback( &tick, (void *)&data );
+ adac->startStream();
+ }
+ catch (RtError &error) {
+ error.printMessage();
+ goto cleanup;
}
- envelope->setRate(0.001);
- envelope->setTarget(0.0);
- nTicks = (long) Stk::sampleRate();
- for (i=0; itick(envelope->tick() * echo->tick(lastSample));
- else if (effect == 1)
- inSample = inout->tick(envelope->tick() * shifter->tick(lastSample));
- else if (effect == 2)
- inSample = inout->tick(envelope->tick() * chorus->tick(lastSample));
- else if (effect == 3)
- inSample = inout->tick(envelope->tick() * prcrev->tick(lastSample));
- else if (effect == 4)
- inSample = inout->tick(envelope->tick() * jcrev->tick(lastSample));
- else if (effect == 5)
- inSample = inout->tick(envelope->tick() * nrev->tick(lastSample));
- lastSample = inSample;
+ // Setup finished.
+ while ( !done ) {
+ // Periodically check "done" status.
+ Stk::sleep( 50 );
}
- delete echo;
- delete shifter;
- delete chorus;
- delete prcrev;
- delete jcrev;
- delete nrev;
- delete score;
- delete envelope;
+ // Shut down the callback and output stream.
+ try {
+ adac->cancelStreamCallback();
+ adac->closeStream();
+ }
+ catch (RtError& error) {
+ error.printMessage();
+ }
cleanup:
- delete messager;
- delete inout;
- printf("effects finished ... goodbye.\n");
+ delete adac;
+
+ std::cout << "\neffects finished ... goodbye.\n\n";
return 0;
}
diff --git a/projects/effects/effects.dsp b/projects/effects/effects.dsp
index 7d6e71d..56a70d8 100644
--- a/projects/effects/effects.dsp
+++ b/projects/effects/effects.dsp
@@ -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
@@ -67,7 +67,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
@@ -118,6 +118,14 @@ SOURCE=..\..\include\Echo.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=.\effects.cpp
# End Source File
# Begin Source File
@@ -138,6 +146,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\JCRev.cpp
# End Source File
# Begin Source File
@@ -154,6 +170,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\NRev.cpp
# End Source File
# Begin Source File
@@ -178,14 +202,6 @@ SOURCE=..\..\include\PRCRev.h
# 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
@@ -194,14 +210,6 @@ SOURCE=..\..\include\RtAudio.h
# End Source File
# Begin Source File
-SOURCE=..\..\src\RtDuplex.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\include\RtDuplex.h
-# End Source File
-# Begin Source File
-
SOURCE=..\..\src\RtMidi.cpp
# End Source File
# Begin Source File
diff --git a/projects/effects/tcl/Effects.tcl b/projects/effects/tcl/Effects.tcl
index 363924a..f8cb927 100644
--- a/projects/effects/tcl/Effects.tcl
+++ b/projects/effects/tcl/Effects.tcl
@@ -26,7 +26,7 @@ label .title -text "STK Effects Controller" \
-font {Times 14 bold} -background white \
-foreground darkred -relief raised
-label .title2 -text "by Gary P. Scavone\n Center for Computer Research in Music & Acoustics (CCRMA) \n Stanford University" \
+label .title2 -text "by Gary P. Scavone\n Music Technology, McGill University" \
-font {Times 12 bold} -background white \
-foreground darkred -relief raised
@@ -50,7 +50,7 @@ frame .left -bg black
scale .left.effectsmix -from 0 -to 127 -length 400 \
-command {printWhatz "ControlChange 0.0 1 " 44} \
--orient horizontal -label "Effects Mix" \
+-orient horizontal -label "Effects Mix (0% effect - 100% effect)" \
-tickinterval 32 -showvalue true -bg grey66 \
-variable mixlevel
@@ -132,7 +132,7 @@ proc changeEffect {tag value1 value2 } {
.left.effect2 config -state disabled -label "Disabled"
}
if ($value2==1) {
- .left.effect1 config -state normal -label "Pitch Shift Amount"
+ .left.effect1 config -state normal -label "Pitch Shift Amount (center = no shift)"
.left.effect2 config -state disabled -label "Disabled"
}
if ($value2==2) {
@@ -140,7 +140,7 @@ proc changeEffect {tag value1 value2 } {
.left.effect2 config -state normal -label "Chorus Modulation Depth"
}
if {$value2>=3 && $value2<=5} {
- .left.effect1 config -state disabled -label "Disabled"
+ .left.effect1 config -state normal -label "T60 Decay Time ( 0 - 10 seconds)"
.left.effect2 config -state disabled -label "Disabled"
}
puts $outID [format "%s %i %f" $tag $value1 $value2]
diff --git a/projects/examples/Makefile.in b/projects/examples/Makefile.in
index 7c04e0b..c242d66 100644
--- a/projects/examples/Makefile.in
+++ b/projects/examples/Makefile.in
@@ -1,6 +1,6 @@
### STK examples Makefile - for various flavors of unix
-PROGRAMS = sine play record io tcpIn tcpOut sineosc rtsine bethree controlbee foursine threebees
+PROGRAMS = sine play record io tcpIn tcpOut sineosc rtsine crtsine bethree controlbee foursine threebees playsmf
RM = /bin/rm
SRC_PATH = ../../src
OBJECT_PATH = @object_path@
@@ -23,7 +23,6 @@ LIBRARY += @frameworks@
REALTIME = @realtime@
ifeq ($(REALTIME),yes)
DEFS += @audio_apis@
- DEFS += @midiator@
endif
RAWWAVES = @rawwaves@
@@ -46,8 +45,8 @@ clean :
strip :
strip $(PROGRAMS)
-play: play.cpp Stk.o WvIn.o WvOut.o RtWvOut.o RtAudio.o
- $(CC) $(CFLAGS) $(DEFS) -o play play.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/WvIn.o $(OBJECT_PATH)/WvOut.o $(OBJECT_PATH)/RtWvOut.o $(OBJECT_PATH)/RtAudio.o $(LIBRARY)
+play: play.cpp Stk.o WvIn.o RtAudio.o
+ $(CC) $(CFLAGS) $(DEFS) -o play play.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/WvIn.o $(OBJECT_PATH)/RtAudio.o $(LIBRARY)
record: record.cpp Stk.o WvIn.o WvOut.o RtWvIn.o RtAudio.o
$(CC) $(CFLAGS) $(DEFS) -o record record.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/WvIn.o $(OBJECT_PATH)/WvOut.o $(OBJECT_PATH)/RtWvIn.o $(OBJECT_PATH)/RtAudio.o $(LIBRARY)
@@ -58,11 +57,11 @@ sine: sine.cpp Stk.o WvIn.o WvOut.o WaveLoop.o
io: io.cpp Stk.o RtAudio.o RtDuplex.o
$(CC) $(CFLAGS) $(DEFS) -o io io.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/RtAudio.o $(OBJECT_PATH)/RtDuplex.o $(LIBRARY)
-tcpIn: tcpIn.cpp Stk.o WvIn.o TcpWvIn.o WvOut.o RtWvOut.o RtAudio.o Socket.o Thread.o
- $(CC) $(CFLAGS) $(DEFS) -o tcpIn tcpIn.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/WvIn.o $(OBJECT_PATH)/Socket.o $(OBJECT_PATH)/Thread.o $(OBJECT_PATH)/TcpWvIn.o $(OBJECT_PATH)/WvOut.o $(OBJECT_PATH)/RtWvOut.o $(OBJECT_PATH)/RtAudio.o $(LIBRARY)
+tcpIn: tcpIn.cpp Stk.o WvIn.o TcpWvIn.o WvOut.o RtWvOut.o RtAudio.o Socket.o Thread.o Mutex.o
+ $(CC) $(CFLAGS) $(DEFS) -o tcpIn tcpIn.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/WvIn.o $(OBJECT_PATH)/Socket.o $(OBJECT_PATH)/Thread.o $(OBJECT_PATH)/Mutex.o $(OBJECT_PATH)/TcpWvIn.o $(OBJECT_PATH)/WvOut.o $(OBJECT_PATH)/RtWvOut.o $(OBJECT_PATH)/RtAudio.o $(LIBRARY)
-tcpOut: tcpOut.cpp Stk.o WvIn.o WvOut.o TcpWvOut.o Socket.o Thread.o
- $(CC) $(CFLAGS) $(DEFS) -o tcpOut tcpOut.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/WvIn.o $(OBJECT_PATH)/WvOut.o $(OBJECT_PATH)/Socket.o $(OBJECT_PATH)/Thread.o $(OBJECT_PATH)/TcpWvOut.o $(LIBRARY)
+tcpOut: tcpOut.cpp Stk.o WvIn.o WvOut.o TcpWvOut.o Socket.o Thread.o Mutex.o
+ $(CC) $(CFLAGS) $(DEFS) -o tcpOut tcpOut.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/WvIn.o $(OBJECT_PATH)/WvOut.o $(OBJECT_PATH)/Socket.o $(OBJECT_PATH)/Thread.o $(OBJECT_PATH)/Mutex.o $(OBJECT_PATH)/TcpWvOut.o $(LIBRARY)
sineosc: sineosc.cpp Stk.o WvIn.o WvOut.o WaveLoop.o
$(CC) $(CFLAGS) $(DEFS) -o sineosc sineosc.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/WvIn.o $(OBJECT_PATH)/WvOut.o $(OBJECT_PATH)/WaveLoop.o $(LIBRARY)
@@ -70,14 +69,20 @@ sineosc: sineosc.cpp Stk.o WvIn.o WvOut.o WaveLoop.o
rtsine: rtsine.cpp Stk.o WvIn.o WaveLoop.o WvOut.o RtWvOut.o RtAudio.o
$(CC) $(CFLAGS) $(DEFS) -o rtsine rtsine.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/WvIn.o $(OBJECT_PATH)/WaveLoop.o $(OBJECT_PATH)/WvOut.o $(OBJECT_PATH)/RtWvOut.o $(OBJECT_PATH)/RtAudio.o $(LIBRARY)
-bethree: bethree.cpp Stk.o WvIn.o WaveLoop.o FM.o WvOut.o RtWvOut.o RtAudio.o Instrmnt.o Filter.o TwoZero.o Envelope.o ADSR.o BeeThree.o
- $(CC) $(CFLAGS) $(DEFS) -o bethree bethree.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/WvIn.o $(OBJECT_PATH)/WaveLoop.o $(OBJECT_PATH)/FM.o $(OBJECT_PATH)/WvOut.o $(OBJECT_PATH)/RtWvOut.o $(OBJECT_PATH)/RtAudio.o $(OBJECT_PATH)/Instrmnt.o $(OBJECT_PATH)/Filter.o $(OBJECT_PATH)/TwoZero.o $(OBJECT_PATH)/Envelope.o $(OBJECT_PATH)/ADSR.o $(OBJECT_PATH)/BeeThree.o $(LIBRARY)
+crtsine: crtsine.cpp Stk.o WvIn.o WaveLoop.o RtAudio.o
+ $(CC) $(CFLAGS) $(DEFS) -o crtsine crtsine.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/WvIn.o $(OBJECT_PATH)/WaveLoop.o $(OBJECT_PATH)/RtAudio.o $(LIBRARY)
-controlbee: controlbee.cpp Stk.o WvIn.o WaveLoop.o FM.o WvOut.o RtWvOut.o RtAudio.o Instrmnt.o Filter.o TwoZero.o Envelope.o ADSR.o BeeThree.o Messager.o RtMidi.o Socket.o Thread.o SKINI.o
- $(CC) $(CFLAGS) $(DEFS) -o controlbee controlbee.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/WvIn.o $(OBJECT_PATH)/WaveLoop.o $(OBJECT_PATH)/FM.o $(OBJECT_PATH)/WvOut.o $(OBJECT_PATH)/RtWvOut.o $(OBJECT_PATH)/RtAudio.o $(OBJECT_PATH)/Instrmnt.o $(OBJECT_PATH)/Filter.o $(OBJECT_PATH)/TwoZero.o $(OBJECT_PATH)/Envelope.o $(OBJECT_PATH)/ADSR.o $(OBJECT_PATH)/BeeThree.o $(OBJECT_PATH)/Messager.o $(OBJECT_PATH)/RtMidi.o $(OBJECT_PATH)/Socket.o $(OBJECT_PATH)/Thread.o $(OBJECT_PATH)/SKINI.o $(LIBRARY)
+bethree: bethree.cpp Stk.o WvIn.o WaveLoop.o FM.o RtAudio.o Instrmnt.o Filter.o TwoZero.o Generator.o Envelope.o ADSR.o BeeThree.o
+ $(CC) $(CFLAGS) $(DEFS) -o bethree bethree.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/WvIn.o $(OBJECT_PATH)/WaveLoop.o $(OBJECT_PATH)/FM.o $(OBJECT_PATH)/RtAudio.o $(OBJECT_PATH)/Instrmnt.o $(OBJECT_PATH)/Filter.o $(OBJECT_PATH)/TwoZero.o $(OBJECT_PATH)/Generator.o $(OBJECT_PATH)/Envelope.o $(OBJECT_PATH)/ADSR.o $(OBJECT_PATH)/BeeThree.o $(LIBRARY)
+
+controlbee: controlbee.cpp Stk.o WvIn.o WaveLoop.o FM.o RtAudio.o Instrmnt.o Filter.o TwoZero.o Generator.o Envelope.o ADSR.o BeeThree.o Messager.o RtMidi.o Socket.o Thread.o Mutex.o Skini.o
+ $(CC) $(CFLAGS) $(DEFS) -o controlbee controlbee.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/WvIn.o $(OBJECT_PATH)/WaveLoop.o $(OBJECT_PATH)/FM.o $(OBJECT_PATH)/RtAudio.o $(OBJECT_PATH)/Instrmnt.o $(OBJECT_PATH)/Filter.o $(OBJECT_PATH)/TwoZero.o $(OBJECT_PATH)/Generator.o $(OBJECT_PATH)/Envelope.o $(OBJECT_PATH)/ADSR.o $(OBJECT_PATH)/BeeThree.o $(OBJECT_PATH)/Messager.o $(OBJECT_PATH)/RtMidi.o $(OBJECT_PATH)/Socket.o $(OBJECT_PATH)/Thread.o $(OBJECT_PATH)/Mutex.o $(OBJECT_PATH)/Skini.o $(LIBRARY)
foursine: foursine.cpp Stk.o WvIn.o WvOut.o WaveLoop.o
$(CC) $(CFLAGS) $(DEFS) -o foursine foursine.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/WvIn.o $(OBJECT_PATH)/WvOut.o $(OBJECT_PATH)/WaveLoop.o $(LIBRARY)
-threebees: threebees.cpp Stk.o WvIn.o WaveLoop.o FM.o WvOut.o RtWvOut.o RtAudio.o Instrmnt.o Filter.o TwoZero.o Envelope.o ADSR.o BeeThree.o Messager.o RtMidi.o Socket.o Thread.o SKINI.o Voicer.o
- $(CC) $(CFLAGS) $(DEFS) -o threebees threebees.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/WvIn.o $(OBJECT_PATH)/WaveLoop.o $(OBJECT_PATH)/FM.o $(OBJECT_PATH)/WvOut.o $(OBJECT_PATH)/RtWvOut.o $(OBJECT_PATH)/RtAudio.o $(OBJECT_PATH)/Instrmnt.o $(OBJECT_PATH)/Filter.o $(OBJECT_PATH)/TwoZero.o $(OBJECT_PATH)/Envelope.o $(OBJECT_PATH)/ADSR.o $(OBJECT_PATH)/BeeThree.o $(OBJECT_PATH)/Messager.o $(OBJECT_PATH)/RtMidi.o $(OBJECT_PATH)/Socket.o $(OBJECT_PATH)/Thread.o $(OBJECT_PATH)/SKINI.o $(OBJECT_PATH)/Voicer.o $(LIBRARY)
+threebees: threebees.cpp Stk.o WvIn.o WaveLoop.o FM.o RtAudio.o Instrmnt.o Filter.o TwoZero.o Generator.o Envelope.o ADSR.o BeeThree.o Messager.o RtMidi.o Socket.o Thread.o Mutex.o Skini.o Voicer.o
+ $(CC) $(CFLAGS) $(DEFS) -o threebees threebees.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/WvIn.o $(OBJECT_PATH)/WaveLoop.o $(OBJECT_PATH)/FM.o $(OBJECT_PATH)/RtAudio.o $(OBJECT_PATH)/Instrmnt.o $(OBJECT_PATH)/Filter.o $(OBJECT_PATH)/TwoZero.o $(OBJECT_PATH)/Generator.o $(OBJECT_PATH)/Envelope.o $(OBJECT_PATH)/ADSR.o $(OBJECT_PATH)/BeeThree.o $(OBJECT_PATH)/Messager.o $(OBJECT_PATH)/RtMidi.o $(OBJECT_PATH)/Socket.o $(OBJECT_PATH)/Thread.o $(OBJECT_PATH)/Mutex.o $(OBJECT_PATH)/Skini.o $(OBJECT_PATH)/Voicer.o $(LIBRARY)
+
+playsmf: playsmf.cpp Stk.o MidiFileIn.o RtMidi.o
+ $(CC) $(CFLAGS) $(DEFS) -o playsmf playsmf.cpp $(OBJECT_PATH)/Stk.o $(OBJECT_PATH)/MidiFileIn.o $(OBJECT_PATH)/RtMidi.o $(LIBRARY)
diff --git a/projects/examples/bethree.cpp b/projects/examples/bethree.cpp
index b563084..10db363 100644
--- a/projects/examples/bethree.cpp
+++ b/projects/examples/bethree.cpp
@@ -1,7 +1,43 @@
// bethree.cpp STK tutorial program
#include "BeeThree.h"
-#include "RtWvOut.h"
+#include "RtAudio.h"
+
+// The TickData structure holds all the class instances and data that
+// are shared by the various processing functions.
+struct TickData {
+ Instrmnt *instrument;
+ StkFloat frequency;
+ StkFloat scaler;
+ long counter;
+ bool done;
+
+ // Default constructor.
+ TickData()
+ : instrument(0), scaler(1.0), counter(0), done( false ) {}
+};
+
+// This tick() function handles sample computation only. It will be
+// called automatically when the system needs a new buffer of audio
+// samples.
+int tick(char *buffer, int bufferSize, void *dataPointer)
+{
+ TickData *data = (TickData *) dataPointer;
+ register StkFloat *samples = (StkFloat *) buffer;
+
+ for ( int i=0; iinstrument->tick();
+ if ( ++data->counter % 2000 == 0 ) {
+ data->scaler += 0.025;
+ data->instrument->setFrequency( data->frequency * data->scaler );
+ }
+ }
+
+ if ( data->counter > 80000 )
+ data->done = true;
+
+ return 0;
+}
int main()
{
@@ -9,50 +45,56 @@ int main()
Stk::setSampleRate( 44100.0 );
Stk::setRawwavePath( "../../rawwaves/" );
- Instrmnt *instrument = 0;
- RtWvOut *output = 0;
- MY_FLOAT frequency, amplitude, scaler;
- long counter, i;
+ TickData data;
+ RtAudio *dac = 0;
+
+ // Figure out how many bytes in an StkFloat and setup the RtAudio object.
+ RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
+ int bufferSize = RT_BUFFER_SIZE;
+ try {
+ dac = new RtAudio(0, 1, 0, 0, format, (int)Stk::sampleRate(), &bufferSize, 4);
+ }
+ catch (RtError& error) {
+ error.printMessage();
+ goto cleanup;
+ }
try {
// Define and load the BeeThree instrument
- instrument = new BeeThree();
-
- // Define and open the default realtime output device for one-channel playback
- output = new RtWvOut(1);
+ data.instrument = new BeeThree();
}
catch (StkError &) {
goto cleanup;
}
- scaler = 1.0;
- frequency = 220.0;
- amplitude = 0.5;
- instrument->noteOn( frequency, amplitude );
+ data.frequency = 220.0;
+ data.instrument->noteOn( data.frequency, 0.5 );
- // Play the instrument for 80000 samples, changing the frequency every 2000 samples
- counter = 0;
- while ( counter < 80000 ) {
- for ( i=0; i<2000; i++ ) {
- try {
- output->tick( instrument->tick() );
- }
- catch (StkError &) {
- goto cleanup;
- }
- }
-
- counter += 2000;
- scaler += 0.025;
- instrument->setFrequency( frequency * scaler );
+ try {
+ dac->setStreamCallback(&tick, (void *)&data);
+ dac->startStream();
+ }
+ catch (RtError &error) {
+ error.printMessage();
+ goto cleanup;
}
- // Turn the instrument off with maximum decay envelope.
- instrument->noteOff( 1.0 );
+ // Block waiting until callback signals done.
+ while ( !data.done )
+ Stk::sleep( 100 );
+
+ // Shut down the callback and output stream.
+ try {
+ dac->cancelStreamCallback();
+ dac->closeStream();
+ }
+ catch (RtError &error) {
+ error.printMessage();
+ }
cleanup:
- delete instrument;
- delete output;
+ delete data.instrument;
+ delete dac;
return 0;
}
diff --git a/projects/examples/bethree.dsp b/projects/examples/bethree.dsp
index 5594555..6a749c2 100755
--- a/projects/examples/bethree.dsp
+++ b/projects/examples/bethree.dsp
@@ -42,14 +42,14 @@ 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 "__LITTLE_ENDIAN__" /D "__WINDOWS_DS__" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../include" /D "NDEBUG" /D "__WINDOWS_DS__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /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
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "bethree - Win32 Debug"
@@ -65,15 +65,15 @@ LINK32=link.exe
# PROP Intermediate_Dir "Debug"
# 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 /GZ /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_DS__" /YX /FD /GZ /c
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "__WINDOWS_DS__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_MM__" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
@@ -111,6 +111,10 @@ SOURCE=..\..\src\FM.cpp
# End Source File
# Begin Source File
+SOURCE=..\..\src\Generator.cpp
+# End Source File
+# Begin Source File
+
SOURCE=..\..\src\Instrmnt.cpp
# End Source File
# Begin Source File
@@ -167,6 +171,10 @@ SOURCE=..\..\include\FM.h
# End Source File
# Begin Source File
+SOURCE=..\..\include\Generator.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\include\Instrmnt.h
# End Source File
# Begin Source File
diff --git a/projects/examples/controlbee.cpp b/projects/examples/controlbee.cpp
index f569c1e..9dae23f 100644
--- a/projects/examples/controlbee.cpp
+++ b/projects/examples/controlbee.cpp
@@ -1,91 +1,175 @@
// controlbee.cpp STK tutorial program
#include "BeeThree.h"
-#include "RtWvOut.h"
+#include "RtAudio.h"
#include "Messager.h"
#include "SKINI.msg"
#include
+#include
+#if !defined(__OS_WINDOWS__) // Windoze bogosity for VC++ 6.0
+ using std::min;
+#endif
-int main()
+void usage(void) {
+ // Error function in case of incorrect command-line
+ // argument specifications.
+ std::cout << "\nuseage: controlbee file\n";
+ std::cout << " where file = a SKINI scorefile.\n\n";
+ exit(0);
+}
+
+// The TickData structure holds all the class instances and data that
+// are shared by the various processing functions.
+struct TickData {
+ Instrmnt *instrument;
+ Messager messager;
+ Skini::Message message;
+ int counter;
+ bool haveMessage;
+ bool done;
+
+ // Default constructor.
+ TickData()
+ : instrument(0), counter(0), haveMessage(false), done( false ) {}
+};
+
+#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 StkFloat value1 = data->message.floatValues[0];
+ register StkFloat value2 = data->message.floatValues[1];
+
+ switch( data->message.type ) {
+
+ case __SK_Exit_:
+ data->done = true;
+ return;
+
+ case __SK_NoteOn_:
+ if ( value2 == 0.0 ) // velocity is zero ... really a NoteOff
+ data->instrument->noteOff( 0.5 );
+ else { // a NoteOn
+ StkFloat frequency = 220.0 * pow( 2.0, (value1 - 57.0) / 12.0 );
+ data->instrument->noteOn( frequency, value2 * ONE_OVER_128 );
+ }
+ break;
+
+ case __SK_NoteOff_:
+ data->instrument->noteOff( value2 * ONE_OVER_128 );
+ break;
+
+ case __SK_ControlChange_:
+ data->instrument->controlChange( (int) value1, value2 );
+ break;
+
+ case __SK_AfterTouch_:
+ data->instrument->controlChange( 128, value1 );
+
+ } // end of switch
+
+ data->haveMessage = false;
+ return;
+}
+
+// This tick() function handles sample computation and scheduling of
+// control updates. It will be called automatically when the system
+// needs a new buffer of audio samples.
+int tick(char *buffer, int bufferSize, void *dataPointer)
+{
+ TickData *data = (TickData *) dataPointer;
+ register StkFloat *samples = (StkFloat *) buffer;
+ int counter, nTicks = bufferSize;
+
+ while ( nTicks > 0 && !data->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 ( int i=0; iinstrument->tick();
+ nTicks--;
+ }
+ if ( nTicks == 0 ) break;
+
+ // Process control messages.
+ if ( data->haveMessage ) processMessage( data );
+ }
+
+ return 0;
+}
+
+int main( int argc, char *argv[] )
+{
+ if ( argc != 2 ) usage();
+
// Set the global sample rate and rawwave path before creating class instances.
Stk::setSampleRate( 44100.0 );
Stk::setRawwavePath( "../../rawwaves/" );
- Instrmnt *instrument = 0;
- RtWvOut *output = 0;
- Messager *messager = 0;
- bool done = FALSE;
+ TickData data;
+ RtAudio *dac = 0;
+
+ // Figure out how many bytes in an StkFloat and setup the RtAudio object.
+ RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
+ int bufferSize = RT_BUFFER_SIZE;
+ try {
+ dac = new RtAudio(0, 1, 0, 0, format, (int)Stk::sampleRate(), &bufferSize, 4);
+ }
+ catch (RtError& error) {
+ error.printMessage();
+ goto cleanup;
+ }
try {
// Define and load the BeeThree instrument
- instrument = new BeeThree();
-
- // Define and open the default realtime output device for one-channel playback
- output = new RtWvOut(1);
+ data.instrument = new BeeThree();
}
catch (StkError &) {
goto cleanup;
}
+ if ( data.messager.setScoreFile( argv[1] ) == false )
+ goto cleanup;
+
try {
- // Create a Messager instance to read from a redirected SKINI scorefile.
- messager = new Messager();
+ dac->setStreamCallback(&tick, (void *)&data);
+ dac->startStream();
}
- catch (StkError &) {
+ catch (RtError &error) {
+ error.printMessage();
goto cleanup;
}
- // Play the instrument until the end of the scorefile.
- int i, nTicks, type;
- MY_FLOAT byte2, byte3, frequency;
- while (!done) {
-
- // Look for new messages and return a delta time (in samples).
- type = messager->nextMessage();
- if (type < 0)
- done = TRUE;
-
- nTicks = messager->getDelta();
- try {
- for ( i=0; itick( instrument->tick() );
- }
- catch (StkError &) {
- goto cleanup;
- }
-
- if ( type > 0 ) {
- // Process the new control message.
- byte2 = messager->getByteTwo();
- byte3 = messager->getByteThree();
-
- switch(type) {
-
- case __SK_NoteOn_:
- frequency = (MY_FLOAT) 220.0 * pow( 2.0, (byte2 - 57.0) / 12.0 );
- instrument->noteOn( frequency, byte3 * ONE_OVER_128 );
- break;
-
- case __SK_NoteOff_:
- instrument->noteOff( byte3 * ONE_OVER_128 );
- break;
-
- case __SK_ControlChange_:
- instrument->controlChange( (int) byte2, byte3 );
- break;
-
- case __SK_AfterTouch_:
- instrument->controlChange( 128, byte2 );
- break;
- }
- }
+ // Block waiting until callback signals done.
+ while ( !data.done )
+ Stk::sleep( 100 );
+
+ // Shut down the callback and output stream.
+ try {
+ dac->cancelStreamCallback();
+ dac->closeStream();
+ }
+ catch (RtError &error) {
+ error.printMessage();
}
cleanup:
- delete instrument;
- delete output;
- delete messager;
+ delete data.instrument;
+ delete dac;
return 0;
}
diff --git a/projects/examples/controlbee.dsp b/projects/examples/controlbee.dsp
index 1c8da9d..b773d71 100755
--- a/projects/examples/controlbee.dsp
+++ b/projects/examples/controlbee.dsp
@@ -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 "__LITTLE_ENDIAN__" /D "__WINDOWS_DS__" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../include" /D "NDEBUG" /D "__WINDOWS_DS__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /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
@@ -67,7 +67,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 /GZ /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_DS__" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "__WINDOWS_DS__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_MM__" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
@@ -112,6 +112,10 @@ SOURCE=..\..\src\FM.cpp
# End Source File
# Begin Source File
+SOURCE=..\..\src\Generator.cpp
+# End Source File
+# Begin Source File
+
SOURCE=..\..\src\Instrmnt.cpp
# End Source File
# Begin Source File
@@ -120,6 +124,10 @@ SOURCE=..\..\src\Messager.cpp
# End Source File
# Begin Source File
+SOURCE=..\..\src\Mutex.cpp
+# End Source File
+# Begin Source File
+
SOURCE=..\..\src\RtAudio.cpp
# End Source File
# Begin Source File
@@ -196,6 +204,10 @@ SOURCE=..\..\include\Messager.h
# End Source File
# Begin Source File
+SOURCE=..\..\include\Mutex.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\include\RtAudio.h
# End Source File
# Begin Source File
diff --git a/projects/examples/crtsine.cpp b/projects/examples/crtsine.cpp
new file mode 100644
index 0000000..9989ba5
--- /dev/null
+++ b/projects/examples/crtsine.cpp
@@ -0,0 +1,78 @@
+// crtsine.cpp STK tutorial program
+
+#include "WaveLoop.h"
+#include "RtAudio.h"
+
+// This tick() function handles sample computation only. It will be
+// called automatically when the system needs a new buffer of audio
+// samples.
+int tick(char *buffer, int bufferSize, void *dataPointer)
+{
+ WaveLoop *sine = (WaveLoop *) dataPointer;
+ register StkFloat *samples = (StkFloat *) buffer;
+
+ for ( int i=0; itick();
+
+ return 0;
+}
+
+int main()
+{
+ // Set the global sample rate before creating class instances.
+ Stk::setSampleRate( 44100.0 );
+
+ WaveLoop *sine = 0;
+ RtAudio *dac = 0;
+
+ // Figure out how many bytes in an StkFloat and setup the RtAudio object.
+ RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
+ int bufferSize = RT_BUFFER_SIZE;
+ try {
+ dac = new RtAudio(0, 1, 0, 0, format, (int)Stk::sampleRate(), &bufferSize, 4);
+ }
+ catch (RtError& error) {
+ error.printMessage();
+ goto cleanup;
+ }
+
+ try {
+ // Define and load the sine wave file
+ sine = new WaveLoop( "rawwaves/sinewave.raw", true );
+ }
+ catch (StkError &) {
+ goto cleanup;
+ }
+
+ sine->setFrequency(440.0);
+
+ try {
+ dac->setStreamCallback(&tick, (void *)sine);
+ dac->startStream();
+ }
+ catch (RtError &error) {
+ error.printMessage();
+ goto cleanup;
+ }
+
+ // Block waiting here.
+ char keyhit;
+ std::cout << "\nPlaying ... press to quit.\n";
+ std::cin.get(keyhit);
+
+ // Shut down the callback and output stream.
+ try {
+ dac->cancelStreamCallback();
+ dac->closeStream();
+ }
+ catch (RtError &error) {
+ error.printMessage();
+ }
+
+ cleanup:
+
+ delete sine;
+ delete dac;
+
+ return 0;
+}
diff --git a/projects/examples/crtsine.dsp b/projects/examples/crtsine.dsp
new file mode 100755
index 0000000..b1ad486
--- /dev/null
+++ b/projects/examples/crtsine.dsp
@@ -0,0 +1,134 @@
+# Microsoft Developer Studio Project File - Name="crtsine" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=crtsine - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "crtsine.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "crtsine.mak" CFG="crtsine - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "crtsine - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "crtsine - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "crtsine - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "crtsine___Win32_Release"
+# PROP BASE Intermediate_Dir "crtsine___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Release"
+# 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 "__LITTLE_ENDIAN__" /D "__WINDOWS_DS__" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "crtsine - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "crtsine___Win32_Debug"
+# PROP BASE Intermediate_Dir "crtsine___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Debug"
+# 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 /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_DS__" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "crtsine - Win32 Release"
+# Name "crtsine - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\crtsine.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\src\RtAudio.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\src\Stk.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\src\WaveLoop.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\src\WvIn.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=..\..\include\RtAudio.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\Stk.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\WaveLoop.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\include\WvIn.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/projects/examples/examples.dsw b/projects/examples/examples.dsw
index edd693c..aa24e97 100644
--- a/projects/examples/examples.dsw
+++ b/projects/examples/examples.dsw
@@ -27,6 +27,18 @@ Package=<4>
###############################################################################
+Project: "crtsine"=".\crtsine.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
Project: "foursine"=".\foursine.dsp" - Package Owner=<4>
Package=<5>
diff --git a/projects/examples/foursine.cpp b/projects/examples/foursine.cpp
index 435e89b..3bab6f6 100644
--- a/projects/examples/foursine.cpp
+++ b/projects/examples/foursine.cpp
@@ -16,7 +16,7 @@ int main()
// Define and load the sine waves
try {
for ( i=0; i<4; i++ ) {
- inputs[i] = new WaveLoop( "rawwaves/sinewave.raw", TRUE );
+ inputs[i] = new WaveLoop( "rawwaves/sinewave.raw", true );
inputs[i]->setFrequency( 220.0 * (i+1) );
}
}
@@ -33,7 +33,7 @@ int main()
}
// Write two seconds of four sines to the output file
- MY_FLOAT frame[4];
+ StkFloat frame[4];
for ( j=0; j<88200; j++ ) {
for ( i=0; i<4; i++ )
frame[i] = inputs[i]->tick();
diff --git a/projects/examples/foursine.dsp b/projects/examples/foursine.dsp
index 72d81c2..da625b3 100755
--- a/projects/examples/foursine.dsp
+++ b/projects/examples/foursine.dsp
@@ -41,15 +41,15 @@ RSC=rc.exe
# PROP Intermediate_Dir "Release"
# 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 "__LITTLE_ENDIAN__" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_MM__" /D "__WINDOWS_DS__" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "foursine - Win32 Debug"
@@ -63,16 +63,16 @@ LINK32=link.exe
# PROP Output_Dir ""
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /YX /FD /GZ /c
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_MM__" /D "__WINDOWS_DS__" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
diff --git a/projects/examples/io.cpp b/projects/examples/io.cpp
index 4703953..24e0d40 100644
--- a/projects/examples/io.cpp
+++ b/projects/examples/io.cpp
@@ -1,15 +1,25 @@
/******************************************/
/*
Example program for realtime input/output
- by Gary P. Scavone, 2000
+ by Gary P. Scavone, 2000.
- This program reads N channels of realtime
- audio input for a specified amount of time
- and immediately play them back in realtime
- (duplex mode). This program also demonstrates
- the use of FIFO scheduling priority. To be
- run with such priority, the program must be
- set suid (chmod +s) and owned by root.
+ NOTE: This program makes use of blocking audio
+ input/output routines. On systems where the
+ underlying audio API is based on a callback scheme
+ (Macintosh OS-X, Windows ASIO, and Linux JACK), these
+ routines are not fully robust (over/underruns can
+ happen with some frequency). See the STK tutorial
+ for example programs using callback schemes and/or
+ visit the RtAudio tutorial page
+ (http://music.mcgill.ca/~gary/rtaudio/) for more
+ information.
+
+ This program reads N channels of realtime audio input
+ for a specified amount of time and immediately play
+ them back in realtime (duplex mode). This program
+ also demonstrates the use of FIFO scheduling
+ priority. To be run with such priority, the program
+ must be set suid (chmod +s) and owned by root.
*/
/******************************************/
@@ -37,7 +47,7 @@ main(int argc, char *argv[])
if (argc != 3) usage();
unsigned int channels = (unsigned int) atoi(argv[1]);
- float time = atof(argv[2]);
+ double time = atof(argv[2]);
// If you want to change the default sample rate (set in Stk.h), do
// it before instantiating any objects! If the sample rate is
@@ -72,8 +82,8 @@ main(int argc, char *argv[])
// Here's the runtime loop
unsigned long i, counter = 0;
- MY_FLOAT *newFrame = new MY_FLOAT[channels];
- const MY_FLOAT *lastFrame = inout->lastFrame();
+ StkFloat *newFrame = new StkFloat[channels];
+ const StkFloat *lastFrame = inout->lastFrame();
unsigned long samples = (unsigned long) (time * Stk::sampleRate());
while ( counter < samples ) {
for ( i=0; i
+#include "RtAudio.h"
+
+#include
+#include
+
+// Eewww ... global variables! :-)
+bool done;
+StkFrames frames;
+static void finish(int ignore){ done = true; }
void usage(void) {
// Error function in case of incorrect command-line
// argument specifications.
- printf("\nuseage: play file \n");
- printf(" where file = the file to play,\n");
- printf(" and rate = an optional playback rate.\n");
- printf(" (default = 1.0, can be negative)\n\n");
+ std::cout << "\nuseage: play file sr \n";
+ std::cout << " where file = the file to play,\n";
+ std::cout << " where sr = sample rate,\n";
+ std::cout << " and rate = an optional playback rate.\n";
+ std::cout << " (default = 1.0, can be negative)\n\n";
exit(0);
}
+// This tick() function handles sample computation only. It will be
+// called automatically when the system needs a new buffer of audio
+// samples.
+int tick(char *buffer, int bufferSize, void *dataPointer)
+{
+ WvIn *input = (WvIn *) dataPointer;
+ register StkFloat *samples = (StkFloat *) buffer;
+
+ input->tickFrame( frames );
+ for ( unsigned int i=0; iisFinished() ) {
+ done = true;
+ return 1;
+ }
+ else
+ return 0;
+}
+
int main(int argc, char *argv[])
{
// Minimal command-line checking.
- if (argc < 2 || argc > 3) usage();
+ if (argc < 3 || argc > 4) usage();
- // Initialize our WvIn/WvOut pointers.
- RtWvOut *output = 0;
+ // Set the global sample rate before creating class instances.
+ Stk::setSampleRate( (StkFloat) atof(argv[2]) );
+
+ // Initialize our WvIn and RtAudio pointers.
+ RtAudio *dac = 0;
WvIn *input = 0;
// Try to load the soundfile.
@@ -45,29 +76,57 @@ int main(int argc, char *argv[])
}
// Set input read rate based on the default STK sample rate.
- float rate = 1.0;
+ double rate = 1.0;
rate = input->getFileRate() / Stk::sampleRate();
- if ( argc == 3 ) rate *= atof(argv[2]);
+ if ( argc == 4 ) rate *= atof(argv[3]);
input->setRate( rate );
// Find out how many channels we have.
int channels = input->getChannels();
- // Define and open the realtime output device
+ // Define and open the realtime output device.
+ // Figure out how many bytes in an StkFloat and setup the RtAudio object.
+ RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
+ int bufferSize = RT_BUFFER_SIZE;
try {
- output = new RtWvOut( channels, Stk::sampleRate(), 0, RT_BUFFER_SIZE, 4 );
+ dac = new RtAudio(0, channels, 0, 0, format, (int)Stk::sampleRate(), &bufferSize, 4);
}
- catch (StkError &) {
+ catch (RtError &error) {
+ error.printMessage();
goto cleanup;
}
- // Here's the runtime loop.
- while (!input->isFinished()) {
- output->tickFrame( input->tickFrame() );
+ // Install an interrupt handler function.
+ (void) signal(SIGINT, finish);
+
+ // Resize the StkFrames object appropriately.
+ frames.resize( bufferSize, channels );
+
+ try {
+ dac->setStreamCallback(&tick, (void *)input);
+ dac->startStream();
+ }
+ catch (RtError &error) {
+ error.printMessage();
+ goto cleanup;
+ }
+
+ // Block waiting until callback signals done.
+ while ( !done )
+ Stk::sleep( 100 );
+
+ // By returning a non-zero value in the callback above, the stream
+ // is automatically stopped. But we should still close it.
+ try {
+ dac->cancelStreamCallback();
+ dac->closeStream();
+ }
+ catch (RtError &error) {
+ error.printMessage();
}
cleanup:
delete input;
- delete output;
+ delete dac;
return 0;
}
diff --git a/projects/examples/play.dsp b/projects/examples/play.dsp
index 28e7cfb..c5fcb12 100644
--- a/projects/examples/play.dsp
+++ b/projects/examples/play.dsp
@@ -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 "__WINDOWS_DS__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /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 /GZ /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 /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "__WINDOWS_DS__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_MM__" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
diff --git a/projects/examples/playsmf.cpp b/projects/examples/playsmf.cpp
new file mode 100644
index 0000000..5dc1466
--- /dev/null
+++ b/projects/examples/playsmf.cpp
@@ -0,0 +1,122 @@
+// playsmf.cpp
+//
+// Simple program to test the MidiFileIn class by reading and playing
+// a single track from a given Standard MIDI file.
+//
+// by Gary Scavone, 2003.
+
+#include "MidiFileIn.h"
+#include "RtMidi.h"
+#include
+#include
+
+bool done = false;
+static void finish(int ignore){ done = true; }
+
+void usage(void) {
+ // Error function in case of incorrect command-line
+ // argument specifications.
+ std::cout << "\nusage: playsmf file track \n";
+ std::cout << " where file = a standard MIDI file,\n";
+ std::cout << " track = the track to play (0 = 1st track),\n";
+ std::cout << " and an optional port integer identifier can be specified\n";
+ std::cout << " (default = 0) or a value of -1 to use a virtual MIDI output port.\n\n";
+ exit(0);
+}
+
+int main( int argc, char *argv[] )
+{
+ RtMidiOut *midiout = 0;
+
+ if ( argc < 3 || argc > 4 ) usage();
+
+ // Attempt to instantiate MIDI output class.
+ try {
+ midiout = new RtMidiOut();
+ }
+ catch ( RtError& error ) {
+ error.printMessage();
+ exit(0);
+ }
+
+ // Check command-line arguments.
+ int port = 0;
+ if ( argc == 4 ) port = atoi( argv[3] );
+ if ( port == -1 ) {
+ try {
+ midiout->openVirtualPort();
+ }
+ catch ( RtError& error ) {
+ error.printMessage();
+ goto cleanup;
+ }
+ std::cout << "\nVirtual port open.\n\n";
+ }
+ else {
+ if ( midiout->getPortCount() < 1 ) {
+ std::cout << "\nThere are no MIDI output destinations available!\n\n";
+ goto cleanup;
+ }
+ try {
+ midiout->openPort( port );
+ }
+ catch ( RtError& error ) {
+ error.printMessage();
+ goto cleanup;
+ }
+ }
+
+ // Install an interrupt handler function. Type "ctrl-c" to quit the
+ // program.
+ (void) signal(SIGINT, finish);
+
+ try {
+ MidiFileIn midiFile( argv[1] );
+
+ // Print a little information about the file.
+ std::cout << "\nThe MIDI file (" << argv[1] << ") information:\n";
+ std::cout << " - format = " << midiFile.getFileFormat() << "\n";
+ std::cout << " - tracks = " << midiFile.getNumberOfTracks() << "\n";
+ std::cout << " - seconds / ticks = " << midiFile.getTickSeconds() << "\n";
+
+ unsigned int track = (unsigned int) atoi( argv[2] );
+ if ( midiFile.getNumberOfTracks() <= track ) {
+ std::cout << "\nInvalid track number ... playing track 0.\n";
+ track = 0;
+ }
+
+ std::cout << "\nPress to start reading/playing.\n";
+ char input;
+ std::cin.get(input);
+
+ std::vector event;
+ unsigned long ticks = midiFile.getNextMidiEvent( &event, track );
+ while ( !done && event.size() ) {
+
+ // Pause for the MIDI event delta time.
+ Stk::sleep( (unsigned long) (ticks * midiFile.getTickSeconds() * 1000 ) );
+
+ midiout->sendMessage( &event );
+
+ // Get a new event.
+ ticks = midiFile.getNextMidiEvent( &event, track );
+ }
+
+ // Send a "all notes off" to the synthesizer.
+ event.clear();
+ event.push_back( 0xb0 );
+ event.push_back( 0x7b );
+ event.push_back( 0x0 );
+ midiout->sendMessage( &event );
+ }
+ catch ( StkError & ) {
+ // You might want to do something more useful here.
+ std::cout << "\nAborting program!\n";
+ goto cleanup;
+ }
+
+ cleanup:
+ delete midiout;
+
+ return 0;
+}
diff --git a/projects/examples/record.cpp b/projects/examples/record.cpp
index 659bf2f..928bd2f 100644
--- a/projects/examples/record.cpp
+++ b/projects/examples/record.cpp
@@ -3,6 +3,17 @@
Example program to record N channels of data
by Gary P. Scavone, 2000
+ NOTE: This program makes use of blocking audio
+ input/output routines. On systems where the
+ underlying audio API is based on a callback scheme
+ (Macintosh OS-X, Windows ASIO, and Linux JACK), these
+ routines are not fully robust (over/underruns can
+ happen with some frequency). See the STK tutorial
+ for example programs using callback schemes and/or
+ visit the RtAudio tutorial page
+ (http://music.mcgill.ca/~gary/rtaudio/) for more
+ information.
+
This program is currently written to read
from a realtime audio input device and to
write to a WAV output file. However, it
@@ -31,8 +42,8 @@ int main(int argc, char *argv[])
if (argc != 5) usage();
int channels = (int) atoi(argv[1]);
- float sample_rate = atof(argv[4]);
- float time = atof(argv[3]);
+ double sample_rate = atof(argv[4]);
+ double time = atof(argv[3]);
long samples, i;
// Set the global sample rate.
diff --git a/projects/examples/record.dsp b/projects/examples/record.dsp
index 292525a..e837bd9 100644
--- a/projects/examples/record.dsp
+++ b/projects/examples/record.dsp
@@ -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 "__WINDOWS_DS__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_MM__" /YX /FD /c
# SUBTRACT CPP /Fr
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
@@ -68,7 +68,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 /GZ /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 /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "__WINDOWS_DS__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_MM__" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
diff --git a/projects/examples/rtsine.cpp b/projects/examples/rtsine.cpp
index e20c0d1..40012b4 100644
--- a/projects/examples/rtsine.cpp
+++ b/projects/examples/rtsine.cpp
@@ -8,27 +8,27 @@ int main()
// Set the global sample rate before creating class instances.
Stk::setSampleRate( 44100.0 );
- WaveLoop *input = 0;
- RtWvOut *output = 0;
+ WaveLoop *sine = 0;
+ RtWvOut *dac = 0;
try {
// Define and load the sine wave file
- input = new WaveLoop( "rawwaves/sinewave.raw", TRUE );
+ sine = new WaveLoop( "rawwaves/sinewave.raw", true );
// Define and open the default realtime output device for one-channel playback
- output = new RtWvOut(1);
+ dac = new RtWvOut(1);
}
catch (StkError &) {
goto cleanup;
}
- input->setFrequency(440.0);
+ sine->setFrequency(440.0);
// Play the oscillator for 40000 samples
int i;
for ( i=0; i<40000; i++ ) {
try {
- output->tick(input->tick());
+ dac->tick( sine->tick() );
}
catch (StkError &) {
goto cleanup;
@@ -36,8 +36,8 @@ int main()
}
cleanup:
- delete input;
- delete output;
+ delete sine;
+ delete dac;
return 0;
}
diff --git a/projects/examples/rtsine.dsp b/projects/examples/rtsine.dsp
index d409e01..285a933 100755
--- a/projects/examples/rtsine.dsp
+++ b/projects/examples/rtsine.dsp
@@ -42,14 +42,14 @@ 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 "__LITTLE_ENDIAN__" /D "__WINDOWS_DS__" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../include" /D "NDEBUG" /D "__WINDOWS_DS__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /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
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "rtsine - Win32 Debug"
@@ -65,15 +65,15 @@ LINK32=link.exe
# PROP Intermediate_Dir "Debug"
# 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 /GZ /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_DS__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "__WINDOWS_DS__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_MM__" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
diff --git a/projects/examples/sine.cpp b/projects/examples/sine.cpp
index 66d892c..933ad3c 100644
--- a/projects/examples/sine.cpp
+++ b/projects/examples/sine.cpp
@@ -43,7 +43,7 @@ main(int argc, char *argv[])
// Initialize our object and data pointers.
WvOut *output = 0;
- MY_FLOAT *vector = 0;
+ StkFloat *vector = 0;
WaveLoop **oscs = (WaveLoop **) malloc( channels * sizeof(WaveLoop *) );
for (i=0; itick();
diff --git a/projects/examples/sine.dsp b/projects/examples/sine.dsp
index 3c9d93d..beba689 100644
--- a/projects/examples/sine.dsp
+++ b/projects/examples/sine.dsp
@@ -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 "__LITTLE_ENDIAN__" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_MM__" /D "__WINDOWS_DS__" /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 /GZ /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_MM__" /D "__WINDOWS_DS__" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
diff --git a/projects/examples/sineosc.cpp b/projects/examples/sineosc.cpp
index a01f45f..59d6cf5 100644
--- a/projects/examples/sineosc.cpp
+++ b/projects/examples/sineosc.cpp
@@ -13,7 +13,7 @@ int main()
try {
// Define and load the sine wave file
- input = new WaveLoop( "rawwaves/sinewave.raw", TRUE );
+ input = new WaveLoop( "rawwaves/sinewave.raw", true );
// Define and open a 16-bit, one-channel WAV formatted output file
output = new WvOut( "hellosine.wav", 1, WvOut::WVOUT_WAV, Stk::STK_SINT16 );
diff --git a/projects/examples/sineosc.dsp b/projects/examples/sineosc.dsp
index 331799a..0f4c9a8 100755
--- a/projects/examples/sineosc.dsp
+++ b/projects/examples/sineosc.dsp
@@ -41,7 +41,7 @@ RSC=rc.exe
# PROP Intermediate_Dir "Release"
# 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 "__LITTLE_ENDIAN__" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_MM__" /D "__WINDOWS_DS__" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
@@ -65,7 +65,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 /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "_AFXDLL" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "_AFXDLL" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_MM__" /D "__WINDOWS_DS__" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG" /d "_AFXDLL"
BSC32=bscmake.exe
diff --git a/projects/examples/tcpIn.cpp b/projects/examples/tcpIn.cpp
index a6aa476..187c02d 100644
--- a/projects/examples/tcpIn.cpp
+++ b/projects/examples/tcpIn.cpp
@@ -6,6 +6,17 @@
by Gary P. Scavone, 2000
+ NOTE: This program makes use of blocking audio
+ input/output routines. On systems where the
+ underlying audio API is based on a callback scheme
+ (Macintosh OS-X, Windows ASIO, and Linux JACK), these
+ routines are not fully robust (over/underruns can
+ happen with some frequency). See the STK tutorial
+ for example programs using callback schemes and/or
+ visit the RtAudio tutorial page
+ (http://music.mcgill.ca/~gary/rtaudio/) for more
+ information.
+
This program is currently written to play
the input data in realtime. However, it
is simple to replace the instance of
@@ -15,7 +26,7 @@
The streamed data format is assumed to be
signed 16-bit integers. However, both
TcpWvIn and TcpWvOut can be initialized
- to read/write any of the defined STK_FORMATs.
+ to read/write any of the defined StkFormats.
The class TcpWvIn sets up a socket server
and waits for a connection. Therefore,
diff --git a/projects/examples/tcpIn.dsp b/projects/examples/tcpIn.dsp
index 8812712..741c8b5 100644
--- a/projects/examples/tcpIn.dsp
+++ b/projects/examples/tcpIn.dsp
@@ -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 "__WINDOWS_DS__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /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 /GZ /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 /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "__WINDOWS_DS__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_MM__" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
@@ -87,6 +87,10 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
+SOURCE=..\..\src\Mutex.cpp
+# End Source File
+# Begin Source File
+
SOURCE=..\..\src\RtAudio.cpp
# End Source File
# Begin Source File
diff --git a/projects/examples/tcpOut.cpp b/projects/examples/tcpOut.cpp
index 5919fa4..6bebf8a 100644
--- a/projects/examples/tcpOut.cpp
+++ b/projects/examples/tcpOut.cpp
@@ -10,7 +10,7 @@
file. The output data format is set for
signed 16-bit integers. However, it is
easy to change the TcpWvOut setting to
- any of the other defined STK_FORMATs.
+ any of the other defined StkFormats.
If using tcpIn, it will be necessary to
change the expected data format there
as well.
diff --git a/projects/examples/tcpOut.dsp b/projects/examples/tcpOut.dsp
index fd1f226..ac608ed 100644
--- a/projects/examples/tcpOut.dsp
+++ b/projects/examples/tcpOut.dsp
@@ -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 "__WINDOWS_DS__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /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 /GZ /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 /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "__WINDOWS_DS__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_MM__" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
diff --git a/projects/examples/threebees.cpp b/projects/examples/threebees.cpp
index e3aee12..793fe1d 100644
--- a/projects/examples/threebees.cpp
+++ b/projects/examples/threebees.cpp
@@ -1,11 +1,116 @@
// threebees.cpp STK tutorial program
#include "BeeThree.h"
-#include "RtWvOut.h"
+#include "RtAudio.h"
#include "Messager.h"
#include "Voicer.h"
#include "SKINI.msg"
+#include
+#if !defined(__OS_WINDOWS__) // Windoze bogosity for VC++ 6.0
+ using std::min;
+#endif
+
+// The TickData structure holds all the class instances and data that
+// are shared by the various processing functions.
+struct TickData {
+ Voicer voicer;
+ Messager messager;
+ Skini::Message message;
+ int counter;
+ bool haveMessage;
+ bool done;
+
+ // Default constructor.
+ TickData()
+ : counter(0), haveMessage(false), done( false ) {}
+};
+
+#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 StkFloat value1 = data->message.floatValues[0];
+ register StkFloat value2 = data->message.floatValues[1];
+
+ switch( data->message.type ) {
+
+ case __SK_Exit_:
+ data->done = true;
+ return;
+
+ case __SK_NoteOn_:
+ if ( value2 == 0.0 ) // velocity is zero ... really a NoteOff
+ data->voicer.noteOff( value1, 64.0 );
+ else { // a NoteOn
+ data->voicer.noteOn( value1, value2 );
+ }
+ break;
+
+ case __SK_NoteOff_:
+ data->voicer.noteOff( value1, value2 );
+ break;
+
+ case __SK_ControlChange_:
+ data->voicer.controlChange( (int) value1, value2 );
+ break;
+
+ case __SK_AfterTouch_:
+ data->voicer.controlChange( 128, value1 );
+
+ case __SK_PitchChange_:
+ data->voicer.setFrequency( value1 );
+ break;
+
+ case __SK_PitchBend_:
+ data->voicer.pitchBend( value1 );
+
+ } // end of switch
+
+ data->haveMessage = false;
+ return;
+}
+
+// This tick() function handles sample computation and scheduling of
+// control updates. It will be called automatically when the system
+// needs a new buffer of audio samples.
+int tick(char *buffer, int bufferSize, void *dataPointer)
+{
+ TickData *data = (TickData *) dataPointer;
+ register StkFloat *samples = (StkFloat *) buffer;
+ int counter, nTicks = bufferSize;
+
+ while ( nTicks > 0 && !data->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 ( int i=0; ivoicer.tick();
+ nTicks--;
+ }
+ if ( nTicks == 0 ) break;
+
+ // Process control messages.
+ if ( data->haveMessage ) processMessage( data );
+ }
+
+ return 0;
+}
+
int main()
{
// Set the global sample rate and rawwave path before creating class instances.
@@ -13,88 +118,63 @@ int main()
Stk::setRawwavePath( "../../rawwaves/" );
int i;
- RtWvOut *output = 0;
- Messager *messager = 0;
- Voicer *voicer = 0;
- bool done = FALSE;
+ TickData data;
+ RtAudio *dac = 0;
Instrmnt *instrument[3];
for ( i=0; i<3; i++ ) instrument[i] = 0;
+ // Figure out how many bytes in an StkFloat and setup the RtAudio object.
+ RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
+ int bufferSize = RT_BUFFER_SIZE;
+ try {
+ dac = new RtAudio(0, 1, 0, 0, format, (int)Stk::sampleRate(), &bufferSize, 4);
+ }
+ catch (RtError& error) {
+ error.printMessage();
+ goto cleanup;
+ }
+
try {
// Define and load the BeeThree instruments
for ( i=0; i<3; i++ )
instrument[i] = new BeeThree();
-
- // Define and open the default realtime output device for one-channel playback
- output = new RtWvOut(1);
}
catch (StkError &) {
goto cleanup;
}
+ // "Add" the instruments to the voicer.
+ for ( i=0; i<3; i++ )
+ data.voicer.addInstrument( instrument[i] );
+
+ if ( data.messager.startStdInput() == false )
+ goto cleanup;
+
try {
- // Create a Messager instance to read from a redirected SKINI scorefile.
- messager = new Messager();
+ dac->setStreamCallback(&tick, (void *)&data);
+ dac->startStream();
}
- catch (StkError &) {
+ catch (RtError &error) {
+ error.printMessage();
goto cleanup;
}
- // Instantiate the voicer for a maximum of three voices.
- voicer = new Voicer( 3 );
- for ( i=0; i<3; i++ )
- voicer->addInstrument( instrument[i] );
-
- // Play the instrument until the end of the scorefile.
- int nTicks, type;
- MY_FLOAT byte2, byte3;
- while (!done) {
-
- // Look for new messages and return a delta time (in samples).
- type = messager->nextMessage();
- if (type < 0)
- done = TRUE;
-
- nTicks = messager->getDelta();
- try {
- for ( i=0; itick( voicer->tick() );
- }
- catch (StkError &) {
- goto cleanup;
- }
-
- if ( type > 0 ) {
- // Process the new control message.
- byte2 = messager->getByteTwo();
- byte3 = messager->getByteThree();
-
- switch(type) {
-
- case __SK_NoteOn_:
- voicer->noteOn( byte2, byte3 );
- break;
-
- case __SK_NoteOff_:
- voicer->noteOff( byte2, byte3 );
- break;
-
- case __SK_ControlChange_:
- voicer->controlChange( (int) byte2, byte3 );
- break;
-
- case __SK_AfterTouch_:
- voicer->controlChange( 128, byte2 );
- break;
- }
- }
+ // Block waiting until callback signals done.
+ while ( !data.done )
+ Stk::sleep( 100 );
+
+ // Shut down the callback and output stream.
+ try {
+ dac->cancelStreamCallback();
+ dac->closeStream();
+ }
+ catch (RtError &error) {
+ error.printMessage();
}
cleanup:
for ( i=0; i<3; i++ ) delete instrument[i];
- delete output;
- delete messager;
- delete voicer;
+ delete dac;
return 0;
}
diff --git a/projects/examples/threebees.dsp b/projects/examples/threebees.dsp
index e22b339..b0d3c3f 100755
--- a/projects/examples/threebees.dsp
+++ b/projects/examples/threebees.dsp
@@ -42,14 +42,14 @@ 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 "__LITTLE_ENDIAN__" /D "__WINDOWS_DS__" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../../include" /D "NDEBUG" /D "__WINDOWS_DS__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /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
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Wsock32.lib winmm.lib dsound.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "threebees - Win32 Debug"
@@ -65,15 +65,15 @@ LINK32=link.exe
# PROP Intermediate_Dir "Debug"
# 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 /GZ /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_DS__" /YX /FD /GZ /c
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../include" /D "_DEBUG" /D "__WINDOWS_DS__" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__LITTLE_ENDIAN__" /D "__WINDOWS_MM__" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Wsock32.lib winmm.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
@@ -107,6 +107,10 @@ SOURCE=..\..\src\FM.cpp
# End Source File
# Begin Source File
+SOURCE=..\..\src\Generator.cpp
+# End Source File
+# Begin Source File
+
SOURCE=..\..\src\Instrmnt.cpp
# End Source File
# Begin Source File
@@ -115,6 +119,10 @@ SOURCE=..\..\src\Messager.cpp
# End Source File
# Begin Source File
+SOURCE=..\..\src\Mutex.cpp
+# End Source File
+# Begin Source File
+
SOURCE=..\..\src\RtAudio.cpp
# End Source File
# Begin Source File
diff --git a/projects/ragamatic/Drone.cpp b/projects/ragamatic/Drone.cpp
index aae463d..836e933 100644
--- a/projects/ragamatic/Drone.cpp
+++ b/projects/ragamatic/Drone.cpp
@@ -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 );
}
diff --git a/projects/ragamatic/Drone.h b/projects/ragamatic/Drone.h
index a4237d7..04cfa89 100644
--- a/projects/ragamatic/Drone.h
+++ b/projects/ragamatic/Drone.h
@@ -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_;
};
diff --git a/projects/ragamatic/Makefile.in b/projects/ragamatic/Makefile.in
index ee6d260..1fe8d89 100644
--- a/projects/ragamatic/Makefile.in
+++ b/projects/ragamatic/Makefile.in
@@ -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 :
diff --git a/projects/ragamatic/Raga b/projects/ragamatic/Raga
new file mode 100755
index 0000000..e19d574
--- /dev/null
+++ b/projects/ragamatic/Raga
@@ -0,0 +1 @@
+wish < tcl/Raga.tcl | ./ragamat -ip
diff --git a/projects/ragamatic/Raga.bat b/projects/ragamatic/Raga.bat
index e19d574..ddd2606 100755
--- a/projects/ragamatic/Raga.bat
+++ b/projects/ragamatic/Raga.bat
@@ -1 +1 @@
-wish < tcl/Raga.tcl | ./ragamat -ip
+wish < tcl/Raga.tcl | ragamat -ip
diff --git a/projects/ragamatic/Tabla.cpp b/projects/ragamatic/Tabla.cpp
index 7ac9f54..4e284b6 100644
--- a/projects/ragamatic/Tabla.cpp
+++ b/projects/ragamatic/Tabla.cpp
@@ -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
#include
Tabla :: Tabla() : Instrmnt()
{
- for (int i=0; i= 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; inormalize(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; isetGain( 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; jclear();
- 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 );
}
diff --git a/projects/ragamatic/Tabla.h b/projects/ragamatic/Tabla.h
index b52b64f..45afc7c 100644
--- a/projects/ragamatic/Tabla.h
+++ b/projects/ragamatic/Tabla.h
@@ -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_;
};
diff --git a/projects/ragamatic/VoicDrum.cpp b/projects/ragamatic/VoicDrum.cpp
index 08f17ce..c3a852e 100644
--- a/projects/ragamatic/VoicDrum.cpp
+++ b/projects/ragamatic/VoicDrum.cpp
@@ -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
#include
VoicDrum :: VoicDrum() : Instrmnt()
{
- for (int i=0; i= 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; inormalize(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; isetGain( 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; jclear();
- 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 );
}
diff --git a/projects/ragamatic/VoicDrum.h b/projects/ragamatic/VoicDrum.h
index 05125e7..0a21009 100644
--- a/projects/ragamatic/VoicDrum.h
+++ b/projects/ragamatic/VoicDrum.h
@@ -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_;
};
diff --git a/projects/ragamatic/ragamat.cpp b/projects/ragamatic/ragamat.cpp
index e162c17..66201d1 100644
--- a/projects/ragamatic/ragamat.cpp
+++ b/projects/ragamatic/ragamat.cpp
@@ -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
+#include
+#include
+#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 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 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; ireverbs[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= 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;itick(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; itick(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; itick(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; itick(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; itick(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; itick(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; itick(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;
+
}
diff --git a/projects/ragamatic/ragamat.dsp b/projects/ragamatic/ragamat.dsp
index e8d8090..9a362c1 100644
--- a/projects/ragamatic/ragamat.dsp
+++ b/projects/ragamatic/ragamat.dsp
@@ -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
diff --git a/src/ADSR.cpp b/src/ADSR.cpp
index b2f837f..cd16dfb 100644
--- a/src/ADSR.cpp
+++ b/src/ADSR.cpp
@@ -11,22 +11,21 @@
envelope value reaches 0.0 in the
ADSR::RELEASE state.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
#include "ADSR.h"
-#include
ADSR :: ADSR() : Envelope()
{
- target = (MY_FLOAT) 0.0;
- value = (MY_FLOAT) 0.0;
- attackRate = (MY_FLOAT) 0.001;
- decayRate = (MY_FLOAT) 0.001;
- sustainLevel = (MY_FLOAT) 0.5;
- releaseRate = (MY_FLOAT) 0.01;
- state = ATTACK;
+ target_ = 0.0;
+ value_ = 0.0;
+ attackRate_ = 0.001;
+ decayRate_ = 0.001;
+ sustainLevel_ = 0.5;
+ releaseRate_ = 0.01;
+ state_ = ATTACK;
}
ADSR :: ~ADSR()
@@ -35,82 +34,89 @@ ADSR :: ~ADSR()
void ADSR :: keyOn()
{
- target = (MY_FLOAT) 1.0;
- rate = attackRate;
- state = ATTACK;
+ target_ = 1.0;
+ rate_ = attackRate_;
+ state_ = ATTACK;
}
void ADSR :: keyOff()
{
- target = (MY_FLOAT) 0.0;
- rate = releaseRate;
- state = RELEASE;
+ target_ = 0.0;
+ rate_ = releaseRate_;
+ state_ = RELEASE;
}
-void ADSR :: setAttackRate(MY_FLOAT aRate)
+void ADSR :: setAttackRate(StkFloat rate)
{
- if (aRate < 0.0) {
- printf("ADSR: negative rates not allowed ... correcting!\n");
- attackRate = -aRate;
+ if (rate < 0.0) {
+ errorString_ << "ADSR::setAttackRate: negative rates not allowed ... correcting!";
+ handleError( StkError::WARNING );
+ attackRate_ = -rate;
}
- else attackRate = aRate;
+ else attackRate_ = rate;
}
-void ADSR :: setDecayRate(MY_FLOAT aRate)
+void ADSR :: setDecayRate(StkFloat rate)
{
- if (aRate < 0.0) {
- printf("ADSR: negative rates not allowed ... correcting!\n");
- decayRate = -aRate;
+ if (rate < 0.0) {
+ errorString_ << "ADSR::setDecayRate: negative rates not allowed ... correcting!";
+ handleError( StkError::WARNING );
+ decayRate_ = -rate;
}
- else decayRate = aRate;
+ else decayRate_ = rate;
}
-void ADSR :: setSustainLevel(MY_FLOAT aLevel)
+void ADSR :: setSustainLevel(StkFloat level)
{
- if (aLevel < 0.0 ) {
- printf("ADSR: sustain level out of range ... correcting!\n");
- sustainLevel = (MY_FLOAT) 0.0;
+ if (level < 0.0 ) {
+ errorString_ << "ADSR::setSustainLevel: level out of range ... correcting!";
+ handleError( StkError::WARNING );
+ sustainLevel_ = 0.0;
}
- else sustainLevel = aLevel;
+ else sustainLevel_ = level;
}
-void ADSR :: setReleaseRate(MY_FLOAT aRate)
+void ADSR :: setReleaseRate(StkFloat rate)
{
- if (aRate < 0.0) {
- printf("ADSR: negative rates not allowed ... correcting!\n");
- releaseRate = -aRate;
+ if (rate < 0.0) {
+ errorString_ << "ADSR::setReleaseRate: negative rates not allowed ... correcting!";
+ handleError( StkError::WARNING );
+ releaseRate_ = -rate;
}
- else releaseRate = aRate;
+ else releaseRate_ = rate;
}
-void ADSR :: setAttackTime(MY_FLOAT aTime)
+void ADSR :: setAttackTime(StkFloat time)
{
- if (aTime < 0.0) {
- printf("ADSR: negative rates not allowed ... correcting!\n");
- attackRate = 1.0 / ( -aTime * Stk::sampleRate() );
+ if (time < 0.0) {
+ errorString_ << "ADSR::setAttackTime: negative times not allowed ... correcting!";
+ handleError( StkError::WARNING );
+ attackRate_ = 1.0 / ( -time * Stk::sampleRate() );
}
- else attackRate = 1.0 / ( aTime * Stk::sampleRate() );
+ else attackRate_ = 1.0 / ( time * Stk::sampleRate() );
}
-void ADSR :: setDecayTime(MY_FLOAT aTime)
+void ADSR :: setDecayTime(StkFloat time)
{
- if (aTime < 0.0) {
- printf("ADSR: negative times not allowed ... correcting!\n");
- decayRate = 1.0 / ( -aTime * Stk::sampleRate() );
+ if (time < 0.0) {
+ errorString_ << "ADSR::setDecayTime: negative times not allowed ... correcting!";
+ handleError( StkError::WARNING );
+ decayRate_ = 1.0 / ( -time * Stk::sampleRate() );
}
- else decayRate = 1.0 / ( aTime * Stk::sampleRate() );
+ else decayRate_ = 1.0 / ( time * Stk::sampleRate() );
}
-void ADSR :: setReleaseTime(MY_FLOAT aTime)
+void ADSR :: setReleaseTime(StkFloat time)
{
- if (aTime < 0.0) {
- printf("ADSR: negative times not allowed ... correcting!\n");
- releaseRate = sustainLevel / ( -aTime * Stk::sampleRate() );
+ if (time < 0.0) {
+ errorString_ << "ADSR::setReleaseTime: negative times not allowed ... correcting!";
+ handleError( StkError::WARNING );
+ releaseRate_ = sustainLevel_ / ( -time * Stk::sampleRate() );
}
- else releaseRate = sustainLevel / ( aTime * Stk::sampleRate() );
+ else releaseRate_ = sustainLevel_ / ( time * Stk::sampleRate() );
}
-void ADSR :: setAllTimes(MY_FLOAT aTime, MY_FLOAT dTime, MY_FLOAT sLevel, MY_FLOAT rTime)
+void ADSR :: setAllTimes(StkFloat aTime, StkFloat dTime, StkFloat sLevel, StkFloat rTime)
{
this->setAttackTime(aTime);
this->setDecayTime(dTime);
@@ -118,73 +124,76 @@ void ADSR :: setAllTimes(MY_FLOAT aTime, MY_FLOAT dTime, MY_FLOAT sLevel, MY_FLO
this->setReleaseTime(rTime);
}
-void ADSR :: setTarget(MY_FLOAT aTarget)
+void ADSR :: setTarget(StkFloat target)
{
- target = aTarget;
- if (value < target) {
- state = ATTACK;
- this->setSustainLevel(target);
- rate = attackRate;
+ target_ = target;
+ if (value_ < target_) {
+ state_ = ATTACK;
+ this->setSustainLevel(target_);
+ rate_ = attackRate_;
}
- if (value > target) {
- this->setSustainLevel(target);
- state = DECAY;
- rate = decayRate;
+ if (value_ > target_) {
+ this->setSustainLevel(target_);
+ state_ = DECAY;
+ rate_ = decayRate_;
}
}
-void ADSR :: setValue(MY_FLOAT aValue)
+void ADSR :: setValue(StkFloat value)
{
- state = SUSTAIN;
- target = aValue;
- value = aValue;
- this->setSustainLevel(aValue);
- rate = (MY_FLOAT) 0.0;
+ state_ = SUSTAIN;
+ target_ = value;
+ value_ = value;
+ this->setSustainLevel(value);
+ rate_ = (StkFloat) 0.0;
}
int ADSR :: getState(void) const
{
- return state;
+ return state_;
}
-MY_FLOAT ADSR :: tick()
+StkFloat ADSR :: tick()
{
- switch (state) {
+ switch (state_) {
case ATTACK:
- value += rate;
- if (value >= target) {
- value = target;
- rate = decayRate;
- target = sustainLevel;
- state = DECAY;
+ value_ += rate_;
+ if (value_ >= target_) {
+ value_ = target_;
+ rate_ = decayRate_;
+ target_ = sustainLevel_;
+ state_ = DECAY;
}
break;
case DECAY:
- value -= decayRate;
- if (value <= sustainLevel) {
- value = sustainLevel;
- rate = (MY_FLOAT) 0.0;
- state = SUSTAIN;
+ value_ -= decayRate_;
+ if (value_ <= sustainLevel_) {
+ value_ = sustainLevel_;
+ rate_ = (StkFloat) 0.0;
+ state_ = SUSTAIN;
}
break;
case RELEASE:
- value -= releaseRate;
- if (value <= 0.0) {
- value = (MY_FLOAT) 0.0;
- state = DONE;
+ value_ -= releaseRate_;
+ if (value_ <= 0.0) {
+ value_ = (StkFloat) 0.0;
+ state_ = DONE;
}
}
- return value;
+ lastOutput_ = value_;
+ return value_;
}
-MY_FLOAT *ADSR :: tick(MY_FLOAT *vector, unsigned int vectorSize)
+StkFloat *ADSR :: tick(StkFloat *vector, unsigned int vectorSize)
{
- for (unsigned int i=0; i
+
+Asymp :: Asymp(void) : Envelope()
+{
+ factor_ = exp( -1.0 / ( 0.3 * Stk::sampleRate() ) );
+ constant_ = 0.0;
+}
+
+Asymp :: ~Asymp(void)
+{
+}
+
+void Asymp :: keyOn(void)
+{
+ Envelope::keyOn();
+ constant_ = ( 1.0 - factor_ ) * target_;
+}
+
+void Asymp :: keyOff(void)
+{
+ Envelope::keyOff();
+ constant_ = ( 1.0 - factor_ ) * target_;
+}
+
+void Asymp :: setTau(StkFloat tau)
+{
+ if (tau <= 0.0) {
+ errorString_ << "Asymp::setTau: negative or zero tau not allowed ... ignoring!";
+ handleError( StkError::WARNING );
+ return;
+ }
+
+ factor_ = exp( -1.0 / ( tau * Stk::sampleRate() ) );
+ constant_ = ( 1.0 - factor_ ) * target_;
+}
+
+void Asymp :: setTime(StkFloat time)
+{
+ if (time <= 0.0) {
+ errorString_ << "Asymp::setTime: negative or zero times not allowed ... ignoring!";
+ handleError( StkError::WARNING );
+ return;
+ }
+
+ StkFloat tau = -time / log( TARGET_THRESHOLD );
+ factor_ = exp( -1.0 / ( tau * Stk::sampleRate() ) );
+ constant_ = ( 1.0 - factor_ ) * target_;
+}
+
+void Asymp :: setTarget(StkFloat target)
+{
+ Envelope::setTarget( target );
+ constant_ = ( 1.0 - factor_ ) * target_;
+}
+
+StkFloat Asymp :: tick(void)
+{
+ if (state_) {
+
+ value_ = factor_ * value_ + constant_;
+
+ // Check threshold.
+ if ( target_ > value_ ) {
+ if ( target_ - value_ <= TARGET_THRESHOLD ) {
+ value_ = target_;
+ state_ = 0;
+ }
+ }
+ else {
+ if ( value_ - target_ <= TARGET_THRESHOLD ) {
+ value_ = target_;
+ state_ = 0;
+ }
+ }
+ }
+
+ lastOutput_ = value_;
+ return value_;
+}
+
+StkFloat *Asymp :: tick(StkFloat *vector, unsigned int vectorSize)
+{
+ return Generator::tick( vector, vectorSize );
+}
+
+StkFrames& Asymp :: tick( StkFrames& frames, unsigned int channel )
+{
+ return Generator::tick( frames, channel );
+}
diff --git a/src/BandedWG.cpp b/src/BandedWG.cpp
index 7fca402..af36953 100644
--- a/src/BandedWG.cpp
+++ b/src/BandedWG.cpp
@@ -24,7 +24,7 @@
- Glass Harmonica = 2
- Tibetan Bowl = 3
- by Georg Essl, 1999 - 2002.
+ by Georg Essl, 1999 - 2004.
Modified for Stk 4.0 by Gary Scavone.
*/
/***************************************************/
@@ -36,45 +36,35 @@
BandedWG :: BandedWG()
{
- doPluck = true;
+ doPluck_ = true;
- delay = new DelayL[MAX_BANDED_MODES];
- bandpass = new BiQuad[MAX_BANDED_MODES];
+ bowTable_.setSlope( 3.0 );
+ adsr_.setAllTimes( 0.02, 0.005, 0.9, 0.01);
+
+ frequency_ = 220.0;
+ this->setPreset(0);
+
+ bowPosition_ = 0;
+ baseGain_ = (StkFloat) 0.999;
- bowTabl = new BowTabl;
- bowTabl->setSlope( 3.0 );
+ integrationConstant_ = 0.0;
+ trackVelocity_ = false;
- adsr = new ADSR;
- adsr->setAllTimes( 0.02, 0.005, 0.9, 0.01);
+ bowVelocity_ = 0.0;
+ bowTarget_ = 0.0;
- freakency = 220.0;
- setPreset(0);
-
- bowPosition = 0;
- baseGain = (MY_FLOAT) 0.999;
-
- integrationConstant = 0.0;
- trackVelocity = false;
-
- bowVelocity = 0.0;
- bowTarget = 0.0;
-
- strikeAmp = 0.0;
+ strikeAmp_ = 0.0;
}
BandedWG :: ~BandedWG()
{
- delete bowTabl;
- delete adsr;
- delete [] bandpass;
- delete [] delay;
}
void BandedWG :: clear()
{
- for (int i=0; i 1568.0) freakency = 1568.0;
+ if (frequency_ > 1568.0) frequency_ = 1568.0;
- MY_FLOAT radius;
- MY_FLOAT base = Stk::sampleRate() / freakency;
- MY_FLOAT length;
- for (int i=0; i 2.0) {
- delay[i].setDelay( length );
- gains[i]=basegains[i];
- // gains[i]=(MY_FLOAT) pow(basegains[i], 1/((MY_FLOAT)delay[i].getDelay()));
- // std::cerr << gains[i];
+ delay_[i].setDelay( length );
+ gains_[i]=basegains_[i];
+ // gains_[i]=(StkFloat) pow(basegains_[i], 1/((StkFloat)delay_[i].getDelay()));
+ // std::cerr << gains_[i];
}
else {
- nModes = i;
+ nModes_ = i;
break;
}
// std::cerr << std::endl;
// Set the bandpass filter resonances
- radius = 1.0 - PI * 32 / Stk::sampleRate(); //freakency * modes[i] / Stk::sampleRate()/32;
+ radius = 1.0 - PI * 32 / Stk::sampleRate(); //frequency_ * modes_[i] / Stk::sampleRate()/32;
if ( radius < 0.0 ) radius = 0.0;
- bandpass[i].setResonance(freakency * modes[i], radius, true);
+ bandpass_[i].setResonance(frequency_ * modes_[i], radius, true);
- delay[i].clear();
- bandpass[i].clear();
+ delay_[i].clear();
+ bandpass_[i].clear();
}
- //int olen = (int)(delay[0].getDelay());
- //strikePosition = (int)(strikePosition*(length/modes[0])/olen);
+ //int olen = (int)(delay_[0].getDelay());
+ //strikePosition_ = (int)(strikePosition_*(length/modes_[0])/olen);
}
-void BandedWG :: setStrikePosition(MY_FLOAT position)
+void BandedWG :: setStrikePosition(StkFloat position)
{
- strikePosition = (int)(delay[0].getDelay() * position / 2.0);
+ strikePosition_ = (int)(delay_[0].getDelay() * position / 2.0);
}
-void BandedWG :: startBowing(MY_FLOAT amplitude, MY_FLOAT rate)
+void BandedWG :: startBowing(StkFloat amplitude, StkFloat rate)
{
- adsr->setRate(rate);
- adsr->keyOn();
- maxVelocity = 0.03 + (0.1 * amplitude);
+ adsr_.setRate(rate);
+ adsr_.keyOn();
+ maxVelocity_ = 0.03 + (0.1 * amplitude);
}
-void BandedWG :: stopBowing(MY_FLOAT rate)
+void BandedWG :: stopBowing(StkFloat rate)
{
- adsr->setRate(rate);
- adsr->keyOff();
+ adsr_.setRate(rate);
+ adsr_.keyOff();
}
-void BandedWG :: pluck(MY_FLOAT amplitude)
+void BandedWG :: pluck(StkFloat amplitude)
{
int j;
- MY_FLOAT min_len = delay[nModes-1].getDelay();
- for (int i=0; isetFrequency(frequency);
- if ( doPluck )
+ if ( doPluck_ )
this->pluck(amplitude);
else
this->startBowing(amplitude, amplitude * 0.001);
#if defined(_STK_DEBUG_)
- std::cerr << "BandedWG: NoteOn frequency = " << frequency << ", amplitude = " << amplitude << std::endl;
+ errorString_ << "BandedWG::NoteOn: frequency = " << frequency << ", amplitude = " << amplitude << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-void BandedWG :: noteOff(MY_FLOAT amplitude)
+void BandedWG :: noteOff(StkFloat amplitude)
{
- if ( !doPluck )
+ if ( !doPluck_ )
this->stopBowing((1.0 - amplitude) * 0.005);
#if defined(_STK_DEBUG_)
- std::cerr << "BandedWG: NoteOff amplitude = " << amplitude << std::endl;
+ errorString_ << "BandedWG::NoteOff: amplitude = " << amplitude << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-MY_FLOAT BandedWG :: tick()
+StkFloat BandedWG :: tick()
{
int k;
- MY_FLOAT input = 0.0;
- if ( doPluck ) {
+ StkFloat input = 0.0;
+ if ( doPluck_ ) {
input = 0.0;
- // input = strikeAmp/nModes;
- // strikeAmp = 0.0;
+ // input = strikeAmp_/nModes_;
+ // strikeAmp_ = 0.0;
}
else {
- if (integrationConstant == 0.0)
- velocityInput = 0.0;
+ if (integrationConstant_ == 0.0)
+ velocityInput_ = 0.0;
else
- velocityInput = integrationConstant * velocityInput;
+ velocityInput_ = integrationConstant_ * velocityInput_;
- for (k=0; ktick() * maxVelocity;
+ bowVelocity_ = adsr_.tick() * maxVelocity_;
- input = bowVelocity - velocityInput;
- input = input * bowTabl->tick(input);
- input = input/(MY_FLOAT)nModes;
+ input = bowVelocity_ - velocityInput_;
+ input = input * bowTable_.tick(input);
+ input = input/(StkFloat)nModes_;
}
- MY_FLOAT data = 0.0;
- for (k=0; k 1.0 ) {
norm = 1.0;
- std::cerr << "BandedWG: Control value greater than 128.0!" << std::endl;
+ errorString_ << "BandedWG::controlChange: control value greater than 128.0 ... setting to 128.0!";
+ handleError( StkError::WARNING );
}
if (number == __SK_BowPressure_) { // 2
if ( norm == 0.0 )
- doPluck = true;
+ doPluck_ = true;
else {
- doPluck = false;
- bowTabl->setSlope( 10.0 - (9.0 * norm));
+ doPluck_ = false;
+ bowTable_.setSlope( 10.0 - (9.0 * norm));
}
}
else if (number == 4) { // 4
- if ( !trackVelocity ) trackVelocity = true;
- bowTarget += 0.005 * (norm - bowPosition);
- bowPosition = norm;
- //adsr->setTarget(bowPosition);
+ if ( !trackVelocity_ ) trackVelocity_ = true;
+ bowTarget_ += 0.005 * (norm - bowPosition_);
+ bowPosition_ = norm;
+ //adsr_.setTarget(bowPosition_);
}
else if (number == 8) // 8
this->setStrikePosition( norm );
else if (number == __SK_AfterTouch_Cont_) { // 128
- //bowTarget += 0.02 * (norm - bowPosition);
- //bowPosition = norm;
- if ( trackVelocity ) trackVelocity = false;
- maxVelocity = 0.13 * norm;
- adsr->setTarget(norm);
+ //bowTarget_ += 0.02 * (norm - bowPosition_);
+ //bowPosition_ = norm;
+ if ( trackVelocity_ ) trackVelocity_ = false;
+ maxVelocity_ = 0.13 * norm;
+ adsr_.setTarget(norm);
}
else if (number == __SK_ModWheel_) { // 1
- // baseGain = 0.9989999999 + (0.001 * norm );
- baseGain = 0.8999999999999999 + (0.1 * norm);
+ // baseGain_ = 0.9989999999 + (0.001 * norm );
+ baseGain_ = 0.8999999999999999 + (0.1 * norm);
// std::cerr << "Yuck!" << std::endl;
- for (int i=0; isetPreset((int) value);
- else
- std::cerr << "BandedWG: Undefined Control Number (" << number << ")!!" << std::endl;
+ else {
+ errorString_ << "BandedWG::controlChange: undefined control number (" << number << ")!";
+ handleError( StkError::WARNING );
+ }
#if defined(_STK_DEBUG_)
- std::cerr << "BandedWG: controlChange number = " << number << ", value = " << value << std::endl;
+ errorString_ << "BandedWG::controlChange: number = " << number << ", value = " << value << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
diff --git a/src/BeeThree.cpp b/src/BeeThree.cpp
index e3f4989..389fce9 100644
--- a/src/BeeThree.cpp
+++ b/src/BeeThree.cpp
@@ -28,7 +28,7 @@
type who should worry about this (making
money) worry away.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
@@ -38,66 +38,77 @@ BeeThree :: BeeThree()
: FM()
{
// Concatenate the STK rawwave path to the rawwave files
- for ( int i=0; i<3; i++ )
- waves[i] = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), TRUE );
- waves[3] = new WaveLoop( (Stk::rawwavePath() + "fwavblnk.raw").c_str(), TRUE );
+ for ( unsigned int i=0; i<3; i++ )
+ waves_[i] = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), true );
+ waves_[3] = new WaveLoop( (Stk::rawwavePath() + "fwavblnk.raw").c_str(), true );
this->setRatio(0, 0.999);
this->setRatio(1, 1.997);
this->setRatio(2, 3.006);
this->setRatio(3, 6.009);
- gains[0] = __FM_gains[95];
- gains[1] = __FM_gains[95];
- gains[2] = __FM_gains[99];
- gains[3] = __FM_gains[95];
+ gains_[0] = fmGains_[95];
+ gains_[1] = fmGains_[95];
+ gains_[2] = fmGains_[99];
+ gains_[3] = fmGains_[95];
- adsr[0]->setAllTimes( 0.005, 0.003, 1.0, 0.01);
- adsr[1]->setAllTimes( 0.005, 0.003, 1.0, 0.01);
- adsr[2]->setAllTimes( 0.005, 0.003, 1.0, 0.01);
- adsr[3]->setAllTimes( 0.005, 0.001, 0.4, 0.03);
+ adsr_[0]->setAllTimes( 0.005, 0.003, 1.0, 0.01);
+ adsr_[1]->setAllTimes( 0.005, 0.003, 1.0, 0.01);
+ adsr_[2]->setAllTimes( 0.005, 0.003, 1.0, 0.01);
+ adsr_[3]->setAllTimes( 0.005, 0.001, 0.4, 0.03);
- twozero->setGain( 0.1 );
+ twozero_.setGain( 0.1 );
}
BeeThree :: ~BeeThree()
{
}
-void BeeThree :: noteOn(MY_FLOAT frequency, MY_FLOAT amplitude)
+void BeeThree :: noteOn(StkFloat frequency, StkFloat amplitude)
{
- gains[0] = amplitude * __FM_gains[95];
- gains[1] = amplitude * __FM_gains[95];
- gains[2] = amplitude * __FM_gains[99];
- gains[3] = amplitude * __FM_gains[95];
- this->setFrequency(frequency);
+ gains_[0] = amplitude * fmGains_[95];
+ gains_[1] = amplitude * fmGains_[95];
+ gains_[2] = amplitude * fmGains_[99];
+ gains_[3] = amplitude * fmGains_[95];
+ this->setFrequency( frequency );
this->keyOn();
#if defined(_STK_DEBUG_)
- cerr << "BeeThree: NoteOn frequency = " << frequency << ", amplitude = " << amplitude << endl;
+ errorString_ << "BeeThree::NoteOn: frequency = " << frequency << ", amplitude = " << amplitude << '.';
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-MY_FLOAT BeeThree :: tick()
+StkFloat BeeThree :: tick()
{
- register MY_FLOAT temp;
+ register StkFloat temp;
- if (modDepth > 0.0) {
- temp = 1.0 + (modDepth * vibrato->tick() * 0.1);
- waves[0]->setFrequency(baseFrequency * temp * ratios[0]);
- waves[1]->setFrequency(baseFrequency * temp * ratios[1]);
- waves[2]->setFrequency(baseFrequency * temp * ratios[2]);
- waves[3]->setFrequency(baseFrequency * temp * ratios[3]);
+ if (modDepth_ > 0.0) {
+ temp = 1.0 + (modDepth_ * vibrato_->tick() * 0.1);
+ waves_[0]->setFrequency(baseFrequency_ * temp * ratios_[0]);
+ waves_[1]->setFrequency(baseFrequency_ * temp * ratios_[1]);
+ waves_[2]->setFrequency(baseFrequency_ * temp * ratios_[2]);
+ waves_[3]->setFrequency(baseFrequency_ * temp * ratios_[3]);
}
- waves[3]->addPhaseOffset(twozero->lastOut());
- temp = control1 * 2.0 * gains[3] * adsr[3]->tick() * waves[3]->tick();
- twozero->tick(temp);
+ waves_[3]->addPhaseOffset( twozero_.lastOut() );
+ temp = control1_ * 2.0 * gains_[3] * adsr_[3]->tick() * waves_[3]->tick();
+ twozero_.tick(temp);
- temp += control2 * 2.0 * gains[2] * adsr[2]->tick() * waves[2]->tick();
- temp += gains[1] * adsr[1]->tick() * waves[1]->tick();
- temp += gains[0] * adsr[0]->tick() * waves[0]->tick();
+ temp += control2_ * 2.0 * gains_[2] * adsr_[2]->tick() * waves_[2]->tick();
+ temp += gains_[1] * adsr_[1]->tick() * waves_[1]->tick();
+ temp += gains_[0] * adsr_[0]->tick() * waves_[0]->tick();
- lastOutput = temp * 0.125;
- return lastOutput;
+ lastOutput_ = temp * 0.125;
+ return lastOutput_;
+}
+
+StkFloat *BeeThree :: tick(StkFloat *vector, unsigned int vectorSize)
+{
+ return Instrmnt::tick( vector, vectorSize );
+}
+
+StkFrames& BeeThree :: tick( StkFrames& frames, unsigned int channel )
+{
+ return Instrmnt::tick( frames, channel );
}
diff --git a/src/BiQuad.cpp b/src/BiQuad.cpp
index b970afb..b2e7f9d 100644
--- a/src/BiQuad.cpp
+++ b/src/BiQuad.cpp
@@ -8,7 +8,7 @@
frequency response while maintaining a constant
filter gain.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
@@ -17,9 +17,11 @@
BiQuad :: BiQuad() : Filter()
{
- MY_FLOAT B[3] = {1.0, 0.0, 0.0};
- MY_FLOAT A[3] = {1.0, 0.0, 0.0};
- Filter::setCoefficients( 3, B, 3, A );
+ std::vector b(3, 0.0);
+ std::vector a(3, 0.0);
+ b[0] = 1.0;
+ a[0] = 1.0;
+ Filter::setCoefficients( b, a );
}
BiQuad :: ~BiQuad()
@@ -31,90 +33,92 @@ void BiQuad :: clear(void)
Filter::clear();
}
-void BiQuad :: setB0(MY_FLOAT b0)
+void BiQuad :: setB0(StkFloat b0)
{
- b[0] = b0;
+ b_[0] = b0;
}
-void BiQuad :: setB1(MY_FLOAT b1)
+void BiQuad :: setB1(StkFloat b1)
{
- b[1] = b1;
+ b_[1] = b1;
}
-void BiQuad :: setB2(MY_FLOAT b2)
+void BiQuad :: setB2(StkFloat b2)
{
- b[2] = b2;
+ b_[2] = b2;
}
-void BiQuad :: setA1(MY_FLOAT a1)
+void BiQuad :: setA1(StkFloat a1)
{
- a[1] = a1;
+ a_[1] = a1;
}
-void BiQuad :: setA2(MY_FLOAT a2)
+void BiQuad :: setA2(StkFloat a2)
{
- a[2] = a2;
+ a_[2] = a2;
}
-void BiQuad :: setResonance(MY_FLOAT frequency, MY_FLOAT radius, bool normalize)
+void BiQuad :: setResonance(StkFloat frequency, StkFloat radius, bool normalize)
{
- a[2] = radius * radius;
- a[1] = -2.0 * radius * cos(TWO_PI * frequency / Stk::sampleRate());
+ a_[2] = radius * radius;
+ a_[1] = -2.0 * radius * cos(TWO_PI * frequency / Stk::sampleRate());
if ( normalize ) {
// Use zeros at +- 1 and normalize the filter peak gain.
- b[0] = 0.5 - 0.5 * a[2];
- b[1] = 0.0;
- b[2] = -b[0];
+ b_[0] = 0.5 - 0.5 * a_[2];
+ b_[1] = 0.0;
+ b_[2] = -b_[0];
}
}
-void BiQuad :: setNotch(MY_FLOAT frequency, MY_FLOAT radius)
+void BiQuad :: setNotch(StkFloat frequency, StkFloat radius)
{
// This method does not attempt to normalize the filter gain.
- b[2] = radius * radius;
- b[1] = (MY_FLOAT) -2.0 * radius * cos(TWO_PI * (double) frequency / Stk::sampleRate());
+ b_[2] = radius * radius;
+ b_[1] = (StkFloat) -2.0 * radius * cos(TWO_PI * (double) frequency / Stk::sampleRate());
}
void BiQuad :: setEqualGainZeroes()
{
- b[0] = 1.0;
- b[1] = 0.0;
- b[2] = -1.0;
+ b_[0] = 1.0;
+ b_[1] = 0.0;
+ b_[2] = -1.0;
}
-void BiQuad :: setGain(MY_FLOAT theGain)
+void BiQuad :: setGain(StkFloat gain)
{
- Filter::setGain(theGain);
+ Filter::setGain(gain);
}
-MY_FLOAT BiQuad :: getGain(void) const
+StkFloat BiQuad :: getGain(void) const
{
return Filter::getGain();
}
-MY_FLOAT BiQuad :: lastOut(void) const
+StkFloat BiQuad :: lastOut(void) const
{
return Filter::lastOut();
}
-MY_FLOAT BiQuad :: tick(MY_FLOAT sample)
+StkFloat BiQuad :: tick(StkFloat sample)
{
- inputs[0] = gain * sample;
- outputs[0] = b[0] * inputs[0] + b[1] * inputs[1] + b[2] * inputs[2];
- outputs[0] -= a[2] * outputs[2] + a[1] * outputs[1];
- inputs[2] = inputs[1];
- inputs[1] = inputs[0];
- outputs[2] = outputs[1];
- outputs[1] = outputs[0];
+ inputs_[0] = gain_ * sample;
+ outputs_[0] = b_[0] * inputs_[0] + b_[1] * inputs_[1] + b_[2] * inputs_[2];
+ outputs_[0] -= a_[2] * outputs_[2] + a_[1] * outputs_[1];
+ inputs_[2] = inputs_[1];
+ inputs_[1] = inputs_[0];
+ outputs_[2] = outputs_[1];
+ outputs_[1] = outputs_[0];
- return outputs[0];
+ return outputs_[0];
}
-MY_FLOAT *BiQuad :: tick(MY_FLOAT *vector, unsigned int vectorSize)
+StkFloat *BiQuad :: tick(StkFloat *vector, unsigned int vectorSize)
{
- for (unsigned int i=0; isetBlockZero();
+ dcBlock_.setBlockZero();
// Concatenate the STK rawwave path to the rawwave file
- vibrato = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), TRUE );
- vibrato->setFrequency( 5.925 );
- vibratoGain = 0.0;
+ vibrato_ = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), true );
+ vibrato_->setFrequency( 5.925 );
+ vibratoGain_ = 0.0;
- resonator = new BiQuad();
- resonator->setResonance(500.0, __BOTTLE_RADIUS_, true);
+ resonator_.setResonance(500.0, __BOTTLE_RADIUS_, true);
+ adsr_.setAllTimes( 0.005, 0.01, 0.8, 0.010);
- adsr = new ADSR();
- adsr->setAllTimes( 0.005, 0.01, 0.8, 0.010);
-
- noise = new Noise();
- noiseGain = 20.0;
-
- maxPressure = (MY_FLOAT) 0.0;
+ noiseGain_ = 20.0;
+ maxPressure_ = (StkFloat) 0.0;
}
BlowBotl :: ~BlowBotl()
{
- delete jetTable;
- delete resonator;
- delete dcBlock;
- delete noise;
- delete adsr;
- delete vibrato;
+ delete vibrato_;
}
void BlowBotl :: clear()
{
- resonator->clear();
+ resonator_.clear();
}
-void BlowBotl :: setFrequency(MY_FLOAT frequency)
+void BlowBotl :: setFrequency(StkFloat frequency)
{
- MY_FLOAT freakency = frequency;
+ StkFloat freakency = frequency;
if ( frequency <= 0.0 ) {
- std::cerr << "BlowBotl: setFrequency parameter is less than or equal to zero!" << std::endl;
+ errorString_ << "BlowBotl::setFrequency: parameter is less than or equal to zero!";
+ handleError( StkError::WARNING );
freakency = 220.0;
}
- resonator->setResonance( freakency, __BOTTLE_RADIUS_, true );
+ resonator_.setResonance( freakency, __BOTTLE_RADIUS_, true );
}
-void BlowBotl :: startBlowing(MY_FLOAT amplitude, MY_FLOAT rate)
+void BlowBotl :: startBlowing(StkFloat amplitude, StkFloat rate)
{
- adsr->setAttackRate(rate);
- maxPressure = amplitude;
- adsr->keyOn();
+ adsr_.setAttackRate(rate);
+ maxPressure_ = amplitude;
+ adsr_.keyOn();
}
-void BlowBotl :: stopBlowing(MY_FLOAT rate)
+void BlowBotl :: stopBlowing(StkFloat rate)
{
- adsr->setReleaseRate(rate);
- adsr->keyOff();
+ adsr_.setReleaseRate(rate);
+ adsr_.keyOff();
}
-void BlowBotl :: noteOn(MY_FLOAT frequency, MY_FLOAT amplitude)
+void BlowBotl :: noteOn(StkFloat frequency, StkFloat amplitude)
{
- setFrequency(frequency);
+ this->setFrequency(frequency);
startBlowing( 1.1 + (amplitude * 0.20), amplitude * 0.02);
- outputGain = amplitude + 0.001;
+ outputGain_ = amplitude + 0.001;
#if defined(_STK_DEBUG_)
- std::cerr << "BlowBotl: NoteOn frequency = " << frequency << ", amplitude = " << amplitude << std::endl;
+ errorString_ << "BlowBotl::NoteOn: frequency = " << frequency << ", amplitude = " << amplitude << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-void BlowBotl :: noteOff(MY_FLOAT amplitude)
+void BlowBotl :: noteOff(StkFloat amplitude)
{
this->stopBlowing(amplitude * 0.02);
#if defined(_STK_DEBUG_)
- std::cerr << "BlowBotl: NoteOff amplitude = " << amplitude << std::endl;
+ errorString_ << "BlowBotl::NoteOff: amplitude = " << amplitude << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-MY_FLOAT BlowBotl :: tick()
+StkFloat BlowBotl :: tick()
{
- MY_FLOAT breathPressure;
- MY_FLOAT randPressure;
- MY_FLOAT pressureDiff;
+ StkFloat breathPressure;
+ StkFloat randPressure;
+ StkFloat pressureDiff;
// Calculate the breath pressure (envelope + vibrato)
- breathPressure = maxPressure * adsr->tick();
- breathPressure += vibratoGain * vibrato->tick();
+ breathPressure = maxPressure_ * adsr_.tick();
+ breathPressure += vibratoGain_ * vibrato_->tick();
- pressureDiff = breathPressure - resonator->lastOut();
+ pressureDiff = breathPressure - resonator_.lastOut();
- randPressure = noiseGain * noise->tick();
+ randPressure = noiseGain_ * noise_.tick();
randPressure *= breathPressure;
randPressure *= (1.0 + pressureDiff);
- resonator->tick( breathPressure + randPressure - ( jetTable->tick( pressureDiff ) * pressureDiff ) );
- lastOutput = 0.2 * outputGain * dcBlock->tick( pressureDiff );
+ resonator_.tick( breathPressure + randPressure - ( jetTable_.tick( pressureDiff ) * pressureDiff ) );
+ lastOutput_ = 0.2 * outputGain_ * dcBlock_.tick( pressureDiff );
- return lastOutput;
+ return lastOutput_;
}
-void BlowBotl :: controlChange(int number, MY_FLOAT value)
+StkFloat *BlowBotl :: tick(StkFloat *vector, unsigned int vectorSize)
{
- MY_FLOAT norm = value * ONE_OVER_128;
+ return Instrmnt::tick( vector, vectorSize );
+}
+
+StkFrames& BlowBotl :: tick( StkFrames& frames, unsigned int channel )
+{
+ return Instrmnt::tick( frames, channel );
+}
+
+void BlowBotl :: controlChange(int number, StkFloat value)
+{
+ StkFloat norm = value * ONE_OVER_128;
if ( norm < 0 ) {
norm = 0.0;
- std::cerr << "BlowBotl: Control value less than zero!" << std::endl;
+ errorString_ << "BlowBotl::controlChange: control value less than zero ... setting to zero!";
+ handleError( StkError::WARNING );
}
else if ( norm > 1.0 ) {
norm = 1.0;
- std::cerr << "BlowBotl: Control value greater than 128.0!" << std::endl;
+ errorString_ << "BlowBotl::controlChange: control value greater than 128.0 ... setting to 128.0!";
+ handleError( StkError::WARNING );
}
if (number == __SK_NoiseLevel_) // 4
- noiseGain = norm * 30.0;
+ noiseGain_ = norm * 30.0;
else if (number == __SK_ModFrequency_) // 11
- vibrato->setFrequency( norm * 12.0 );
+ vibrato_->setFrequency( norm * 12.0 );
else if (number == __SK_ModWheel_) // 1
- vibratoGain = norm * 0.4;
+ vibratoGain_ = norm * 0.4;
else if (number == __SK_AfterTouch_Cont_) // 128
- adsr->setTarget( norm );
- else
- std::cerr << "BlowBotl: Undefined Control Number (" << number << ")!!" << std::endl;
+ adsr_.setTarget( norm );
+ else {
+ errorString_ << "BlowBotl::controlChange: undefined control number (" << number << ")!";
+ handleError( StkError::WARNING );
+ }
#if defined(_STK_DEBUG_)
- std::cerr << "BlowBotl: controlChange number = " << number << ", value = " << value << std::endl;
+ errorString_ << "BlowBotl::controlChange: number = " << number << ", value = " << value << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
diff --git a/src/BlowHole.cpp b/src/BlowHole.cpp
index 7ee7f69..2efb8c5 100644
--- a/src/BlowHole.cpp
+++ b/src/BlowHole.cpp
@@ -29,7 +29,7 @@
- Register State = 1
- Breath Pressure = 128
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
@@ -37,221 +37,232 @@
#include "SKINI.msg"
#include
-BlowHole :: BlowHole(MY_FLOAT lowestFrequency)
+BlowHole :: BlowHole(StkFloat lowestFrequency)
{
- length = (long) (Stk::sampleRate() / lowestFrequency + 1);
+ length_ = (unsigned long) (Stk::sampleRate() / lowestFrequency + 1);
// delays[0] is the delay line between the reed and the register vent.
- delays[0] = (DelayL *) new DelayL( 5.0 * Stk::sampleRate() / 22050.0, 100 );
+ delays_[0].setDelay( 5.0 * Stk::sampleRate() / 22050.0 );
// delays[1] is the delay line between the register vent and the tonehole.
- delays[1] = (DelayL *) new DelayL( length >> 1, length );
+ delays_[1].setMaximumDelay( length_ );
+ delays_[1].setDelay( length_ >> 1 );
// delays[2] is the delay line between the tonehole and the end of the bore.
- delays[2] = (DelayL *) new DelayL( 4.0 * Stk::sampleRate() / 22050.0, 100 );
- reedTable = new ReedTabl();
- reedTable->setOffset((MY_FLOAT) 0.7);
- reedTable->setSlope((MY_FLOAT) -0.3);
- filter = new OneZero;
- envelope = new Envelope;
- noise = new Noise;
+ delays_[2].setDelay( 4.0 * Stk::sampleRate() / 22050.0 );
+
+ reedTable_.setOffset( 0.7 );
+ reedTable_.setSlope( -0.3 );
// Calculate the initial tonehole three-port scattering coefficient
- double r_b = 0.0075; // main bore radius
- r_th = 0.003; // tonehole radius
- scatter = -pow(r_th,2) / ( pow(r_th,2) + 2*pow(r_b,2) );
+ StkFloat rb = 0.0075; // main bore radius
+ StkFloat rth = 0.003; // tonehole radius
+ scatter_ = -pow(rth,2) / ( pow(rth,2) + 2*pow(rb,2) );
- // Calculate tonehole coefficients
- MY_FLOAT te = 1.4 * r_th; // effective length of the open hole
- th_coeff = (te*2*Stk::sampleRate() - 347.23) / (te*2*Stk::sampleRate() + 347.23);
- tonehole = new PoleZero;
- // Start with tonehole open
- tonehole->setA1(-th_coeff);
- tonehole->setB0(th_coeff);
- tonehole->setB1(-1.0);
+ // Calculate tonehole coefficients and set for initially open.
+ StkFloat te = 1.4 * rth; // effective length of the open hole
+ thCoeff_ = (te*2*Stk::sampleRate() - 347.23) / (te*2*Stk::sampleRate() + 347.23);
+ tonehole_.setA1(-thCoeff_);
+ tonehole_.setB0(thCoeff_);
+ tonehole_.setB1(-1.0);
// Calculate register hole filter coefficients
double r_rh = 0.0015; // register vent radius
- te = 1.4 * r_rh; // effective length of the open hole
+ te = 1.4 * r_rh; // effective length of the open hole
double xi = 0.0; // series resistance term
- double zeta = 347.23 + 2*PI*pow(r_b,2)*xi/1.1769;
- double psi = 2*PI*pow(r_b,2)*te / (PI*pow(r_rh,2));
- rh_coeff = (zeta - 2 * Stk::sampleRate() * psi) / (zeta + 2 * Stk::sampleRate() * psi);
- rh_gain = -347.23 / (zeta + 2 * Stk::sampleRate() * psi);
- vent = new PoleZero;
- vent->setA1(rh_coeff);
- vent->setB0(1.0);
- vent->setB1(1.0);
+ double zeta = 347.23 + 2*PI*pow(rb,2)*xi/1.1769;
+ double psi = 2*PI*pow(rb,2)*te / (PI*pow(r_rh,2));
+ StkFloat rhCoeff = (zeta - 2 * Stk::sampleRate() * psi) / (zeta + 2 * Stk::sampleRate() * psi);
+ rhGain_ = -347.23 / (zeta + 2 * Stk::sampleRate() * psi);
+ vent_.setA1( rhCoeff );
+ vent_.setB0(1.0);
+ vent_.setB1(1.0);
// Start with register vent closed
- vent->setGain(0.0);
+ vent_.setGain(0.0);
// Concatenate the STK rawwave path to the rawwave file
- vibrato = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), TRUE );
- vibrato->setFrequency((MY_FLOAT) 5.735);
- outputGain = (MY_FLOAT) 1.0;
- noiseGain = (MY_FLOAT) 0.2;
- vibratoGain = (MY_FLOAT) 0.01;
+ vibrato_ = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), true );
+ vibrato_->setFrequency((StkFloat) 5.735);
+ outputGain_ = 1.0;
+ noiseGain_ = 0.2;
+ vibratoGain_ = 0.01;
}
BlowHole :: ~BlowHole()
{
- delete delays[0];
- delete delays[1];
- delete delays[2];
- delete reedTable;
- delete filter;
- delete tonehole;
- delete vent;
- delete envelope;
- delete noise;
- delete vibrato;
+ delete vibrato_;
}
void BlowHole :: clear()
{
- delays[0]->clear();
- delays[1]->clear();
- delays[2]->clear();
- filter->tick((MY_FLOAT) 0.0);
- tonehole->tick((MY_FLOAT) 0.0);
- vent->tick((MY_FLOAT) 0.0);
+ delays_[0].clear();
+ delays_[1].clear();
+ delays_[2].clear();
+ filter_.tick( 0.0 );
+ tonehole_.tick( 0.0 );
+ vent_.tick( 0.0 );
}
-void BlowHole :: setFrequency(MY_FLOAT frequency)
+void BlowHole :: setFrequency(StkFloat frequency)
{
- MY_FLOAT freakency = frequency;
+ StkFloat freakency = frequency;
if ( frequency <= 0.0 ) {
std::cerr << "BlowHole: setFrequency parameter is less than or equal to zero!" << std::endl;
freakency = 220.0;
}
// Delay = length - approximate filter delay.
- MY_FLOAT delay = (Stk::sampleRate() / freakency) * 0.5 - 3.5;
- delay -= delays[0]->getDelay() + delays[2]->getDelay();
+ StkFloat delay = (Stk::sampleRate() / freakency) * 0.5 - 3.5;
+ delay -= delays_[0].getDelay() + delays_[2].getDelay();
if (delay <= 0.0) delay = 0.3;
- else if (delay > length) delay = length;
- delays[1]->setDelay(delay);
+ else if (delay > length_) delay = length_;
+ delays_[1].setDelay(delay);
}
-void BlowHole :: setVent(MY_FLOAT newValue)
+void BlowHole :: setVent(StkFloat newValue)
{
// This method allows setting of the register vent "open-ness" at
// any point between "Open" (newValue = 1) and "Closed"
// (newValue = 0).
- MY_FLOAT gain;
+ StkFloat gain;
- if (newValue <= 0.0) gain = 0.0;
- else if (newValue >= 1.0) gain = rh_gain;
- else gain = newValue * rh_gain;
- vent->setGain(gain);
+ if (newValue <= 0.0)
+ gain = 0.0;
+ else if (newValue >= 1.0)
+ gain = rhGain_;
+ else
+ gain = newValue * rhGain_;
+
+ vent_.setGain( gain );
}
-void BlowHole :: setTonehole(MY_FLOAT newValue)
+void BlowHole :: setTonehole(StkFloat newValue)
{
// This method allows setting of the tonehole "open-ness" at
// any point between "Open" (newValue = 1) and "Closed"
// (newValue = 0).
- MY_FLOAT new_coeff;
+ StkFloat new_coeff;
- if (newValue <= 0.0) new_coeff = 0.9995;
- else if (newValue >= 1.0) new_coeff = th_coeff;
- else new_coeff = (newValue * (th_coeff - 0.9995)) + 0.9995;
- tonehole->setA1(-new_coeff);
- tonehole->setB0(new_coeff);
+ if ( newValue <= 0.0 )
+ new_coeff = 0.9995;
+ else if ( newValue >= 1.0 )
+ new_coeff = thCoeff_;
+ else
+ new_coeff = (newValue * (thCoeff_ - 0.9995)) + 0.9995;
+
+ tonehole_.setA1( -new_coeff );
+ tonehole_.setB0( new_coeff );
}
-void BlowHole :: startBlowing(MY_FLOAT amplitude, MY_FLOAT rate)
+void BlowHole :: startBlowing(StkFloat amplitude, StkFloat rate)
{
- envelope->setRate(rate);
- envelope->setTarget(amplitude);
+ envelope_.setRate( rate );
+ envelope_.setTarget( amplitude );
}
-void BlowHole :: stopBlowing(MY_FLOAT rate)
+void BlowHole :: stopBlowing(StkFloat rate)
{
- envelope->setRate(rate);
- envelope->setTarget((MY_FLOAT) 0.0);
+ envelope_.setRate( rate );
+ envelope_.setTarget( 0.0 );
}
-void BlowHole :: noteOn(MY_FLOAT frequency, MY_FLOAT amplitude)
+void BlowHole :: noteOn(StkFloat frequency, StkFloat amplitude)
{
- setFrequency(frequency);
- startBlowing((MY_FLOAT) 0.55 + (amplitude * 0.30), amplitude * 0.005);
- outputGain = amplitude + 0.001;
+ this->setFrequency( frequency );
+ this->startBlowing( 0.55 + (amplitude * 0.30), amplitude * 0.005 );
+ outputGain_ = amplitude + 0.001;
#if defined(_STK_DEBUG_)
- std::cerr << "BlowHole: NoteOn frequency = " << frequency << ", amplitude = " << amplitude << std::endl;
+ errorString_ << "BlowHole::NoteOn: frequency = " << frequency << ", amplitude = " << amplitude << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-void BlowHole :: noteOff(MY_FLOAT amplitude)
+void BlowHole :: noteOff(StkFloat amplitude)
{
- this->stopBlowing(amplitude * 0.01);
+ this->stopBlowing( amplitude * 0.01 );
#if defined(_STK_DEBUG_)
- std::cerr << "BlowHole: NoteOff amplitude = " << amplitude << std::endl;
+ errorString_ << "BlowHole::NoteOff: amplitude = " << amplitude << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-MY_FLOAT BlowHole :: tick()
+StkFloat BlowHole :: tick()
{
- MY_FLOAT pressureDiff;
- MY_FLOAT breathPressure;
- MY_FLOAT temp;
+ StkFloat pressureDiff;
+ StkFloat breathPressure;
+ StkFloat temp;
// Calculate the breath pressure (envelope + noise + vibrato)
- breathPressure = envelope->tick();
- breathPressure += breathPressure * noiseGain * noise->tick();
- breathPressure += breathPressure * vibratoGain * vibrato->tick();
+ breathPressure = envelope_.tick();
+ breathPressure += breathPressure * noiseGain_ * noise_.tick();
+ breathPressure += breathPressure * vibratoGain_ * vibrato_->tick();
// Calculate the differential pressure = reflected - mouthpiece pressures
- pressureDiff = delays[0]->lastOut() - breathPressure;
+ pressureDiff = delays_[0].lastOut() - breathPressure;
// Do two-port junction scattering for register vent
- MY_FLOAT pa = breathPressure + pressureDiff * reedTable->tick(pressureDiff);
- MY_FLOAT pb = delays[1]->lastOut();
- vent->tick(pa+pb);
+ StkFloat pa = breathPressure + pressureDiff * reedTable_.tick( pressureDiff );
+ StkFloat pb = delays_[1].lastOut();
+ vent_.tick( pa+pb );
- lastOutput = delays[0]->tick(vent->lastOut()+pb);
- lastOutput *= outputGain;
+ lastOutput_ = delays_[0].tick( vent_.lastOut()+pb );
+ lastOutput_ *= outputGain_;
// Do three-port junction scattering (under tonehole)
- pa += vent->lastOut();
- pb = delays[2]->lastOut();
- MY_FLOAT pth = tonehole->lastOut();
- temp = scatter * (pa + pb - 2 * pth);
+ pa += vent_.lastOut();
+ pb = delays_[2].lastOut();
+ StkFloat pth = tonehole_.lastOut();
+ temp = scatter_ * (pa + pb - 2 * pth);
- delays[2]->tick(filter->tick(pa + temp) * -0.95);
- delays[1]->tick(pb + temp);
- tonehole->tick(pa + pb - pth + temp);
+ delays_[2].tick( filter_.tick(pa + temp) * -0.95 );
+ delays_[1].tick( pb + temp );
+ tonehole_.tick( pa + pb - pth + temp );
- return lastOutput;
+ return lastOutput_;
}
-void BlowHole :: controlChange(int number, MY_FLOAT value)
+StkFloat *BlowHole :: tick(StkFloat *vector, unsigned int vectorSize)
{
- MY_FLOAT norm = value * ONE_OVER_128;
+ return Instrmnt::tick( vector, vectorSize );
+}
+
+StkFrames& BlowHole :: tick( StkFrames& frames, unsigned int channel )
+{
+ return Instrmnt::tick( frames, channel );
+}
+
+void BlowHole :: controlChange(int number, StkFloat value)
+{
+ StkFloat norm = value * ONE_OVER_128;
if ( norm < 0 ) {
norm = 0.0;
- std::cerr << "BlowHole: Control value less than zero!" << std::endl;
+ errorString_ << "BlowHole::controlChange: control value less than zero ... setting to zero!";
+ handleError( StkError::WARNING );
}
else if ( norm > 1.0 ) {
norm = 1.0;
- std::cerr << "BlowHole: Control value greater than 128.0!" << std::endl;
+ errorString_ << "BlowHole::controlChange: control value greater than 128.0 ... setting to 128.0!";
+ handleError( StkError::WARNING );
}
if (number == __SK_ReedStiffness_) // 2
- reedTable->setSlope( -0.44 + (0.26 * norm) );
+ reedTable_.setSlope( -0.44 + (0.26 * norm) );
else if (number == __SK_NoiseLevel_) // 4
- noiseGain = ( norm * 0.4);
+ noiseGain_ = ( norm * 0.4);
else if (number == __SK_ModFrequency_) // 11
this->setTonehole( norm );
else if (number == __SK_ModWheel_) // 1
this->setVent( norm );
else if (number == __SK_AfterTouch_Cont_) // 128
- envelope->setValue( norm );
- else
- std::cerr << "BlowHole: Undefined Control Number (" << number << ")!!" << std::endl;
+ envelope_.setValue( norm );
+ else {
+ errorString_ << "BlowHole::controlChange: undefined control number (" << number << ")!";
+ handleError( StkError::WARNING );
+ }
#if defined(_STK_DEBUG_)
- std::cerr << "BlowHole: controlChange number = " << number << ", value = " << value << std::endl;
+ errorString_ << "BlowHole::controlChange: number = " << number << ", value = " << value << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
diff --git a/src/BowTabl.cpp b/src/BowTabl.cpp
deleted file mode 100644
index 089e1ae..0000000
--- a/src/BowTabl.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-/***************************************************/
-/*! \class BowTabl
- \brief STK bowed string table class.
-
- This class implements a simple bowed string
- non-linear function, as described by Smith (1986).
-
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
-*/
-/***************************************************/
-
-#include "BowTabl.h"
-#include
-
-BowTabl :: BowTabl()
-{
- offSet = (MY_FLOAT) 0.0;
- slope = (MY_FLOAT) 0.1;
-}
-
-BowTabl :: ~BowTabl()
-{
-}
-
-void BowTabl :: setOffset(MY_FLOAT aValue)
-{
- offSet = aValue;
-}
-
-void BowTabl :: setSlope(MY_FLOAT aValue)
-{
- slope = aValue;
-}
-
-MY_FLOAT BowTabl :: lastOut() const
-{
- return lastOutput;
-}
-
-MY_FLOAT BowTabl :: tick(MY_FLOAT input)
-{
- // The input represents differential string vs. bow velocity.
- MY_FLOAT sample;
- sample = input + offSet; // add bias to input
- sample *= slope; // then scale it
- lastOutput = (MY_FLOAT) fabs((double) sample) + (MY_FLOAT) 0.75;
- lastOutput = (MY_FLOAT) pow( lastOutput,(MY_FLOAT) -4.0 );
-
- // Set minimum friction to 0.0
- //if (lastOutput < 0.0 ) lastOutput = 0.0;
- // Set maximum friction to 1.0.
- if (lastOutput > 1.0 ) lastOutput = (MY_FLOAT) 1.0;
-
- return lastOutput;
-}
-
-MY_FLOAT *BowTabl :: tick(MY_FLOAT *vector, unsigned int vectorSize)
-{
- for (unsigned int i=0; i
+
+BowTable :: BowTable()
+{
+ offset_ = (StkFloat) 0.0;
+ slope_ = (StkFloat) 0.1;
+}
+
+BowTable :: ~BowTable()
+{
+}
+
+void BowTable :: setOffset(StkFloat offset)
+{
+ offset_ = offset;
+}
+
+void BowTable :: setSlope(StkFloat slope)
+{
+ slope_ = slope;
+}
+
+StkFloat BowTable :: tick(StkFloat input)
+{
+ // The input represents differential string vs. bow velocity.
+ StkFloat sample;
+ sample = input + offset_; // add bias to input
+ sample *= slope_; // then scale it
+ lastOutput_ = (StkFloat) fabs( (double) sample ) + (StkFloat) 0.75;
+ lastOutput_ = (StkFloat) pow( lastOutput_, (StkFloat) -4.0 );
+
+ // Set minimum friction to 0.0
+ // if (lastOutput < 0.0 ) lastOutput = 0.0;
+ // Set maximum friction to 1.0.
+ if (lastOutput_ > 1.0 ) lastOutput_ = (StkFloat) 1.0;
+
+ return lastOutput_;
+}
+
+StkFloat *BowTable :: tick(StkFloat *vector, unsigned int vectorSize)
+{
+ return Function::tick( vector, vectorSize );
+}
+
+StkFrames& BowTable :: tick( StkFrames& frames, unsigned int channel )
+{
+ return Function::tick( frames, channel );
+}
diff --git a/src/Bowed.cpp b/src/Bowed.cpp
index 48208ef..ebd493a 100644
--- a/src/Bowed.cpp
+++ b/src/Bowed.cpp
@@ -17,173 +17,184 @@
- Vibrato Gain = 1
- Volume = 128
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
#include "Bowed.h"
#include "SKINI.msg"
-Bowed :: Bowed(MY_FLOAT lowestFrequency)
+Bowed :: Bowed(StkFloat lowestFrequency)
{
- long length;
- length = (long) (Stk::sampleRate() / lowestFrequency + 1);
- neckDelay = new DelayL(100.0, length);
- length >>= 1;
- bridgeDelay = new DelayL(29.0, length);
+ unsigned long length;
+ length = (long) ( Stk::sampleRate() / lowestFrequency + 1 );
+ neckDelay_.setMaximumDelay( length );
+ neckDelay_.setDelay( 100.0 );
- bowTable = new BowTabl;
- bowTable->setSlope((MY_FLOAT) 3.0);
+ length >>= 1;
+ bridgeDelay_.setMaximumDelay( length );
+ bridgeDelay_.setDelay( 29.0 );
+
+ bowTable_.setSlope(3.0 );
// Concatenate the STK rawwave path to the rawwave file
- vibrato = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), TRUE );
- vibrato->setFrequency((MY_FLOAT) 6.12723);
- vibratoGain = (MY_FLOAT) 0.0;
+ vibrato_ = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), true );
+ vibrato_->setFrequency( 6.12723 );
+ vibratoGain_ = 0.0;
- stringFilter = new OnePole;
- stringFilter->setPole((MY_FLOAT) (0.6 - (0.1 * 22050.0 / Stk::sampleRate() ) ) );
- stringFilter->setGain((MY_FLOAT) 0.95);
+ stringFilter_.setPole( 0.6 - (0.1 * 22050.0 / Stk::sampleRate()) );
+ stringFilter_.setGain( 0.95 );
- bodyFilter = new BiQuad;
- bodyFilter->setResonance( 500.0, 0.85, TRUE );
- bodyFilter->setGain((MY_FLOAT) 0.2);
+ bodyFilter_.setResonance( 500.0, 0.85, true );
+ bodyFilter_.setGain( 0.2 );
- adsr = new ADSR;
- adsr->setAllTimes((MY_FLOAT) 0.02,(MY_FLOAT) 0.005,(MY_FLOAT) 0.9,(MY_FLOAT) 0.01);
+ adsr_.setAllTimes( 0.02, 0.005, 0.9, 0.01 );
- betaRatio = (MY_FLOAT) 0.127236;
+ betaRatio_ = 0.127236;
// Necessary to initialize internal variables.
- setFrequency( 220.0 );
+ this->setFrequency( 220.0 );
}
Bowed :: ~Bowed()
{
- delete neckDelay;
- delete bridgeDelay;
- delete bowTable;
- delete stringFilter;
- delete bodyFilter;
- delete vibrato;
- delete adsr;
+ delete vibrato_;
}
void Bowed :: clear()
{
- neckDelay->clear();
- bridgeDelay->clear();
+ neckDelay_.clear();
+ bridgeDelay_.clear();
}
-void Bowed :: setFrequency(MY_FLOAT frequency)
+void Bowed :: setFrequency(StkFloat frequency)
{
- MY_FLOAT freakency = frequency;
+ StkFloat freakency = frequency;
if ( frequency <= 0.0 ) {
- std::cerr << "Bowed: setFrequency parameter is less than or equal to zero!" << std::endl;
+ errorString_ << "Bowed::setFrequency: parameter is less than or equal to zero!";
+ handleError( StkError::WARNING );
freakency = 220.0;
}
// Delay = length - approximate filter delay.
- baseDelay = Stk::sampleRate() / freakency - (MY_FLOAT) 4.0;
- if ( baseDelay <= 0.0 ) baseDelay = 0.3;
- bridgeDelay->setDelay(baseDelay * betaRatio); // bow to bridge length
- neckDelay->setDelay(baseDelay * ((MY_FLOAT) 1.0 - betaRatio)); // bow to nut (finger) length
+ baseDelay_ = Stk::sampleRate() / freakency - 4.0;
+ if ( baseDelay_ <= 0.0 ) baseDelay_ = 0.3;
+ bridgeDelay_.setDelay( baseDelay_ * betaRatio_ ); // bow to bridge length
+ neckDelay_.setDelay( baseDelay_ * (1.0 - betaRatio_) ); // bow to nut (finger) length
}
-void Bowed :: startBowing(MY_FLOAT amplitude, MY_FLOAT rate)
+void Bowed :: startBowing(StkFloat amplitude, StkFloat rate)
{
- adsr->setRate(rate);
- adsr->keyOn();
- maxVelocity = (MY_FLOAT) 0.03 + ((MY_FLOAT) 0.2 * amplitude);
+ adsr_.setRate( rate );
+ adsr_.keyOn();
+ maxVelocity_ = 0.03 + ( 0.2 * amplitude );
}
-void Bowed :: stopBowing(MY_FLOAT rate)
+void Bowed :: stopBowing(StkFloat rate)
{
- adsr->setRate(rate);
- adsr->keyOff();
+ adsr_.setRate( rate );
+ adsr_.keyOff();
}
-void Bowed :: noteOn(MY_FLOAT frequency, MY_FLOAT amplitude)
+void Bowed :: noteOn(StkFloat frequency, StkFloat amplitude)
{
- this->startBowing(amplitude, amplitude * 0.001);
- this->setFrequency(frequency);
+ this->startBowing( amplitude, amplitude * 0.001 );
+ this->setFrequency( frequency );
#if defined(_STK_DEBUG_)
- std::cerr << "Bowed: NoteOn frequency = " << frequency << ", amplitude = " << amplitude << std::endl;
+ errorString_ << "Bowed::NoteOn: frequency = " << frequency << ", amplitude = " << amplitude << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-void Bowed :: noteOff(MY_FLOAT amplitude)
+void Bowed :: noteOff(StkFloat amplitude)
{
- this->stopBowing(((MY_FLOAT) 1.0 - amplitude) * (MY_FLOAT) 0.005);
+ this->stopBowing( (1.0 - amplitude) * 0.005 );
#if defined(_STK_DEBUG_)
- std::cerr << "Bowed: NoteOff amplitude = " << amplitude << std::endl;
+ errorString_ << "Bowed::NoteOff: amplitude = " << amplitude << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-void Bowed :: setVibrato(MY_FLOAT gain)
+void Bowed :: setVibrato(StkFloat gain)
{
- vibratoGain = gain;
+ vibratoGain_ = gain;
}
-MY_FLOAT Bowed :: tick()
+StkFloat Bowed :: tick()
{
- MY_FLOAT bowVelocity;
- MY_FLOAT bridgeRefl;
- MY_FLOAT nutRefl;
- MY_FLOAT newVel;
- MY_FLOAT velDiff;
- MY_FLOAT stringVel;
+ StkFloat bowVelocity;
+ StkFloat bridgeRefl;
+ StkFloat nutRefl;
+ StkFloat newVel;
+ StkFloat velDiff;
+ StkFloat stringVel;
- bowVelocity = maxVelocity * adsr->tick();
+ bowVelocity = maxVelocity_ * adsr_.tick();
- bridgeRefl = -stringFilter->tick( bridgeDelay->lastOut() );
- nutRefl = -neckDelay->lastOut();
+ bridgeRefl = -stringFilter_.tick( bridgeDelay_.lastOut() );
+ nutRefl = -neckDelay_.lastOut();
stringVel = bridgeRefl + nutRefl; // Sum is String Velocity
velDiff = bowVelocity - stringVel; // Differential Velocity
- newVel = velDiff * bowTable->tick( velDiff ); // Non-Linear Bow Function
- neckDelay->tick(bridgeRefl + newVel); // Do string propagations
- bridgeDelay->tick(nutRefl + newVel);
+ newVel = velDiff * bowTable_.tick( velDiff ); // Non-Linear Bow Function
+ neckDelay_.tick(bridgeRefl + newVel); // Do string propagations
+ bridgeDelay_.tick(nutRefl + newVel);
- if (vibratoGain > 0.0) {
- neckDelay->setDelay((baseDelay * ((MY_FLOAT) 1.0 - betaRatio)) +
- (baseDelay * vibratoGain * vibrato->tick()));
+ if ( vibratoGain_ > 0.0 ) {
+ neckDelay_.setDelay( (baseDelay_ * (1.0 - betaRatio_) ) +
+ (baseDelay_ * vibratoGain_ * vibrato_->tick()) );
}
- lastOutput = bodyFilter->tick(bridgeDelay->lastOut());
+ lastOutput_ = bodyFilter_.tick( bridgeDelay_.lastOut() );
- return lastOutput;
+ return lastOutput_;
}
-void Bowed :: controlChange(int number, MY_FLOAT value)
+StkFloat *Bowed :: tick(StkFloat *vector, unsigned int vectorSize)
{
- MY_FLOAT norm = value * ONE_OVER_128;
+ return Instrmnt::tick( vector, vectorSize );
+}
+
+StkFrames& Bowed :: tick( StkFrames& frames, unsigned int channel )
+{
+ return Instrmnt::tick( frames, channel );
+}
+
+void Bowed :: controlChange(int number, StkFloat value)
+{
+ StkFloat norm = value * ONE_OVER_128;
if ( norm < 0 ) {
norm = 0.0;
- std::cerr << "Bowed: Control value less than zero!" << std::endl;
+ errorString_ << "Bowed::controlChange: control value less than zero ... setting to zero!";
+ handleError( StkError::WARNING );
}
else if ( norm > 1.0 ) {
norm = 1.0;
- std::cerr << "Bowed: Control value greater than 128.0!" << std::endl;
+ errorString_ << "Bowed::controlChange: control value greater than 128.0 ... setting to 128.0!";
+ handleError( StkError::WARNING );
}
if (number == __SK_BowPressure_) // 2
- bowTable->setSlope( 5.0 - (4.0 * norm) );
+ bowTable_.setSlope( 5.0 - (4.0 * norm) );
else if (number == __SK_BowPosition_) { // 4
- betaRatio = 0.027236 + (0.2 * norm);
- bridgeDelay->setDelay(baseDelay * betaRatio);
- neckDelay->setDelay(baseDelay * ((MY_FLOAT) 1.0 - betaRatio));
+ betaRatio_ = 0.027236 + (0.2 * norm);
+ bridgeDelay_.setDelay( baseDelay_ * betaRatio_ );
+ neckDelay_.setDelay( baseDelay_ * (1.0 - betaRatio_) );
}
else if (number == __SK_ModFrequency_) // 11
- vibrato->setFrequency( norm * 12.0 );
+ vibrato_->setFrequency( norm * 12.0 );
else if (number == __SK_ModWheel_) // 1
- vibratoGain = ( norm * 0.4 );
+ vibratoGain_ = ( norm * 0.4 );
else if (number == __SK_AfterTouch_Cont_) // 128
- adsr->setTarget(norm);
- else
- std::cerr << "Bowed: Undefined Control Number (" << number << ")!!" << std::endl;
+ adsr_.setTarget(norm);
+ else {
+ errorString_ << "Bowed::controlChange: undefined control number (" << number << ")!";
+ handleError( StkError::WARNING );
+ }
#if defined(_STK_DEBUG_)
- std::cerr << "Bowed: controlChange number = " << number << ", value = " << value << std::endl;
+ errorString_ << "Bowed::controlChange: number = " << number << ", value = " << value << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
diff --git a/src/Brass.cpp b/src/Brass.cpp
index a235c06..f5aee41 100644
--- a/src/Brass.cpp
+++ b/src/Brass.cpp
@@ -16,7 +16,7 @@
- Vibrato Gain = 1
- Volume = 128
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
@@ -24,153 +24,167 @@
#include "SKINI.msg"
#include
-Brass :: Brass(MY_FLOAT lowestFrequency)
+Brass :: Brass(StkFloat lowestFrequency)
{
- length = (long) (Stk::sampleRate() / lowestFrequency + 1);
- delayLine = new DelayA( 0.5 * length, length );
+ length_ = (unsigned long) (Stk::sampleRate() / lowestFrequency + 1);
+ delayLine_.setMaximumDelay( length_ );
+ delayLine_.setDelay( 0.5 * length_ );
- lipFilter = new BiQuad();
- lipFilter->setGain( 0.03 );
- dcBlock = new PoleZero();
- dcBlock->setBlockZero();
+ lipFilter_.setGain( 0.03 );
+ dcBlock_.setBlockZero();
- adsr = new ADSR;
- adsr->setAllTimes( 0.005, 0.001, 1.0, 0.010);
+ adsr_.setAllTimes( 0.005, 0.001, 1.0, 0.010);
// Concatenate the STK rawwave path to the rawwave file
- vibrato = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), TRUE );
- vibrato->setFrequency( 6.137 );
- vibratoGain = 0.0;
+ vibrato_ = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), true );
+ vibrato_->setFrequency( 6.137 );
+ vibratoGain_ = 0.0;
this->clear();
- maxPressure = (MY_FLOAT) 0.0;
- lipTarget = 0.0;
+ maxPressure_ = 0.0;
+ lipTarget_ = 0.0;
- // Necessary to initialize variables.
- setFrequency( 220.0 );
+ // This is necessary to initialize variables.
+ this->setFrequency( 220.0 );
}
Brass :: ~Brass()
{
- delete delayLine;
- delete lipFilter;
- delete dcBlock;
- delete adsr;
- delete vibrato;
+ delete vibrato_;
}
void Brass :: clear()
{
- delayLine->clear();
- lipFilter->clear();
- dcBlock->clear();
+ delayLine_.clear();
+ lipFilter_.clear();
+ dcBlock_.clear();
}
-void Brass :: setFrequency(MY_FLOAT frequency)
+void Brass :: setFrequency(StkFloat frequency)
{
- MY_FLOAT freakency = frequency;
+ StkFloat freakency = frequency;
if ( frequency <= 0.0 ) {
- std::cerr << "Brass: setFrequency parameter is less than or equal to zero!" << std::endl;
+ errorString_ << "Brass::setFrequency: parameter is less than or equal to zero!";
+ handleError( StkError::WARNING );
freakency = 220.0;
}
// Fudge correction for filter delays.
- slideTarget = (Stk::sampleRate() / freakency * 2.0) + 3.0;
- delayLine->setDelay(slideTarget); // play a harmonic
+ slideTarget_ = (Stk::sampleRate() / freakency * 2.0) + 3.0;
+ delayLine_.setDelay( slideTarget_ ); // play a harmonic
- lipTarget = freakency;
- lipFilter->setResonance( freakency, 0.997 );
+ lipTarget_ = freakency;
+ lipFilter_.setResonance( freakency, 0.997 );
}
-void Brass :: setLip(MY_FLOAT frequency)
+void Brass :: setLip(StkFloat frequency)
{
- MY_FLOAT freakency = frequency;
+ StkFloat freakency = frequency;
if ( frequency <= 0.0 ) {
- std::cerr << "Brass: setLip parameter is less than or equal to zero!" << std::endl;
+ errorString_ << "Brass::setLip: parameter is less than or equal to zero!";
+ handleError( StkError::WARNING );
freakency = 220.0;
}
- lipFilter->setResonance( freakency, 0.997 );
+ lipFilter_.setResonance( freakency, 0.997 );
}
-void Brass :: startBlowing(MY_FLOAT amplitude, MY_FLOAT rate)
+void Brass :: startBlowing(StkFloat amplitude, StkFloat rate)
{
- adsr->setAttackRate(rate);
- maxPressure = amplitude;
- adsr->keyOn();
+ adsr_.setAttackRate( rate );
+ maxPressure_ = amplitude;
+ adsr_.keyOn();
}
-void Brass :: stopBlowing(MY_FLOAT rate)
+void Brass :: stopBlowing(StkFloat rate)
{
- adsr->setReleaseRate(rate);
- adsr->keyOff();
+ adsr_.setReleaseRate( rate );
+ adsr_.keyOff();
}
-void Brass :: noteOn(MY_FLOAT frequency, MY_FLOAT amplitude)
+void Brass :: noteOn(StkFloat frequency, StkFloat amplitude)
{
- setFrequency(frequency);
- this->startBlowing(amplitude, amplitude * 0.001);
+ this->setFrequency( frequency );
+ this->startBlowing( amplitude, amplitude * 0.001 );
#if defined(_STK_DEBUG_)
- std::cerr << "Brass: NoteOn frequency = " << frequency << ", amplitude = " << amplitude << std::endl;
+ errorString_ << "Brass::NoteOn: frequency = " << frequency << ", amplitude = " << amplitude << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-void Brass :: noteOff(MY_FLOAT amplitude)
+void Brass :: noteOff(StkFloat amplitude)
{
- this->stopBlowing(amplitude * 0.005);
+ this->stopBlowing( amplitude * 0.005 );
#if defined(_STK_DEBUG_)
- std::cerr << "Brass: NoteOff amplitude = " << amplitude << std::endl;
+ errorString_ << "Brass::NoteOff: amplitude = " << amplitude << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-MY_FLOAT Brass :: tick()
+StkFloat Brass :: tick()
{
- MY_FLOAT breathPressure = maxPressure * adsr->tick();
- breathPressure += vibratoGain * vibrato->tick();
+ StkFloat breathPressure = maxPressure_ * adsr_.tick();
+ breathPressure += vibratoGain_ * vibrato_->tick();
- MY_FLOAT mouthPressure = 0.3 * breathPressure;
- MY_FLOAT borePressure = 0.85 * delayLine->lastOut();
- MY_FLOAT deltaPressure = mouthPressure - borePressure; // Differential pressure.
- deltaPressure = lipFilter->tick( deltaPressure ); // Force - > position.
+ StkFloat mouthPressure = 0.3 * breathPressure;
+ StkFloat borePressure = 0.85 * delayLine_.lastOut();
+ StkFloat deltaPressure = mouthPressure - borePressure; // Differential pressure.
+ deltaPressure = lipFilter_.tick( deltaPressure ); // Force - > position.
deltaPressure *= deltaPressure; // Basic position to area mapping.
- if ( deltaPressure > 1.0 ) deltaPressure = 1.0; // Non-linear saturation.
- // The following input scattering assumes the mouthPressure = area.
- lastOutput = deltaPressure * mouthPressure + ( 1.0 - deltaPressure) * borePressure;
- lastOutput = delayLine->tick( dcBlock->tick( lastOutput ) );
+ if ( deltaPressure > 1.0 ) deltaPressure = 1.0; // Non-linear saturation.
- return lastOutput;
+ // The following input scattering assumes the mouthPressure = area.
+ lastOutput_ = deltaPressure * mouthPressure + ( 1.0 - deltaPressure) * borePressure;
+ lastOutput_ = delayLine_.tick( dcBlock_.tick( lastOutput_ ) );
+
+ return lastOutput_;
}
-void Brass :: controlChange(int number, MY_FLOAT value)
+StkFloat *Brass :: tick(StkFloat *vector, unsigned int vectorSize)
{
- MY_FLOAT norm = value * ONE_OVER_128;
+ return Instrmnt::tick( vector, vectorSize );
+}
+
+StkFrames& Brass :: tick( StkFrames& frames, unsigned int channel )
+{
+ return Instrmnt::tick( frames, channel );
+}
+
+void Brass :: controlChange(int number, StkFloat value)
+{
+ StkFloat norm = value * ONE_OVER_128;
if ( norm < 0 ) {
norm = 0.0;
- std::cerr << "Brass: Control value less than zero!" << std::endl;
+ errorString_ << "Brass::controlChange: control value less than zero ... setting to zero!";
+ handleError( StkError::WARNING );
}
else if ( norm > 1.0 ) {
norm = 1.0;
- std::cerr << "Brass: Control value greater than 128.0!" << std::endl;
+ errorString_ << "Brass::controlChange: control value greater than 128.0 ... setting to 128.0!";
+ handleError( StkError::WARNING );
}
if (number == __SK_LipTension_) { // 2
- MY_FLOAT temp = lipTarget * pow( 4.0, (2.0 * norm) - 1.0 );
+ StkFloat temp = lipTarget_ * pow( 4.0, (2.0 * norm) - 1.0 );
this->setLip(temp);
}
else if (number == __SK_SlideLength_) // 4
- delayLine->setDelay( slideTarget * (0.5 + norm) );
+ delayLine_.setDelay( slideTarget_ * (0.5 + norm) );
else if (number == __SK_ModFrequency_) // 11
- vibrato->setFrequency( norm * 12.0 );
+ vibrato_->setFrequency( norm * 12.0 );
else if (number == __SK_ModWheel_ ) // 1
- vibratoGain = norm * 0.4;
+ vibratoGain_ = norm * 0.4;
else if (number == __SK_AfterTouch_Cont_) // 128
- adsr->setTarget( norm );
- else
- std::cerr << "Brass: Undefined Control Number (" << number << ")!!" << std::endl;
+ adsr_.setTarget( norm );
+ else {
+ errorString_ << "Brass::controlChange: undefined control number (" << number << ")!";
+ handleError( StkError::WARNING );
+ }
#if defined(_STK_DEBUG_)
- std::cerr << "Brass: controlChange number = " << number << ", value = " << value << std::endl;
+ errorString_ << "Brass::controlChange: number = " << number << ", value = " << value << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
diff --git a/src/Chorus.cpp b/src/Chorus.cpp
index e0a3bbf..b779024 100644
--- a/src/Chorus.cpp
+++ b/src/Chorus.cpp
@@ -4,99 +4,73 @@
This class implements a chorus effect.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
#include "Chorus.h"
#include
-Chorus :: Chorus(MY_FLOAT baseDelay)
+Chorus :: Chorus(StkFloat baseDelay)
{
- delayLine[0] = new DelayL((long) baseDelay, (long) (baseDelay * 1.414) + 2);
- delayLine[1] = new DelayL((long) (baseDelay), (long) baseDelay + 2);
- baseLength = baseDelay;
+ delayLine_[0].setMaximumDelay( (unsigned long) (baseDelay * 1.414) + 2);
+ delayLine_[0].setDelay( baseDelay );
+ delayLine_[1].setMaximumDelay( (unsigned long) (baseDelay * 1.414) + 2);
+ delayLine_[1].setDelay( baseDelay );
+ baseLength_ = baseDelay;
// Concatenate the STK rawwave path to the rawwave file
- mods[0] = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), TRUE );
- mods[1] = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), TRUE );
- mods[0]->setFrequency(0.2);
- mods[1]->setFrequency(0.222222);
- modDepth = 0.05;
- effectMix = 0.5;
+ mods_[0] = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), true );
+ mods_[1] = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), true );
+ mods_[0]->setFrequency(0.2);
+ mods_[1]->setFrequency(0.222222);
+ modDepth_ = 0.05;
+ effectMix_ = 0.5;
this->clear();
}
Chorus :: ~Chorus()
{
- delete delayLine[0];
- delete delayLine[1];
- delete mods[0];
- delete mods[1];
+ delete mods_[0];
+ delete mods_[1];
}
void Chorus :: clear()
{
- delayLine[0]->clear();
- delayLine[1]->clear();
- lastOutput[0] = 0.0;
- lastOutput[1] = 0.0;
+ delayLine_[0].clear();
+ delayLine_[1].clear();
+ lastOutput_[0] = 0.0;
+ lastOutput_[1] = 0.0;
}
-void Chorus :: setEffectMix(MY_FLOAT mix)
+void Chorus :: setModDepth(StkFloat depth)
{
- effectMix = mix;
- if ( mix < 0.0 ) {
- std::cerr << "Chorus: setEffectMix parameter is less than zero!" << std::endl;
- effectMix = 0.0;
- }
- else if ( mix > 1.0 ) {
- std::cerr << "Chorus: setEffectMix parameter is greater than 1.0!" << std::endl;
- effectMix = 1.0;
- }
+ modDepth_ = depth;
}
-void Chorus :: setModDepth(MY_FLOAT depth)
+void Chorus :: setModFrequency(StkFloat frequency)
{
- modDepth = depth;
+ mods_[0]->setFrequency(frequency);
+ mods_[1]->setFrequency(frequency * 1.1111);
}
-void Chorus :: setModFrequency(MY_FLOAT frequency)
+StkFloat Chorus :: tick(StkFloat input)
{
- mods[0]->setFrequency(frequency);
- mods[1]->setFrequency(frequency * 1.1111);
+ delayLine_[0].setDelay( baseLength_ * 0.707 * (1.0 + mods_[0]->tick()) );
+ delayLine_[1].setDelay( baseLength_ * 0.5 * (1.0 - mods_[1]->tick()) );
+ lastOutput_[0] = input * (1.0 - effectMix_);
+ lastOutput_[0] += effectMix_ * delayLine_[0].tick(input);
+ lastOutput_[1] = input * (1.0 - effectMix_);
+ lastOutput_[1] += effectMix_ * delayLine_[1].tick(input);
+ return Effect::lastOut();
}
-MY_FLOAT Chorus :: lastOut() const
+StkFloat *Chorus :: tick(StkFloat *vector, unsigned int vectorSize)
{
- return (lastOutput[0] + lastOutput[1]) * (MY_FLOAT) 0.5;
+ return Effect::tick( vector, vectorSize );
}
-MY_FLOAT Chorus :: lastOutLeft() const
+StkFrames& Chorus :: tick( StkFrames& frames, unsigned int channel )
{
- return lastOutput[0];
-}
-
-MY_FLOAT Chorus :: lastOutRight() const
-{
- return lastOutput[1];
-}
-
-MY_FLOAT Chorus :: tick(MY_FLOAT input)
-{
- delayLine[0]->setDelay(baseLength * 0.707 * (1.0 + mods[0]->tick()));
- delayLine[1]->setDelay(baseLength * 0.5 * (1.0 - mods[1]->tick()));
- lastOutput[0] = input * (1.0 - effectMix);
- lastOutput[0] += effectMix * delayLine[0]->tick(input);
- lastOutput[1] = input * (1.0 - effectMix);
- lastOutput[1] += effectMix * delayLine[1]->tick(input);
- return (lastOutput[0] + lastOutput[1]) * (MY_FLOAT) 0.5;
-}
-
-MY_FLOAT *Chorus :: tick(MY_FLOAT *vector, unsigned int vectorSize)
-{
- for (unsigned int i=0; isetOffset((MY_FLOAT) 0.7);
- reedTable->setSlope((MY_FLOAT) -0.3);
- filter = new OneZero;
- envelope = new Envelope;
- noise = new Noise;
+ length_ = (long) (Stk::sampleRate() / lowestFrequency + 1);
+ delayLine_.setMaximumDelay( length_ );
+ delayLine_.setDelay( length_ / 2.0 );
+ reedTable_.setOffset((StkFloat) 0.7);
+ reedTable_.setSlope((StkFloat) -0.3);
// Concatenate the STK rawwave path to the rawwave file
- vibrato = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), TRUE );
- vibrato->setFrequency((MY_FLOAT) 5.735);
- outputGain = (MY_FLOAT) 1.0;
- noiseGain = (MY_FLOAT) 0.2;
- vibratoGain = (MY_FLOAT) 0.1;
+ vibrato_ = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), true );
+ vibrato_->setFrequency((StkFloat) 5.735);
+ outputGain_ = (StkFloat) 1.0;
+ noiseGain_ = (StkFloat) 0.2;
+ vibratoGain_ = (StkFloat) 0.1;
}
Clarinet :: ~Clarinet()
{
- delete delayLine;
- delete reedTable;
- delete filter;
- delete envelope;
- delete noise;
- delete vibrato;
+ delete vibrato_;
}
void Clarinet :: clear()
{
- delayLine->clear();
- filter->tick((MY_FLOAT) 0.0);
+ delayLine_.clear();
+ filter_.tick((StkFloat) 0.0);
}
-void Clarinet :: setFrequency(MY_FLOAT frequency)
+void Clarinet :: setFrequency(StkFloat frequency)
{
- MY_FLOAT freakency = frequency;
+ StkFloat freakency = frequency;
if ( frequency <= 0.0 ) {
- std::cerr << "Clarinet: setFrequency parameter is less than or equal to zero!" << std::endl;
+ errorString_ << "Clarinet::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) * 0.5 - 1.5;
+ StkFloat delay = (Stk::sampleRate() / freakency) * 0.5 - 1.5;
if (delay <= 0.0) delay = 0.3;
- else if (delay > length) delay = length;
- delayLine->setDelay(delay);
+ else if (delay > length_) delay = length_;
+ delayLine_.setDelay(delay);
}
-void Clarinet :: startBlowing(MY_FLOAT amplitude, MY_FLOAT rate)
+void Clarinet :: startBlowing(StkFloat amplitude, StkFloat rate)
{
- envelope->setRate(rate);
- envelope->setTarget(amplitude);
+ envelope_.setRate(rate);
+ envelope_.setTarget(amplitude);
}
-void Clarinet :: stopBlowing(MY_FLOAT rate)
+void Clarinet :: stopBlowing(StkFloat rate)
{
- envelope->setRate(rate);
- envelope->setTarget((MY_FLOAT) 0.0);
+ envelope_.setRate(rate);
+ envelope_.setTarget((StkFloat) 0.0);
}
-void Clarinet :: noteOn(MY_FLOAT frequency, MY_FLOAT amplitude)
+void Clarinet :: noteOn(StkFloat frequency, StkFloat amplitude)
{
this->setFrequency(frequency);
- this->startBlowing((MY_FLOAT) 0.55 + (amplitude * (MY_FLOAT) 0.30), amplitude * (MY_FLOAT) 0.005);
- outputGain = amplitude + (MY_FLOAT) 0.001;
+ this->startBlowing((StkFloat) 0.55 + (amplitude * (StkFloat) 0.30), amplitude * (StkFloat) 0.005);
+ outputGain_ = amplitude + (StkFloat) 0.001;
#if defined(_STK_DEBUG_)
- std::cerr << "Clarinet: NoteOn frequency = " << frequency << ", amplitude = " << amplitude << std::endl;
+ errorString_ << "Clarinet::NoteOn: frequency = " << frequency << ", amplitude = " << amplitude << '.';
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-void Clarinet :: noteOff(MY_FLOAT amplitude)
+void Clarinet :: noteOff(StkFloat amplitude)
{
- this->stopBlowing(amplitude * (MY_FLOAT) 0.01);
+ this->stopBlowing( amplitude * 0.01 );
#if defined(_STK_DEBUG_)
- std::cerr << "Clarinet: NoteOff amplitude = " << amplitude << std::endl;
+ errorString_ << "Clarinet::NoteOff: amplitude = " << amplitude << '.';
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-MY_FLOAT Clarinet :: tick()
+StkFloat Clarinet :: tick()
{
- MY_FLOAT pressureDiff;
- MY_FLOAT breathPressure;
+ StkFloat pressureDiff;
+ StkFloat breathPressure;
// Calculate the breath pressure (envelope + noise + vibrato)
- breathPressure = envelope->tick();
- breathPressure += breathPressure * noiseGain * noise->tick();
- breathPressure += breathPressure * vibratoGain * vibrato->tick();
+ breathPressure = envelope_.tick();
+ breathPressure += breathPressure * noiseGain_ * noise_.tick();
+ breathPressure += breathPressure * vibratoGain_ * vibrato_->tick();
// Perform commuted loss filtering.
- pressureDiff = -0.95 * filter->tick(delayLine->lastOut());
+ pressureDiff = -0.95 * filter_.tick(delayLine_.lastOut());
// Calculate pressure difference of reflected and mouthpiece pressures.
pressureDiff = pressureDiff - breathPressure;
// Perform non-linear scattering using pressure difference in reed function.
- lastOutput = delayLine->tick(breathPressure + pressureDiff * reedTable->tick(pressureDiff));
+ lastOutput_ = delayLine_.tick(breathPressure + pressureDiff * reedTable_.tick(pressureDiff));
// Apply output gain.
- lastOutput *= outputGain;
+ lastOutput_ *= outputGain_;
- return lastOutput;
+ return lastOutput_;
}
-void Clarinet :: controlChange(int number, MY_FLOAT value)
+StkFloat *Clarinet :: tick(StkFloat *vector, unsigned int vectorSize)
{
- MY_FLOAT norm = value * ONE_OVER_128;
+ return Instrmnt::tick( vector, vectorSize );
+}
+
+StkFrames& Clarinet :: tick( StkFrames& frames, unsigned int channel )
+{
+ return Instrmnt::tick( frames, channel );
+}
+
+void Clarinet :: controlChange(int number, StkFloat value)
+{
+ StkFloat norm = value * ONE_OVER_128;
if ( norm < 0 ) {
norm = 0.0;
- std::cerr << "Clarinet: Control value less than zero!" << std::endl;
+ errorString_ << "Clarinet::controlChange: control value less than zero ... setting to zero!";
+ handleError( StkError::WARNING );
}
else if ( norm > 1.0 ) {
norm = 1.0;
- std::cerr << "Clarinet: Control value greater than 128.0!" << std::endl;
+ errorString_ << "Clarinet::controlChange: control value greater than 128.0 ... setting to 128.0!";
+ handleError( StkError::WARNING );
}
if (number == __SK_ReedStiffness_) // 2
- reedTable->setSlope((MY_FLOAT) -0.44 + ( (MY_FLOAT) 0.26 * norm ));
+ reedTable_.setSlope((StkFloat) -0.44 + ( (StkFloat) 0.26 * norm ));
else if (number == __SK_NoiseLevel_) // 4
- noiseGain = (norm * (MY_FLOAT) 0.4);
+ noiseGain_ = (norm * (StkFloat) 0.4);
else if (number == __SK_ModFrequency_) // 11
- vibrato->setFrequency((norm * (MY_FLOAT) 12.0));
+ vibrato_->setFrequency((norm * (StkFloat) 12.0));
else if (number == __SK_ModWheel_) // 1
- vibratoGain = (norm * (MY_FLOAT) 0.5);
+ vibratoGain_ = (norm * (StkFloat) 0.5);
else if (number == __SK_AfterTouch_Cont_) // 128
- envelope->setValue(norm);
- else
- std::cerr << "Clarinet: Undefined Control Number (" << number << ")!!" << std::endl;
+ envelope_.setValue(norm);
+ else {
+ errorString_ << "Clarinet::controlChange: undefined control number (" << number << ")!";
+ handleError( StkError::WARNING );
+ }
#if defined(_STK_DEBUG_)
- std::cerr << "Clarinet: controlChange number = " << number << ", value = " << value << std::endl;
+ errorString_ << "Clarinet::controlChange: number = " << number << ", value = " << value << '.';
+ handleError( StkError::DEBUG_WARNING );
#endif
}
diff --git a/src/Delay.cpp b/src/Delay.cpp
index c6b2b1d..0bd2b63 100644
--- a/src/Delay.cpp
+++ b/src/Delay.cpp
@@ -14,40 +14,45 @@
used in fixed delay-length applications, such
as for reverberation.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
#include "Delay.h"
-#include
-Delay :: Delay()
+Delay :: Delay() : Filter()
{
- // Default max delay length set to 4095.
- length = 4096;
- delete [] inputs;
- inputs = new MY_FLOAT[length];
+ // Default maximum delay length set to 4095.
+ inputs_.resize( 4096 );
this->clear();
- inPoint = 0;
- outPoint = 0;
- delay = 0;
+ inPoint_ = 0;
+ outPoint_ = 0;
+ delay_ = 0;
}
-Delay :: Delay(long theDelay, long maxDelay)
+Delay :: Delay(unsigned long delay, unsigned long maxDelay)
{
// Writing before reading allows delays from 0 to length-1.
// If we want to allow a delay of maxDelay, we need a
// delay-line of length = maxDelay+1.
- length = maxDelay+1;
+ if ( maxDelay < 1 ) {
+ errorString_ << "Delay::Delay: maxDelay must be > 0!\n";
+ handleError( StkError::FUNCTION_ARGUMENT );
+ }
- // We need to delete the previously allocated inputs.
- delete [] inputs;
- inputs = new MY_FLOAT[length];
- this->clear();
+ if ( delay > maxDelay ) {
+ errorString_ << "Delay::Delay: maxDelay must be > than delay argument!\n";
+ handleError( StkError::FUNCTION_ARGUMENT );
+ }
- inPoint = 0;
- this->setDelay(theDelay);
+ if ( maxDelay > inputs_.size()-1 ) {
+ inputs_.resize( maxDelay+1 );
+ this->clear();
+ }
+
+ inPoint_ = 0;
+ this->setDelay( delay );
}
Delay :: ~Delay()
@@ -56,109 +61,135 @@ Delay :: ~Delay()
void Delay :: clear(void)
{
- long i;
- for (i=0;i length-1) { // The value is too big.
- std::cerr << "Delay: setDelay(" << theDelay << ") too big!" << std::endl;
- // Force delay to maxLength.
- outPoint = inPoint + 1;
- delay = length - 1;
+ if ( delay < inputs_.size() ) return;
+
+ if ( delay < 0 ) {
+ errorString_ << "Delay::setMaximumDelay: argument (" << delay << ") less than zero!\n";
+ handleError( StkError::WARNING );
+ return;
}
- else if (theDelay < 0 ) {
- std::cerr << "Delay: setDelay(" << theDelay << ") less than zero!" << std::endl;
- outPoint = inPoint;
- delay = 0;
- }
- else {
- outPoint = inPoint - (long) theDelay; // read chases write
- delay = theDelay;
+ else if (delay < delay_ ) {
+ errorString_ << "Delay::setMaximumDelay: argument (" << delay << ") less than current delay setting (" << delay_ << ")!\n";
+ handleError( StkError::WARNING );
+ return;
}
- while (outPoint < 0) outPoint += length; // modulo maximum length
+ inputs_.resize( delay + 1 );
}
-long Delay :: getDelay(void) const
+void Delay :: setDelay(unsigned long delay)
{
- return (long)delay;
+ if ( delay > inputs_.size() - 1 ) { // The value is too big.
+ errorString_ << "Delay::setDelay: argument (" << delay << ") too big ... setting to maximum!\n";
+ handleError( StkError::WARNING );
+
+ // Force delay to maximum length.
+ outPoint_ = inPoint_ + 1;
+ if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
+ delay_ = inputs_.size() - 1;
+ }
+ else if ( delay < 0 ) {
+ errorString_ << "Delay::setDelay: argument (" << delay << ") less than zero ... setting to zero!\n";
+ handleError( StkError::WARNING );
+
+ outPoint_ = inPoint_;
+ delay_ = 0;
+ }
+ else { // read chases write
+ if ( inPoint_ >= delay ) outPoint_ = inPoint_ - delay;
+ else outPoint_ = inputs_.size() + inPoint_ - delay;
+ delay_ = delay;
+ }
}
-MY_FLOAT Delay :: energy(void) const
+unsigned long Delay :: getDelay(void) const
{
- int i;
- register MY_FLOAT e = 0;
- if (inPoint >= outPoint) {
- for (i=outPoint; i= outPoint_) {
+ for (i=outPoint_; i delay) {
- std::cerr << "Delay: contentsAt(" << tapDelay << ") too big!" << std::endl;
- i = (long) delay;
+ else if (i > delay_) {
+ errorString_ << "Delay::contentsAt: argument (" << tapDelay << ") too big!";
+ handleError( StkError::WARNING );
+ return 0.0;
}
- long tap = inPoint - i;
+ long tap = inPoint_ - i;
if (tap < 0) // Check for wraparound.
- tap += length;
+ tap += inputs_.size();
- return inputs[tap];
+ return inputs_[tap];
}
-MY_FLOAT Delay :: lastOut(void) const
+StkFloat Delay :: lastOut(void) const
{
return Filter::lastOut();
}
-MY_FLOAT Delay :: nextOut(void) const
+StkFloat Delay :: nextOut(void)
{
- return inputs[outPoint];
+ return inputs_[outPoint_];
}
-MY_FLOAT Delay :: tick(MY_FLOAT sample)
+StkFloat Delay :: tick(StkFloat sample)
{
- inputs[inPoint++] = sample;
+ inputs_[inPoint_++] = sample;
// Check for end condition
- if (inPoint == length)
- inPoint -= length;
+ if (inPoint_ == inputs_.size())
+ inPoint_ = 0;
// Read out next value
- outputs[0] = inputs[outPoint++];
+ outputs_[0] = inputs_[outPoint_++];
- if (outPoint>=length)
- outPoint -= length;
+ if (outPoint_ == inputs_.size())
+ outPoint_ = 0;
- return outputs[0];
+ return outputs_[0];
}
-MY_FLOAT *Delay :: tick(MY_FLOAT *vector, unsigned int vectorSize)
+StkFloat *Delay :: tick(StkFloat *vector, unsigned int vectorSize)
{
- for (unsigned int i=0; i
-DelayA :: DelayA()
+DelayA :: DelayA() : Delay()
{
this->setDelay( 0.5 );
- apInput = 0.0;
- doNextOut = true;
+ apInput_ = 0.0;
+ doNextOut_ = true;
}
-DelayA :: DelayA(MY_FLOAT theDelay, long maxDelay)
+DelayA :: DelayA(StkFloat delay, unsigned long maxDelay)
{
- // Writing before reading allows delays from 0 to length-1.
- length = maxDelay+1;
+ if ( delay < 0.0 || maxDelay < 1 ) {
+ errorString_ << "DelayA::DelayA: delay must be >= 0.0, maxDelay must be > 0!";
+ handleError( StkError::FUNCTION_ARGUMENT );
+ }
- if ( length > 4096 ) {
- // We need to delete the previously allocated inputs.
- delete [] inputs;
- inputs = new MY_FLOAT[length];
+ if ( delay > (StkFloat) maxDelay ) {
+ errorString_ << "DelayA::DelayA: maxDelay must be > than delay argument!";
+ handleError( StkError::FUNCTION_ARGUMENT );
+ }
+
+ // Writing before reading allows delays from 0 to length-1.
+ if ( maxDelay > inputs_.size()-1 ) {
+ inputs_.resize( maxDelay+1 );
this->clear();
}
- inPoint = 0;
- this->setDelay(theDelay);
- apInput = 0.0;
- doNextOut = true;
+ inPoint_ = 0;
+ this->setDelay(delay);
+ apInput_ = 0.0;
+ doNextOut_ = true;
}
DelayA :: ~DelayA()
@@ -57,74 +62,90 @@ DelayA :: ~DelayA()
void DelayA :: clear()
{
Delay::clear();
- apInput = 0.0;
+ apInput_ = 0.0;
}
-void DelayA :: setDelay(MY_FLOAT theDelay)
+void DelayA :: setDelay(StkFloat delay)
{
- MY_FLOAT outPointer;
+ StkFloat outPointer;
+ unsigned long length = inputs_.size();
+
+ if ( delay > inputs_.size() - 1 ) { // The value is too big.
+ errorString_ << "DelayA::setDelay: argument (" << delay << ") too big ... setting to maximum!";
+ handleError( StkError::WARNING );
- if (theDelay > length-1) {
- std::cerr << "DelayA: setDelay(" << theDelay << ") too big!" << std::endl;
// Force delay to maxLength
- outPointer = inPoint + 1.0;
- delay = length - 1;
+ outPointer = inPoint_ + 1.0;
+ delay_ = length - 1;
}
- else if (theDelay < 0.5) {
- std::cerr << "DelayA: setDelay(" << theDelay << ") less than 0.5 not possible!" << std::endl;
- outPointer = inPoint + 0.4999999999;
- delay = 0.5;
+ else if (delay < 0.5) {
+ errorString_ << "DelayA::setDelay: argument (" << delay << ") less than 0.5 not possible!";
+ handleError( StkError::WARNING );
+
+ outPointer = inPoint_ + 0.4999999999;
+ delay_ = 0.5;
}
else {
- outPointer = inPoint - theDelay + 1.0; // outPoint chases inpoint
- delay = theDelay;
+ outPointer = inPoint_ - delay + 1.0; // outPoint chases inpoint
+ delay_ = delay;
}
if (outPointer < 0)
outPointer += length; // modulo maximum length
- outPoint = (long) outPointer; // integer part
- alpha = 1.0 + outPoint - outPointer; // fractional part
+ outPoint_ = (long) outPointer; // integer part
+ if ( outPoint_ == length ) outPoint_ = 0;
+ alpha_ = 1.0 + outPoint_ - outPointer; // fractional part
- if (alpha < 0.5) {
+ if (alpha_ < 0.5) {
// The optimal range for alpha is about 0.5 - 1.5 in order to
// achieve the flattest phase delay response.
- outPoint += 1;
- if (outPoint >= length) outPoint -= length;
- alpha += (MY_FLOAT) 1.0;
+ outPoint_ += 1;
+ if (outPoint_ >= length) outPoint_ -= length;
+ alpha_ += (StkFloat) 1.0;
}
- coeff = ((MY_FLOAT) 1.0 - alpha) /
- ((MY_FLOAT) 1.0 + alpha); // coefficient for all pass
+ coeff_ = ((StkFloat) 1.0 - alpha_) /
+ ((StkFloat) 1.0 + alpha_); // coefficient for all pass
}
-MY_FLOAT DelayA :: nextOut(void)
+StkFloat DelayA :: nextOut(void)
{
- if ( doNextOut ) {
+ if ( doNextOut_ ) {
// Do allpass interpolation delay.
- nextOutput = -coeff * outputs[0];
- nextOutput += apInput + (coeff * inputs[outPoint]);
- doNextOut = false;
+ nextOutput_ = -coeff_ * outputs_[0];
+ nextOutput_ += apInput_ + (coeff_ * inputs_[outPoint_]);
+ doNextOut_ = false;
}
- return nextOutput;
+ return nextOutput_;
}
-MY_FLOAT DelayA :: tick(MY_FLOAT sample)
+StkFloat DelayA :: tick(StkFloat sample)
{
- inputs[inPoint++] = sample;
+ inputs_[inPoint_++] = sample;
// Increment input pointer modulo length.
- if (inPoint == length)
- inPoint -= length;
+ if (inPoint_ == inputs_.size())
+ inPoint_ = 0;
- outputs[0] = nextOut();
- doNextOut = true;
+ outputs_[0] = nextOut();
+ doNextOut_ = true;
// Save the allpass input and increment modulo length.
- apInput = inputs[outPoint++];
- if (outPoint == length)
- outPoint -= length;
+ apInput_ = inputs_[outPoint_++];
+ if (outPoint_ == inputs_.size())
+ outPoint_ = 0;
- return outputs[0];
+ return outputs_[0];
+}
+
+StkFloat *DelayA :: tick(StkFloat *vector, unsigned int vectorSize)
+{
+ return Filter::tick( vector, vectorSize );
+}
+
+StkFrames& DelayA :: tick( StkFrames& frames, unsigned int channel )
+{
+ return Filter::tick( frames, channel );
}
diff --git a/src/DelayL.cpp b/src/DelayL.cpp
index cbe6139..0313271 100644
--- a/src/DelayL.cpp
+++ b/src/DelayL.cpp
@@ -18,102 +18,122 @@
order Lagrange interpolators can typically
improve (minimize) this attenuation characteristic.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
#include "DelayL.h"
-#include
-DelayL :: DelayL()
+DelayL :: DelayL() : Delay()
{
- doNextOut = true;
+ doNextOut_ = true;
}
-DelayL :: DelayL(MY_FLOAT theDelay, long maxDelay)
+DelayL :: DelayL(StkFloat delay, unsigned long maxDelay)
{
- // Writing before reading allows delays from 0 to length-1.
- length = maxDelay+1;
+ if ( delay < 0.0 || maxDelay < 1 ) {
+ errorString_ << "DelayL::DelayL: delay must be >= 0.0, maxDelay must be > 0!";
+ handleError( StkError::FUNCTION_ARGUMENT );
+ }
- if ( length > 4096 ) {
- // We need to delete the previously allocated inputs.
- delete [] inputs;
- inputs = new MY_FLOAT[length];
+ if ( delay > (StkFloat) maxDelay ) {
+ errorString_ << "DelayL::DelayL: maxDelay must be > than delay argument!";
+ handleError( StkError::FUNCTION_ARGUMENT );
+ }
+
+ // Writing before reading allows delays from 0 to length-1.
+ if ( maxDelay > inputs_.size()-1 ) {
+ inputs_.resize( maxDelay+1 );
this->clear();
}
- inPoint = 0;
- this->setDelay(theDelay);
- doNextOut = true;
+ inPoint_ = 0;
+ this->setDelay(delay);
+ doNextOut_ = true;
}
DelayL :: ~DelayL()
{
}
-void DelayL :: setDelay(MY_FLOAT theDelay)
+void DelayL :: setDelay(StkFloat delay)
{
- MY_FLOAT outPointer;
+ StkFloat outPointer;
+
+ if ( delay > inputs_.size() - 1 ) { // The value is too big.
+ errorString_ << "DelayL::setDelay: argument (" << delay << ") too big ... setting to maximum!";
+ handleError( StkError::WARNING );
- if (theDelay > length-1) {
- std::cerr << "DelayL: setDelay(" << theDelay << ") too big!" << std::endl;
// Force delay to maxLength
- outPointer = inPoint + 1.0;
- delay = length - 1;
+ outPointer = inPoint_ + 1.0;
+ delay_ = inputs_.size() - 1;
}
- else if (theDelay < 0 ) {
- std::cerr << "DelayL: setDelay(" << theDelay << ") less than zero!" << std::endl;
- outPointer = inPoint;
- delay = 0;
+ else if (delay < 0 ) {
+ errorString_ << "DelayL::setDelay: argument (" << delay << ") less than zero ... setting to zero!";
+ handleError( StkError::WARNING );
+
+ outPointer = inPoint_;
+ delay_ = 0;
}
else {
- outPointer = inPoint - theDelay; // read chases write
- delay = theDelay;
+ outPointer = inPoint_ - delay; // read chases write
+ delay_ = delay;
}
while (outPointer < 0)
- outPointer += length; // modulo maximum length
+ outPointer += inputs_.size(); // modulo maximum length
- outPoint = (long) outPointer; // integer part
- alpha = outPointer - outPoint; // fractional part
- omAlpha = (MY_FLOAT) 1.0 - alpha;
+ outPoint_ = (long) outPointer; // integer part
+ if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
+ alpha_ = outPointer - outPoint_; // fractional part
+ omAlpha_ = (StkFloat) 1.0 - alpha_;
}
-MY_FLOAT DelayL :: getDelay(void) const
+StkFloat DelayL :: getDelay(void) const
{
- return delay;
+ return delay_;
}
-MY_FLOAT DelayL :: nextOut(void)
+StkFloat DelayL :: nextOut(void)
{
- if ( doNextOut ) {
+ if ( doNextOut_ ) {
// First 1/2 of interpolation
- nextOutput = inputs[outPoint] * omAlpha;
+ nextOutput_ = inputs_[outPoint_] * omAlpha_;
// Second 1/2 of interpolation
- if (outPoint+1 < length)
- nextOutput += inputs[outPoint+1] * alpha;
+ if (outPoint_+1 < inputs_.size())
+ nextOutput_ += inputs_[outPoint_+1] * alpha_;
else
- nextOutput += inputs[0] * alpha;
- doNextOut = false;
+ nextOutput_ += inputs_[0] * alpha_;
+ doNextOut_ = false;
}
- return nextOutput;
+ return nextOutput_;
}
-MY_FLOAT DelayL :: tick(MY_FLOAT sample)
+StkFloat DelayL :: tick(StkFloat sample)
{
- inputs[inPoint++] = sample;
+ inputs_[inPoint_++] = sample;
// Increment input pointer modulo length.
- if (inPoint == length)
- inPoint -= length;
+ if (inPoint_ == inputs_.size())
+ inPoint_ = 0;
- outputs[0] = nextOut();
- doNextOut = true;
+ outputs_[0] = nextOut();
+ doNextOut_ = true;
// Increment output pointer modulo length.
- if (++outPoint >= length)
- outPoint -= length;
+ if (++outPoint_ == inputs_.size())
+ outPoint_ = 0;
- return outputs[0];
+ return outputs_[0];
+}
+
+StkFloat *DelayL :: tick(StkFloat *vector, unsigned int vectorSize)
+{
+ return Filter::tick( vector, vectorSize );
+}
+
+StkFrames& DelayL :: tick( StkFrames& frames, unsigned int channel )
+{
+ return Filter::tick( frames, channel );
}
diff --git a/src/Drummer.cpp b/src/Drummer.cpp
index 251dc4c..444c9ba 100644
--- a/src/Drummer.cpp
+++ b/src/Drummer.cpp
@@ -11,14 +11,14 @@
of simultaneous voices) via a #define in the
Drummer.h.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
#include "Drummer.h"
#include
-// Not really General MIDI yet. Coming soon.
+// Not really General MIDI yet.
unsigned char genMIDIMap[128] =
{ 0,0,0,0,0,0,0,0, // 0-7
0,0,0,0,0,0,0,0, // 8-15
@@ -55,122 +55,133 @@ char waveNames[DRUM_NUMWAVES][16] =
Drummer :: Drummer() : Instrmnt()
{
- for (int i=0; i= 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 == DRUM_POLYPHONY) {
+ if (nSounding_ == DRUM_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; isetRate( 22050.0 / Stk::sampleRate() );
- filters[nSounding-1]->setPole((MY_FLOAT) 0.999 - (gain * 0.6) );
- filters[nSounding-1]->setGain( gain );
+ 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; isetGain( amplitude * 0.01 );
- }
+ while ( i < nSounding_ ) filters_[i++]->setGain( amplitude * 0.01 );
}
-MY_FLOAT Drummer :: tick()
+StkFloat Drummer :: 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; jclear();
- 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 *Drummer :: tick(StkFloat *vector, unsigned int vectorSize)
+{
+ return Instrmnt::tick( vector, vectorSize );
+}
+
+StkFrames& Drummer :: tick( StkFrames& frames, unsigned int channel )
+{
+ return Instrmnt::tick( frames, channel );
}
diff --git a/src/Echo.cpp b/src/Echo.cpp
index 4774389..02e1452 100644
--- a/src/Echo.cpp
+++ b/src/Echo.cpp
@@ -2,78 +2,72 @@
/*! \class Echo
\brief STK echo effect class.
- This class implements a echo effect.
+ This class implements an echo effect.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
#include "Echo.h"
#include
-Echo :: Echo(MY_FLOAT longestDelay)
+Echo :: Echo( unsigned long maximumDelay ) : Effect()
{
- length = (long) longestDelay + 2;
- delayLine = new Delay(length>>1, length);
- effectMix = 0.5;
+ this->setMaximumDelay( maximumDelay );
+ delayLine_.setDelay( length_ >> 1 );
+ effectMix_ = 0.5;
this->clear();
}
Echo :: ~Echo()
{
- delete delayLine;
}
void Echo :: clear()
{
- delayLine->clear();
- lastOutput = 0.0;
+ delayLine_.clear();
+ lastOutput_[0] = 0.0;
+ lastOutput_[1] = 0.0;
}
-void Echo :: setDelay(MY_FLOAT delay)
+void Echo :: setMaximumDelay( unsigned long delay )
{
- MY_FLOAT size = delay;
- if ( delay < 0.0 ) {
- std::cerr << "Echo: setDelay parameter is less than zero!" << std::endl;
- size = 0.0;
- }
- else if ( delay > length ) {
- std::cerr << "Echo: setDelay parameter is greater than delay length!" << std::endl;
- size = length;
+ length_ = delay;
+ if ( delay == 0 ) {
+ errorString_ << "Echo::setMaximumDelay: parameter cannot be zero ... setting to 10!";
+ handleError( StkError::WARNING );
+ length_ = 10;
}
- delayLine->setDelay((long)size);
+ delayLine_.setMaximumDelay( length_ );
}
-void Echo :: setEffectMix(MY_FLOAT mix)
+void Echo :: setDelay( unsigned long delay )
{
- effectMix = mix;
- if ( mix < 0.0 ) {
- std::cerr << "Echo: setEffectMix parameter is less than zero!" << std::endl;
- effectMix = 0.0;
- }
- else if ( mix > 1.0 ) {
- std::cerr << "Echo: setEffectMix parameter is greater than 1.0!" << std::endl;
- effectMix = 1.0;
+ unsigned long size = delay;
+ if ( delay > length_ ) {
+ errorString_ << "Echo::setDelay: parameter is greater than maximum delay length ... setting to max!";
+ handleError( StkError::WARNING );
+ size = length_;
}
+
+ delayLine_.setDelay( size );
}
-MY_FLOAT Echo :: lastOut() const
+StkFloat Echo :: tick(StkFloat input)
{
- return lastOutput;
+ lastOutput_[0] = effectMix_ * delayLine_.tick(input);
+ lastOutput_[0] += input * (1.0 - effectMix_);
+ lastOutput_[1] = lastOutput_[0];
+ return lastOutput_[0];
}
-MY_FLOAT Echo :: tick(MY_FLOAT input)
+StkFloat *Echo :: tick(StkFloat *vector, unsigned int vectorSize)
{
- lastOutput = effectMix * delayLine->tick(input);
- lastOutput += input * (1.0 - effectMix);
- return lastOutput;
+ return Effect::tick( vector, vectorSize );
}
-MY_FLOAT *Echo :: tick(MY_FLOAT *vector, unsigned int vectorSize)
+StkFrames& Echo :: tick( StkFrames& frames, unsigned int channel )
{
- for (unsigned int i=0; i
+
+Effect :: Effect()
+{
+}
+
+Effect :: ~Effect()
+{
+}
+
+void Effect :: setEffectMix(StkFloat mix)
+{
+ if ( mix < 0.0 ) {
+ errorString_ << "Effect::setEffectMix: mix parameter is less than zero ... setting to zero!";
+ handleError( StkError::WARNING );
+ effectMix_ = 0.0;
+ }
+ else if ( mix > 1.0 ) {
+ errorString_ << "Effect::setEffectMix: mix parameter is greater than 1.0 ... setting to one!";
+ handleError( StkError::WARNING );
+ effectMix_ = 1.0;
+ }
+ else
+ effectMix_ = mix;
+}
+
+StkFloat Effect :: lastOut() const
+{
+ return (lastOutput_[0] + lastOutput_[1]) * 0.5;
+}
+
+StkFloat Effect :: lastOutLeft() const
+{
+ return lastOutput_[0];
+}
+
+StkFloat Effect :: lastOutRight() const
+{
+ return lastOutput_[1];
+}
+
+StkFloat *Effect :: tick(StkFloat *vector, unsigned int vectorSize)
+{
+ for (unsigned int i=0; i channels in StkFrames argument!";
+ handleError( StkError::FUNCTION_ARGUMENT );
+ }
+
+ if ( frames.channels() == 1 ) {
+ for ( unsigned int i=0; i
-Envelope :: Envelope(void) : Stk()
+Envelope :: Envelope(void) : Generator()
{
- target = (MY_FLOAT) 0.0;
- value = (MY_FLOAT) 0.0;
- rate = (MY_FLOAT) 0.001;
- state = 0;
+ target_ = 0.0;
+ value_ = 0.0;
+ rate_ = 0.001;
+ state_ = 0;
}
Envelope :: ~Envelope(void)
@@ -30,85 +29,85 @@ Envelope :: ~Envelope(void)
void Envelope :: keyOn(void)
{
- target = (MY_FLOAT) 1.0;
- if (value != target) state = 1;
+ target_ = 1.0;
+ if (value_ != target_) state_ = 1;
}
void Envelope :: keyOff(void)
{
- target = (MY_FLOAT) 0.0;
- if (value != target) state = 1;
+ target_ = 0.0;
+ if (value_ != target_) state_ = 1;
}
-void Envelope :: setRate(MY_FLOAT aRate)
+void Envelope :: setRate(StkFloat rate)
{
- if (aRate < 0.0) {
- printf("Envelope: negative rates not allowed ... correcting!\n");
- rate = -aRate;
+ if (rate < 0.0) {
+ errorString_ << "Envelope::setRate: negative rates not allowed ... correcting!";
+ handleError( StkError::WARNING );
+ rate_ = -rate;
}
else
- rate = aRate;
+ rate_ = rate;
}
-void Envelope :: setTime(MY_FLOAT aTime)
+void Envelope :: setTime(StkFloat time)
{
- if (aTime < 0.0) {
- printf("Envelope: negative times not allowed ... correcting!\n");
- rate = 1.0 / (-aTime * Stk::sampleRate());
+ if (time < 0.0) {
+ errorString_ << "Envelope::setTime: negative times not allowed ... correcting!";
+ handleError( StkError::WARNING );
+ rate_ = 1.0 / (-time * Stk::sampleRate());
}
else
- rate = 1.0 / (aTime * Stk::sampleRate());
+ rate_ = 1.0 / (time * Stk::sampleRate());
}
-void Envelope :: setTarget(MY_FLOAT aTarget)
+void Envelope :: setTarget(StkFloat target)
{
- target = aTarget;
- if (value != target) state = 1;
+ target_ = target;
+ if (value_ != target_) state_ = 1;
}
-void Envelope :: setValue(MY_FLOAT aValue)
+void Envelope :: setValue(StkFloat value)
{
- state = 0;
- target = aValue;
- value = aValue;
+ state_ = 0;
+ target_ = value;
+ value_ = value;
}
int Envelope :: getState(void) const
{
- return state;
+ return state_;
}
-MY_FLOAT Envelope :: tick(void)
+StkFloat Envelope :: tick(void)
{
- if (state) {
- if (target > value) {
- value += rate;
- if (value >= target) {
- value = target;
- state = 0;
+ if (state_) {
+ if (target_ > value_) {
+ value_ += rate_;
+ if (value_ >= target_) {
+ value_ = target_;
+ state_ = 0;
}
}
else {
- value -= rate;
- if (value <= target) {
- value = target;
- state = 0;
+ value_ -= rate_;
+ if (value_ <= target_) {
+ value_ = target_;
+ state_ = 0;
}
}
}
- return value;
+
+ lastOutput_ = value_;
+ return value_;
}
-MY_FLOAT *Envelope :: tick(MY_FLOAT *vector, unsigned int vectorSize)
+StkFloat *Envelope :: tick(StkFloat *vector, unsigned int vectorSize)
{
- for (unsigned int i=0; i
-FM :: FM(int operators)
- : nOperators(operators)
+FM :: FM( unsigned int operators )
+ : nOperators_(operators)
{
- if ( nOperators <= 0 ) {
- char msg[256];
- sprintf(msg, "FM: Invalid number of operators (%d) argument to constructor!", operators);
- handleError(msg, StkError::FUNCTION_ARGUMENT);
+ if ( nOperators_ == 0 ) {
+ errorString_ << "FM: Invalid number of operators (" << operators << ") argument to constructor!";
+ handleError( StkError::FUNCTION_ARGUMENT );
}
- twozero = new TwoZero();
- twozero->setB2( -1.0 );
- twozero->setGain( 0.0 );
+ twozero_.setB2( -1.0 );
+ twozero_.setGain( 0.0 );
// Concatenate the STK rawwave path to the rawwave file
- vibrato = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), TRUE );
- vibrato->setFrequency(6.0);
+ vibrato_ = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), true );
+ vibrato_->setFrequency( 6.0 );
- int i;
- ratios = (MY_FLOAT *) new MY_FLOAT[nOperators];
- gains = (MY_FLOAT *) new MY_FLOAT[nOperators];
- adsr = (ADSR **) calloc( nOperators, sizeof(ADSR *) );
- waves = (WaveLoop **) calloc( nOperators, sizeof(WaveLoop *) );
- for (i=0; i=0; i--) {
- __FM_gains[i] = temp;
+ fmGains_[i] = temp;
temp *= 0.933033;
}
temp = 1.0;
for (i=15; i>=0; i--) {
- __FM_susLevels[i] = temp;
+ fmSusLevels_[i] = temp;
temp *= 0.707101;
}
temp = 8.498186;
for (i=0; i<32; i++) {
- __FM_attTimes[i] = temp;
+ fmAttTimes_[i] = temp;
temp *= 0.707101;
}
}
FM :: ~FM()
{
- delete vibrato;
- delete twozero;
+ delete vibrato_;
- delete [] ratios;
- delete [] gains;
- for (int i=0; isetFrequency( baseFrequency * ratios[i] );
+ for (unsigned int i=0; isetFrequency( baseFrequency_ * ratios_[i] );
}
-void FM :: setRatio(int waveIndex, MY_FLOAT ratio)
+void FM :: setRatio(unsigned int waveIndex, StkFloat ratio)
{
if ( waveIndex < 0 ) {
- std::cerr << "FM: setRatio waveIndex parameter is less than zero!" << std::endl;
+ errorString_ << "FM::setRatio: waveIndex parameter is less than zero!";
+ handleError( StkError::WARNING );
return;
}
- else if ( waveIndex >= nOperators ) {
- std::cerr << "FM: setRatio waveIndex parameter is greater than the number of operators!" << std::endl;
+ else if ( waveIndex >= nOperators_ ) {
+ errorString_ << "FM:setRatio: waveIndex parameter is greater than the number of operators!";
+ handleError( StkError::WARNING );
return;
}
- ratios[waveIndex] = ratio;
+ ratios_[waveIndex] = ratio;
if (ratio > 0.0)
- waves[waveIndex]->setFrequency(baseFrequency * ratio);
+ waves_[waveIndex]->setFrequency( baseFrequency_ * ratio );
else
- waves[waveIndex]->setFrequency(ratio);
+ waves_[waveIndex]->setFrequency( ratio );
}
-void FM :: setGain(int waveIndex, MY_FLOAT gain)
+void FM :: setGain(unsigned int waveIndex, StkFloat gain)
{
if ( waveIndex < 0 ) {
- std::cerr << "FM: setGain waveIndex parameter is less than zero!" << std::endl;
+ errorString_ << "FM::setGain: waveIndex parameter is less than zero!";
+ handleError( StkError::WARNING );
return;
}
- else if ( waveIndex >= nOperators ) {
- std::cerr << "FM: setGain waveIndex parameter is greater than the number of operators!" << std::endl;
+ else if ( waveIndex >= nOperators_ ) {
+ errorString_ << "FM::setGain: waveIndex parameter is greater than the number of operators!";
+ handleError( StkError::WARNING );
return;
}
- gains[waveIndex] = gain;
+ gains_[waveIndex] = gain;
}
-void FM :: setModulationSpeed(MY_FLOAT mSpeed)
+void FM :: setModulationSpeed(StkFloat mSpeed)
{
- vibrato->setFrequency(mSpeed);
+ vibrato_->setFrequency( mSpeed );
}
-void FM :: setModulationDepth(MY_FLOAT mDepth)
+void FM :: setModulationDepth(StkFloat mDepth)
{
- modDepth = mDepth;
+ modDepth_ = mDepth;
}
-void FM :: setControl1(MY_FLOAT cVal)
+void FM :: setControl1(StkFloat cVal)
{
- control1 = cVal * (MY_FLOAT) 2.0;
+ control1_ = cVal * 2.0;
}
-void FM :: setControl2(MY_FLOAT cVal)
+void FM :: setControl2(StkFloat cVal)
{
- control2 = cVal * (MY_FLOAT) 2.0;
+ control2_ = cVal * 2.0;
}
void FM :: keyOn()
{
- for (int i=0; ikeyOn();
+ for (unsigned int i=0; ikeyOn();
}
void FM :: keyOff()
{
- for (int i=0; ikeyOff();
+ for (unsigned int i=0; ikeyOff();
}
-void FM :: noteOff(MY_FLOAT amplitude)
+void FM :: noteOff(StkFloat amplitude)
{
- keyOff();
+ this->keyOff();
#if defined(_STK_DEBUG_)
- std::cerr << "FM: NoteOff amplitude = " << amplitude << std::endl;
+ errorString_ << "FM::NoteOff: amplitude = " << amplitude << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-void FM :: controlChange(int number, MY_FLOAT value)
+void FM :: controlChange(int number, StkFloat value)
{
- MY_FLOAT norm = value * ONE_OVER_128;
+ StkFloat norm = value * ONE_OVER_128;
if ( norm < 0 ) {
norm = 0.0;
- std::cerr << "FM: Control value less than zero!" << std::endl;
+ errorString_ << "FM::controlChange: control value less than zero ... setting to zero!";
+ handleError( StkError::WARNING );
}
else if ( norm > 1.0 ) {
norm = 1.0;
- std::cerr << "FM: Control value greater than 128.0!" << std::endl;
+ errorString_ << "FM::controlChange: control value greater than 128.0 ... setting to 128.0!";
+ handleError( StkError::WARNING );
}
if (number == __SK_Breath_) // 2
- setControl1( norm );
+ this->setControl1( norm );
else if (number == __SK_FootControl_) // 4
- setControl2( norm );
+ this->setControl2( norm );
else if (number == __SK_ModFrequency_) // 11
- setModulationSpeed( norm * 12.0);
+ this->setModulationSpeed( norm * 12.0);
else if (number == __SK_ModWheel_) // 1
- setModulationDepth( norm );
+ this->setModulationDepth( norm );
else if (number == __SK_AfterTouch_Cont_) { // 128
- //adsr[0]->setTarget( norm );
- adsr[1]->setTarget( norm );
- //adsr[2]->setTarget( norm );
- adsr[3]->setTarget( norm );
+ //adsr_[0]->setTarget( norm );
+ adsr_[1]->setTarget( norm );
+ //adsr_[2]->setTarget( norm );
+ adsr_[3]->setTarget( norm );
+ }
+ else {
+ errorString_ << "FM::controlChange: undefined control number (" << number << ")!";
+ handleError( StkError::WARNING );
}
- else
- std::cerr << "FM: Undefined Control Number (" << number << ")!!" << std::endl;
#if defined(_STK_DEBUG_)
- std::cerr << "FM: controlChange number = " << number << ", value = " << value << std::endl;
+ errorString_ << "FM::controlChange: number = " << number << ", value = " << value << '.';
+ handleError( StkError::DEBUG_WARNING );
#endif
}
diff --git a/src/FMVoices.cpp b/src/FMVoices.cpp
index d893582..4e229dc 100644
--- a/src/FMVoices.cpp
+++ b/src/FMVoices.cpp
@@ -26,7 +26,7 @@
type who should worry about this (making
money) worry away.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
@@ -38,146 +38,163 @@ FMVoices :: FMVoices()
: FM()
{
// Concatenate the STK rawwave path to the rawwave files
- for ( int i=0; i<3; i++ )
- waves[i] = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), TRUE );
- waves[3] = new WaveLoop( (Stk::rawwavePath() + "fwavblnk.raw").c_str(), TRUE );
+ for ( unsigned int i=0; i<3; i++ )
+ waves_[i] = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), true );
+ waves_[3] = new WaveLoop( (Stk::rawwavePath() + "fwavblnk.raw").c_str(), true );
this->setRatio(0, 2.00);
this->setRatio(1, 4.00);
this->setRatio(2, 12.0);
this->setRatio(3, 1.00);
- gains[3] = __FM_gains[80];
+ gains_[3] = fmGains_[80];
- adsr[0]->setAllTimes( 0.05, 0.05, __FM_susLevels[15], 0.05);
- adsr[1]->setAllTimes( 0.05, 0.05, __FM_susLevels[15], 0.05);
- adsr[2]->setAllTimes( 0.05, 0.05, __FM_susLevels[15], 0.05);
- adsr[3]->setAllTimes( 0.01, 0.01, __FM_susLevels[15], 0.5);
+ adsr_[0]->setAllTimes( 0.05, 0.05, fmSusLevels_[15], 0.05);
+ adsr_[1]->setAllTimes( 0.05, 0.05, fmSusLevels_[15], 0.05);
+ adsr_[2]->setAllTimes( 0.05, 0.05, fmSusLevels_[15], 0.05);
+ adsr_[3]->setAllTimes( 0.01, 0.01, fmSusLevels_[15], 0.5);
- twozero->setGain( 0.0 );
- modDepth = (MY_FLOAT) 0.005;
- currentVowel = 0;
- tilt[0] = 1.0;
- tilt[1] = 0.5;
- tilt[2] = 0.2;
- mods[0] = 1.0;
- mods[1] = 1.1;
- mods[2] = 1.1;
- baseFrequency = 110.0;
- setFrequency( 110.0 );
+ twozero_.setGain( 0.0 );
+ modDepth_ = (StkFloat) 0.005;
+ currentVowel_ = 0;
+ tilt_[0] = 1.0;
+ tilt_[1] = 0.5;
+ tilt_[2] = 0.2;
+ mods_[0] = 1.0;
+ mods_[1] = 1.1;
+ mods_[2] = 1.1;
+ baseFrequency_ = 110.0;
+ this->setFrequency( 110.0 );
}
FMVoices :: ~FMVoices()
{
}
-void FMVoices :: setFrequency(MY_FLOAT frequency)
+void FMVoices :: setFrequency(StkFloat frequency)
{
- MY_FLOAT temp, temp2 = 0.0;
+ StkFloat temp, temp2 = 0.0;
int tempi = 0;
unsigned int i = 0;
- if (currentVowel < 32) {
- i = currentVowel;
- temp2 = (MY_FLOAT) 0.9;
+ if (currentVowel_ < 32) {
+ i = currentVowel_;
+ temp2 = 0.9;
}
- else if (currentVowel < 64) {
- i = currentVowel - 32;
- temp2 = (MY_FLOAT) 1.0;
+ else if (currentVowel_ < 64) {
+ i = currentVowel_ - 32;
+ temp2 = 1.0;
}
- else if (currentVowel < 96) {
- i = currentVowel - 64;
- temp2 = (MY_FLOAT) 1.1;
+ else if (currentVowel_ < 96) {
+ i = currentVowel_ - 64;
+ temp2 = 1.1;
}
- else if (currentVowel <= 128) {
- i = currentVowel - 96;
- temp2 = (MY_FLOAT) 1.2;
+ else if (currentVowel_ <= 128) {
+ i = currentVowel_ - 96;
+ temp2 = 1.2;
}
- baseFrequency = frequency;
- temp = (temp2 * Phonemes::formantFrequency(i, 0) / baseFrequency) + 0.5;
+ baseFrequency_ = frequency;
+ temp = (temp2 * Phonemes::formantFrequency(i, 0) / baseFrequency_) + 0.5;
tempi = (int) temp;
- this->setRatio(0,(MY_FLOAT) tempi);
- temp = (temp2 * Phonemes::formantFrequency(i, 1) / baseFrequency) + 0.5;
+ this->setRatio( 0, (StkFloat) tempi );
+ temp = (temp2 * Phonemes::formantFrequency(i, 1) / baseFrequency_) + 0.5;
tempi = (int) temp;
- this->setRatio(1,(MY_FLOAT) tempi);
- temp = (temp2 * Phonemes::formantFrequency(i, 2) / baseFrequency) + 0.5;
+ this->setRatio( 1, (StkFloat) tempi );
+ temp = (temp2 * Phonemes::formantFrequency(i, 2) / baseFrequency_) + 0.5;
tempi = (int) temp;
- this->setRatio(2, (MY_FLOAT) tempi);
- gains[0] = 1.0;
- gains[1] = 1.0;
- gains[2] = 1.0;
+ this->setRatio( 2, (StkFloat) tempi );
+ gains_[0] = 1.0;
+ gains_[1] = 1.0;
+ gains_[2] = 1.0;
}
-void FMVoices :: noteOn(MY_FLOAT frequency, MY_FLOAT amplitude)
+void FMVoices :: noteOn(StkFloat frequency, StkFloat amplitude)
{
- this->setFrequency(frequency);
- tilt[0] = amplitude;
- tilt[1] = amplitude * amplitude;
- tilt[2] = tilt[1] * amplitude;
+ this->setFrequency( frequency );
+ tilt_[0] = amplitude;
+ tilt_[1] = amplitude * amplitude;
+ tilt_[2] = tilt_[1] * amplitude;
this->keyOn();
#if defined(_STK_DEBUG_)
- std::cerr << "FMVoices: NoteOn frequency = " << frequency << ", amplitude = " << amplitude << std::endl;
+ errorString_ << "FMVoices::NoteOn: frequency = " << frequency << ", amplitude = " << amplitude << '.';
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-MY_FLOAT FMVoices :: tick()
+StkFloat FMVoices :: tick()
{
- register MY_FLOAT temp, temp2;
+ register StkFloat temp, temp2;
- temp = gains[3] * adsr[3]->tick() * waves[3]->tick();
- temp2 = vibrato->tick() * modDepth * (MY_FLOAT) 0.1;
+ temp = gains_[3] * adsr_[3]->tick() * waves_[3]->tick();
+ temp2 = vibrato_->tick() * modDepth_ * 0.1;
- waves[0]->setFrequency(baseFrequency * (1.0 + temp2) * ratios[0]);
- waves[1]->setFrequency(baseFrequency * (1.0 + temp2) * ratios[1]);
- waves[2]->setFrequency(baseFrequency * (1.0 + temp2) * ratios[2]);
- waves[3]->setFrequency(baseFrequency * (1.0 + temp2) * ratios[3]);
+ waves_[0]->setFrequency(baseFrequency_ * (1.0 + temp2) * ratios_[0]);
+ waves_[1]->setFrequency(baseFrequency_ * (1.0 + temp2) * ratios_[1]);
+ waves_[2]->setFrequency(baseFrequency_ * (1.0 + temp2) * ratios_[2]);
+ waves_[3]->setFrequency(baseFrequency_ * (1.0 + temp2) * ratios_[3]);
- waves[0]->addPhaseOffset(temp * mods[0]);
- waves[1]->addPhaseOffset(temp * mods[1]);
- waves[2]->addPhaseOffset(temp * mods[2]);
- waves[3]->addPhaseOffset(twozero->lastOut());
- twozero->tick(temp);
- temp = gains[0] * tilt[0] * adsr[0]->tick() * waves[0]->tick();
- temp += gains[1] * tilt[1] * adsr[1]->tick() * waves[1]->tick();
- temp += gains[2] * tilt[2] * adsr[2]->tick() * waves[2]->tick();
-
- return temp * 0.33;
+ waves_[0]->addPhaseOffset(temp * mods_[0]);
+ waves_[1]->addPhaseOffset(temp * mods_[1]);
+ waves_[2]->addPhaseOffset(temp * mods_[2]);
+ waves_[3]->addPhaseOffset( twozero_.lastOut() );
+ twozero_.tick( temp );
+ temp = gains_[0] * tilt_[0] * adsr_[0]->tick() * waves_[0]->tick();
+ temp += gains_[1] * tilt_[1] * adsr_[1]->tick() * waves_[1]->tick();
+ temp += gains_[2] * tilt_[2] * adsr_[2]->tick() * waves_[2]->tick();
+
+ lastOutput_ = temp * 0.33;
+ return lastOutput_;
}
-void FMVoices :: controlChange(int number, MY_FLOAT value)
+StkFloat *FMVoices :: tick(StkFloat *vector, unsigned int vectorSize)
{
- MY_FLOAT norm = value * ONE_OVER_128;
+ return Instrmnt::tick( vector, vectorSize );
+}
+
+StkFrames& FMVoices :: tick( StkFrames& frames, unsigned int channel )
+{
+ return Instrmnt::tick( frames, channel );
+}
+
+void FMVoices :: controlChange(int number, StkFloat value)
+{
+ StkFloat norm = value * ONE_OVER_128;
if ( norm < 0 ) {
norm = 0.0;
- std::cerr << "FMVoices: Control value less than zero!" << std::endl;
+ errorString_ << "FMVoices::controlChange: control value less than zero ... setting to zero!";
+ handleError( StkError::WARNING );
}
else if ( norm > 1.0 ) {
norm = 1.0;
- std::cerr << "FMVoices: Control value greater than 128.0!" << std::endl;
+ errorString_ << "FMVoices::controlChange: control value greater than 128.0 ... setting to 128.0!";
+ handleError( StkError::WARNING );
}
if (number == __SK_Breath_) // 2
- gains[3] = __FM_gains[(int) ( norm * 99.9 )];
+ gains_[3] = fmGains_[(int) ( norm * 99.9 )];
else if (number == __SK_FootControl_) { // 4
- currentVowel = (int) (norm * 128.0);
- this->setFrequency(baseFrequency);
+ currentVowel_ = (int) (norm * 128.0);
+ this->setFrequency(baseFrequency_);
}
else if (number == __SK_ModFrequency_) // 11
this->setModulationSpeed( norm * 12.0);
else if (number == __SK_ModWheel_) // 1
this->setModulationDepth( norm );
else if (number == __SK_AfterTouch_Cont_) { // 128
- tilt[0] = norm;
- tilt[1] = norm * norm;
- tilt[2] = tilt[1] * norm;
+ tilt_[0] = norm;
+ tilt_[1] = norm * norm;
+ tilt_[2] = tilt_[1] * norm;
+ }
+ else {
+ errorString_ << "FMVoices::controlChange: undefined control number (" << number << ")!";
+ handleError( StkError::WARNING );
}
- else
- std::cerr << "FMVoices: Undefined Control Number (" << number << ")!!" << std::endl;
#if defined(_STK_DEBUG_)
- std::cerr << "FMVoices: controlChange number = " << number << ", value = " << value << std::endl;
+ errorString_ << "FMVoices::controlChange: number = " << number << ", value = " << value << '.';
+ handleError( StkError::DEBUG_WARNING );
#endif
}
diff --git a/src/Filter.cpp b/src/Filter.cpp
index a27b56e..097fc68 100644
--- a/src/Filter.cpp
+++ b/src/Filter.cpp
@@ -14,7 +14,7 @@
a[0]*y[n] = b[0]*x[n] + ... + b[nb]*x[n-nb] -
a[1]*y[n-1] - ... - a[na]*y[n-na]
- If a[0] is not equal to 1, the filter coeffcients
+ If a[0] is not equal to 1, the filter coefficients
are normalized by a[0].
The \e gain parameter is applied at the filter
@@ -23,7 +23,7 @@
results in one extra multiply per computed sample,
but allows easy control of the overall filter gain.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
@@ -33,212 +33,209 @@
Filter :: Filter()
{
// The default constructor should setup for pass-through.
- gain = 1.0;
- nB = 1;
- nA = 1;
- b = new MY_FLOAT[nB];
- b[0] = 1.0;
- a = new MY_FLOAT[nA];
- a[0] = 1.0;
+ gain_ = 1.0;
+ b_.push_back( 1.0 );
+ a_.push_back( 1.0 );
- inputs = new MY_FLOAT[nB];
- outputs = new MY_FLOAT[nA];
- this->clear();
+ inputs_.push_back( 0.0 );
+ outputs_.push_back( 0.0 );
}
-Filter :: Filter(int nb, MY_FLOAT *bCoefficients, int na, MY_FLOAT *aCoefficients)
+Filter :: Filter( std::vector &bCoefficients, std::vector &aCoefficients )
{
- char message[256];
-
// Check the arguments.
- if ( nb < 1 || na < 1 ) {
- sprintf(message, "Filter: nb (%d) and na (%d) must be >= 1!", nb, na);
- handleError( message, StkError::FUNCTION_ARGUMENT );
+ if ( bCoefficients.size() == 0 || aCoefficients.size() == 0 ) {
+ errorString_ << "Filter: a and b coefficient vectors must both have size > 0!";
+ handleError( StkError::FUNCTION_ARGUMENT );
}
if ( aCoefficients[0] == 0.0 ) {
- sprintf(message, "Filter: a[0] coefficient cannot == 0!");
- handleError( message, StkError::FUNCTION_ARGUMENT );
+ errorString_ << "Filter: a[0] coefficient cannot == 0!";
+ handleError( StkError::FUNCTION_ARGUMENT );
}
- gain = 1.0;
- nB = nb;
- nA = na;
- b = new MY_FLOAT[nB];
- a = new MY_FLOAT[nA];
+ gain_ = 1.0;
+ b_ = bCoefficients;
+ a_ = aCoefficients;
- inputs = new MY_FLOAT[nB];
- outputs = new MY_FLOAT[nA];
+ inputs_ = std::vector ( b_.size() );
+ outputs_ = std::vector ( a_.size() );
this->clear();
-
- this->setCoefficients(nB, bCoefficients, nA, aCoefficients);
}
Filter :: ~Filter()
{
- delete [] b;
- delete [] a;
- delete [] inputs;
- delete [] outputs;
}
void Filter :: clear(void)
{
- int i;
- for (i=0; i &bCoefficients, std::vector &aCoefficients )
{
- int i;
- char message[256];
-
// Check the arguments.
- if ( nb < 1 || na < 1 ) {
- sprintf(message, "Filter: nb (%d) and na (%d) must be >= 1!", nb, na);
- handleError( message, StkError::FUNCTION_ARGUMENT );
+ if ( bCoefficients.size() == 0 || aCoefficients.size() == 0 ) {
+ errorString_ << "Filter::setCoefficients: a and b coefficient vectors must both have size > 0!";
+ handleError( StkError::FUNCTION_ARGUMENT );
}
if ( aCoefficients[0] == 0.0 ) {
- sprintf(message, "Filter: a[0] coefficient cannot == 0!");
- handleError( message, StkError::FUNCTION_ARGUMENT );
+ errorString_ << "Filter::setCoefficients: a[0] coefficient cannot == 0!";
+ handleError( StkError::FUNCTION_ARGUMENT );
}
- if (nb != nB) {
- delete [] b;
- delete [] inputs;
- nB = nb;
- b = new MY_FLOAT[nB];
- inputs = new MY_FLOAT[nB];
- for (i=0; i ( b_.size() );
+ }
+ else {
+ for ( unsigned int i=0; i ( a_.size() );
+ }
+ else {
+ for ( unsigned int i=0; iclear();
- // scale coefficients by a[0] if necessary
- if (a[0] != 1.0) {
- for (i=0; i &bCoefficients )
{
- int i;
- char message[256];
-
- // Check the arguments.
- if ( nb < 1 ) {
- sprintf(message, "Filter: nb (%d) must be >= 1!", nb);
- handleError( message, StkError::FUNCTION_ARGUMENT );
+ // Check the argument.
+ if ( bCoefficients.size() == 0 ) {
+ errorString_ << "Filter::setNumerator: coefficient vector must have size > 0!";
+ handleError( StkError::FUNCTION_ARGUMENT );
}
- if (nb != nB) {
- delete [] b;
- delete [] inputs;
- nB = nb;
- b = new MY_FLOAT[nB];
- inputs = new MY_FLOAT[nB];
- for (i=0; i ( b_.size() );
+ }
+ else {
+ for ( unsigned int i=0; iclear();
}
-void Filter :: setDenominator(int na, MY_FLOAT *aCoefficients)
+void Filter :: setDenominator( std::vector &aCoefficients )
{
- int i;
- char message[256];
-
- // Check the arguments.
- if ( na < 1 ) {
- sprintf(message, "Filter: na (%d) must be >= 1!", na);
- handleError( message, StkError::FUNCTION_ARGUMENT );
+ // Check the argument.
+ if ( aCoefficients.size() == 0 ) {
+ errorString_ << "Filter::setDenominator: coefficient vector must have size > 0!";
+ handleError( StkError::FUNCTION_ARGUMENT );
}
if ( aCoefficients[0] == 0.0 ) {
- sprintf(message, "Filter: a[0] coefficient cannot == 0!");
- handleError( message, StkError::FUNCTION_ARGUMENT );
+ errorString_ << "Filter::setDenominator: a[0] coefficient cannot == 0!";
+ handleError( StkError::FUNCTION_ARGUMENT );
}
- if (na != nA) {
- delete [] a;
- delete [] outputs;
- nA = na;
- a = new MY_FLOAT[nA];
- outputs = new MY_FLOAT[nA];
- for (i=0; i ( a_.size() );
+ }
+ else {
+ for ( unsigned int i=0; iclear();
- // scale coefficients by a[0] if necessary
- if (a[0] != 1.0) {
- for (i=0; i0; i--) {
- outputs[0] += b[i] * inputs[i];
- inputs[i] = inputs[i-1];
+ outputs_[0] = 0.0;
+ inputs_[0] = gain_ * sample;
+ for (i=b_.size()-1; i>0; i--) {
+ outputs_[0] += b_[i] * inputs_[i];
+ inputs_[i] = inputs_[i-1];
}
- outputs[0] += b[0] * inputs[0];
+ outputs_[0] += b_[0] * inputs_[0];
- for (i=nA-1; i>0; i--) {
- outputs[0] += -a[i] * outputs[i];
- outputs[i] = outputs[i-1];
+ for (i=a_.size()-1; i>0; i--) {
+ outputs_[0] += -a_[i] * outputs_[i];
+ outputs_[i] = outputs_[i-1];
}
- return outputs[0];
+ return outputs_[0];
}
-MY_FLOAT *Filter :: tick(MY_FLOAT *vector, unsigned int vectorSize)
+StkFloat *Filter :: tick(StkFloat *vector, unsigned int vectorSize)
{
for (unsigned int i=0; i channels in StkFrames argument!";
+ handleError( StkError::FUNCTION_ARGUMENT );
+ }
+
+ if ( frames.channels() == 1 ) {
+ for ( unsigned int i=0; i>= 1;
- jetDelay = new DelayL( 49.0, length );
- jetTable = new JetTabl();
- filter = new OnePole();
- dcBlock = new PoleZero();
- dcBlock->setBlockZero();
- noise = new Noise();
- adsr = new ADSR();
+ length_ = (unsigned long) (Stk::sampleRate() / lowestFrequency + 1);
+ boreDelay_.setMaximumDelay( length_ );
+ boreDelay_.setDelay( 100.0 );
+
+ length_ >>= 1;
+ jetDelay_.setMaximumDelay( length_ );
+ jetDelay_.setDelay( 49.0 );
// Concatenate the STK rawwave path to the rawwave file
- vibrato = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), TRUE );
- vibrato->setFrequency( 5.925 );
+ vibrato_ = new WaveLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), true );
+ vibrato_->setFrequency( 5.925 );
this->clear();
- filter->setPole( 0.7 - ((MY_FLOAT) 0.1 * 22050.0 / Stk::sampleRate() ) );
- filter->setGain( -1.0 );
- adsr->setAllTimes( 0.005, 0.01, 0.8, 0.010);
- endReflection = (MY_FLOAT) 0.5;
- jetReflection = (MY_FLOAT) 0.5;
- noiseGain = 0.15; // Breath pressure random component.
- vibratoGain = (MY_FLOAT) 0.05; // Breath periodic vibrato component.
- jetRatio = (MY_FLOAT) 0.32;
+ filter_.setPole( 0.7 - ((StkFloat) 0.1 * 22050.0 / Stk::sampleRate() ) );
+ filter_.setGain( -1.0 );
+ adsr_.setAllTimes( 0.005, 0.01, 0.8, 0.010);
+ endReflection_ = 0.5;
+ jetReflection_ = 0.5;
+ noiseGain_ = 0.15; // Breath pressure random component.
+ vibratoGain_ = 0.05; // Breath periodic vibrato component.
+ jetRatio_ = 0.32;
- maxPressure = (MY_FLOAT) 0.0;
- lastFrequency = 220.0;
+ maxPressure_ = 0.0;
+ lastFrequency_ = 220.0;
}
Flute :: ~Flute()
{
- delete jetDelay;
- delete boreDelay;
- delete jetTable;
- delete filter;
- delete dcBlock;
- delete noise;
- delete adsr;
- delete vibrato;
+ delete vibrato_;
}
void Flute :: clear()
{
- jetDelay->clear();
- boreDelay->clear();
- filter->clear();
- dcBlock->clear();
+ jetDelay_.clear();
+ boreDelay_.clear();
+ filter_.clear();
+ dcBlock_.clear();
}
-void Flute :: setFrequency(MY_FLOAT frequency)
+void Flute :: setFrequency(StkFloat frequency)
{
- lastFrequency = frequency;
+ lastFrequency_ = frequency;
if ( frequency <= 0.0 ) {
- std::cerr << "Flute: setFrequency parameter is less than or equal to zero!" << std::endl;
- lastFrequency = 220.0;
+ errorString_ << "Flute::setFrequency: parameter is less than or equal to zero!";
+ handleError( StkError::WARNING );
+ lastFrequency_ = 220.0;
}
// We're overblowing here.
- lastFrequency *= 0.66666;
- // Delay = length - approximate filter delay.
- MY_FLOAT delay = Stk::sampleRate() / lastFrequency - (MY_FLOAT) 2.0;
- if (delay <= 0.0) delay = 0.3;
- else if (delay > length) delay = length;
+ lastFrequency_ *= 0.66666;
- boreDelay->setDelay(delay);
- jetDelay->setDelay(delay * jetRatio);
+ // delay = length - approximate filter delay.
+ StkFloat delay = Stk::sampleRate() / lastFrequency_ - (StkFloat) 2.0;
+ if ( delay <= 0.0 ) delay = 0.3;
+ else if ( delay > length_ ) delay = length_;
+
+ boreDelay_.setDelay(delay);
+ jetDelay_.setDelay(delay * jetRatio_);
}
-void Flute :: startBlowing(MY_FLOAT amplitude, MY_FLOAT rate)
+void Flute :: startBlowing(StkFloat amplitude, StkFloat rate)
{
- adsr->setAttackRate(rate);
- maxPressure = amplitude / (MY_FLOAT) 0.8;
- adsr->keyOn();
+ adsr_.setAttackRate( rate );
+ maxPressure_ = amplitude / (StkFloat) 0.8;
+ adsr_.keyOn();
}
-void Flute :: stopBlowing(MY_FLOAT rate)
+void Flute :: stopBlowing(StkFloat rate)
{
- adsr->setReleaseRate(rate);
- adsr->keyOff();
+ adsr_.setReleaseRate( rate );
+ adsr_.keyOff();
}
-void Flute :: noteOn(MY_FLOAT frequency, MY_FLOAT amplitude)
+void Flute :: noteOn(StkFloat frequency, StkFloat amplitude)
{
- setFrequency(frequency);
- startBlowing( 1.1 + (amplitude * 0.20), amplitude * 0.02);
- outputGain = amplitude + 0.001;
+ this->setFrequency( frequency );
+ this->startBlowing( 1.1 + (amplitude * 0.20), amplitude * 0.02 );
+ outputGain_ = amplitude + 0.001;
#if defined(_STK_DEBUG_)
- std::cerr << "Flute: NoteOn frequency = " << frequency << ", amplitude = " << amplitude << std::endl;
+ errorString_ << "Flute::NoteOn: frequency = " << frequency << ", amplitude = " << amplitude << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-void Flute :: noteOff(MY_FLOAT amplitude)
+void Flute :: noteOff(StkFloat amplitude)
{
- this->stopBlowing(amplitude * 0.02);
+ this->stopBlowing( amplitude * 0.02 );
#if defined(_STK_DEBUG_)
- std::cerr << "Flute: NoteOff amplitude = " << amplitude << std::endl;
+ errorString_ << "Flute::NoteOff: amplitude = " << amplitude << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-void Flute :: setJetReflection(MY_FLOAT coefficient)
+void Flute :: setJetReflection(StkFloat coefficient)
{
- jetReflection = coefficient;
+ jetReflection_ = coefficient;
}
-void Flute :: setEndReflection(MY_FLOAT coefficient)
+void Flute :: setEndReflection(StkFloat coefficient)
{
- endReflection = coefficient;
+ endReflection_ = coefficient;
}
-void Flute :: setJetDelay(MY_FLOAT aRatio)
+void Flute :: setJetDelay(StkFloat aRatio)
{
// Delay = length - approximate filter delay.
- MY_FLOAT temp = Stk::sampleRate() / lastFrequency - (MY_FLOAT) 2.0;
- jetRatio = aRatio;
- jetDelay->setDelay(temp * aRatio); // Scaled by ratio.
+ StkFloat temp = Stk::sampleRate() / lastFrequency_ - (StkFloat) 2.0;
+ jetRatio_ = aRatio;
+ jetDelay_.setDelay(temp * aRatio); // Scaled by ratio.
}
-MY_FLOAT Flute :: tick()
+StkFloat Flute :: tick()
{
- MY_FLOAT pressureDiff;
- MY_FLOAT breathPressure;
+ StkFloat pressureDiff;
+ StkFloat breathPressure;
// Calculate the breath pressure (envelope + noise + vibrato)
- breathPressure = maxPressure * adsr->tick();
- breathPressure += breathPressure * noiseGain * noise->tick();
- breathPressure += breathPressure * vibratoGain * vibrato->tick();
+ breathPressure = maxPressure_ * adsr_.tick();
+ breathPressure += breathPressure * noiseGain_ * noise_.tick();
+ breathPressure += breathPressure * vibratoGain_ * vibrato_->tick();
- MY_FLOAT temp = filter->tick( boreDelay->lastOut() );
- temp = dcBlock->tick(temp); // Block DC on reflection.
+ StkFloat temp = filter_.tick( boreDelay_.lastOut() );
+ temp = dcBlock_.tick(temp); // Block DC on reflection.
- pressureDiff = breathPressure - (jetReflection * temp);
- pressureDiff = jetDelay->tick( pressureDiff );
- pressureDiff = jetTable->tick( pressureDiff ) + (endReflection * temp);
- lastOutput = (MY_FLOAT) 0.3 * boreDelay->tick( pressureDiff );
+ pressureDiff = breathPressure - (jetReflection_ * temp);
+ pressureDiff = jetDelay_.tick( pressureDiff );
+ pressureDiff = jetTable_.tick( pressureDiff ) + (endReflection_ * temp);
+ lastOutput_ = (StkFloat) 0.3 * boreDelay_.tick( pressureDiff );
- lastOutput *= outputGain;
- return lastOutput;
+ lastOutput_ *= outputGain_;
+ return lastOutput_;
}
-void Flute :: controlChange(int number, MY_FLOAT value)
+StkFloat *Flute :: tick(StkFloat *vector, unsigned int vectorSize)
{
- MY_FLOAT norm = value * ONE_OVER_128;
+ return Instrmnt::tick( vector, vectorSize );
+}
+
+StkFrames& Flute :: tick( StkFrames& frames, unsigned int channel )
+{
+ return Instrmnt::tick( frames, channel );
+}
+
+void Flute :: controlChange(int number, StkFloat value)
+{
+ StkFloat norm = value * ONE_OVER_128;
if ( norm < 0 ) {
norm = 0.0;
- std::cerr << "Flute: Control value less than zero!" << std::endl;
+ errorString_ << "Flute::controlChange: control value less than zero ... setting to zero!";
+ handleError( StkError::WARNING );
}
else if ( norm > 1.0 ) {
norm = 1.0;
- std::cerr << "Flute: Control value greater than 128.0!" << std::endl;
+ errorString_ << "Flute::controlChange: control value greater than 128.0 ... setting to 128.0!";
+ handleError( StkError::WARNING );
}
if (number == __SK_JetDelay_) // 2
- this->setJetDelay( (MY_FLOAT) (0.08 + (0.48 * norm)) );
+ this->setJetDelay( (StkFloat) (0.08 + (0.48 * norm)) );
else if (number == __SK_NoiseLevel_) // 4
- noiseGain = ( norm * 0.4);
+ noiseGain_ = ( norm * 0.4);
else if (number == __SK_ModFrequency_) // 11
- vibrato->setFrequency( norm * 12.0);
+ vibrato_->setFrequency( norm * 12.0);
else if (number == __SK_ModWheel_) // 1
- vibratoGain = ( norm * 0.4 );
+ vibratoGain_ = ( norm * 0.4 );
else if (number == __SK_AfterTouch_Cont_) // 128
- adsr->setTarget( norm );
- else
- std::cerr << "Flute: Undefined Control Number (" << number << ")!!" << std::endl;
+ adsr_.setTarget( norm );
+ else {
+ errorString_ << "Flute::controlChange: undefined control number (" << number << ")!";
+ handleError( StkError::WARNING );
+ }
#if defined(_STK_DEBUG_)
- std::cerr << "Flute: controlChange number = " << number << ", value = " << value << std::endl;
+ errorString_ << "Flute::controlChange: number = " << number << ", value = " << value << ".";
+ handleError( StkError::DEBUG_WARNING );
#endif
}
diff --git a/src/FormSwep.cpp b/src/FormSwep.cpp
index 831c2c6..6ffebe0 100644
--- a/src/FormSwep.cpp
+++ b/src/FormSwep.cpp
@@ -8,7 +8,7 @@
It provides methods for controlling the sweep
rate and target frequency.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
@@ -16,17 +16,17 @@
FormSwep :: FormSwep() : BiQuad()
{
- frequency = (MY_FLOAT) 0.0;
- radius = (MY_FLOAT) 0.0;
- targetGain = (MY_FLOAT) 1.0;
- targetFrequency = (MY_FLOAT) 0.0;
- targetRadius = (MY_FLOAT) 0.0;
- deltaGain = (MY_FLOAT) 0.0;
- deltaFrequency = (MY_FLOAT) 0.0;
- deltaRadius = (MY_FLOAT) 0.0;
- sweepState = (MY_FLOAT) 0.0;
- sweepRate = (MY_FLOAT) 0.002;
- dirty = false;
+ frequency_ = (StkFloat) 0.0;
+ radius_ = (StkFloat) 0.0;
+ targetGain_ = (StkFloat) 1.0;
+ targetFrequency_ = (StkFloat) 0.0;
+ targetRadius_ = (StkFloat) 0.0;
+ deltaGain_ = (StkFloat) 0.0;
+ deltaFrequency_ = (StkFloat) 0.0;
+ deltaRadius_ = (StkFloat) 0.0;
+ sweepState_ = (StkFloat) 0.0;
+ sweepRate_ = (StkFloat) 0.002;
+ dirty_ = false;
this->clear();
}
@@ -34,85 +34,87 @@ FormSwep :: ~FormSwep()
{
}
-void FormSwep :: setResonance(MY_FLOAT aFrequency, MY_FLOAT aRadius)
+void FormSwep :: setResonance(StkFloat frequency, StkFloat radius)
{
- dirty = false;
- radius = aRadius;
- frequency = aFrequency;
+ dirty_ = false;
+ radius_ = radius;
+ frequency_ = frequency;
- BiQuad::setResonance( frequency, radius, true );
+ BiQuad::setResonance( frequency_, radius_, true );
}
-void FormSwep :: setStates(MY_FLOAT aFrequency, MY_FLOAT aRadius, MY_FLOAT aGain)
+void FormSwep :: setStates(StkFloat frequency, StkFloat radius, StkFloat gain)
{
- dirty = false;
+ dirty_ = false;
- if ( frequency != aFrequency || radius != aRadius )
- BiQuad::setResonance( aFrequency, aRadius, true );
+ if ( frequency_ != frequency || radius_ != radius )
+ BiQuad::setResonance( frequency, radius, true );
- frequency = aFrequency;
- radius = aRadius;
- gain = aGain;
- targetFrequency = aFrequency;
- targetRadius = aRadius;
- targetGain = aGain;
+ frequency_ = frequency;
+ radius_ = radius;
+ gain_ = gain;
+ targetFrequency_ = frequency;
+ targetRadius_ = radius;
+ targetGain_ = gain;
}
-void FormSwep :: setTargets(MY_FLOAT aFrequency, MY_FLOAT aRadius, MY_FLOAT aGain)
+void FormSwep :: setTargets(StkFloat frequency, StkFloat radius, StkFloat gain)
{
- dirty = true;
- startFrequency = frequency;
- startRadius = radius;
- startGain = gain;
- targetFrequency = aFrequency;
- targetRadius = aRadius;
- targetGain = aGain;
- deltaFrequency = aFrequency - frequency;
- deltaRadius = aRadius - radius;
- deltaGain = aGain - gain;
- sweepState = (MY_FLOAT) 0.0;
+ dirty_ = true;
+ startFrequency_ = frequency_;
+ startRadius_ = radius_;
+ startGain_ = gain_;
+ targetFrequency_ = frequency;
+ targetRadius_ = radius;
+ targetGain_ = gain;
+ deltaFrequency_ = frequency - frequency_;
+ deltaRadius_ = radius - radius_;
+ deltaGain_ = gain - gain_;
+ sweepState_ = (StkFloat) 0.0;
}
-void FormSwep :: setSweepRate(MY_FLOAT aRate)
+void FormSwep :: setSweepRate(StkFloat rate)
{
- sweepRate = aRate;
- if ( sweepRate > 1.0 ) sweepRate = 1.0;
- if ( sweepRate < 0.0 ) sweepRate = 0.0;
+ sweepRate_ = rate;
+ if ( sweepRate_ > 1.0 ) sweepRate_ = 1.0;
+ if ( sweepRate_ < 0.0 ) sweepRate_ = 0.0;
}
-void FormSwep :: setSweepTime(MY_FLOAT aTime)
+void FormSwep :: setSweepTime(StkFloat time)
{
- sweepRate = 1.0 / ( aTime * Stk::sampleRate() );
- if ( sweepRate > 1.0 ) sweepRate = 1.0;
- if ( sweepRate < 0.0 ) sweepRate = 0.0;
+ sweepRate_ = 1.0 / ( time * Stk::sampleRate() );
+ if ( sweepRate_ > 1.0 ) sweepRate_ = 1.0;
+ if ( sweepRate_ < 0.0 ) sweepRate_ = 0.0;
}
-MY_FLOAT FormSwep :: tick(MY_FLOAT sample)
+StkFloat FormSwep :: tick(StkFloat sample)
{
- if (dirty) {
- sweepState += sweepRate;
- if ( sweepState >= 1.0 ) {
- sweepState = (MY_FLOAT) 1.0;
- dirty = false;
- radius = targetRadius;
- frequency = targetFrequency;
- gain = targetGain;
+ if (dirty_) {
+ sweepState_ += sweepRate_;
+ if ( sweepState_ >= 1.0 ) {
+ sweepState_ = (StkFloat) 1.0;
+ dirty_ = false;
+ radius_ = targetRadius_;
+ frequency_ = targetFrequency_;
+ gain_ = targetGain_;
}
else {
- radius = startRadius + (deltaRadius * sweepState);
- frequency = startFrequency + (deltaFrequency * sweepState);
- gain = startGain + (deltaGain * sweepState);
+ radius_ = startRadius_ + (deltaRadius_ * sweepState_);
+ frequency_ = startFrequency_ + (deltaFrequency_ * sweepState_);
+ gain_ = startGain_ + (deltaGain_ * sweepState_);
}
- BiQuad::setResonance( frequency, radius, true );
+ BiQuad::setResonance( frequency_, radius_, true );
}
return BiQuad::tick( sample );
}
-MY_FLOAT *FormSwep :: tick(MY_FLOAT *vector, unsigned int vectorSize)
+StkFloat *FormSwep :: tick(StkFloat *vector, unsigned int vectorSize)
{
- for (unsigned int i=0; i channels in StkFrames argument!";
+ handleError( StkError::FUNCTION_ARGUMENT );
+ }
+
+ if ( frames.channels() == 1 ) {
+ for ( unsigned int i=0; i channels in StkFrames argument!";
+ handleError( StkError::FUNCTION_ARGUMENT );
+ }
+
+ if ( frames.channels() == 1 ) {
+ for ( unsigned int i=0; isetRatio(0, 1.0 * 1.000);
this->setRatio(1, 4.0 * 0.999);
this->setRatio(2, 3.0 * 1.001);
this->setRatio(3, 0.5 * 1.002);
- gains[0] = __FM_gains[92];
- gains[1] = __FM_gains[76];
- gains[2] = __FM_gains[91];
- gains[3] = __FM_gains[68];
+ gains_[0] = fmGains_[92];
+ gains_[1] = fmGains_[76];
+ gains_[2] = fmGains_[91];
+ gains_[3] = fmGains_[68];
- adsr[0]->setAllTimes( 0.001, 0.001, 1.0, 0.01);
- adsr[1]->setAllTimes( 0.001, 0.010, 1.0, 0.50);
- adsr[2]->setAllTimes( 0.010, 0.005, 1.0, 0.20);
- adsr[3]->setAllTimes( 0.030, 0.010, 0.2, 0.20);
+ adsr_[0]->setAllTimes( 0.001, 0.001, 1.0, 0.01);
+ adsr_[1]->setAllTimes( 0.001, 0.010, 1.0, 0.50);
+ adsr_[2]->setAllTimes( 0.010, 0.005, 1.0, 0.20);
+ adsr_[3]->setAllTimes( 0.030, 0.010, 0.2, 0.20);
- twozero->setGain( 2.0 );
- vibrato->setFrequency( 5.5 );
- modDepth = 0.0;
+ twozero_.setGain( 2.0 );
+ vibrato_->setFrequency( 5.5 );
+ modDepth_ = 0.0;
}
HevyMetl :: ~HevyMetl()
{
}
-void HevyMetl :: noteOn(MY_FLOAT frequency, MY_FLOAT amplitude)
+void HevyMetl :: noteOn(StkFloat frequency, StkFloat amplitude)
{
- gains[0] = amplitude * __FM_gains[92];
- gains[1] = amplitude * __FM_gains[76];
- gains[2] = amplitude * __FM_gains[91];
- gains[3] = amplitude * __FM_gains[68];
- this->setFrequency(frequency);
+ gains_[0] = amplitude * fmGains_[92];
+ gains_[1] = amplitude * fmGains_[76];
+ gains_[2] = amplitude * fmGains_[91];
+ gains_[3] = amplitude * fmGains_[68];
+ this->setFrequency( frequency );
this->keyOn();
#if defined(_STK_DEBUG_)
- cerr << "HevyMetl: NoteOn frequency = " << frequency << ", amplitude = " << amplitude << endl;
+ errorString_ << "HevyMetl::NoteOn: frequency = " << frequency << ", amplitude = " << amplitude << '.';
+ handleError( StkError::DEBUG_WARNING );
#endif
}
-MY_FLOAT HevyMetl :: tick()
+StkFloat HevyMetl :: tick()
{
- register MY_FLOAT temp;
+ register StkFloat temp;
- temp = vibrato->tick() * modDepth * 0.2;
- waves[0]->setFrequency(baseFrequency * (1.0 + temp) * ratios[0]);
- waves[1]->setFrequency(baseFrequency * (1.0 + temp) * ratios[1]);
- waves[2]->setFrequency(baseFrequency * (1.0 + temp) * ratios[2]);
- waves[3]->setFrequency(baseFrequency * (1.0 + temp) * ratios[3]);
+ temp = vibrato_->tick() * modDepth_ * 0.2;
+ waves_[0]->setFrequency(baseFrequency_ * (1.0 + temp) * ratios_[0]);
+ waves_[1]->setFrequency(baseFrequency_ * (1.0 + temp) * ratios_[1]);
+ waves_[2]->setFrequency(baseFrequency_ * (1.0 + temp) * ratios_[2]);
+ waves_[3]->setFrequency(baseFrequency_ * (1.0 + temp) * ratios_[3]);
- temp = gains[2] * adsr[2]->tick() * waves[2]->tick();
- waves[1]->addPhaseOffset(temp);
+ temp = gains_[2] * adsr_[2]->tick() * waves_[2]->tick();
+ waves_[1]->addPhaseOffset( temp );
- waves[3]->addPhaseOffset(twozero->lastOut());
- temp = (1.0 - (control2 * 0.5)) * gains[3] * adsr[3]->tick() * waves[3]->tick();
- twozero->tick(temp);
+ waves_[3]->addPhaseOffset( twozero_.lastOut() );
+ temp = (1.0 - (control2_ * 0.5)) * gains_[3] * adsr_[3]->tick() * waves_[3]->tick();
+ twozero_.tick(temp);
- temp += control2 * (MY_FLOAT) 0.5 * gains[1] * adsr[1]->tick() * waves[1]->tick();
- temp = temp * control1;
+ temp += control2_ * 0.5 * gains_[1] * adsr_[1]->tick() * waves_[1]->tick();
+ temp = temp * control1_;
- waves[0]->addPhaseOffset(temp);
- temp = gains[0] * adsr[0]->tick() * waves[0]->tick();
+ waves_[0]->addPhaseOffset( temp );
+ temp = gains_[0] * adsr_[0]->tick() * waves_[0]->tick();
- lastOutput = temp * 0.5;
- return lastOutput;
+ lastOutput_ = temp * 0.5;
+ return lastOutput_;
}
+
+StkFloat *HevyMetl :: tick(StkFloat *vector, unsigned int vectorSize)
+{
+ return Instrmnt::tick( vector, vectorSize );
+}
+
+StkFrames& HevyMetl :: tick( StkFrames& frames, unsigned int channel )
+{
+ return Instrmnt::tick( frames, channel );
+}
+
diff --git a/src/Instrmnt.cpp b/src/Instrmnt.cpp
index 5c9af3a..b4e377c 100644
--- a/src/Instrmnt.cpp
+++ b/src/Instrmnt.cpp
@@ -5,7 +5,7 @@
This class provides a common interface for
all STK instruments.
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
+ by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
@@ -19,28 +19,29 @@ Instrmnt :: ~Instrmnt()
{
}
-void Instrmnt :: setFrequency(MY_FLOAT frequency)
+void Instrmnt :: setFrequency(StkFloat frequency)
{
- std::cerr << "Instrmnt: virtual setFrequency function call!" << std::endl;
+ errorString_ << "Instrmnt::setFrequency: virtual setFrequency function call!";
+ handleError( StkError::WARNING );
}
-MY_FLOAT Instrmnt :: lastOut() const
+StkFloat Instrmnt :: lastOut() const
{
- return lastOutput;
+ return lastOutput_;
}
// Support for stereo output:
-MY_FLOAT Instrmnt :: lastOutLeft(void) const
+StkFloat Instrmnt :: lastOutLeft(void) const
{
- return 0.5 * lastOutput;
+ return 0.5 * lastOutput_;
}
-MY_FLOAT Instrmnt :: lastOutRight(void) const
+StkFloat Instrmnt :: lastOutRight(void) const
{
- return 0.5 * lastOutput;
+ return 0.5 * lastOutput_;
}
-MY_FLOAT *Instrmnt :: tick(MY_FLOAT *vector, unsigned int vectorSize)
+StkFloat *Instrmnt :: tick(StkFloat *vector, unsigned int vectorSize)
{
for (unsigned int i=0; i channels in StkFrames argument!";
+ handleError( StkError::FUNCTION_ARGUMENT );
+ }
+
+ if ( frames.channels() == 1 ) {
+ for ( unsigned int i=0; i
-JCRev :: JCRev(MY_FLOAT T60)
+JCRev :: JCRev(StkFloat T60)
{
// Delay lengths for 44100 Hz sample rate.
int lengths[9] = {1777, 1847, 1993, 2137, 389, 127, 43, 211, 179};
@@ -33,89 +33,101 @@ JCRev :: JCRev(MY_FLOAT T60)
}
}
- for (i=0; i<3; i++)
- allpassDelays[i] = new Delay(lengths[i+4], lengths[i+4]);
-
- for (i=0; i<4; i++) {
- combDelays[i] = new Delay(lengths[i], lengths[i]);
- combCoefficient[i] = pow(10.0,(-3 * lengths[i] / (T60 * Stk::sampleRate())));
+ for (i=0; i<3; i++) {
+ allpassDelays_[i].setMaximumDelay( lengths[i+4] );
+ allpassDelays_[i].setDelay( lengths[i+4] );
}
- outLeftDelay = new Delay(lengths[7], lengths[7]);
- outRightDelay = new Delay(lengths[8], lengths[8]);
- allpassCoefficient = 0.7;
- effectMix = 0.3;
+ for ( i=0; i<4; i++ ) {
+ combDelays_[i].setMaximumDelay( lengths[i] );
+ combDelays_[i].setDelay( lengths[i] );
+ }
+
+ this->setT60( T60 );
+ outLeftDelay_.setMaximumDelay( lengths[7] );
+ outLeftDelay_.setDelay( lengths[7] );
+ outRightDelay_.setMaximumDelay( lengths[8] );
+ outRightDelay_.setDelay( lengths[8] );
+ allpassCoefficient_ = 0.7;
+ effectMix_ = 0.3;
this->clear();
}
JCRev :: ~JCRev()
{
- delete allpassDelays[0];
- delete allpassDelays[1];
- delete allpassDelays[2];
- delete combDelays[0];
- delete combDelays[1];
- delete combDelays[2];
- delete combDelays[3];
- delete outLeftDelay;
- delete outRightDelay;
}
void JCRev :: clear()
{
- allpassDelays[0]->clear();
- allpassDelays[1]->clear();
- allpassDelays[2]->clear();
- combDelays[0]->clear();
- combDelays[1]->clear();
- combDelays[2]->clear();
- combDelays[3]->clear();
- outRightDelay->clear();
- outLeftDelay->clear();
- lastOutput[0] = 0.0;
- lastOutput[1] = 0.0;
+ allpassDelays_[0].clear();
+ allpassDelays_[1].clear();
+ allpassDelays_[2].clear();
+ combDelays_[0].clear();
+ combDelays_[1].clear();
+ combDelays_[2].clear();
+ combDelays_[3].clear();
+ outRightDelay_.clear();
+ outLeftDelay_.clear();
+ lastOutput_[0] = 0.0;
+ lastOutput_[1] = 0.0;
}
-MY_FLOAT JCRev :: tick(MY_FLOAT input)
+void JCRev :: setT60( StkFloat T60 )
{
- MY_FLOAT temp, temp0, temp1, temp2, temp3, temp4, temp5, temp6;
- MY_FLOAT filtout;
+ for ( int i=0; i<4; i++ )
+ combCoefficient_[i] = pow(10.0, (-3.0 * combDelays_[i].getDelay() / (T60 * Stk::sampleRate())));
+}
- temp = allpassDelays[0]->lastOut();
- temp0 = allpassCoefficient * temp;
+StkFloat JCRev :: tick(StkFloat input)
+{
+ StkFloat temp, temp0, temp1, temp2, temp3, temp4, temp5, temp6;
+ StkFloat filtout;
+
+ temp = allpassDelays_[0].lastOut();
+ temp0 = allpassCoefficient_ * temp;
temp0 += input;
- allpassDelays[0]->tick(temp0);
- temp0 = -(allpassCoefficient * temp0) + temp;
+ allpassDelays_[0].tick(temp0);
+ temp0 = -(allpassCoefficient_ * temp0) + temp;
- temp = allpassDelays[1]->lastOut();
- temp1 = allpassCoefficient * temp;
+ temp = allpassDelays_[1].lastOut();
+ temp1 = allpassCoefficient_ * temp;
temp1 += temp0;
- allpassDelays[1]->tick(temp1);
- temp1 = -(allpassCoefficient * temp1) + temp;
+ allpassDelays_[1].tick(temp1);
+ temp1 = -(allpassCoefficient_ * temp1) + temp;
- temp = allpassDelays[2]->lastOut();
- temp2 = allpassCoefficient * temp;
+ temp = allpassDelays_[2].lastOut();
+ temp2 = allpassCoefficient_ * temp;
temp2 += temp1;
- allpassDelays[2]->tick(temp2);
- temp2 = -(allpassCoefficient * temp2) + temp;
+ allpassDelays_[2].tick(temp2);
+ temp2 = -(allpassCoefficient_ * temp2) + temp;
- temp3 = temp2 + (combCoefficient[0] * combDelays[0]->lastOut());
- temp4 = temp2 + (combCoefficient[1] * combDelays[1]->lastOut());
- temp5 = temp2 + (combCoefficient[2] * combDelays[2]->lastOut());
- temp6 = temp2 + (combCoefficient[3] * combDelays[3]->lastOut());
+ temp3 = temp2 + (combCoefficient_[0] * combDelays_[0].lastOut());
+ temp4 = temp2 + (combCoefficient_[1] * combDelays_[1].lastOut());
+ temp5 = temp2 + (combCoefficient_[2] * combDelays_[2].lastOut());
+ temp6 = temp2 + (combCoefficient_[3] * combDelays_[3].lastOut());
- combDelays[0]->tick(temp3);
- combDelays[1]->tick(temp4);
- combDelays[2]->tick(temp5);
- combDelays[3]->tick(temp6);
+ combDelays_[0].tick(temp3);
+ combDelays_[1].tick(temp4);
+ combDelays_[2].tick(temp5);
+ combDelays_[3].tick(temp6);
filtout = temp3 + temp4 + temp5 + temp6;
- lastOutput[0] = effectMix * (outLeftDelay->tick(filtout));
- lastOutput[1] = effectMix * (outRightDelay->tick(filtout));
- temp = (1.0 - effectMix) * input;
- lastOutput[0] += temp;
- lastOutput[1] += temp;
+ lastOutput_[0] = effectMix_ * (outLeftDelay_.tick(filtout));
+ lastOutput_[1] = effectMix_ * (outRightDelay_.tick(filtout));
+ temp = (1.0 - effectMix_) * input;
+ lastOutput_[0] += temp;
+ lastOutput_[1] += temp;
- return (lastOutput[0] + lastOutput[1]) * 0.5;
+ return Effect::lastOut();
+}
+
+StkFloat *JCRev :: tick(StkFloat *vector, unsigned int vectorSize)
+{
+ return Effect::tick( vector, vectorSize );
+}
+
+StkFrames& JCRev :: tick( StkFrames& frames, unsigned int channel )
+{
+ return Effect::tick( frames, channel );
}
diff --git a/src/JetTabl.cpp b/src/JetTabl.cpp
deleted file mode 100644
index c4b9b61..0000000
--- a/src/JetTabl.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/***************************************************/
-/*! \class JetTabl
- \brief STK jet table class.
-
- This class implements a flue jet non-linear
- function, computed by a polynomial calculation.
- Contrary to the name, this is not a "table".
-
- Consult Fletcher and Rossing, Karjalainen,
- Cook, and others for more information.
-
- by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
-*/
-/***************************************************/
-
-#include "JetTabl.h"
-
-JetTabl :: JetTabl()
-{
- lastOutput = (MY_FLOAT) 0.0;
-}
-
-JetTabl :: ~JetTabl()
-{
-}
-
-MY_FLOAT JetTabl :: lastOut() const
-{
- return lastOutput;
-}
-
-MY_FLOAT JetTabl :: tick( MY_FLOAT input )
-{
- // Perform "table lookup" using a polynomial
- // calculation (x^3 - x), which approximates
- // the jet sigmoid behavior.
- lastOutput = input * (input * input - (MY_FLOAT) 1.0);
-
- // Saturate at +/- 1.0.
- if (lastOutput > 1.0)
- lastOutput = (MY_FLOAT) 1.0;
- if (lastOutput < -1.0)
- lastOutput = (MY_FLOAT) -1.0;
- return lastOutput;
-}
-
-MY_FLOAT *JetTabl :: tick(MY_FLOAT *vector, unsigned int vectorSize)
-{
- for (unsigned int i=0; i