mirror of
https://github.com/thestk/stk
synced 2026-01-11 03:51:53 +00:00
44 lines
2.8 KiB
Plaintext
44 lines
2.8 KiB
Plaintext
/*! \page realtime Realtime Audio (blocking)
|
|
|
|
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
|
|
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
|
|
optional constructor arguments can be used to fine tune its
|
|
performance for a given system. RtWvOut provides a "single-sample"
|
|
interface to the RtAudio class. Note that RtWvOut (as well as the
|
|
RtWvIn and RtDuplex classes described below) make use of RtAudio's
|
|
blocking input/output functionality. On systems that implement an
|
|
inherently callback-based audio API (Linux Jack, Windows ASIO, OS-X
|
|
CoreAudio), this blocking functionality will be less robust. An
|
|
example of audio output using a callback scheme will be discussed in a
|
|
subsequent tutorial section.
|
|
|
|
Though not used here, an 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 hardware device or devices. However, it is recommended to instead use a single instance of RtDuplex to achieve this behavior, in that it guarantees better synchronization between the input and output data. See the <TT>effects</TT> project or the <TT>io.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):
|
|
|
|
\code
|
|
g++ -Wall -D__LINUX_ALSA__ -D__LITTLE_ENDIAN__ -o rtsine Stk.cpp Generator.cpp SineWave.cpp WvOut.cpp \
|
|
RtWvOut.cpp RtAudio.cpp rtsine.cpp -lpthread -lasound
|
|
\endcode
|
|
|
|
On a Macintosh OS X system, the syntax would be:
|
|
|
|
\code
|
|
g++ -Wall -D__MACOSX_CORE__ -o rtsine Stk.cpp Generator.cpp SineWave.cpp WvOut.cpp RtWvOut.cpp RtAudio.cpp \
|
|
rtsine.cpp -lpthread -framework CoreAudio -framework CoreMIDI -framework CoreFoundation
|
|
\endcode
|
|
|
|
[<A HREF="tutorial.html">Main tutorial page</A>] [<A HREF="crealtime.html">Next tutorial</A>]
|
|
*/
|