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 
109  StkFrames& tick( StkFrames& frames );
110 
111  // Called by the thread routine to receive data via the socket connection
112  // and fill the socket buffer. This is not intended for general use but
113  // must be public for access from the thread.
114  void receive( void );
115 
116 protected:
117 
118  // Read buffered socket data into the data buffer ... will block if none available.
119  int readData( void );
120 
121  Socket *soket_;
122  Thread thread_;
123  Mutex mutex_;
124  char *buffer_;
125  unsigned long bufferFrames_;
126  unsigned long bufferBytes_;
127  unsigned long bytesFilled_;
128  unsigned int nBuffers_;
129  unsigned long writePoint_;
130  unsigned long readPoint_;
131  long bufferCounter_;
132  int dataBytes_;
133  bool connected_;
134  int fd_;
135  ThreadInfo threadInfo_;
136  Stk::StkFormat dataType_;
137 
138 };
139 
140 inline StkFloat InetWvIn :: lastOut( unsigned int channel )
141 {
142 #if defined(_STK_DEBUG_)
143  if ( channel >= data_.channels() ) {
144  oStream_ << "InetWvIn::lastOut(): channel argument and data stream are incompatible!";
145  handleError( StkError::FUNCTION_ARGUMENT );
146  }
147 #endif
148 
149  // If no connection and we've output all samples in the queue, return.
150  if ( !connected_ && bytesFilled_ == 0 && bufferCounter_ == 0 ) return 0.0;
151 
152  return lastFrame_[channel];
153 }
154 
155 } // stk namespace
156 
157 #endif

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