Commit 7a5b48e0 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Intermediate update, trying to fix network error

parent 9099bdd3
......@@ -71,15 +71,18 @@ void WriteFromDatasourceToBuffer(ITADatasource* pSource,
unsigned int k = (uiNumberOfSamples - n);
if (k > uiBlocklength) k = uiBlocklength;
if (!pfData)
// Stille einfgen
for (unsigned int j=0; j<uiBlocklength; j++) ppfDest[i][n + j] = 0;
else {
if (dGain = 1.0)
memcpy(ppfDest[i] + n, pfData, k * sizeof(float));
if( !pfData )
{ // Stille einfgen
for( unsigned int j = 0; j < uiBlocklength; j++ )
ppfDest[ i ][ n + j ] = 0;
}
else
{
if( dGain == 1.0f )
memcpy( ppfDest[ i ] + n, pfData, k * sizeof( float ) );
else
for (unsigned int j=0; j<k; j++)
ppfDest[i][n + j] = (float) ((double) pfData[j] * dGain);
for( unsigned int j = 0; j < k; j++ )
ppfDest[ i ][ n + j ] = ( float ) ( ( double ) pfData[ j ] * dGain );
}
}
......
......@@ -111,45 +111,35 @@ void CITANetAudioMessage::WriteMessage()
void CITANetAudioMessage::ReadMessage()
{
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "CITANetAudioMessage [ Reading ] Waiting for incoming data" << std::endl;
vstr::out() << "CITANetAudioMessage [ Reading ] Waiting for incoming data" << std::endl;
#endif
long nIncomingBytes = m_pConnection->WaitForIncomingData( 0 );
assert( nIncomingBytes >= 4 ); // we need at least the size of message
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "CITANetAudioMessage [ Reading ] " << nIncomingBytes << " bytes incoming" << std::endl;
vstr::out() << "CITANetAudioMessage [ Reading ] " << nIncomingBytes << " bytes incoming" << std::endl;
#endif
VistaType::sint32 nMessagePayloadSize;
int nBytesRead = m_pConnection->ReadInt32( nMessagePayloadSize );
assert( nBytesRead == sizeof( VistaType::sint32 ) );
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "CITANetAudioMessage [ Reading ] Expecting " << nMessagePayloadSize << " bytes message payload" << std::endl;
vstr::out() << "CITANetAudioMessage [ Reading ] Expecting " << nMessagePayloadSize << " bytes message payload" << std::endl;
#endif
// we need at least the two protocol ints
assert( nMessagePayloadSize >= 2 * sizeof( VistaType::sint32 ) );
if( nMessagePayloadSize > ( int ) m_vecIncomingBuffer.size() )
m_vecIncomingBuffer.resize( nMessagePayloadSize );
/*
int iBytesReceivedTotal = 0;
while( iPayloadDataSize != iBytesReceivedTotal )
{
long nIncomingBytes = pSocket->WaitForIncomingData( 0 );
int iBytesReceived = pSocket->ReceiveRaw( &vdIncomingData[ iBytesReceivedTotal ], nIncomingBytes );
iBytesReceivedTotal += iBytesReceived;
vstr::out() << "[ Server ] " << setw( 3 ) << std::floor( iBytesReceivedTotal / float( iPayloadDataSize ) * 100.0f ) << "% transmitted" << endl;
}
*/
// Receive all incoming data (potentially splitted)
int iBytesReceivedTotal = 0;
while( nMessagePayloadSize != iBytesReceivedTotal )
{
int iIncommingBytes = m_pConnection->WaitForIncomingData( 0 );
int iBytesReceived = m_pConnection->Receive( &m_vecIncomingBuffer[ iBytesReceivedTotal ], iIncommingBytes );
iBytesReceivedTotal += iBytesReceived;
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "CITANetAudioMessage [ Reading ] Further " << std::setw( 3 ) << iBytesReceivedTotal << " transmitted" << std::endl;
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "[ CITANetAudioMessage ] " << std::setw( 3 ) << std::floor( iBytesReceivedTotal / float( nMessagePayloadSize ) * 100.0f ) << "% transmitted" << std::endl;
#endif
}
......@@ -159,7 +149,7 @@ void CITANetAudioMessage::ReadMessage()
m_nMessageId = ReadInt();
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "CITANetAudioMessage [ Reading ] Finished receiving " << m_nMessageType << " (id=" << std::setw( 4 ) << m_nMessageId << ")" << std::endl;
vstr::out() << "CITANetAudioMessage [ Reading ] Finished receiving " << m_nMessageType << " (id=" << std::setw( 4 ) << m_nMessageId << ")" << std::endl;
#endif
}
......@@ -167,7 +157,7 @@ void CITANetAudioMessage::WriteAnswer()
{
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "CITANetAudioMessage [ Answering] to " << m_nMessageType << " with " << m_nAnswerType << " (id=" << std::setw( 4 ) << m_nMessageId << ")" << std::endl;
vstr::out() << "CITANetAudioMessage [ Answering] to " << m_nMessageType << " with " << m_nAnswerType << " (id=" << std::setw( 4 ) << m_nMessageId << ")" << std::endl;
#endif
assert( m_nAnswerType != CITANetAudioProtocol::NP_INVALID );
......@@ -208,40 +198,46 @@ void CITANetAudioMessage::ReadAnswer()
{
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "CITANetAudioMessage [ Reading] yet unkown answer from message " << m_nMessageType << " (id=" << std::setw( 4 ) << m_nMessageId << ") OK" << std::endl;
vstr::out() << "CITANetAudioMessage [ Reading] yet unkown answer from message " << m_nMessageType << " (id=" << std::setw( 4 ) << m_nMessageId << ") OK" << std::endl;
#endif
VistaType::sint32 nMessageSize;
VistaType::sint32 nMessagePayloadSize;
int nReturn;
nReturn = m_pConnection->ReadInt32( nMessageSize );
nReturn = m_pConnection->ReadInt32( nMessagePayloadSize );
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "CITANetAudioMessage [ Reading] 1. return is " << nReturn << " (id=" << std::setw( 4 ) << m_nMessageId << ") OK" << std::endl;
vstr::out() << "CITANetAudioMessage [ Reading] 1. return is " << nReturn << " (id=" << std::setw( 4 ) << m_nMessageId << ") OK" << std::endl;
#endif
if( nReturn != sizeof( VistaType::sint32 ) )
ITA_EXCEPT1( UNKNOWN, "Protokoll error, was expecting 4 bytes to read message size, but received " + std::to_string( nReturn ) );
// we need at least the two protocol types
assert( nMessageSize >= 2 * sizeof( VistaType::sint32 ) );
assert( nMessagePayloadSize >= 2 * sizeof( VistaType::sint32 ) );
if( nMessageSize > ( int ) m_vecIncomingBuffer.size() )
m_vecIncomingBuffer.resize( nMessageSize );
if( nMessagePayloadSize > ( int ) m_vecIncomingBuffer.size() )
m_vecIncomingBuffer.resize( nMessagePayloadSize );
// @todo: read over while( received < total ) loop!!!
// jst: hier nicht while( nReturn < nMessageSize) ReadRawBuffer??
nReturn = m_pConnection->ReadRawBuffer( &m_vecIncomingBuffer[ 0 ], nMessageSize );
if( nReturn != nMessageSize )
ITA_EXCEPT1( UNKNOWN, "Protokoll error, Received less bytes than expected" );
#if NET_AUDIO_SHOW_TRAFFIC
std::cout << "CITANetAudioMessage [ Reading] 2. return is " << nReturn << " (id=" << std::setw( 4 ) << m_nMessageId << ") OK" << std::endl;
int iBytesReceivedTotal = 0;
while( nMessagePayloadSize != iBytesReceivedTotal )
{
int iIncommingBytes = m_pConnection->WaitForIncomingData( 0 );
int iBytesReceived = m_pConnection->Receive( &m_vecIncomingBuffer[ iBytesReceivedTotal ], iIncommingBytes );
iBytesReceivedTotal += iBytesReceived;
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "[ CITANetAudioMessage ] " << std::setw( 3 ) << std::floor( iBytesReceivedTotal / float( nMessagePayloadSize ) * 100.0f ) << "% of answer transmitted" << std::endl;
#endif
}
if( iBytesReceivedTotal != nMessagePayloadSize )
ITA_EXCEPT1( UNKNOWN, "Protokoll error, Received less bytes than expected when trying to receive answer" );
// Swap data to deserialization buffer
m_oIncoming.SetBuffer( &m_vecIncomingBuffer[ 0 ], nReturn );
m_nAnswerType = ReadInt();
int nMessageID = ReadInt();
assert( nMessageID == m_nMessageId );
m_nMessageId = nMessageID;
}
int CITANetAudioMessage::GetMessageType() const
......
......@@ -191,7 +191,7 @@ const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const
m_sfOutputStreamBuffer[ uiChannel ].Zero();
m_iStreamingStatus = BUFFER_UNDERRUN;
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "[ Stream ] Buffer underrun" << std::endl;
//vstr::out() << "[ Stream ] Buffer underrun" << std::endl;
#endif
}
else
......@@ -202,7 +202,7 @@ const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const
m_sfRingBuffer[ uiChannel ].Zero();
m_iStreamingStatus = BUFFER_UNDERRUN;
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "[ Stream ] Buffer underrun" << std::endl;
//vstr::out() << "[ Stream ] Buffer underrun" << std::endl;
#endif
}
else
......@@ -234,21 +234,21 @@ void CITANetAudioStream::IncrementBlockPointer()
m_iReadCursor = ( m_iReadCursor + m_sfOutputStreamBuffer.GetLength() ) % m_sfRingBuffer.GetLength();
m_iStreamingStatus = STREAMING;
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "[ Stream ] Streaming" << std::endl;
//vstr::out() << "[ Stream ] Streaming" << std::endl;
#endif
}
else if ( GetIsRingBufferEmpty( ) )
{
m_iStreamingStatus = BUFFER_UNDERRUN;
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "[ Stream ] Buffer underrun" << std::endl;
//vstr::out() << "[ Stream ] Buffer underrun" << std::endl;
#endif
}
else
{
m_iStreamingStatus = BUFFER_OVERRUN;
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "[ Stream ] Buffer overrun" << std::endl;
//vstr::out() << "[ Stream ] Buffer overrun" << std::endl;
#endif
m_iReadCursor = m_iWriteCursor;
}
......
......@@ -150,7 +150,7 @@ void ITAStreamPatchbay::SetInputDatasource( const int iInput, ITADatasource* pds
ITA_EXCEPT1( INVALID_PARAMETER, "Datasource properties do not match the input properties (num channel missmatch" );
if( pdsDatasource->GetSampleRate() != m_dSamplerate )
ITA_EXCEPT1( INVALID_PARAMETER, "Datasource properties do not match the input properties (samplerate missmatch" );
if( (unsigned int) pdsDatasource->GetBlocklength() != m_iBlockLength )
if( (int) pdsDatasource->GetBlocklength() != m_iBlockLength )
ITA_EXCEPT1( INVALID_PARAMETER, "Datasource properties do not match the input properties (blocklength missmatch)" );
}
......@@ -445,6 +445,7 @@ void ITAStreamPatchbay::HandleProcessStream( ITADatasourceRealization* pSender,
{
// Output X wants data
OutputDesc* pOutput = dynamic_cast< OutputDesc* >( pSender );
assert( pOutput != nullptr );
// Produce all data?
if( m_bProcessData ) {
......
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