Commit f794c92d authored by Anne's avatar Anne

running

Serverlog + client Plockpointer überarbeitet + freie Samples aus dem Buffer werden richtig kalkuliert
parent 437cbfd9
......@@ -25,12 +25,16 @@
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <ITANetAudioProtocol.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <ITASampleFrame.h>
using namespace std;
class ITADatasource;
class CITANetAudioMessage;
class CITANetAudioProtocol;
......@@ -91,6 +95,8 @@ private:
int m_iClientRingBufferFreeSamples;
friend class CITANetAudioServer;
ofstream outputFile;
};
#endif // INCLUDE_WATCHER_ITA_NET_AUDIO_STREAMING_SERVER
......@@ -49,57 +49,60 @@ bool CITANetAudioStream::GetIsConnected() const
const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const ITAStreamInfo* )
{
ITASampleBuffer& sbOutputStreamBuffer( m_sfOutputStreamBuffer[ uiChannel ] );
sbOutputStreamBuffer.Zero();
const float* pfBlockPointer = sbOutputStreamBuffer.GetData();
if( !GetIsConnected() )
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
outputFile << "GBP ";
if ( !GetIsConnected( ) )
{
m_sfOutputStreamBuffer[ uiChannel ].Zero( );
return m_sfOutputStreamBuffer[ uiChannel ].GetData( );
}
int iReadableSamples = iCurrentWriteCursor - m_iReadCursor;
if ( iReadableSamples > int( GetBlocklength( ) ) ) // samples can be cyclic-copied safely from ring buffer
if ( GetIsRingBufferEmpty( ) )
{
m_sfRingBuffer[ uiChannel ].cyclic_read( sbOutputStreamBuffer.GetData( ), sbOutputStreamBuffer.GetLength( ), m_iReadCursor );
pfBlockPointer = sbOutputStreamBuffer.GetData( );
outputFile << "ZERO ";
m_sfOutputStreamBuffer[ uiChannel ].Zero( );
}
else if( iReadableSamples > 0)
// Es ist mindestens ein Block da
else
{
// @todo: fade with ITAFade
//std::cerr << "Should fade right now, but skipping samples." << std::endl;
outputFile << "Norm ";
// 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()
{
// 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_iStreamingStatus = STREAMING;
//outputFile << "incRead ";
outputFile << "incRead ";
}
else if ( GetIsRingBufferEmpty( ) )
{
//outputFile << "buffer empty ";
m_iStreamingStatus = STOPPED;
outputFile << "buffer empty ";
}
else
{
m_iStreamingStatus = BUFFER_UNDERRUN;
m_iReadCursor = m_iWriteCursor;
//outputFile << "BufferOverrun ";
outputFile << "BufferOverrun ";
}
m_bRingBufferFull = false;
//outputFile << "\tRead: " << m_iReadCursor;
//outputFile << "\tWrite : " << m_iWriteCursor;
//outputFile << "\tFreeSamples: " << GetRingBufferFreeSamples ()<< endl;
outputFile << "\tRead: " << m_iReadCursor;
outputFile << "\tWrite : " << m_iWriteCursor;
outputFile << "\tFreeSamples: " << GetRingBufferFreeSamples ()<< endl;
m_pNetAudioStreamingClient->TriggerBlockIncrement();
}
......@@ -112,28 +115,34 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa
if( iCurrentWriteCursor < iCurrentReadCursor )
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
//std::cerr << "BUFFER_OVERRUN! Would partly write samples because ring buffer will be full then." << std::endl;
m_iWriteCursor = m_iReadCursor;
m_bRingBufferFull = false;
//outputFile << " incSomeWrite: ";
outputFile << " incSomeWrite: ";
}
else
{
// write samples into ring buffer
m_sfRingBuffer.cyclic_write( sfNewSamples, iNumSamples, 0, iCurrentWriteCursor );
m_bRingBufferFull = false;
// set write curser
m_iWriteCursor = ( m_iWriteCursor + iNumSamples ) % GetRingBufferSize( );
if ( m_iWriteCursor == m_iReadCursor )
m_bRingBufferFull = true;
//outputFile << " IncWrite: ";
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();
}
......
......@@ -24,7 +24,8 @@ CITANetAudioStreamingServer::CITANetAudioStreamingServer()
, m_iUpdateStrategy( AUTO )
, m_pConnection( NULL )
{
m_pNetAudioServer = new CITANetAudioServer();
m_pNetAudioServer = new CITANetAudioServer( );
outputFile.open( "ServerLog.txt" );
}
bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort )
......@@ -89,6 +90,8 @@ int CITANetAudioStreamingServer::GetNetworkPort() const
void CITANetAudioStreamingServer::Stop()
{
m_pNetAudioServer->Stop();
outputFile.close( );
}
void CITANetAudioStreamingServer::SetInputStream( ITADatasource* pInStream )
......@@ -128,9 +131,12 @@ bool CITANetAudioStreamingServer::LoopBody()
case CITANetAudioProtocol::NP_CLIENT_WAITING_FOR_SAMPLES:
{
int iFreeSamples = m_pMessage->ReadInt();
outputFile << "freeSamples " << iFreeSamples;
if( iFreeSamples >= m_pInputStream->GetBlocklength() )
{
// Send Samples
outputFile << "SendSamples" << endl;
for( int i = 0; i < m_pInputStream->GetNumberOfChannels(); i++ )
{
ITAStreamInfo oStreamInfo;
......@@ -147,6 +153,7 @@ bool CITANetAudioStreamingServer::LoopBody()
}
else
{
outputFile << "Waiting" << endl;
//std::cout << "Could not transmitt, because there where only " << iFreeSamples << " free samples on client side" << std::endl;
// Waiting for Trigger
......
......@@ -16,7 +16,7 @@ static int g_iBlockLength = 256;
int main( int , char** )
{
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;
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