Version 4.4.0

This commit is contained in:
Gary Scavone
2013-09-29 23:11:39 +02:00
committed by Stephen Sinclair
parent d199342e86
commit eccd8c9981
287 changed files with 11712 additions and 7676 deletions

View File

@@ -1,6 +1,6 @@
The Synthesis ToolKit in C++ (STK)
By Perry R. Cook and Gary P. Scavone, 1995-2007.
By Perry R. Cook and Gary P. Scavone, 1995-2009.
The Synthesis ToolKit in C++ can be used in a variety of ways, depending on your particular needs. Some people just choose the classes they need for a particular project and copy those to their project directory. Others like to compile and link to a library of object files. STK was not designed with one particular style of use in mind.

4
README
View File

@@ -1,6 +1,6 @@
The Synthesis ToolKit in C++ (STK)
By Perry R. Cook and Gary P. Scavone, 1995-2007.
By Perry R. Cook and Gary P. Scavone, 1995-2009.
This distribution of the Synthesis ToolKit in C++ (STK) contains the following:
@@ -146,7 +146,7 @@ LICENSE:
STK WWW site: http://ccrma.stanford.edu/software/stk/
The Synthesis ToolKit in C++ (STK)
Copyright (c) 1995-2007 Perry R. Cook and Gary P. Scavone
Copyright (c) 1995-2009 Perry R. Cook and Gary P. Scavone
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

189
bin/treesed Executable file
View File

@@ -0,0 +1,189 @@
#!/usr/bin/perl
# treesed
# Written January 1996 by Rick Jansen (rick@sara.nl)
# URL: http://www.sara.nl/rick
# usage: treesed pattern1 pattern2 -tree
# treesed pattern1 pattern2 -files file1 file2 ...
# example: treesed href HREF -files *.html
# Treesed searches for pattern1 and replaces pattern1 by pattern2
# if pattern2 supplied. If only pattern1 given treesed just searches.
# Treesed will search in all files and subdirectories of the current
# directory
#--------------------------------------------------------
# Parameters
$DoEdit=0;
$search_pattern = $ARGV[0];
$search_pattern =~ s/(\W)/\\$1/g; # escape regexp chars
shift;
while ($#ARGV >= 0) {
if ($ARGV[0] eq '-files') {
@temp_ls = @ARGV[1 .. $#ARGV];
# Get list of files, skip dirs
foreach $file (@ARGV[1 .. $#ARGV]) {
if (-f $file) {
push(@ls, $file);
}
}
last;
}
elsif ($ARGV[0] eq '-tree') {
&Get_LS;
last;
}
if (! -f $ARGV[0]) {
if (defined($replacement_pattern)) {
print "usage: treesed pattern1 <pattern2> -tree/-files <files>\n";
exit(1);
}
$replacement_pattern = $ARGV[0];
#$replacement_pattern =~ s/(\W)/\\$1/g; # escape regexp chars
$DoEdit=1;
shift;
}
}
# No files?
if ($#ls < 0) {
print "xx No input files\n";
exit(1);
}
print "search_pattern: $search_pattern\n";
print "replacement_pattern: $replacement_pattern\n";
if ($DoEdit) {
print "\n** EDIT MODE!\n\n"; }
else {
print "\n** Search mode\n\n";
}
#foreach $file (@ls) {
# print "$file \n";
#}
#--------------------------------------------------------
# Search list of files for pattern
$linepos=0;
$| = 1; # Force flush after every write
foreach $file (@ls) {
#print "$file\n";
print '.';
$linepos++;
if ($linepos > 50) {
$linepos=0;
print "\n";
}
if (!open(FILE, $file)) {
print "\nCould not open $file\n";
next;
}
$Found = 0;
$Count = 0;
$lineno = 0;
@lines = ();
while (<FILE>) {
$lineno++;
if (/$search_pattern/i) {
#print;
$Count++;
$Found = 1;
push(@lines, $lineno);
}
}
close(FILE);
if ($Found) {
print "\n$file: $Count lines on: @lines\n";
}
if ($Found && $DoEdit) { &Edit($file); }
}
$| = 0;
print "\n";
exit(0);
#--------------------------------------------------------
# Edit file
sub Edit {
# Replace $ARGV[0] with $ARGV[1] in $file
local($file) = @_;
local($bakfile) = $file.'.'.$$;
# First create backup
open(FILE, $file) || die "Could not open $file for read\n";
open(BAKFILE, ">$bakfile") || die "Could not open $bakfile for backup\n";
while (<FILE>) {
print BAKFILE;
}
close(BAKFILE);
close(FILE);
# Now replace $ARGV[0] by $ARGV[1] in the backupfile,
# result into $file
open(BAKFILE, $bakfile) || die "Could not open $bakfile for read\n";
open(FILE,">$file") || die "Could not open $file for write\n";
$Count=0;
while (<BAKFILE>) {
if (/$search_pattern/i) { $Count++; }
s/$search_pattern/$replacement_pattern/gi;
print FILE;
}
close(BAKFILE);
close(FILE);
print
"\nReplaced $search_pattern by $replacement_pattern on $Count lines in $file\n";
} #sub Edit
#--------------------------------------------------------
sub Get_LS {
# Get a list of full path names into array @ls
local(@localls)=`ls -R1`;
local($item,$Dir);
#print "localls: @localls\n";
$Dir='';
foreach $item (@localls) {
#print "$item\n";
if ($item =~ /:$/) {
$Dir=$item;
chop($Dir);
$Dir =~ s/:$/\//;
}
else {
chop($item);
$item = $Dir.$item;
if ($item !~ /^\s*$/) { push(@ls, $item); }
}
}
@localls=();
} # sub Get_LS

View File

View File

View File

@@ -1,5 +1,6 @@
# Process this file with autoconf to produce a configure script.
AC_INIT(STK, 4.3, gary@music.mcgill.ca, stk)
AC_INIT(STK, 4.4, gary@music.mcgill.ca, stk)
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_SRCDIR(src/Stk.cpp)
AC_CONFIG_FILES(src/Makefile projects/demo/Makefile projects/effects/Makefile projects/ragamatic/Makefile projects/examples/Makefile projects/examples/libMakefile)
@@ -7,9 +8,12 @@ AC_CONFIG_FILES(src/Makefile projects/demo/Makefile projects/effects/Makefile pr
AC_SUBST( GXX, ["no"] )
# Checks for programs.
AC_PROG_CC
AC_PROG_CXX(g++ CC c++ cxx)
AC_PROG_CXX
AC_PROG_RANLIB
AC_PATH_PROG(AR, ar, no)
if [[ $AR = "no" ]] ; then
AC_MSG_ERROR("Could not find ar - needed to create a library");
fi
# Checks for header files.
AC_HEADER_STDC
@@ -42,121 +46,115 @@ AC_MSG_RESULT($realtime)
# Check for math library
AC_CHECK_LIB(m, cos, , AC_MSG_ERROR(math library is needed!))
# Checks for functions
if test $realtime = yes; then
AC_CHECK_FUNCS(select socket)
AC_CHECK_FUNC(gettimeofday, [cflags=$cflags" -DHAVE_GETTIMEOFDAY"], )
fi
# Check for debug
AC_MSG_CHECKING(whether to compile debug version)
AC_ARG_ENABLE(debug,
[ --enable-debug = enable various debug output],
[AC_SUBST( debug, ["-D_STK_DEBUG_ -D__RTAUDIO_DEBUG__"] ) AC_SUBST( cflags, ["-g -O2"] ) AC_SUBST( object_path, [Debug] ) AC_MSG_RESULT(yes)],
[AC_SUBST( debug, [] ) AC_SUBST( cflags, [-O3] ) AC_SUBST( object_path, [Release] ) AC_MSG_RESULT(no)])
[AC_SUBST( cppflag, ["-D_STK_DEBUG_ -D__RTAUDIO_DEBUG__ -D__RTMIDI_DEBUG__"] ) AC_SUBST( cxxflag, ["-g"] ) AC_SUBST( object_path, [Debug] ) AC_MSG_RESULT(yes)],
[AC_SUBST( cppflag, [] ) AC_SUBST( cxxflag, [-O3] ) AC_SUBST( object_path, [Release] ) AC_MSG_RESULT(no)])
# Checks for functions
if test $realtime = yes; then
AC_CHECK_FUNCS(select socket)
AC_CHECK_FUNC(gettimeofday, [cppflag="$cppflag -DHAVE_GETTIMEOFDAY"], )
fi
# For -I and -D flags
CPPFLAGS="$CPPFLAGS $cppflag"
# For debugging and optimization ... overwrite default because it has both -g and -O2
CXXFLAGS="$cxxflag"
# Check compiler and use -Wall if gnu.
if test $GXX = "yes" ; then
AC_SUBST( warn, ["-Wall -g -D__GXX__"] )
if [test $GXX = "yes" ;] then
AC_SUBST( cxxflag, [-Wall] )
fi
CXXFLAGS="$CXXFLAGS $cxxflag"
if test $realtime = yes; then
# Checks for package options and external software
AC_CANONICAL_HOST
AC_MSG_CHECKING(for audio API)
case $host in
*-*-linux*)
AC_SUBST( sound_api, [_NO_API_] )
AC_ARG_WITH(jack, [ --with-jack = choose JACK server support (mac and linux only)], [
api="$api -D__UNIX_JACK__"
AC_MSG_RESULT(using JACK)
AC_CHECK_LIB(jack, jack_client_open, , AC_MSG_ERROR(JACK support requires the jack library!))
AC_CHECK_LIB(asound, snd_pcm_open, , AC_MSG_ERROR(Jack support also requires the asound library!))], )
# Look for ALSA flag
AC_ARG_WITH(alsa, [ --with-alsa = choose native ALSA API support (linux only)], [
api="$api -D__LINUX_ALSA__"
AC_MSG_RESULT(using ALSA)
AC_CHECK_LIB(asound, snd_pcm_open, , AC_MSG_ERROR(ALSA support requires the asound library!))], )
# Look for OSS flag
AC_ARG_WITH(oss, [ --with-oss = choose OSS API support (linux only)], [
api="$api -D__LINUX_OSS__"
AC_MSG_RESULT(using OSS)], )
# If no audio api flags specified, use ALSA
if [test "$api" == "";] then
AC_MSG_RESULT(using ALSA)
AC_SUBST( api, [-D__LINUX_ALSA__] )
AC_CHECK_LIB(asound, snd_pcm_open, , AC_MSG_ERROR(ALSA support requires the asound library!))
fi
# Look for ALSA library because we need it for RtMidi
AC_CHECK_LIB(asound, snd_pcm_open, , AC_MSG_ERROR(STK in Linux requires the ALSA asound library for RtMidi!))
audio_apis="-D__LINUX_ALSASEQ__"
# Look for Jack flag
AC_ARG_WITH(jack, [ --with-jack = choose JACK server support (linux only)], [AC_SUBST( sound_api, [-D__UNIX_JACK__] ) AC_MSG_RESULT(using JACK)] , )
if [test $sound_api = -D__UNIX_JACK__;] then
TEMP_LIBS=$LIBS
AC_CHECK_LIB(jack, jack_client_new, , AC_MSG_ERROR(JACK support requires the jack library!))
LIBS="`pkg-config --cflags --libs jack` $TEMP_LIBS -lasound"
audio_apis="-D__UNIX_JACK__ $audio_apis"
fi
# Look for Alsa flag
AC_ARG_WITH(alsa, [ --with-alsa = choose native ALSA API support (linux only)], [AC_SUBST( sound_api, [-D__LINUX_ALSA__] ) AC_MSG_RESULT(using ALSA)], )
if test $sound_api = -D__LINUX_ALSA__; then
audio_apis="-D__LINUX_ALSA__ $audio_apis"
fi
# Look for OSS flag
AC_ARG_WITH(oss, [ --with-oss = choose OSS API support (linux only)], [AC_SUBST( sound_api, [-D__LINUX_OSS__] ) AC_MSG_RESULT(using OSS)], )
if test $sound_api = -D__LINUX_OSS__; then
audio_apis="-D__LINUX_OSS__ $audio_apis"
fi
# If no audio api flags specified, use ALSA
if [test $sound_api = _NO_API_;] then
AC_MSG_RESULT(using ALSA)
audio_apis="-D__LINUX_ALSA__ $audio_apis"
fi
api="$api -D__LINUX_ALSASEQ__"
AC_CHECK_LIB(pthread, pthread_create, , AC_MSG_ERROR(realtime support requires the pthread library!))
;;
*-apple*)
AC_SUBST( sound_api, [_NO_API_] )
# Look for JACK flag
AC_ARG_WITH(jack, [ --with-jack = choose JACK server support (unix only)], [AC_SUBST( sound_api, [-D__UNIX_JACK__] ) AC_MSG_RESULT(using JACK)], )
if [test $sound_api = -D__UNIX_JACK__;] then
AC_CHECK_LIB(jack, jack_client_new, , AC_MSG_ERROR(JACK support requires the jack library!))
audio_apis="-D__UNIX_JACK__"
fi
AC_ARG_WITH(jack, [ --with-jack = choose JACK server support (unix only)], [
api="$api -D__UNIX_JACK__"
AC_MSG_RESULT(using JACK)
AC_CHECK_LIB(jack, jack_client_new, , AC_MSG_ERROR(JACK support requires the jack library!))], )
# Look for Core flag
AC_ARG_WITH(core, [ --with-core = choose CoreAudio API support (mac only)], [AC_SUBST( sound_api, [-D__MACOSX_CORE__] ) AC_MSG_RESULT(using CoreAudio)], )
if test $sound_api = -D__MACOSX_CORE__; then
AC_CHECK_HEADER(CoreAudio/CoreAudio.h, [], [AC_MSG_ERROR(CoreAudio header files not found!)] )
AC_SUBST( frameworks, ["-framework CoreAudio -framework CoreFoundation -framework CoreMidi"] )
audio_apis="-D__MACOSX_CORE__ $audio_apis"
fi
AC_ARG_WITH(core, [ --with-core = choose CoreAudio API support (mac only)], [
api="$api -D__MACOSX_CORE__"
AC_MSG_RESULT(using CoreAudio)
AC_CHECK_HEADER(CoreAudio/CoreAudio.h, [], [AC_MSG_ERROR(CoreAudio header files not found!)] )
LIBS="$LIBS -framework CoreAudio -framework CoreFoundation -framework CoreMidi" ], )
# If no audio api flags specified, use CoreAudio
if [test $sound_api = _NO_API_;] then
AC_SUBST( sound_api, [-D__MACOSX_CORE__] )
if [test "$api" == ""; ] then
AC_SUBST( api, [-D__MACOSX_CORE__] )
AC_MSG_RESULT(using CoreAudio)
AC_CHECK_HEADER(CoreAudio/CoreAudio.h,
[AC_SUBST( audio_apis, [-D__MACOSX_CORE__] )],
[AC_MSG_ERROR(CoreAudio header files not found!)] )
AC_SUBST( frameworks, ["-framework CoreAudio -framework CoreFoundation -framework CoreMidi"] )
[],
[AC_MSG_ERROR(CoreAudio header files not found!)] )
AC_SUBST( LIBS, ["-framework CoreAudio -framework CoreFoundation -framework CoreMidi"] )
fi
AC_CHECK_LIB(pthread, pthread_create, , AC_MSG_ERROR(realtime support requires the pthread library!))
AC_CHECK_LIB(pthread, pthread_create, , AC_MSG_ERROR(RtAudio requires the pthread library!))
;;
*-mingw32*)
AC_SUBST( sound_api, [_NO_API_] )
AC_ARG_WITH(asio, [ --with-asio = choose ASIO API support (windoze only)], [AC_SUBST( sound_api, [-D__WINDOWS_ASIO__] ) AC_MSG_RESULT(using ASIO)], )
if [test $sound_api = -D__WINDOWS_ASIO__;] then
audio_apis="-D__WINDOWS_ASIO__"
AC_SUBST( objects, ["asio.o asiodrivers.o asiolist.o iasiothiscallresolver.o"] )
fi
AC_ARG_WITH(asio, [ --with-asio = choose ASIO API support (windoze only)], [
api="$api -D__WINDOWS_ASIO__"
AC_MSG_RESULT(using ASIO)
AC_SUBST( objects, ["asio.o asiodrivers.o asiolist.o iasiothiscallresolver.o"] ) ], )
# Look for DirectSound flag
AC_ARG_WITH(ds, [ --with-ds = choose DirectSound API support (windoze only)], [AC_SUBST( sound_api, [-D__WINDOWS_DS__] ) AC_MSG_RESULT(using DirectSound)], )
if test $sound_api = -D__WINDOWS_DS__; then
audio_apis="-D__WINDOWS_DS__ $audio_apis"
LIBS="-ldsound $LIBS"
fi
AC_ARG_WITH(ds, [ --with-ds = choose DirectSound API support (windoze only)], [
api="$api -D__WINDOWS_DS__"
AC_MSG_RESULT(using DirectSound)
LIBS="-ldsound -lwinmm $LIBS" ], )
# If no audio api flags specified, use DirectSound
if [test $sound_api = _NO_API_;] then
AC_SUBST( sound_api, [-D__WINDOWS_DS__] )
if [test "$api" == "";] then
AC_SUBST( api, [-D__WINDOWS_DS__] )
AC_MSG_RESULT(using DirectSound)
audio_apis="-D__WINDOWS_DS__"
LIBS="-ldsound $LIBS"
LIBS="-ldsound -lwinmm $LIBS"
fi
audio_apis="-D__WINDOWS_MM__ $audio_apis"
api="$api -D__WINDOWS_MM__"
LIBS="-lole32 -lwinmm -lWsock32 $LIBS"
;;
@@ -165,10 +163,8 @@ if test $realtime = yes; then
AC_MSG_ERROR(Unknown system type for realtime support ... try --disable-realtime argument!)
;;
esac
CPPFLAGS="$CPPFLAGS $api"
fi
# Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_CHECK_FUNCS(strstr)
AC_OUTPUT

View File

@@ -1,6 +1,6 @@
The Synthesis ToolKit in C++ (STK)
By Perry R. Cook and Gary P. Scavone, 1995-2007.
By Perry R. Cook and Gary P. Scavone, 1995-2009.
Please read the file README and INSTALL for more general STK information.

View File

@@ -1,12 +1,12 @@
The Synthesis ToolKit in C++ (STK)
By Perry R. Cook and Gary P. Scavone, 1995-2007.
By Perry R. Cook and Gary P. Scavone, 1995-2009.
Please read the file README and INSTALL for more general STK information.
The default realtime support for Macintosh OS X uses the CoreAudio HAL API and is specified during compilation using the __MACOSX_CORE__ preprocessor definition. There is also support for the JACK low-latency audio server using the __UNIX_JACK__ preprocessor definition.
The default realtime support for Macintosh OS X uses the CoreAudio HAL API and is specified during compilation using the __MACOSX_CORE__ preprocessor definition. There is also support for the JACK audio server using the __UNIX_JACK__ preprocessor definition.
It is necessary to install the OS X developer kit in order to compile STK. STK was successfully tested on OS X versions 10.4.
It is necessary to install the OS X developer kit in order to compile STK. STK was successfully tested on OS X versions 10.5.
The internal Macintosh audio hardware typically supports a sample rate of 44100 Hz only. The default STK sample rate is now 44100 Hz and all current example programs use this rate. However, it is possible to manually override this value in some programs from the command-line. The default sample rate is set in Stk.h. In addition, the RT_BUFFER_SIZE, specified in Stk.h, could be increased (to a higher power of two) for more robust performance.

View File

@@ -1,6 +1,6 @@
The Synthesis ToolKit in C++ (STK)
By Perry R. Cook and Gary P. Scavone, 1995-2007.
By Perry R. Cook and Gary P. Scavone, 1995-2009.
Please read the file README and INSTALL for more general STK information.

View File

@@ -1,6 +1,6 @@
The Synthesis ToolKit in C++ (STK)
By Perry R. Cook and Gary P. Scavone, 1995-2007.
By Perry R. Cook and Gary P. Scavone, 1995-2009.
Please read the file README and INSTALL for more general STK information.

View File

@@ -1,6 +1,6 @@
The Synthesis ToolKit in C++ (STK)
By Perry R. Cook and Gary P. Scavone, 1995-2007.
By Perry R. Cook and Gary P. Scavone, 1995-2009.
Please read the file README for more general STK information.

View File

@@ -1,6 +1,20 @@
The Synthesis ToolKit in C++ (STK)
By Perry R. Cook and Gary P. Scavone, 1995-2007.
By Perry R. Cook and Gary P. Scavone, 1995-2009.
v4.4: (30 April 2009)
- all classes embedded in the "stk" namespace (except RtAudio, RtMidi, and RtError)
- class WaveLoop renamed FileLoop
- significant efficiency improvements via code restructuring and inlining
- some class source (.cpp) files deleted as part of inlining (Generator, Filter, Function, WvIn, WvOut, Effect, Instrmnt, BowTable, ReedTable, JetTable, Vector3D)
- updates to RtAudio and RtMidi
- previous "tickFrame()" functions renamed "tick" for more consistent API
- more consistent and scalable approach to multichannel data and computations
- multichannel support added to Granulate class
- Filter class made abstract. New Iir and Fir classes made for non-order-specific filtering.
- new TapDelay class
- SubNoise class deleted (same as sub-sampled "ticking" of Noise class)
v4.3.1: (7 December 2007)
- further headerless file support in FileRead
@@ -14,6 +28,7 @@ v4.3.0: (13 August 2007)
- an official MIT-like license
- new functionality to automatically update class data when the STK sample rate changes (partly implemented)
- updates for new RtAudio version 4.0
- removed RtDuplex class, users should use RtAudio directly with a callback function
- bug fix in interpolate() function in Stk.h for non-interleaved data
- fixes / improvements to the Granulate class
- fix in Whistle when doing animation

File diff suppressed because it is too large Load Diff

View File

@@ -56,7 +56,7 @@ STK compiles with realtime support on the following flavors of the Unix operatin
<TD>Macintosh OS X</TD>
<TD>CoreAudio</TD>
<TD>__MACOSX_CORE__</TD>
<TD><TT>pthread, CoreAudio, CoreMIDI, CoreFoundation</TT></TD>
<TD><TT>pthread, CoreAudio, CoreMidi, CoreFoundation</TT></TD>
</TR>
</TABLE>
</CENTER>
@@ -69,13 +69,11 @@ a particular program into a project directory. Taking the
would be necessary to set up a directory that includes the files
<TT>sineosc.cpp</TT>, the rawwave file <TT>sinewave.raw</TT> in a
subdirectory called <TT>rawwaves</TT>, and the header and source files
for the classes Stk, FileRead, FileWrite, WvIn, FileWvIn, WaveLoop,
WvOut, and FileWvOut. The program could then be compiled on a
little-endian system, such as a PC running Linux, using the GNU g++
compiler as follows:
\code
g++ -Wall -D__LITTLE_ENDIAN__ -o sineosc Stk.cpp FileRead.cpp FileWrite.cpp WvIn.cpp FileWvIn.cpp WaveLoop.cpp WvOut.cpp FileWvOut.cpp sineosc.cpp
\endcode
for the classes Stk, FileRead, FileWrite, FileWvIn, FileLoop, and
FileWvOut. The program could then be compiled on a little-endian
system, such as a PC running Linux, using the GNU g++ compiler as
follows:
\code g++ -Wall -D__LITTLE_ENDIAN__ -o sineosc Stk.cpp FileRead.cpp FileWrite.cpp FileWvIn.cpp FileLoop.cpp FileWvOut.cpp sineosc.cpp \endcode
Note that the <TT>sineosc.cpp</TT> example does not make use of realtime audio or MIDI input/output classes. For programs using any of the STK realtime classes mentioned above, it is necessary to specify an audio/MIDI API preprocessor definition and link with the appropriate libraries or frameworks.
@@ -95,7 +93,7 @@ g++ -Wall -D__LITTLE_ENDIAN__ -I/usr/include/stk -o sineosc sineosc.cpp -lstk
With the header files in a standard search path, it is possible to modify the <TT>\#include</TT> statements in the <TT>sineosc.cpp</TT> program as follows:
\code
#include "stk/WaveLoop.h"
#include "stk/FileLoop.h"
#include "stk/FileWvOut.h"
\endcode
@@ -117,7 +115,7 @@ includes the necessary ToolKit files from the distribution
<TT>src</TT> and <TT>include</TT> directories. For the example
program from the previous tutorial chapter, create a VC++ console
application project, add the Stk, FileRead, FileWrite, WvIn, FileWvIn,
WaveLoop, WvOut, and FileWvOut class files, as well as
FileLoop, WvOut, and FileWvOut class files, as well as
<TT>sineosc.cpp</TT>, and make sure the <TT>sinewave.raw</TT> file is
in the subdirectory <TT>rawwaves</TT>.

View File

@@ -19,9 +19,20 @@ NoteOff 1.000000 2 69.0 64.0
MIDI messages are easily represented within the SKINI protocol.
The class Messager can be used to acquire and parse MIDI messages from a MIDI device and SKINI messages from STDIN and socket connections. Incoming messages are acquired asynchronously and saved to an internal message queue of Skini::Message types (MIDI messages are converted to the Skini:Message format). The user then uses the Messager:popMessage() function to retrieve incoming control messages. This function does not block, instead returning a message type of zero when no more messages are in the queue. Many of the example programs included with the ToolKit distribution use a Messager instance to accept control input from the accompanying tcl/tk graphical user interfaces, from external MIDI devices, or from SKINI scorefiles.
The class stk::Messager can be used to acquire and parse MIDI messages
from a MIDI device and SKINI messages from STDIN and socket
connections. Incoming messages are acquired asynchronously and saved
to an internal message queue of stk::Skini::Message types (MIDI
messages are converted to the stk::Skini:Message format). The user
then uses the stk::Messager:popMessage() function to retrieve incoming
control messages. This function does not block, instead returning a
message type of zero when no more messages are in the queue. Many of
the example programs included with the ToolKit distribution use a
stk::Messager instance to accept control input from the accompanying tcl/tk
graphical user interfaces, from external MIDI devices, or from SKINI
scorefiles.
In the following example, we'll modify the <TT>bethree.cpp</TT> program from the previous tutorial chapter and incorporate a Messager class to allow control via SKINI messages read from a SKINI file.
In the following example, we'll modify the <TT>bethree.cpp</TT> program from the previous tutorial chapter and incorporate a stk::Messager class to allow control via SKINI messages read from a SKINI file.
\include controlbee.cpp
@@ -37,7 +48,7 @@ controlbee scores/bookert.ski
Only a few basic SKINI message type case statements are included in this example. It is easy to extend the program to support a much more elaborate set of instrument control parameters.
This example could also be easily extended to accept "realtime" control input messages via pipe, socket or MIDI connections. The Messager class provides Messager::startStdInput(), Messager::startSocketInput(), and Messager::startMidiInput() functions for this purpose.
This example could also be easily extended to accept "realtime" control input messages via pipe, socket or MIDI connections. The stk::Messager class provides stk::Messager::startStdInput(), stk::Messager::startSocketInput(), and stk::Messager::startMidiInput() functions for this purpose.
[<A HREF="tutorial.html">Main tutorial page</A>] &nbsp; [<A HREF="multichannel.html">Next tutorial</A>]
*/

View File

@@ -11,8 +11,8 @@ invoked automatically by the audio system controller (RtAudio) when
new data is needed and it is necessary to compute a full audio buffer
of samples at that time (see \ref callback for further information).
The previous section described the use of the RtWvOut class for
realtime audio output. The RtWvOut::tick() function writes data to a
The previous section described the use of the stk::RtWvOut class for
realtime audio output. The stk::RtWvOut::tick() function writes data to a
large ring-buffer, from which data is periodically written to the
computer's audio hardware via an underlying callback routine.

View File

