mirror of
https://github.com/thestk/stk
synced 2026-01-11 20:11:52 +00:00
Version 4.4.0
This commit is contained in:
committed by
Stephen Sinclair
parent
d199342e86
commit
eccd8c9981
@@ -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>] [<A HREF="compile.html">Next tutorial</A>]
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user