The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

InetWvIn.h
1#ifndef STK_INETWVIN_H
2#define STK_INETWVIN_H
3
4#include "WvIn.h"
5#include "TcpServer.h"
6#include "UdpSocket.h"
7#include "Thread.h"
8#include "Mutex.h"
9
10namespace stk {
11
12/***************************************************/
36/***************************************************/
37
38typedef struct {
39 bool finished;
40 void *object;
41} ThreadInfo;
42
43 class InetWvIn : public WvIn
44{
45public:
47
50 InetWvIn( unsigned long bufferFrames = 1024, unsigned int nBuffers = 8 );
51
53 ~InetWvIn();
54
56
63 void listen( int port = 2006, unsigned int nChannels = 1,
64 Stk::StkFormat format = STK_SINT16,
65 Socket::ProtocolType protocol = Socket::PROTO_TCP );
66
68
72 bool isConnected( void );
73
75
84 StkFloat lastOut( unsigned int channel = 0 );
85
87
97 StkFloat tick( unsigned int channel = 0 );
98
100
110 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
111
112 // Called by the thread routine to receive data via the socket connection
113 // and fill the socket buffer. This is not intended for general use but
114 // must be public for access from the thread.
115 void receive( void );
116
117protected:
118
119 // Read buffered socket data into the data buffer ... will block if none available.
120 int readData( void );
121
122 Socket *soket_;
123 Thread thread_;
124 Mutex mutex_;
125 char *buffer_;
126 unsigned long bufferFrames_;
127 unsigned long bufferBytes_;
128 unsigned long bytesFilled_;
129 unsigned int nBuffers_;
130 unsigned long writePoint_;
131 unsigned long readPoint_;
132 long bufferCounter_;
133 int dataBytes_;
134 bool connected_;
135 int fd_;
136 ThreadInfo threadInfo_;
137 Stk::StkFormat dataType_;
138
139};
140
141 inline StkFloat InetWvIn :: lastOut( unsigned int channel )
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}
155
156} // stk namespace
157
158#endif
stk::InetWvIn::tick
StkFloat tick(unsigned int channel=0)
Compute a sample frame and return the specified channel value.
stk::InetWvIn::~InetWvIn
~InetWvIn()
Class destructor.
stk::InetWvIn::isConnected
bool isConnected(void)
Returns true is an input connection exists or input data remains in the queue.
stk::InetWvIn::tick
StkFrames & tick(StkFrames &frames, unsigned int channel=0)
Fill the StkFrames object with computed sample frames, starting at the specified channel and return t...
stk::InetWvIn::lastOut
StkFloat lastOut(unsigned int channel=0)
Return the specified channel value of the last computed frame.
Definition InetWvIn.h:141
stk::InetWvIn::InetWvIn
InetWvIn(unsigned long bufferFrames=1024, unsigned int nBuffers=8)
Default constructor.
stk::InetWvIn::listen
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.
stk::Mutex
STK mutex class.
Definition Mutex.h:37
stk::Socket
STK internet socket abstract base class.
Definition Socket.h:39
stk::StkFrames
An STK class to handle vectorized audio data.
Definition Stk.h:279
stk::Stk::handleError
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
stk::Stk::STK_SINT16
static const StkFormat STK_SINT16
Definition Stk.h:141
stk::Thread
STK thread class.
Definition Thread.h:50
stk::WvIn
STK audio input abstract base class.
Definition WvIn.h:20
stk
The STK namespace.
Definition ADSR.h:6

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