Aufgrund einer Wartung wird GitLab am 26.10. zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 26.10. between 8:00 and 9:00 am.

ITANetAudioStream.h 3.05 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
class ITABufferedAudiofileWriter;
36
37
38
39
40
41
42

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

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

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

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

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

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

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

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

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

	double m_dSampleRate;
	ITASampleFrame m_sfOutputStreamBuffer;

	int m_iReadCursor; //!< Cursor where samples will be consumed from ring buffer on next block
96
97
	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)
98
	ITASampleFrame m_sfRingBuffer; //!< Buffer incoming data
99

100
101
	ITABufferedAudiofileWriter* m_pfNetStreamSampleWriter;

102
103
	int m_iStreamingStatus; //!< Current streaming status

104
105
	friend class CITANetAudioStreamingClient;
	ofstream outputFile;
106
107
108
};

#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAM