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

#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>
29
30
31
32
#include <iostream>
#include <fstream>
using namespace std;

33

34
class CITANetAudioStreamingClient;
35
36
37
38
39
40
41

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

48
49
50
51
52
53
54
55
56
	enum StreamingStatus
	{
		INVALID = -1,
		STOPPED,
		CONNECTED,
		STREAMING,
		BUFFER_UNDERRUN,
	};

57
	bool Connect( const std::string& sAddress, int iPort );
58
	bool GetIsConnected() const;
59

60
	//! Returns (static) size of ring buffer
61
	int GetRingBufferSize() const;
62
63
64
65
66
67

	//! Returns true if ring buffer is full
	bool GetIsRingBufferFull() const;

	//! Returns true if ring buffer is empty
	bool GetIsRingBufferEmpty() const;
68
69
70
71
72
73
74
75
	
	unsigned int GetBlocklength() const;
	unsigned int GetNumberOfChannels() const;
	double GetSampleRate() const;
	const float* GetBlockPointer( unsigned int uiChannel, const ITAStreamInfo* );
	void IncrementBlockPointer();

protected:
76
77
78
79
80
81
82
	//! 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
	  */
83
84
	int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );

85
86
	//! Returns free samples between write and read cursor
	int GetRingBufferFreeSamples() const;
87

88
private:
89
	CITANetAudioStreamingClient* m_pNetAudioStreamingClient;
90
91
92
93
94

	double m_dSampleRate;
	ITASampleFrame m_sfOutputStreamBuffer;

	int m_iReadCursor; //!< Cursor where samples will be consumed from ring buffer on next block
95
96
	int m_iWriteCursor; //!< Cursor where samples will be fed into ring buffer from net audio producer (always ahead)
	bool m_bRingBufferFull; //!< Indicator if ring buffer is full (and read cursor equals write cursor)
97
	ITASampleFrame m_sfRingBuffer; //!< Buffer incoming data
98

99
100
	int m_iStreamingStatus; //!< Current streaming status

101
102
	friend class CITANetAudioStreamingClient;
	ofstream outputFile;
103
104
105
};

#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAM