Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Institute of Technical Acoustics (ITA)
ITADataSources
Commits
8bc757bd
Commit
8bc757bd
authored
Mar 29, 2017
by
Dipl.-Ing. Jonas Stienen
Browse files
Merging server impl of NetAudio
parents
a10c1417
a4a9fd6d
Changes
5
Hide whitespace changes
Inline
Side-by-side
include/ITANetAudioStreamingServer.h
View file @
8bc757bd
...
...
@@ -64,7 +64,7 @@ public:
~
CITANetAudioStreamingServer
();
//! Start to listen on a socket (blocking)
bool
Start
(
const
std
::
string
&
sAddress
,
const
int
iPort
,
const
double
dTimeIntervalCientSendStatus
);
bool
Start
(
const
std
::
string
&
sAddress
,
const
int
iPort
,
const
double
dTimeIntervalCientSendStatus
);
bool
IsClientConnected
()
const
;
std
::
string
GetNetworkAddress
()
const
;
int
GetNetworkPort
()
const
;
...
...
@@ -77,6 +77,9 @@ public:
int
GetNetStreamNumberOfChannels
()
const
;
double
GetNetStreamSampleRate
()
const
;
int
GetSendingBlockLength
()
const
;
void
SetSendingBlockLength
(
const
int
iSendingBlockLength
);
void
SetAutomaticUpdateRate
();
void
SetTargetLatencySamples
(
const
int
iTargetLatency
);
...
...
@@ -108,6 +111,7 @@ private:
int
m_iEstimatedClientRingBufferFreeSamples
;
int
m_iTargetLatencySamples
;
int
m_iMaxSendBlocks
;
int
m_iSendingBlockLength
;
double
m_dLastTimeStamp
;
friend
class
CITANetAudioServer
;
...
...
src/ITANetAudioStreamingServer.cpp
View file @
8bc757bd
...
...
@@ -81,7 +81,7 @@ CITANetAudioStreamingServer::~CITANetAudioStreamingServer()
vstr
::
out
()
<<
"[ ITANetAudioStreamingServer ] Try-read access statistics: "
<<
m_swTryReadAccessStats
.
ToString
()
<<
std
::
endl
;
}
bool
CITANetAudioStreamingServer
::
Start
(
const
std
::
string
&
sAddress
,
int
iPort
,
double
dTimeIntervalCientSendStatus
)
bool
CITANetAudioStreamingServer
::
Start
(
const
std
::
string
&
sAddress
,
int
iPort
,
double
dTimeIntervalCientSendStatus
)
{
if
(
!
m_pInputStream
)
ITA_EXCEPT1
(
MODAL_EXCEPTION
,
"Can not start server without a valid input stream"
);
...
...
@@ -133,6 +133,7 @@ bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort,
#ifdef NET_AUDIO_SHOW_TRAFFIC
vstr
::
out
()
<<
"[ITANetAudioStreamingServer] Server and client parameters mismatch detected. Will notify client and stop."
<<
std
::
endl
;
#endif
return
false
;
}
}
...
...
@@ -147,28 +148,27 @@ bool CITANetAudioStreamingServer::LoopBody()
oLog
.
iTransmittedSamples
=
0
;
// Sending Samples
int
iBlockLength
=
m_pInputStream
->
GetBlocklength
();
int
iEstimatedClientRingBufferTargetLatencyFreeSamples
=
m_iEstimatedClientRingBufferFreeSamples
-
(
m_oServerParams
.
iRingBufferSize
-
m_iTargetLatencySamples
);
if
(
iEstimatedClientRingBufferTargetLatencyFreeSamples
>=
i
BlockLength
)
if
(
iEstimatedClientRingBufferTargetLatencyFreeSamples
>=
m_iSending
BlockLength
)
{
// Send Samples
int
iSendBlocks
=
iEstimatedClientRingBufferTargetLatencyFreeSamples
/
i
BlockLength
;
int
iSendBlocks
=
iEstimatedClientRingBufferTargetLatencyFreeSamples
/
m_iSending
BlockLength
;
// Besser wre vermutlich, gleich alle samples zu senden und nicht nur einen Block nach dem anderen
if
(
m_sfTempTransmitBuffer
.
GetLength
()
!=
i
BlockLength
)
m_sfTempTransmitBuffer
.
init
(
m_pInputStream
->
GetNumberOfChannels
(),
i
BlockLength
,
false
);
if
(
m_sfTempTransmitBuffer
.
GetLength
()
!=
m_iSending
BlockLength
)
m_sfTempTransmitBuffer
.
init
(
m_pInputStream
->
GetNumberOfChannels
(),
m_iSending
BlockLength
,
false
);
for
(
int
j
=
0
;
j
<
iSendBlocks
;
j
++
)
{
for
(
int
i
=
0
;
i
<
int
(
m_pInputStream
->
GetNumberOfChannels
()
);
i
++
)
{
ITAStreamInfo
oStreamInfo
;
oStreamInfo
.
nSamples
=
i
BlockLength
;
oStreamInfo
.
nSamples
=
m_iSending
BlockLength
;
const
float
*
pfData
=
m_pInputStream
->
GetBlockPointer
(
i
,
&
oStreamInfo
);
if
(
pfData
!=
0
)
m_sfTempTransmitBuffer
[
i
].
write
(
pfData
,
i
BlockLength
,
0
);
m_sfTempTransmitBuffer
[
i
].
write
(
pfData
,
m_iSending
BlockLength
,
0
);
}
m_pInputStream
->
IncrementBlockPointer
();
...
...
@@ -177,7 +177,7 @@ bool CITANetAudioStreamingServer::LoopBody()
m_pMessage
->
SetMessageType
(
CITANetAudioProtocol
::
NP_SERVER_SENDING_SAMPLES
);
m_pMessage
->
WriteSampleFrame
(
&
m_sfTempTransmitBuffer
);
m_pMessage
->
WriteMessage
();
m_iEstimatedClientRingBufferFreeSamples
-=
i
BlockLength
;
m_iEstimatedClientRingBufferFreeSamples
-=
m_iSending
BlockLength
;
}
#ifdef NET_AUDIO_SHOW_TRAFFIC
...
...
@@ -266,6 +266,16 @@ int CITANetAudioStreamingServer::GetNetStreamBlocklength() const
return
m_sfTempTransmitBuffer
.
GetLength
();
}
int
CITANetAudioStreamingServer
::
GetSendingBlockLength
()
const
{
return
m_iSendingBlockLength
;
}
void
CITANetAudioStreamingServer
::
SetSendingBlockLength
(
const
int
iSendingBlockLength
)
{
m_iSendingBlockLength
=
iSendingBlockLength
;
}
int
CITANetAudioStreamingServer
::
GetNetStreamNumberOfChannels
()
const
{
return
m_sfTempTransmitBuffer
.
channels
();
...
...
tests/NetAudio/ITANetAudioStreamingClientTest.cpp
View file @
8bc757bd
...
...
@@ -21,6 +21,7 @@ int g_iBlockLength = 512;
int
g_iChannels
=
2
;
int
g_iTargetLatencySamples
=
2
*
g_iBlockLength
;
// 1.4512ms
int
g_iRingBufferSize
=
2
*
g_iTargetLatencySamples
;
int
g_iSendingBlockLength
=
8
;
double
g_dPlaybackDuration
=
10
;
// seconds
int
main
(
int
argc
,
char
*
argv
[]
)
...
...
@@ -37,6 +38,7 @@ int main( int argc, char* argv[] )
g_iChannels
=
atoi
(
argv
[
5
]);
g_iTargetLatencySamples
=
atoi
(
argv
[
6
]);
g_iRingBufferSize
=
atoi
(
argv
[
7
]);
g_iSendingBlockLength
=
atoi
(
argv
[
8
]);
}
if
(
argc
>=
9
)
...
...
@@ -58,6 +60,7 @@ int main( int argc, char* argv[] )
ss
<<
"_B"
<<
g_iBlockLength
;
ss
<<
"_TL"
<<
g_iTargetLatencySamples
;
ss
<<
"_RB"
<<
g_iRingBufferSize
;
ss
<<
"_SB"
<<
g_iSendingBlockLength
;
oNetAudioStream
.
SetNetAudioStreamingLoggerBaseName
(
ss
.
str
()
);
ITAStreamPatchbay
oPatchbay
(
g_dSampleRate
,
g_iBlockLength
);
...
...
tests/NetAudio/ITANetAudioStreamingServerTest.cpp
View file @
8bc757bd
...
...
@@ -18,6 +18,7 @@ int g_iBlockLength = 512;
int
g_iChannels
=
1
;
int
g_iTargetLatencySamples
=
4
*
g_iBlockLength
;
// 1.4512ms
int
g_iRingBufferSize
=
2
*
g_iTargetLatencySamples
;
int
g_iSendingBlockLength
=
8
;
double
g_dClientStatusMessageTimeout
=
0.001
;
// seconds
string
g_sFileName
=
"gershwin-mono.wav"
;
...
...
@@ -34,13 +35,14 @@ int main( int argc, char** argv )
g_dSampleRate
=
strtod
(
argv
[
3
],
NULL
);
g_iBlockLength
=
atoi
(
argv
[
4
]
);
g_iChannels
=
atoi
(
argv
[
5
]
);
g_iTargetLatencySamples
=
atoi
(
argv
[
6
]
);
g_iRingBufferSize
=
atoi
(
argv
[
7
]
);
g_iTargetLatencySamples
=
atoi
(
argv
[
6
]);
g_iRingBufferSize
=
atoi
(
argv
[
7
]);
g_iSendingBlockLength
=
atoi
(
argv
[
8
]);
}
}
else
{
cout
<<
"Syntax: ServerName ServerPort SampleRate BufferSize Channel TargetLatencySamples RingBufferSize"
<<
endl
;
cout
<<
"Syntax: ServerName ServerPort SampleRate BufferSize Channel TargetLatencySamples RingBufferSize
SnedingBlockLength
"
<<
endl
;
cout
<<
"Using default values ..."
<<
endl
;
}
...
...
@@ -67,10 +69,12 @@ int main( int argc, char** argv )
ss
<<
"_B"
<<
g_iBlockLength
;
ss
<<
"_TL"
<<
g_iTargetLatencySamples
;
ss
<<
"_RB"
<<
g_iRingBufferSize
;
ss
<<
"_SB"
<<
g_iSendingBlockLength
;
oStreamingServer
.
SetServerLogBaseName
(
ss
.
str
()
);
oStreamingServer
.
SetInputStream
(
&
oMuliplier
);
oStreamingServer
.
SetTargetLatencySamples
(
g_iTargetLatencySamples
);
oStreamingServer
.
SetSendingBlockLength
(
g_iSendingBlockLength
);
cout
<<
"Starting net audio server and waiting for connections on '"
<<
g_sServerName
<<
"' on port "
<<
g_iServerPort
<<
endl
;
if
(
oStreamingServer
.
Start
(
g_sServerName
,
g_iServerPort
,
g_dClientStatusMessageTimeout
)
)
...
...
tests/NetAudio/ITANetAudioTest.cpp
View file @
8bc757bd
...
...
@@ -24,7 +24,7 @@ const static string g_sServerName = "localhost";
const
static
string
g_sInputFilePath
=
"gershwin-mono.wav"
;
const
static
int
g_iServerPort
=
12480
;
const
static
double
g_dSampleRate
=
44100
;
const
static
int
g_iBlockLength
=
2
56
;
const
static
int
g_iBlockLength
=
3
2
;
const
static
int
g_iChannels
=
2
;
const
static
int
g_iTargetLatencySamples
=
g_iBlockLength
*
1
;
const
static
int
g_iRingerBufferCapacity
=
g_iBlockLength
*
5
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment