Commit 9804d5ef authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Adding sample server stub and test for net audio classes

parent af53a171
......@@ -48,6 +48,7 @@ set( ITADataSourcesHeader
"include/ITAFileDataSink.h"
"include/ITAFileDataSource.h"
"include/ITANetAudioStream.h"
"include/ITANetAudioSampleServer.h"
"include/ITAPeakDetector.h"
"include/ITARMSDetector.h"
"include/ITAStreamAmplifier.h"
......
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2016
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_NET_AUDIO_SAMPLE_SERVER
#define INCLUDE_WATCHER_ITA_NET_AUDIO_SAMPLE_SERVER
#include <ITADataSourcesDefinitions.h>
#include <string>
#include <vector>
class ITADatasource;
//! Network audio sample server (for connecting a net audio stream)
/**
* Audio sample transmitter for a networked signal source that can connect via TCP/IP.
*
* \sa CITANetAudioStream
* \note not thread-safe
*/
class CITANetAudioSampleServer
{
public:
CITANetAudioSampleServer();
virtual ~CITANetAudioStream();
bool Start( const std::string& sAddress, int iPort );
bool IsClientConnected() const;
std::string GetNetworkAddress() const;
int GetNetworkPort() const;
int Stop();
void SetInputStream( ITADatasource* pInStream );
int GetNetStreamBlocklength() const;
int GetNetStreamNumberOfChannels() const;
double GetNetStreamSampleRate() const;
protected:
int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );
private:
CITANetAudioStreamServer* m_pNetAudioServer;
ITASampleFrame m_sfTempTransmitBuffer;
ITADatasource* m_pInputStream;
friend class CITANetAudioStreamServer;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_SAMPLE_SERVER
......@@ -124,40 +124,40 @@ CITANetAudioStream::~CITANetAudioStream()
delete m_pNetAudioProducer;
}
int CITANetAudioStream::GetRingBufferSize() const
const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const ITAStreamInfo* )
{
return m_sfRingBuffer.GetLength();
// @todo: implement cyclic read from ring buffer
return m_sfOutputStreamBuffer[ uiChannel ].GetData();
}
unsigned int CITANetAudioStream::GetBlocklength() const
void CITANetAudioStream::IncrementBlockPointer()
{
return ( unsigned int ) m_sfOutputStreamBuffer.GetLength();
// Increment read cursor by one audio block and wrap around if exceeding ring buffer
m_iReadCursor = ( m_iReadCursor + m_sfOutputStreamBuffer.GetLength() ) % m_sfRingBuffer.GetLength();
}
unsigned int CITANetAudioStream::GetNumberOfChannels() const
int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples )
{
return ( unsigned int ) m_sfOutputStreamBuffer.channels();
ITA_EXCEPT0( NOT_IMPLEMENTED );
}
double CITANetAudioStream::GetSampleRate() const
int CITANetAudioStream::GetRingBufferSize() const
{
return m_dSampleRate;
return m_sfRingBuffer.GetLength();
}
const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const ITAStreamInfo* )
unsigned int CITANetAudioStream::GetBlocklength() const
{
// @todo: implement cyclic read from ring buffer
return m_sfOutputStreamBuffer[ uiChannel ].GetData();
return ( unsigned int ) m_sfOutputStreamBuffer.GetLength();
}
void CITANetAudioStream::IncrementBlockPointer()
unsigned int CITANetAudioStream::GetNumberOfChannels() const
{
// Increment read cursor by one audio block and wrap around if exceeding ring buffer
m_iReadCursor = ( m_iReadCursor + m_sfOutputStreamBuffer.GetLength() ) % m_sfRingBuffer.GetLength();
return ( unsigned int ) m_sfOutputStreamBuffer.channels();
}
int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples )
double CITANetAudioStream::GetSampleRate() const
{
ITA_EXCEPT0( NOT_IMPLEMENTED );
return m_dSampleRate;
}
......@@ -30,3 +30,23 @@ vista_install( ITANAPlayerTest )
vista_create_default_info_file( ITANAPlayerTest )
set_property( TARGET ITANAPlayerTest PROPERTY FOLDER "ITACoreLibs/Tests/ITADataSources/NetAudio" )
add_executable( ITANetAudioSampleServerTest ITANetAudioSampleServerTest.cpp )
target_link_libraries( ITANetAudioSampleServerTest ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_configure_app( ITANetAudioSampleServerTest )
vista_install( ITANetAudioSampleServerTest )
vista_create_default_info_file( ITANetAudioSampleServerTest )
set_property( TARGET ITANetAudioSampleServerTest PROPERTY FOLDER "ITACoreLibs/Tests/ITADataSources/NetAudio" )
add_executable( ITANetAudioClientTest ITANetAudioClientTest.cpp )
target_link_libraries( ITANetAudioClientTest ${VISTA_USE_PACKAGE_LIBRARIES} )
vista_configure_app( ITANetAudioClientTest )
vista_install( ITANetAudioClientTest )
vista_create_default_info_file( ITANetAudioClientTest )
set_property( TARGET ITANetAudioClientTest PROPERTY FOLDER "ITACoreLibs/Tests/ITADataSources/NetAudio" )
#include <iostream>
#include <string>
#include <ITANetAudioStream.h>
#include <ITAPortaudioInterface.h>
#include <ITAStreamMultiplier1N.h>
#include <ITAException.h>
using namespace std;
static string g_sServerName = "localhost";
static int g_iServerPort = 12480;
static double g_dSampleRate = 44.1e3;
static int g_iBufferSize = 256;
int main( int , char** )
{
CITANetAudioStream oNetAudioStream( 1, g_dSampleRate, g_iBufferSize, 4 * g_iBufferSize );
ITAStreamMultiplier1N oMultiplier( &oNetAudioStream, 2 );
ITAPortaudioInterface ITAPA( g_dSampleRate, g_iBufferSize );
ITAPA.Initialize();
ITAPA.SetPlaybackDatasource( &oMultiplier );
ITAPA.Open();
ITAPA.Start();
cout << "Waiting 3 seconds (net audio stream not connected and returning zeros)" << endl;
ITAPA.Sleep( 3.0f );
cout << "Will now connect to '" << g_sServerName << "' on port " << g_iServerPort << endl;
try
{
oNetAudioStream.Connect( g_sServerName, g_iServerPort );
}
catch( ITAException e )
{
cout << "Connection failed." << endl;
cerr << e << endl;
return 255;
}
cout << "Connected." << endl;
// Playback
float fSeconds = 10.0f;
cout << "Playback started, waiting " << fSeconds << " seconds" << endl;
ITAPA.Sleep( fSeconds ); // blocking
cout << "Done." << endl;
cout << "Will now disconnect from '" << g_sServerName << "' and port " << g_iServerPort << endl;
cout << "Closing in 3 seconds (net audio stream not connected and returning zeros)" << endl;
ITAPA.Sleep( 3.0f );
ITAPA.Stop();
ITAPA.Close();
ITAPA.Finalize();
return 0;
}
#include <iostream>
#include <string>
#include <ITANetAudioSampleServer.h>
#include <ITAStreamFunctionGenerator.h>
using namespace std;
static string g_sServerName = "localhost";
static int g_iServerPort = 12480;
static double g_dSampleRate = 44.1e3;
int main( int , char** )
{
ITAStreamFunctionGenerator oGenerator();
CITANetAudioSampleServer oSampleServer();
oSampleServer.Start( g_iServerPort, g_iServerPort );
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment