Commit 8bc757bd authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen

Merging server impl of NetAudio

parents a10c1417 a4a9fd6d
......@@ -64,7 +64,7 @@ public:
~CITANetAudioStreamingServer();
//! Start to listen on a socket (blocking)
bool Start( const std::string& sAddress, const int iPort, const double dTimeIntervalCientSendStatus );
bool Start(const std::string& sAddress, const int iPort, const double dTimeIntervalCientSendStatus);
bool IsClientConnected() const;
std::string GetNetworkAddress() const;
int GetNetworkPort() const;
......@@ -77,6 +77,9 @@ public:
int GetNetStreamNumberOfChannels() const;
double GetNetStreamSampleRate() const;
int GetSendingBlockLength() const;
void SetSendingBlockLength( const int iSendingBlockLength );
void SetAutomaticUpdateRate();
void SetTargetLatencySamples( const int iTargetLatency );
......@@ -108,6 +111,7 @@ private:
int m_iEstimatedClientRingBufferFreeSamples;
int m_iTargetLatencySamples;
int m_iMaxSendBlocks;
int m_iSendingBlockLength;
double m_dLastTimeStamp;
friend class CITANetAudioServer;
......
......@@ -81,7 +81,7 @@ CITANetAudioStreamingServer::~CITANetAudioStreamingServer()
vstr::out() << "[ ITANetAudioStreamingServer ] Try-read access statistics: " << m_swTryReadAccessStats.ToString() << std::endl;
}
bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort, double dTimeIntervalCientSendStatus )
bool CITANetAudioStreamingServer::Start(const std::string& sAddress, int iPort, double dTimeIntervalCientSendStatus)
{
if( !m_pInputStream )
ITA_EXCEPT1( MODAL_EXCEPTION, "Can not start server without a valid input stream" );
......@@ -133,6 +133,7 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort,
#ifdef NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "[ITANetAudioStreamingServer] Server and client parameters mismatch detected. Will notify client and stop." << std::endl;
#endif
return false;
}
}
......@@ -147,28 +148,27 @@ bool CITANetAudioStreamingServer::LoopBody()
oLog.iTransmittedSamples = 0;
// Sending Samples
int iBlockLength = m_pInputStream->GetBlocklength();
int iEstimatedClientRingBufferTargetLatencyFreeSamples = m_iEstimatedClientRingBufferFreeSamples - ( m_oServerParams.iRingBufferSize - m_iTargetLatencySamples );
if( iEstimatedClientRingBufferTargetLatencyFreeSamples >= iBlockLength )
if (iEstimatedClientRingBufferTargetLatencyFreeSamples >= m_iSendingBlockLength)
{
// Send Samples
int iSendBlocks = iEstimatedClientRingBufferTargetLatencyFreeSamples / iBlockLength;
int iSendBlocks = iEstimatedClientRingBufferTargetLatencyFreeSamples / m_iSendingBlockLength;
// Besser wre vermutlich, gleich alle samples zu senden und nicht nur einen Block nach dem anderen
if( m_sfTempTransmitBuffer.GetLength() != iBlockLength )
m_sfTempTransmitBuffer.init( m_pInputStream->GetNumberOfChannels(), iBlockLength, false );
if (m_sfTempTransmitBuffer.GetLength() != m_iSendingBlockLength)
m_sfTempTransmitBuffer.init(m_pInputStream->GetNumberOfChannels(), m_iSendingBlockLength, false);
for( int j = 0; j < iSendBlocks; j++ )
{
for( int i = 0; i < int( m_pInputStream->GetNumberOfChannels() ); i++ )
{
ITAStreamInfo oStreamInfo;
oStreamInfo.nSamples = iBlockLength;
oStreamInfo.nSamples = m_iSendingBlockLength;
const float* pfData = m_pInputStream->GetBlockPointer( i, &oStreamInfo );
if( pfData != 0 )
m_sfTempTransmitBuffer[ i ].write( pfData, iBlockLength, 0 );
m_sfTempTransmitBuffer[i].write(pfData, m_iSendingBlockLength, 0);
}
m_pInputStream->IncrementBlockPointer();
......@@ -177,7 +177,7 @@ bool CITANetAudioStreamingServer::LoopBody()
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_SERVER_SENDING_SAMPLES );
m_pMessage->WriteSampleFrame( &m_sfTempTransmitBuffer );
m_pMessage->WriteMessage();
m_iEstimatedClientRingBufferFreeSamples -= iBlockLength;
m_iEstimatedClientRingBufferFreeSamples -= m_iSendingBlockLength;
}
#ifdef NET_AUDIO_SHOW_TRAFFIC
......@@ -266,6 +266,16 @@ int CITANetAudioStreamingServer::GetNetStreamBlocklength() const
return m_sfTempTransmitBuffer.GetLength();
}
int CITANetAudioStreamingServer::GetSendingBlockLength() const
{
return m_iSendingBlockLength;
}
void CITANetAudioStreamingServer::SetSendingBlockLength(const int iSendingBlockLength)
{
m_iSendingBlockLength = iSendingBlockLength;
}
int CITANetAudioStreamingServer::GetNetStreamNumberOfChannels() const
{
return m_sfTempTransmitBuffer.channels();
......
......@@ -21,6 +21,7 @@ int g_iBlockLength = 512;
int g_iChannels = 2;
int g_iTargetLatencySamples = 2 * g_iBlockLength; // 1.4512ms
int g_iRingBufferSize = 2 * g_iTargetLatencySamples;
int g_iSendingBlockLength = 8;
double g_dPlaybackDuration = 10 ; // seconds
int main( int argc, char* argv[] )
......@@ -37,6 +38,7 @@ int main( int argc, char* argv[] )
g_iChannels = atoi(argv[5]);
g_iTargetLatencySamples = atoi(argv[6]);
g_iRingBufferSize = atoi(argv[7]);
g_iSendingBlockLength = atoi(argv[8]);
}
if( argc >= 9 )
......@@ -58,6 +60,7 @@ int main( int argc, char* argv[] )
ss << "_B" << g_iBlockLength;
ss << "_TL" << g_iTargetLatencySamples;
ss << "_RB" << g_iRingBufferSize;
ss << "_SB" << g_iSendingBlockLength;
oNetAudioStream.SetNetAudioStreamingLoggerBaseName( ss.str() );
ITAStreamPatchbay oPatchbay( g_dSampleRate, g_iBlockLength );
......
......@@ -18,6 +18,7 @@ int g_iBlockLength = 512;
int g_iChannels = 1;
int g_iTargetLatencySamples = 4 * g_iBlockLength; // 1.4512ms
int g_iRingBufferSize = 2 * g_iTargetLatencySamples;
int g_iSendingBlockLength = 8;
double g_dClientStatusMessageTimeout = 0.001; // seconds
string g_sFileName = "gershwin-mono.wav";
......@@ -34,13 +35,14 @@ int main( int argc, char** argv )
g_dSampleRate = strtod( argv[ 3 ], NULL );
g_iBlockLength = atoi( argv[ 4 ] );
g_iChannels = atoi( argv[ 5 ] );
g_iTargetLatencySamples = atoi( argv[ 6 ] );
g_iRingBufferSize = atoi( argv[ 7 ] );
g_iTargetLatencySamples = atoi(argv[6]);
g_iRingBufferSize = atoi(argv[7]);
g_iSendingBlockLength = atoi(argv[8]);
}
}
else
{
cout << "Syntax: ServerName ServerPort SampleRate BufferSize Channel TargetLatencySamples RingBufferSize" << endl;
cout << "Syntax: ServerName ServerPort SampleRate BufferSize Channel TargetLatencySamples RingBufferSize SnedingBlockLength" << endl;
cout << "Using default values ..." << endl;
}
......@@ -67,10 +69,12 @@ int main( int argc, char** argv )
ss << "_B" << g_iBlockLength;
ss << "_TL" << g_iTargetLatencySamples;
ss << "_RB" << g_iRingBufferSize;
ss << "_SB" << g_iSendingBlockLength;
oStreamingServer.SetServerLogBaseName( ss.str() );
oStreamingServer.SetInputStream( &oMuliplier );
oStreamingServer.SetTargetLatencySamples( g_iTargetLatencySamples );
oStreamingServer.SetSendingBlockLength( g_iSendingBlockLength );
cout << "Starting net audio server and waiting for connections on '" << g_sServerName << "' on port " << g_iServerPort << endl;
if( oStreamingServer.Start( g_sServerName, g_iServerPort, g_dClientStatusMessageTimeout ) )
......
......@@ -24,7 +24,7 @@ const static string g_sServerName = "localhost";
const static string g_sInputFilePath = "gershwin-mono.wav";
const static int g_iServerPort = 12480;
const static double g_dSampleRate = 44100;
const static int g_iBlockLength = 256;
const static int g_iBlockLength = 32;
const static int g_iChannels = 2;
const static int g_iTargetLatencySamples = g_iBlockLength * 1;
const static int g_iRingerBufferCapacity = g_iBlockLength * 5;
......
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