@@ -1,16 +1,31 @@
/*! \page download Download, Release Notes, and Bug Fixes
\section down Download Version 4.3.1 (7 December 2007):
\section down Download Version 4.4.0 (30 April 2009):
<UL>
<LI><A HREF="http://ccrma.stanford.edu/software/stk/release/stk-4.3.1.tar.gz">Source distribution</A></LI>
<LI><A HREF="http://ccrma.stanford.edu/planetccrma/software/">Linux RPMs from Planet CCRMA</A></LI>
<LI><A HREF="http://ccrma.stanford.edu/software/stk/release/stk-4.4.0.tar.gz">Source distribution</A></LI>
</UL>
\section notes Release Notes:
\subsection v4dot3dot0 Version 4.3.1
\subsection v4dot4dot0 Version 4.4.0
<ul>
<li>All classes embedded in the "stk" namespace (except RtAudio, RtMidi, and RtError).</li>
<li>Class WaveLoop renamed FileLoop.</li>
<li>Significant efficiency improvements via code restructuring and inlining.</li>
<li>Some class source (.cpp) files deleted as part of inlining (Generator, Filter, Function, WvIn, WvOut, Effect, Instrmnt, BowTable, ReedTable, JetTable, Vector3D).</li>
<li>Updates to RtAudio and RtMidi.</li>
<li>Previous "tickFrame()" functions renamed "tick" for more consistent API.</li>
<li>More consistent and scalable approach to multichannel data and computations.</li>
<li>Multichannel support added to Granulate class.</li>
<li>Filter class made abstract. New Iir and Fir classes made for non-order-specific filtering.</li>
<li>New TapDelay class.</li>
<li>SubNoise class deleted (same as sub-sampled "ticking" of Noise class).</li>
</ul>
\subsection v4dot3dot1 Version 4.3.1
<ul>
<li>Further headerless file support in FileRead.</li>
@@ -20,13 +35,13 @@
<li>Changes to channel assignment in demo.cpp.</li>
</ul>
\subsection v4dot3dot0 Version 4.3.0
<ul>
<li>An official MIT-like license.</li>
<li>New functionality to automatically update class data when the STK sample rate changes (partly implemented).</li>
<li>Updates for new RtAudio version 4.0.</li>
<li>Removed RtDuplex class, users should use RtAudio directly with a callback function.</li>
<li>Bug fix in interpolate() function in Stk.h for non-interleaved data.</li>
<li>Fixes / improvements to the Granulate class.</li>
<li>Fix in Whistle when doing animation.</li>

View File

@@ -2,8 +2,6 @@
- \ref license
- \ref filerate
- \ref computesample
- \ref tickframe
- \ref endianness
- \ref xwindows
@@ -26,7 +24,7 @@ work with any standard C++ compiler.
STK WWW site: http://ccrma.stanford.edu/software/stk/
The Synthesis ToolKit in C++ (STK)
Copyright (c) 1995-2007 Perry R. Cook and Gary P. Scavone
Copyright (c) 1995-2009 Perry R. Cook and Gary P. Scavone
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -65,21 +63,13 @@ Stk::setSampleRate( sampleRate ); // set a new STK sample rate based o
With version 4.3 and higher of STK, the FileWvIn class will be notified of a sample rate change and it will automatically adjust its read rate accordingly. Previous versions of STK did not perform this change and thus, the read rate could end up being incorrect. If you do not want FileWvIn to perform this automatic adjustment, you can call the \c ignoreSampleRateChange() function for a given class instance.
\section tickframe What is the difference between the tick() and tickFrame() functions?
\e tickFrame() functions are provided in classes that can handle multi-channel data. A <i>sample frame</i> of audio data represents a single "slice" in time across many audio channels. The WvIn and WvOut subclasses are the primary classes in STK that currently implement the \e tickFrame() functions. \e tick() functions are used for monophonic classes. Note, however, that the WvIn and WvOut classes also implement \e tick() functions though their behavior is dependent on the number of channels you are working with. For example, if using the FileWvIn class with a monophonic soundfile, then there is no difference between the \e tick() and \e tickFrame() functions (aside from the format of their arguments). But if you have a multi-channel file open, then the single value returned from the tick() function is an average of all the samples in the multi-channel sample frame.
\section computesample Hey, why was the tick() function replaced by computeSample() in various STK classes?
C++ doesn't like overloaded virtual functions. All STK classes that implement a single-sample \e tick() function also provide an overloaded version that takes an StkFrames argument (for vectorized computations). Further, many STK classes inherit from abstract base classes (Instrmnt, Generator, ...) and it is most convenient to define functionality common to all subclasses (like the \e tick() function that takes an StkFrames argument) in only the base class. So, to get around the overloaded virtual function problem, STK now uses the \e computeSample() function as a non-overloaded virtual function that is implemented in all subclasses (it essentially replaces the \e tick() function). Note, however, that the overloaded \e tick() functions are still available to the user ... they are implemented in the base classes.
\section endianness Why does the sound I generated with STK sound like *&#@!?
If the resultant sound generated by an STK program sounds like noise (and you're not doing an MLS experiment), the problem is likely related to the byte "endianness" of your computer. By default, STK assumes "big endian" byte order. If you are working with STK classes on a PC (Windows or Linux), you \e must define the <TT>__LITTLE_ENDIAN__</TT> preprocessor definition \e before compiling. If after reading this you realize you need to make this change, do not forget to recompile all STK classes from scratch.
\section xwindows Why do I get a Tk display error message?
The following error will be printed to your terminal window if you attempt to start an STK tcl/tk interface without the X Server first running:
The following error may be printed to your terminal window (depending on the version of the tcl/tk interpreter you are running) if you attempt to start an STK tcl/tk interface without the X Server first running:
\code
Application initialization failed: this isn't a Tk applicationcouldn't connect to display ":0.0"

View File

@@ -1,9 +1,10 @@
/*! \page filtering Using Filters
In this section, we demonstrate the use of a few of the STK filter classes. The Filter class provides functionality to implement a generalized digital filter of any type, similar to the \c filter function in Matlab. In this example, we create a Filter instance and initialize it with specific numerator and denominator coefficients. We then compute its impulse response for 20 samples.
In this section, we demonstrate the use of a few of the STK filter classes. The stk::Iir class provides functionality to implement a generalized infinite impulse response (IIR) digital filter, similar to the \c filter function in Matlab. In this example, we create an stk::Iir instance and initialize it with specific numerator and denominator coefficients. We then compute its impulse response for 20 samples.
\code
#include "Filter.h"
#include "Iir.h"
using namespace stk;
int main()
{
@@ -16,7 +17,7 @@ int main()
denominator.push_back( 0.3 );
denominator.push_back( -0.5 );
Filter filter( numerator, denominator );
Iir filter( numerator, denominator );
filter.tick( output );
for ( unsigned int i=0; i<output.size(); i++ ) {
@@ -27,22 +28,23 @@ int main()
}
\endcode
The Filter class implements the standard difference equation
The stk::Iir class implements the standard difference equation
\code
a[0]*y[n] = b[0]*x[n] + ... + b[nb]*x[n-nb] - a[1]*y[n-1] - ... - a[na]*y[n-na],
\endcode
where "b" values are numerator coefficients and "a" values are denominator coefficients. Note that if the first denominator coefficient is not 1.0, the Filter class automatically normalizes all filter coefficients by that value. The coefficient values are passed to the Filter class via a C++ <a href="http://www.roguewave.com/support/docs/sourcepro/stdlibref/vector.html">vector</a>, a container object provided by the C++ Standard Library.
where "b" values are numerator coefficients and "a" values are denominator coefficients. Note that if the first denominator coefficient is not 1.0, the Iir class automatically normalizes all filter coefficients by that value. The coefficient values are passed to the Iir class via a C++ <a href="http://www.roguewave.com/support/docs/sourcepro/stdlibref/vector.html">vector</a>, a container object provided by the C++ Standard Library.
Most STK classes use more specific types of digital filters, such as the OneZero, OnePole, TwoPole, or BiQuad varieties. These classes inherit from the Filter class and provide specific functionality particular to their use, as well as functions to independently control individual coefficient values.
Most STK classes use more specific types of digital filters, such as the stk::OneZero, stk::OnePole, stk::TwoPole, or stk::BiQuad varieties. These classes inherit from the stk::Filter abstract base class and provide specific functionality particular to their use, as well as functions to independently control individual coefficient values.
\section reson Resonances:
The STK BiQuad and TwoPole classes provide functionality for creating resonance filters. The following example demonstrates how to create a resonance centered at 440 Hz that is used to filter the output of a Noise generator.
The STK stk::BiQuad and stk::TwoPole classes provide functionality for creating resonance filters. The following example demonstrates how to create a resonance centered at 440 Hz that is used to filter the output of a stk::Noise generator.
\code
#include "BiQuad.h"
#include "Noise.h"
using namespace stk;
int main()
{
@@ -61,11 +63,12 @@ int main()
}
\endcode
By passing a boolian value of \c true as the third argument to the BiQuad::setResonance() function, the filter coefficients are automatically scaled to achieve unity gain at the resonance peak frequency. The previous code could be easily modified for "vector-based" calculations:
By passing a boolian value of \c true as the third argument to the stk::BiQuad::setResonance() function, the filter coefficients are automatically scaled to achieve unity gain at the resonance peak frequency. The previous code could be easily modified for "vector-based" calculations:
\code
#include "BiQuad.h"
#include "Noise.h"
using namespace stk;
int main()
{

View File

@@ -2,7 +2,7 @@
<table>
<tr><td><A HREF="http://ccrma.stanford.edu/software/stk/"><I>The Synthesis ToolKit in C++ (STK)</I></A></td></tr>
<tr><td>&copy;1995-2007 Perry R. Cook and Gary P. Scavone. All Rights Reserved.</td></tr>
<tr><td>&copy;1995-2009 Perry R. Cook and Gary P. Scavone. All Rights Reserved.</td></tr>
</table>
</BODY>

View File

@@ -1,15 +1,16 @@
/*! \page fundamentals STK Fundamentals
The Synthesis ToolKit is implemented in the C++ programming language. STK does not attempt to provide a new programming environment or paradigm but rather provides a set of objects that can be used within a normal C++ programming framework. Therefore, it is expected that users of STK will have some familiarity with C/C++ programming concepts. That said, the STK classes do have some particular idiosyncrasies that we will mention here.
The Synthesis ToolKit is implemented in the C++ programming language. STK does not attempt to provide a new programming environment or paradigm but rather provides a set of objects that can be used within a normal C++ programming framework. Therefore, it is expected that users of STK will have some familiarity with C/C++ programming concepts. That said, the STK classes do have some particular idiosyncrasies that we will mention here. Starting with STK version 4.4, all STK classes except RtAudio, RtMidi, and RtError are defined within the stk namespace.
\section Signal Computations:
Audio and control signals throughout STK use a floating-point data type, <tt>StkFloat</tt>, the exact precision of which can be controlled via a typedef statement in Stk.h. By default, an StkFloat is a double-precision floating-point value. Thus, the ToolKit can use any normalization scheme desired. The base instruments and algorithms are implemented with a general audio sample dynamic maximum of +/-1.0.
In general, the computation and/or passing of values is performed on a "single-sample" basis. For example, the Noise class outputs random floating-point numbers in the range +/-1.0. The computation of such values occurs in the Noise::tick() function. The following program will generate 20 random floating-point (<tt>StkFloat</tt>) values in the range -1.0 to +1.0:
In general, the computation and/or passing of values is performed on a "single-sample" basis. For example, the stk::Noise class outputs random floating-point numbers in the range +/-1.0. The computation of such values occurs in the stk::Noise::tick() function. The following program will generate 20 random floating-point (<tt>StkFloat</tt>) values in the range -1.0 to +1.0:
\code
#include "Noise.h"
using namespace stk;
int main()
{
@@ -29,6 +30,7 @@ Nearly all STK classes implement <TT>tick()</TT> functions that take and/or retu
\code
#include "Noise.h"
using namespace stk;
int main()
{
@@ -44,19 +46,19 @@ int main()
}
\endcode
In this way, it might be possible to achieve improved processing efficiency using vectorized computations. The StkFrames class is a relatively new addition to the ToolKit to provide a general "mechanism" for handling and passing vectorized, multi-channel audio data. The StkFrames "type" provides functions to set and/or determine the number of audio channels and sample frames it holds, as well as the format (interleaved or non-interleaved) of its data. Further, the StkFrames class provides data interpolation and subscripting functionality by frame/channel values.
In this way, it might be possible to achieve improved processing efficiency using vectorized computations. The StkFrames class is a relatively new addition to the ToolKit to provide a general "mechanism" for handling and passing vectorized, multi-channel audio data. The StkFrames "type" provides functions to set and/or determine the number of audio channels and sample frames it holds. Further, the StkFrames class provides data interpolation and subscripting functionality by frame/channel values.
\section STK Inheritance:
Nearly all STK classes inherit from the Stk abstract base class, which provides common functionality related to error reporting, sample rate control, and byte swapping. Several other base classes exist that roughly group many of the classes according to function as follows:
- Generator: source signal unit generator classes [Envelope, ADSR, Asymp, Noise, SubNoise, Modulate, SingWave, SineWave Blit, BlitSaw, BlitSquare, Granulate]
- Filter: digital filtering classes [OneZero, OnePole, PoleZero, TwoZero, TwoPole, BiQuad, FormSwep, Delay, DelayL, DelayA]
- Function: input to output function mappings [BowTable, JetTable, ReedTable]
- Instrmnt: sound synthesis algorithms, including physical, FM, modal, and particle models
- Effect: sound processing effect classes [Echo, Chorus, PitShift, PRCRev, JCRev, NRev]
- WvOut: audio data output classes [FileWvOut, RtWvOut, InetWvOut]
- WvIn: audio data input classes [FileWvIn, WaveLoop, RtWvIn, InetWvIn]
- stk::Generator: source signal unit generator classes [stk::Envelope, stk::ADSR, stk::Asymp, stk::Noise, stk::SubNoise, stk::Modulate, stk::SingWave, stk::SineWave, stk::Blit, stk::BlitSaw, stk::BlitSquare, stk::Granulate]
- stk::Filter: digital filtering classes [stk::OneZero, stk::OnePole, stk::PoleZero, stk::TwoZero, stk::TwoPole, stk::BiQuad, stk::FormSwep, stk::Delay, stk::DelayL, stk::DelayA, stk::TapDelay]
- stk::Function: input to output function mappings [stk::BowTable, stk::JetTable, stk::ReedTable]
- stk::Instrmnt: sound synthesis algorithms, including physical, FM, modal, and particle models
- stk::Effect: sound processing effect classes [stk::Echo, stk::Chorus, stk::PitShift, stk::PRCRev, stk::JCRev, stk::NRev]
- stk::WvOut: audio data output classes [stk::FileWvOut, stk::RtWvOut, stk::InetWvOut]
- stk::WvIn: audio data input classes [stk::FileWvIn, stk::FileLoop, stk::RtWvIn, stk::InetWvIn]
[<A HREF="tutorial.html">Main tutorial page</A>] &nbsp; [<A HREF="hello.html">Next tutorial</A>]

View File

@@ -3,24 +3,25 @@
We'll continue our introduction to the Synthesis ToolKit with a simple
sine-wave oscillator program. STK provides two different classes for
sine-wave generation. We will first look at a generic waveform
oscillator class, WaveLoop, that can load a variety of common file
oscillator class, stk::FileLoop, that can load a variety of common file
types. In this example, we load a sine "table" from an STK RAW file
(defined as monophonic, 16-bit, big-endian data). We use the class
FileWvOut to write the result to a 16-bit, WAV formatted audio file.
stk::FileWvOut to write the result to a 16-bit, WAV formatted audio file.
\code
// sineosc.cpp
#include "WaveLoop.h"
#include "FileLoop.h"
#include "FileWvOut.h"
using namespace stk;
int main()
{
// Set the global sample rate before creating class instances.
Stk::setSampleRate( 44100.0 );
WaveLoop input;
FileLoop input;
FileWvOut output;
// Load the sine wave file.
@@ -39,29 +40,37 @@ int main()
}
\endcode
WaveLoop is a subclass of FileWvIn, which supports WAV, SND (AU),
AIFF, MAT-file (Matlab), and RAW file formats with 8-, 16-, and 32-bit
integer and 32- and 64-bit floating-point data types. FileWvIn
provides interpolating, read-once ("oneshot") functionality, as well
as methods for setting the read rate and read position.
stk::FileLoop is a subclass of stk::FileWvIn, which supports WAV, SND
(AU), AIFF, MAT-file (Matlab), and RAW file formats with 8-, 16-, and
32-bit integer and 32- and 64-bit floating-point data types.
stk::FileWvIn provides interpolating, read-once ("oneshot")
functionality, as well as methods for setting the read rate and read
position.
FileWvIn provides a "tick level" and interpolating interface to the
FileRead class. Likewise, FileWvOut provides a "tick level" interface
to the FileWrite class. FileRead and FileWrite both support WAV,
SND(AU), AIFF, MAT-file (Matlab), and RAW file formats with 8-, 16-,
and 32-bit integer and 32- and 64-bit floating-point data types.
FileWvOut does not currently offer data interpolation functionality.
stk::FileWvIn provides a "tick level" and interpolating interface to
the stk::FileRead class. Likewise, stk::FileWvOut provides a "tick
level" interface to the stk::FileWrite class. stk::FileRead and
FileWrite both support WAV, SND(AU), AIFF, MAT-file (Matlab), and RAW
file formats with 8-, 16-, and 32-bit integer and 32- and 64-bit
floating-point data types. stk::FileWvOut does not currently offer
data interpolation functionality.
The WvIn and WvOut parent classes and all subclasses support
multi-channel sample frames. To distinguish single-sample frame
operations from multi-channel frame operations, these classes also
implement <TT>tickFrame()</TT> functions. When a <TT>tick()</TT>
method is called for multi-channel data, frame averages are returned
or the input sample is distributed across all channels of a sample
frame.
A number of STK parent classes, including stk::WvIn, stk::WvOut,
stk::Instrmnt, stk::Generator, and stk::Effect, (and some or all of
their subclasses) support multi-channel sample frames. If a
single-sample version of the <TT>tick()</TT> function is called for
these classes, a full sample frame is computed but only a single value
is either input and/or output. For example, if the single-sample
<TT>tick()</TT> function is called for subclasses of stk::WvOut, the
sample argument is written to all channels in the one computed frame.
For classes returning values, an optional \c channel argument
specifies which channel value is returned from the computed frame (the
default is always channel 0). To input and/or output multichannel data
to these classes, the overloaded <TT>tick()</TT> functions taking
StkFrames reference arguments should be used.
Nearly all STK classes inherit from the Stk base class. Stk provides
a static sample rate that is queried by subclasses as needed.
Nearly all STK classes inherit from the stk::Stk base class. Stk
provides a static sample rate that is queried by subclasses as needed.
Because many classes use the current sample rate value during
instantiation, it is important that the desired value be set at the
beginning of a program. The default STK sample rate is 44100 Hz.
@@ -75,7 +84,11 @@ rewritten as shown below.
\include sineosc.cpp
In this particular case, we simply exit the program if an error occurs (an error message is automatically printed to stderr). A more refined program might attempt to recover from or fix a particular problem and, if successful, continue processing. See the \ref classes to determine which constructors and functions can throw an error.
In this particular case, we simply exit the program if an error occurs
(an error message is automatically printed to stderr). A more refined
program might attempt to recover from or fix a particular problem and,
if successful, continue processing. See the \ref classes to determine
which constructors and functions can throw an error.
[<A HREF="fundamentals.html">Main tutorial page</A>] &nbsp; [<A HREF="compile.html">Next tutorial</A>]
*/

View File

@@ -1,4 +1,4 @@
/*! \mainpage <I>The Synthesis ToolKit in C++ (STK)</I>
/*! \mainpage The Synthesis ToolKit in C++ (STK)
\htmlonly
<BODY BGCOLOR="white">
@@ -15,7 +15,7 @@ portable (it's mostly platform-independent C and C++ code), and it's
completely user-extensible (all source included, no unusual libraries,
and no hidden drivers). We like to think that this increases the
chances that our programs will still work in another 5-10 years. In
fact, the ToolKit has been working continuously for about 10 years
fact, the ToolKit has been working continuously for nearly 15 years
now. STK currently runs with realtime support (audio and MIDI) on
Linux, Macintosh OS X, and Windows computer platforms. Generic,
non-realtime support has been tested under NeXTStep, Sun, and other

View File

@@ -18,9 +18,9 @@ Here's a link to a book that includes an chapter on STK.
<H4>What is the <I>Synthesis ToolKit</I>?</H4>
The Synthesis ToolKit in C++ (STK) is a set of open source audio signal processing and algorithmic synthesis classes written in the C++ programming language. STK was designed to facilitate rapid development of music synthesis and audio processing software, with an emphasis on cross-platform functionality, realtime control, ease of use, and educational example code. The Synthesis ToolKit is extremely portable (it's mostly platform-independent C and C++ code), and it's completely user-extensible (all source included, no unusual libraries, and no hidden drivers). We like to think that this increases the chances that our programs will still work in another 5-10 years. In fact, the ToolKit has been working continuously for nearly 10 years now. STK currently runs with realtime support (audio and MIDI) on Linux, Macintosh OS X, and Windows computer platforms. Generic, non-realtime support has been tested under NeXTStep, Sun, and other platforms and should work with any standard C++ compiler.
The Synthesis ToolKit in C++ (STK) is a set of open source audio signal processing and algorithmic synthesis classes written in the C++ programming language. STK was designed to facilitate rapid development of music synthesis and audio processing software, with an emphasis on cross-platform functionality, realtime control, ease of use, and educational example code. The Synthesis ToolKit is extremely portable (it's mostly platform-independent C and C++ code), and it's completely user-extensible (all source included, no unusual libraries, and no hidden drivers). We like to think that this increases the chances that our programs will still work in another 5-10 years. In fact, the ToolKit has been working continuously for nearly 15 years now. STK currently runs with realtime support (audio and MIDI) on Linux, Macintosh OS X, and Windows computer platforms. Generic, non-realtime support has been tested under NeXTStep, Sun, and other platforms and should work with any standard C++ compiler.
The Synthesis ToolKit is free for non-commercial use. The only parts of the Synthesis ToolKit that are platform-dependent concern real-time audio and MIDI input and output, and that is taken care of with a few special classes. The interface for MIDI input and the simple <A HREF="http://dev.scriptics.com">Tcl/Tk</A> graphical user interfaces (GUIs) provided is the same, so it's easy to experiment in real time using either the GUIs or MIDI. The Synthesis ToolKit can generate simultaneous SND (AU), WAV, AIFF, and MAT-file output soundfile formats (as well as realtime sound output), so you can view your results using one of a large variety of sound/signal analysis tools already available (e.g. <A HREF="http://www-ccrma.stanford.edu/software/snd/">Snd</A>, Cool Edit, Matlab).
The Synthesis ToolKit is free. The only parts of the Synthesis ToolKit that are platform-dependent concern real-time audio and MIDI input and output, and that is taken care of with a few special classes. The interface for MIDI input and the simple <A HREF="http://dev.scriptics.com">Tcl/Tk</A> graphical user interfaces (GUIs) provided is the same, so it's easy to experiment in real time using either the GUIs or MIDI. The Synthesis ToolKit can generate simultaneous SND (AU), WAV, AIFF, and MAT-file output soundfile formats (as well as realtime sound output), so you can view your results using one of a large variety of sound/signal analysis tools already available (e.g. <A HREF="http://www-ccrma.stanford.edu/software/snd/">Snd</A>, Cool Edit, Matlab).
<H4>What the <I>Synthesis ToolKit</I> is not.</H4>

View File

@@ -1,6 +1,6 @@
/*! \page instruments Instruments
The ToolKit comes with a wide variety of synthesis algorithms, all of which inherit from the Instrmnt class. In this example, we'll fire up an instance of the BeeThree FM synthesis class and show how its frequency can be modified over time.
The ToolKit comes with a wide variety of synthesis algorithms, all of which inherit from the stk::Instrmnt class. In this example, we'll fire up an instance of the stk::BeeThree FM synthesis class and show how its frequency can be modified over time.
\include bethree.cpp
@@ -10,7 +10,7 @@ with any other STK instrument class. It should be noted, however,
that a few classes do not respond to the setFrequency() function
(e.g., Shakers, Drummer).
The noteOn() function initiates an instrument attack. Instruments that are continuously excited (e.g., Clarinet, BeeThree) will continue to sound until stopped with a noteOff(). Impulsively excited instrument sounds (e.g., Plucked, Wurley) typically decay within a few seconds time, requiring subsequent noteOn() messages for re-attack.
The noteOn() function initiates an instrument attack. Instruments that are continuously excited (e.g., stk::Clarinet, stk::BeeThree) will continue to sound until stopped with a noteOff(). Impulsively excited instrument sounds (e.g., stk::Plucked, stk::Wurley) typically decay within a few seconds time, requiring subsequent noteOn() messages for re-attack.
Instrument parameters can be precisely controlled as demonstrated above. A more flexible approach to instrument control, allowing arbitrary scorefile or realtime updates, is described in the next tutorial chapter.

View File

@@ -1,8 +1,8 @@
/*! \page links Miscellaneous Links
- <A HREF="http://music.mcgill.ca/~gary/rtaudio/">The %RtAudio WWW site</A>
- <A HREF="http://www.music.mcgill.ca/~gary/rtaudio/">The %RtAudio WWW site</A>
- <A HREF="http://music.mcgill.ca/~gary/rtmidi/">The %RtMidi WWW site</A>
- <A HREF="http://www.music.mcgill.ca/~gary/rtmidi/">The %RtMidi WWW site</A>
- <A HREF="http://ccrma.stanford.edu/~woony/software/stkx/">StkX: A Cocoa STK Framework for Mac OS X by Woon Seung Yeo</A>

View File

@@ -1,22 +1,25 @@
/*! \page multichannel Multi-Channel I/O
The ToolKit WvIn and WvOut classes (and their subclasses) support multi-channel audio data input and output. A set of interleaved audio samples representing a single time "slice" is referred to as a <I>sample frame</I>. At a sample rate of 44.1 kHz, a four-channel audio stream will have 44100 sample frames per second and a total of 176400 individual samples per second.
The ToolKit stk::WvIn and stk::WvOut classes (and their subclasses) support multi-channel audio data input and output. Several other abstract base classes, such as stk::Instrmnt, stk::Generator, and stk::Effect, also support multi-channel computations though not all of their subclasses produce or take multi-channel data. A set of interleaved audio samples representing a single time "slice" is referred to as a <I>sample frame</I>. At a sample rate of 44.1 kHz, a four-channel audio stream will have 44100 sample frames per second and a total of 176400 individual samples per second.
Most STK classes process single-sample data streams via their
<TT>tick()</TT> function. In order to distinguish single-sample and
sample frame calculations, the WvIn and WvOut classes implement both
<TT>tick()</TT> and <TT>tickFrame()</TT> functions. The
<TT>tickFrame()</TT> functions take or return a reference to an StkFrames object
representing one or more sample frames. For single-channel
streams, the <TT>tick()</TT> and <TT>tickFrame()</TT> functions
produce equivalent results. When <TT>tick()</TT> is called for a
multi-channel stream, however, the function either returns a sample
frame average (WvIn) or writes a single sample argument to all
channels (WvOut).
<TT>tick()</TT> function. For classes supporting multi-channel data,
one must distinguish the <TT>tick()</TT> functions taking or producing
single \c StkFloat arguments from those taking stk::StkFrames& arguments. If
a single-sample version of the <TT>tick()</TT> function is called for
these classes, a full sample frame is computed but only a single value
is either input and/or output. For example, if the single-sample
<TT>tick()</TT> function is called for subclasses of WvOut, the sample
argument is written to all channels in the one computed frame. For
classes returning values, an optional \c channel argument specifies
which channel value is returned from the computed frame (the default
is always channel 0). To input and/or output multichannel data to
these classes, the overloaded <TT>tick()</TT> functions taking
StkFrames reference arguments should be used.
Multi-channel support for realtime audio input and output is dependent on the audio device(s) available on your system.
The following example demonstrates the use of the FileWvOut class for
The following example demonstrates the use of the stk::FileWvOut class for
creating a four channel, 16-bit AIFF formatted audio file. We will
use four sinewaves of different frequencies for the first two seconds
and then a single sinewave for the last two seconds.

View File

@@ -1,10 +1,10 @@
/*! \page polyvoices Voice Management
The previous tutorial chapters were concerned only with monophonic ToolKit instrument playback and control. At this point, it should be relatively clear that one can instantiate multiple instruments and perhaps sum together their outputs or even direct their outputs to separate channels. It is less clear how one might go about controlling a group of instruments. The Voicer class is designed to serve just this purpose.
The previous tutorial chapters were concerned only with monophonic ToolKit instrument playback and control. At this point, it should be relatively clear that one can instantiate multiple instruments and perhaps sum together their outputs or even direct their outputs to separate channels. It is less clear how one might go about controlling a group of instruments. The stk::Voicer class is designed to serve just this purpose.
The STK Voicer class is a relatively simple voice manager. The user can dynamically add and delete instruments to/from its "control", with the option of controlling specific instruments via unique note tags and/or grouping sets of instruments via a "channel" number. All sounding instrument outputs are summed and returned via the <TT>tick()</TT> function. The Voicer class responds to noteOn, noteOff, setFrequency, pitchBend, and controlChange messages, automatically assigning incoming messages to the voices in its control. When all voices are sounding and a new noteOn is encountered, the Voicer interrupts the oldest sounding voice. The user is responsible for creating and deleting all instrument instances.
The stk::Voicer class is a relatively simple voice manager. The user can dynamically add and delete instruments to/from its "control", with the option of controlling specific instruments via unique note tags and/or grouping sets of instruments via a "group" number. All sounding instrument outputs are summed and returned via the <TT>tick()</TT> function. The stk::Voicer class responds to noteOn, noteOff, setFrequency, pitchBend, and controlChange messages, automatically assigning incoming messages to the voices in its control. When all voices are sounding and a new noteOn is encountered, the stk::Voicer interrupts the oldest sounding voice. The user is responsible for creating and deleting all instrument instances.
In the following example, we modify the <TT>controlbee.cpp</TT> program to make use of three BeeThree instruments, all controlled using a Voicer.
In the following example, we modify the <TT>controlbee.cpp</TT> program to make use of three stk::BeeThree instruments, all controlled using a stk::Voicer.
\include threebees.cpp
@@ -16,7 +16,7 @@ threebees < scores/bachfugue.ski
For more fun, surf to <A HREF="http://kern.humdrum.net/">Kern Scores</A> for a huge assortment of other scorefiles that can be downloaded in the SKINI format.
Another easy extension would be to add the \c Messager::startMidiInput() function to the program and then play the instruments via a MIDI keyboard.
Another easy extension would be to add the \c stk::Messager::startMidiInput() function to the program and then play the instruments via a MIDI keyboard.
[<A HREF="tutorial.html">Main tutorial page</A>]
*/

View File

@@ -2,36 +2,36 @@
In this section, we modify the <TT>sineosc.cpp</TT> program in order
to send the output to the default audio playback device on your
computer system. We also make use of the SineWave class as a
sine-wave oscillator. SineWave computes an internal, static sine-wave
computer system. We also make use of the stk::SineWave class as a
sine-wave oscillator. stk::SineWave computes an internal, static sine-wave
table when its first instance is created. Subsequent instances make
use of the same table. The default table length, specified in
SineWave.h, is 2048 samples.
\include rtsine.cpp
The class RtWvOut is a protected subclass of WvOut. A number of
The class stk::RtWvOut is a protected subclass of stk::WvOut. A number of
optional constructor arguments can be used to fine tune its
performance for a given system. RtWvOut provides a "single-sample",
blocking interface to the RtAudio class. Note that RtWvOut (as well
as the RtWvIn class described below) makes use of RtAudio's callback
performance for a given system. stk::RtWvOut provides a "single-sample",
blocking interface to the RtAudio class. Note that stk::RtWvOut (as well
as the stk::RtWvIn class described below) makes use of RtAudio's callback
input/output functionality by creating a large ring-buffer into which
data is written. These classes should not be used when low-latency
and robust performance is necessary
Though not used here, an RtWvIn class exists as well that can be used
Though not used here, an stk::RtWvIn class exists as well that can be used
to read realtime audio data from an input device. See the
<TT>record.cpp</TT> example program in the <TT>examples</TT> project
for more information.
It may be possible to use an instance of RtWvOut and an instance of
RtWvIn to simultaneously read and write realtime audio to and from a
It may be possible to use an instance of stk::RtWvOut and an instance of
stk::RtWvIn to simultaneously read and write realtime audio to and from a
hardware device or devices. However, it is recommended to instead use
a single instance of RtAudio to achieve this behavior, as described in the next section.
See the <TT>effects</TT> project or the <TT>duplex.cpp</TT> example
program in the <TT>examples</TT> project for more information.
When using any realtime STK class (RtAudio, RtWvOut, RtWvIn, RtDuplex, RtMidi, InetWvIn, InetWvOut, Socket, UdpSocket, TcpServer, TcpClient, and Thread), it is necessary to specify an audio/MIDI API preprocessor definition and link with the appropriate libraries or frameworks. For example, the above program could be compiled on a Linux system using the GNU g++ compiler and the ALSA audio API as follows (assuming all necessary files exist in the project directory):
When using any realtime STK class (RtAudio, stk::RtWvOut, stk::RtWvIn, RtMidi, stk::InetWvIn, stk::InetWvOut, stk::Socket, stk::UdpSocket, stk::TcpServer, stk::TcpClient, and stk::Thread), it is necessary to specify an audio/MIDI API preprocessor definition and link with the appropriate libraries or frameworks. For example, the above program could be compiled on a Linux system using the GNU g++ compiler and the ALSA audio API as follows (assuming all necessary files exist in the project directory):
\code
g++ -Wall -D__LINUX_ALSA__ -D__LITTLE_ENDIAN__ -o rtsine Stk.cpp Generator.cpp SineWave.cpp WvOut.cpp \

View File

@@ -15,10 +15,9 @@
<B>Macintosh OS X (specific):</B>
<UL>
<LI>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.</LI>
<LI><B>IMPORTANT:</B>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 that 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.</LI>
<LI>A C++ compiler is not installed 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.</LI>
<LI>If you experience frequent audio input/output "glitches", try increasing the RT_BUFFER_SIZE specified in Stk.h.</LI>
<LI>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.
<LI>The tcl/tk interpreter does not ship by default with OS X and 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.
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.</LI>
@@ -32,11 +31,6 @@ It appears that socket support in Tcl/Tk uses the Nagle algorithm, which produce
<LI>For compiling the source (if not already in your system): <UL><LI><A HREF="Misc/dsound.h">dsound.h</A> header file (DirectX 6.1) - put somewhere in your header search path</LI><LI><A HREF="Misc/dsound.lib">dsound.lib</A> library file (DirectX 6.1) - put somewhere in your library search path</LI></UL></LI>
</UL>
<B>WindowsNT (specific):</B>
<UL>
<LI>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.</LI>
</UL>
<P>
*/

View File

@@ -45,8 +45,6 @@ This release of STK comes with four separate "project" directories:
<UL>
<LI><B>Windows95/98/2000/XP:</B> Realtime support is available using either DirectSound or ASIO audio drivers. For DirectSound support, use the <TT>__WINDOWS_DS__</TT> preprocessor definition and link with the <TT>dsound.lib</TT>, <TT>winmm.lib</TT>, and <TT>Wsock32.lib</TT> libraries. For ASIO support, use the <TT>__WINDOWS_ASIO__</TT> preprocessor definition, include all the files in the <TT>src/asio/</TT> directory (i.e. <TT>asio.h,cpp</TT>, <TT>asiodrivers.h,cpp</TT>, ...), and link with the <TT>winmm.lib</TT>, and <TT>Wsock32.lib</TT> libraries. In addition, the <TT>__LITTLE_ENDIAN__</TT> and <TT>__WINDOWS_MM__</TT> 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 <A HREF="http://www.microsoft.com/directx/">Microsoft</A>). Further, the <I><B>effects</B></I> project requires that your soundcard and drivers provide full duplex mode capabilities. Visual C++ .NET 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.</LI>
<LI><B>WindowsNT:</B> 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.</LI>
<LI><B>Unix Systems:</B> A GNU <TT>configure</TT> shell script is included in the distribution for unix-based systems. From the top-level distribution directory, type <TT>'./configure'</TT> and the script will create <TT>Makefiles</TT> in each project directory specific to the characteristics of the host computer. Then from within any given project directory (example <TT>demo</TT>), type <TT>'make'</TT> to compile the project. In addition, an STK library can be compiled from within the <TT>src</TT> directory.
Several options can be supplied to the <TT>configure</TT> script to customize the build behavior:

