Commit f794c92d authored by Anne's avatar Anne

running

Serverlog + client Plockpointer überarbeitet + freie Samples aus dem Buffer werden richtig kalkuliert
parent 437cbfd9
...@@ -25,11 +25,15 @@ ...@@ -25,11 +25,15 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <iostream>
#include <fstream>
#include <ITANetAudioProtocol.h> #include <ITANetAudioProtocol.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h> #include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <ITASampleFrame.h> #include <ITASampleFrame.h>
using namespace std;
class ITADatasource; class ITADatasource;
class CITANetAudioMessage; class CITANetAudioMessage;
...@@ -91,6 +95,8 @@ private: ...@@ -91,6 +95,8 @@ private:
int m_iClientRingBufferFreeSamples; int m_iClientRingBufferFreeSamples;
friend class CITANetAudioServer; friend class CITANetAudioServer;
ofstream outputFile;
}; };
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER #endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
...@@ -49,57 +49,60 @@ bool CITANetAudioStream::GetIsConnected() const ...@@ -49,57 +49,60 @@ bool CITANetAudioStream::GetIsConnected() const
const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const ITAStreamInfo* ) const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const ITAStreamInfo* )
{ {
ITASampleBuffer& sbOutputStreamBuffer( m_sfOutputStreamBuffer[ uiChannel ] ); outputFile << "GBP ";
sbOutputStreamBuffer.Zero(); if ( !GetIsConnected( ) )
const float* pfBlockPointer = sbOutputStreamBuffer.GetData(); {
m_sfOutputStreamBuffer[ uiChannel ].Zero( );
if( !GetIsConnected() ) return m_sfOutputStreamBuffer[ uiChannel ].GetData( );
return pfBlockPointer; }
m_iStreamingStatus = STREAMING;
int iCurrentWriteCursor = m_iWriteCursor; // local copy
if( iCurrentWriteCursor <= m_iReadCursor && GetRingBufferFreeSamples() > 0 ) // Wrap around?
iCurrentWriteCursor += GetRingBufferSize(); // Write pointer always ahead, so unwrap first
int iReadableSamples = iCurrentWriteCursor - m_iReadCursor; if ( GetIsRingBufferEmpty( ) )
if ( iReadableSamples > int( GetBlocklength( ) ) ) // samples can be cyclic-copied safely from ring buffer
{ {
m_sfRingBuffer[ uiChannel ].cyclic_read( sbOutputStreamBuffer.GetData( ), sbOutputStreamBuffer.GetLength( ), m_iReadCursor ); outputFile << "ZERO ";
pfBlockPointer = sbOutputStreamBuffer.GetData( ); m_sfOutputStreamBuffer[ uiChannel ].Zero( );
} }
else if( iReadableSamples > 0) // Es ist mindestens ein Block da
else
{ {
// @todo: fade with ITAFade outputFile << "Norm ";
//std::cerr << "Should fade right now, but skipping samples." << std::endl; // Es ist mindestens ein Block da
m_sfRingBuffer[ uiChannel ].cyclic_read( m_sfOutputStreamBuffer[ uiChannel ].GetData( ), m_sfOutputStreamBuffer.GetLength( ), m_iReadCursor );
// weniger als ein Block
// todo fading
} }
return pfBlockPointer;
return m_sfOutputStreamBuffer[uiChannel].GetData();
} }
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 ( ( GetRingBufferSize() - GetRingBufferFreeSamples( )) >= int( GetBlocklength( ) ) )
int iSavedSample = GetRingBufferSize( ) - GetRingBufferFreeSamples( );
if ( iSavedSample >= int( GetBlocklength( ) ) )
{ {
//es wurden Samples abgespielt
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( ) ) else if ( GetIsRingBufferEmpty( ) )
{ {
//outputFile << "buffer empty "; m_iStreamingStatus = STOPPED;
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 ";
} }
m_bRingBufferFull = false; m_bRingBufferFull = false;
//outputFile << "\tRead: " << m_iReadCursor; outputFile << "\tRead: " << m_iReadCursor;
//outputFile << "\tWrite : " << m_iWriteCursor; outputFile << "\tWrite : " << m_iWriteCursor;
//outputFile << "\tFreeSamples: " << GetRingBufferFreeSamples ()<< endl; outputFile << "\tFreeSamples: " << GetRingBufferFreeSamples ()<< endl;
m_pNetAudioStreamingClient->TriggerBlockIncrement(); m_pNetAudioStreamingClient->TriggerBlockIncrement();
} }
...@@ -112,28 +115,34 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa ...@@ -112,28 +115,34 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa
if( iCurrentWriteCursor < iCurrentReadCursor ) if( iCurrentWriteCursor < iCurrentReadCursor )
iCurrentWriteCursor += GetRingBufferSize(); // Unwrap, because write cursor always ahead iCurrentWriteCursor += GetRingBufferSize(); // Unwrap, because write cursor always ahead
if( GetRingBufferFreeSamples() < iNumSamples ) if ( m_iWriteCursor == m_iReadCursor )
{
m_bRingBufferFull = true;
outputFile << " BuffFull: ";
}
else 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;
m_bRingBufferFull = false; outputFile << " incSomeWrite: ";
//outputFile << " incSomeWrite: ";
} }
else else
{ {
// write samples into ring buffer // write samples into ring buffer
m_sfRingBuffer.cyclic_write( sfNewSamples, iNumSamples, 0, iCurrentWriteCursor ); m_sfRingBuffer.cyclic_write( sfNewSamples, iNumSamples, 0, iCurrentWriteCursor );
m_bRingBufferFull = false;
// set write curser // set write curser
m_iWriteCursor = ( m_iWriteCursor + iNumSamples ) % GetRingBufferSize( ); m_iWriteCursor = ( m_iWriteCursor + iNumSamples ) % GetRingBufferSize( );
m_bRingBufferFull = true; if ( m_iWriteCursor == m_iReadCursor )
//outputFile << " IncWrite: "; m_bRingBufferFull = true;
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();
} }
......
...@@ -24,7 +24,8 @@ CITANetAudioStreamingServer::CITANetAudioStreamingServer() ...@@ -24,7 +24,8 @@ CITANetAudioStreamingServer::CITANetAudioStreamingServer()
, m_iUpdateStrategy( AUTO ) , m_iUpdateStrategy( AUTO )
, m_pConnection( NULL ) , m_pConnection( NULL )
{ {
m_pNetAudioServer = new CITANetAudioServer(); m_pNetAudioServer = new CITANetAudioServer( );
outputFile.open( "ServerLog.txt" );
} }
bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort ) bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort )
...@@ -89,6 +90,8 @@ int CITANetAudioStreamingServer::GetNetworkPort() const ...@@ -89,6 +90,8 @@ int CITANetAudioStreamingServer::GetNetworkPort() const
void CITANetAudioStreamingServer::Stop() void CITANetAudioStreamingServer::Stop()
{ {
m_pNetAudioServer->Stop(); m_pNetAudioServer->Stop();
outputFile.close( );
} }
void CITANetAudioStreamingServer::SetInputStream( ITADatasource* pInStream ) void CITANetAudioStreamingServer::SetInputStream( ITADatasource* pInStream )
...@@ -128,9 +131,12 @@ bool CITANetAudioStreamingServer::LoopBody() ...@@ -128,9 +131,12 @@ bool CITANetAudioStreamingServer::LoopBody()
case CITANetAudioProtocol::NP_CLIENT_WAITING_FOR_SAMPLES: case CITANetAudioProtocol::NP_CLIENT_WAITING_FOR_SAMPLES:
{ {
int iFreeSamples = m_pMessage->ReadInt(); int iFreeSamples = m_pMessage->ReadInt();
outputFile << "freeSamples " << iFreeSamples;
if( iFreeSamples >= m_pInputStream->GetBlocklength() ) if( iFreeSamples >= m_pInputStream->GetBlocklength() )
{ {
// Send Samples // Send Samples
outputFile << "SendSamples" << endl;
for( int i = 0; i < m_pInputStream->GetNumberOfChannels(); i++ ) for( int i = 0; i < m_pInputStream->GetNumberOfChannels(); i++ )
{ {
ITAStreamInfo oStreamInfo; ITAStreamInfo oStreamInfo;
...@@ -146,7 +152,8 @@ bool CITANetAudioStreamingServer::LoopBody() ...@@ -146,7 +152,8 @@ bool CITANetAudioStreamingServer::LoopBody()
//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
{ {
outputFile << "Waiting" << endl;
//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
......
...@@ -16,7 +16,7 @@ static int g_iBlockLength = 256; ...@@ -16,7 +16,7 @@ static int g_iBlockLength = 256;
int main( int , char** ) int main( int , char** )
{ {
ITAStreamFunctionGenerator oGenerator( 2, g_dSampleRate, g_iBlockLength, ITAStreamFunctionGenerator::SINE, 456.78f, 0.81f, true ); ITAStreamFunctionGenerator oGenerator( 2, g_dSampleRate, g_iBlockLength, ITAStreamFunctionGenerator::SINE, 456.78f, 0.81f, true );
ITAFileDatasource oDatei("01_Empfang_Guten_Tag.wav", g_iBlockLength); ITAFileDatasource oDatei("Gershwin.wav", g_iBlockLength);
CITANetAudioStreamingServer oStreamingServer; CITANetAudioStreamingServer oStreamingServer;
oStreamingServer.SetInputStream(&oDatei); oStreamingServer.SetInputStream(&oDatei);
......
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