Commit e6795989 authored by Anne's avatar Anne
Browse files

bugfix

parent b29b1010
...@@ -64,36 +64,42 @@ const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const ...@@ -64,36 +64,42 @@ const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const
iCurrentWriteCursor += GetRingBufferSize(); // Write pointer always ahead, so unwrap first iCurrentWriteCursor += GetRingBufferSize(); // Write pointer always ahead, so unwrap first
int iReadableSamples = iCurrentWriteCursor - m_iReadCursor; int iReadableSamples = iCurrentWriteCursor - m_iReadCursor;
if( iReadableSamples > int( GetBlocklength() ) ) // samples can be cyclic-copied safely from ring buffer if ( iReadableSamples > int( GetBlocklength( ) ) ) // samples can be cyclic-copied safely from ring buffer
m_sfRingBuffer[ uiChannel ].cyclic_read( sbOutputStreamBuffer.GetData(), sbOutputStreamBuffer.GetLength(), m_iReadCursor ); {
m_sfRingBuffer[ uiChannel ].cyclic_read( sbOutputStreamBuffer.GetData( ), sbOutputStreamBuffer.GetLength( ), m_iReadCursor );
if( iReadableSamples > 0 && iReadableSamples < int( GetBlocklength() ) ) pfBlockPointer = sbOutputStreamBuffer.GetData( );
}
else if( iReadableSamples > 0)
{ {
// @todo: fade with ITAFade // @todo: fade with ITAFade
std::cerr << "Should fade right now, but skipping samples." << std::endl; //std::cerr << "Should fade right now, but skipping samples." << std::endl;
} }
return pfBlockPointer; return pfBlockPointer;
} }
void CITANetAudioStream::IncrementBlockPointer() void CITANetAudioStream::IncrementBlockPointer()
{ {
// Increment read cursor by one audio block and wrap around if exceeding ring buffer // Increment read cursor by one audio block and wrap around if exceeding ring buffer
if( GetRingBufferFreeSamples() >= int( GetBlocklength() ) ) if ( ( GetRingBufferSize() - GetRingBufferFreeSamples( )) >= int( GetBlocklength( ) ) )
{ {
m_iReadCursor = ( m_iReadCursor + m_sfOutputStreamBuffer.GetLength() ) % m_sfRingBuffer.GetLength(); m_iReadCursor = ( m_iReadCursor + m_sfOutputStreamBuffer.GetLength() ) % m_sfRingBuffer.GetLength();
m_iStreamingStatus = STREAMING; m_iStreamingStatus = STREAMING;
outputFile << "incRead "; //outputFile << "incRead ";
}
else if ( GetIsRingBufferEmpty( ) )
{
//outputFile << "buffer empty ";
} }
else else
{ {
m_iStreamingStatus = BUFFER_UNDERRUN; m_iStreamingStatus = BUFFER_UNDERRUN;
m_iReadCursor = m_iWriteCursor; m_iReadCursor = m_iWriteCursor;
outputFile << "BufferOverrun "; //outputFile << "BufferOverrun ";
} }
outputFile << "\tRead: " << m_iReadCursor; m_bRingBufferFull = false;
outputFile << "\tWrite : " << m_iWriteCursor; //outputFile << "\tRead: " << m_iReadCursor;
outputFile << "\tFreeSamples: " << GetRingBufferFreeSamples ()<< endl; //outputFile << "\tWrite : " << m_iWriteCursor;
//outputFile << "\tFreeSamples: " << GetRingBufferFreeSamples ()<< endl;
m_pNetAudioStreamingClient->TriggerBlockIncrement(); m_pNetAudioStreamingClient->TriggerBlockIncrement();
} }
...@@ -109,10 +115,11 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa ...@@ -109,10 +115,11 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa
if( GetRingBufferFreeSamples() < iNumSamples ) if( GetRingBufferFreeSamples() < iNumSamples )
{ {
// @todo: only partly write // @todo: only partly write
std::cerr << "BUFFER_OVERRUN! Would partly write samples because ring buffer will be full then." << std::endl; //std::cerr << "BUFFER_OVERRUN! Would partly write samples because ring buffer will be full then." << std::endl;
m_iWriteCursor = m_iReadCursor; m_iWriteCursor = m_iReadCursor;
outputFile << " incSomeWrite: "; m_bRingBufferFull = false;
//outputFile << " incSomeWrite: ";
} }
else else
{ {
...@@ -120,13 +127,13 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa ...@@ -120,13 +127,13 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa
m_sfRingBuffer.cyclic_write( sfNewSamples, iNumSamples, 0, iCurrentWriteCursor ); m_sfRingBuffer.cyclic_write( sfNewSamples, iNumSamples, 0, iCurrentWriteCursor );
// set write curser // set write curser
m_iWriteCursor += ( m_iWriteCursor + iNumSamples ); m_iWriteCursor = ( m_iWriteCursor + iNumSamples ) % GetRingBufferSize( );
m_iWriteCursor %= GetRingBufferSize( ); m_bRingBufferFull = true;
outputFile << " IncWrite: "; //outputFile << " IncWrite: ";
} }
outputFile << "\tRead: " << m_iReadCursor; //outputFile << "\tRead: " << m_iReadCursor;
outputFile << "\tWrite : " << m_iWriteCursor; //outputFile << "\tWrite : " << m_iWriteCursor;
outputFile << "\tFreeSamples: " << GetRingBufferFreeSamples( ) << endl; //outputFile << "\tFreeSamples: " << GetRingBufferFreeSamples( ) << endl;
return GetRingBufferFreeSamples(); return GetRingBufferFreeSamples();
} }
......
...@@ -96,7 +96,7 @@ bool CITANetAudioStreamingClient::LoopBody() ...@@ -96,7 +96,7 @@ bool CITANetAudioStreamingClient::LoopBody()
case CITANetAudioProtocol::NP_SERVER_WAITING_FOR_TRIGGER: case CITANetAudioProtocol::NP_SERVER_WAITING_FOR_TRIGGER:
// Wait until block increment is triggered by audio context (more free samples in ring buffer) // Wait until block increment is triggered by audio context (more free samples in ring buffer)
std::cout << "Will wait for block increment" << std::endl; //std::cout << "Will wait for block increment" << std::endl;
m_oBlockIncrementEvent.WaitForEvent( true ); m_oBlockIncrementEvent.WaitForEvent( true );
break; break;
...@@ -104,7 +104,7 @@ bool CITANetAudioStreamingClient::LoopBody() ...@@ -104,7 +104,7 @@ bool CITANetAudioStreamingClient::LoopBody()
// Receive samples from net message and forward them to the stream ring buffer // Receive samples from net message and forward them to the stream ring buffer
m_pMessage->ReadSampleFrame( &m_sfReceivingBuffer ); m_pMessage->ReadSampleFrame( &m_sfReceivingBuffer );
std::cout << "Receiving " << m_sfReceivingBuffer.GetLength() << " samples from streaming server" << std::endl; //std::cout << "Receiving " << m_sfReceivingBuffer.GetLength() << " samples from streaming server" << std::endl;
if ( m_pStream->GetRingBufferFreeSamples( ) >= m_sfReceivingBuffer.GetLength( ) ) if ( m_pStream->GetRingBufferFreeSamples( ) >= m_sfReceivingBuffer.GetLength( ) )
m_pStream->Transmit( m_sfReceivingBuffer, m_sfReceivingBuffer.GetLength( ) ); m_pStream->Transmit( m_sfReceivingBuffer, m_sfReceivingBuffer.GetLength( ) );
//else //else
......
...@@ -143,11 +143,11 @@ bool CITANetAudioStreamingServer::LoopBody() ...@@ -143,11 +143,11 @@ bool CITANetAudioStreamingServer::LoopBody()
m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_SEND_SAMPLES ); m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_SEND_SAMPLES );
m_pMessage->WriteSampleFrame( &m_sfTempTransmitBuffer ); m_pMessage->WriteSampleFrame( &m_sfTempTransmitBuffer );
m_pMessage->WriteAnswer(); m_pMessage->WriteAnswer();
std::cout << "Transmitted " << m_pInputStream->GetBlocklength() << " samples, because there where " << iFreeSamples << " free samples on client side" << std::endl; //std::cout << "Transmitted " << m_pInputStream->GetBlocklength() << " samples, because there where " << iFreeSamples << " free samples on client side" << std::endl;
} }
else else
{ {
std::cout << "Could not transmitt, because there where only " << iFreeSamples << " free samples on client side" << std::endl; //std::cout << "Could not transmitt, because there where only " << iFreeSamples << " free samples on client side" << std::endl;
// Waiting for Trigger // Waiting for Trigger
m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_WAITING_FOR_TRIGGER ); m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_WAITING_FOR_TRIGGER );
......
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