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
a38eb579
Commit
a38eb579
authored
Apr 19, 2017
by
Jonas Stienen
Browse files
Adding ita_convio, a convolution application to test streaming convolution performance
parent
a26509d4
Changes
4
Show whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
a38eb579
...
@@ -63,6 +63,13 @@ vista_create_default_info_file( ITAConvolution )
...
@@ -63,6 +63,13 @@ vista_create_default_info_file( ITAConvolution )
set_property
(
TARGET ITAConvolution PROPERTY FOLDER
"ITACoreLibs"
)
set_property
(
TARGET ITAConvolution PROPERTY FOLDER
"ITACoreLibs"
)
# apps
if
(
ITA_CORE_LIBS_WITH_APPS
)
set
(
ITACONVOLUTION_COMMON_BUILD TRUE
)
add_subdirectory
(
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/apps"
)
endif
(
)
# tests
# tests
if
(
ITA_CORE_LIBS_WITH_TESTS
)
if
(
ITA_CORE_LIBS_WITH_TESTS
)
set
(
ITACONVOLUTION_COMMON_BUILD TRUE
)
set
(
ITACONVOLUTION_COMMON_BUILD TRUE
)
...
...
apps/CMakeLists.txt
0 → 100644
View file @
a38eb579
add_subdirectory
(
"ita_convoi"
)
\ No newline at end of file
apps/ita_convoi/CMakeLists.txt
0 → 100644
View file @
a38eb579
cmake_minimum_required
(
VERSION 2.8
)
project
(
ita_convoi
)
list
(
APPEND CMAKE_MODULE_PATH
"$ENV{VISTA_CMAKE_COMMON}"
)
include
(
VistaCommon
)
vista_use_package
(
ITAConvolution REQUIRED FIND_DEPENDENCIES
)
vista_use_package
(
ITADataSources REQUIRED FIND_DEPENDENCIES
)
vista_use_package
(
VistaCoreLibs REQUIRED COMPONENTS VistaTools FIND_DEPENDENCIES
)
if
(
NOT ITA_CORE_LIBS_BUILD_STATIC
)
add_definitions
(
-DITA_BASE_STATIC -DITA_FFT_STATIC -DITA_CONVOLUTION_STATIC -DITA_DATA_SOURCES_STATIC
)
endif
(
)
add_executable
(
ita_convoi
"ita_convoi.cpp"
)
target_link_libraries
(
ita_convoi
${
VISTA_USE_PACKAGE_LIBRARIES
}
)
vista_configure_app
(
ita_convoi
)
vista_install
(
ita_convoi
)
vista_create_default_info_file
(
ita_convoi
)
set_property
(
TARGET ita_convoi PROPERTY FOLDER
"ITACoreLibs/Apps/ITAConvolution"
)
vista_set_target_msvc_arguments
(
ita_convoi
"ita_demosound.wav"
"unequal_dirac.wav"
)
apps/ita_convoi/ita_convoi.cpp
0 → 100644
View file @
a38eb579
/*
* ----------------------------------------------------------------
*
* ITA core libs
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2015-2017
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#include <DSMBCConvolver.h>
#include <DSMBCFilter.h>
#include <DSMBCFilterPool.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 <string>
#include <iostream>
#include <sstream>
#include <conio.h>
#include <VistaTools/VistaFileSystemFile.h>
using
namespace
std
;
class
ITAStreamConvolver
:
public
ITADatasourceRealizationEventHandler
,
public
DSMBCConvolver
{
public:
inline
ITAStreamConvolver
(
const
double
dSampleRate
,
const
int
iBlockLength
,
const
int
iFilterLength
)
:
DSMBCConvolver
(
iBlockLength
,
iFilterLength
)
,
pdsInput
(
NULL
)
{
m_pdsOutput
=
new
ITADatasourceRealization
(
1
,
dSampleRate
,
iBlockLength
);
m_pdsOutput
->
SetStreamEventHandler
(
this
);
};
inline
void
HandleProcessStream
(
ITADatasourceRealization
*
,
const
ITAStreamInfo
*
pStreamInfo
)
{
if
(
!
pdsInput
)
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
(),
DSMBCConvolver
::
OUTPUT_OVERWRITE
);
m_pdsOutput
->
IncrementWritePointer
();
};
void
HandlePostIncrementBlockPointer
(
ITADatasourceRealization
*
)
{
pdsInput
->
IncrementBlockPointer
();
};
ITADatasource
*
GetOutputDataSource
()
{
return
m_pdsOutput
;
};
ITADatasource
*
pdsInput
;
private:
ITADatasourceRealization
*
m_pdsOutput
;
};
string
ita_convoi_syntax
();
string
ita_convoi_commands
();
void
ita_convio_exchange_channel
(
ITAStreamConvolver
*
,
const
ITASampleFrame
&
,
const
int
iChannelIndex
);
int
main
(
int
argc
,
char
*
argv
[]
)
{
if
(
argc
<
3
)
{
cout
<<
ita_convoi_syntax
()
<<
endl
;
return
255
;
}
// Input wav file
string
sInputFilePath
=
string
(
argv
[
1
]
);
VistaFileSystemFile
oInputFile
(
sInputFilePath
);
if
(
!
oInputFile
.
Exists
()
||
!
oInputFile
.
IsFile
()
)
{
cerr
<<
"Input file '"
<<
oInputFile
.
GetName
()
<<
"' not found or invalid"
<<
endl
;
return
255
;
}
ITAAudiofileReader
*
pSample
=
NULL
;
try
{
pSample
=
ITAAudiofileReader
::
create
(
oInputFile
.
GetName
()
);
}
catch
(
ITAException
&
e
)
{
cerr
<<
"Could not read input file: "
<<
e
<<
endl
;
return
255
;
}
double
dSamplingRate
=
pSample
->
getSamplerate
();
delete
pSample
;
// IR filter file
string
sIRFilePath
=
string
(
argv
[
2
]
);
VistaFileSystemFile
oIRFile
(
sIRFilePath
);
if
(
!
oIRFile
.
Exists
()
||
!
oIRFile
.
IsFile
()
)
{
cerr
<<
"IR filter file '"
<<
oIRFile
.
GetName
()
<<
"' not found or invalid"
<<
endl
;
return
255
;
}
ITAAudiofileReader
*
pIRAudioFile
=
NULL
;
try
{
pIRAudioFile
=
ITAAudiofileReader
::
create
(
oIRFile
.
GetName
()
);
}
catch
(
ITAException
&
e
)
{
cerr
<<
"Could not read IR filter file: "
<<
e
<<
endl
;
return
255
;
}
double
dSamplingRateFilter
=
pIRAudioFile
->
getSamplerate
();
int
iFilterChannels
=
pIRAudioFile
->
getNumberOfChannels
();
int
iFilterLength
=
pIRAudioFile
->
getLength
();
delete
pIRAudioFile
;
// Require matching sampling rates
if
(
dSamplingRate
!=
dSamplingRateFilter
)
{
cerr
<<
"Sampling rate of input file ("
<<
dSamplingRate
<<
") and IR filter ("
<<
dSamplingRateFilter
<<
") does not match"
<<
endl
;
return
255
;
}
int
iBlockLength
=
ITAPortaudioInterface
::
GetPreferredBufferSize
();
if
(
argc
>
3
)
{
iBlockLength
=
int
(
*
argv
[
3
]
);
}
// Start audio streaming
ITAPortaudioInterface
oITAPA
(
dSamplingRate
,
iBlockLength
);
int
iPortaudioDeviceID
=
oITAPA
.
GetDefaultOutputDevice
();
if
(
argc
>
4
)
iPortaudioDeviceID
=
int
(
*
argv
[
4
]
);
ITAPortaudioInterface
::
ITA_PA_ERRORCODE
iError
;
if
(
(
iError
=
oITAPA
.
Initialize
(
iPortaudioDeviceID
)
)
!=
ITAPortaudioInterface
::
ITA_PA_NO_ERROR
)
{
cerr
<<
"Could not initialize Portaudio, encountered error: "
<<
ITAPortaudioInterface
::
GetErrorCodeString
(
iError
)
<<
endl
;
return
255
;
}
// Streaming chaing
ITAStreamConvolver
oConvolver
(
dSamplingRate
,
iBlockLength
,
iFilterLength
);
ITAFileDatasource
oSample
(
oInputFile
.
GetName
(),
iBlockLength
,
true
);
if
(
oSample
.
GetNumberOfChannels
()
!=
1
)
{
cout
<<
"Warning ... input file has multiple channels, mixing to mono."
<<
endl
;
}
ITAStreamPatchbay
oPatchBay
(
dSamplingRate
,
iBlockLength
);
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
oPatchBay
.
ConnectChannels
(
iInputID
,
n
,
iOutputID
,
0
);
ITAStreamMultiplier1N
oMultiplier
(
oConvolver
.
GetOutputDataSource
(),
oITAPA
.
GetNumOutputChannels
(
iPortaudioDeviceID
)
);
oITAPA
.
SetPlaybackDatasource
(
&
oMultiplier
);
oITAPA
.
Start
();
int
iCurrentIRChannelIndex
=
0
;
ITASampleFrame
sfIR
(
oIRFile
.
GetName
()
);
ita_convio_exchange_channel
(
&
oConvolver
,
sfIR
,
iCurrentIRChannelIndex
);
// Start user interaction
cout
<<
ita_convoi_commands
()
<<
endl
;
int
iKey
;
while
(
(
iKey
=
_getch
()
)
!=
'q'
)
{
switch
(
iKey
)
{
case
(
'm'
)
:
{
// Toggle
oPatchBay
.
SetOutputMuted
(
iOutputID
,
!
oPatchBay
.
IsOutputMuted
(
iOutputID
)
);
break
;
}
case
(
'n'
)
:
{
// Switch to next channel
if
(
iFilterChannels
>
1
)
{
iCurrentIRChannelIndex
=
(
iCurrentIRChannelIndex
+
1
)
%
iFilterChannels
;
ita_convio_exchange_channel
(
&
oConvolver
,
sfIR
,
iCurrentIRChannelIndex
);
}
else
{
cout
<<
"Only one channel available, doing nothing."
<<
endl
;
}
break
;
}
case
(
1
)
:
case
(
2
)
:
case
(
3
)
:
case
(
4
)
:
case
(
5
)
:
case
(
6
)
:
case
(
7
)
:
case
(
8
)
:
case
(
9
)
:
{
// Switch to next channel
if
(
iFilterChannels
<=
iKey
)
{
iCurrentIRChannelIndex
=
iKey
-
1
;
ita_convio_exchange_channel
(
&
oConvolver
,
sfIR
,
iCurrentIRChannelIndex
);
}
else
{
cerr
<<
"Requested channel is out of range, maximum IR channel number is "
<<
iFilterChannels
<<
endl
;
}
break
;
}
default:
{
cerr
<<
"Unrecognized key command '"
<<
char
(
iKey
)
<<
"'"
<<
endl
;
cout
<<
ita_convoi_commands
()
<<
endl
;
break
;
}
}
}
oITAPA
.
Stop
();
return
0
;
}
string
ita_convoi_syntax
()
{
stringstream
ss
;
ss
<<
"Syntax: ita_convoi SAMPLE_INPUT_WAV_MONO IR_FILTER_WAV_MULTICHANNEL [BLOCKLENGTH] [PORTAUDIO_DEVICE]"
<<
endl
;
return
ss
.
str
();
}
string
ita_convoi_commands
()
{
stringstream
ss
;
ss
<<
"Commands:
\t
'q' quit"
<<
endl
;
ss
<<
"
\t\t\t
'm' toggle mute"
<<
endl
;
ss
<<
"
\t\t
'n' switch to next IR channel"
<<
endl
;
ss
<<
"
\t\t
1-9 exchange IR filter to given channel, if available"
<<
endl
;
return
ss
.
str
();
}
void
ita_convio_exchange_channel
(
ITAStreamConvolver
*
pSC
,
const
ITASampleFrame
&
sfIR
,
const
int
iChannelIndex
)
{
assert
(
sfIR
.
channels
()
>
iChannelIndex
);
DSMBCFilter
*
pFilter
=
pSC
->
requestFilter
();
pFilter
->
load
(
sfIR
[
iChannelIndex
].
GetData
(),
sfIR
.
GetLength
()
);
pSC
->
exchangeFilter
(
pFilter
);
pSC
->
releaseFilter
(
pFilter
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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