View File

@@ -5,10 +5,7 @@ By Perry R. Cook and Gary P. Scavone, 1995-2007.
STK Classes - See the HTML documentation in the html directory for complete information.
.- Generator - (Modulate, Noise, SingWave, Envelope, SineWave, Blit, BlitSaw, BlitSquare, Granulate)
| | |
| SubNoise ADSR
| Asymp
.- Generator - (Modulate, Noise, SingWave, Envelope, ADSR, Asymp, SineWave, Blit, BlitSaw, BlitSquare, Granulate)
|
|- Function - (BowTable, JetTable, ReedTable)
|
@@ -16,14 +13,11 @@ STK Classes - See the HTML documentation in the html directory for complete info
|
|- WvIn - (FileWvIn, RtWvIn, InetWvIn)
| |
| WaveLoop
| FileLoop
|
|- WvOut - (FileWvOut, RtWvOut, TcpWvOut)
|
|- Filter - (OnePole, OneZero, Delay, TwoPole, TwoZero, PoleZero, Biquad)
| | |
| DelayL FormSwep
| DelayA
|- Filter - (OnePole, OneZero, TwoPole, TwoZero, PoleZero, Biquad, FormSwep, Delay, DelayL, DelayA, TapDelay)
|
|- RtAudio, RtMidi, RtDuplex, Socket, Thread, Mutex
| |
@@ -68,34 +62,35 @@ Stk -| UdpSocket
Master Class: Stk.cpp Sample rate, byte-swapping, error handling functionality
Sources: Generator.cpp Abstract base class for various source signal classes
Function.cpp Abstract base class for various input/output mapping classes
Sources: Generator.h Abstract base class for various source signal classes
Function.h Abstract base class for various input/output mapping classes
Envelope.cpp Linearly goes to target by rate
ADSR.cpp ADSR flavor of Envelope
ADSR.cpp ADSR envelope
Asymp.cpp Exponentially approaches target
Noise.cpp Random number generator
SubNoise.cpp Random numbers each N samples
SineWave.cpp Sinusoidal oscillator with internally computed static table
Blit.cpp Bandlimited impulse train
BlitSaw.cpp Bandlimited sawtooth generator
BlitSquare.cpp Bandlimited square wave generator
Granulate.cpp Granular synthesis class that processes a monophonic audio file
FileRead.cpp Audio file input class (no internal data storage) for RAW, WAV, SND (AU), AIFF, MAT-file files
WvIn.cpp Abstract base class for audio data input classes
WvIn.h Abstract base class for audio data input classes
FileWvIn.cpp Audio file input interface class with interpolation
WaveLoop.cpp Wavetable looping (subclass of FileWvIn)
FileLoop.cpp Wavetable looping (subclass of FileWvIn)
RtWvIn.cpp Realtime audio input class (subclass of WvIn)
InetWvIn.cpp Audio streaming (socket server) input class (subclass of WvIn)
Sinks: FileWrite.cpp Audio file output class (no internal data storage) for RAW, WAV, SND (AU), AIFF, MAT-file files
WvOut.cpp Abstract base class for audio data output classes
WvOut.h Abstract base class for audio data output classes
FileWvOut.cpp Audio file output interface class to FileWrite
RtWvOut.cpp Realtime audio output class (subclass of WvOut)
InetWvOut.cpp Audio streaming (socket client) output class (subclass of WvOut)
Duplex: RtDuplex.cpp Synchronous realtime audio input/output class (blocking)
Filters: Filter.cpp Filter master class
Filters: Filter.h Filter master class
Iir.h General infinite-impulse response filter
Fir.h General finite-impulse response filter
OneZero.cpp One zero filter
OnePole.cpp One pole filter
PoleZero.cpp One pole/one zero filter
@@ -104,15 +99,16 @@ Filters: Filter.cpp Filter master class
BiQuad.cpp Two pole/two zero filter
FormSwep.cpp Sweepable biquad filter (goes to target by rate)
Delay.cpp Non-interpolating delay line class
DelayL.cpp Linearly interpolating delay line (subclass of Delay)
DelayA.cpp Allpass interpolating delay line (subclass of Delay)
DelayL.cpp Linearly interpolating delay line
DelayA.cpp Allpass interpolating delay line
TapDelay.cpp Multi-tap non-interpolating delay line class
Non-Linear: JetTabl.cpp Cubic jet non-linearity
BowTabl.cpp x^(-3) Bow non-linearity
ReedTabl.cpp One breakpoint saturating reed non-linearity
Non-Linear: JetTabl.h Cubic jet non-linearity
BowTabl.h x^(-3) Bow non-linearity
ReedTabl.h One breakpoint saturating reed non-linearity
Derived: Modulate.cpp Periodic and random vibrato: WvIn, SubNoise, OnePole
SingWave.cpp Looping wave table with randomness: Modulate, WaveLoop, Envelope
Derived: Modulate.cpp Periodic and random vibrato: WvIn, Noise, OnePole
SingWave.cpp Looping wave table with randomness: Modulate, FileLoop, Envelope
********** INSTRUMENTS AND ALGORITHMS **************
@@ -153,7 +149,7 @@ Shakers.cpp PhISM statistical model for shakers and real-world sound effects
Mesh2D.cpp Two-dimensional, rectilinear digital waveguide mesh.
Whistle.cpp Hybrid physical/spectral model of a police whistle.
Effect.cpp Effects Processor Base Class
Effect.h Effects Processor Base Class
JCRev.cpp Chowning Reverberator 3 series allpass units, 4 parallel combs, 2 stereo delays
NRev.cpp Another famous CCRMA Reverb 8 allpass, 6 parallel comb filters
PRCRev.cpp Dirt Cheap Reverb by Cook 2 allpass, 2 comb filters

175
doc/treesed.html Normal file
View File

@@ -0,0 +1,175 @@
<html>
<head>
<title>Treesed Usage</title>
</head>
<body>
<table border="0" width="660" cellpadding="0" cellspacing="0">
<tbody><tr valign="top"><td width="165">
<h3>How to Use Treesed</h3>
Go to the directory where you want to search or make changes.
<p>
There are two choices you can make when using treesed:
</p><ol>
<li>Do I just want to search for a text, or do I want to search for a
text and replace it with something else?
<br>
If you are just searching you are using Treesed in "search mode", otherwise it is in
"replace mode."
</li><li>Do I want to search/replace only in files in my current directory,
or should files in all subdirectories (and all directories below that)
also be done?
</li></ol>
Some examples will make this clear.
<h4>Searching</h4>
Say you are faced with the situation that the author of a slew of web-pages, Nathan Brazil, has left and has been succeeded by Mavra Chang. First, let us see which files are affected by this (what you type in is shown in <b><tt>bold</tt></b>):
<blockquote>
<pre>[localhost] <b>treesed "Nathan Brazil" -files *.html</b>
search_pattern: Nathan\ Brazil
replacement_pattern:
** Search mode
.
midnight.html: 1 lines on: 2
..
well.html: 1 lines on: 3
</pre>
</blockquote>
We notice the following:
<ul>
<li>The search text <tt>"Nathan Brazil"</tt> is enclosed in
double-quotes (<tt>"</tt>).
</li><li>You specify which files to search with <tt>-files</tt> followed by a
list of file names--in this case <tt>*.html</tt>.
</li><li>Treesed reports the search pattern ("pattern" is just a fancy word
for "text") you specified (you can ignore
that \).
</li><li>Treesed reports an empty <tt>replacement_pattern</tt>. This is
correct, because you haven't entered one.
</li><li>It therefore deduces that is is in search mode.
</li><li>It finds two files containing "Nathan Brazil", and reports on which
lines of these files it found it; it does not show the lines themselves.
</li></ul>
Because you used <tt>-files</tt>, Treesed will search in the files you
specify <i>in the current directory</i>. You can also search files in
the current directory <i>and</i> all directories below it. However, in
that case you can not specify which file names to use, all files will be
searched:
<blockquote>
<pre>[localhost] <b>treesed "Nathan Brazil" -tree</b>
search_pattern: Nathan\ Brazil
replacement_pattern:
** Search mode
.
midnight.html: 1 lines on: 2
...
well.html: 1 lines on: 3
.
new/echoes.html: 1 lines on: 2
</pre>
</blockquote>
We notice the following:
<ul>
<li>Instead of <tt>-files</tt> we now see <tt>-tree</tt>.
</li><li>We do not see a specification of file names.
</li><li>Treesed finds an occurence of "Nathan Brazil" in the file
<tt>echoes.html</tt> in the subdirectory <tt>new</tt>; it did not
find this file in the previous example (as it shouldn't).
</li></ul>
<h4>Replacing</h4>
To replace a text you simply add the replacement text right after the
search text:
<blockquote>
<pre>[localhost] <b>treesed "Nathan Brazil" "Mavra Change" -files *.html</b>
search_pattern: Nathan\ Brazil
replacement_pattern: Mavra Chang
** EDIT MODE!
.
midnight.html: 1 lines on: 2
Replaced Nathan\ Brazil by Mavra Chang on 1 lines in midnight.html
..
well.html: 1 lines on: 3
Replaced Nathan\ Brazil by Mavra Chang on 1 lines in well.html
</pre>
</blockquote>
We notice the following:
<ul>
<li>Right after the search text "Nathan Brazil" you specify the
replacement text "Mavra Chang".
</li><li>As a result, Treesed now reports a non-empty
<tt>replacement_pattern</tt>.
</li><li>Hence it concludes it is in "edit mode", which means replacment mode.
</li><li>Treesed dutifully reports on which lines in which files it did the
replacement.
</li></ul>
To replace a text in all files in the current directory and the ones
below it, we do the following:
<blockquote>
<pre>[localhost] <b>treesed "Nathan Brazil" "Mavra Chang" -tree</b>
search_pattern: Nathan\ Brazil
replacement_pattern: Mavra Chang
** EDIT MODE!
.
midnight.html: 1 lines on: 2
Replaced Nathan\ Brazil by Mavra Chang on 1 lines in midnight.html
....
well.html: 1 lines on: 3
Replaced Nathan\ Brazil by Mavra Chang on 1 lines in well.html
.
new/echoes.html: 1 lines on: 2
Replaced Nathan\ Brazil by Mavra Chang on 1 lines in new/echoes.html
</pre>
</blockquote>
and we get the expected results, including the replace in
<tt>new/echoes.html</tt>.
<h4>Old Versions</h4>
Treesed leaves behind quite a mess of old versions of the files it
changed (only in change-mode, of course). These old files have the same
name as the original file, with <tt>.ddddd</tt> appended to it. For
example, if treesed makes a change to <tt>midnight.html</tt> it will
leave the original version as something like
<tt>midnight.html.26299</tt>. You'll have to remove these files lest
your disk area clutters up. Here is a command that does that, <b>but
beware!</b> This command removes all files in the current directory and
all below it, that end in a period followed by one or more
digits:
<blockquote>
<pre>find . -name "*.[0-9]*" -exec rm {} \;
</pre>
</blockquote>
It is interesting to note that if you use treesed again without cleaning
up, you may get files like <tt>midnight.html.26299.27654</tt>. These
will also be cleaned up by the above slightly dangerous command.
<h3>About Treesed</h3>
<tt>treesed</tt> is public domain software developed
and designed by Rick Jansen from Sara, Amsterdam, Netherlands, January
1996.
<p>
<h3>About This Document</h3>
This usage document was created by the Division of Information Technology Services at The
University of Western Ontario.
</body></html>

View File

@@ -1,86 +1,163 @@
#ifndef STK_ADSR_H
#define STK_ADSR_H
#include "Generator.h"
namespace stk {
/***************************************************/
/*! \class ADSR
\brief STK ADSR envelope class.
This Envelope subclass implements a
traditional ADSR (Attack, Decay,
Sustain, Release) envelope. It
responds to simple keyOn and keyOff
messages, keeping track of its state.
The \e state = ADSR::DONE after the
envelope value reaches 0.0 in the
ADSR::RELEASE state.
This class implements a traditional ADSR (Attack, Decay, Sustain,
Release) envelope. It responds to simple keyOn and keyOff
messages, keeping track of its state. The \e state = ADSR::DONE
after the envelope value reaches 0.0 in the ADSR::RELEASE state.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_ADSR_H
#define STK_ADSR_H
#include "Envelope.h"
class ADSR : public Envelope
class ADSR : public Generator
{
public:
//! Envelope states.
enum { ATTACK, DECAY, SUSTAIN, RELEASE, DONE };
//! ADSR envelope states.
enum {
ATTACK, /*!< Attack */
DECAY, /*!< Decay */
SUSTAIN, /*!< Sustain */
RELEASE, /*!< Release */
DONE /*!< End of release */
};
//! Default constructor.
ADSR(void);
ADSR( void );
//! Class destructor.
~ADSR(void);
~ADSR( void );
//! Set target = 1, state = \e ADSR::ATTACK.
void keyOn(void);
void keyOn( void );
//! Set target = 0, state = \e ADSR::RELEASE.
void keyOff(void);
void keyOff( void );
//! Set the attack rate.
void setAttackRate(StkFloat rate);
void setAttackRate( StkFloat rate );
//! Set the decay rate.
void setDecayRate(StkFloat rate);
void setDecayRate( StkFloat rate );
//! Set the sustain level.
void setSustainLevel(StkFloat level);
void setSustainLevel( StkFloat level );
//! Set the release rate.
void setReleaseRate(StkFloat rate);
void setReleaseRate( StkFloat rate );
//! Set the attack rate based on a time duration.
void setAttackTime(StkFloat time);
void setAttackTime( StkFloat time );
//! Set the decay rate based on a time duration.
void setDecayTime(StkFloat time);
void setDecayTime( StkFloat time );
//! Set the release rate based on a time duration.
void setReleaseTime(StkFloat time);
void setReleaseTime( StkFloat time );
//! Set sustain level and attack, decay, and release time durations.
void setAllTimes(StkFloat aTime, StkFloat dTime, StkFloat sLevel, StkFloat rTime);
void setAllTimes( StkFloat aTime, StkFloat dTime, StkFloat sLevel, StkFloat rTime );
//! Set the target value.
void setTarget(StkFloat target);
void setTarget( StkFloat target );
//! Return the current envelope \e state (ATTACK, DECAY, SUSTAIN, RELEASE, DONE).
int getState(void) const;
int getState( void ) const { return state_; };
//! Set to state = ADSR::SUSTAIN with current and target values of \e aValue.
void setValue(StkFloat value);
//! Set to state = ADSR::SUSTAIN with current and target values of \e value.
void setValue( StkFloat value );
//! Return the last computed output value.
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Compute and return one output sample.
StkFloat tick( void );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument must be less than the number of
channels in the StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
int state_;
StkFloat value_;
StkFloat target_;
StkFloat attackRate_;
StkFloat decayRate_;
StkFloat sustainLevel_;
StkFloat releaseRate_;
StkFloat sustainLevel_;
};
inline StkFloat ADSR :: tick( void )
{
switch ( state_ ) {
case ATTACK:
value_ += attackRate_;
if ( value_ >= target_ ) {
value_ = target_;
target_ = sustainLevel_;
state_ = DECAY;
}
lastFrame_[0] = value_;
break;
case DECAY:
value_ -= decayRate_;
if ( value_ <= sustainLevel_ ) {
value_ = sustainLevel_;
state_ = SUSTAIN;
}
lastFrame_[0] = value_;
break;
case RELEASE:
value_ -= releaseRate_;
if ( value_ <= 0.0 ) {
value_ = (StkFloat) 0.0;
state_ = DONE;
}
lastFrame_[0] = value_;
}
return value_;
}
inline StkFrames& ADSR :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "ADSR::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
*samples = ADSR::tick();
return frames;
}
} // stk namespace
#endif

View File

@@ -1,3 +1,10 @@
#ifndef STK_ASYMP_H
#define STK_ASYMP_H
#include "Generator.h"
namespace stk {
/***************************************************/
/*! \class Asymp
\brief STK asymptotic curve envelope class
@@ -6,7 +13,7 @@
which asymptotically approaches a target value.
The algorithm used is of the form:
x[n] = a x[n-1] + (1-a) target,
y[n] = a y[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
@@ -19,32 +26,27 @@
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 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_ASYMP_H
#define STK_ASYMP_H
#include "Envelope.h"
const StkFloat TARGET_THRESHOLD = 0.000001;
class Asymp : public Envelope
class Asymp : public Generator
{
public:
//! Default constructor.
Asymp(void);
Asymp( void );
//! Class destructor.
~Asymp(void);
~Asymp( void );
//! Set target = 1.
void keyOn(void);
void keyOn( void );
//! Set target = 0.
void keyOff(void);
void keyOff( void );
//! Set the asymptotic rate via the time factor \e tau (must be > 0).
/*!
@@ -53,21 +55,89 @@ class Asymp : public Envelope
fast approach rates, while values greater than 1.0 produce rather
slow rates.
*/
void setTau(StkFloat tau);
void setTau( StkFloat tau );
//! Set the asymptotic rate based on a time duration (must be > 0).
void setTime(StkFloat time);
void setTime( StkFloat time );
//! Set the target value.
void setTarget(StkFloat target);
void setTarget( StkFloat target );
//! Set current and target values to \e value.
void setValue( StkFloat value );
//! Return the current envelope \e state (0 = at target, 1 otherwise).
int getState( void ) const { return state_; };
//! Return the last computed output value.
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Compute and return one output sample.
StkFloat tick( void );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument must be less than the number of
channels in the StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
StkFloat value_;
StkFloat target_;
StkFloat factor_;
StkFloat constant_;
int state_;
};
inline 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;
}
}
lastFrame_[0] = value_;
}
return value_;
}
inline StkFrames& Asymp :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "Asymp::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
*samples = Asymp::tick();
return frames;
}
} // stk namespace
#endif

View File

@@ -1,3 +1,14 @@
#ifndef STK_BANDEDWG_H
#define STK_BANDEDWG_H
#include "Instrmnt.h"
#include "DelayL.h"
#include "BowTable.h"
#include "ADSR.h"
#include "BiQuad.h"
namespace stk {
/***************************************************/
/*! \class BandedWG
\brief Banded waveguide modeling class.
@@ -25,64 +36,56 @@
- Tibetan Bowl = 3
by Georg Essl, 1999 - 2004.
Modified for Stk 4.0 by Gary Scavone.
Modified for STK 4.0 by Gary Scavone.
*/
/***************************************************/
#ifndef STK_BANDEDWG_H
#define STK_BANDEDWG_H
const int MAX_BANDED_MODES = 20;
#include "Instrmnt.h"
#include "DelayL.h"
#include "BowTable.h"
#include "ADSR.h"
#include "BiQuad.h"
class BandedWG : public Instrmnt
{
public:
//! Class constructor.
BandedWG();
BandedWG( void );
//! Class destructor.
~BandedWG();
~BandedWG( void );
//! Reset and clear all internal state.
void clear();
void clear( void );
//! Set strike position (0.0 - 1.0).
void setStrikePosition(StkFloat position);
void setStrikePosition( StkFloat position );
//! Select a preset.
void setPreset(int preset);
void setPreset( int preset );
//! Set instrument parameters for a particular frequency.
void setFrequency(StkFloat frequency);
void setFrequency( StkFloat frequency );
//! Apply bow velocity/pressure to instrument with given amplitude and rate of increase.
void startBowing(StkFloat amplitude, StkFloat rate);
void startBowing( StkFloat amplitude, StkFloat rate );
//! Decrease bow velocity/breath pressure with given rate of decrease.
void stopBowing(StkFloat rate);
void stopBowing( StkFloat rate );
//! Pluck the instrument with given amplitude.
void pluck(StkFloat amp);
void pluck( StkFloat amp );
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
void noteOff( StkFloat amplitude );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
void controlChange( int number, StkFloat value );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
bool doPluck_;
bool trackVelocity_;
int nModes_;
@@ -108,4 +111,6 @@ class BandedWG : public Instrmnt
};
} // stk namespace
#endif

View File

@@ -1,3 +1,10 @@
#ifndef STK_BEETHREE_H
#define STK_BEETHREE_H
#include "FM.h"
namespace stk {
/***************************************************/
/*! \class BeeThree
\brief STK Hammond-oid organ FM synthesis instrument.
@@ -28,15 +35,10 @@
type who should worry about this (making
money) worry away.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_BEETHREE_H
#define STK_BEETHREE_H
#include "FM.h"
class BeeThree : public FM
{
public:
@@ -44,17 +46,45 @@ class BeeThree : public FM
/*!
An StkError will be thrown if the rawwave path is incorrectly set.
*/
BeeThree();
BeeThree( void );
//! Class destructor.
~BeeThree();
~BeeThree( void );
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
};
inline StkFloat BeeThree :: tick( unsigned int )
{
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] );
}
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();
lastFrame_[0] = temp * 0.125;
return lastFrame_[0];
}
} // stk namespace
#endif

View File

@@ -1,23 +1,23 @@
/***************************************************/
/*! \class BiQuad
\brief STK biquad (two-pole, two-zero) filter class.
This protected Filter subclass implements a
two-pole, two-zero digital filter. A method
is provided for creating a resonance in the
frequency response while maintaining a constant
filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
*/
/***************************************************/
#ifndef STK_BIQUAD_H
#define STK_BIQUAD_H
#include "Filter.h"
class BiQuad : protected Filter
namespace stk {
/***************************************************/
/*! \class BiQuad
\brief STK biquad (two-pole, two-zero) filter class.
This class implements a two-pole, two-zero digital filter.
Methods are provided for creating a resonance or notch in the
frequency response while maintaining a constant filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
class BiQuad : public Filter
{
public:
@@ -25,28 +25,28 @@ public:
BiQuad();
//! Class destructor.
virtual ~BiQuad();
~BiQuad();
//! A function to enable/disable the automatic updating of class data when the STK sample rate changes.
void ignoreSampleRateChange( bool ignore = true ) { ignoreSampleRateChange_ = ignore; };
//! Clears all internal states of the filter.
void clear(void);
//! Set all filter coefficients.
void setCoefficients( StkFloat b0, StkFloat b1, StkFloat b2, StkFloat a1, StkFloat a2, bool clearState = false );
//! Set the b[0] coefficient value.
void setB0(StkFloat b0);
void setB0( StkFloat b0 ) { b_[0] = b0; };
//! Set the b[1] coefficient value.
void setB1(StkFloat b1);
void setB1( StkFloat b1 ) { b_[1] = b1; };
//! Set the b[2] coefficient value.
void setB2(StkFloat b2);
void setB2( StkFloat b2 ) { b_[2] = b2; };
//! Set the a[1] coefficient value.
void setA1(StkFloat a1);
void setA1( StkFloat a1 ) { a_[1] = a1; };
//! Set the a[2] coefficient value.
void setA2(StkFloat a2);
void setA2( StkFloat a2 ) { a_[2] = a2; };
//! Sets the filter coefficients for a resonance at \e frequency (in Hz).
/*!
@@ -60,7 +60,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(StkFloat frequency, StkFloat 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).
/*!
@@ -69,7 +69,7 @@ public:
and \e radius from the z-plane origin. No filter normalization
is attempted.
*/
void setNotch(StkFloat frequency, StkFloat radius);
void setNotch( StkFloat frequency, StkFloat radius );
//! Sets the filter zeroes for equal resonance gain.
/*!
@@ -78,62 +78,106 @@ public:
where R is the pole radius setting.
*/
void setEqualGainZeroes();
//! 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(StkFloat gain);
//! Return the current filter gain.
StkFloat getGain(void) const;
void setEqualGainZeroes( void );
//! Return the last computed output value.
StkFloat lastOut(void) const;
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Input one sample to the filter and return one output.
virtual StkFloat tick(StkFloat sample);
//! Input one sample to the filter and return a reference to one output.
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
The StkFrames argument reference is returned. The \c channel
argument must be less than the number of channels in the
StkFrames argument (the first channel is specified by 0).
However, range checking is only performed if _STK_DEBUG_ is
defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Take a channel of the \c iFrames object as inputs to the filter and write outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. Each channel
argument must be less than the number of channels in the
corresponding StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
protected:
// This function must be implemented in all subclasses. It is used
// to get around a C++ problem with overloaded virtual functions.
virtual StkFloat computeSample( StkFloat input );
virtual void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
};
inline StkFloat BiQuad :: computeSample( StkFloat input )
inline StkFloat BiQuad :: tick( StkFloat input )
{
inputs_[0] = gain_ * input;
outputs_[0] = b_[0] * inputs_[0] + b_[1] * inputs_[1] + b_[2] * inputs_[2];
outputs_[0] -= a_[2] * outputs_[2] + a_[1] * outputs_[1];
lastFrame_[0] = b_[0] * inputs_[0] + b_[1] * inputs_[1] + b_[2] * inputs_[2];
lastFrame_[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];
outputs_[1] = lastFrame_[0];
return outputs_[0];
}
inline StkFloat BiQuad :: tick( StkFloat input )
{
return this->computeSample( input );
return lastFrame_[0];
}
inline StkFrames& BiQuad :: tick( StkFrames& frames, unsigned int channel )
{
return Filter::tick( frames, channel );
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "BiQuad::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
inputs_[0] = gain_ * *samples;
*samples = b_[0] * inputs_[0] + b_[1] * inputs_[1] + b_[2] * inputs_[2];
*samples -= a_[2] * outputs_[2] + a_[1] * outputs_[1];
inputs_[2] = inputs_[1];
inputs_[1] = inputs_[0];
outputs_[2] = outputs_[1];
outputs_[1] = *samples;
}
lastFrame_[0] = outputs_[1];
return frames;
}
inline StkFrames& BiQuad :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
{
#if defined(_STK_DEBUG_)
if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
errorString_ << "BiQuad::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *iSamples = &iFrames[iChannel];
StkFloat *oSamples = &oFrames[oChannel];
unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
inputs_[0] = gain_ * *iSamples;
*oSamples = b_[0] * inputs_[0] + b_[1] * inputs_[1] + b_[2] * inputs_[2];
*oSamples -= a_[2] * outputs_[2] + a_[1] * outputs_[1];
inputs_[2] = inputs_[1];
inputs_[1] = inputs_[0];
outputs_[2] = outputs_[1];
outputs_[1] = *oSamples;
}
lastFrame_[0] = outputs_[1];
return iFrames;
}
} // stk namespace
#endif

View File

@@ -1,3 +1,12 @@
#ifndef STK_BLIT_H
#define STK_BLIT_H
#include "Generator.h"
#include <cmath>
#include <limits>
namespace stk {
/***************************************************/
/*! \class Blit
\brief STK band-limited impulse train class.
@@ -21,11 +30,6 @@
*/
/***************************************************/
#ifndef STK_BLIT_H
#define STK_BLIT_H
#include "Generator.h"
class Blit: public Generator
{
public:
@@ -68,10 +72,25 @@ class Blit: public Generator
*/
void setHarmonics( unsigned int nHarmonics = 0 );
//! Return the last computed output value.
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Compute and return one output sample.
StkFloat tick( void );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument must be less than the number of
channels in the StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
protected:
void updateHarmonics( void );
StkFloat computeSample( void );
unsigned int nHarmonics_;
unsigned int m_;
@@ -81,4 +100,52 @@ class Blit: public Generator
};
inline StkFloat Blit :: tick( void )
{
// The code below implements the SincM algorithm of Stilson and
// Smith with an additional scale factor of P / M applied to
// normalize the output.
// A fully optimized version of this code would replace the two sin
// calls with a pair of fast sin oscillators, for which stable fast
// two-multiply algorithms are well known. In the spirit of STK,
// which favors clarity over performance, the optimization has not
// been made here.
// Avoid a divide by zero at the sinc peak, which has a limiting
// value of 1.0.
StkFloat tmp, denominator = sin( phase_ );
if ( denominator <= std::numeric_limits<StkFloat>::epsilon() )
tmp = 1.0;
else {
tmp = sin( m_ * phase_ );
tmp /= m_ * denominator;
}
phase_ += rate_;
if ( phase_ >= PI ) phase_ -= PI;
lastFrame_[0] = tmp;
return lastFrame_[0];
}
inline StkFrames& Blit :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "Blit::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
*samples = Blit::tick();
return frames;
}
} // stk namespace
#endif

View File

@@ -1,3 +1,12 @@
#ifndef STK_BLITSAW_H
#define STK_BLITSAW_H
#include "Generator.h"
#include <cmath>
#include <limits>
namespace stk {
/***************************************************/
/*! \class BlitSaw
\brief STK band-limited sawtooth wave class.
@@ -19,11 +28,6 @@
*/
/***************************************************/
#ifndef STK_BLITSAW_H
#define STK_BLITSAW_H
#include "Generator.h"
class BlitSaw: public Generator
{
public:
@@ -54,10 +58,25 @@ class BlitSaw: public Generator
*/
void setHarmonics( unsigned int nHarmonics = 0 );
//! Return the last computed output value.
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Compute and return one output sample.
StkFloat tick( void );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument must be less than the number of
channels in the StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
protected:
void updateHarmonics( void );
StkFloat computeSample( void );
unsigned int nHarmonics_;
unsigned int m_;
@@ -70,4 +89,60 @@ class BlitSaw: public Generator
};
inline StkFloat BlitSaw :: tick( void )
{
// The code below implements the BLIT algorithm of Stilson and
// Smith, followed by a summation and filtering operation to produce
// a sawtooth waveform. After experimenting with various approaches
// to calculate the average value of the BLIT over one period, I
// found that an estimate of C2_ = 1.0 / period (in samples) worked
// most consistently. A "leaky integrator" is then applied to the
// difference of the BLIT output and C2_. (GPS - 1 October 2005)
// A fully optimized version of this code would replace the two sin
// calls with a pair of fast sin oscillators, for which stable fast
// two-multiply algorithms are well known. In the spirit of STK,
// which favors clarity over performance, the optimization has
// not been made here.
// Avoid a divide by zero, or use of a denormalized divisor
// at the sinc peak, which has a limiting value of m_ / p_.
StkFloat tmp, denominator = sin( phase_ );
if ( fabs(denominator) <= std::numeric_limits<StkFloat>::epsilon() )
tmp = a_;
else {
tmp = sin( m_ * phase_ );
tmp /= p_ * denominator;
}
tmp += state_ - C2_;
state_ = tmp * 0.995;
phase_ += rate_;
if ( phase_ >= PI ) phase_ -= PI;
lastFrame_[0] = tmp;
return lastFrame_[0];
}
inline StkFrames& BlitSaw :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "BlitSaw::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
*samples = BlitSaw::tick();
return frames;
}
} // stk namespace
#endif

View File

@@ -1,3 +1,12 @@
#ifndef STK_BLITSQUARE_H
#define STK_BLITSQUARE_H
#include "Generator.h"
#include <cmath>
#include <limits>
namespace stk {
/***************************************************/
/*! \class BlitSquare
\brief STK band-limited square wave class.
@@ -30,11 +39,6 @@
*/
/***************************************************/
#ifndef STK_BLITSQUARE_H
#define STK_BLITSQUARE_H
#include "Generator.h"
class BlitSquare: public Generator
{
public:
@@ -77,10 +81,25 @@ class BlitSquare: public Generator
*/
void setHarmonics( unsigned int nHarmonics = 0 );
//! Return the last computed output value.
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Compute and return one output sample.
StkFloat tick( void );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument must be less than the number of
channels in the StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
protected:
void updateHarmonics( void );
StkFloat computeSample( void );
unsigned int nHarmonics_;
unsigned int m_;
@@ -92,4 +111,60 @@ class BlitSquare: public Generator
StkFloat dcbState_;
};
inline StkFloat BlitSquare :: tick( void )
{
StkFloat temp = lastBlitOutput_;
// A fully optimized version of this would replace the two sin calls
// with a pair of fast sin oscillators, for which stable fast
// two-multiply algorithms are well known. In the spirit of STK,
// which favors clarity over performance, the optimization has
// not been made here.
// Avoid a divide by zero, or use of a denomralized divisor
// at the sinc peak, which has a limiting value of 1.0.
StkFloat denominator = sin( phase_ );
if ( fabs( denominator ) < std::numeric_limits<StkFloat>::epsilon() ) {
// Inexact comparison safely distinguishes betwen *close to zero*, and *close to PI*.
if ( phase_ < 0.1f || phase_ > TWO_PI - 0.1f )
lastBlitOutput_ = a_;
else
lastBlitOutput_ = -a_;
}
else {
lastBlitOutput_ = sin( m_ * phase_ );
lastBlitOutput_ /= p_ * denominator;
}
lastBlitOutput_ += temp;
// Now apply DC blocker.
lastFrame_[0] = lastBlitOutput_ - dcbState_ + 0.999 * lastFrame_[0];
dcbState_ = lastBlitOutput_;
phase_ += rate_;
if ( phase_ >= TWO_PI ) phase_ -= TWO_PI;
return lastFrame_[0];
}
inline StkFrames& BlitSquare :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "BlitSquare::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
*samples = BlitSquare::tick();
return frames;
}
} // stk namespace
#endif

View File

@@ -1,3 +1,16 @@
#ifndef STK_BLOWBOTL_H
#define STK_BLOWBOTL_H
#include "Instrmnt.h"
#include "JetTable.h"
#include "BiQuad.h"
#include "PoleZero.h"
#include "Noise.h"
#include "ADSR.h"
#include "SineWave.h"
namespace stk {
/***************************************************/
/*! \class BlowBotl
\brief STK blown bottle instrument class.
@@ -12,21 +25,10 @@
- Vibrato Gain = 1
- Volume = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_BLOWBOTL_H
#define STK_BLOWBOTL_H
#include "Instrmnt.h"
#include "JetTable.h"
#include "BiQuad.h"
#include "PoleZero.h"
#include "Noise.h"
#include "ADSR.h"
#include "SineWave.h"
class BlowBotl : public Instrmnt
{
public:
@@ -34,36 +36,37 @@ class BlowBotl : public Instrmnt
/*!
An StkError will be thrown if the rawwave path is incorrectly set.
*/
BlowBotl();
BlowBotl( void );
//! Class destructor.
~BlowBotl();
~BlowBotl( void );
//! Reset and clear all internal state.
void clear();
void clear( void );
//! Set instrument parameters for a particular frequency.
void setFrequency(StkFloat frequency);
void setFrequency( StkFloat frequency );
//! Apply breath velocity to instrument with given amplitude and rate of increase.
void startBlowing(StkFloat amplitude, StkFloat rate);
void startBlowing( StkFloat amplitude, StkFloat rate );
//! Decrease breath velocity with given rate of decrease.
void stopBlowing(StkFloat rate);
void stopBlowing( StkFloat rate );
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
void noteOff( StkFloat amplitude );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
void controlChange( int number, StkFloat value );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
JetTable jetTable_;
BiQuad resonator_;
PoleZero dcBlock_;
@@ -77,4 +80,28 @@ class BlowBotl : public Instrmnt
};
inline StkFloat BlowBotl :: tick( unsigned int )
{
StkFloat breathPressure;
StkFloat randPressure;
StkFloat pressureDiff;
// Calculate the breath pressure (envelope + vibrato)
breathPressure = maxPressure_ * adsr_.tick();
breathPressure += vibratoGain_ * vibrato_.tick();
pressureDiff = breathPressure - resonator_.lastOut();
randPressure = noiseGain_ * noise_.tick();
randPressure *= breathPressure;
randPressure *= (1.0 + pressureDiff);
resonator_.tick( breathPressure + randPressure - ( jetTable_.tick( pressureDiff ) * pressureDiff ) );
lastFrame_[0] = 0.2 * outputGain_ * dcBlock_.tick( pressureDiff );
return lastFrame_[0];
}
} // stk namespace
#endif

View File

@@ -1,3 +1,17 @@
#ifndef STK_BLOWHOLE_H
#define STK_BLOWHOLE_H
#include "Instrmnt.h"
#include "DelayL.h"
#include "ReedTable.h"
#include "OneZero.h"
#include "PoleZero.h"
#include "Envelope.h"
#include "Noise.h"
#include "SineWave.h"
namespace stk {
/***************************************************/
/*! \class BlowHole
\brief STK clarinet physical model with one
@@ -29,22 +43,10 @@
- Register State = 1
- Breath Pressure = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_BLOWHOLE_H
#define STK_BLOWHOLE_H
#include "Instrmnt.h"
#include "DelayL.h"
#include "ReedTable.h"
#include "OneZero.h"
#include "PoleZero.h"
#include "Envelope.h"
#include "Noise.h"
#include "SineWave.h"
class BlowHole : public Instrmnt
{
public:
@@ -52,42 +54,43 @@ class BlowHole : public Instrmnt
/*!
An StkError will be thrown if the rawwave path is incorrectly set.
*/
BlowHole(StkFloat lowestFrequency);
BlowHole( StkFloat lowestFrequency );
//! Class destructor.
~BlowHole();
~BlowHole( void );
//! Reset and clear all internal state.
void clear();
void clear( void );
//! Set instrument parameters for a particular frequency.
void setFrequency(StkFloat frequency);
void setFrequency( StkFloat frequency );
//! Set the tonehole state (0.0 = closed, 1.0 = fully open).
void setTonehole(StkFloat newValue);
void setTonehole( StkFloat newValue );
//! Set the register hole state (0.0 = closed, 1.0 = fully open).
void setVent(StkFloat newValue);
void setVent( StkFloat newValue );
//! Apply breath pressure to instrument with given amplitude and rate of increase.
void startBlowing(StkFloat amplitude, StkFloat rate);
void startBlowing( StkFloat amplitude, StkFloat rate );
//! Decrease breath pressure with given rate of decrease.
void stopBlowing(StkFloat rate);
void stopBlowing( StkFloat rate );
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
void noteOff( StkFloat amplitude );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
void controlChange( int number, StkFloat value );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
DelayL delays_[3];
ReedTable reedTable_;
OneZero filter_;
@@ -106,4 +109,41 @@ class BlowHole : public Instrmnt
};
inline StkFloat BlowHole :: tick( unsigned int )
{
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();
// Calculate the differential pressure = reflected - mouthpiece pressures
pressureDiff = delays_[0].lastOut() - breathPressure;
// Do two-port junction scattering for register vent
StkFloat pa = breathPressure + pressureDiff * reedTable_.tick( pressureDiff );
StkFloat pb = delays_[1].lastOut();
vent_.tick( pa+pb );
lastFrame_[0] = delays_[0].tick( vent_.lastOut()+pb );
lastFrame_[0] *= outputGain_;
// Do three-port junction scattering (under tonehole)
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 );
return lastFrame_[0];
}
} // stk namespace
#endif

View File

@@ -1,3 +1,11 @@
#ifndef STK_BOWTABL_H
#define STK_BOWTABL_H
#include "Function.h"
#include <cmath>
namespace stk {
/***************************************************/
/*! \class BowTable
\brief STK bowed string table class.
@@ -5,23 +13,15 @@
This class implements a simple bowed string
non-linear function, as described by Smith (1986).
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_BOWTABL_H
#define STK_BOWTABL_H
#include "Function.h"
class BowTable : public Function
{
public:
//! Default constructor.
BowTable();
//! Class destructor.
~BowTable();
BowTable( void ) : offset_(0.0), slope_(0.1) {};
//! Set the table offset value.
/*!
@@ -30,22 +30,111 @@ public:
friction to vary with direction, use a non-zero
value for the offset. The default value is zero.
*/
void setOffset(StkFloat offset);
void setOffset( StkFloat offset ) { offset_ = 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);
void setSlope( StkFloat slope ) { slope_ = slope; };
//! Take one sample input and map to one sample of output.
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the table and replace with corresponding outputs.
/*!
The StkFrames argument reference is returned. The \c channel
argument must be less than the number of channels in the
StkFrames argument (the first channel is specified by 0).
However, range checking is only performed if _STK_DEBUG_ is
defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Take a channel of the \c iFrames object as inputs to the table and write outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. Each channel
argument must be less than the number of channels in the
corresponding StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
protected:
StkFloat computeSample( StkFloat input );
StkFloat offset_;
StkFloat slope_;
};
inline StkFloat BowTable :: tick( StkFloat input )
{
// The input represents differential string vs. bow velocity.
StkFloat sample = input + offset_; // add bias to input
sample *= slope_; // then scale it
lastFrame_[0] = (StkFloat) fabs( (double) sample ) + (StkFloat) 0.75;
lastFrame_[0] = (StkFloat) pow( lastFrame_[0], (StkFloat) -4.0 );
// Set minimum friction to 0.0
// if ( lastFrame_[0] < 0.0 ) lastFrame_[0] = 0.0;
// Set maximum friction to 1.0.
if ( lastFrame_[0] > 1.0 ) lastFrame_[0] = (StkFloat) 1.0;
return lastFrame_[0];
}
inline StkFrames& BowTable :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "BowTable::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
*samples = *samples + offset_;
*samples *= slope_;
*samples = (StkFloat) fabs( (double) *samples ) + 0.75;
*samples = (StkFloat) pow( *samples, (StkFloat) -4.0 );
if ( *samples > 1.0) *samples = 1.0;
}
lastFrame_[0] = *(samples-hop);
return frames;
}
inline StkFrames& BowTable :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
{
#if defined(_STK_DEBUG_)
if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
errorString_ << "BowTable::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *iSamples = &iFrames[iChannel];
StkFloat *oSamples = &oFrames[oChannel];
unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
*oSamples = *iSamples + offset_;
*oSamples *= slope_;
*oSamples = (StkFloat) fabs( (double) *oSamples ) + 0.75;
*oSamples = (StkFloat) pow( *oSamples, (StkFloat) -4.0 );
if ( *oSamples > 1.0) *oSamples = 1.0;
}
lastFrame_[0] = *(oSamples-oHop);
return iFrames;
}
} // stk namespace
#endif

View File

@@ -1,3 +1,16 @@
#ifndef STK_BOWED_H
#define STK_BOWED_H
#include "Instrmnt.h"
#include "DelayL.h"
#include "BowTable.h"
#include "OnePole.h"
#include "BiQuad.h"
#include "SineWave.h"
#include "ADSR.h"
namespace stk {
/***************************************************/
/*! \class Bowed
\brief STK bowed string instrument class.
@@ -17,58 +30,48 @@
- Vibrato Gain = 1
- Volume = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_BOWED_H
#define STK_BOWED_H
#include "Instrmnt.h"
#include "DelayL.h"
#include "BowTable.h"
#include "OnePole.h"
#include "BiQuad.h"
#include "SineWave.h"
#include "ADSR.h"
class Bowed : public Instrmnt
{
public:
//! Class constructor, taking the lowest desired playing frequency.
Bowed(StkFloat lowestFrequency);
Bowed( StkFloat lowestFrequency );
//! Class destructor.
~Bowed();
~Bowed( void );
//! Reset and clear all internal state.
void clear();
void clear( void );
//! Set instrument parameters for a particular frequency.
void setFrequency(StkFloat frequency);
void setFrequency( StkFloat frequency );
//! Set vibrato gain.
void setVibrato(StkFloat gain);
void setVibrato( StkFloat gain );
//! Apply breath pressure to instrument with given amplitude and rate of increase.
void startBowing(StkFloat amplitude, StkFloat rate);
void startBowing( StkFloat amplitude, StkFloat rate );
//! Decrease breath pressure with given rate of decrease.
void stopBowing(StkFloat rate);
void stopBowing( StkFloat rate );
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
void noteOff( StkFloat amplitude );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
void controlChange( int number, StkFloat value );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
DelayL neckDelay_;
DelayL bridgeDelay_;
BowTable bowTable_;
@@ -83,4 +86,27 @@ class Bowed : public Instrmnt
};
inline StkFloat Bowed :: tick( unsigned int )
{
StkFloat bowVelocity = maxVelocity_ * adsr_.tick();
StkFloat bridgeRefl = -stringFilter_.tick( bridgeDelay_.lastOut() );
StkFloat nutRefl = -neckDelay_.lastOut();
StkFloat stringVel = bridgeRefl + nutRefl; // Sum is string velocity
StkFloat velDiff = bowVelocity - stringVel; // Differential velocity
StkFloat 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_ * (1.0 - betaRatio_) ) +
(baseDelay_ * vibratoGain_ * vibrato_.tick()) );
}
lastFrame_[0] = bodyFilter_.tick( bridgeDelay_.lastOut() );
return lastFrame_[0];
}
} // stk namespace
#endif

View File

@@ -1,3 +1,15 @@
#ifndef STK_BRASS_H
#define STK_BRASS_H
#include "Instrmnt.h"
#include "DelayA.h"
#include "BiQuad.h"
#include "PoleZero.h"
#include "ADSR.h"
#include "SineWave.h"
namespace stk {
/***************************************************/
/*! \class Brass
\brief STK simple brass instrument class.
@@ -16,20 +28,10 @@
- Vibrato Gain = 1
- Volume = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_BRASS_H
#define STK_BRASS_H
#include "Instrmnt.h"
#include "DelayA.h"
#include "BiQuad.h"
#include "PoleZero.h"
#include "ADSR.h"
#include "SineWave.h"
class Brass: public Instrmnt
{
public:
@@ -37,39 +39,40 @@ class Brass: public Instrmnt
/*!
An StkError will be thrown if the rawwave path is incorrectly set.
*/
Brass(StkFloat lowestFrequency);
Brass( StkFloat lowestFrequency );
//! Class destructor.
~Brass();
~Brass( );
//! Reset and clear all internal state.
void clear();
void clear( );
//! Set instrument parameters for a particular frequency.
void setFrequency(StkFloat frequency);
void setFrequency( StkFloat frequency );
//! Set the lips frequency.
void setLip(StkFloat frequency);
void setLip( StkFloat frequency );
//! Apply breath pressure to instrument with given amplitude and rate of increase.
void startBlowing(StkFloat amplitude, StkFloat rate);
void startBlowing( StkFloat amplitude, StkFloat rate );
//! Decrease breath pressure with given rate of decrease.
void stopBlowing(StkFloat rate);
void stopBlowing( StkFloat rate );
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
void noteOff( StkFloat amplitude );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
void controlChange( int number, StkFloat value );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
DelayA delayLine_;
BiQuad lipFilter_;
PoleZero dcBlock_;
@@ -83,4 +86,25 @@ class Brass: public Instrmnt
};
inline StkFloat Brass :: tick( unsigned int )
{
StkFloat breathPressure = maxPressure_ * adsr_.tick();
breathPressure += vibratoGain_ * vibrato_.tick();
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.
lastFrame_[0] = deltaPressure * mouthPressure + ( 1.0 - deltaPressure) * borePressure;
lastFrame_[0] = delayLine_.tick( dcBlock_.tick( lastFrame_[0] ) );
return lastFrame_[0];
}
} // stk namespace
#endif

View File

@@ -1,20 +1,23 @@
#ifndef STK_CHORUS_H
#define STK_CHORUS_H
#include "Effect.h"
#include "DelayL.h"
#include "SineWave.h"
namespace stk {
/***************************************************/
/*! \class Chorus
\brief STK chorus effect class.
This class implements a chorus effect.
This class implements a chorus effect. It takes a monophonic
input signal and produces a stereo output signal.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_CHORUS_H
#define STK_CHORUS_H
#include "Effect.h"
#include "DelayL.h"
#include "SineWave.h"
class Chorus : public Effect
{
public:
@@ -24,22 +27,62 @@ class Chorus : public Effect
*/
Chorus( StkFloat baseDelay = 6000 );
//! Class destructor.
~Chorus();
//! Reset and clear all internal state.
void clear();
void clear( void );
//! Set modulation depth.
void setModDepth(StkFloat depth);
void setModDepth( StkFloat depth ) { modDepth_ = depth; };
//! Set modulation frequency.
void setModFrequency(StkFloat frequency);
void setModFrequency( StkFloat frequency );
//! Return the specified channel value of the last computed stereo frame.
/*!
Use the lastFrame() function to get both values of the last
computed stereo frame. The \c channel argument must be 0 or 1
(the first channel is specified by 0). However, range checking is
only performed if _STK_DEBUG_ is defined during compilation, in
which case an out-of-range value will trigger an StkError
exception.
*/
StkFloat lastOut( unsigned int channel = 0 );
//! Input one sample to the effect and return the specified \c channel value of the computed stereo frame.
/*!
Use the lastFrame() function to get both values of the computed
stereo output frame. The \c channel argument must be 0 or 1 (the
first channel is specified by 0). However, range checking is only
performed if _STK_DEBUG_ is defined during compilation, in which
case an out-of-range value will trigger an StkError exception.
*/
StkFloat tick( StkFloat input, unsigned int channel = 0 );
//! Take a channel of the StkFrames object as inputs to the effect and replace with stereo outputs.
/*!
The StkFrames argument reference is returned. The stereo
outputs are written to the StkFrames argument starting at the
specified \c channel. Therefore, the \c channel argument must be
less than ( channels() - 1 ) of the StkFrames argument (the first
channel is specified by 0). However, range checking is only
performed if _STK_DEBUG_ is defined during compilation, in which
case an out-of-range value will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Take a channel of the \c iFrames object as inputs to the effect and write stereo outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. The \c iChannel
argument must be less than the number of channels in the \c
iFrames argument (the first channel is specified by 0). The \c
oChannel argument must be less than ( channels() - 1 ) of the \c
oFrames argument. However, range checking is only performed if
_STK_DEBUG_ is defined during compilation, in which case an
out-of-range value will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
protected:
StkFloat computeSample( StkFloat input );
DelayL delayLine_[2];
SineWave mods_[2];
StkFloat baseLength_;
@@ -47,5 +90,79 @@ class Chorus : public Effect
};
inline StkFloat Chorus :: lastOut( unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel > 1 ) {
errorString_ << "Chorus::lastOut(): channel argument must be less than 2!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
return lastFrame_[channel];
}
inline StkFloat Chorus :: tick( StkFloat input, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel > 1 ) {
errorString_ << "Chorus::tick(): channel argument must be less than 2!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
delayLine_[0].setDelay( baseLength_ * 0.707 * ( 1.0 + modDepth_ * mods_[0].tick() ) );
delayLine_[1].setDelay( baseLength_ * 0.5 * ( 1.0 - modDepth_ * mods_[1].tick() ) );
lastFrame_[0] = effectMix_ * ( delayLine_[0].tick( input ) - input ) + input;
lastFrame_[1] = effectMix_ * ( delayLine_[1].tick( input ) - input ) + input;
return lastFrame_[channel];
}
inline StkFrames& Chorus :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() - 1 ) {
errorString_ << "Chorus::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels() - 1;
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
*samples = effectMix_ * ( delayLine_[0].tick( *samples ) - *samples ) + *samples;
samples++;
*samples = effectMix_ * ( delayLine_[1].tick( *samples ) - *samples ) + *samples;
}
lastFrame_[0] = *(samples-hop);
lastFrame_[1] = *(samples-hop+1);
return frames;
}
inline StkFrames& Chorus :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
{
#if defined(_STK_DEBUG_)
if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() - 1 ) {
errorString_ << "Chorus::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *iSamples = &iFrames[iChannel];
StkFloat *oSamples = &oFrames[oChannel];
unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
*oSamples++ = effectMix_ * ( delayLine_[0].tick( *iSamples ) - *iSamples ) + *iSamples;
*oSamples = effectMix_ * ( delayLine_[1].tick( *iSamples ) - *iSamples ) + *iSamples;
}
lastFrame_[0] = *(oSamples-oHop);
lastFrame_[1] = *(oSamples-oHop+1);
return iFrames;
}
} // stk namespace
#endif

View File

@@ -1,3 +1,16 @@
#ifndef STK_CLARINET_H
#define STK_CLARINET_H
#include "Instrmnt.h"
#include "DelayL.h"
#include "ReedTable.h"
#include "OneZero.h"
#include "Envelope.h"
#include "Noise.h"
#include "SineWave.h"
namespace stk {
/***************************************************/
/*! \class Clarinet
\brief STK clarinet physical model class.
@@ -18,21 +31,10 @@
- Vibrato Gain = 1
- Breath Pressure = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_CLARINET_H
#define STK_CLARINET_H
#include "Instrmnt.h"
#include "DelayL.h"
#include "ReedTable.h"
#include "OneZero.h"
#include "Envelope.h"
#include "Noise.h"
#include "SineWave.h"
class Clarinet : public Instrmnt
{
public:
@@ -40,36 +42,37 @@ class Clarinet : public Instrmnt
/*!
An StkError will be thrown if the rawwave path is incorrectly set.
*/
Clarinet(StkFloat lowestFrequency);
Clarinet( StkFloat lowestFrequency );
//! Class destructor.
~Clarinet();
~Clarinet( void );
//! Reset and clear all internal state.
void clear();
void clear( void );
//! Set instrument parameters for a particular frequency.
void setFrequency(StkFloat frequency);
void setFrequency( StkFloat frequency );
//! Apply breath pressure to instrument with given amplitude and rate of increase.
void startBlowing(StkFloat amplitude, StkFloat rate);
void startBlowing( StkFloat amplitude, StkFloat rate );
//! Decrease breath pressure with given rate of decrease.
void stopBlowing(StkFloat rate);
void stopBlowing( StkFloat rate );
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
void noteOff( StkFloat amplitude );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
void controlChange( int number, StkFloat value );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
DelayL delayLine_;
ReedTable reedTable_;
OneZero filter_;
@@ -83,4 +86,31 @@ class Clarinet : public Instrmnt
};
inline StkFloat Clarinet :: tick( unsigned int )
{
StkFloat pressureDiff;
StkFloat breathPressure;
// Calculate the breath pressure (envelope + noise + vibrato)
breathPressure = envelope_.tick();
breathPressure += breathPressure * noiseGain_ * noise_.tick();
breathPressure += breathPressure * vibratoGain_ * vibrato_.tick();
// Perform commuted loss filtering.
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.
lastFrame_[0] = delayLine_.tick(breathPressure + pressureDiff * reedTable_.tick(pressureDiff));
// Apply output gain.
lastFrame_[0] *= outputGain_;
return lastFrame_[0];
}
} // stk namespace
#endif

View File

@@ -1,48 +1,40 @@
/***************************************************/
/*! \class Delay
\brief STK non-interpolating delay line class.
This protected Filter subclass implements
a non-interpolating digital delay-line.
A fixed maximum length of 4095 and a delay
of zero is set using the default constructor.
Alternatively, the delay and maximum length
can be set during instantiation with an
overloaded constructor.
A non-interpolating delay line is typically
used in fixed delay-length applications, such
as for reverberation.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
*/
/***************************************************/
#ifndef STK_DELAY_H
#define STK_DELAY_H
#include "Filter.h"
class Delay : protected Filter
namespace stk {
/***************************************************/
/*! \class Delay
\brief STK non-interpolating delay line class.
This class implements a non-interpolating digital delay-line. If
the delay and maximum length are not specified during
instantiation, a fixed maximum length of 4095 and a delay of zero
is set.
A non-interpolating delay line is typically used in fixed
delay-length applications, such as for reverberation.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
class Delay : public Filter
{
public:
//! Default constructor creates a delay-line with maximum length of 4095 samples and zero delay.
Delay();
//! Overloaded constructor which specifies the current and maximum delay-line lengths.
//! The default constructor creates a delay-line with maximum length of 4095 samples and zero delay.
/*!
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);
Delay( unsigned long delay = 0, unsigned long maxDelay = 4095 );
//! Class destructor.
virtual ~Delay();
//! Clears the internal state of the delay line.
void clear();
~Delay();
//! Set the maximum delay-line length.
/*!
@@ -52,19 +44,16 @@ public:
likely occur. If the current maximum length is greater than the
new length, no change will be made.
*/
void setMaximumDelay(unsigned long delay);
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.
The valid range for \e delay is from 0 to the maximum delay-line length.
*/
void setDelay(unsigned long delay);
void setDelay( unsigned long delay );
//! Return the current delay-line length.
unsigned long getDelay(void) const;
//! Calculate and return the signal energy in the delay-line.
StkFloat energy(void) const;
unsigned long getDelay( void ) const { return delay_; };
//! Return the value at \e tapDelay samples from the delay-line input.
/*!
@@ -72,39 +61,114 @@ public:
relative to the last input value (i.e., a tapDelay of zero returns
the last input value).
*/
StkFloat contentsAt(unsigned long tapDelay);
StkFloat contentsAt( unsigned long tapDelay );
//! Return the last computed output value.
StkFloat lastOut(void) const;
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Return the value which will be output by the next call to tick().
//! Return the value that will be output by the next call to tick().
/*!
This method is valid only for delay settings greater than zero!
*/
virtual StkFloat nextOut(void);
StkFloat nextOut( void ) { return inputs_[outPoint_]; };
//! Calculate and return the signal energy in the delay-line.
StkFloat energy( void ) const;
//! Input one sample to the filter and return one output.
virtual StkFloat tick(StkFloat sample);
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
The StkFrames argument reference is returned. The \c channel
argument must be less than the number of channels in the
StkFrames argument (the first channel is specified by 0).
However, range checking is only performed if _STK_DEBUG_ is
defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Take a channel of the \c iFrames object as inputs to the filter and write outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. Each channel
argument must be less than the number of channels in the
corresponding StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
protected:
// This function must be implemented in all subclasses. It is used
// to get around a C++ problem with overloaded virtual functions.
virtual StkFloat computeSample( StkFloat input );
unsigned long inPoint_;
unsigned long outPoint_;
StkFloat delay_;
unsigned long delay_;
};
inline StkFloat Delay :: tick( StkFloat input )
{
inputs_[inPoint_++] = input * gain_;
// Check for end condition
if ( inPoint_ == inputs_.size() )
inPoint_ = 0;
// Read out next value
lastFrame_[0] = inputs_[outPoint_++];
if ( outPoint_ == inputs_.size() )
outPoint_ = 0;
return lastFrame_[0];
}
inline StkFrames& Delay :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "Delay::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
inputs_[inPoint_++] = *samples * gain_;
if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
*samples = inputs_[outPoint_++];
if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
}
lastFrame_[0] = *(samples-hop);
return frames;
}
inline StkFrames& Delay :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
{
#if defined(_STK_DEBUG_)
if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
errorString_ << "Delay::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *iSamples = &iFrames[iChannel];
StkFloat *oSamples = &oFrames[oChannel];
unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
inputs_[inPoint_++] = *iSamples * gain_;
if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
*oSamples = inputs_[outPoint_++];
if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
}
lastFrame_[0] = *(oSamples-oHop);
return iFrames;
}
} // stk namespace
#endif

View File

@@ -1,12 +1,18 @@
#ifndef STK_DELAYA_H
#define STK_DELAYA_H
#include "Filter.h"
namespace stk {
/***************************************************/
/*! \class DelayA
\brief STK allpass interpolating delay line class.
This Delay subclass implements a fractional-length digital
delay-line using a first-order allpass filter. A fixed maximum
length of 4095 and a delay of 0.5 is set using the default
constructor. Alternatively, the delay and maximum length can be
set during instantiation with an overloaded constructor.
This class implements a fractional-length digital delay-line using
a first-order allpass filter. If the delay and maximum length are
not specified during instantiation, a fixed maximum length of 4095
and a delay of 0.5 is set.
An allpass filter has unity magnitude gain but variable phase
delay properties, making it useful in achieving fractional delays
@@ -15,55 +21,94 @@
minimum delay possible in this implementation is limited to a
value of 0.5.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_DELAYA_H
#define STK_DELAYA_H
#include "Delay.h"
class DelayA : public Delay
class DelayA : public Filter
{
public:
//! Default constructor creates a delay-line with maximum length of 4095 samples and zero delay.
DelayA();
//! Overloaded constructor which specifies the current and maximum delay-line lengths.
//! Default constructor creates a delay-line with maximum length of 4095 samples and delay = 0.5.
/*!
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);
DelayA( StkFloat delay = 0.5, unsigned long maxDelay = 4095 );
//! Class destructor.
~DelayA();
//! Clears the internal state of the delay line.
void clear();
//! Clears all internal states of the delay line.
void clear( void );
//! 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.5 to the maximum delay-line length.
The valid range for \e delay is from 0.5 to the maximum delay-line length.
*/
void setDelay(StkFloat delay);
void setDelay( StkFloat delay );
//! Return the current delay-line length.
StkFloat getDelay(void) const;
StkFloat getDelay( void ) const { return delay_; };
//! Return the value at \e tapDelay samples from the delay-line input.
/*!
The tap point is determined modulo the delay-line length and is
relative to the last input value (i.e., a tapDelay of zero returns
the last input value).
*/
StkFloat contentsAt( unsigned long tapDelay );
//! Return the last computed output value.
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Return the value which will be output by the next call to tick().
/*!
This method is valid only for delay settings greater than zero!
*/
StkFloat nextOut(void);
StkFloat nextOut( void );
//! Input one sample to the filter and return one output.
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The StkFrames argument reference is returned. The \c channel
argument must be less than the number of channels in the
StkFrames argument (the first channel is specified by 0).
However, range checking is only performed if _STK_DEBUG_ is
defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Take a channel of the \c iFrames object as inputs to the filter and write outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. Each channel
argument must be less than the number of channels in the
corresponding StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
protected:
StkFloat computeSample( StkFloat input );
unsigned long inPoint_;
unsigned long outPoint_;
StkFloat delay_;
StkFloat alpha_;
StkFloat coeff_;
StkFloat apInput_;
@@ -71,4 +116,86 @@ protected:
bool doNextOut_;
};
inline StkFloat DelayA :: nextOut( void )
{
if ( doNextOut_ ) {
// Do allpass interpolation delay.
nextOutput_ = -coeff_ * lastFrame_[0];
nextOutput_ += apInput_ + ( coeff_ * inputs_[outPoint_] );
doNextOut_ = false;
}
return nextOutput_;
}
inline StkFloat DelayA :: tick( StkFloat input )
{
inputs_[inPoint_++] = input * gain_;
// Increment input pointer modulo length.
if ( inPoint_ == inputs_.size() )
inPoint_ = 0;
lastFrame_[0] = nextOut();
doNextOut_ = true;
// Save the allpass input and increment modulo length.
apInput_ = inputs_[outPoint_++];
if ( outPoint_ == inputs_.size() )
outPoint_ = 0;
return lastFrame_[0];
}
inline StkFrames& DelayA :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "DelayA::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
inputs_[inPoint_++] = *samples * gain_;
if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
*samples = nextOut();
lastFrame_[0] = *samples;
doNextOut_ = true;
apInput_ = inputs_[outPoint_++];
if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
}
return frames;
}
inline StkFrames& DelayA :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
{
#if defined(_STK_DEBUG_)
if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
errorString_ << "DelayA::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *iSamples = &iFrames[iChannel];
StkFloat *oSamples = &oFrames[oChannel];
unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
inputs_[inPoint_++] = *iSamples * gain_;
if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
*oSamples = nextOut();
lastFrame_[0] = *oSamples;
doNextOut_ = true;
apInput_ = inputs_[outPoint_++];
if ( outPoint_ == inputs_.size() ) outPoint_ = 0;
}
return iFrames;
}
} // stk namespace
#endif

View File

@@ -1,73 +1,197 @@
/***************************************************/
/*! \class DelayL
\brief STK linear interpolating delay line class.
This Delay subclass implements a fractional-
length digital delay-line using first-order
linear interpolation. A fixed maximum length
of 4095 and a delay of zero is set using the
default constructor. Alternatively, the
delay and maximum length can be set during
instantiation with an overloaded constructor.
Linear interpolation is an efficient technique
for achieving fractional delay lengths, though
it does introduce high-frequency signal
attenuation to varying degrees depending on the
fractional delay setting. The use of higher
order Lagrange interpolators can typically
improve (minimize) this attenuation characteristic.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
*/
/***************************************************/
#ifndef STK_DELAYL_H
#define STK_DELAYL_H
#include "Delay.h"
class DelayL : public Delay
namespace stk {
/***************************************************/
/*! \class DelayL
\brief STK linear interpolating delay line class.
This class implements a fractional-length digital delay-line using
first-order linear interpolation. If the delay and maximum length
are not specified during instantiation, a fixed maximum length of
4095 and a delay of zero is set.
Linear interpolation is an efficient technique for achieving
fractional delay lengths, though it does introduce high-frequency
signal attenuation to varying degrees depending on the fractional
delay setting. The use of higher order Lagrange interpolators can
typically improve (minimize) this attenuation characteristic.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
class DelayL : public Filter
{
public:
//! Default constructor creates a delay-line with maximum length of 4095 samples and zero delay.
DelayL();
//! Overloaded constructor which specifies the current and maximum delay-line lengths.
/*!
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);
DelayL( StkFloat delay = 0.0, unsigned long maxDelay = 4095 );
//! Class destructor.
~DelayL();
//! 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.
The valid range for \e delay is from 0 to the maximum delay-line length.
*/
void setDelay(StkFloat delay);
void setDelay( StkFloat delay );
//! Return the current delay-line length.
StkFloat getDelay(void) const;
StkFloat getDelay( void ) const { return delay_; };
//! Return the value at \e tapDelay samples from the delay-line input.
/*!
The tap point is determined modulo the delay-line length and is
relative to the last input value (i.e., a tapDelay of zero returns
the last input value).
*/
StkFloat contentsAt( unsigned long tapDelay );
//! Return the last computed output value.
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Return the value which will be output by the next call to tick().
/*!
This method is valid only for delay settings greater than zero!
*/
StkFloat nextOut(void);
StkFloat nextOut( void );
//! Input one sample to the filter and return one output.
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The StkFrames argument reference is returned. The \c channel
argument must be less than the number of channels in the
StkFrames argument (the first channel is specified by 0).
However, range checking is only performed if _STK_DEBUG_ is
defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Take a channel of the \c iFrames object as inputs to the filter and write outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. Each channel
argument must be less than the number of channels in the
corresponding StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
protected:
StkFloat computeSample( StkFloat input );
unsigned long inPoint_;
unsigned long outPoint_;
StkFloat delay_;
StkFloat alpha_;
StkFloat omAlpha_;
StkFloat nextOutput_;
bool doNextOut_;
};
inline StkFloat DelayL :: nextOut( void )
{
if ( doNextOut_ ) {
// First 1/2 of interpolation
nextOutput_ = inputs_[outPoint_] * omAlpha_;
// Second 1/2 of interpolation
if (outPoint_+1 < inputs_.size())
nextOutput_ += inputs_[outPoint_+1] * alpha_;
else
nextOutput_ += inputs_[0] * alpha_;
doNextOut_ = false;
}
return nextOutput_;
}
inline StkFloat DelayL :: tick( StkFloat input )
{
inputs_[inPoint_++] = input * gain_;
// Increment input pointer modulo length.
if ( inPoint_ == inputs_.size() )
inPoint_ = 0;
lastFrame_[0] = nextOut();
doNextOut_ = true;
// Increment output pointer modulo length.
if ( ++outPoint_ == inputs_.size() )
outPoint_ = 0;
return lastFrame_[0];
}
inline StkFrames& DelayL :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "DelayL::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
inputs_[inPoint_++] = *samples * gain_;
if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
*samples = nextOut();
doNextOut_ = true;
if ( ++outPoint_ == inputs_.size() ) outPoint_ = 0;
}
lastFrame_[0] = *(samples-hop);
return frames;
}
inline StkFrames& DelayL :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
{
#if defined(_STK_DEBUG_)
if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
errorString_ << "DelayL::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *iSamples = &iFrames[iChannel];
StkFloat *oSamples = &oFrames[oChannel];
unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
inputs_[inPoint_++] = *iSamples * gain_;
if ( inPoint_ == inputs_.size() ) inPoint_ = 0;
*oSamples = nextOut();
doNextOut_ = true;
if ( ++outPoint_ == inputs_.size() ) outPoint_ = 0;
}
lastFrame_[0] = *(oSamples-oHop);
return iFrames;
}
} // stk namespace
#endif

View File

@@ -1,3 +1,12 @@
#ifndef STK_DRUMMER_H
#define STK_DRUMMER_H
#include "Instrmnt.h"
#include "FileWvIn.h"
#include "OnePole.h"
namespace stk {
/***************************************************/
/*! \class Drummer
\brief STK drum sample player class.
@@ -11,17 +20,10 @@
of simultaneous voices) via a #define in the
Drummer.h.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_DRUMMER_H
#define STK_DRUMMER_H
#include "Instrmnt.h"
#include "FileWvIn.h"
#include "OnePole.h"
const int DRUM_NUMWAVES = 11;
const int DRUM_POLYPHONY = 4;
@@ -32,10 +34,10 @@ class Drummer : public Instrmnt
/*!
An StkError will be thrown if the rawwave path is incorrectly set.
*/
Drummer();
Drummer( void );
//! Class destructor.
~Drummer();
~Drummer( void );
//! Start a note with the given drum type and amplitude.
/*!
@@ -44,15 +46,16 @@ class Drummer : public Instrmnt
instrument. An StkError will be thrown if the rawwave path is
incorrectly set.
*/
void noteOn(StkFloat instrument, StkFloat amplitude);
void noteOn( StkFloat instrument, StkFloat amplitude );
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
void noteOff( StkFloat amplitude );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
FileWvIn waves_[DRUM_POLYPHONY];
OnePole filters_[DRUM_POLYPHONY];
std::vector<int> soundOrder_;
@@ -60,4 +63,30 @@ class Drummer : public Instrmnt
int nSounding_;
};
inline StkFloat Drummer :: tick( unsigned int )
{
lastFrame_[0] = 0.0;
if ( nSounding_ == 0 ) return lastFrame_[0];
for ( int i=0; i<DRUM_POLYPHONY; i++ ) {
if ( soundOrder_[i] >= 0 ) {
if ( waves_[i].isFinished() ) {
// Re-order the list.
for ( int j=0; j<DRUM_POLYPHONY; j++ ) {
if ( soundOrder_[j] > soundOrder_[i] )
soundOrder_[j] -= 1;
}
soundOrder_[i] = -1;
nSounding_--;
}
else
lastFrame_[0] += filters_[i].tick( waves_[i].tick() );
}
}
return lastFrame_[0];
}
} // stk namespace
#endif

View File

@@ -1,19 +1,21 @@
#ifndef STK_ECHO_H
#define STK_ECHO_H
#include "Effect.h"
#include "Delay.h"
namespace stk {
/***************************************************/
/*! \class Echo
\brief STK echo effect class.
This class implements an echo effect.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_ECHO_H
#define STK_ECHO_H
#include "Effect.h"
#include "Delay.h"
class Echo : public Effect
{
public:
@@ -23,9 +25,6 @@ class Echo : public Effect
*/
Echo( unsigned long maximumDelay = (unsigned long) Stk::sampleRate() );
//! Class destructor.
~Echo();
//! Reset and clear all internal state.
void clear();
@@ -35,14 +34,87 @@ class Echo : public Effect
//! Set the delay line length in samples.
void setDelay( unsigned long delay );
protected:
//! Return the last computed output value.
StkFloat lastOut( void ) const { return lastFrame_[0]; };
StkFloat computeSample( StkFloat input );
//! Input one sample to the effect and return one output.
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the effect and replace with corresponding outputs.
/*!
The StkFrames argument reference is returned. The \c channel
argument must be less than the number of channels in the
StkFrames argument (the first channel is specified by 0).
However, range checking is only performed if _STK_DEBUG_ is
defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Take a channel of the \c iFrames object as inputs to the effect and write outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. Each channel
argument must be less than the number of channels in the
corresponding StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
protected:
Delay delayLine_;
unsigned long length_;
};
inline StkFloat Echo :: tick( StkFloat input )
{
lastFrame_[0] = effectMix_ * ( delayLine_.tick( input ) - input ) + input;
return lastFrame_[0];
}
inline StkFrames& Echo :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "Echo::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
*samples = effectMix_ * ( delayLine_.tick( *samples ) - *samples ) + *samples;
}
lastFrame_[0] = *(samples-hop);
return frames;
}
inline StkFrames& Echo :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
{
#if defined(_STK_DEBUG_)
if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
errorString_ << "Echo::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *iSamples = &iFrames[iChannel];
StkFloat *oSamples = &oFrames[oChannel];
unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
*oSamples = effectMix_ * ( delayLine_.tick( *iSamples ) - *iSamples ) + *iSamples;
}
lastFrame_[0] = *(oSamples-oHop);
return iFrames;
}
} // stk namespace
#endif

View File

@@ -1,69 +1,79 @@
#ifndef STK_EFFECT_H
#define STK_EFFECT_H
#include "Stk.h"
#include <cmath>
namespace stk {
/***************************************************/
/*! \class Effect
\brief STK abstract effects parent class.
This class provides common functionality for
STK effects subclasses.
This class provides common functionality for STK effects
subclasses. It is general enough to support both monophonic and
polyphonic input/output classes.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#include "Stk.h"
#ifndef STK_EFFECT_H
#define STK_EFFECT_H
class Effect : public Stk
{
public:
//! Class constructor.
Effect();
Effect( void ) { lastFrame_.resize( 1, 1, 0.0 ); };
//! Class destructor.
virtual ~Effect();
//! Return the number of output channels for the class.
unsigned int channelsOut( void ) const { return lastFrame_.channels(); };
//! Return an StkFrames reference to the last output sample frame.
const StkFrames& lastFrame( void ) const { return lastFrame_; };
//! 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;
//! Take one sample input and compute one sample of output.
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the effect and replace with corresponding outputs.
/*!
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Set the mixture of input and "effected" levels in the output (0.0 = input only, 1.0 = effect only).
void setEffectMix( StkFloat mix );
protected:
// This abstract function must be implemented in all subclasses.
// It is used to get around a C++ problem with overloaded virtual
// functions.
virtual StkFloat computeSample( StkFloat input ) = 0;
// Returns true if argument value is prime.
bool isPrime( int number );
bool isPrime( unsigned int number );
StkFloat lastOutput_[2];
StkFrames lastFrame_;
StkFloat effectMix_;
};
inline 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;
}
inline bool Effect :: isPrime( unsigned int number )
{
if ( number == 2 ) return true;
if ( number & 1 ) {
for ( int i=3; i<(int)sqrt((double)number)+1; i+=2 )
if ( (number % i) == 0 ) return false;
return true; // prime
}
else return false; // even
}
} // stk namespace
#endif

View File

@@ -1,64 +1,76 @@
/***************************************************/
/*! \class Envelope
\brief STK envelope base class.
This class implements a simple envelope
generator which is capable of ramping to
a target value by a specified \e rate.
It also responds to simple \e keyOn and
\e keyOff messages, ramping to 1.0 on
keyOn and to 0.0 on keyOff.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
*/
/***************************************************/
#ifndef STK_ENVELOPE_H
#define STK_ENVELOPE_H
#include "Generator.h"
namespace stk {
/***************************************************/
/*! \class Envelope
\brief STK linear line envelope class.
This class implements a simple linear line envelope generator
which is capable of ramping to an arbitrary target value by a
specified \e rate. It also responds to simple \e keyOn and \e
keyOff messages, ramping to 1.0 on keyOn and to 0.0 on keyOff.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
class Envelope : public Generator
{
public:
//! Default constructor.
Envelope(void);
//! Copy constructor.
Envelope( const Envelope& e );
Envelope( void );
//! Class destructor.
virtual ~Envelope(void);
~Envelope( void );
//! Assignment operator.
Envelope& operator= ( const Envelope& e );
//! Set target = 1.
virtual void keyOn(void);
void keyOn( void ) { this->setTarget( 1.0 ); };
//! Set target = 0.
virtual void keyOff(void);
void keyOff( void ) { this->setTarget( 0.0 ); };
//! Set the \e rate.
void setRate(StkFloat rate);
void setRate( StkFloat rate );
//! Set the \e rate based on a time duration.
void setTime(StkFloat time);
void setTime( StkFloat time );
//! Set the target value.
virtual void setTarget(StkFloat target);
void setTarget( StkFloat target );
//! Set current and target values to \e aValue.
virtual void setValue(StkFloat value);
//! Set current and target values to \e value.
void setValue( StkFloat value );
//! Return the current envelope \e state (0 = at target, 1 otherwise).
virtual int getState(void) const;
int getState( void ) const { return state_; };
//! Return the last computed output value.
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Compute and return one output sample.
StkFloat tick( void );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument must be less than the number of
channels in the StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
protected:
virtual StkFloat computeSample( void );
virtual void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
StkFloat value_;
StkFloat target_;
@@ -66,4 +78,85 @@ class Envelope : public Generator
int state_;
};
inline void Envelope :: setRate( StkFloat rate )
{
#if defined(_STK_DEBUG_)
if ( rate < 0.0 ) {
errorString_ << "Envelope::setRate: negative rates not allowed ... correcting!";
handleError( StkError::WARNING );
rate_ = -rate;
}
else
#endif
rate_ = rate;
}
inline void Envelope :: setTime( StkFloat time )
{
#if defined(_STK_DEBUG_)
if ( time < 0.0 ) {
errorString_ << "Envelope::setTime: negative times not allowed ... correcting!";
handleError( StkError::WARNING );
rate_ = 1.0 / ( -time * Stk::sampleRate() );
}
else
#endif
rate_ = 1.0 / ( time * Stk::sampleRate() );
}
inline void Envelope :: setTarget( StkFloat target )
{
target_ = target;
if ( value_ != target_ ) state_ = 1;
}
inline void Envelope :: setValue( StkFloat value )
{
state_ = 0;
target_ = value;
value_ = value;
}
inline StkFloat Envelope :: tick( void )
{
if ( state_ ) {
if ( target_ > value_ ) {
value_ += rate_;
if ( value_ >= target_ ) {
value_ = target_;
state_ = 0;
}
}
else {
value_ -= rate_;
if ( value_ <= target_ ) {
value_ = target_;
state_ = 0;
}
}
lastFrame_[0] = value_;
}
return value_;
}
inline StkFrames& Envelope :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "Envelope::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
*samples = tick();
return frames;
}
} // stk namespace
#endif

View File

@@ -1,3 +1,14 @@
#ifndef STK_FM_H
#define STK_FM_H
#include "Instrmnt.h"
#include "ADSR.h"
#include "FileLoop.h"
#include "SineWave.h"
#include "TwoZero.h"
namespace stk {
/***************************************************/
/*! \class FM
\brief STK abstract FM synthesis base class.
@@ -19,19 +30,10 @@
type who should worry about this (making
money) worry away.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_FM_H
#define STK_FM_H
#include "Instrmnt.h"
#include "ADSR.h"
#include "WaveLoop.h"
#include "SineWave.h"
#include "TwoZero.h"
class FM : public Instrmnt
{
public:
@@ -42,53 +44,54 @@ class FM : public Instrmnt
FM( unsigned int operators = 4 );
//! Class destructor.
virtual ~FM();
virtual ~FM( void );
//! Reset and clear all wave and envelope states.
void clear();
void clear( void );
//! Load the rawwave filenames in waves.
void loadWaves(const char **filenames);
void loadWaves( const char **filenames );
//! Set instrument parameters for a particular frequency.
virtual void setFrequency(StkFloat frequency);
virtual void setFrequency( StkFloat frequency );
//! Set the frequency ratio for the specified wave.
void setRatio(unsigned int waveIndex, StkFloat ratio);
void setRatio( unsigned int waveIndex, StkFloat ratio );
//! Set the gain for the specified wave.
void setGain(unsigned int waveIndex, StkFloat gain);
void setGain( unsigned int waveIndex, StkFloat gain );
//! Set the modulation speed in Hz.
void setModulationSpeed(StkFloat mSpeed);
void setModulationSpeed( StkFloat mSpeed ) { vibrato_.setFrequency( mSpeed ); };
//! Set the modulation depth.
void setModulationDepth(StkFloat mDepth);
void setModulationDepth( StkFloat mDepth ) { modDepth_ = mDepth; };
//! Set the value of control1.
void setControl1(StkFloat cVal);
void setControl1( StkFloat cVal ) { control1_ = cVal * 2.0; };
//! Set the value of control1.
void setControl2(StkFloat cVal);
void setControl2( StkFloat cVal ) { control2_ = cVal * 2.0; };
//! Start envelopes toward "on" targets.
void keyOn();
void keyOn( void );
//! Start envelopes toward "off" targets.
void keyOff();
void keyOff( void );
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
void noteOff( StkFloat amplitude );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
virtual void controlChange(int number, StkFloat value);
virtual void controlChange( int number, StkFloat value );
//! Compute and return one output sample.
virtual StkFloat tick( unsigned int ) = 0;
protected:
virtual StkFloat computeSample( void ) = 0;
std::vector<ADSR *> adsr_;
std::vector<WaveLoop *> waves_;
std::vector<FileLoop *> waves_;
SineWave vibrato_;
TwoZero twozero_;
unsigned int nOperators_;
@@ -104,4 +107,6 @@ class FM : public Instrmnt
};
} // stk namespace
#endif

View File

@@ -1,3 +1,10 @@
#ifndef STK_FMVOICES_H
#define STK_FMVOICES_H
#include "FM.h"
namespace stk {
/***************************************************/
/*! \class FMVoices
\brief STK singing FM synthesis instrument.
@@ -26,15 +33,10 @@
type who should worry about this (making
money) worry away.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_FMVOICES_H
#define STK_FMVOICES_H
#include "FM.h"
class FMVoices : public FM
{
public:
@@ -42,27 +44,55 @@ class FMVoices : public FM
/*!
An StkError will be thrown if the rawwave path is incorrectly set.
*/
FMVoices();
FMVoices( void );
//! Class destructor.
~FMVoices();
~FMVoices( void );
//! Set instrument parameters for a particular frequency.
virtual void setFrequency(StkFloat frequency);
void setFrequency( StkFloat frequency );
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
virtual void controlChange(int number, StkFloat value);
void controlChange( int number, StkFloat value );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
int currentVowel_;
StkFloat tilt_[3];
StkFloat mods_[3];
};
inline StkFloat FMVoices :: tick( unsigned int )
{
register StkFloat temp, temp2;
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]->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();
lastFrame_[0] = temp * 0.33;
return lastFrame_[0];
}
} // stk namespace
#endif

161
include/FileLoop.h Normal file
View File

@@ -0,0 +1,161 @@
#ifndef STK_FILELOOP_H
#define STK_FILELOOP_H
#include "FileWvIn.h"
namespace stk {
/***************************************************/
/*! \class FileLoop
\brief STK file looping / oscillator class.
This class provides audio file looping functionality. Any audio
file that can be loaded by FileRead can be looped using this
class.
FileLoop supports multi-channel data. It is important to
distinguish the tick() method that computes a single frame (and
returns only the specified sample of a multi-channel frame) from
the overloaded one that takes an StkFrames object for
multi-channel and/or multi-frame data.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
class FileLoop : protected FileWvIn
{
public:
//! Default constructor.
FileLoop( unsigned long chunkThreshold = 1000000, unsigned long chunkSize = 1024 );
//! Class constructor that opens a specified file.
FileLoop( std::string fileName, bool raw = false, bool doNormalize = true,
unsigned long chunkThreshold = 1000000, unsigned long chunkSize = 1024 );
//! Class destructor.
~FileLoop( void );
//! Open the specified file and load its data.
/*!
Data from a previously opened file will be overwritten by this
function. An StkError will be thrown if the file is not found,
its format is unknown, or a read error occurs. If the file data
is to be loaded incrementally from disk and normalization is
specified, a scaling will be applied with respect to fixed-point
limits. If the data format is floating-point, no scaling is
performed.
*/
void openFile( std::string fileName, bool raw = false, bool doNormalize = true );
//! Close a file if one is open.
void closeFile( void ) { FileWvIn::closeFile(); };
//! Clear outputs and reset time (file) pointer to zero.
void reset( void ) { FileWvIn::reset(); };
//! Normalize data to a maximum of +-1.0.
/*!
This function has no effect when data is incrementally loaded
from disk.
*/
void normalize( void ) { FileWvIn::normalize( 1.0 ); };
//! Normalize data to a maximum of \e +-peak.
/*!
This function has no effect when data is incrementally loaded
from disk.
*/
void normalize( StkFloat peak ) { FileWvIn::normalize( peak ); };
//! Return the file size in sample frames.
unsigned long getSize( void ) const { return data_.frames(); };
//! Return the input file sample rate in Hz (not the data read rate).
/*!
WAV, SND, and AIF formatted files specify a sample rate in
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.
*/
StkFloat getFileRate( void ) const { return data_.dataRate(); };
//! Set the data read rate in samples. The rate can be negative.
/*!
If the rate value is negative, the data is read in reverse order.
*/
void setRate( StkFloat rate );
//! Set the data interpolation rate based on a looping frequency.
/*!
This function determines the interpolation rate based on the file
size and the current Stk::sampleRate. The \e frequency value
corresponds to file cycles per second. The frequency can be
negative, in which case the loop is read in reverse order.
*/
void setFrequency( StkFloat frequency ) { this->setRate( file_.fileSize() * frequency / Stk::sampleRate() ); };
//! Increment the read pointer by \e time samples, modulo file size.
void addTime( StkFloat time );
//! Increment current read pointer by \e angle, relative to a looping frequency.
/*!
This function increments the read pointer based on the file
size and the current Stk::sampleRate. The \e anAngle value
is a multiple of file size.
*/
void addPhase( StkFloat angle );
//! Add a phase offset to the current read pointer.
/*!
This function determines a time offset based on the file
size and the current Stk::sampleRate. The \e angle value
is a multiple of file size.
*/
void addPhaseOffset( StkFloat angle );
//! Return the specified channel value of the last computed frame.
/*!
For multi-channel files, use the lastFrame() function to get
all values from the last computed frame. If no file data is
loaded, the returned value is 0.0. The \c channel argument must
be less than the number of channels in the file data (the first
channel is specified by 0). However, range checking is only
performed if _STK_DEBUG_ is defined during compilation, in which
case an out-of-range value will trigger an StkError exception.
*/
StkFloat lastOut( unsigned int channel = 0 ) { return FileWvIn::lastOut( channel ); };
//! Compute a sample frame and return the specified \c channel value.
/*!
For multi-channel files, use the lastFrame() function to get
all values from the computed frame. If no file data is loaded,
the returned value is 0.0. The \c channel argument must be less
than the number of channels in the file data (the first channel is
specified by 0). However, range checking is only performed if
_STK_DEBUG_ is defined during compilation, in which case an
out-of-range value will trigger an StkError exception.
*/
StkFloat tick( unsigned int channel = 0 );
//! Fill the StkFrames argument with computed frames and return the same reference.
/*!
The number of channels in the StkFrames argument should equal
the number of channels in the file data. However, this is only
checked if _STK_DEBUG_ is defined during compilation, in which
case an incompatibility will trigger an StkError exception. If no
file data is loaded, the function does nothing (a warning will be
issued if _STK_DEBUG_ is defined during compilation and
Stk::showWarnings() has been set to \e true).
*/
StkFrames& tick( StkFrames& frames );
protected:
StkFrames firstFrame_;
StkFloat phaseOffset_;
};
} // stk namespace
#endif

View File

@@ -1,3 +1,10 @@
#ifndef STK_FILEREAD_H
#define STK_FILEREAD_H
#include "Stk.h"
namespace stk {
/***************************************************/
/*! \class FileRead
\brief STK audio file input class.
@@ -25,20 +32,15 @@
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 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_FILEREAD_H
#define STK_FILEREAD_H
#include "Stk.h"
class FileRead : public Stk
{
public:
//! Default constructor.
FileRead();
FileRead( void );
//! Overloaded constructor that opens a file during instantiation.
/*!
@@ -51,7 +53,7 @@ public:
StkFormat format = STK_SINT16, StkFloat rate = 22050.0 );
//! Class destructor.
~FileRead();
~FileRead( void );
//! Open the specified file and determine its formatting.
/*!
@@ -126,4 +128,6 @@ protected:
StkFloat fileRate_;
};
} // stk namespace
#endif

View File

@@ -1,3 +1,10 @@
#ifndef STK_FILEWRITE_H
#define STK_FILEWRITE_H
#include "Stk.h"
namespace stk {
/***************************************************/
/*! \class FileWrite
\brief STK audio file output class.
@@ -17,15 +24,10 @@
type, the data type will automatically be modified. Compressed
data types are not supported.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_FILEWRITE_H
#define STK_FILEWRITE_H
#include "Stk.h"
class FileWrite : public Stk
{
public:
@@ -39,7 +41,7 @@ class FileWrite : public Stk
static const FILE_TYPE FILE_MAT; /*!< Matlab MAT-file type. */
//! Default constructor.
FileWrite();
FileWrite( void );
//! Overloaded constructor used to specify a file name, type, and data format with this object.
/*!
@@ -109,4 +111,6 @@ class FileWrite : public Stk
};
} // stk namespace
#endif

View File

@@ -1,17 +1,26 @@
#ifndef STK_FILEWVIN_H
#define STK_FILEWVIN_H
#include "WvIn.h"
#include "FileRead.h"
namespace stk {
/***************************************************/
/*! \class FileWvIn
\brief STK audio file input class.
This class inherits from WvIn. It provides a "tick-level"
interface to the FileRead class. It also provides variable-rate
"playback" functionality. Audio file support is provided by the
FileRead class. Linear interpolation is used for fractional "read
rates".
playback functionality. Audio file support is provided by the
FileRead class. Linear interpolation is used for fractional read
rates.
FileWvIn supports multi-channel data. It is important to distinguish
the tick() methods, which return samples produced by averaging
across sample frames, from the tickFrame() methods, which return
references to multi-channel sample frames.
FileWvIn supports multi-channel data. It is important to
distinguish the tick() method that computes a single frame (and
returns only the specified sample of a multi-channel frame) from
the overloaded one that takes an StkFrames object for
multi-channel and/or multi-frame data.
FileWvIn will either load the entire content of an audio file into
local memory or incrementally read file data from disk in chunks.
@@ -21,22 +30,15 @@
chunks of \e chunkSize each (also in sample frames).
When the file end is reached, subsequent calls to the tick()
functions return zero-valued data and isFinished() returns \e
true.
functions return zeros and isFinished() returns \e true.
See the FileRead class for a description of the supported audio
file formats.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_FILEWVIN_H
#define STK_FILEWVIN_H
#include "WvIn.h"
#include "FileRead.h"
class FileWvIn : public WvIn
{
public:
@@ -52,7 +54,7 @@ public:
unsigned long chunkThreshold = 1000000, unsigned long chunkSize = 1024 );
//! Class destructor.
virtual ~FileWvIn();
~FileWvIn( void );
//! Open the specified file and load its data.
/*!
@@ -64,30 +66,30 @@ public:
limits. If the data format is floating-point, no scaling is
performed.
*/
void openFile( std::string fileName, bool raw = false, bool doNormalize = true );
virtual void openFile( std::string fileName, bool raw = false, bool doNormalize = true );
//! Close a file if one is open.
void closeFile( void );
virtual void closeFile( void );
//! Clear outputs and reset time (file) pointer to zero.
void reset( void );
virtual void reset( void );
//! Normalize data to a maximum of +-1.0.
/*!
This function has no effect when data is incrementally loaded
from disk.
*/
void normalize( void );
virtual void normalize( void );
//! Normalize data to a maximum of \e +-peak.
/*!
This function has no effect when data is incrementally loaded
from disk.
*/
void normalize( StkFloat peak );
virtual void normalize( StkFloat peak );
//! Return the file size in sample frames.
unsigned long getSize( void ) const { return data_.frames(); };
virtual unsigned long getSize( void ) const { return data_.frames(); };
//! Return the input file sample rate in Hz (not the data read rate).
/*!
@@ -95,7 +97,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.
*/
StkFloat getFileRate( void ) const { return data_.dataRate(); };
virtual StkFloat getFileRate( void ) const { return data_.dataRate(); };
//! Query whether reading is complete.
bool isFinished( void ) const { return finished_; };
@@ -104,7 +106,7 @@ public:
/*!
If the rate value is negative, the data is read in reverse order.
*/
void setRate( StkFloat rate );
virtual void setRate( StkFloat rate );
//! Increment the read pointer by \e time samples.
/*!
@@ -121,12 +123,44 @@ public:
*/
void setInterpolate( bool doInterpolate ) { interpolate_ = doInterpolate; };
StkFloat lastOut( void ) const;
//! Return the specified channel value of the last computed frame.
/*!
If no file is loaded, the returned value is 0.0. The \c
channel argument must be less than the number of output channels,
which can be determined with the channelsOut() function (the first
channel is specified by 0). However, range checking is only
performed if _STK_DEBUG_ is defined during compilation, in which
case an out-of-range value will trigger an StkError exception. \sa
lastFrame()
*/
StkFloat lastOut( unsigned int channel = 0 );
//! Compute a sample frame and return the specified \c channel value.
/*!
For multi-channel files, use the lastFrame() function to get
all values from the computed frame. If no file data is loaded,
the returned value is 0.0. The \c channel argument must be less
than the number of channels in the file data (the first channel is
specified by 0). However, range checking is only performed if
_STK_DEBUG_ is defined during compilation, in which case an
out-of-range value will trigger an StkError exception.
*/
virtual StkFloat tick( unsigned int channel = 0 );
//! Fill the StkFrames argument with computed frames and return the same reference.
/*!
The number of channels in the StkFrames argument must equal
the number of channels in the file data. However, this is only
checked if _STK_DEBUG_ is defined during compilation, in which
case an incompatibility will trigger an StkError exception. If no
file data is loaded, the function does nothing (a warning will be
issued if _STK_DEBUG_ is defined during compilation).
*/
virtual StkFrames& tick( StkFrames& frames );
protected:
virtual void computeFrame( void );
virtual void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
FileRead file_;
bool finished_;
@@ -141,4 +175,19 @@ protected:
};
inline StkFloat FileWvIn :: lastOut( unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= data_.channels() ) {
errorString_ << "FileWvIn::lastOut(): channel argument and soundfile data are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
if ( finished_ ) return 0.0;
return lastFrame_[channel];
}
} // stk namespace
#endif

View File

@@ -1,3 +1,11 @@
#ifndef STK_FILEWVOUT_H
#define STK_FILEWVOUT_H
#include "WvOut.h"
#include "FileWrite.h"
namespace stk {
/***************************************************/
/*! \class FileWvOut
\brief STK audio file output class.
@@ -7,9 +15,9 @@
FileWvOut writes samples to an audio file and supports
multi-channel data. It is important to distinguish the tick()
methods, which output single samples to all channels in a sample
frame, from the tickFrame() methods, which take a pointer or
reference to multi-channel sample frame data.
method that outputs a single sample to all channels in a sample
frame from the overloaded one that takes a reference to an
StkFrames object for multi-channel and/or multi-frame data.
See the FileWrite class for a description of the supported audio
file formats.
@@ -17,16 +25,10 @@
Currently, FileWvOut is non-interpolating and the output rate is
always Stk::sampleRate().
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_FILEWVOUT_H
#define STK_FILEWVOUT_H
#include "WvOut.h"
#include "FileWrite.h"
class FileWvOut : public WvOut
{
public:
@@ -69,12 +71,23 @@ class FileWvOut : public WvOut
*/
void closeFile( void );
//! Output a single sample to all channels in a sample frame.
/*!
An StkError is thrown if an output error occurs.
*/
void tick( const StkFloat sample );
//! Output the StkFrames data.
/*!
An StkError will be thrown if an output error occurs. An
StkError will also be thrown if _STK_DEBUG_ is defined during
compilation and there is an incompatability between the number of
channels in the FileWvOut object and that in the StkFrames object.
*/
void tick( const StkFrames& frames );
protected:
void computeSample( const StkFloat sample );
void computeFrames( const StkFrames& frames );
void incrementFrame( void );
FileWrite file_;
@@ -84,4 +97,6 @@ class FileWvOut : public WvOut
};
} // stk namespace
#endif

