Arduino STK  4.6.2
InetWvIn.h
1 #include "Mutex.h"
2 #ifdef STK_MUTEXT_SUPPORTED
3 
4 #ifndef STK_INETWVIN_H
5 #define STK_INETWVIN_H
6 
7 #include "WvIn.h"
8 #include "TcpServer.h"
9 #include "UdpSocket.h"
10 #include "Thread.h"
11 #include "Mutex.h"
12 
13 namespace stk {
14 
15 /***************************************************/
39 /***************************************************/
40 
41 typedef struct {
42  bool finished;
43  void *object;
44 } ThreadInfo;
45 
46 class InetWvIn : public WvIn
47 {
48 public:
50 
53  InetWvIn( unsigned long bufferFrames = 1024, unsigned int nBuffers = 8 );
54 
57 
59 
66  void listen( int port = 2006, unsigned int nChannels = 1,
67  Stk::StkFormat format = STK_SINT16,
68  Socket::ProtocolType protocol = Socket::PROTO_TCP );
69 
71 
75  bool isConnected( void );
76 
78 
87  StkFloat lastOut( unsigned int channel = 0 );
88 
90 
100  StkFloat tick( unsigned int channel = 0 );
101 
103 
113  StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
114 
115  // Called by the thread routine to receive data via the socket connection
116  // and fill the socket buffer. This is not intended for general use but
117  // must be public for access from the thread.
118  void receive( void );
119 
120 protected:
121 
122  // Read buffered socket data into the data buffer ... will block if none available.
123  int readData( void );
124 
125  Socket *soket_;
126  Thread thread_;
127  Mutex mutex_;
128  char *buffer_;
129  unsigned long bufferFrames_;
130  unsigned long bufferBytes_;
131  unsigned long bytesFilled_;
132  unsigned int nBuffers_;
133  unsigned long writePoint_;
134  unsigned long readPoint_;
135  long bufferCounter_;
136  int dataBytes_;
137  bool connected_;
138  int fd_;
139  ThreadInfo threadInfo_;
140  Stk::StkFormat dataType_;
141 
142 };
143 
144 inline StkFloat InetWvIn :: lastOut( unsigned int channel )
145 {
146 #if defined(_STK_DEBUG_)
147  if ( channel >= data_.channels() ) {
148  oStream_ << "InetWvIn::lastOut(): channel argument and data stream are incompatible!";
149  handleError( StkError::FUNCTION_ARGUMENT );
150  }
151 #endif
152 
153  // If no connection and we've output all samples in the queue, return.
154  if ( !connected_ && bytesFilled_ == 0 && bufferCounter_ == 0 ) return 0.0;
155 
156  return lastFrame_[channel];
157 }
158 
159 } // stk namespace
160 
161 #endif
162 #endif
STK internet streaming input class.
Definition: InetWvIn.h:47
StkFloat tick(unsigned int channel=0)
Compute a sample frame and return the specified channel value.
~InetWvIn()
Class destructor.
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.
Definition: InetWvIn.h:144
InetWvIn(unsigned long bufferFrames=1024, unsigned int nBuffers=8)
Default constructor.
StkFrames & tick(StkFrames &frames, unsigned int channel=0)
Fill the StkFrames object with computed sample frames, starting at the specified channel and return t...
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 class.
Definition: Mutex.h:51
An STK class to handle vectorized audio data.
Definition: Stk.h:287
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition: Stk.h:415
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
static const StkFormat STK_SINT16
Definition: Stk.h:149
STK thread class.
Definition: Thread.h:63
STK audio input abstract base class.
Definition: WvIn.h:20
The STK namespace.
Definition: ADSR.h:8