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

Commit df4aa311 authored by Anne Heimes's avatar Anne Heimes

server sendet variable Blocklängen

parent 79a868df
...@@ -64,7 +64,7 @@ public: ...@@ -64,7 +64,7 @@ public:
~CITANetAudioStreamingServer(); ~CITANetAudioStreamingServer();
//! Start to listen on a socket (blocking) //! 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; bool IsClientConnected() const;
std::string GetNetworkAddress() const; std::string GetNetworkAddress() const;
int GetNetworkPort() const; int GetNetworkPort() const;
...@@ -77,6 +77,9 @@ public: ...@@ -77,6 +77,9 @@ public:
int GetNetStreamNumberOfChannels() const; int GetNetStreamNumberOfChannels() const;
double GetNetStreamSampleRate() const; double GetNetStreamSampleRate() const;
int GetSendingBlockLength() const;
void SetSendingBlockLength( const int iSendingBlockLength );
void SetAutomaticUpdateRate(); void SetAutomaticUpdateRate();
void SetTargetLatencySamples( const int iTargetLatency ); void SetTargetLatencySamples( const int iTargetLatency );
...@@ -108,6 +111,7 @@ private: ...@@ -108,6 +111,7 @@ private:
int m_iEstimatedClientRingBufferFreeSamples; int m_iEstimatedClientRingBufferFreeSamples;
int m_iTargetLatencySamples; int m_iTargetLatencySamples;
int m_iMaxSendBlocks; int m_iMaxSendBlocks;
int m_iSendingBlockLength;
double m_dLastTimeStamp; double m_dLastTimeStamp;
friend class CITANetAudioServer; friend class CITANetAudioServer;
......
...@@ -81,7 +81,7 @@ CITANetAudioStreamingServer::~CITANetAudioStreamingServer() ...@@ -81,7 +81,7 @@ CITANetAudioStreamingServer::~CITANetAudioStreamingServer()
vstr::out() << "[ ITANetAudioStreamingServer ] Try-read access statistics: " << m_swTryReadAccessStats.ToString() << std::endl; 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 ) if( !m_pInputStream )
ITA_EXCEPT1( MODAL_EXCEPTION, "Can not start server without a valid input stream" ); ITA_EXCEPT1( MODAL_EXCEPTION, "Can not start server without a valid input stream" );
...@@ -128,6 +128,8 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort, ...@@ -128,6 +128,8 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort,
m_pMessage->WriteDouble( dTimeIntervalCientSendStatus ); m_pMessage->WriteDouble( dTimeIntervalCientSendStatus );
m_pMessage->WriteMessage(); m_pMessage->WriteMessage();
m_iSendingBlockLength = m_pInputStream->GetBlocklength();
m_sfTempTransmitBuffer.init( m_pInputStream->GetNumberOfChannels(), m_oServerParams.iRingBufferSize, true ); m_sfTempTransmitBuffer.init( m_pInputStream->GetNumberOfChannels(), m_oServerParams.iRingBufferSize, true );
...@@ -147,28 +149,27 @@ bool CITANetAudioStreamingServer::LoopBody() ...@@ -147,28 +149,27 @@ bool CITANetAudioStreamingServer::LoopBody()
oLog.iTransmittedSamples = 0; oLog.iTransmittedSamples = 0;
// Sending Samples // Sending Samples
int iBlockLength = m_pInputStream->GetBlocklength();
int iEstimatedClientRingBufferTargetLatencyFreeSamples = m_iEstimatedClientRingBufferFreeSamples - ( m_oServerParams.iRingBufferSize - m_iTargetLatencySamples ); int iEstimatedClientRingBufferTargetLatencyFreeSamples = m_iEstimatedClientRingBufferFreeSamples - ( m_oServerParams.iRingBufferSize - m_iTargetLatencySamples );
if( iEstimatedClientRingBufferTargetLatencyFreeSamples >= iBlockLength ) if (iEstimatedClientRingBufferTargetLatencyFreeSamples >= m_iSendingBlockLength)
{ {
// Send Samples // 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 // Besser wre vermutlich, gleich alle samples zu senden und nicht nur einen Block nach dem anderen
if( m_sfTempTransmitBuffer.GetLength() != iBlockLength ) if (m_sfTempTransmitBuffer.GetLength() != m_iSendingBlockLength)
m_sfTempTransmitBuffer.init( m_pInputStream->GetNumberOfChannels(), iBlockLength, false ); m_sfTempTransmitBuffer.init(m_pInputStream->GetNumberOfChannels(), m_iSendingBlockLength, false);
for( int j = 0; j < iSendBlocks; j++ ) for( int j = 0; j < iSendBlocks; j++ )
{ {
for( int i = 0; i < int( m_pInputStream->GetNumberOfChannels() ); i++ ) for( int i = 0; i < int( m_pInputStream->GetNumberOfChannels() ); i++ )
{ {
ITAStreamInfo oStreamInfo; ITAStreamInfo oStreamInfo;
oStreamInfo.nSamples = iBlockLength; oStreamInfo.nSamples = m_iSendingBlockLength;
const float* pfData = m_pInputStream->GetBlockPointer( i, &oStreamInfo ); const float* pfData = m_pInputStream->GetBlockPointer( i, &oStreamInfo );
if( pfData != 0 ) if( pfData != 0 )
m_sfTempTransmitBuffer[ i ].write( pfData, iBlockLength, 0 ); m_sfTempTransmitBuffer[i].write(pfData, m_iSendingBlockLength, 0);
} }
m_pInputStream->IncrementBlockPointer(); m_pInputStream->IncrementBlockPointer();
...@@ -177,7 +178,7 @@ bool CITANetAudioStreamingServer::LoopBody() ...@@ -177,7 +178,7 @@ bool CITANetAudioStreamingServer::LoopBody()
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_SERVER_SENDING_SAMPLES ); m_pMessage->SetMessageType( CITANetAudioProtocol::NP_SERVER_SENDING_SAMPLES );
m_pMessage->WriteSampleFrame( &m_sfTempTransmitBuffer ); m_pMessage->WriteSampleFrame( &m_sfTempTransmitBuffer );
m_pMessage->WriteMessage(); m_pMessage->WriteMessage();
m_iEstimatedClientRingBufferFreeSamples -= iBlockLength; m_iEstimatedClientRingBufferFreeSamples -= m_iSendingBlockLength;
} }
#ifdef NET_AUDIO_SHOW_TRAFFIC #ifdef NET_AUDIO_SHOW_TRAFFIC
...@@ -266,6 +267,16 @@ int CITANetAudioStreamingServer::GetNetStreamBlocklength() const ...@@ -266,6 +267,16 @@ int CITANetAudioStreamingServer::GetNetStreamBlocklength() const
return m_sfTempTransmitBuffer.GetLength(); return m_sfTempTransmitBuffer.GetLength();
} }
int CITANetAudioStreamingServer::GetSendingBlockLength() const
{
return m_iSendingBlockLength;
}
void CITANetAudioStreamingServer::SetSendingBlockLength(const int iSendingBlockLength)
{
m_iSendingBlockLength = iSendingBlockLength;
}
int CITANetAudioStreamingServer::GetNetStreamNumberOfChannels() const int CITANetAudioStreamingServer::GetNetStreamNumberOfChannels() const
{ {
return m_sfTempTransmitBuffer.channels(); return m_sfTempTransmitBuffer.channels();
......
...@@ -18,6 +18,7 @@ int g_iBlockLength = 32; ...@@ -18,6 +18,7 @@ int g_iBlockLength = 32;
int g_iChannels = 2; int g_iChannels = 2;
int g_iTargetLatencySamples = 4 * g_iBlockLength; // 1.4512ms int g_iTargetLatencySamples = 4 * g_iBlockLength; // 1.4512ms
int g_iRingBufferSize = 2 * g_iTargetLatencySamples; int g_iRingBufferSize = 2 * g_iTargetLatencySamples;
int g_iSendingBlockLength = 8;
double g_dClientStatusMessageTimeout = 0.001; // seconds double g_dClientStatusMessageTimeout = 0.001; // seconds
string g_sFileName = "gershwin-mono.wav"; string g_sFileName = "gershwin-mono.wav";
...@@ -34,13 +35,14 @@ int main( int argc, char** argv ) ...@@ -34,13 +35,14 @@ int main( int argc, char** argv )
g_dSampleRate = strtod( argv[ 3 ], NULL ); g_dSampleRate = strtod( argv[ 3 ], NULL );
g_iBlockLength = atoi( argv[ 4 ] ); g_iBlockLength = atoi( argv[ 4 ] );
g_iChannels = atoi( argv[ 5 ] ); g_iChannels = atoi( argv[ 5 ] );
g_iTargetLatencySamples = atoi( argv[ 6 ] ); g_iTargetLatencySamples = atoi(argv[6]);
g_iRingBufferSize = atoi( argv[ 7 ] ); g_iRingBufferSize = atoi(argv[7]);
g_iSendingBlockLength = atoi(argv[8]);
} }
} }
else 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; cout << "Using default values ..." << endl;
} }
...@@ -71,6 +73,7 @@ int main( int argc, char** argv ) ...@@ -71,6 +73,7 @@ int main( int argc, char** argv )
oStreamingServer.SetInputStream( &oMuliplier ); oStreamingServer.SetInputStream( &oMuliplier );
oStreamingServer.SetTargetLatencySamples( g_iTargetLatencySamples ); 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; cout << "Starting net audio server and waiting for connections on '" << g_sServerName << "' on port " << g_iServerPort << endl;
oStreamingServer.Start( g_sServerName, g_iServerPort, g_dClientStatusMessageTimeout ); oStreamingServer.Start( g_sServerName, g_iServerPort, g_dClientStatusMessageTimeout );
......
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