View File

@@ -1,122 +1,86 @@
/***************************************************/
/*! \class Filter
\brief STK filter class.
This class implements a generic structure that
can be used to create a wide range of filters.
It can function independently or be subclassed
to provide more specific controls based on a
particular filter type.
In particular, this class implements the standard
difference equation:
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
are normalized by a[0].
The \e gain parameter is applied at the filter
input and does not affect the coefficient values.
The default gain value is 1.0. This structure
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 - 2007.
*/
/***************************************************/
#ifndef STK_FILTER_H
#define STK_FILTER_H
#include "Stk.h"
#include <vector>
namespace stk {
/***************************************************/
/*! \class Filter
\brief STK abstract filter class.
This class provides limited common functionality for STK digital
filter subclasses. It is general enough to support both
monophonic and polyphonic input/output classes.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
class Filter : public Stk
{
public:
//! Default constructor creates a zero-order pass-through "filter".
Filter(void);
//! Class constructor.
Filter( void ) { gain_ = 1.0; channelsIn_ = 1; lastFrame_.resize( 1, 1, 0.0 ); };
//! Overloaded constructor which takes filter coefficients.
/*!
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( std::vector<StkFloat> &bCoefficients, std::vector<StkFloat> &aCoefficients );
//! Return the number of input channels for the class.
unsigned int channelsIn( void ) const { return channelsIn_; };
//! Class destructor.
virtual ~Filter(void);
//! Return the number of output channels for the class.
unsigned int channelsOut( void ) const { return lastFrame_.channels(); };
//! Sets all internal states of the filter to zero.
void clear(void);
//! Set filter coefficients.
/*!
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 not cleared unless the
\e clearState flag is \c true.
*/
void setCoefficients( std::vector<StkFloat> &bCoefficients, std::vector<StkFloat> &aCoefficients, bool clearState = false );
//! Set numerator coefficients.
/*!
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 not
cleared unless the \e clearState flag is \c true.
*/
void setNumerator( std::vector<StkFloat> &bCoefficients, bool clearState = false );
//! Set denominator coefficients.
/*!
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 not cleared
unless the \e clearState flag is \c true.
*/
void setDenominator( std::vector<StkFloat> &aCoefficients, bool clearState = false );
//! Clears all internal states of the filter.
virtual void clear( void );
//! 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(StkFloat gain);
void setGain( StkFloat gain ) { gain_ = gain; };
//! Return the current filter gain.
virtual StkFloat getGain(void) const;
StkFloat getGain( void ) const { return gain_; };
//! Return the last computed output value.
virtual StkFloat lastOut(void) const;
//! Input one sample to the filter and return one output.
virtual StkFloat tick( StkFloat input );
//! Return an StkFrames reference to the last output sample frame.
const StkFrames& lastFrame( void ) const { return lastFrame_; };
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
The StkFrames argument reference is returned. The \c channel
argument must be less than the number of channels in the
StkFrames argument (the first channel is specified by 0).
However, range checking is only performed if _STK_DEBUG_ is
defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ) = 0;
protected:
unsigned int channelsIn_;
StkFrames lastFrame_;
StkFloat gain_;
std::vector<StkFloat> b_;
std::vector<StkFloat> a_;
std::vector<StkFloat> outputs_;
std::vector<StkFloat> inputs_;
StkFrames outputs_;
StkFrames inputs_;
};
inline void Filter :: clear( void )
{
unsigned int i;
for ( i=0; i<inputs_.size(); i++ )
inputs_[i] = 0.0;
for ( i=0; i<outputs_.size(); i++ )
outputs_[i] = 0.0;
for ( i=0; i<lastFrame_.size(); i++ )
lastFrame_[i] = 0.0;
}
} // stk namespace
#endif

155
include/Fir.h Normal file
View File

@@ -0,0 +1,155 @@
#ifndef STK_FIR_H
#define STK_FIR_H
#include "Filter.h"
namespace stk {
/***************************************************/
/*! \class Fir
\brief STK general finite impulse response filter class.
This class provides a generic digital filter structure that can be
used to implement FIR filters. For filters with feedback terms,
the Iir class should be used.
In particular, this class implements the standard difference
equation:
y[n] = b[0]*x[n] + ... + b[nb]*x[n-nb]
The \e gain parameter is applied at the filter input and does not
affect the coefficient values. The default gain value is 1.0.
This structure 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 - 2009.
*/
/***************************************************/
class Fir : public Filter
{
public:
//! Default constructor creates a zero-order pass-through "filter".
Fir( void );
//! Overloaded constructor which takes filter coefficients.
/*!
An StkError can be thrown if the coefficient vector size is
zero.
*/
Fir( std::vector<StkFloat> &coefficients );
//! Class destructor.
~Fir( void );
//! Set filter coefficients.
/*!
An StkError can be thrown if the coefficient vector size is
zero. The internal state of the filter is not cleared unless the
\e clearState flag is \c true.
*/
void setCoefficients( std::vector<StkFloat> &coefficients, bool clearState = false );
//! Return the last computed output value.
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Input one sample to the filter and return one output.
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The StkFrames argument reference is returned. The \c channel
argument must be less than the number of channels in the
StkFrames argument (the first channel is specified by 0).
However, range checking is only performed if _STK_DEBUG_ is
defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Take a channel of the \c iFrames object as inputs to the filter and write outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. Each channel
argument must be less than the number of channels in the
corresponding StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
protected:
};
inline StkFloat Fir :: tick( StkFloat input )
{
lastFrame_[0] = 0.0;
inputs_[0] = gain_ * input;
for ( unsigned int i=b_.size()-1; i>0; i-- ) {
lastFrame_[0] += b_[i] * inputs_[i];
inputs_[i] = inputs_[i-1];
}
lastFrame_[0] += b_[0] * inputs_[0];
return lastFrame_[0];
}
inline StkFrames& Fir :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "Fir::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int i, hop = frames.channels();
for ( unsigned int j=0; j<frames.frames(); j++, samples += hop ) {
inputs_[0] = gain_ * *samples;
*samples = 0.0;
for ( i=b_.size()-1; i>0; i-- ) {
*samples += b_[i] * inputs_[i];
inputs_[i] = inputs_[i-1];
}
*samples += b_[0] * inputs_[0];
}
lastFrame_[0] = *(samples-hop);
return frames;
}
inline StkFrames& Fir :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
{
#if defined(_STK_DEBUG_)
if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
errorString_ << "Fir::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *iSamples = &iFrames[iChannel];
StkFloat *oSamples = &oFrames[oChannel];
unsigned int i, iHop = iFrames.channels(), oHop = oFrames.channels();
for ( unsigned int j=0; j<iFrames.frames(); j++, iSamples += iHop, oSamples += oHop ) {
inputs_[0] = gain_ * *iSamples;
*oSamples = 0.0;
for ( i=b_.size()-1; i>0; i-- ) {
*oSamples += b_[i] * inputs_[i];
inputs_[i] = inputs_[i-1];
}
*oSamples += b_[0] * inputs_[0];
}
lastFrame_[0] = *(oSamples-oHop);
return iFrames;
}
} // stk namespace
#endif

View File

@@ -1,3 +1,17 @@
#ifndef STK_FLUTE_H
#define STK_FLUTE_H
#include "Instrmnt.h"
#include "JetTable.h"
#include "DelayL.h"
#include "OnePole.h"
#include "PoleZero.h"
#include "Noise.h"
#include "ADSR.h"
#include "SineWave.h"
namespace stk {
/***************************************************/
/*! \class Flute
\brief STK flute physical model class.
@@ -18,22 +32,10 @@
- Vibrato Gain = 1
- Breath Pressure = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_FLUTE_H
#define STK_FLUTE_H
#include "Instrmnt.h"
#include "JetTable.h"
#include "DelayL.h"
#include "OnePole.h"
#include "PoleZero.h"
#include "Noise.h"
#include "ADSR.h"
#include "SineWave.h"
class Flute : public Instrmnt
{
public:
@@ -41,45 +43,46 @@ class Flute : public Instrmnt
/*!
An StkError will be thrown if the rawwave path is incorrectly set.
*/
Flute(StkFloat lowestFrequency);
Flute( StkFloat lowestFrequency );
//! Class destructor.
~Flute();
~Flute( void );
//! Reset and clear all internal state.
void clear();
void clear( void );
//! Set instrument parameters for a particular frequency.
void setFrequency(StkFloat frequency);
void setFrequency( StkFloat frequency );
//! Set the reflection coefficient for the jet delay (-1.0 - 1.0).
void setJetReflection(StkFloat coefficient);
void setJetReflection( StkFloat coefficient );
//! Set the reflection coefficient for the air column delay (-1.0 - 1.0).
void setEndReflection(StkFloat 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(StkFloat aRatio);
void setJetDelay( StkFloat aRatio );
//! Apply breath velocity to instrument with given amplitude and rate of increase.
void startBlowing(StkFloat amplitude, StkFloat rate);
void startBlowing( StkFloat amplitude, StkFloat rate );
//! Decrease breath velocity with given rate of decrease.
void stopBlowing(StkFloat rate);
void stopBlowing( StkFloat rate );
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
void noteOff( StkFloat amplitude );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
void controlChange( int number, StkFloat value );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
DelayL jetDelay_;
DelayL boreDelay_;
JetTable jetTable_;
@@ -100,4 +103,27 @@ class Flute : public Instrmnt
};
inline StkFloat Flute :: tick( unsigned int )
{
StkFloat pressureDiff;
StkFloat breathPressure;
// Calculate the breath pressure (envelope + noise + vibrato)
breathPressure = maxPressure_ * adsr_.tick();
breathPressure += breathPressure * ( noiseGain_ * noise_.tick() + vibratoGain_ * vibrato_.tick() );
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);
lastFrame_[0] = (StkFloat) 0.3 * boreDelay_.tick( pressureDiff );
lastFrame_[0] *= outputGain_;
return lastFrame_[0];
}
} // stk namespace
#endif

View File

@@ -1,32 +1,35 @@
#ifndef STK_FORMSWEP_H
#define STK_FORMSWEP_H
#include "Filter.h"
namespace stk {
/***************************************************/
/*! \class FormSwep
\brief STK sweepable formant filter class.
This public BiQuad filter subclass implements
a formant (resonance) which can be "swept"
over time from one frequency setting to another.
It provides methods for controlling the sweep
rate and target frequency.
This class implements a formant (resonance) which can be "swept"
over time from one frequency setting to another. It provides
methods for controlling the sweep rate and target frequency.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_FORMSWEP_H
#define STK_FORMSWEP_H
#include "BiQuad.h"
class FormSwep : public BiQuad
class FormSwep : public Filter
{
public:
//! Default constructor creates a second-order pass-through filter.
FormSwep();
FormSwep( void );
//! Class destructor.
~FormSwep();
//! A function to enable/disable the automatic updating of class data when the STK sample rate changes.
void ignoreSampleRateChange( bool ignore = true ) { ignoreSampleRateChange_ = ignore; };
//! Sets the filter coefficients for a resonance at \e frequency (in Hz).
/*!
This method determines the filter coefficients corresponding to
@@ -39,13 +42,13 @@ class FormSwep : public BiQuad
the unit-circle (\e radius close to one), the narrower the
resulting resonance width.
*/
void setResonance(StkFloat frequency, StkFloat radius);
void setResonance( StkFloat frequency, StkFloat radius );
//! Set both the current and target resonance parameters.
void setStates(StkFloat frequency, StkFloat radius, StkFloat gain = 1.0);
void setStates( StkFloat frequency, StkFloat radius, StkFloat gain = 1.0 );
//! Set target resonance parameters.
void setTargets(StkFloat frequency, StkFloat radius, StkFloat gain = 1.0);
void setTargets( StkFloat frequency, StkFloat radius, StkFloat gain = 1.0 );
//! Set the sweep rate (between 0.0 - 1.0).
/*!
@@ -56,7 +59,7 @@ class FormSwep : public BiQuad
target values. A sweep rate of 0.0 will produce no
change in resonance parameters.
*/
void setSweepRate(StkFloat rate);
void setSweepRate( StkFloat rate );
//! Set the sweep rate in terms of a time value in seconds.
/*!
@@ -64,11 +67,39 @@ class FormSwep : public BiQuad
given time for the formant parameters to reach
their target values.
*/
void setSweepTime(StkFloat time);
void setSweepTime( StkFloat time );
//! Return the last computed output value.
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Input one sample to the filter and return a reference to one output.
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The StkFrames argument reference is returned. The \c channel
argument must be less than the number of channels in the
StkFrames argument (the first channel is specified by 0).
However, range checking is only performed if _STK_DEBUG_ is
defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Take a channel of the \c iFrames object as inputs to the filter and write outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. Each channel
argument must be less than the number of channels in the
corresponding StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
protected:
StkFloat computeSample( StkFloat input );
virtual void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
bool dirty_;
StkFloat frequency_;
@@ -87,4 +118,71 @@ class FormSwep : public BiQuad
};
inline StkFloat FormSwep :: tick( StkFloat input )
{
if ( dirty_ ) {
sweepState_ += sweepRate_;
if ( sweepState_ >= 1.0 ) {
sweepState_ = 1.0;
dirty_ = false;
radius_ = targetRadius_;
frequency_ = targetFrequency_;
gain_ = targetGain_;
}
else {
radius_ = startRadius_ + (deltaRadius_ * sweepState_);
frequency_ = startFrequency_ + (deltaFrequency_ * sweepState_);
gain_ = startGain_ + (deltaGain_ * sweepState_);
}
this->setResonance( frequency_, radius_ );
}
inputs_[0] = gain_ * input;
lastFrame_[0] = b_[0] * inputs_[0] + b_[1] * inputs_[1] + b_[2] * inputs_[2];
lastFrame_[0] -= a_[2] * outputs_[2] + a_[1] * outputs_[1];
inputs_[2] = inputs_[1];
inputs_[1] = inputs_[0];
outputs_[2] = outputs_[1];
outputs_[1] = lastFrame_[0];
return lastFrame_[0];
}
inline StkFrames& FormSwep :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "FormSwep::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
*samples = tick( *samples );
return frames;
}
inline StkFrames& FormSwep :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
{
#if defined(_STK_DEBUG_)
if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
errorString_ << "FormSwep::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *iSamples = &iFrames[iChannel];
StkFloat *oSamples = &oFrames[oChannel];
unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop )
*oSamples = tick( *iSamples );
return iFrames;
}
} // stk namespace
#endif

View File

@@ -1,54 +1,41 @@
#ifndef STK_FUNCTION_H
#define STK_FUNCTION_H
#include "Stk.h"
namespace stk {
/***************************************************/
/*! \class Function
\brief STK abstract function parent class.
This class provides common functionality for STK classes which
This class provides common functionality for STK classes that
implement tables or other types of input to output function
mappings.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#include "Stk.h"
#ifndef STK_FUNCTION_H
#define STK_FUNCTION_H
class Function : public Stk
{
public:
//! Class constructor.
Function();
Function( void ) { lastFrame_.resize( 1, 1, 0.0 ); };
//! Class destructor.
virtual ~Function();
//! Return the last output value.
virtual StkFloat lastOut() const { return lastOutput_; };
//! Return the last computed output sample.
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Take one sample input and compute one sample of output.
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the function and replace with corresponding outputs.
/*!
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
*/
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
virtual StkFloat tick( StkFloat input ) = 0;
protected:
// This abstract function must be implemented in all subclasses.
// It is used to get around a C++ problem with overloaded virtual
// functions.
virtual StkFloat computeSample( StkFloat input ) = 0;
StkFloat lastOutput_;
StkFrames lastFrame_;
};
} // stk namespace
#endif

View File

@@ -1,53 +1,50 @@
/***************************************************/
/*! \class Generator
\brief STK abstract unit generator parent class.
This class provides common functionality for
STK unit generator sample-source subclasses.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
*/
/***************************************************/
#ifndef STK_GENERATOR_H
#define STK_GENERATOR_H
#include "Stk.h"
namespace stk {
/***************************************************/
/*! \class Generator
\brief STK abstract unit generator parent class.
This class provides limited common functionality for STK unit
generator sample-source subclasses. It is general enough to
support both monophonic and polyphonic output classes.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
class Generator : public Stk
{
public:
//! Class constructor.
Generator( void );
Generator( void ) { lastFrame_.resize( 1, 1, 0.0 ); };
//! Class destructor.
virtual ~Generator( void );
//! Return the number of output channels for the class.
unsigned int channelsOut( void ) const { return lastFrame_.channels(); };
//! Return the last output value.
virtual StkFloat lastOut( void ) const { return lastOutput_; };
//! Return an StkFrames reference to the last output sample frame.
const StkFrames& lastFrame( void ) const { return lastFrame_; };
//! Compute one sample and output.
StkFloat tick( void );
//! Fill a channel of the StkFrames object with computed outputs.
//! Fill the StkFrames object with computed sample frames, starting at the specified channel.
/*!
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
The \c channel argument plus the number of output channels must
be less than the number of channels in the StkFrames argument (the
first channel is specified by 0). However, range checking is only
performed if _STK_DEBUG_ is defined during compilation, in which
case an out-of-range value will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ) = 0;
protected:
// This abstract function must be implemented in all subclasses.
// It is used to get around a C++ problem with overloaded virtual
// functions.
virtual StkFloat computeSample( void ) = 0;
StkFloat lastOutput_;
protected:
StkFrames lastFrame_;
};
#endif
} // stk namespace
#endif

View File

@@ -1,20 +1,3 @@
/***************************************************/
/*! \class Granulate
\brief STK granular synthesis class.
This class implements a real-time granular synthesis algorithm
that operates on an input soundfile. Currently, only monophonic
files are supported. Various functions are provided to allow
control over voice and grain parameters.
The functionality of this class is based on the program MacPod by
Chris Rolfe and Damian Keller, though there are likely to be a
number of differences in the actual implementation.
by Gary Scavone, 2005.
*/
/***************************************************/
#ifndef STK_GRANULATE_H
#define STK_GRANULATE_H
@@ -23,6 +6,25 @@
#include "Envelope.h"
#include "Noise.h"
namespace stk {
/***************************************************/
/*! \class Granulate
\brief STK granular synthesis class.
This class implements a real-time granular synthesis algorithm
that operates on an input soundfile. Multi-channel files are
supported. Various functions are provided to allow control over
voice and grain parameters.
The functionality of this class is based on the program MacPod by
Chris Rolfe and Damian Keller, though there are likely to be a
number of differences in the actual implementation.
by Gary Scavone, 2005 - 2009.
*/
/***************************************************/
class Granulate: public Generator
{
public:
@@ -33,7 +35,7 @@ class Granulate: public Generator
Granulate( unsigned int nVoices, std::string fileName, bool typeRaw = false );
//! Class destructor.
~Granulate();
~Granulate( void );
//! Load a monophonic soundfile to be "granulated".
/*!
@@ -47,7 +49,7 @@ class Granulate: public Generator
Multiple grains are offset from one another in time by grain
duration / nVoices.
*/
void reset();
void reset( void );
//! Set the number of simultaneous grain "voices" to use.
/*!
@@ -96,6 +98,30 @@ class Granulate: public Generator
*/
void setRandomFactor( StkFloat randomness = 0.1 );
//! Return the specified channel value of the last computed frame.
/*!
The \c channel argument must be less than the number of output
channels, which can be determined with the channelsOut() function
(the first channel is specified by 0). However, range checking is
only performed if _STK_DEBUG_ is defined during compilation, in
which case an out-of-range value will trigger an StkError
exception. \sa lastFrame()
*/
StkFloat lastOut( unsigned int channel = 0 );
//! Compute one sample frame and return the specified \c channel value.
StkFloat tick( unsigned int channel = 0 );
//! Fill the StkFrames object with computed sample frames, starting at the specified channel.
/*!
The \c channel argument plus the number of output channels must
be less than the number of channels in the StkFrames argument (the
first channel is specified by 0). However, range checking is only
performed if _STK_DEBUG_ is defined during compilation, in which
case an out-of-range value will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
enum GrainState {
GRAIN_STOPPED,
GRAIN_FADEIN,
@@ -124,7 +150,6 @@ class Granulate: public Generator
delayCount(0), counter(0), pointer(0), startPointer(0), repeats(0), state(GRAIN_STOPPED) {}
};
StkFloat computeSample( void );
void calculateGrain( Granulate::Grain& grain );
StkFrames data_;
@@ -144,4 +169,39 @@ class Granulate: public Generator
};
inline StkFloat Granulate :: lastOut( unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= lastFrame_.channels() ) {
errorString_ << "Granulate::lastOut(): channel argument is invalid!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
return lastFrame_[channel];
}
inline StkFrames& Granulate :: tick( StkFrames& frames, unsigned int channel )
{
unsigned int nChannels = lastFrame_.channels();
#if defined(_STK_DEBUG_)
if ( channel > frames.channels() - nChannels ) {
errorString_ << "Granulate::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int j, hop = frames.channels() - nChannels;
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
*samples++ = tick();
for ( j=1; j<nChannels; j++ )
*samples++ = lastFrame_[j];
}
return frames;
}
} // stk namespace
#endif

View File

@@ -1,3 +1,10 @@
#ifndef STK_HEVYMETL_H
#define STK_HEVYMETL_H
#include "FM.h"
namespace stk {
/***************************************************/
/*! \class HevyMetl
\brief STK heavy metal FM synthesis instrument.
@@ -24,15 +31,10 @@
type who should worry about this (making
money) worry away.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_HEVYMETL_H
#define STK_HEVYMETL_H
#include "FM.h"
class HevyMetl : public FM
{
public:
@@ -40,17 +42,48 @@ class HevyMetl : public FM
/*!
An StkError will be thrown if the rawwave path is incorrectly set.
*/
HevyMetl();
HevyMetl( void );
//! Class destructor.
~HevyMetl();
~HevyMetl( void );
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
};
inline StkFloat HevyMetl :: tick( unsigned int )
{
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 = 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);
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();
lastFrame_[0] = temp * 0.5;
return lastFrame_[0];
}
} // stk namespace
#endif

202
include/Iir.h Normal file
View File

@@ -0,0 +1,202 @@
#ifndef STK_IIR_H
#define STK_IIR_H
#include "Filter.h"
namespace stk {
/***************************************************/
/*! \class Iir
\brief STK general infinite impulse response filter class.
This class provides a generic digital filter structure that can be
used to implement IIR filters. For filters containing only
feedforward terms, the Fir class is slightly more efficient.
In particular, this class implements the standard difference
equation:
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 are normalized
by a[0].
The \e gain parameter is applied at the filter input and does not
affect the coefficient values. The default gain value is 1.0.
This structure 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 - 2009.
*/
/***************************************************/
class Iir : public Filter
{
public:
//! Default constructor creates a zero-order pass-through "filter".
Iir( void );
//! Overloaded constructor which takes filter coefficients.
/*!
An StkError can be thrown if either of the coefficient vector
sizes is zero, or if the a[0] coefficient is equal to zero.
*/
Iir( std::vector<StkFloat> &bCoefficients, std::vector<StkFloat> &aCoefficients );
//! Class destructor.
~Iir( void );
//! Set filter coefficients.
/*!
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 not cleared unless the
\e clearState flag is \c true.
*/
void setCoefficients( std::vector<StkFloat> &bCoefficients, std::vector<StkFloat> &aCoefficients, bool clearState = false );
//! Set numerator coefficients.
/*!
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 not
cleared unless the \e clearState flag is \c true.
*/
void setNumerator( std::vector<StkFloat> &bCoefficients, bool clearState = false );
//! Set denominator coefficients.
/*!
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 not cleared
unless the \e clearState flag is \c true.
*/
void setDenominator( std::vector<StkFloat> &aCoefficients, bool clearState = false );
//! Return the last computed output value.
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Input one sample to the filter and return one output.
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The StkFrames argument reference is returned. The \c channel
argument must be less than the number of channels in the
StkFrames argument (the first channel is specified by 0).
However, range checking is only performed if _STK_DEBUG_ is
defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Take a channel of the \c iFrames object as inputs to the filter and write outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. Each channel
argument must be less than the number of channels in the
corresponding StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
protected:
};
inline StkFloat Iir :: tick( StkFloat input )
{
unsigned int i;
outputs_[0] = 0.0;
inputs_[0] = gain_ * input;
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];
for ( i=a_.size()-1; i>0; i-- ) {
outputs_[0] += -a_[i] * outputs_[i];
outputs_[i] = outputs_[i-1];
}
lastFrame_[0] = outputs_[0];
return lastFrame_[0];
}
inline StkFrames& Iir :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "Iir::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int i, hop = frames.channels();
for ( unsigned int j=0; j<frames.frames(); j++, samples += hop ) {
outputs_[0] = 0.0;
inputs_[0] = gain_ * *samples;
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];
for ( i=a_.size()-1; i>0; i-- ) {
outputs_[0] += -a_[i] * outputs_[i];
outputs_[i] = outputs_[i-1];
}
*samples = outputs_[0];
}
lastFrame_[0] = *(samples-hop);
return frames;
}
inline StkFrames& Iir :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
{
#if defined(_STK_DEBUG_)
if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
errorString_ << "Iir::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *iSamples = &iFrames[iChannel];
StkFloat *oSamples = &oFrames[oChannel];
unsigned int i, iHop = iFrames.channels(), oHop = oFrames.channels();
for ( unsigned int j=0; j<iFrames.frames(); j++, iSamples += iHop, oSamples += oHop ) {
outputs_[0] = 0.0;
inputs_[0] = gain_ * *iSamples;
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];
for ( i=a_.size()-1; i>0; i-- ) {
outputs_[0] += -a_[i] * outputs_[i];
outputs_[i] = outputs_[i-1];
}
*oSamples = outputs_[0];
}
lastFrame_[0] = *(oSamples-oHop);
return iFrames;
}
} // stk namespace
#endif

View File

@@ -1,3 +1,14 @@
#ifndef STK_INETWVIN_H
#define STK_INETWVIN_H
#include "WvIn.h"
#include "TcpServer.h"
#include "UdpSocket.h"
#include "Thread.h"
#include "Mutex.h"
namespace stk {
/***************************************************/
/*! \class InetWvIn
\brief STK internet streaming input class.
@@ -8,10 +19,10 @@
supported.
InetWvIn supports multi-channel data. It is important to
distinguish the tick() methods, which return samples produced by
averaging across sample frames, from the tickFrame() methods,
which return references or pointers to multi-channel sample
frames.
distinguish the tick() method that computes a single frame (and
returns only the specified sample of a multi-channel frame) from
the overloaded one that takes an StkFrames object for
multi-channel and/or multi-frame data.
This class implements a socket server. When using the TCP
protocol, the server "listens" for a single remote connection
@@ -20,19 +31,10 @@
data type for the incoming stream is signed 16-bit integers,
though any of the defined StkFormats are permissible.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_INETWVIN_H
#define STK_INETWVIN_H
#include "WvIn.h"
#include "TcpServer.h"
#include "UdpSocket.h"
#include "Thread.h"
#include "Mutex.h"
typedef struct {
bool finished;
void *object;
@@ -69,9 +71,46 @@ public:
*/
bool isConnected( void );
//! Return the specified channel value of the last computed frame.
/*!
For multi-channel files, use the lastFrame() function to get
all values from the last computed frame. If no connection exists,
the returned value is 0.0. The \c channel argument must be less
than the number of channels in the data stream (the first channel
is specified by 0). However, range checking is only performed if
_STK_DEBUG_ is defined during compilation, in which case an
out-of-range value will trigger an StkError exception.
*/
StkFloat lastOut( unsigned int channel = 0 );
//! Compute a sample frame and return the specified \c channel value.
/*!
For multi-channel files, use the lastFrame() function to get
all values from the computed frame. If no connection exists, the
returned value is 0.0 (and a warning will be issued if _STK_DEBUG_
is defined during compilation). The \c channel argument must be
less than the number of channels in the data stream (the first
channel is specified by 0). However, range checking is only
performed if _STK_DEBUG_ is defined during compilation, in which
case an out-of-range value will trigger an StkError exception.
*/
StkFloat tick( unsigned int channel = 0 );
//! Fill the StkFrames argument with computed frames and return the same reference.
/*!
The number of channels in the StkFrames argument must equal the
number of channels specified in the listen() function. However,
this is only checked if _STK_DEBUG_ is defined during compilation,
in which case an incompatibility will trigger an StkError
exception. If no connection exists, the function does
nothing (a warning will be issued if _STK_DEBUG_ is defined during
compilation).
*/
StkFrames& tick( 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
// had to be made public for access from the thread.
// must be public for access from the thread.
void receive( void );
protected:
@@ -79,8 +118,6 @@ protected:
// Read buffered socket data into the data buffer ... will block if none available.
int readData( void );
void computeFrame( void );
Socket *soket_;
Thread thread_;
Mutex mutex_;
@@ -100,4 +137,21 @@ protected:
};
inline StkFloat InetWvIn :: lastOut( unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= data_.channels() ) {
errorString_ << "InetWvIn::lastOut(): channel argument and data stream are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
// If no connection and we've output all samples in the queue, return.
if ( !connected_ && bytesFilled_ == 0 && bufferCounter_ == 0 ) return 0.0;
return lastFrame_[channel];
}
} // stk namespace
#endif

View File

@@ -1,3 +1,11 @@
#ifndef STK_INETWVOUT_H
#define STK_INETWVOUT_H
#include "WvOut.h"
#include "Socket.h"
namespace stk {
/***************************************************/
/*! \class InetWvOut
\brief STK internet streaming output class.
@@ -7,25 +15,20 @@
order, if necessary, before being transmitted.
InetWvOut supports multi-channel data. It is important to
distinguish the tick() methods, which output single samples to all
channels in a sample frame, from the tickFrame() method, which
takes a reference to multi-channel sample frame data.
distinguish the tick() method that outputs a single sample to all
channels in a sample frame from the overloaded one that takes a
reference to an StkFrames object for multi-channel and/or
multi-frame data.
This class connects to a socket server, the 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
StkFormats are permissible.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_INETWVOUT_H
#define STK_INETWVOUT_H
#include "WvOut.h"
#include "Socket.h"
class InetWvOut : public WvOut
{
public:
@@ -51,14 +54,30 @@ class InetWvOut : public WvOut
std::string 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);
void disconnect( void );
//! Output a single sample to all channels in a sample frame.
/*!
An StkError is thrown if an output error occurs. If a socket
connection does not exist, the function does nothing (a warning
will be issued if _STK_DEBUG_ is defined during compilation).
*/
void tick( const StkFloat sample );
//! Output the StkFrames data.
/*!
An StkError will be thrown if an output error occurs. An
StkError will also be thrown if _STK_DEBUG_ is defined during
compilation and there is an incompatability between the number of
channels in the FileWvOut object and that in the StkFrames object.
If a socket connection does not exist, the function does nothing
(a warning will be issued if _STK_DEBUG_ is defined during
compilation).
*/
void tick( const StkFrames& frames );
protected:
void computeSample( const StkFloat sample );
void computeFrames( const StkFrames& frames );
void incrementFrame( void );
// Write a buffer of length frames via the socket connection.
@@ -74,4 +93,6 @@ class InetWvOut : public WvOut
Stk::StkFormat dataType_;
};
} // stk namespace
#endif

View File

@@ -1,70 +1,129 @@
/***************************************************/
/*! \class Instrmnt
\brief STK instrument abstract base class.
This class provides a common interface for
all STK instruments.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
*/
/***************************************************/
#ifndef STK_INSTRMNT_H
#define STK_INSTRMNT_H
#include "Stk.h"
namespace stk {
/***************************************************/
/*! \class Instrmnt
\brief STK instrument abstract base class.
This class provides a common interface for
all STK instruments.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
class Instrmnt : public Stk
{
public:
//! Default constructor.
Instrmnt();
//! Class destructor.
virtual ~Instrmnt();
//! Class constructor.
Instrmnt( void ) { lastFrame_.resize( 1, 1, 0.0 ); };
//! Start a note with the given frequency and amplitude.
virtual void noteOn(StkFloat frequency, StkFloat amplitude) = 0;
virtual void noteOn( StkFloat frequency, StkFloat amplitude ) = 0;
//! Stop a note with the given amplitude (speed of decay).
virtual void noteOff(StkFloat amplitude) = 0;
virtual void noteOff( StkFloat amplitude ) = 0;
//! Set instrument parameters for a particular frequency.
virtual void setFrequency(StkFloat frequency);
//! 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;
//! Compute one sample and output.
StkFloat tick( void );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
virtual void setFrequency( StkFloat frequency );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
virtual void controlChange(int number, StkFloat value);
//! Return the number of output channels for the class.
unsigned int channelsOut( void ) const { return lastFrame_.channels(); };
//! Return an StkFrames reference to the last output sample frame.
const StkFrames& lastFrame( void ) const { return lastFrame_; };
//! Return the specified channel value of the last computed frame.
/*!
The \c channel argument must be less than the number of output
channels, which can be determined with the channelsOut() function
(the first channel is specified by 0). However, range checking is
only performed if _STK_DEBUG_ is defined during compilation, in
which case an out-of-range value will trigger an StkError
exception. \sa lastFrame()
*/
StkFloat lastOut( unsigned int channel = 0 );
//! Compute one sample frame and return the specified \c channel value.
/*!
For monophonic instruments, the \c channel argument is ignored.
*/
virtual StkFloat tick( unsigned int channel = 0 ) = 0;
//! Fill the StkFrames object with computed sample frames, starting at the specified channel.
/*!
The \c channel argument plus the number of output channels must
be less than the number of channels in the StkFrames argument (the
first channel is specified by 0). However, range checking is only
performed if _STK_DEBUG_ is defined during compilation, in which
case an out-of-range value will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
protected:
// This abstract function must be implemented in all subclasses.
// It is used to get around a C++ problem with overloaded virtual
// functions.
virtual StkFloat computeSample( void ) = 0;
StkFloat lastOutput_;
StkFrames lastFrame_;
};
inline void Instrmnt :: setFrequency(StkFloat frequency)
{
errorString_ << "Instrmnt::setFrequency: virtual setFrequency function call!";
handleError( StkError::WARNING );
}
inline StkFloat Instrmnt :: lastOut( unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= lastFrame_.channels() ) {
errorString_ << "Instrmnt::lastOut(): channel argument is invalid!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
return lastFrame_[channel];
}
inline StkFrames& Instrmnt :: tick( StkFrames& frames, unsigned int channel )
{
unsigned int nChannels = lastFrame_.channels();
#if defined(_STK_DEBUG_)
if ( channel > frames.channels() - nChannels ) {
errorString_ << "Instrmnt::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int j, hop = frames.channels() - nChannels;
if ( nChannels == 1 ) {
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
*samples++ = tick();
}
else {
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
*samples++ = tick();
for ( j=1; j<nChannels; j++ )
*samples++ = lastFrame_[j];
}
}
return frames;
}
inline void Instrmnt :: controlChange( int number, StkFloat value )
{
errorString_ << "Instrmnt::controlChange: virtual function call!";
handleError( StkError::WARNING );
}
} // stk namespace
#endif

View File

@@ -1,24 +1,25 @@
/***************************************************/
/*! \class JCRev
\brief John Chowning's reverberator class.
This class is derived from the CLM JCRev
function, which is based on the use of
networks of simple allpass and comb delay
filters. This class implements three series
allpass units, followed by four parallel comb
filters, and two decorrelation delay lines in
parallel at the output.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
*/
/***************************************************/
#ifndef STK_JCREV_H
#define STK_JCREV_H
#include "Effect.h"
#include "Delay.h"
#include "Delay.h"
namespace stk {
/***************************************************/
/*! \class JCRev
\brief John Chowning's reverberator class.
This class takes a monophonic input signal and produces a stereo
output signal. It is derived from the CLM JCRev function, which
is based on the use of networks of simple allpass and comb delay
filters. This class implements three series allpass units,
followed by four parallel comb filters, and two decorrelation
delay lines in parallel at the output.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
class JCRev : public Effect
{
@@ -26,18 +27,58 @@ class JCRev : public Effect
//! Class constructor taking a T60 decay time argument (one second default value).
JCRev( StkFloat T60 = 1.0 );
//! Class destructor.
~JCRev();
//! Reset and clear all internal state.
void clear();
void clear( void );
//! Set the reverberation T60 decay time.
void setT60( StkFloat T60 );
protected:
//! Return the specified channel value of the last computed stereo frame.
/*!
Use the lastFrame() function to get both values of the last
computed stereo frame. The \c channel argument must be 0 or 1
(the first channel is specified by 0). However, range checking is
only performed if _STK_DEBUG_ is defined during compilation, in
which case an out-of-range value will trigger an StkError
exception.
*/
StkFloat lastOut( unsigned int channel = 0 );
StkFloat computeSample( StkFloat input );
//! Input one sample to the effect and return the specified \c channel value of the computed stereo frame.
/*!
Use the lastFrame() function to get both values of the computed
stereo output frame. The \c channel argument must be 0 or 1 (the
first channel is specified by 0). However, range checking is only
performed if _STK_DEBUG_ is defined during compilation, in which
case an out-of-range value will trigger an StkError exception.
*/
StkFloat tick( StkFloat input, unsigned int channel = 0 );
//! Take a channel of the StkFrames object as inputs to the effect and replace with stereo outputs.
/*!
The StkFrames argument reference is returned. The stereo
outputs are written to the StkFrames argument starting at the
specified \c channel. Therefore, the \c channel argument must be
less than ( channels() - 1 ) of the StkFrames argument (the first
channel is specified by 0). However, range checking is only
performed if _STK_DEBUG_ is defined during compilation, in which
case an out-of-range value will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Take a channel of the \c iFrames object as inputs to the effect and write stereo outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. The \c iChannel
argument must be less than the number of channels in the \c
iFrames argument (the first channel is specified by 0). The \c
oChannel argument must be less than ( channels() - 1 ) of the \c
oFrames argument. However, range checking is only performed if
_STK_DEBUG_ is defined during compilation, in which case an
out-of-range value will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
protected:
Delay allpassDelays_[3];
Delay combDelays_[4];
@@ -48,5 +89,70 @@ class JCRev : public Effect
};
inline StkFloat JCRev :: lastOut( unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel > 1 ) {
errorString_ << "JCRev::lastOut(): channel argument must be less than 2!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
return lastFrame_[channel];
}
inline StkFloat JCRev :: tick( StkFloat input, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel > 1 ) {
errorString_ << "JCRev::tick(): channel argument must be less than 2!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
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;
temp = allpassDelays_[1].lastOut();
temp1 = allpassCoefficient_ * temp;
temp1 += temp0;
allpassDelays_[1].tick(temp1);
temp1 = -(allpassCoefficient_ * temp1) + temp;
temp = allpassDelays_[2].lastOut();
temp2 = allpassCoefficient_ * temp;
temp2 += temp1;
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());
combDelays_[0].tick(temp3);
combDelays_[1].tick(temp4);
combDelays_[2].tick(temp5);
combDelays_[3].tick(temp6);
filtout = temp3 + temp4 + temp5 + temp6;
lastFrame_[0] = effectMix_ * (outLeftDelay_.tick(filtout));
lastFrame_[1] = effectMix_ * (outRightDelay_.tick(filtout));
temp = (1.0 - effectMix_) * input;
lastFrame_[0] += temp;
lastFrame_[1] += temp;
return lastFrame_[channel];
}
} // stk namespace
#endif

View File

@@ -1,3 +1,10 @@
#ifndef STK_JETTABL_H
#define STK_JETTABL_H
#include "Function.h"
namespace stk {
/***************************************************/
/*! \class JetTable
\brief STK jet table class.
@@ -9,28 +16,97 @@
Consult Fletcher and Rossing, Karjalainen,
Cook, and others for more information.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_JETTABL_H
#define STK_JETTABL_H
#include "Function.h"
class JetTable : public Function
{
public:
//! Default constructor.
JetTable();
//! Class destructor.
~JetTable();
//! Take one sample input and map to one sample of output.
StkFloat tick( StkFloat input );
protected:
//! Take a channel of the StkFrames object as inputs to the table and replace with corresponding outputs.
/*!
The StkFrames argument reference is returned. The \c channel
argument must be less than the number of channels in the
StkFrames argument (the first channel is specified by 0).
However, range checking is only performed if _STK_DEBUG_ is
defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
StkFloat computeSample( StkFloat input );
//! Take a channel of the \c iFrames object as inputs to the table and write outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. Each channel
argument must be less than the number of channels in the
corresponding StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
};
inline StkFloat JetTable :: tick( StkFloat input )
{
// Perform "table lookup" using a polynomial
// calculation (x^3 - x), which approximates
// the jet sigmoid behavior.
lastFrame_[0] = input * (input * input - 1.0);
// Saturate at +/- 1.0.
if ( lastFrame_[0] > 1.0 ) lastFrame_[0] = 1.0;
if ( lastFrame_[0] < -1.0 ) lastFrame_[0] = -1.0;
return lastFrame_[0];
}
inline StkFrames& JetTable :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "JetTable::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
*samples = *samples * (*samples * *samples - 1.0);
if ( *samples > 1.0) *samples = 1.0;
if ( *samples < -1.0) *samples = -1.0;
}
lastFrame_[0] = *(samples-hop);
return frames;
}
inline StkFrames& JetTable :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
{
#if defined(_STK_DEBUG_)
if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
errorString_ << "JetTable::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *iSamples = &iFrames[iChannel];
StkFloat *oSamples = &oFrames[oChannel];
unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
*oSamples = *oSamples * (*oSamples * *oSamples - 1.0);
if ( *oSamples > 1.0) *oSamples = 1.0;
if ( *oSamples < -1.0) *oSamples = -1.0;
}
lastFrame_[0] = *(oSamples-oHop);
return iFrames;
}
} // stk namespace
#endif

View File

@@ -1,3 +1,11 @@
#ifndef STK_MANDOLIN_H
#define STK_MANDOLIN_H
#include "PluckTwo.h"
#include "FileWvIn.h"
namespace stk {
/***************************************************/
/*! \class Mandolin
\brief STK mandolin instrument model class.
@@ -23,48 +31,75 @@
- String Detuning = 1
- Microphone Position = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_MANDOLIN_H
#define STK_MANDOLIN_H
#include "PluckTwo.h"
#include "FileWvIn.h"
class Mandolin : public PluckTwo
{
public:
//! Class constructor, taking the lowest desired playing frequency.
Mandolin(StkFloat lowestFrequency);
Mandolin( StkFloat lowestFrequency );
//! Class destructor.
~Mandolin();
~Mandolin( void );
//! Pluck the strings with the given amplitude (0.0 - 1.0) using the current frequency.
void pluck(StkFloat amplitude);
void pluck( StkFloat amplitude );
//! Pluck the strings with the given amplitude (0.0 - 1.0) and position (0.0 - 1.0).
void pluck(StkFloat amplitude,StkFloat position);
void pluck( StkFloat amplitude,StkFloat position );
//! Start a note with the given frequency and amplitude (0.0 - 1.0).
void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Set the body size (a value of 1.0 produces the "default" size).
void setBodySize(StkFloat size);
void setBodySize( StkFloat size );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
void controlChange( int number, StkFloat value );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
FileWvIn *soundfile_[12];
int mic_;
long dampTime_;
bool waveDone_;
};
inline StkFloat Mandolin :: tick( unsigned int )
{
StkFloat temp = 0.0;
if ( !waveDone_ ) {
// Scale the pluck excitation with comb
// filtering for the duration of the file.
temp = soundfile_[mic_]->tick() * pluckAmplitude_;
temp = temp - combDelay_.tick(temp);
waveDone_ = soundfile_[mic_]->isFinished();
}
// Damping hack to help avoid overflow on re-plucking.
if ( dampTime_ >=0 ) {
dampTime_ -= 1;
// Calculate 1st delay filtered reflection plus pluck excitation.
lastFrame_[0] = delayLine_.tick( filter_.tick( temp + (delayLine_.lastOut() * 0.7) ) );
// Calculate 2nd delay just like the 1st.
lastFrame_[0] += delayLine2_.tick( filter2_.tick( temp + (delayLine2_.lastOut() * 0.7) ) );
}
else { // No damping hack after 1 period.
// Calculate 1st delay filtered reflection plus pluck excitation.
lastFrame_[0] = delayLine_.tick( filter_.tick( temp + (delayLine_.lastOut() * loopGain_) ) );
// Calculate 2nd delay just like the 1st.
lastFrame_[0] += delayLine2_.tick( filter2_.tick( temp + (delayLine2_.lastOut() * loopGain_) ) );
}
lastFrame_[0] *= 0.3;
return lastFrame_[0];
}
} // stk namespace
#endif

View File

@@ -1,3 +1,11 @@
#ifndef STK_MESH2D_H
#define STK_MESH2D_H
#include "Instrmnt.h"
#include "OnePole.h"
namespace stk {
/***************************************************/
/*! \class Mesh2D
\brief Two-dimensional rectilinear waveguide mesh class.
@@ -24,12 +32,6 @@
*/
/***************************************************/
#ifndef STK_MESH2D_H
#define STK_MESH2D_H
#include "Instrmnt.h"
#include "OnePole.h"
const short NXMAX = 12;
const short NYMAX = 12;
@@ -37,45 +39,46 @@ class Mesh2D : public Instrmnt
{
public:
//! Class constructor, taking the x and y dimensions in samples.
Mesh2D(short nX, short nY);
Mesh2D( short nX, short nY );
//! Class destructor.
~Mesh2D();
~Mesh2D( void );
//! Reset and clear all internal state.
void clear();
void clear( void );
//! Set the x dimension size in samples.
void setNX(short lenX);
void setNX( short lenX );
//! Set the y dimension size in samples.
void setNY(short lenY);
void setNY( short lenY );
//! Set the x, y input position on a 0.0 - 1.0 scale.
void setInputPosition(StkFloat xFactor, StkFloat yFactor);
void setInputPosition( StkFloat xFactor, StkFloat yFactor );
//! Set the loss filters gains (0.0 - 1.0).
void setDecay(StkFloat decayFactor);
void setDecay( StkFloat decayFactor );
//! Impulse the mesh with the given amplitude (frequency ignored).
void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Stop a note with the given amplitude (speed of decay) ... currently ignored.
void noteOff(StkFloat amplitude);
void noteOff( StkFloat amplitude );
//! Calculate and return the signal energy stored in the mesh.
StkFloat energy();
StkFloat energy( void );
//! Input a sample to the mesh and compute one output sample.
StkFloat inputTick( StkFloat input );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
void controlChange( int number, StkFloat value );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
StkFloat tick0();
StkFloat tick1();
void clearMesh();
@@ -99,4 +102,6 @@ class Mesh2D : public Instrmnt
int counter_; // time in samples
};
} // stk namespace
#endif

View File

@@ -1,3 +1,21 @@
#ifndef STK_MESSAGER_H
#define STK_MESSAGER_H
#include "Stk.h"
#include "Skini.h"
#include <queue>
#if defined(__STK_REALTIME__)
#include "Mutex.h"
#include "Thread.h"
#include "TcpServer.h"
#include "RtMidi.h"
#endif // __STK_REALTIME__
namespace stk {
/***************************************************/
/*! \class Messager
\brief STK input control message parser.
@@ -28,32 +46,12 @@
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 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_MESSAGER_H
#define STK_MESSAGER_H
#include "Stk.h"
#include "Skini.h"
#include <queue>
const int DEFAULT_QUEUE_LIMIT = 200;
#if defined(__STK_REALTIME__)
#include "Mutex.h"
#include "Thread.h"
#include "TcpServer.h"
#include "RtMidi.h"
extern "C" THREAD_RETURN THREAD_TYPE stdinHandler(void * ptr);
extern "C" THREAD_RETURN THREAD_TYPE socketHandler(void * ptr);
#endif // __STK_REALTIME__
class Messager : public Stk
{
public:
@@ -163,4 +161,6 @@ class Messager : public Stk
};
} // stk namespace
#endif

View File

@@ -1,3 +1,14 @@
#ifndef STK_MIDIFILEIN_H
#define STK_MIDIFILEIN_H
#include "Stk.h"
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
namespace stk {
/**********************************************************************/
/*! \class MidiFileIn
\brief A standard MIDI file reading/parsing class.
@@ -11,19 +22,10 @@
Tempo changes are internally tracked by the class and reflected in
the values returned by the function getTickSeconds().
by Gary P. Scavone, 2003.
by Gary P. Scavone, 2003 - 2009.
*/
/**********************************************************************/
#ifndef STK_MIDIFILEIN_H
#define STK_MIDIFILEIN_H
#include "Stk.h"
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
class MidiFileIn : public Stk
{
public:
@@ -128,4 +130,6 @@ class MidiFileIn : public Stk
std::vector<unsigned int> trackTempoIndex_;
};
} // stk namespace
#endif

View File

@@ -1,26 +1,28 @@
#ifndef STK_MODAL_H
#define STK_MODAL_H
#include "Instrmnt.h"
#include "Envelope.h"
#include "FileLoop.h"
#include "SineWave.h"
#include "BiQuad.h"
#include "OnePole.h"
namespace stk {
/***************************************************/
/*! \class Modal
\brief STK resonance model instrument.
\brief STK resonance model abstract base class.
This class contains an excitation wavetable,
an envelope, an oscillator, and N resonances
(non-sweeping BiQuad filters), where N is set
during instantiation.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_MODAL_H
#define STK_MODAL_H
#include "Instrmnt.h"
#include "Envelope.h"
#include "WaveLoop.h"
#include "SineWave.h"
#include "BiQuad.h"
#include "OnePole.h"
class Modal : public Instrmnt
{
public:
@@ -31,45 +33,46 @@ public:
Modal( unsigned int modes = 4 );
//! Class destructor.
virtual ~Modal();
virtual ~Modal( void );
//! Reset and clear all internal state.
void clear();
void clear( void );
//! Set instrument parameters for a particular frequency.
virtual void setFrequency(StkFloat frequency);
virtual void setFrequency( StkFloat frequency );
//! Set the ratio and radius for a specified mode filter.
void setRatioAndRadius(unsigned int modeIndex, StkFloat ratio, StkFloat radius);
void setRatioAndRadius( unsigned int modeIndex, StkFloat ratio, StkFloat radius );
//! Set the master gain.
void setMasterGain(StkFloat aGain);
void setMasterGain( StkFloat aGain ) { masterGain_ = aGain; };
//! Set the direct gain.
void setDirectGain(StkFloat aGain);
void setDirectGain( StkFloat aGain ) { directGain_ = aGain; };
//! Set the gain for a specified mode filter.
void setModeGain(unsigned int modeIndex, StkFloat gain);
void setModeGain( unsigned int modeIndex, StkFloat gain );
//! Initiate a strike with the given amplitude (0.0 - 1.0).
virtual void strike(StkFloat amplitude);
virtual void strike( StkFloat amplitude );
//! Damp modes with a given decay factor (0.0 - 1.0).
void damp(StkFloat amplitude);
void damp( StkFloat amplitude );
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
void noteOff( StkFloat amplitude );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
virtual void controlChange(int number, StkFloat value) = 0;
virtual void controlChange( int number, StkFloat value ) = 0;
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
Envelope envelope_;
FileWvIn *wave_;
BiQuad **filters_;
@@ -88,4 +91,27 @@ protected:
StkFloat baseFrequency_;
};
inline StkFloat Modal :: tick( unsigned int )
{
StkFloat temp = masterGain_ * onepole_.tick( wave_->tick() * envelope_.tick() );
StkFloat temp2 = 0.0;
for ( unsigned int i=0; i<nModes_; i++ )
temp2 += filters_[i]->tick(temp);
temp2 -= temp2 * directGain_;
temp2 += directGain_ * temp;
if ( vibratoGain_ != 0.0 ) {
// Calculate AM and apply to master out
temp = 1.0 + ( vibrato_.tick() * vibratoGain_ );
temp2 = temp * temp2;
}
lastFrame_[0] = temp2;
return lastFrame_[0];
}
} // stk namespace
#endif

View File

@@ -1,3 +1,10 @@
#ifndef STK_MODALBAR_H
#define STK_MODALBAR_H
#include "Modal.h"
namespace stk {
/***************************************************/
/*! \class ModalBar
\brief STK resonant bar instrument class.
@@ -24,38 +31,35 @@
- Two Fixed = 7
- Clump = 8
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_MODALBAR_H
#define STK_MODALBAR_H
#include "Modal.h"
class ModalBar : public Modal
{
public:
//! Class constructor.
ModalBar();
ModalBar( void );
//! Class destructor.
~ModalBar();
~ModalBar( void );
//! Set stick hardness (0.0 - 1.0).
void setStickHardness(StkFloat hardness);
void setStickHardness( StkFloat hardness );
//! Set stick position (0.0 - 1.0).
void setStrikePosition(StkFloat position);
void setStrikePosition( StkFloat position );
//! Select a bar preset (currently modulo 9).
void setPreset(int preset);
void setPreset( int preset );
//! Set the modulation (vibrato) depth.
void setModulationDepth(StkFloat mDepth);
void setModulationDepth( StkFloat mDepth );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
void controlChange( int number, StkFloat value );
};
} // stk namespace
#endif

View File

@@ -1,3 +1,13 @@
#ifndef STK_MODULATE_H
#define STK_MODULATE_H
#include "Generator.h"
#include "SineWave.h"
#include "Noise.h"
#include "OnePole.h"
namespace stk {
/***************************************************/
/*! \class Modulate
\brief STK periodic/random modulator.
@@ -6,18 +16,10 @@
modulations to give a nice, natural human
modulation function.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_MODULATE_H
#define STK_MODULATE_H
#include "Generator.h"
#include "SineWave.h"
#include "SubNoise.h"
#include "OnePole.h"
class Modulate : public Generator
{
public:
@@ -25,33 +27,82 @@ class Modulate : public Generator
/*!
An StkError can be thrown if the rawwave path is incorrect.
*/
Modulate();
Modulate( void );
//! Class destructor.
~Modulate();
~Modulate( void );
//! Reset internal state.
void reset();
void reset( void ) { lastFrame_[0] = 0.0; };
//! Set the periodic (vibrato) rate or frequency in Hz.
void setVibratoRate(StkFloat rate);
void setVibratoRate( StkFloat rate ) { vibrato_.setFrequency( rate ); };
//! Set the periodic (vibrato) gain.
void setVibratoGain(StkFloat gain);
void setVibratoGain( StkFloat gain ) { vibratoGain_ = gain; };
//! Set the random modulation gain.
void setRandomGain(StkFloat gain);
void setRandomGain( StkFloat gain );
//! Return the last computed output value.
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Compute and return one output sample.
StkFloat tick( void );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument must be less than the number of
channels in the StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
SineWave vibrato_;
SubNoise noise_;
Noise noise_;
OnePole filter_;
StkFloat vibratoGain_;
StkFloat randomGain_;
unsigned int noiseRate_;
unsigned int noiseCounter_;
};
inline StkFloat Modulate :: tick( void )
{
// Compute periodic and random modulations.
lastFrame_[0] = vibratoGain_ * vibrato_.tick();
if ( noiseCounter_++ >= noiseRate_ ) {
noise_.tick();
noiseCounter_ = 0;
}
lastFrame_[0] += filter_.tick( noise_.lastOut() );
return lastFrame_[0];
}
inline StkFrames& Modulate :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "Modulate::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
*samples = Modulate::tick();
return frames;
}
} // stk namespace
#endif

View File

@@ -1,3 +1,11 @@
#ifndef STK_MOOG_H
#define STK_MOOG_H
#include "Sampler.h"
#include "FormSwep.h"
namespace stk {
/***************************************************/
/*! \class Moog
\brief STK moog-like swept filter sampling synthesis class.
@@ -14,16 +22,10 @@
- Vibrato Gain = 1
- Gain = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_MOOG_H
#define STK_MOOG_H
#include "Sampler.h"
#include "FormSwep.h"
class Moog : public Sampler
{
public:
@@ -31,30 +33,31 @@ class Moog : public Sampler
/*!
An StkError will be thrown if the rawwave path is incorrectly set.
*/
Moog();
Moog( void );
//! Class destructor.
~Moog();
~Moog( void );
//! Set instrument parameters for a particular frequency.
void setFrequency(StkFloat frequency);
void setFrequency( StkFloat frequency );
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Set the modulation (vibrato) speed in Hz.
void setModulationSpeed(StkFloat mSpeed);
void setModulationSpeed( StkFloat mSpeed ) { loops_[1]->setFrequency( mSpeed ); };
//! Set the modulation (vibrato) depth.
void setModulationDepth(StkFloat mDepth);
void setModulationDepth( StkFloat mDepth ) { modDepth_ = mDepth * 0.5; };
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
void controlChange( int number, StkFloat value );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
FormSwep filters_[2];
StkFloat modDepth_;
StkFloat filterQ_;
@@ -62,4 +65,24 @@ class Moog : public Sampler
};
inline StkFloat Moog :: tick( unsigned int )
{
StkFloat temp;
if ( modDepth_ != 0.0 ) {
temp = loops_[1]->tick() * modDepth_;
loops_[0]->setFrequency( baseFrequency_ * (1.0 + temp) );
}
temp = attackGain_ * attacks_[0]->tick();
temp += loopGain_ * loops_[0]->tick();
temp = filter_.tick( temp );
temp *= adsr_.tick();
temp = filters_[0].tick( temp );
lastFrame_[0] = filters_[1].tick( temp );
return lastFrame_[0] * 6.0;
}
} // stk namespace
#endif

View File

@@ -1,16 +1,3 @@
/***************************************************/
/*! \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 - 2007.
*/
/***************************************************/
#ifndef STK_MUTEX_H
#define STK_MUTEX_H
@@ -31,6 +18,21 @@
#endif
namespace stk {
/***************************************************/
/*! \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 - 2009.
*/
/***************************************************/
class Mutex : public Stk
{
public:
@@ -67,4 +69,6 @@ class Mutex : public Stk
};
} // stk namespace
#endif

View File

@@ -1,45 +1,85 @@
#ifndef STK_NREV_H
#define STK_NREV_H
#include "Effect.h"
#include "Delay.h"
namespace stk {
/***************************************************/
/*! \class NRev
\brief CCRMA's NRev reverberator class.
This class is derived from the CLM NRev
function, which is based on the use of
networks of simple allpass and comb delay
filters. This particular arrangement consists
of 6 comb filters in parallel, followed by 3
allpass filters, a lowpass filter, and another
allpass in series, followed by two allpass
filters in parallel with corresponding right
and left outputs.
This class takes a monophonic input signal and produces a stereo
output signal. It is derived from the CLM NRev function, which is
based on the use of networks of simple allpass and comb delay
filters. This particular arrangement consists of 6 comb filters
in parallel, followed by 3 allpass filters, a lowpass filter, and
another allpass in series, followed by two allpass filters in
parallel with corresponding right and left outputs.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_NREV_H
#define STK_NREV_H
#include "Effect.h"
#include "Delay.h"
class NRev : public Effect
{
public:
//! Class constructor taking a T60 decay time argument (one second default value).
NRev( StkFloat T60 = 1.0 );
//! Class destructor.
~NRev();
//! Reset and clear all internal state.
void clear();
void clear( void );
//! Set the reverberation T60 decay time.
void setT60( StkFloat T60 );
protected:
//! Return the specified channel value of the last computed stereo frame.
/*!
Use the lastFrame() function to get both values of the last
computed stereo frame. The \c channel argument must be 0 or 1
(the first channel is specified by 0). However, range checking is
only performed if _STK_DEBUG_ is defined during compilation, in
which case an out-of-range value will trigger an StkError
exception.
*/
StkFloat lastOut( unsigned int channel = 0 );
StkFloat computeSample( StkFloat input );
//! Input one sample to the effect and return the specified \c channel value of the computed stereo frame.
/*!
Use the lastFrame() function to get both values of the computed
stereo output frame. The \c channel argument must be 0 or 1 (the
first channel is specified by 0). However, range checking is only
performed if _STK_DEBUG_ is defined during compilation, in which
case an out-of-range value will trigger an StkError exception.
*/
StkFloat tick( StkFloat input, unsigned int channel = 0 );
//! Take a channel of the StkFrames object as inputs to the effect and replace with stereo outputs.
/*!
The StkFrames argument reference is returned. The stereo
outputs are written to the StkFrames argument starting at the
specified \c channel. Therefore, the \c channel argument must be
less than ( channels() - 1 ) of the StkFrames argument (the first
channel is specified by 0). However, range checking is only
performed if _STK_DEBUG_ is defined during compilation, in which
case an out-of-range value will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Take a channel of the \c iFrames object as inputs to the effect and write stereo outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. The \c iChannel
argument must be less than the number of channels in the \c
iFrames argument (the first channel is specified by 0). The \c
oChannel argument must be less than ( channels() - 1 ) of the \c
oFrames argument. However, range checking is only performed if
_STK_DEBUG_ is defined during compilation, in which case an
out-of-range value will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
protected:
Delay allpassDelays_[8];
Delay combDelays_[6];
@@ -49,5 +89,72 @@ class NRev : public Effect
};
inline StkFloat NRev :: lastOut( unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel > 1 ) {
errorString_ << "NRev::lastOut(): channel argument must be less than 2!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
return lastFrame_[channel];
}
inline StkFloat NRev :: tick( StkFloat input, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel > 1 ) {
errorString_ << "NRev::tick(): channel argument must be less than 2!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat temp, temp0, temp1, temp2, temp3;
int i;
temp0 = 0.0;
for ( i=0; i<6; i++ ) {
temp = input + (combCoefficient_[i] * combDelays_[i].lastOut());
temp0 += combDelays_[i].tick(temp);
}
for ( i=0; i<3; i++ ) {
temp = allpassDelays_[i].lastOut();
temp1 = allpassCoefficient_ * temp;
temp1 += temp0;
allpassDelays_[i].tick(temp1);
temp0 = -(allpassCoefficient_ * temp1) + temp;
}
// One-pole lowpass filter.
lowpassState_ = 0.7 * lowpassState_ + 0.3 * temp0;
temp = allpassDelays_[3].lastOut();
temp1 = allpassCoefficient_ * temp;
temp1 += lowpassState_;
allpassDelays_[3].tick( temp1 );
temp1 = -( allpassCoefficient_ * temp1 ) + temp;
temp = allpassDelays_[4].lastOut();
temp2 = allpassCoefficient_ * temp;
temp2 += temp1;
allpassDelays_[4].tick( temp2 );
lastFrame_[0] = effectMix_*( -( allpassCoefficient_ * temp2 ) + temp );
temp = allpassDelays_[5].lastOut();
temp3 = allpassCoefficient_ * temp;
temp3 += temp1;
allpassDelays_[5].tick( temp3 );
lastFrame_[1] = effectMix_*( - ( allpassCoefficient_ * temp3 ) + temp );
temp = ( 1.0 - effectMix_ ) * input;
lastFrame_[0] += temp;
lastFrame_[1] += temp;
return lastFrame_[channel];
}
} // stk namespace
#endif

View File

@@ -1,3 +1,10 @@
#ifndef STK_NOISE_H
#define STK_NOISE_H
#include "Generator.h"
namespace stk {
/***************************************************/
/*! \class Noise
\brief STK noise generator.
@@ -6,31 +13,20 @@
C rand() function. The quality of the rand()
function varies from one OS to another.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_NOISE_H
#define STK_NOISE_H
#include "Generator.h"
class Noise : public Generator
{
public:
//! Default constructor which seeds the random number generator with the system time.
Noise();
//! Constructor which seeds the random number generator with a given seed.
//! Default constructor that can also take a specific seed value.
/*!
If the seed value is zero, the random number generator is
If the seed value is zero (the default value), the random number generator is
seeded with the system time.
*/
Noise( unsigned int seed );
//! Class destructor.
virtual ~Noise();
Noise( unsigned int seed = 0 );
//! Seed the random number generator with a specific seed value.
/*!
@@ -39,10 +35,49 @@ public:
*/
void setSeed( unsigned int seed = 0 );
protected:
//! Return the last computed output value.
StkFloat lastOut( void ) const { return lastFrame_[0]; };
virtual StkFloat computeSample( void );
//! Compute and return one output sample.
StkFloat tick( void );
//! Fill a channel of the StkFrames object with computed outputs.
/*!
The \c channel argument must be less than the number of
channels in the StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
protected:
};
inline StkFloat Noise :: tick( void )
{
return lastFrame_[0] = (StkFloat) ( 2.0 * rand() / (RAND_MAX + 1.0) - 1.0 );
}
inline StkFrames& Noise :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "Noise::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
*samples = (StkFloat) ( 2.0 * rand() / (RAND_MAX + 1.0) - 1.0 );
lastFrame_[0] = *(samples-hop);
return frames;
}
} // stk namespace
#endif

View File

@@ -1,43 +1,40 @@
/***************************************************/
/*! \class OnePole
\brief STK one-pole filter class.
This protected Filter subclass implements
a one-pole digital filter. A method is
provided for setting the pole position along
the real axis of the z-plane while maintaining
a constant peak filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
*/
/***************************************************/
#ifndef STK_ONEPOLE_H
#define STK_ONEPOLE_H
#include "Filter.h"
class OnePole : protected Filter
namespace stk {
/***************************************************/
/*! \class OnePole
\brief STK one-pole filter class.
This class implements a one-pole digital filter. A method is
provided for setting the pole position along the real axis of the
z-plane while maintaining a constant peak filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
class OnePole : public Filter
{
public:
//! Default constructor creates a first-order low-pass filter.
OnePole();
//! Overloaded constructor which sets the pole position during instantiation.
OnePole( StkFloat thePole );
//! The default constructor creates a low-pass filter (pole at z = 0.9).
OnePole( StkFloat thePole = 0.9 );
//! Class destructor.
~OnePole();
//! Clears the internal state of the filter.
void clear(void);
//! Set the b[0] coefficient value.
void setB0(StkFloat b0);
void setB0( StkFloat b0 ) { b_[0] = b0; };
//! Set the a[1] coefficient value.
void setA1(StkFloat a1);
void setA1( StkFloat a1 ) { a_[1] = a1; };
//! Set all filter coefficients.
void setCoefficients( StkFloat b0, StkFloat a1, bool clearState = false );
//! Set the pole position in the z-plane.
/*!
@@ -47,33 +44,90 @@ public:
pole value produces a high-pass filter. This method does not
affect the filter \e gain value.
*/
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(StkFloat gain);
//! Return the current filter gain.
StkFloat getGain(void) const;
void setPole( StkFloat thePole );
//! Return the last computed output value.
StkFloat lastOut(void) const;
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Input one sample to the filter and return one output.
StkFloat tick(StkFloat sample);
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
The StkFrames argument reference is returned. The \c channel
argument must be less than the number of channels in the
StkFrames argument (the first channel is specified by 0).
However, range checking is only performed if _STK_DEBUG_ is
defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Take a channel of the \c iFrames object as inputs to the filter and write outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. Each channel
argument must be less than the number of channels in the
corresponding StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
};
inline StkFloat OnePole :: tick( StkFloat input )
{
inputs_[0] = gain_ * input;
lastFrame_[0] = b_[0] * inputs_[0] - a_[1] * outputs_[1];
outputs_[1] = lastFrame_[0];
return lastFrame_[0];
}
inline StkFrames& OnePole :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "OnePole::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
inputs_[0] = gain_ * *samples;
*samples = b_[0] * inputs_[0] - a_[1] * outputs_[1];
outputs_[1] = *samples;
}
lastFrame_[0] = outputs_[1];
return frames;
}
inline StkFrames& OnePole :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
{
#if defined(_STK_DEBUG_)
if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
errorString_ << "OnePole::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *iSamples = &iFrames[iChannel];
StkFloat *oSamples = &oFrames[oChannel];
unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
inputs_[0] = gain_ * *iSamples;
*oSamples = b_[0] * inputs_[0] - a_[1] * outputs_[1];
outputs_[1] = *oSamples;
}
lastFrame_[0] = outputs_[1];
return iFrames;
}
} // stk namespace
#endif

