Compiling and linking net audio tests

parent 75f6836b
......@@ -52,7 +52,6 @@ set( ITADataSourcesHeader
"include/ITAPeakDetector.h"
"include/ITARMSDetector.h"
"include/ITAStreamAmplifier.h"
#"include/ITAStreamFilter.h"
"include/ITAStreamFunctionGenerator.h"
"include/ITAStreamModalSynthesizer.h"
"include/ITAStreamMultiplier1N.h"
......@@ -70,10 +69,10 @@ set( ITADataSourcesSources
"src/ITAFileDataSink.cpp"
"src/ITAFileDataSource.cpp"
"src/ITANetAudioStream.cpp"
"src/ITANetAudioSampleServer.cpp"
"src/ITAPeakDetector.cpp"
"src/ITARMSDetector.cpp"
"src/ITAStreamAmplifier.cpp"
#"src/ITAStreamFilter.cpp"
"src/ITAStreamFunctionGenerator.cpp"
"src/ITAStreamModalSynthesizer.cpp"
"src/ITAStreamMultiplier1N.cpp"
......
......@@ -39,8 +39,16 @@ class CITANetAudioStreamServer;
class ITA_DATA_SOURCES_API CITANetAudioSampleServer
{
public:
enum UpdateStrategy
{
AUTO = 1, //!< Automatic update rate based on sample rate and block length of client (default)
ADAPTIVE, //!< Adaptive update rate, adjusts for drifting clocks
CONSTANT, //!< Set a user-defined update rate (may cause forced pausing of sample feeding or dropouts on client side)
};
CITANetAudioSampleServer();
virtual ~CITANetAudioSampleServer();
virtual ~CITANetAudioSampleServer() {};
bool Start( const std::string& sAddress, int iPort );
bool IsClientConnected() const;
......@@ -54,14 +62,19 @@ public:
int GetNetStreamNumberOfChannels() const;
double GetNetStreamSampleRate() const;
void SetAutomaticUpdateRate();
protected:
int Transmit( const ITASampleFrame& sfNewSamples, int iNumSamples );
ITADatasource* GetInputStream() const;
private:
CITANetAudioStreamServer* m_pNetAudioServer;
ITASampleFrame m_sfTempTransmitBuffer;
ITADatasource* m_pInputStream;
int m_iUpdateStrategy;
friend class CITANetAudioStreamServer;
};
......
......@@ -27,7 +27,7 @@
#include <string>
#include <vector>
class ITA_DATA_SOURCES_API CITANetAudioStreamConnection;
class CITANetAudioStreamConnection;
//! Network audio stream
/**
......@@ -35,7 +35,7 @@ class ITA_DATA_SOURCES_API CITANetAudioStreamConnection;
*
* \note not thread-safe
*/
class CITANetAudioStream : public ITADatasource
class ITA_DATA_SOURCES_API CITANetAudioStream : public ITADatasource
{
public:
CITANetAudioStream( int iChannels, double dSamplingRate, int iBufferSize, int iRingBufferCapacity );
......
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2016
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
// $Id: ITAStreamFunctionGenerator.h 2900 2012-09-17 08:42:42Z stienen $
#ifndef INCLUDE_WATCHER_ITA_STREAM_FILTER
#define INCLUDE_WATCHER_ITA_STREAM_FILTER
#include <ITADataSourcesDefinitions.h>
#include <ITADataSource.h>
#include <ITATypes.h>
#include <vector>
class ITAStreamFilter : public ITADatasource
{
public:
//! Konstruktor
ITAStreamFilter(ITADatasource* pdsInput=NULL);
//! Destruktor
virtual ~ITAStreamFilter();
//! Eingangsdatenquelle zurckgeben
ITADatasource* GetInputDatasource() const;
// TODO: Erstmal aus...
//! Eingangsdatenquelle setzen
//void SetInputDatasource(ITADatasource* pdsInput);
// -= Realisierung der abstrakten Methoden von "ITADatasource" =-
const float* GetBlockPointer(unsigned int uiChannel, bool bWaitForData=true);
void IncrementBlockPointer();
protected:
//! Verarbeitungsmethode
/**
* In dieser Methode werden die neue Eingangsdaten aller Kanle verarbeitet und das Filter berechnet.
*/
virtual void ProcessAllChannels(const float** ppfInputData, float** ppfOutputData) {
/*
Hinweis: Diese Vorgabe-Implementierung setzt den Methodenaufruf in die kanalweise
Verarbeitung mittels der Methode "ProcessChannel" um. Diese Verfahrensweise
ist adquat fr Filter welche eine kanal-unabhngige Verarbeitung erlauben.
Mchten Sie einen Filter mit kanal-abhngiger Verarbeitung bauen,
so muss diese Methode entsprechend angepasst werden.
Hierbei mssen Sie nicht zwangslufig die Methode "ProcessChannel" involvieren.
*/
for (unsigned int i=0; i<m_uiChannels; i++) ProcessChannel(i, ppfInputData[i], ppfOutputData[i]);
}
//! Verarbeitungsmethode
/**
* In dieser Methode werden fr einen Kanal neue Eingangsdaten verarbeitet und das Filter berechnet.
* Diese Methode wird die kanal-unabhngige Datenverarbeitung des Filters realisiert. Kanal-unabhngig
* bedeutet, dass die Ausgangsdaten dieses Kanals einzig aus den Eingangsdaten des selben Kanals
* berechnet werden knnen.
*/
virtual void ProcessChannel(unsigned int uiChannel, const float* pfInputData, float* pfOutputData) {
// Dies ist eine Vorgabe-Implementierung, welche die Eingangsdaten unverndert in die Ausgabe kopiert
//fm_copy(pfOutputData, pfInputData, m_uiBlocklength);
memcpy(pfOutputData, pfInputData, m_uiBlocklength * sizeof(float));
}
private:
ITADatasource* m_pdsInput; // Eingangsdatenquelle
std::vector<const float*> m_vpfInputData; // Eingangsdatenzeiger
std::vector<float*> m_vpfOutputBuffer; // Ausgabepuffer
bool m_bGBPCalled; // Flag die Anzeigt ob seit dem letzten IncrementBlockPointer (IBP)
// bereits ein erneuter Eintritt in GetBlockPointer (GBP) erfolgt ist
};
#endif // INCLUDE_WATCHER_ITA_STREAM_FILTER
\ No newline at end of file
......@@ -37,16 +37,6 @@ public:
WHITE_NOISE //!< White noise
};
//! Constructor
/**
* Creates a new function generator.
*
* \param uiChannels Number of output channels
* \param dSamplerate Sampling rate [Hz]
* \param uiBlocklength Blocklength [samples]
*/
ITAStreamFunctionGenerator( unsigned int uiChannels, double dSamplerate, unsigned int uiBlocklength );
//! Constructor
/**
* Creates a new function generator with specific parameters
......@@ -62,7 +52,7 @@ public:
ITAStreamFunctionGenerator( unsigned int uiChannels, double dSamplerate, unsigned int uiBlocklength, int iSignalFunction, double dFrequency, float fAmplitude, bool bPeriodic );
//! Destructor
virtual ~ITAStreamFunctionGenerator();
inline virtual ~ITAStreamFunctionGenerator() {};
//! Reset
/**
......
#include <ITANetAudioSampleServer.h>
// ITA includes
#include <ITADataSource.h>
#include <ITAException.h>
#include <ITAStreamInfo.h>
// Vista includes
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaInterProcComm/IPNet/VistaTCPServer.h>
#include <VistaInterProcComm/IPNet/VistaTCPSocket.h>
#include <VistaBase/VistaTimeUtils.h>
#include <VistaInterProcComm/IPNet/VistaIPAddress.h>
// STL
#include <cmath>
#include <cassert>
class CITANetAudioStreamServer : public VistaThreadLoop
{
public:
enum MessageType
{
NET_MESSAGE_NONE = 0,
NET_MESSAGE_OPEN,
NET_MESSAGE_CLOSE,
NET_MESSAGE_SAMPLES,
};
inline CITANetAudioStreamServer( CITANetAudioSampleServer* pParent )
: m_pParent( pParent )
, m_bStopIndicated( false )
, m_pServer( NULL )
, m_pSocket( NULL )
, m_iClientRingBufferSize( - 1 )
, m_iClientBufferSize( -1 )
, m_iClientRingBufferFreeSamples( 0 )
, m_dClientSampleRate( -1 )
{
};
inline ~CITANetAudioStreamServer()
{
};
inline std::string GetServerAddress() const
{
if( m_pServer )
{
std::string sAddress;
m_pServer->GetServerAddress().GetIPAddress().GetAddressString( sAddress );
return sAddress;
}
else
return "";
};
inline int GetNetworkPort() const
{
if( m_pServer )
m_pServer->GetServerAddress().GetPortNumber();
else
return -1;
};
inline bool Start( const std::string& sAddress, int iPort )
{
if( m_pServer )
ITA_EXCEPT1( MODAL_EXCEPTION, "This net sample server is already started" );
m_pServer = new VistaTCPServer( sAddress, iPort, 1 );
m_pSocket = m_pServer->GetNextClient();
long nIncomingBytes = m_pSocket->WaitForIncomingData( 0 );
int iBytesReceived = m_pSocket->ReceiveRaw( &m_iClientChannels, sizeof( int ) );
iBytesReceived = m_pSocket->ReceiveRaw( &m_dClientSampleRate, sizeof( double ) );
iBytesReceived = m_pSocket->ReceiveRaw( &m_iClientBufferSize, sizeof( int ) );
iBytesReceived = m_pSocket->ReceiveRaw( &m_iClientRingBufferSize, sizeof( int ) );
m_iClientRingBufferFreeSamples = m_iClientRingBufferFreeSamples;
int iMessageID = 1;
m_pSocket->SendRaw( &iMessageID, sizeof( int ) );
Run();
};
inline void Disconnect()
{
m_bStopIndicated = true;
StopGently( true );
m_pSocket = NULL;
delete m_pServer;
m_pServer = NULL;
m_bStopIndicated = false;
};
inline bool IsConnected() const
{
if( !m_pSocket )
return false;
return m_pSocket->GetIsConnected();
};
inline bool LoopBody()
{
if( m_bStopIndicated )
return true;
if( m_pSocket->GetIsConnected() == false )
{
StopGently( true );
return false;
}
ITAStreamInfo oStreamInfo;
ITADatasource* pIn = m_pParent->GetInputStream();
for( int iChannelIndex = 0; iChannelIndex < int( m_pParent->GetInputStream()->GetNumberOfChannels() ); iChannelIndex++ )
{
const float* pfData = pIn->GetBlockPointer( iChannelIndex, &oStreamInfo );
int iNumSamples = pIn->GetBlocklength();
m_pSocket->SendRaw( pfData, iNumSamples * sizeof( float ) );
}
return true;
};
private:
VistaTCPServer* m_pServer;
VistaTCPSocket* m_pSocket;
CITANetAudioSampleServer* m_pParent;
ITASampleFrame m_sfReceivingBuffer;
bool m_bStopIndicated;
int m_iClientChannels;
int m_iClientRingBufferSize;
int m_iClientBufferSize;
int m_iClientRingBufferFreeSamples;
double m_dClientSampleRate;
};
CITANetAudioSampleServer::CITANetAudioSampleServer()
: m_pInputStream( NULL )
, m_iUpdateStrategy( AUTO )
{
m_pNetAudioServer = new CITANetAudioStreamServer( this );
}
bool CITANetAudioSampleServer::Start( const std::string& sAddress, int iPort )
{
return m_pNetAudioServer->Start( sAddress, iPort );
}
bool CITANetAudioSampleServer::IsClientConnected() const
{
return m_pNetAudioServer->IsConnected();
}
std::string CITANetAudioSampleServer::GetNetworkAddress() const
{
return m_pNetAudioServer->GetServerAddress();
}
int CITANetAudioSampleServer::GetNetworkPort() const
{
return m_pNetAudioServer->GetNetworkPort();
}
void CITANetAudioSampleServer::SetInputStream( ITADatasource* pInStream )
{
m_pInputStream = pInStream;
}
void CITANetAudioSampleServer::SetAutomaticUpdateRate()
{
m_iUpdateStrategy = AUTO;
}
ITADatasource* CITANetAudioSampleServer::GetInputStream() const
{
return m_pInputStream;
}
/*
+----------------------------------------------------------+
| |
| ITAStreamFilter.cpp |
| Eine abstrakte Basisklasse fr Filter welche |
| auf Audiostreams arbeiten |
| |
| Autoren: Frank Wefers |
| |
| (c) Copyright Institut fr technische Akustik (ITA) |
| Aachen university of technology (RWTH), 2008 |
| |
+----------------------------------------------------------+
*/
// $Id: ITAStreamFilter.cpp,v 1.2 2008-09-02 08:53:35 fwefers Exp $
#include "ITAStreamFilter.h"
#include <ITAException.h>
ITAStreamFilter::ITAStreamFilter(ITADatasource* pdsInput)
: ITADatasource(pdsInput->GetBlocklength(), pdsInput->GetNumberOfChannels(), pdsInput->GetSamplerate()),
m_pdsInput(pdsInput),
m_vpfInputData(pdsInput->GetNumberOfChannels()),
m_vpfOutputBuffer(pdsInput->GetNumberOfChannels(), NULL) {
// Ausgabepuffer allozieren (SIMD-aligned!)
for (unsigned int i=0; i<m_uiChannels; i++)
m_vpfOutputBuffer[i] = fm_falloc(m_uiBlocklength);
m_bGBPCalled = false;
if (pdsInput != NULL) SetInputDatasource(pdsInput);
}
ITAStreamFilter::~ITAStreamFilter() {
delete[] m_ppfInputData;
if (m_ppfOutputBuffer)
for (unsigned int i=0; i<m_uiChannels; i++) delete[] m_ppfOutputBuffer[i];
delete[] m_ppfOutputBuffer;
}
ITADatasource* ITAStreamFilter::GetInputDatasource() const { return m_pdsInput; }
void ITAStreamFilter::SetInputDatasource(ITADatasource* pdsInput) {
/* Hinweis: Sicherstellen, das sobald erstmal eine Datenquelle zugeordnet wurde,
die Zuordnung zu einer Datenquelle nicht mehr aufgehoben werden kann (Nullzeiger).
Also: Es drfen andere Datenquellen gesetzt werden, diese mssen aber
die selben Eigenschaften ausweisen, wie die erstmalig zugeordnete Datenquelle. */
if (pdsInput == NULL)
ITA_EXCEPT1(INVALID_PARAMETER, "Nullpointer not allowed as parameter");
// Wurde schon erstmalig eine Datenquelle zuordnet? Dann auf gleiche Eigenschaften prfen!
if (m_pdsInput != NULL) {
if ((pdsInput->GetBlocklength() != m_uiBlocklength) ||
(pdsInput->GetNumberOfChannels() != m_uiChannels) ||
(pdsInput->GetSamplerate() != m_dSamplerate))
ITA_EXCEPT1(INVALID_PARAMETER, "The new datasources' properties do not match the previous datasources' properties");
// TODO: Bei alter Datenquelle aufrumen? z.B. IncrementBlockPointer aufrufen?
for (unsigned int i=0; i<m_uiChannels; i++)
for (unsigned int j=0; j<m_uiBlocklength; j++)
m_ppfOutputBuffer[i][j] = 0;
} else {
// Erstmalige Zuordnung. Sicherstellen das alle Datenquellen-Eigenschaften bereits festgelegt sind
if ((pdsInput->GetBlocklength() == 0) ||
(pdsInput->GetNumberOfChannels() == 0) ||
(pdsInput->GetSamplerate() == 0))
ITA_EXCEPT1(INVALID_PARAMETER, "The input datasources' properties are not (completely) defined yet");
m_pdsInput = pdsInput;
m_uiChannels = m_pdsInput->GetNumberOfChannels();
m_uiBlocklength = m_pdsInput->GetBlocklength();
m_dSamplerate = m_pdsInput->GetSamplerate();
m_ppfOutputBuffer = new float*[m_uiChannels];
memset(m_ppfOutputBuffer, 0, m_uiChannels * sizeof(float*));
for (unsigned int i=0; i<m_uiChannels; i++) m_ppfOutputBuffer[i] = new float[m_uiBlocklength];
for (unsigned int i=0; i<m_uiChannels; i++)
for (unsigned int j=0; j<m_uiBlocklength; j++)
m_ppfOutputBuffer[i][j] = 0;
m_ppfInputData = new const float*[m_uiChannels];
}
m_bGBPCalled = false;
}
const float* ITAStreamFilter::GetBlockPointer(unsigned int uiChannel, bool bWaitForData) {
if ((m_pdsInput != NULL) && !m_bGBPCalled) {
// Daten holen
for (unsigned int i=0; i<m_uiChannels; i++)
m_ppfInputData[i] = m_pdsInput->GetBlockPointer(i, bWaitForData);
// Filter berechnen
ProcessAllChannels(m_ppfInputData, m_ppfOutputBuffer);
m_bGBPCalled = true;
}
return m_ppfOutputBuffer[uiChannel];
}
void ITAStreamFilter::IncrementBlockPointer() {
if (m_pdsInput) m_pdsInput->IncrementBlockPointer();
m_bGBPCalled = false;
}
\ No newline at end of file
......@@ -38,8 +38,6 @@ ITAStreamFunctionGenerator::ITAStreamFunctionGenerator(unsigned int uiChannels,
Reset();
}
ITAStreamFunctionGenerator::~ITAStreamFunctionGenerator() {}
void ITAStreamFunctionGenerator::Reset()
{
m_iSampleCount = 0;
......
......@@ -13,9 +13,7 @@ static int g_iBlockLength = 265;
int main( int , char** )
{
ITAStreamFunctionGenerator oGenerator( 1, g_dSampleRate, g_iBlockLength );
oGenerator.SetFunction( ITAStreamFunctionGenerator::SINE );
oGenerator.SetFrequency( 567.89f );
ITAStreamFunctionGenerator oGenerator( 1, g_dSampleRate, g_iBlockLength, ITAStreamFunctionGenerator::SINE, 456.78f, 0.81f, true );
CITANetAudioSampleServer oSampleServer;
oSampleServer.SetInputStream( &oGenerator );
......
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