Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
audiowmark
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
audiowmark
Commits
1dc5f353
Commit
1dc5f353
authored
May 27, 2024
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use more efficient float->int conversion in SFOutputStream.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
4c331b4c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
26 deletions
+21
-26
rawconverter.cc
src/rawconverter.cc
+0
-18
rawconverter.hh
src/rawconverter.hh
+18
-0
sfoutputstream.cc
src/sfoutputstream.cc
+2
-7
sfoutputstream.hh
src/sfoutputstream.hh
+1
-1
No files found.
src/rawconverter.cc
View file @
1dc5f353
...
...
@@ -104,24 +104,6 @@ make_endian_shift ()
}
}
template
<
int
BITS
>
static
int
float_to_int_clip
(
float
f
)
{
const
int64_t
inorm
=
(
1LL
<<
(
BITS
-
1
));
const
float
min_value
=
-
inorm
;
const
float
max_value
=
inorm
-
1
;
const
float
norm
=
inorm
;
const
float
snorm
=
f
*
norm
;
if
(
snorm
>=
max_value
)
return
inorm
-
1
;
else
if
(
snorm
<=
min_value
)
return
-
inorm
;
else
return
snorm
;
}
template
<
int
BIT_DEPTH
,
RawFormat
::
Endian
ENDIAN
,
RawFormat
::
Encoding
ENCODING
>
void
RawConverterImpl
<
BIT_DEPTH
,
ENDIAN
,
ENCODING
>::
to_raw
(
const
float
*
samples
,
unsigned
char
*
output_bytes
,
size_t
n_samples
)
...
...
src/rawconverter.hh
View file @
1dc5f353
...
...
@@ -31,4 +31,22 @@ public:
virtual
void
from_raw
(
const
unsigned
char
*
bytes
,
float
*
samples
,
size_t
n_samples
)
=
0
;
};
template
<
int
BITS
>
static
inline
int
float_to_int_clip
(
float
f
)
{
const
int64_t
inorm
=
(
1LL
<<
(
BITS
-
1
));
const
float
min_value
=
-
inorm
;
const
float
max_value
=
inorm
-
1
;
const
float
norm
=
inorm
;
const
float
snorm
=
f
*
norm
;
if
(
snorm
>=
max_value
)
return
inorm
-
1
;
else
if
(
snorm
<=
min_value
)
return
-
inorm
;
else
return
snorm
;
}
#endif
/* AUDIOWMARK_RAW_CONVERTER_HH */
src/sfoutputstream.cc
View file @
1dc5f353
...
...
@@ -16,6 +16,7 @@
*/
#include "sfoutputstream.hh"
#include "rawconverter.hh"
#include "utils.hh"
#include <math.h>
...
...
@@ -103,13 +104,7 @@ SFOutputStream::write_frames (const vector<float>& samples)
{
vector
<
int
>
isamples
(
samples
.
size
());
for
(
size_t
i
=
0
;
i
<
samples
.
size
();
i
++
)
{
const
double
norm
=
0x80000000LL
;
const
double
min_value
=
-
0x80000000LL
;
const
double
max_value
=
0x7FFFFFFF
;
isamples
[
i
]
=
lrint
(
bound
<
double
>
(
min_value
,
samples
[
i
]
*
norm
,
max_value
));
}
isamples
[
i
]
=
float_to_int_clip
<
32
>
(
samples
[
i
]);
sf_count_t
frames
=
samples
.
size
()
/
m_n_channels
;
sf_count_t
count
=
sf_writef_int
(
m_sndfile
,
isamples
.
data
(),
frames
);
...
...
src/sfoutputstream.hh
View file @
1dc5f353
...
...
@@ -51,7 +51,7 @@ public:
Error
open
(
const
std
::
string
&
filename
,
int
n_channels
,
int
sample_rate
,
int
bit_depth
,
OutFormat
out_format
=
OutFormat
::
WAV
);
Error
open
(
std
::
vector
<
unsigned
char
>
*
data
,
int
n_channels
,
int
sample_rate
,
int
bit_depth
,
OutFormat
out_format
=
OutFormat
::
WAV
);
Error
write_frames
(
const
std
::
vector
<
float
>&
frames
)
override
;
Error
write_frames
(
const
std
::
vector
<
float
>&
frames
)
override
AUDIOWMARK_EXTRA_OPT
;
Error
close
()
override
;
int
bit_depth
()
const
override
;
int
sample_rate
()
const
override
;
...
...
Write
Preview
Markdown
is supported
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