View File

@@ -1,43 +1,40 @@
/***************************************************/
/*! \class OneZero
\brief STK one-zero filter class.
This protected Filter subclass implements
a one-zero digital filter. A method is
provided for setting the zero position
along the real axis of the z-plane while
maintaining a constant filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
*/
/***************************************************/
#ifndef STK_ONEZERO_H
#define STK_ONEZERO_H
#include "Filter.h"
class OneZero : protected Filter
namespace stk {
/***************************************************/
/*! \class OneZero
\brief STK one-zero filter class.
This class implements a one-zero digital filter. A method is
provided for setting the zero position along the real axis of the
z-plane while maintaining a constant filter gain.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
class OneZero : public Filter
{
public:
//! Default constructor creates a first-order low-pass filter.
OneZero();
//! Overloaded constructor which sets the zero position during instantiation.
OneZero(StkFloat theZero);
//! The default constructor creates a low-pass filter (zero at z = -1.0).
OneZero( StkFloat theZero = -1.0 );
//! Class destructor.
~OneZero();
//! Clears the internal state of the filter.
void clear(void);
//! Set the b[0] coefficient value.
void setB0(StkFloat b0);
void setB0( StkFloat b0 ) { b_[0] = b0; };
//! Set the b[1] coefficient value.
void setB1(StkFloat b1);
void setB1( StkFloat b1 ) { b_[1] = b1; };
//! Set all filter coefficients.
void setCoefficients( StkFloat b0, StkFloat b1, bool clearState = false );
//! Set the zero position in the z-plane.
/*!
@@ -47,33 +44,91 @@ class OneZero : protected Filter
negative zero value produces a low-pass filter. This method does
not affect the filter \e gain value.
*/
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(StkFloat gain);
//! Return the current filter gain.
StkFloat getGain(void) const;
void setZero( StkFloat theZero );
//! Return the last computed output value.
StkFloat lastOut(void) const;
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Input one sample to the filter and return one output.
StkFloat tick(StkFloat sample);
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
The StkFrames argument reference is returned. The \c channel
argument must be less than the number of channels in the
StkFrames argument (the first channel is specified by 0).
However, range checking is only performed if _STK_DEBUG_ is
defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Take a channel of the \c iFrames object as inputs to the filter and write outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. Each channel
argument must be less than the number of channels in the
corresponding StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
};
inline StkFloat OneZero :: tick( StkFloat input )
{
inputs_[0] = gain_ * input;
lastFrame_[0] = b_[1] * inputs_[1] + b_[0] * inputs_[0];
inputs_[1] = inputs_[0];
return lastFrame_[0];
}
inline StkFrames& OneZero :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "OneZero::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
inputs_[0] = gain_ * *samples;
*samples = b_[1] * inputs_[1] + b_[0] * inputs_[0];
inputs_[1] = inputs_[0];
}
lastFrame_[0] = *(samples-hop);
return frames;
}
inline StkFrames& OneZero :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
{
#if defined(_STK_DEBUG_)
if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
errorString_ << "OneZero::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *iSamples = &iFrames[iChannel];
StkFloat *oSamples = &oFrames[oChannel];
unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
inputs_[0] = gain_ * *iSamples;
*oSamples = b_[1] * inputs_[1] + b_[0] * inputs_[0];
inputs_[1] = inputs_[0];
}
lastFrame_[0] = *(oSamples-oHop);
return iFrames;
}
} // stk namespace
#endif

View File

@@ -1,43 +1,84 @@
#ifndef STK_PRCREV_H
#define STK_PRCREV_H
#include "Effect.h"
#include "Delay.h"
namespace stk {
/***************************************************/
/*! \class PRCRev
\brief Perry's simple reverberator class.
This class is based on some of the famous
Stanford/CCRMA reverbs (NRev, KipRev), which
were based on the Chowning/Moorer/Schroeder
reverberators using networks of simple allpass
and comb delay filters. This class implements
two series allpass units and two parallel comb
filters.
This class takes a monophonic input signal and produces a stereo
output signal. It is based on some of the famous Stanford/CCRMA
reverbs (NRev, KipRev), which were based on the
Chowning/Moorer/Schroeder reverberators using networks of simple
allpass and comb delay filters. This class implements two series
allpass units and two parallel comb filters.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_PRCREV_H
#define STK_PRCREV_H
#include "Effect.h"
#include "Delay.h"
class PRCRev : public Effect
{
public:
//! Class constructor taking a T60 decay time argument (one second default value).
PRCRev( StkFloat T60 = 1.0 );
//! Class destructor.
~PRCRev();
//! Reset and clear all internal state.
void clear();
void clear( void );
//! Set the reverberation T60 decay time.
void setT60( StkFloat T60 );
protected:
//! Return the specified channel value of the last computed stereo frame.
/*!
Use the lastFrame() function to get both values of the last
computed stereo frame. The \c channel argument must be 0 or 1
(the first channel is specified by 0). However, range checking is
only performed if _STK_DEBUG_ is defined during compilation, in
which case an out-of-range value will trigger an StkError
exception.
*/
StkFloat lastOut( unsigned int channel = 0 );
StkFloat computeSample( StkFloat input );
//! Input one sample to the effect and return the specified \c channel value of the computed stereo frame.
/*!
Use the lastFrame() function to get both values of the computed
stereo output frame. The \c channel argument must be 0 or 1 (the
first channel is specified by 0). However, range checking is only
performed if _STK_DEBUG_ is defined during compilation, in which
case an out-of-range value will trigger an StkError exception.
*/
StkFloat tick( StkFloat input, unsigned int channel = 0 );
//! Take a channel of the StkFrames object as inputs to the effect and replace with stereo outputs.
/*!
The StkFrames argument reference is returned. The stereo
outputs are written to the StkFrames argument starting at the
specified \c channel. Therefore, the \c channel argument must be
less than ( channels() - 1 ) of the StkFrames argument (the first
channel is specified by 0). However, range checking is only
performed if _STK_DEBUG_ is defined during compilation, in which
case an out-of-range value will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Take a channel of the \c iFrames object as inputs to the effect and write stereo outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. The \c iChannel
argument must be less than the number of channels in the \c
iFrames argument (the first channel is specified by 0). The \c
oChannel argument must be less than ( channels() - 1 ) of the \c
oFrames argument. However, range checking is only performed if
_STK_DEBUG_ is defined during compilation, in which case an
out-of-range value will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
protected:
Delay allpassDelays_[2];
Delay combDelays_[2];
@@ -46,5 +87,54 @@ protected:
};
inline StkFloat PRCRev :: lastOut( unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel > 1 ) {
errorString_ << "PRCRev::lastOut(): channel argument must be less than 2!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
return lastFrame_[channel];
}
inline StkFloat PRCRev :: tick( StkFloat input, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel > 1 ) {
errorString_ << "PRCRev::tick(): channel argument must be less than 2!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat temp, temp0, temp1, temp2, temp3;
temp = allpassDelays_[0].lastOut();
temp0 = allpassCoefficient_ * temp;
temp0 += input;
allpassDelays_[0].tick(temp0);
temp0 = -(allpassCoefficient_ * temp0) + temp;
temp = allpassDelays_[1].lastOut();
temp1 = allpassCoefficient_ * temp;
temp1 += temp0;
allpassDelays_[1].tick(temp1);
temp1 = -(allpassCoefficient_ * temp1) + temp;
temp2 = temp1 + (combCoefficient_[0] * combDelays_[0].lastOut());
temp3 = temp1 + (combCoefficient_[1] * combDelays_[1].lastOut());
lastFrame_[0] = effectMix_ * (combDelays_[0].tick(temp2));
lastFrame_[1] = effectMix_ * (combDelays_[1].tick(temp3));
temp = (1.0 - effectMix_) * input;
lastFrame_[0] += temp;
lastFrame_[1] += temp;
return lastFrame_[channel];
}
} // stk namespace
#endif

View File

@@ -1,3 +1,10 @@
#ifndef STK_PERCFLUT_H
#define STK_PERCFLUT_H
#include "FM.h"
namespace stk {
/***************************************************/
/*! \class PercFlut
\brief STK percussive flute FM synthesis instrument.
@@ -22,15 +29,10 @@
type who should worry about this (making
money) worry away.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_PERCFLUT_H
#define STK_PERCFLUT_H
#include "FM.h"
class PercFlut : public FM
{
public:
@@ -38,20 +40,51 @@ class PercFlut : public FM
/*!
An StkError will be thrown if the rawwave path is incorrectly set.
*/
PercFlut();
PercFlut( void );
//! Class destructor.
~PercFlut();
~PercFlut( void );
//! Set instrument parameters for a particular frequency.
void setFrequency(StkFloat frequency);
void setFrequency( StkFloat frequency );
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
};
inline StkFloat PercFlut :: tick( unsigned int )
{
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]);
waves_[3]->addPhaseOffset( twozero_.lastOut() );
temp = gains_[3] * adsr_[3]->tick() * waves_[3]->tick();
twozero_.tick(temp);
waves_[2]->addPhaseOffset( temp );
temp = (1.0 - (control2_ * 0.5)) * gains_[2] * adsr_[2]->tick() * waves_[2]->tick();
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();
lastFrame_[0] = temp * 0.5;
return lastFrame_[0];
}
} // stk namespace
#endif

View File

@@ -1,3 +1,10 @@
#ifndef STK_PHONEMES_H
#define STK_PHONEMES_H
#include "Stk.h"
namespace stk {
/***************************************************/
/*! \class Phonemes
\brief STK phonemes table.
@@ -6,15 +13,10 @@
set of 32 static phoneme formant parameters
and provide access to those values.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_PHONEMES_H
#define STK_PHONEMES_H
#include "Stk.h"
class Phonemes : public Stk
{
public:
@@ -47,4 +49,6 @@ private:
static const StkFloat phonemeParameters[][4][3];
};
} // stk namespace
#endif

View File

@@ -1,3 +1,11 @@
#ifndef STK_PITSHIFT_H
#define STK_PITSHIFT_H
#include "Effect.h"
#include "DelayL.h"
namespace stk {
/***************************************************/
/*! \class PitShift
\brief STK simple pitch shifter effect class.
@@ -5,43 +13,95 @@
This class implements a simple pitch shifter
using delay lines.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_PITSHIFT_H
#define STK_PITSHIFT_H
#include "Effect.h"
#include "DelayL.h"
const int maxDelay = 5024;
class PitShift : public Effect
{
public:
//! Class constructor.
PitShift();
//! Class destructor.
~PitShift();
PitShift( void );
//! Reset and clear all internal state.
void clear();
void clear( void );
//! Set the pitch shift factor (1.0 produces no shift).
void setShift(StkFloat shift);
void setShift( StkFloat shift );
//! Return the last computed output value.
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Input one sample to the effect and return one output.
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the effect and replace with corresponding outputs.
/*!
The StkFrames argument reference is returned. The \c channel
argument must be less than the number of channels in the
StkFrames argument (the first channel is specified by 0).
However, range checking is only performed if _STK_DEBUG_ is
defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Take a channel of the \c iFrames object as inputs to the effect and write outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. Each channel
argument must be less than the number of channels in the
corresponding StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
protected:
StkFloat computeSample( StkFloat input );
DelayL delayLine_[2];
StkFloat delay_[2];
StkFloat env_[2];
StkFloat rate_;
unsigned long delayLength;
unsigned long halfLength;
unsigned long delayLength_;
unsigned long halfLength_;
};
inline StkFloat PitShift :: tick( StkFloat input )
{
// Calculate the two delay length values, keeping them within the
// range 12 to maxDelay-12.
delay_[0] += rate_;
while ( delay_[0] > maxDelay-12 ) delay_[0] -= delayLength_;
while ( delay_[0] < 12 ) delay_[0] += delayLength_;
delay_[1] = delay_[0] + halfLength_;
while ( delay_[1] > maxDelay-12 ) delay_[1] -= delayLength_;
while ( delay_[1] < 12 ) delay_[1] += delayLength_;
// Set the new delay line lengths.
delayLine_[0].setDelay( delay_[0] );
delayLine_[1].setDelay( delay_[1] );
// Calculate a triangular envelope.
env_[1] = fabs( ( delay_[0] - halfLength_ + 12 ) * ( 1.0 / (halfLength_ + 12 ) ) );
env_[0] = 1.0 - env_[1];
// Delay input and apply envelope.
lastFrame_[0] = env_[0] * delayLine_[0].tick( input );
lastFrame_[0] += env_[1] * delayLine_[1].tick( input );
// Compute effect mix and output.
lastFrame_[0] *= effectMix_;
lastFrame_[0] += ( 1.0 - effectMix_ ) * input;
return lastFrame_[0];
}
} // stk namespace
#endif

View File

@@ -1,3 +1,13 @@
#ifndef STK_PLUCKTWO_H
#define STK_PLUCKTWO_H
#include "Instrmnt.h"
#include "DelayL.h"
#include "DelayA.h"
#include "OneZero.h"
namespace stk {
/***************************************************/
/*! \class PluckTwo
\brief STK enhanced plucked string model class.
@@ -14,41 +24,33 @@
use possibly subject to patents held by
Stanford University, Yamaha, and others.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_PLUCKTWO_H
#define STK_PLUCKTWO_H
#include "Instrmnt.h"
#include "DelayL.h"
#include "DelayA.h"
#include "OneZero.h"
class PluckTwo : public Instrmnt
{
public:
//! Class constructor, taking the lowest desired playing frequency.
PluckTwo(StkFloat lowestFrequency);
PluckTwo( StkFloat lowestFrequency );
//! Class destructor.
virtual ~PluckTwo();
virtual ~PluckTwo( void );
//! Reset and clear all internal state.
void clear();
void clear( void );
//! Set instrument parameters for a particular frequency.
virtual void setFrequency(StkFloat frequency);
virtual void setFrequency( StkFloat frequency );
//! Detune the two strings by the given factor. A value of 1.0 produces unison strings.
void setDetune(StkFloat detune);
void setDetune( StkFloat detune );
//! Efficient combined setting of frequency and detuning.
void setFreqAndDetune(StkFloat frequency, StkFloat detune);
void setFreqAndDetune( StkFloat frequency, StkFloat detune );
//! Set the pluck or "excitation" position along the string (0.0 - 1.0).
void setPluckPosition(StkFloat position);
void setPluckPosition( StkFloat position );
//! Set the base loop gain.
/*!
@@ -56,15 +58,15 @@ class PluckTwo : public Instrmnt
Because of high-frequency loop filter roll-off, higher
frequency settings have greater loop gains.
*/
void setBaseLoopGain(StkFloat aGain);
void setBaseLoopGain( StkFloat aGain );
//! Stop a note with the given amplitude (speed of decay).
virtual void noteOff(StkFloat amplitude);
virtual void noteOff( StkFloat amplitude );
virtual StkFloat tick( unsigned int channel = 0 ) = 0;
protected:
virtual StkFloat computeSample( void ) = 0;
DelayA delayLine_;
DelayA delayLine2_;
DelayL combDelay_;
@@ -82,4 +84,6 @@ class PluckTwo : public Instrmnt
};
} // stk namespace
#endif

View File

@@ -1,3 +1,14 @@
#ifndef STK_PLUCKED_H
#define STK_PLUCKED_H
#include "Instrmnt.h"
#include "DelayA.h"
#include "OneZero.h"
#include "OnePole.h"
#include "Noise.h"
namespace stk {
/***************************************************/
/*! \class Plucked
\brief STK plucked string model class.
@@ -13,47 +24,39 @@
Stanford, bearing the names of Karplus and/or
Strong.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_PLUCKED_H
#define STK_PLUCKED_H
#include "Instrmnt.h"
#include "DelayA.h"
#include "OneZero.h"
#include "OnePole.h"
#include "Noise.h"
class Plucked : public Instrmnt
{
public:
//! Class constructor, taking the lowest desired playing frequency.
Plucked(StkFloat lowestFrequency);
Plucked( StkFloat lowestFrequency );
//! Class destructor.
~Plucked();
~Plucked( void );
//! Reset and clear all internal state.
void clear();
void clear( void );
//! Set instrument parameters for a particular frequency.
virtual void setFrequency(StkFloat frequency);
void setFrequency( StkFloat frequency );
//! Pluck the string with the given amplitude using the current frequency.
void pluck(StkFloat amplitude);
void pluck( StkFloat amplitude );
//! Start a note with the given frequency and amplitude.
virtual void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Stop a note with the given amplitude (speed of decay).
virtual void noteOff(StkFloat amplitude);
void noteOff( StkFloat amplitude );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
DelayA delayLine_;
OneZero loopFilter_;
OnePole pickFilter_;
@@ -63,5 +66,13 @@ class Plucked : public Instrmnt
};
inline StkFloat Plucked :: tick( unsigned int )
{
// Here's the whole inner loop of the instrument!!
return lastFrame_[0] = 3.0 * delayLine_.tick( loopFilter_.tick( delayLine_.lastOut() * loopGain_ ) );
}
} // stk namespace
#endif

View File

@@ -1,23 +1,24 @@
/***************************************************/
/*! \class PoleZero
\brief STK one-pole, one-zero filter class.
This protected Filter subclass implements
a one-pole, one-zero digital filter. A
method is provided for creating an allpass
filter with a given coefficient. Another
method is provided to create a DC blocking filter.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
*/
/***************************************************/
#ifndef STK_POLEZERO_H
#define STK_POLEZERO_H
#include "Filter.h"
class PoleZero : protected Filter
namespace stk {
/***************************************************/
/*! \class PoleZero
\brief STK one-pole, one-zero filter class.
This class implements a one-pole, one-zero digital filter. A
method is provided for creating an allpass filter with a given
coefficient. Another method is provided to create a DC blocking
filter.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
class PoleZero : public Filter
{
public:
@@ -27,17 +28,17 @@ class PoleZero : protected Filter
//! Class destructor.
~PoleZero();
//! Clears the internal states of the filter.
void clear(void);
//! Set the b[0] coefficient value.
void setB0(StkFloat b0);
void setB0( StkFloat b0 ) { b_[0] = b0; };
//! Set the b[1] coefficient value.
void setB1(StkFloat b1);
void setB1( StkFloat b1 ) { b_[1] = b1; };
//! Set the a[1] coefficient value.
void setA1(StkFloat a1);
void setA1( StkFloat a1 ) { a_[1] = a1; };
//! Set all filter coefficients.
void setCoefficients( StkFloat b0, StkFloat b1, StkFloat a1, bool clearState = false );
//! Set the filter for allpass behavior using \e coefficient.
/*!
@@ -45,7 +46,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(StkFloat coefficient);
void setAllpass( StkFloat coefficient );
//! Create a DC blocking filter with the given pole position in the z-plane.
/*!
@@ -54,33 +55,58 @@ class PoleZero : protected Filter
close to one to minimize low-frequency attenuation.
*/
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( StkFloat gain );
//! Return the current filter gain.
StkFloat getGain( void ) const;
void setBlockZero( StkFloat thePole = 0.99 );
//! Return the last computed output value.
StkFloat lastOut( void ) const;
StkFloat lastOut( void ) const { return lastFrame_[0]; };
//! Input one sample to the filter and return one output.
StkFloat tick( StkFloat sample );
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the filter and replace with corresponding outputs.
/*!
The \c channel argument should be zero or greater (the first
channel is specified by 0). An StkError will be thrown if the \c
channel argument is equal to or greater than the number of
channels in the StkFrames object.
The \c channel argument must be less than the number of
channels in the StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
};
inline StkFloat PoleZero :: tick( StkFloat input )
{
inputs_[0] = gain_ * input;
lastFrame_[0] = b_[0] * inputs_[0] + b_[1] * inputs_[1] - a_[1] * outputs_[1];
inputs_[1] = inputs_[0];
outputs_[1] = lastFrame_[0];
return lastFrame_[0];
}
inline StkFrames& PoleZero :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "PoleZero::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
inputs_[0] = gain_ * *samples;
*samples = b_[0] * inputs_[0] + b_[1] * inputs_[1] - a_[1] * outputs_[1];
inputs_[1] = inputs_[0];
outputs_[1] = *samples;
}
lastFrame_[0] = outputs_[1];
return frames;
}
} // stk namespace
#endif

View File

@@ -1,3 +1,10 @@
#ifndef STK_REEDTABLE_H
#define STK_REEDTABLE_H
#include "Function.h"
namespace stk {
/***************************************************/
/*! \class ReedTable
\brief STK reed table class.
@@ -13,23 +20,15 @@
Smith (1986), Hirschman, Cook, Scavone, and
others for more information.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_REEDTABLE_H
#define STK_REEDTABLE_H
#include "Function.h"
class ReedTable : public Function
{
public:
//! Default constructor.
ReedTable();
//! Class destructor.
~ReedTable();
ReedTable( void ) : offset_(0.6), slope_(-0.8) {};
//! Set the table offset value.
/*!
@@ -37,7 +36,7 @@ public:
of the initial reed tip opening (a greater offset
represents a smaller opening).
*/
void setOffset(StkFloat offset);
void setOffset( StkFloat offset ) { offset_ = offset; };
//! Set the table slope value.
/*!
@@ -45,15 +44,100 @@ public:
stiffness (a greater slope represents a harder
reed).
*/
void setSlope(StkFloat slope);
void setSlope( StkFloat slope ) { slope_ = slope; };
//! Take one sample input and map to one sample of output.
StkFloat tick( StkFloat input );
//! Take a channel of the StkFrames object as inputs to the table and replace with corresponding outputs.
/*!
The StkFrames argument reference is returned. The \c channel
argument must be less than the number of channels in the
StkFrames argument (the first channel is specified by 0).
However, range checking is only performed if _STK_DEBUG_ is
defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
//! Take a channel of the \c iFrames object as inputs to the table and write outputs to the \c oFrames object.
/*!
The \c iFrames object reference is returned. Each channel
argument must be less than the number of channels in the
corresponding StkFrames argument (the first channel is specified
by 0). However, range checking is only performed if _STK_DEBUG_
is defined during compilation, in which case an out-of-range value
will trigger an StkError exception.
*/
StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
protected:
StkFloat computeSample( StkFloat input );
StkFloat offset_;
StkFloat slope_;
};
inline StkFloat ReedTable :: tick( StkFloat input )
{
// The input is differential pressure across the reed.
lastFrame_[0] = offset_ + (slope_ * input);
// If output is > 1, the reed has slammed shut and the
// reflection function value saturates at 1.0.
if ( lastFrame_[0] > 1.0) lastFrame_[0] = (StkFloat) 1.0;
// This is nearly impossible in a physical system, but
// a reflection function value of -1.0 corresponds to
// an open end (and no discontinuity in bore profile).
if ( lastFrame_[0] < -1.0) lastFrame_[0] = (StkFloat) -1.0;
return lastFrame_[0];
}
inline StkFrames& ReedTable :: tick( StkFrames& frames, unsigned int channel )
{
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() ) {
errorString_ << "ReedTable::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
*samples = offset_ + (slope_ * *samples);
if ( *samples > 1.0) *samples = 1.0;
if ( *samples < -1.0) *samples = -1.0;
}
lastFrame_[0] = *(samples-hop);
return frames;
}
inline StkFrames& ReedTable :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
{
#if defined(_STK_DEBUG_)
if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
errorString_ << "ReedTable::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *iSamples = &iFrames[iChannel];
StkFloat *oSamples = &oFrames[oChannel];
unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
*oSamples = offset_ + (slope_ * *iSamples);
if ( *oSamples > 1.0) *oSamples = 1.0;
if ( *oSamples < -1.0) *oSamples = -1.0;
}
lastFrame_[0] = *(oSamples-oHop);
return iFrames;
}
} // stk namespace
#endif

View File

@@ -1,3 +1,13 @@
#ifndef STK_RESONATE_H
#define STK_RESONATE_H
#include "Instrmnt.h"
#include "ADSR.h"
#include "BiQuad.h"
#include "Noise.h"
namespace stk {
/***************************************************/
/*! \class Resonate
\brief STK noise driven formant filter.
@@ -13,58 +23,51 @@
- Zero Radii = 1
- Envelope Gain = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_RESONATE_H
#define STK_RESONATE_H
#include "Instrmnt.h"
#include "ADSR.h"
#include "BiQuad.h"
#include "Noise.h"
class Resonate : public Instrmnt
{
public:
//! Class constructor.
Resonate();
Resonate( void );
//! Class destructor.
~Resonate();
~Resonate( void );
//! Reset and clear all internal state.
void clear();
void clear( void );
//! Set the filter for a resonance at the given frequency (Hz) and radius.
void setResonance(StkFloat frequency, StkFloat radius);
void setResonance( StkFloat frequency, StkFloat radius );
//! Set the filter for a notch at the given frequency (Hz) and radius.
void setNotch(StkFloat frequency, StkFloat radius);
void setNotch( StkFloat frequency, StkFloat radius );
//! Set the filter zero coefficients for contant resonance gain.
void setEqualGainZeroes();
void setEqualGainZeroes( void ) { filter_.setEqualGainZeroes(); };
//! Initiate the envelope with a key-on event.
void keyOn();
void keyOn( void ) { adsr_.keyOn(); };
//! Signal a key-off event to the envelope.
void keyOff();
void keyOff( void ) { adsr_.keyOff(); };
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Stop a note with the given amplitude (speed of decay).
void noteOff(StkFloat amplitude);
void noteOff( StkFloat amplitude );
//! Perform the control change specified by \e number and \e value (0.0 - 128.0).
void controlChange(int number, StkFloat value);
void controlChange( int number, StkFloat value );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
ADSR adsr_;
BiQuad filter_;
Noise noise_;
@@ -75,4 +78,13 @@ class Resonate : public Instrmnt
};
inline StkFloat Resonate :: tick( unsigned int )
{
lastFrame_[0] = filter_.tick( noise_.tick() );
lastFrame_[0] *= adsr_.tick();
return lastFrame_[0];
}
} // stk namespace
#endif

View File

@@ -1,3 +1,10 @@
#ifndef STK_RHODEY_H
#define STK_RHODEY_H
#include "FM.h"
namespace stk {
/***************************************************/
/*! \class Rhodey
\brief STK Fender Rhodes electric piano FM
@@ -26,15 +33,10 @@
type who should worry about this (making
money) worry away.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#ifndef STK_RHODEY_H
#define STK_RHODEY_H
#include "FM.h"
class Rhodey : public FM
{
public:
@@ -42,20 +44,48 @@ class Rhodey : public FM
/*!
An StkError will be thrown if the rawwave path is incorrectly set.
*/
Rhodey();
Rhodey( void );
//! Class destructor.
~Rhodey();
~Rhodey( void );
//! Set instrument parameters for a particular frequency.
void setFrequency(StkFloat frequency);
void setFrequency( StkFloat frequency );
//! Start a note with the given frequency and amplitude.
void noteOn(StkFloat frequency, StkFloat amplitude);
void noteOn( StkFloat frequency, StkFloat amplitude );
//! Compute and return one output sample.
StkFloat tick( unsigned int channel = 0 );
protected:
StkFloat computeSample( void );
};
inline StkFloat Rhodey :: tick( unsigned int )
{
StkFloat temp, temp2;
temp = gains_[1] * adsr_[1]->tick() * waves_[1]->tick();
temp = temp * control1_;
waves_[0]->addPhaseOffset( temp );
waves_[3]->addPhaseOffset( twozero_.lastOut() );
temp = gains_[3] * adsr_[3]->tick() * waves_[3]->tick();
twozero_.tick(temp);
waves_[2]->addPhaseOffset( temp );
temp = ( 1.0 - (control2_ * 0.5)) * gains_[0] * adsr_[0]->tick() * waves_[0]->tick();
temp += control2_ * 0.5 * gains_[2] * adsr_[2]->tick() * waves_[2]->tick();
// Calculate amplitude modulation and apply it to output.
temp2 = vibrato_.tick() * modDepth_;
temp = temp * (1.0 + temp2);
lastFrame_[0] = temp * 0.5;
return lastFrame_[0];
}
} // stk namespace
#endif

Some files were not shown because too many files have changed in this diff Show More