The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# InetWvIn.h

    00001 #ifndef STK_INETWVIN_H
    00002 #define STK_INETWVIN_H
    00003
    00004 #include "WvIn.h"
    00005 #include "TcpServer.h"
    00006 #include "UdpSocket.h"
    00007 #include "Thread.h"
    00008 #include "Mutex.h"
    00009
    00010 namespace stk {
    00011
    00012 /***************************************************/
    00036 /***************************************************/
    00037
    00038 typedef struct {
    00039   bool finished;
    00040   void *object;
    00041 } ThreadInfo;
    00042
    00043 class InetWvIn : public WvIn
    00044 {
    00045 public:
    00047
    00050   InetWvIn( unsigned long bufferFrames = 1024, unsigned int nBuffers = 8 );
    00051
    00053   ~InetWvIn();
    00054
    00056
    00063   void listen( int port = 2006, unsigned int nChannels = 1,
    00064                Stk::StkFormat format = STK_SINT16,
    00065                Socket::ProtocolType protocol = Socket::PROTO_TCP );
    00066
    00068
    00072   bool isConnected( void );
    00073
    00075
    00084   StkFloat lastOut( unsigned int channel = 0 );
    00085
    00087
    00097   StkFloat tick( unsigned int channel = 0 );
    00098
    00100
    00109   StkFrames& tick( StkFrames& frames );
    00110
    00111   // Called by the thread routine to receive data via the socket connection
    00112   // and fill the socket buffer.  This is not intended for general use but
    00113   // must be public for access from the thread.
    00114   void receive( void );
    00115
    00116 protected:
    00117
    00118   // Read buffered socket data into the data buffer ... will block if none available.
    00119   int readData( void );
    00120
    00121   Socket *soket_;
    00122   Thread thread_;
    00123   Mutex mutex_;
    00124   char *buffer_;
    00125   unsigned long bufferFrames_;
    00126   unsigned long bufferBytes_;
    00127   unsigned long bytesFilled_;
    00128   unsigned int nBuffers_;
    00129   unsigned long writePoint_;
    00130   unsigned long readPoint_;
    00131   long bufferCounter_;
    00132   int dataBytes_;
    00133   bool connected_;
    00134   int fd_;
    00135   ThreadInfo threadInfo_;
    00136   Stk::StkFormat dataType_;
    00137
    00138 };
    00139
    00140 inline StkFloat InetWvIn :: lastOut( unsigned int channel )
    00141 {
    00142 #if defined(_STK_DEBUG_)
    00143   if ( channel >= data_.channels() ) {
    00144     oStream_ << "InetWvIn::lastOut(): channel argument and data stream are incompatible!";
    00145     handleError( StkError::FUNCTION_ARGUMENT );
    00146   }
    00147 #endif
    00148
    00149   // If no connection and we've output all samples in the queue, return.
    00150   if ( !connected_ && bytesFilled_ == 0 && bufferCounter_ == 0 ) return 0.0;
    00151
    00152   return lastFrame_[channel];
    00153 }
    00154
    00155 } // stk namespace
    00156
    00157 #endif

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