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)
ITABase
Commits
17568746
Commit
17568746
authored
Jun 14, 2017
by
Dipl.-Ing. Jonas Stienen
Browse files
Dry SRC implementation for audio samples
parent
89d54de2
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/ITAAudioSample.cpp
View file @
17568746
...
...
@@ -32,30 +32,6 @@ void CITAAudioSample::Init( const int iNumChannels, const int iLength, const flo
ITASampleFrame
::
Init
(
iNumChannels
,
iLength
,
bZeroInit
);
}
void
CITAAudioSample
::
Load
(
const
ITASampleFrame
&
sfSource
,
const
float
fSourceSampleRate
)
{
if
(
fSourceSampleRate
<=
0.0
f
)
ITA_EXCEPT_INVALID_PARAMETER
(
"Source sample rate must be greater zero."
);
// Same sample rate
if
(
fabs
(
fSourceSampleRate
-
m_fSampleRate
)
<
1e-20
)
{
Init
(
sfSource
.
GetNumChannels
(),
sfSource
.
GetLength
(),
m_fSampleRate
);
ITASampleFrame
::
write
(
sfSource
,
sfSource
.
GetLength
()
);
return
;
}
const
int
iConverter
=
SRC_SINC_MEDIUM_QUALITY
;
int
iSRCError
;
SRC_STATE
*
pSRC
=
src_new
(
iConverter
,
sfSource
.
GetNumChannels
(),
&
iSRCError
);
if
(
pSRC
==
nullptr
)
ITA_EXCEPT_INVALID_PARAMETER
(
"Could not create sample rate converter, samplerate error was: "
+
std
::
to_string
(
iSRCError
)
);
const
float
fSRCRation
=
GetSampleRate
()
/
fSourceSampleRate
;
SRC_DATA
src_data
;
}
void
CITAAudioSample
::
LoadWithSampleTypeConversion
(
const
std
::
string
&
sFilePath
)
{
if
(
m_fSampleRate
<=
0.0
f
)
...
...
@@ -73,3 +49,41 @@ float CITAAudioSample::GetSampleRate() const
{
return
m_fSampleRate
;
}
void
CITAAudioSample
::
Load
(
const
ITASampleFrame
&
sfSource
,
const
float
fSourceSampleRate
)
{
if
(
fSourceSampleRate
<=
0.0
f
)
ITA_EXCEPT_INVALID_PARAMETER
(
"Source sample rate must be greater zero."
);
// Same sample rate
if
(
fabs
(
fSourceSampleRate
-
m_fSampleRate
)
<
1e-20
)
{
Init
(
sfSource
.
GetNumChannels
(),
sfSource
.
GetLength
(),
m_fSampleRate
);
ITASampleFrame
::
write
(
sfSource
,
sfSource
.
GetLength
()
);
return
;
}
const
float
fSRCRation
=
GetSampleRate
()
/
fSourceSampleRate
;
const
int
iTargetLength
=
(
int
)
ceil
(
sfSource
.
GetLength
()
*
fSRCRation
);
// @tbd test!
Init
(
sfSource
.
GetNumChannels
(),
iTargetLength
,
m_fSampleRate
);
const
int
iConverter
=
SRC_SINC_MEDIUM_QUALITY
;
for
(
int
i
=
0
;
i
<
sfSource
.
GetNumChannels
();
i
++
)
{
int
iSRCError
;
SRC_STATE
*
pSRCStace
=
src_new
(
iConverter
,
sfSource
.
GetNumChannels
(),
&
iSRCError
);
if
(
pSRCStace
==
nullptr
)
ITA_EXCEPT_INVALID_PARAMETER
(
"Could not create sample rate converter, samplerate error was: "
+
std
::
string
(
src_strerror
(
iSRCError
)
)
);
SRC_DATA
oSRCData
;
oSRCData
.
data_in
=
sfSource
[
i
].
GetData
();
oSRCData
.
data_out
=
(
*
this
)[
i
].
GetData
();
oSRCData
.
input_frames
=
1
;
oSRCData
.
output_frames
=
1
;
oSRCData
.
src_ratio
=
fSRCRation
;
if
(
(
iSRCError
=
src_process
(
pSRCStace
,
&
oSRCData
)
)
!=
0
)
ITA_EXCEPT_INVALID_PARAMETER
(
"Could not convert sample rate: "
+
std
::
string
(
src_strerror
(
iSRCError
)
)
);
src_delete
(
pSRCStace
);
}
}
\ No newline at end of file
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