ITANetAudioStream.h 2.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
 * ----------------------------------------------------------------
 *
 *		ITA core libs
 *		(c) Copyright Institute of Technical Acoustics (ITA)
 *		RWTH Aachen University, Germany, 2015-2016
 *
 * ----------------------------------------------------------------
 *				    ____  __________  _______
 *				   //  / //__   ___/ //  _   |
 *				  //  /    //  /    //  /_|  |
 *				 //  /    //  /    //  ___   |
 *				//__/    //__/    //__/   |__|
 *
 * ----------------------------------------------------------------
 *
 */

#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_STREAM
#define INCLUDE_WATCHER_ITA_NET_AUDIO_STREAM

#include <ITADataSourcesDefinitions.h>

#include <ITADataSource.h>
#include <ITASampleFrame.h>

#include <string>
#include <vector>

30
class CITANetAudioStreamingClient;
31 32 33 34 35 36 37

//! Network audio stream
/**
 * Audio streaming for a signal source that is connected via TCP/IP.
 *
 * \note not thread-safe
 */
38
class ITA_DATA_SOURCES_API CITANetAudioStream : public ITADatasource
39 40
{
public:
41
	CITANetAudioStream( int iChannels, double dSamplingRate, int iBufferSize, int iRingBufferCapacity = 2048 );
42 43 44
	virtual ~CITANetAudioStream();

	bool Connect( const std::string& sAddress, int iPort );
45
	bool GetIsConnected() const;
46 47 48 49 50 51 52 53 54 55

	int GetRingBufferSize() const;
	
	unsigned int GetBlocklength() const;
	unsigned int GetNumberOfChannels() const;
	double GetSampleRate() const;
	const float* GetBlockPointer( unsigned int uiChannel, const ITAStreamInfo* );
	void IncrementBlockPointer();

protected:
56 57 58 59 60 61 62
	//! This method is called by the streaming client and pushes sampes into the ring buffer
	/**
	  * \param sfNewSamples Sample buffer (multi channel) with sample data
	  * \param iNumSamples samples to be read from the sample frame (must be smaller or equal length)
	  *
	  * \return Number of free samples in ring buffer
	  */
63 64
	int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );

65 66
	int GetRingbufferFreeSamples();

67
private:
68
	CITANetAudioStreamingClient* m_pNetAudioStreamingClient;
69 70 71 72 73 74

	double m_dSampleRate;
	ITASampleFrame m_sfOutputStreamBuffer;

	int m_iReadCursor; //!< Cursor where samples will be consumed from ring buffer on next block
	int m_iWriteCursor; //!< Cursor where samples will feeded into ring buffer from net audio producer
75
	ITASampleFrame m_sfRingBuffer; //!< Buffer incoming data
76

77
	friend class CITANetAudioStreamingClient;
78 79 80
};

#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAM