Commit 0d8e5df6 authored by Jonas Stienen's avatar Jonas Stienen
Browse files

Tests with transmit [ok] and ring buffer playback [ok] - problem must be with...

Tests with transmit [ok] and ring buffer playback [ok] - problem must be with concurrent read/write on ring buffer in combination with network streaming
parent b863a129
......@@ -32,6 +32,7 @@ using namespace std;
class CITANetAudioStreamingClient;
class ITABufferedAudiofileWriter;
//! Network audio stream
/**
......@@ -96,6 +97,8 @@ private:
bool m_bRingBufferFull; //!< Indicator if ring buffer is full (and read cursor equals write cursor)
ITASampleFrame m_sfRingBuffer; //!< Buffer incoming data
ITABufferedAudiofileWriter* m_pfNetStreamSampleWriter;
int m_iStreamingStatus; //!< Current streaming status
friend class CITANetAudioStreamingClient;
......
......@@ -3,6 +3,7 @@
#include <ITANetAudioStreamingClient.h>
// ITA includes
#include <ITABufferedAudiofileWriter.h>
#include <ITAException.h>
// STL
......@@ -26,12 +27,27 @@ CITANetAudioStream::CITANetAudioStream( int iChannels, double dSamplingRate, int
m_iStreamingStatus = STOPPED;
outputFile.open( "program3data.txt" );
ITAAudiofileProperties props;
props.dSampleRate = dSamplingRate;
props.eDomain = ITADomain::ITA_TIME_DOMAIN;
props.eQuantization = ITAQuantization::ITA_FLOAT;
props.iChannels = iChannels;
props.sComment = "NetAudio transmitted stream";
m_pfNetStreamSampleWriter = ITABufferedAudiofileWriter::create( "NetStreamTransmition.wav", props );
// nachher weg!
m_sfRingBuffer.zero();
ITASampleFrame sfLangShort( "lang_short.wav" );
m_sfRingBuffer.write( sfLangShort, iRingBufferCapacity );
m_bRingBufferFull = true;
}
CITANetAudioStream::~CITANetAudioStream()
{
delete m_pNetAudioStreamingClient;
outputFile.close( );
delete m_pfNetStreamSampleWriter;
}
bool CITANetAudioStream::Connect( const std::string& sAddress, int iPort )
......@@ -79,6 +95,13 @@ const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const
void CITANetAudioStream::IncrementBlockPointer()
{
if( !GetIsConnected() )
return;
m_iReadCursor = ( m_iReadCursor + m_sfOutputStreamBuffer.GetLength() ) % m_sfRingBuffer.GetLength();
m_iWriteCursor = ( m_iReadCursor + 2*m_sfOutputStreamBuffer.GetLength() ) % m_sfRingBuffer.GetLength();
return;
// Increment read cursor by one audio block and wrap around if exceeding ring buffer
if ( ( GetRingBufferSize() - GetRingBufferFreeSamples( )) >= int( GetBlocklength( ) ) )
{
......@@ -117,23 +140,26 @@ int CITANetAudioStream::Transmit( const ITASampleFrame& sfNewSamples, int iNumSa
// @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_iWriteCursor = m_iReadCursor;
m_bRingBufferFull = false;
//outputFile << " incSomeWrite: ";
}
else
{
// write samples into ring buffer
m_sfRingBuffer.cyclic_write( sfNewSamples, iNumSamples, 0, iCurrentWriteCursor );
//m_sfRingBuffer.cyclic_write( sfNewSamples, iNumSamples, 0, iCurrentWriteCursor );
// set write curser
m_iWriteCursor = ( m_iWriteCursor + iNumSamples ) % GetRingBufferSize( );
//m_iWriteCursor = ( m_iWriteCursor + iNumSamples ) % GetRingBufferSize( );
m_bRingBufferFull = true;
//outputFile << " IncWrite: ";
}
//outputFile << "\tRead: " << m_iReadCursor;
//outputFile << "\tWrite : " << m_iWriteCursor;
//outputFile << "\tFreeSamples: " << GetRingBufferFreeSamples( ) << endl;
const ITASampleFrame* pNewSamples = &sfNewSamples;
m_pfNetStreamSampleWriter->write( pNewSamples );
return GetRingBufferFreeSamples();
}
......
......@@ -17,13 +17,13 @@ static int g_iBufferSize = 256;
int main( int , char** )
{
CITANetAudioStream oNetAudioStream( 2, g_dSampleRate, g_iBufferSize, 100 * g_iBufferSize );
CITANetAudioStream oNetAudioStream( 1, g_dSampleRate, g_iBufferSize, 1000 * g_iBufferSize );
ITAStreamProbe oProbe( &oNetAudioStream, "out_gutentag.wav" );
//ITAStreamMultiplier1N oMultiplier( &oProbe, 2 );
ITAStreamMultiplier1N oMultiplier( &oProbe, 2 );
ITAPortaudioInterface ITAPA( g_dSampleRate, g_iBufferSize );
ITAPA.Initialize();
ITAPA.SetPlaybackDatasource( &oProbe );
ITAPA.SetPlaybackDatasource( &oMultiplier );
ITAPA.Open();
ITAPA.Start();
......
......@@ -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("lang_short.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