The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Public Member Functions | List of all members
stk::InetWvIn Class Reference

STK internet streaming input class. More...

`#include <InetWvIn.h>`

Inheritance diagram for stk::InetWvIn:

## Public Member Functions
| InetWvIn (unsigned long bufferFrames=1024, unsigned int nBuffers=8)
| Default constructor.
| ~InetWvIn ()
| Class destructor.
void | listen (int port=2006, unsigned int nChannels=1, Stk::StkFormat format=STK_SINT16, Socket::ProtocolType protocol=Socket::PROTO_TCP)
| Wait for a (new) socket connection with specified protocol, port, data channels and format.
bool | isConnected (void)
| Returns true is an input connection exists or input data remains in the queue.
StkFloat | lastOut (unsigned int channel=0)
| Return the specified channel value of the last computed frame.
StkFloat | tick (unsigned int channel=0)
| Compute a sample frame and return the specified `channel` value.
StkFrames & | tick (StkFrames &frames, unsigned int channel=0)
| Fill the StkFrames object with computed sample frames, starting at the specified channel and return the same reference.
Public Member Functions inherited from stk::WvIn
unsigned int | channelsOut (void) const
| Return the number of audio channels in the data or stream.
const StkFrames & | lastFrame (void) const
| Return an StkFrames reference to the last computed sample frame.
virtual StkFloat | tick (unsigned int channel=0)=0
| Compute one sample frame and return the specified `channel` value.
virtual StkFrames & | tick (StkFrames &frames, unsigned int channel=0)=0
| Fill the StkFrames object with computed sample frames, starting at the specified channel and return the same reference.
Public Member Functions inherited from stk::Stk
void | ignoreSampleRateChange (bool ignore=true)
| A function to enable/disable the automatic updating of class data when the STK sample rate changes.

## Additional Inherited Members
Static Public Member Functions inherited from stk::Stk
static StkFloat | sampleRate (void)
| Static method that returns the current STK sample rate.
static void | setSampleRate (StkFloat rate)
| Static method that sets the STK sample rate.
static void | clear_alertList ()
| Static method that frees memory from alertList_.
static std::string | rawwavePath (void)
| Static method that returns the current rawwave path.
static void | setRawwavePath (std::string path)
| Static method that sets the STK rawwave path.
static void | swap16 (unsigned char *ptr)
| Static method that byte-swaps a 16-bit data type.
static void | swap32 (unsigned char *ptr)
| Static method that byte-swaps a 32-bit data type.
static void | swap64 (unsigned char *ptr)
| Static method that byte-swaps a 64-bit data type.
static void | sleep (unsigned long milliseconds)
| Static cross-platform method to sleep for a number of milliseconds.
static bool | inRange (StkFloat value, StkFloat min, StkFloat max)
| Static method to check whether a value is within a specified range.
static void | handleError (const char *message, StkError::Type type)
| Static function for error reporting and handling using c-strings.
static void | handleError (std::string message, StkError::Type type)
| Static function for error reporting and handling using c++ strings.
static void | showWarnings (bool status)
| Toggle display of WARNING and STATUS messages.
static void | printErrors (bool status)
| Toggle display of error messages before throwing exceptions.
Static Public Attributes inherited from stk::Stk
static const StkFormat | STK_SINT8
static const StkFormat | STK_SINT16
static const StkFormat | STK_SINT24
static const StkFormat | STK_SINT32
static const StkFormat | STK_FLOAT32
static const StkFormat | STK_FLOAT64
Protected Member Functions inherited from stk::Stk
| Stk (void)
| Default constructor.
virtual | ~Stk (void)
| Class destructor.
virtual void | sampleRateChanged (StkFloat newRate, StkFloat oldRate)
| This function should be implemented in subclasses that depend on the sample rate.
void | addSampleRateAlert (Stk *ptr)
| Add class pointer to list for sample rate change notification.
void | removeSampleRateAlert (Stk *ptr)
| Remove class pointer from list for sample rate change notification.
void | handleError (StkError::Type type) const
| Internal function for error reporting that assumes message in `oStream_` variable.

## Detailed Description

STK internet streaming input class.

This Wvin subclass reads streamed audio data over a network via a TCP or UDP socket connection. The data is assumed in big-endian, or network, byte order. Only a single socket connection is supported.

InetWvIn 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.

This class implements a socket server. When using the TCP protocol, the server "listens" for a single remote connection within the InetWvIn::start() function. For the UDP protocol, no attempt is made to verify packet delivery or order. The default 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–2023.

## Constructor & Destructor Documentation

## ◆ InetWvIn()

stk::InetWvIn::InetWvIn | ( | unsigned long | bufferFrames = `1024`,
|  | unsigned int | nBuffers = `8`
| ) |  |

Default constructor.

An StkError will be thrown if an error occurs while initializing the input thread.

## Member Function Documentation

## ◆ listen()

void stk::InetWvIn::listen | ( | int | port = `2006`,
|  | unsigned int | nChannels = `1`,
|  | Stk::StkFormat | format = `STK_SINT16`,
|  | Socket::ProtocolType | protocol = `Socket::PROTO_TCP`
| ) |  |

Wait for a (new) socket connection with specified protocol, port, data channels and format.

For the UDP protocol, this function will create a socket instance and return. For the TCP protocol, this function will block until a connection is established. An StkError will be thrown if a socket error occurs or an invalid function argument is provided.

## ◆ isConnected()

bool stk::InetWvIn::isConnected | ( | void |  | ) |

Returns true is an input connection exists or input data remains in the queue.

This method will not return false after an input connection has been closed until all buffered input data has been read out.

## ◆ lastOut()

StkFloat stk::InetWvIn::lastOut | ( | unsigned int | channel = `0` | ) |
| inline

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 `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.

142{
143#if defined(_STK_DEBUG_)
144 if ( channel >= data_.channels() ) {
145 oStream_ << "InetWvIn::lastOut(): channel argument and data stream are incompatible!";
146 handleError( StkError::FUNCTION_ARGUMENT );
147 }
148#endif
149
150 // If no connection and we've output all samples in the queue, return.
151 if ( !connected_ && bytesFilled_ == 0 && bufferCounter_ == 0 ) return 0.0;
152
153 return lastFrame_[channel];
154}
stk::StkFrames::channels
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition Stk.h:416
stk::Stk::handleError
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.

## ◆ tick() [1/2]

StkFloat stk::InetWvIn::tick | ( | unsigned int | channel = `0` | ) |
| virtual

Compute a sample frame and return the specified `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 `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.

Implements stk::WvIn.

## ◆ tick() [2/2]

StkFrames & stk::InetWvIn::tick | ( | StkFrames & | frames,
|  | unsigned int | channel = `0`
| ) |  |
| virtual

Fill the StkFrames object with computed sample frames, starting at the specified channel and return the same reference.

The `channel` argument plus the number of channels specified in the listen() function must be less than the number of channels in the StkFrames argument (the first channel is specified by 0). 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).

Implements stk::WvIn.

The documentation for this class was generated from the following file:

- InetWvIn.h

The Synthesis ToolKit in C++ (STK)
©1995--2023 Perry R. Cook and Gary P. Scavone. All Rights Reserved.