Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Institute of Technical Acoustics (ITA)
ITAConvolution
Commits
841ffd75
Commit
841ffd75
authored
Dec 17, 2021
by
Philipp Schäfer
Browse files
Applied clang format to missing files
parent
bb8209fd
Changes
8
Hide whitespace changes
Inline
Side-by-side
apps/ita_convoi/ita_convoi.cpp
View file @
841ffd75
...
...
@@ -15,40 +15,39 @@
* ----------------------------------------------------------------
*
*/
#include <ITAUPConvolution.h>
#include <ITAUPFilter.h>
#include <ITAUPFilterPool.h>
#include <ITAFileDataSource.h>
#include <ITAPortaudioInterface.h>
#include <ITAAudiofileReader.h>
#include <ITAStreamPatchBay.h>
#include <ITADataSourceRealization.h>
#include <ITAStreamMultiplier1N.h>
#include <ITASampleFrame.h>
#include <ITAException.h>
#include <ITAFileDataSource.h>
#include <ITAPortaudioInterface.h>
#include <ITASampleFrame.h>
#include <ITAStreamMultiplier1N.h>
#include <ITAStreamPatchBay.h>
#include <ITAUPConvolution.h>
#include <ITAUPFilter.h>
#include <ITAUPFilterPool.h>
#include <cassert>
#include <string>
#include <iostream>
#include <sstream>
#include <string>
#ifdef WIN32
#include <conio.h>
#
include <conio.h>
#else
#include <ncurses.h>
#
include <ncurses.h>
#endif
#include <VistaTools/VistaFileSystemFile.h>
class
ITAStreamConvolver
:
public
ITADatasourceRealizationEventHandler
,
public
ITAUPConvolution
class
ITAStreamConvolver
:
public
ITADatasourceRealizationEventHandler
,
public
ITAUPConvolution
{
public:
inline
ITAStreamConvolver
(
const
double
dSampleRate
,
const
int
iBlockLength
,
const
int
iFilterLength
)
:
ITAUPConvolution
(
iBlockLength
,
iFilterLength
)
,
pdsInput
(
NULL
)
:
ITAUPConvolution
(
iBlockLength
,
iFilterLength
)
,
pdsInput
(
NULL
)
{
m_pdsOutput
=
new
ITADatasourceRealization
(
1
,
dSampleRate
,
iBlockLength
);
m_pdsOutput
->
SetStreamEventHandler
(
this
);
...
...
@@ -60,19 +59,13 @@ public:
ITA_EXCEPT1
(
MODAL_EXCEPTION
,
"Input data source not defined yet"
);
const
float
*
pfInputData
=
pdsInput
->
GetBlockPointer
(
0
,
pStreamInfo
);
Process
(
pfInputData
,
GetBlocklength
(),
m_pdsOutput
->
GetWritePointer
(
0
),
GetBlocklength
(),
ITABase
::
MixingMethod
::
OVERWRITE
);
m_pdsOutput
->
IncrementWritePointer
();
Process
(
pfInputData
,
GetBlocklength
(
),
m_pdsOutput
->
GetWritePointer
(
0
),
GetBlocklength
(
),
ITABase
::
MixingMethod
::
OVERWRITE
);
m_pdsOutput
->
IncrementWritePointer
(
);
};
void
HandlePostIncrementBlockPointer
(
ITADatasourceRealization
*
)
{
pdsInput
->
IncrementBlockPointer
();
};
void
HandlePostIncrementBlockPointer
(
ITADatasourceRealization
*
)
{
pdsInput
->
IncrementBlockPointer
(
);
};
ITADatasource
*
GetOutputDataSource
()
{
return
m_pdsOutput
;
};
ITADatasource
*
GetOutputDataSource
(
)
{
return
m_pdsOutput
;
};
ITADatasource
*
pdsInput
;
...
...
@@ -80,8 +73,8 @@ private:
ITADatasourceRealization
*
m_pdsOutput
;
};
std
::
string
ita_convoi_syntax
();
std
::
string
ita_convoi_commands
();
std
::
string
ita_convoi_syntax
(
);
std
::
string
ita_convoi_commands
(
);
void
ita_convio_exchange_channel
(
ITAStreamConvolver
*
,
const
ITASampleFrame
&
,
const
int
iChannelIndex
);
void
ita_convio_dirac_channel
(
ITAStreamConvolver
*
);
...
...
@@ -89,234 +82,235 @@ int main( int argc, char* argv[] )
{
if
(
argc
<
3
)
{
std
::
cout
<<
ita_convoi_syntax
()
<<
std
::
endl
;
std
::
cout
<<
ita_convoi_syntax
(
)
<<
std
::
endl
;
return
255
;
}
// Input wav file
std
::
string
sInputFilePath
=
std
::
string
(
argv
[
1
]
);
std
::
string
sInputFilePath
=
std
::
string
(
argv
[
1
]
);
VistaFileSystemFile
oInputFile
(
sInputFilePath
);
if
(
!
oInputFile
.
Exists
()
||
!
oInputFile
.
IsFile
()
)
if
(
!
oInputFile
.
Exists
(
)
||
!
oInputFile
.
IsFile
(
)
)
{
std
::
cerr
<<
"Input file '"
<<
oInputFile
.
GetName
()
<<
"' not found or invalid"
<<
std
::
endl
;
std
::
cerr
<<
"Input file '"
<<
oInputFile
.
GetName
(
)
<<
"' not found or invalid"
<<
std
::
endl
;
return
255
;
}
ITAAudiofileReader
*
pSample
=
NULL
;
try
{
pSample
=
ITAAudiofileReader
::
create
(
oInputFile
.
GetName
()
);
pSample
=
ITAAudiofileReader
::
create
(
oInputFile
.
GetName
(
)
);
}
catch
(
ITAException
&
e
)
{
std
::
cerr
<<
"Could not read input file: "
<<
e
<<
std
::
endl
;
std
::
cerr
<<
"Could not read input file: "
<<
e
<<
std
::
endl
;
return
255
;
}
double
dSamplingRate
=
pSample
->
getSamplerate
();
double
dSamplingRate
=
pSample
->
getSamplerate
(
);
delete
pSample
;
// IR filter file
std
::
string
sIRFilePath
=
std
::
string
(
argv
[
2
]
);
std
::
string
sIRFilePath
=
std
::
string
(
argv
[
2
]
);
VistaFileSystemFile
oIRFile
(
sIRFilePath
);
if
(
!
oIRFile
.
Exists
()
||
!
oIRFile
.
IsFile
()
)
if
(
!
oIRFile
.
Exists
(
)
||
!
oIRFile
.
IsFile
(
)
)
{
std
::
cerr
<<
"IR filter file '"
<<
oIRFile
.
GetName
()
<<
"' not found or invalid"
<<
std
::
endl
;
std
::
cerr
<<
"IR filter file '"
<<
oIRFile
.
GetName
(
)
<<
"' not found or invalid"
<<
std
::
endl
;
return
255
;
}
ITAAudiofileReader
*
pIRAudioFile
=
NULL
;
try
{
pIRAudioFile
=
ITAAudiofileReader
::
create
(
oIRFile
.
GetName
()
);
pIRAudioFile
=
ITAAudiofileReader
::
create
(
oIRFile
.
GetName
(
)
);
}
catch
(
ITAException
&
e
)
{
std
::
cerr
<<
"Could not read IR filter file: "
<<
e
<<
std
::
endl
;
std
::
cerr
<<
"Could not read IR filter file: "
<<
e
<<
std
::
endl
;
return
255
;
}
double
dSamplingRateFilter
=
pIRAudioFile
->
getSamplerate
();
int
iFilterChannels
=
pIRAudioFile
->
getNumberOfChannels
();
int
iFilterLength
=
pIRAudioFile
->
getLength
();
double
dSamplingRateFilter
=
pIRAudioFile
->
getSamplerate
(
);
int
iFilterChannels
=
pIRAudioFile
->
getNumberOfChannels
(
);
int
iFilterLength
=
pIRAudioFile
->
getLength
(
);
delete
pIRAudioFile
;
// Require matching sampling rates
if
(
dSamplingRate
!=
dSamplingRateFilter
)
{
std
::
cerr
<<
"Sampling rate of input file ("
<<
dSamplingRate
<<
") and IR filter ("
<<
dSamplingRateFilter
<<
") does not match"
<<
std
::
endl
;
std
::
cerr
<<
"Sampling rate of input file ("
<<
dSamplingRate
<<
") and IR filter ("
<<
dSamplingRateFilter
<<
") does not match"
<<
std
::
endl
;
return
255
;
}
int
iBlockLength
=
ITAPortaudioInterface
::
GetPreferredBufferSize
();
int
iBlockLength
=
ITAPortaudioInterface
::
GetPreferredBufferSize
(
);
if
(
argc
>
3
)
{
iBlockLength
=
atoi
(
argv
[
3
]
);
iBlockLength
=
atoi
(
argv
[
3
]
);
}
// Start audio streaming
ITAPortaudioInterface
::
ITA_PA_ERRORCODE
iError
;
ITAPortaudioInterface
oITAPA
(
dSamplingRate
,
iBlockLength
);
int
iPortaudioDeviceID
=
oITAPA
.
GetDefaultOutputDevice
();
int
iPortaudioDeviceID
=
oITAPA
.
GetDefaultOutputDevice
(
);
if
(
argc
>
4
)
iPortaudioDeviceID
=
atoi
(
argv
[
4
]
);
iPortaudioDeviceID
=
atoi
(
argv
[
4
]
);
std
::
cout
<<
"Attempting to initialize Portaudio device with ID "
<<
iPortaudioDeviceID
<<
std
::
endl
;
if
(
(
iError
=
oITAPA
.
Initialize
(
iPortaudioDeviceID
)
)
!=
ITAPortaudioInterface
::
ITA_PA_NO_ERROR
)
{
std
::
cerr
<<
"Could not initialize Portaudio, encountered error: "
<<
ITAPortaudioInterface
::
GetErrorCodeString
(
iError
)
<<
std
::
endl
;
std
::
cerr
<<
"Could not initialize Portaudio, encountered error: "
<<
ITAPortaudioInterface
::
GetErrorCodeString
(
iError
)
<<
std
::
endl
;
return
255
;
}
std
::
cout
<<
"Starting audio streaming on device '"
<<
oITAPA
.
GetDeviceName
(
iPortaudioDeviceID
)
<<
"'"
<<
" with "
<<
dSamplingRate
/
1.0e3
<<
" kHz and a block size of "
<<
iBlockLength
<<
" samples on "
<<
oITAPA
.
GetNumOutputChannels
(
iPortaudioDeviceID
)
<<
" output channels."
<<
std
::
endl
;
std
::
cout
<<
"Your FIR filter has "
<<
iFilterChannels
<<
" channel"
<<
(
iFilterChannels
>
1
?
"s"
:
""
)
<<
" and a length of "
<<
iFilterLength
<<
" taps / samples"
<<
" ("
<<
double
(
iFilterLength
)
/
dSamplingRate
<<
" seconds)."
<<
std
::
endl
;
std
::
cout
<<
"Starting audio streaming on device '"
<<
oITAPA
.
GetDeviceName
(
iPortaudioDeviceID
)
<<
"'"
<<
" with "
<<
dSamplingRate
/
1.0e3
<<
" kHz and a block size of "
<<
iBlockLength
<<
" samples on "
<<
oITAPA
.
GetNumOutputChannels
(
iPortaudioDeviceID
)
<<
" output channels."
<<
std
::
endl
;
std
::
cout
<<
"Your FIR filter has "
<<
iFilterChannels
<<
" channel"
<<
(
iFilterChannels
>
1
?
"s"
:
""
)
<<
" and a length of "
<<
iFilterLength
<<
" taps / samples"
<<
" ("
<<
double
(
iFilterLength
)
/
dSamplingRate
<<
" seconds)."
<<
std
::
endl
;
// Streaming chaing
ITAStreamConvolver
oConvolver
(
dSamplingRate
,
iBlockLength
,
iFilterLength
);
ITAFileDatasource
oSample
(
oInputFile
.
GetName
(),
iBlockLength
,
true
);
if
(
oSample
.
GetNumberOfChannels
()
!=
1
)
ITAFileDatasource
oSample
(
oInputFile
.
GetName
(
),
iBlockLength
,
true
);
if
(
oSample
.
GetNumberOfChannels
(
)
!=
1
)
{
std
::
cout
<<
"Warning ... input file has multiple channels, mixing to mono."
<<
std
::
endl
;
std
::
cout
<<
"Warning ... input file has multiple channels, mixing to mono."
<<
std
::
endl
;
}
ITAStreamPatchbay
oPatchBay
(
dSamplingRate
,
iBlockLength
);
int
iInputID
=
oPatchBay
.
AddInput
(
&
oSample
);
int
iOutputID
=
oPatchBay
.
AddOutput
(
1
);
int
iInputID
=
oPatchBay
.
AddInput
(
&
oSample
);
int
iOutputID
=
oPatchBay
.
AddOutput
(
1
);
oConvolver
.
pdsInput
=
oPatchBay
.
GetOutputDatasource
(
iOutputID
);
for
(
int
n
=
0
;
n
<
int
(
oSample
.
GetNumberOfChannels
()
);
n
++
)
// Downmix
for
(
int
n
=
0
;
n
<
int
(
oSample
.
GetNumberOfChannels
(
)
);
n
++
)
// Downmix
oPatchBay
.
ConnectChannels
(
iInputID
,
n
,
iOutputID
,
0
);
ITAStreamMultiplier1N
oMultiplier
(
oConvolver
.
GetOutputDataSource
(),
oITAPA
.
GetNumOutputChannels
(
iPortaudioDeviceID
)
);
ITAStreamMultiplier1N
oMultiplier
(
oConvolver
.
GetOutputDataSource
(
),
oITAPA
.
GetNumOutputChannels
(
iPortaudioDeviceID
)
);
if
(
(
iError
=
oITAPA
.
SetPlaybackDatasource
(
&
oMultiplier
)
)
!=
ITAPortaudioInterface
::
ITA_PA_NO_ERROR
)
{
std
::
cerr
<<
"Could not set streaming playback for Portaudio, encountered error: "
<<
ITAPortaudioInterface
::
GetErrorCodeString
(
iError
)
<<
std
::
endl
;
std
::
cerr
<<
"Could not set streaming playback for Portaudio, encountered error: "
<<
ITAPortaudioInterface
::
GetErrorCodeString
(
iError
)
<<
std
::
endl
;
return
255
;
}
if
(
(
iError
=
oITAPA
.
Open
()
)
!=
ITAPortaudioInterface
::
ITA_PA_NO_ERROR
)
if
(
(
iError
=
oITAPA
.
Open
(
)
)
!=
ITAPortaudioInterface
::
ITA_PA_NO_ERROR
)
{
std
::
cerr
<<
"Could not open streaming over Portaudio, encountered error: "
<<
ITAPortaudioInterface
::
GetErrorCodeString
(
iError
)
<<
std
::
endl
;
std
::
cerr
<<
"Could not open streaming over Portaudio, encountered error: "
<<
ITAPortaudioInterface
::
GetErrorCodeString
(
iError
)
<<
std
::
endl
;
return
255
;
}
if
(
(
iError
=
oITAPA
.
Start
()
)
!=
ITAPortaudioInterface
::
ITA_PA_NO_ERROR
)
if
(
(
iError
=
oITAPA
.
Start
(
)
)
!=
ITAPortaudioInterface
::
ITA_PA_NO_ERROR
)
{
std
::
cerr
<<
"Could not start streaming, encountered error: "
<<
ITAPortaudioInterface
::
GetErrorCodeString
(
iError
)
<<
std
::
endl
;
std
::
cerr
<<
"Could not start streaming, encountered error: "
<<
ITAPortaudioInterface
::
GetErrorCodeString
(
iError
)
<<
std
::
endl
;
return
255
;
}
int
iCurrentIRChannelIndex
=
0
;
ITASampleFrame
sfIR
(
oIRFile
.
GetName
()
);
ITASampleFrame
sfIR
(
oIRFile
.
GetName
(
)
);
ita_convio_exchange_channel
(
&
oConvolver
,
sfIR
,
iCurrentIRChannelIndex
);
// Start user interaction
std
::
cout
<<
ita_convoi_commands
()
<<
std
::
endl
;
std
::
cout
<<
ita_convoi_commands
(
)
<<
std
::
endl
;
int
iKey
;
while
(
(
iKey
=
_getch
()
)
!=
'q'
)
while
(
(
iKey
=
_getch
(
)
)
!=
'q'
)
{
switch
(
iKey
)
{
case
(
'm'
)
:
{
// Toggle
oMultiplier
.
SetMuted
(
!
oMultiplier
.
IsMuted
()
);
if
(
oMultiplier
.
IsMuted
()
)
std
::
cout
<<
"Output is now muted"
<<
std
::
endl
;
else
std
::
cout
<<
"Output is loud"
<<
std
::
endl
;
break
;
}
case
(
'n'
)
:
{
// Switch to next (or only) channel
iCurrentIRChannelIndex
=
(
iCurrentIRChannelIndex
+
1
)
%
iFilterChannels
;
ita_convio_exchange_channel
(
&
oConvolver
,
sfIR
,
iCurrentIRChannelIndex
);
break
;
}
case
(
'd'
)
:
{
ita_convio_dirac_channel
(
&
oConvolver
);
break
;
}
case
(
48
+
1
)
:
case
(
48
+
2
)
:
case
(
48
+
3
)
:
case
(
48
+
4
)
:
case
(
48
+
5
)
:
case
(
48
+
6
)
:
case
(
48
+
7
)
:
case
(
48
+
8
)
:
case
(
48
+
9
)
:
{
// Switch to next channel
int
iRequestedChannelIndex
=
iKey
-
1
-
48
;
if
(
iFilterChannels
>
iRequestedChannelIndex
)
case
(
'm'
):
{
// Toggle
oMultiplier
.
SetMuted
(
!
oMultiplier
.
IsMuted
(
)
);
if
(
oMultiplier
.
IsMuted
(
)
)
std
::
cout
<<
"Output is now muted"
<<
std
::
endl
;
else
std
::
cout
<<
"Output is loud"
<<
std
::
endl
;
break
;
}
case
(
'n'
):
{
iCurrentIRChannelIndex
=
iRequestedChannelIndex
;
// Switch to next (or only) channel
iCurrentIRChannelIndex
=
(
iCurrentIRChannelIndex
+
1
)
%
iFilterChannels
;
ita_convio_exchange_channel
(
&
oConvolver
,
sfIR
,
iCurrentIRChannelIndex
);
break
;
}
else
case
(
'd'
):
{
std
::
cerr
<<
"Requested channel is out of range, maximum IR channel number is "
<<
iFilterChannels
<<
std
::
endl
;
ita_convio_dirac_channel
(
&
oConvolver
);
break
;
}
case
(
48
+
1
):
case
(
48
+
2
):
case
(
48
+
3
):
case
(
48
+
4
):
case
(
48
+
5
):
case
(
48
+
6
):
case
(
48
+
7
):
case
(
48
+
8
):
case
(
48
+
9
):
{
// Switch to next channel
int
iRequestedChannelIndex
=
iKey
-
1
-
48
;
if
(
iFilterChannels
>
iRequestedChannelIndex
)
{
iCurrentIRChannelIndex
=
iRequestedChannelIndex
;
ita_convio_exchange_channel
(
&
oConvolver
,
sfIR
,
iCurrentIRChannelIndex
);
}
else
{
std
::
cerr
<<
"Requested channel is out of range, maximum IR channel number is "
<<
iFilterChannels
<<
std
::
endl
;
}
break
;
}
default:
{
std
::
cerr
<<
"Unrecognized key command '"
<<
char
(
iKey
)
<<
"'"
<<
std
::
endl
;
std
::
cout
<<
ita_convoi_commands
(
)
<<
std
::
endl
;
break
;
}
break
;
}
default:
{
std
::
cerr
<<
"Unrecognized key command '"
<<
char
(
iKey
)
<<
"'"
<<
std
::
endl
;
std
::
cout
<<
ita_convoi_commands
()
<<
std
::
endl
;
break
;
}
}
}
oITAPA
.
Stop
();
oITAPA
.
Close
();
oITAPA
.
Finalize
();
oITAPA
.
Stop
(
);
oITAPA
.
Close
(
);
oITAPA
.
Finalize
(
);
return
0
;
}
std
::
string
ita_convoi_syntax
()
std
::
string
ita_convoi_syntax
(
)
{
std
::
stringstream
ss
;
ss
<<
"Syntax: ita_convoi SAMPLE_INPUT_WAV_MONO IR_FILTER_WAV_MULTICHANNEL [BLOCKLENGTH] [PORTAUDIO_DEVICE]"
<<
std
::
endl
;
return
ss
.
str
();
ss
<<
"Syntax: ita_convoi SAMPLE_INPUT_WAV_MONO IR_FILTER_WAV_MULTICHANNEL [BLOCKLENGTH] [PORTAUDIO_DEVICE]"
<<
std
::
endl
;
return
ss
.
str
(
);
}
std
::
string
ita_convoi_commands
()
std
::
string
ita_convoi_commands
(
)
{
std
::
stringstream
ss
;
ss
<<
"Commands:
\t
'q' quit"
<<
std
::
endl
;
ss
<<
"
\t\t
'm' toggle mute"
<<
std
::
endl
;
ss
<<
"
\t\t
'n' switch to next IR channel"
<<
std
::
endl
;
ss
<<
"
\t\t
'd' exchange a Dirac filter"
<<
std
::
endl
;
ss
<<
"
\t\t
1-9 exchange IR filter to given channel, if available"
<<
std
::
endl
;
return
ss
.
str
();
ss
<<
"Commands:
\t
'q' quit"
<<
std
::
endl
;
ss
<<
"
\t\t
'm' toggle mute"
<<
std
::
endl
;
ss
<<
"
\t\t
'n' switch to next IR channel"
<<
std
::
endl
;
ss
<<
"
\t\t
'd' exchange a Dirac filter"
<<
std
::
endl
;
ss
<<
"
\t\t
1-9 exchange IR filter to given channel, if available"
<<
std
::
endl
;
return
ss
.
str
(
);
}
void
ita_convio_exchange_channel
(
ITAStreamConvolver
*
pSC
,
const
ITASampleFrame
&
sfIR
,
const
int
iChannelIndex
)
{
assert
(
sfIR
.
channels
()
>
iChannelIndex
);
ITAUPFilter
*
pFilter
=
pSC
->
RequestFilter
();
pFilter
->
Load
(
sfIR
[
iChannelIndex
].
GetData
(),
sfIR
.
GetLength
()
);
assert
(
sfIR
.
channels
(
)
>
iChannelIndex
);
ITAUPFilter
*
pFilter
=
pSC
->
RequestFilter
(
);
pFilter
->
Load
(
sfIR
[
iChannelIndex
].
GetData
(
),
sfIR
.
GetLength
(
)
);
pSC
->
ExchangeFilter
(
pFilter
);
pSC
->
ReleaseFilter
(
pFilter
);
std
::
cout
<<
"Exchanged filter, now streaming channel "
<<
iChannelIndex
+
1
<<
std
::
endl
;
std
::
cout
<<
"Exchanged filter, now streaming channel "
<<
iChannelIndex
+
1
<<
std
::
endl
;
}
void
ita_convio_dirac_channel
(
ITAStreamConvolver
*
pSC
)
{
ITAUPFilter
*
pFilter
=
pSC
->
RequestFilter
();
pFilter
->
identity
();
ITAUPFilter
*
pFilter
=
pSC
->
RequestFilter
(
);
pFilter
->
identity
(
);
pSC
->
ExchangeFilter
(
pFilter
);
pSC
->
ReleaseFilter
(
pFilter
);
std
::
cout
<<
"Exchanged Dirac filter"
<<
std
::
endl
;
std
::
cout
<<
"Exchanged Dirac filter"
<<
std
::
endl
;
}
tests/NUPConvolutionTest/NUPCPPTest.cpp
View file @
841ffd75
#include <iostream>
#include <ITAException.h>
#include "../../src/ITANUPCPerformanceProfile.h"
#include <ITAException.h>
#include <iostream>
using
namespace
std
;
int
main
(
int
argc
,
char
*
argv
[]
)
...
...
@@ -14,19 +15,19 @@ int main( int argc, char* argv[] )
try
{
PerformanceProfile
PP
(
argv
[
1
]
);
cout
<<
endl
<<
PP
.
toString
()
<<
endl
;
PerformanceProfile
PP
(
argv
[
1
]
);
cout
<<
endl
<<
PP
.
toString
(
)
<<
endl
;
ITADynaBuffer
db
(
65536
);
PP
.
write
(
db
);
db
.
seek
(
0
);
PerformanceProfile
PP2
(
db
);
cout
<<
endl
<<
"Deserialized Profile:"
<<
endl
<<
endl
<<
PP2
.
toString
()
<<
endl
;
cout
<<
endl
<<
"Deserialized Profile:"
<<
endl
<<
endl
<<
PP2
.
toString
(
)
<<
endl
;
}
catch
(
ITAException
&
e
)
{
cerr
<<
"Fehler: "
<<
e
.
ToString
()
<<
endl
;
cerr
<<
"Fehler: "
<<
e
.
ToString
(
)
<<
endl
;
return
255
;
}
...
...
tests/NUPConvolutionTest/NUPConvFileTest.cpp
View file @
841ffd75
#include "NUPHelpers.h"
#include <ITAAudiofileReader.h>
#include <ITADataSourceUtils.h>
#include <ITAException.h>
#include <ITAFileDataSource.h>
#include <ITADataSourceUtils.h>
#include <ITANumericUtils.h>
#include <ITANUPConvolution.h>
#include <ITANumericUtils.h>
#include <stdio.h>
#include <vector>
...
...
@@ -25,19 +23,20 @@ int main( int argc, char* argv[] )
}
ITANUPC
::
IConvolution
*
pConv
=
NULL
;
std
::
string
sInfile
=
argv
[
1
];
std
::
string
sIRFile
=
argv
[
2
];
std
::
string
sOutfile
=
argv
[
3
];
unsigned
int
uiBufferSize
=
atoi
(
argv
[
4
]
);
double
dGain
=
1.0
;
std
::
string
sInfile
=
argv
[
1
];
std
::
string
sIRFile
=
argv
[
2
];
std
::
string
sOutfile
=
argv
[
3
];
unsigned
int
uiBufferSize
=
atoi
(
argv
[
4
]
);
double
dGain
=
1.0
;
if
(
argc
==
6
)
dGain
=
atof
(
argv
[
5
]
);
if
(
argc
==
6
)
dGain
=
atof
(
argv
[
5
]
);
// try {
// Dateiquelle erzeugen
ITAFileDatasource
source
(
sInfile
,
uiBufferSize
);
unsigned
int
uiChannels
=
source
.
GetNumberOfChannels
();
double
dSamplerate
=
source
.
GetSampleRate
();
unsigned
int
uiChannels
=
source
.
GetNumberOfChannels
(
);
double
dSamplerate
=
source
.
GetSampleRate
(
);
if
(
uiChannels
!=
1
)
{
...
...
@@ -57,59 +56,58 @@ int main( int argc, char* argv[] )
//! Audiodatei in Puffer laden (Puffer werden erzeugt)
vector
<
float
*>
vpfData
=
readAudiofile
(
sIRFile
,
props
);
uiIRLength
=
props
.
iLength
;
uiIRLength
=
props
.
iLength
;
// Convolution creation
ITANUPC
::
CConvolutionParameter
oParams
;
oParams
.
dSamplerate
=
dSamplerate
;
oParams
.
dSamplerate
=
dSamplerate
;
oParams
.
iBlocklength
=
uiBufferSize
;
oParams
.
iIRLength
=
uiIRLength
;
pConv
=
ITANUPC
::
IConvolution
::
create
(
oParams
);
unsigned
int
uiCCID
=
pConv
->
requestConvolutionChannel
();
oParams
.
iIRLength
=
uiIRLength
;
pConv
=
ITANUPC
::
IConvolution
::
create
(
oParams
);
unsigned
int
uiCCID
=
pConv
->
requestConvolutionChannel
(
);
/*
// Zwischentest: getSegment
for (unsigned int i=0; i< pConv->getMaxIRLength(); i++)
printf("Segment[%d] = %d\n", i, pConv->getSegment(i));
*/
// Zwischentest: getSegment
for (unsigned int i=0; i< pConv->getMaxIRLength(); i++)
printf("Segment[%d] = %d\n", i, pConv->getSegment(i));
*/
// Create filter object
ITANUPC
::
CFilterComponent
*
pFC
=
pConv
->
requestFilterComponent
();
ITANUPC
::
CFilterComponent
*
pFC
=
pConv
->
requestFilterComponent
(
);
if
(
props
.
uiChannels
==
1
)
pFC
->
load
(
vpfData
[
0
],
uiIRLength
,
vpfData
[
0
],
uiIRLength
);
pFC
->
load
(
vpfData
[
0
],
uiIRLength
,
vpfData
[
0
],
uiIRLength
);
else
pFC
->
load
(
vpfData
[
0
],
uiIRLength
,
vpfData
[
1
],
uiIRLength
);
pFC
->
load
(
vpfData
[
0
],
uiIRLength
,
vpfData
[
1
],
uiIRLength
);
pConv
->
setInputDatasource
(
uiCCID
,
&
source
);
pConv
->
setFilterComponent
(
uiCCID
,
pFC
);
//pConv->setInputDatasource(2, &source);
//pConv->setFilterComponent(2, pFC);
//pConv->setOutputGain(0.3);
//
pConv->setInputDatasource(2, &source);
//
pConv->setFilterComponent(2, pFC);
//
pConv->setOutputGain(0.3);
// Anzahl der Durchlufe berechnen
unsigned
int
l
=
uprmul
(
source
.
GetFileCapacity
()
+
uiIRLength
-
1
,
uiBufferSize
);
unsigned
int
l
=
uprmul
(
source
.
GetFileCapacity
(
)
+
uiIRLength
-
1
,
uiBufferSize
);
// Infos ausgeben
printf
(
"
\n
Eingabedatei:
\"
%s
\"
(%d Kanaele, %0.3f kHz)
\n
"
,
sInfile
.
c_str
(),
uiChannels
,
dSamplerate
/
1000
);
printf
(
"Impulsantwort:
\"
%s
\"
(%d Samples)
\n
"
,
argv
[
2
],
uiIRLength
);
printf
(
"Ausgabedatei:
\"
%s
\"\n
"
,
sOutfile
.
c_str
()
);
printf
(
"
\n
Eingabedatei:
\"
%s
\"
(%d Kanaele, %0.3f kHz)
\n
"
,
sInfile
.
c_str
(
),
uiChannels
,
dSamplerate
/
1000
);
printf
(
"Impulsantwort:
\"
%s
\"
(%d Samples)
\n
"
,
argv
[
2
],
uiIRLength
);
printf
(
"Ausgabedatei:
\"
%s
\"\n
"
,
sOutfile
.
c_str
(
)
);
printf
(
"Puffergroesse: %d Samples
\n\n
"
,
uiBufferSize
);
// Falten...
printf
(
"
\n
Berechne %d Samples ...
\n
"
,
l
);
WriteFromDatasourceToFile
(
pConv
->
getOutputDatasource
(),
sOutfile
,
l
,
dGain
,
true
,
true
);
//WriteFromDatasourceToFile(&source, sOutfile, source.GetFileCapacity(), dGain, true, true);
WriteFromDatasourceToFile
(
pConv
->
getOutputDatasource
(
),
sOutfile
,
l
,
dGain
,
true
,
true
);
//
WriteFromDatasourceToFile(&source, sOutfile, source.GetFileCapacity(), dGain, true, true);
printf
(
"
\n
Fertig!
\n
"
);
delete
pConv
;
/* } catch (ITAException& e) {
delete pConv;
fprintf(stderr, "Fehler %s\n", e.toString().c_str());
} catch (ITAException& e) {
delete pConv;
fprintf(stderr, "Fehler %s\n", e.toString().c_str());
} */