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
iCurrentWriteCursor += GetRingBufferSize(); // Write pointer always ahead, so unwrap first
int iReadableSamples = iCurrentWriteCursor - m_iReadCursor;
if( iReadableSamples > int( GetBlocklength() ) ) // samples can be cyclic-copied safely from ring buffer
m_sfRingBuffer[ uiChannel ].cyclic_read( sbOutputStreamBuffer.GetData(), sbOutputStreamBuffer.GetLength(), m_iReadCursor );
if( iReadableSamples > 0 && iReadableSamples < int( GetBlocklength() ) )
if ( iReadableSamples > int( GetBlocklength( ) ) ) // samples can be cyclic-copied safely from ring buffer
{
m_sfRingBuffer[ uiChannel ].cyclic_read( sbOutputStreamBuffer.GetData( ), sbOutputStreamBuffer.GetLength( ), m_iReadCursor );
pfBlockPointer = sbOutputStreamBuffer.GetData( );
}
else if( iReadableSamples > 0)
{
// @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;
}
void CITANetAudioStream::IncrementBlockPointer()
{
// 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_iStreamingStatus = STREAMING;
outputFile << "incRead ";
//outputFile << "incRead ";
}
else if ( GetIsRingBufferEmpty( ) )
{
//outputFile << "buffer empty ";
}
else
{
m_iStreamingStatus = BUFFER_UNDERRUN;
m_iReadCursor = m_iWriteCursor;
outputFile << "BufferOverrun ";
//outputFile << "BufferOverrun ";
}
outputFile << "\tRead: " << m_iReadCursor;
outputFile << "\tWrite : " << m_iWriteCursor;
outputFile << "\tFreeSamples: " << GetRingBufferFreeSamples ()<< endl;
m_bRingBufferFull = false;
//outputFile << "\tRead: " << m_iReadCursor;
//outputFile << "\tWrite : " << m_iWriteCursor;
//outputFile << "\tFreeSamples: " << GetRingBufferFreeSamples ()<< endl;
m_pNetAudioStreamingClient->TriggerBlockIncrement();
}
......@@ -109,10 +115,11 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa
if( GetRingBufferFreeSamples() < iNumSamples )
{
// @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;
outputFile << " incSomeWrite: ";
m_bRingBufferFull = false;
//outputFile << " incSomeWrite: ";
}
else
{
......@@ -120,13 +127,13 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa
m_sfRingBuffer.cyclic_write( sfNewSamples, iNumSamples, 0, iCurrentWriteCursor );
// set write curser
m_iWriteCursor += ( m_iWriteCursor + iNumSamples );
m_iWriteCursor %= GetRingBufferSize( );
outputFile << " IncWrite: ";
m_iWriteCursor = ( m_iWriteCursor + iNumSamples ) % GetRingBufferSize( );
m_bRingBufferFull = true;
//outputFile << " IncWrite: ";
}
outputFile << "\tRead: " << m_iReadCursor;
outputFile << "\tWrite : " << m_iWriteCursor;
outputFile << "\tFreeSamples: " << GetRingBufferFreeSamples( ) << endl;
//outputFile << "\tRead: " << m_iReadCursor;
//outputFile << "\tWrite : " << m_iWriteCursor;
//outputFile << "\tFreeSamples: " << GetRingBufferFreeSamples( ) << endl;
return GetRingBufferFreeSamples();
}
......
......@@ -96,7 +96,7 @@ bool CITANetAudioStreamingClient::LoopBody()
case CITANetAudioProtocol::NP_SERVER_WAITING_FOR_TRIGGER:
// 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 );
break;
......@@ -104,7 +104,7 @@ bool CITANetAudioStreamingClient::LoopBody()
// Receive samples from net message and forward them to the stream ring buffer
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( ) )
m_pStream->Transmit( m_sfReceivingBuffer, m_sfReceivingBuffer.GetLength( ) );
//else
......
......@@ -143,11 +143,11 @@ bool CITANetAudioStreamingServer::LoopBody()
m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_SEND_SAMPLES );
m_pMessage->WriteSampleFrame( &m_sfTempTransmitBuffer );
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
{
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
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