Împroving looping mode setter getter for buffer data source

also style
and adding a real-time latency setter for netaudio stream
parent 33491525
......@@ -151,6 +151,18 @@ public:
//! Wiederholung Ein-/Ausschalten
void SetLoopMode(bool bLoopMode);
//! Sets the looping mode
/**
* @param[in] bLoopingEnabled True means looping, false will play until EOF
*/
void SetIsLooping( bool bLoopingEnabled );
//! Looping mode getter
/**
* @return True means looping, false will play until EOF
*/
bool GetIsLooping();
//! Arbeitsbereich (region of interest) festlegen
/**
* Legt den Arbeitsbereich fest, d.h. das Interval in den Quellendaten, aus dem die
......
......@@ -49,7 +49,8 @@
*
* \ingroup datasources
*/
class ITA_DATA_SOURCES_API ITAFileDatasource : public ITABufferDatasource {
class ITA_DATA_SOURCES_API ITAFileDatasource : public ITABufferDatasource
{
public:
//! Konstruktor
/**
......
......@@ -94,12 +94,34 @@ public:
void SetAllowedLatencySamples( int iLatencySamples );
float GetAllowedLatencySeconds() const;
int GetAllowedLatencySamples() const;
//! Sets the minimal latency possible
/**
* Real-time network audio is considered to process at lowest latency possible.
* However, this implementation requires at least one block. Hence latency is
* depending on sampling rate and block length.
*
* @sa GetMinimumLatencySamples()
* @sa GetMinimumLatencySamples()
*/
float GetMinimumLatencySeconds() const;
float GetMaximumLatencySeconds() const;
int GetMinimumLatencySamples() const;
int GetMaximumLatencySamples() const;
//! Sets the latency for real-time processing
/**
* Real-time network audio is considered to process at lowest latency possible.
* However, this implementation requires at least one block. Hence latency is
* depending on sampling rate and block length. This method basically
* sets the minimum allowed latency to this value.
*
* @sa GetMinimumLatencySeconds()
* @sa SetAllowedLatencySeconds()
*/
void SetLatencyForRealtime();
//! Returns (static) size of ring buffer
/**
* @return Number of maximum samples that can be hold by internal ring buffer
......
......@@ -176,6 +176,16 @@ void ITABufferDatasource::SetCursor(unsigned int uiNewCursor) {
m_iCursor = (int) uiNewCursor;
}
void ITABufferDatasource::SetIsLooping( bool bEnabled )
{
SetLoopMode( bEnabled );
}
bool ITABufferDatasource::GetIsLooping()
{
return GetLoopMode();
}
bool ITABufferDatasource::GetLoopMode() {
/* TODO: Diese Implementierung ist NICHT THREAD-SAFE.
m_bLoopMode kann durch IncrementReadPointer modifiziert werden,
......@@ -190,6 +200,7 @@ void ITABufferDatasource::SetLoopMode(bool bLoopMode) {
m_bChangeLoopMode = true;
}
bool ITABufferDatasource::IsPaused() const {
return m_bPaused;
}
......
......@@ -178,6 +178,11 @@ int CITANetAudioStream::GetMaximumLatencySamples() const
return GetRingBufferSize();
}
void CITANetAudioStream::SetLatencyForRealtime()
{
SetAllowedLatencySamples( GetMinimumLatencySamples() );
}
const float* CITANetAudioStream::GetBlockPointer( unsigned int uiChannel, const ITAStreamInfo* pInfo )
{
if( !GetIsConnected() )
......
......@@ -132,6 +132,10 @@ bool CITANetAudioStreamingClient::LoopBody()
vstr::err() << "Received invalid message type" << std::endl;
break;
case CITANetAudioProtocol::NP_SERVER_CLOSE:
Disconnect();
break;
case CITANetAudioProtocol::NP_SERVER_WAITING_FOR_TRIGGER:
// Wait until block increment is triggered by audio context (more free samples in ring buffer)
m_oBlockIncrementEvent.WaitForEvent( true );
......
......@@ -120,6 +120,9 @@ bool CITANetAudioStreamingServer::LoopBody()
}
case CITANetAudioProtocol::NP_CLIENT_CLOSE:
{
m_pMessage->SetAnswerType( CITANetAudioProtocol::NP_SERVER_CLOSE );
m_pMessage->WriteAnswer();
m_pConnection = NULL;
StopGently( true );
Stop();
......
......@@ -9,25 +9,25 @@
using namespace std;
static string g_sServerName = "137.226.61.67";
static string g_sServerName = "localhost";
static int g_iServerPort = 12480;
static double g_dSampleRate = 44100;
static int g_iBlockLength = 512;
static int g_iChannels = 500;
int main( int , char** )
int main( int, char** )
{
//ITAStreamFunctionGenerator oGenerator( 2, g_dSampleRate, g_iBlockLength, ITAStreamFunctionGenerator::SINE, 456.78f, 0.81f, true );
ITAFileDatasource oFile("gershwin-mono.wav", g_iBlockLength);
ITAFileDatasource oFile( "gershwin-mono.wav", g_iBlockLength );
oFile.SetIsLooping( true );
ITAStreamMultiplier1N oMuliplier( &oFile, g_iChannels );
CITANetAudioStreamingServer oStreamingServer;
oStreamingServer.SetInputStream( &oMuliplier );
cout << "Starting server and waiting for connections on '" << g_sServerName << "' on port " << g_iServerPort << endl;
cout << "Starting net audio server and waiting for connections on '" << g_sServerName << "' on port " << g_iServerPort << endl;
oStreamingServer.Start( g_sServerName, g_iServerPort );
int iKey;
std::cin >> iKey;
return 0;
}
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