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)
ITABase
Commits
2145e66c
Commit
2145e66c
authored
Jun 16, 2017
by
Dipl.-Ing. Jonas Stienen
Browse files
Adding Load/Store of WAV files for sample buffer, if libsndfile available
parent
5744175d
Changes
3
Hide whitespace changes
Inline
Side-by-side
include/ITASampleBuffer.h
View file @
2145e66c
...
...
@@ -61,7 +61,7 @@ public:
//! Deprecated
inline
int
length
()
{
{
return
GetLength
();
};
...
...
@@ -333,6 +333,10 @@ public:
//! Werte als Zeichenkette zurckgeben
std
::
string
ValuesToString
()
const
;
void
Load
(
const
std
::
string
&
sFilePath
);
void
Load
(
const
std
::
string
&
sFilePath
,
float
&
fSampleRate
);
void
Store
(
const
std
::
string
&
sFilePath
,
const
float
fSampleRate
=
44100.0
f
)
const
;
//! berblendfunktionen
enum
...
...
src/ITASampleBuffer.cpp
View file @
2145e66c
...
...
@@ -9,6 +9,8 @@
#include
<ITAException.h>
#include
<ITAFade.h>
#include
<ITAFastMath.h>
#include
<ITAAudiofileReader.h>
#include
<ITAAudiofileWriter.h>
ITASampleBuffer
::
ITASampleBuffer
()
...
...
@@ -384,15 +386,15 @@ void ITASampleBuffer::mul_scalar( float fValue )
void
ITASampleBuffer
::
div_scalar
(
float
fValue
)
{
if
(
fValue
==
0
)
if
(
fValue
==
0
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Division by zero"
);
// Invariante
if
(
fValue
==
1
)
if
(
fValue
==
1
)
return
;
// TODO: Schnelle Implementierung?
for
(
int
i
=
0
;
i
<
m_iLength
;
i
++
)
for
(
int
i
=
0
;
i
<
m_iLength
;
i
++
)
m_pfData
[
i
]
/=
fValue
;
}
...
...
@@ -403,11 +405,11 @@ void ITASampleBuffer::add_buf( const ITASampleBuffer* pSource )
void
ITASampleBuffer
::
add_buf
(
const
ITASampleBuffer
*
pSource
,
int
iCount
)
{
if
(
!
pSource
)
if
(
!
pSource
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Nullpointer passed"
);
if
(
pSource
->
GetLength
()
<
iCount
)
if
(
pSource
->
GetLength
()
<
iCount
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Lengths of source buffer too small"
);
if
(
m_iLength
<
iCount
)
if
(
m_iLength
<
iCount
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Requested lengths of source buffer too big to fit into target buffer"
);
fm_add
(
m_pfData
,
pSource
->
GetData
(),
iCount
);
...
...
@@ -415,7 +417,7 @@ void ITASampleBuffer::add_buf( const ITASampleBuffer* pSource, int iCount )
void
ITASampleBuffer
::
add_buf_pos
(
const
ITASampleBuffer
*
pSource
,
int
iPos
)
// TODO: move this to add_buf(mit offset=0)
{
if
(
!
pSource
)
if
(
!
pSource
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Nullpointer passed"
);
//if (pSource->GetLength() < iCount) ITA_EXCEPT1(INVALID_PARAMETER, "Lengths of source buffer too small");
if
(
(
pSource
->
m_iLength
+
iPos
)
>
m_iLength
)
...
...
@@ -426,7 +428,7 @@ void ITASampleBuffer::add_buf_pos( const ITASampleBuffer* pSource, int iPos ) //
void
ITASampleBuffer
::
add_buf_pos
(
float
*
fSource
,
int
iSize
,
int
iPos
)
{
if
(
!
fSource
)
if
(
!
fSource
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Nullpointer passed"
);
if
(
m_iLength
<
iPos
+
iSize
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Source length + delay exceed length of filter"
);
...
...
@@ -436,7 +438,7 @@ void ITASampleBuffer::add_buf_pos( float* fSource, int iSize, int iPos )
void
ITASampleBuffer
::
sub_buf
(
const
ITASampleBuffer
*
pSource
)
{
if
(
!
pSource
)
if
(
!
pSource
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Nullpointer passed"
);
if
(
pSource
->
GetLength
()
!=
m_iLength
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Block lengths do not match"
);
...
...
@@ -482,40 +484,40 @@ void ITASampleBuffer::add_buf( const ITASampleBuffer& sbSource )
}
void
ITASampleBuffer
::
sub_buf
(
const
ITASampleBuffer
&
sbSource
)
{
sub_buf
(
&
sbSource
);
{
sub_buf
(
&
sbSource
);
}
void
ITASampleBuffer
::
mul_buf
(
const
ITASampleBuffer
&
sbSource
)
{
mul_buf
(
&
sbSource
);
{
mul_buf
(
&
sbSource
);
}
void
ITASampleBuffer
::
div_buf
(
const
ITASampleBuffer
&
sbSource
)
{
div_buf
(
&
sbSource
);
div_buf
(
&
sbSource
);
}
void
ITASampleBuffer
::
MulAdd
(
const
ITASampleBuffer
*
pSource
,
float
fScalar
,
int
iSrcOffset
,
int
iDestOffset
,
int
iCount
)
void
ITASampleBuffer
::
MulAdd
(
const
ITASampleBuffer
*
pSource
,
float
fScalar
,
int
iSrcOffset
,
int
iDestOffset
,
int
iCount
)
{
if
(
!
pSource
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Nullpointer passed"
);
if
(
iSrcOffset
<
0
)
if
(
iSrcOffset
<
0
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Invalid source offset"
);
if
(
iDestOffset
<
0
)
if
(
iDestOffset
<
0
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Invalid destination offset"
);
if
(
iCount
<
0
)
if
(
iCount
<
0
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Invalid count"
);
// Test: Lesen innerhalb des Quellblockes
if
(
(
iSrcOffset
+
iCount
)
>
pSource
->
GetLength
()
)
if
(
(
iSrcOffset
+
iCount
)
>
pSource
->
GetLength
()
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Source range exceeds source buffer"
);
if
(
(
iDestOffset
+
iCount
)
>
m_iLength
)
if
(
(
iDestOffset
+
iCount
)
>
m_iLength
)
ITA_EXCEPT1
(
INVALID_PARAMETER
,
"Destination range exceeds destination buffer"
);
// Spezialfall: Count = 0 => Nichts zu tun
if
(
iCount
==
0
)
if
(
iCount
==
0
)
return
;
// Spezialfall: Skalar = 0 => Nichts zu tun
...
...
@@ -678,3 +680,71 @@ std::string ITASampleBuffer::ValuesToString() const
ss
<<
"}"
;
return
ss
.
str
();
}
void
ITASampleBuffer
::
Load
(
const
std
::
string
&
sFilePath
)
{
float
fSampleRate
;
Load
(
sFilePath
,
fSampleRate
);
}
void
ITASampleBuffer
::
Load
(
const
std
::
string
&
sFilePath
,
float
&
fSampleRate
)
{
#ifdef ITABASE_WITH_SNDFILE
ITAAudiofileReader
*
pReader
(
NULL
);
try
{
pReader
=
ITAAudiofileReader
::
create
(
sFilePath
);
const
ITAAudiofileProperties
oProps
=
pReader
->
getAudiofileProperties
();
if
(
oProps
.
iChannels
>
1
)
ITA_EXCEPT_INVALID_PARAMETER
(
"Could not load multi channel wav into sample buffer, use sample frame instead."
);
fSampleRate
=
float
(
oProps
.
dSampleRate
);
Init
(
oProps
.
iLength
,
false
);
std
::
vector
<
float
*
>
vpfDest
(
1
);
vpfDest
[
0
]
=
GetData
();
pReader
->
read
(
oProps
.
iLength
,
vpfDest
);
}
catch
(
...
)
{
delete
pReader
;
throw
;
}
delete
pReader
;
#else
ITA_EXCEPT1
(
NOT_IMPLEMENTED
,
"ITASampleBuffer::Store() function not available without libsndfile"
);
#endif
}
void
ITASampleBuffer
::
Store
(
const
std
::
string
&
sFilePath
,
const
float
fSampleRate
/*= 44100.0f */
)
const
{
#ifdef ITABASE_WITH_SNDFILE
ITAAudiofileWriter
*
pWriter
(
NULL
);
try
{
ITAAudiofileProperties
oProps
;
oProps
.
dSampleRate
=
double
(
fSampleRate
);
oProps
.
eDomain
=
ITADomain
::
ITA_TIME_DOMAIN
;
oProps
.
eQuantization
=
ITAQuantization
::
ITA_FLOAT
;
oProps
.
iChannels
=
1
;
oProps
.
iLength
=
(
unsigned
int
)
GetLength
();
pWriter
=
ITAAudiofileWriter
::
create
(
sFilePath
,
oProps
);
std
::
vector
<
const
float
*
>
vpfDest
(
1
);
vpfDest
[
0
]
=
GetData
();
pWriter
->
write
(
oProps
.
iLength
,
vpfDest
);
}
catch
(
...
)
{
delete
pWriter
;
throw
;
}
delete
pWriter
;
#else
ITA_EXCEPT1
(
NOT_IMPLEMENTED
,
"ITASampleBuffer::Store() function not available without libsndfile"
);
#endif
}
src/ITASampleFrame.cpp
View file @
2145e66c
...
...
@@ -152,7 +152,6 @@ void ITASampleFrame::Store( const std::string& sFilePath, double dSamplingRate )
#else
ITA_EXCEPT1
(
NOT_IMPLEMENTED
,
"ITASampleFrame::Store() function not available without libsndfile"
);
#endif
}
void
ITASampleFrame
::
free
()
...
...
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