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
10 namespace stk {
11
12 /***************************************************/
36 /***************************************************/
37
38 typedef struct {
39 bool finished;
40 void *object;
41 } ThreadInfo;
42
43 class InetWvIn : public WvIn
44 {
45 public:
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
117 protected:
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

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