Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.3KB

  1. #ifndef STK_INETWVOUT_H
  2. #define STK_INETWVOUT_H
  3. #include "WvOut.h"
  4. #include "Socket.h"
  5. namespace stk {
  6. /***************************************************/
  7. /*! \class InetWvOut
  8. \brief STK internet streaming output class.
  9. This WvOut subclass can stream data over a network via a TCP or
  10. UDP socket connection. The data is converted to big-endian byte
  11. order, if necessary, before being transmitted.
  12. InetWvOut supports multi-channel data. It is important to
  13. distinguish the tick() method that outputs a single sample to all
  14. channels in a sample frame from the overloaded one that takes a
  15. reference to an StkFrames object for multi-channel and/or
  16. multi-frame data.
  17. This class connects to a socket server, the port and IP address of
  18. which must be specified as constructor arguments. The default
  19. data type is signed 16-bit integers but any of the defined
  20. StkFormats are permissible.
  21. by Perry R. Cook and Gary P. Scavone, 1995-2011.
  22. */
  23. /***************************************************/
  24. class InetWvOut : public WvOut
  25. {
  26. public:
  27. //! Default constructor ... the socket is not instantiated.
  28. InetWvOut( unsigned long packetFrames = 1024 );
  29. //! Overloaded constructor which opens a network connection during instantiation.
  30. /*!
  31. An StkError is thrown if a socket error occurs or an invalid argument is specified.
  32. */
  33. InetWvOut( int port, Socket::ProtocolType protocol = Socket::PROTO_TCP,
  34. std::string hostname = "localhost", unsigned int nChannels = 1, Stk::StkFormat format = STK_SINT16,
  35. unsigned long packetFrames = 1024 );
  36. //! Class destructor.
  37. ~InetWvOut();
  38. //! Connect to the specified host and port and prepare to stream \e nChannels of data in the given data format.
  39. /*!
  40. An StkError is thrown if a socket error occurs or an invalid argument is specified.
  41. */
  42. void connect( int port, Socket::ProtocolType protocol = Socket::PROTO_TCP,
  43. std::string hostname = "localhost", unsigned int nChannels = 1, Stk::StkFormat format = STK_SINT16 );
  44. //! If a connection is open, write out remaining samples in the queue and then disconnect.
  45. void disconnect( void );
  46. //! Output a single sample to all channels in a sample frame.
  47. /*!
  48. An StkError is thrown if an output error occurs. If a socket
  49. connection does not exist, the function does nothing (a warning
  50. will be issued if _STK_DEBUG_ is defined during compilation).
  51. */
  52. void tick( const StkFloat sample );
  53. //! Output the StkFrames data.
  54. /*!
  55. An StkError will be thrown if an output error occurs. An
  56. StkError will also be thrown if _STK_DEBUG_ is defined during
  57. compilation and there is an incompatability between the number of
  58. channels in the FileWvOut object and that in the StkFrames object.
  59. If a socket connection does not exist, the function does nothing
  60. (a warning will be issued if _STK_DEBUG_ is defined during
  61. compilation).
  62. */
  63. void tick( const StkFrames& frames );
  64. protected:
  65. void incrementFrame( void );
  66. // Write a buffer of length frames via the socket connection.
  67. void writeData( unsigned long frames );
  68. char *buffer_;
  69. Socket *soket_;
  70. unsigned long bufferFrames_;
  71. unsigned long bufferBytes_;
  72. unsigned long bufferIndex_;
  73. unsigned long iData_;
  74. unsigned int dataBytes_;
  75. Stk::StkFormat dataType_;
  76. };
  77. } // stk namespace
  78. #endif