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
23774f55
Commit
23774f55
authored
May 26, 2024
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use similar API for from/to raw conversion in RawConverter.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
721bd177
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
19 deletions
+30
-19
rawconverter.cc
src/rawconverter.cc
+7
-9
rawconverter.hh
src/rawconverter.hh
+1
-1
rawinputstream.cc
src/rawinputstream.cc
+1
-1
rawoutputstream.cc
src/rawoutputstream.cc
+2
-2
stdoutwavoutputstream.cc
src/stdoutwavoutputstream.cc
+18
-6
stdoutwavoutputstream.hh
src/stdoutwavoutputstream.hh
+1
-0
No files found.
src/rawconverter.cc
View file @
23774f55
...
...
@@ -30,11 +30,11 @@ RawConverter::~RawConverter()
}
template
<
int
BIT_DEPTH
,
RawFormat
::
Endian
ENDIAN
,
RawFormat
::
Encoding
ENCODING
>
class
RawConverterImpl
:
public
RawConverter
class
RawConverterImpl
final
:
public
RawConverter
{
public
:
void
to_raw
(
const
std
::
vector
<
float
>&
samples
,
std
::
vector
<
unsigned
char
>&
bytes
)
AUDIOWMARK_EXTRA_OPT
;
void
from_raw
(
const
unsigned
char
*
bytes
,
float
*
samples
,
size_t
n_samples
)
AUDIOWMARK_EXTRA_OPT
;
void
to_raw
(
const
float
*
samples
,
unsigned
char
*
bytes
,
size_t
n_samples
)
override
AUDIOWMARK_EXTRA_OPT
;
void
from_raw
(
const
unsigned
char
*
bytes
,
float
*
samples
,
size_t
n_samples
)
override
AUDIOWMARK_EXTRA_OPT
;
};
template
<
int
BIT_DEPTH
,
RawFormat
::
Endian
ENDIAN
>
...
...
@@ -124,7 +124,7 @@ float_to_int_clip (float f)
template
<
int
BIT_DEPTH
,
RawFormat
::
Endian
ENDIAN
,
RawFormat
::
Encoding
ENCODING
>
void
RawConverterImpl
<
BIT_DEPTH
,
ENDIAN
,
ENCODING
>::
to_raw
(
const
vector
<
float
>&
samples
,
vector
<
unsigned
char
>&
output_byt
es
)
RawConverterImpl
<
BIT_DEPTH
,
ENDIAN
,
ENCODING
>::
to_raw
(
const
float
*
samples
,
unsigned
char
*
output_bytes
,
size_t
n_sampl
es
)
{
constexpr
int
sample_width
=
BIT_DEPTH
/
8
;
constexpr
auto
eshift
=
make_endian_shift
<
BIT_DEPTH
,
ENDIAN
>
();
...
...
@@ -134,13 +134,11 @@ RawConverterImpl<BIT_DEPTH, ENDIAN, ENCODING>::to_raw (const vector<float>& samp
#else
constexpr
bool
native_endian
=
ENDIAN
==
RawFormat
::
LITTLE
;
#endif
assert
((
uintptr_t
(
output_bytes
.
data
()
)
&
3
)
==
0
);
// ensure alignment for optimized 32 bit native endian version
assert
((
uintptr_t
(
output_bytes
)
&
3
)
==
0
);
// ensure alignment for optimized 32 bit native endian version
output_bytes
.
resize
(
sample_width
*
samples
.
size
())
;
unsigned
char
*
ptr
=
output_bytes
;
unsigned
char
*
ptr
=
output_bytes
.
data
();
for
(
size_t
i
=
0
;
i
<
samples
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
n_samples
;
i
++
)
{
if
(
native_endian
&&
ENCODING
==
RawFormat
::
SIGNED
&&
BIT_DEPTH
==
32
)
((
int32_t
*
)
ptr
)[
i
]
=
float_to_int_clip
<
32
>
(
samples
[
i
]);
...
...
src/rawconverter.hh
View file @
23774f55
...
...
@@ -27,7 +27,7 @@ public:
virtual
~
RawConverter
()
=
0
;
virtual
void
to_raw
(
const
std
::
vector
<
float
>&
samples
,
std
::
vector
<
unsigned
char
>&
byt
es
)
=
0
;
virtual
void
to_raw
(
const
float
*
samples
,
unsigned
char
*
bytes
,
size_t
n_sampl
es
)
=
0
;
virtual
void
from_raw
(
const
unsigned
char
*
bytes
,
float
*
samples
,
size_t
n_samples
)
=
0
;
};
...
...
src/rawinputstream.cc
View file @
23774f55
...
...
@@ -144,7 +144,7 @@ RawInputStream::read_frames (vector<float>& samples, size_t count)
if
(
ferror
(
m_input_file
))
return
Error
(
"error reading sample data"
);
input_bytes
.
resize
(
r_count
*
n_channels
*
sample_width
);
samples
.
resize
(
r_count
*
n_channels
);
m_raw_converter
->
from_raw
(
input_bytes
.
data
(),
samples
.
data
(),
r_count
*
n_channels
);
...
...
src/rawoutputstream.cc
View file @
23774f55
...
...
@@ -91,8 +91,8 @@ RawOutputStream::write_frames (const vector<float>& samples)
if
(
samples
.
empty
())
return
Error
::
Code
::
NONE
;
vector
<
unsigned
char
>
bytes
;
m_raw_converter
->
to_raw
(
samples
,
bytes
);
vector
<
unsigned
char
>
bytes
(
samples
.
size
()
*
m_format
.
bit_depth
()
/
8
)
;
m_raw_converter
->
to_raw
(
samples
.
data
(),
bytes
.
data
(),
samples
.
size
()
);
fwrite
(
&
bytes
[
0
],
1
,
bytes
.
size
(),
m_output_file
);
if
(
ferror
(
m_output_file
))
...
...
src/stdoutwavoutputstream.cc
View file @
23774f55
...
...
@@ -23,6 +23,7 @@
using
std
::
string
;
using
std
::
vector
;
using
std
::
min
;
StdoutWavOutputStream
::~
StdoutWavOutputStream
()
{
...
...
@@ -145,15 +146,26 @@ StdoutWavOutputStream::write_frames (const vector<float>& samples)
if
(
samples
.
empty
())
return
Error
::
Code
::
NONE
;
vector
<
unsigned
char
>
output_bytes
;
const
size_t
block_size
=
1024
;
const
int
sample_width
=
m_bit_depth
/
8
;
m_raw_converter
->
to_raw
(
samples
,
output_bytes
);
m_output_bytes
.
resize
(
sample_width
*
block_size
);
size_t
pos
=
0
;
fwrite
(
&
output_bytes
[
0
],
1
,
output_bytes
.
size
(),
stdout
);
if
(
ferror
(
stdout
))
return
Error
(
"write sample data failed"
);
for
(;;)
{
size_t
todo
=
min
(
block_size
,
samples
.
size
()
-
pos
);
if
(
!
todo
)
return
Error
::
Code
::
NONE
;
return
Error
::
Code
::
NONE
;
m_raw_converter
->
to_raw
(
samples
.
data
()
+
pos
,
m_output_bytes
.
data
(),
todo
);
fwrite
(
m_output_bytes
.
data
(),
1
,
todo
*
sample_width
,
stdout
);
if
(
ferror
(
stdout
))
return
Error
(
"write sample data failed"
);
pos
+=
todo
;
}
}
Error
...
...
src/stdoutwavoutputstream.hh
View file @
23774f55
...
...
@@ -37,6 +37,7 @@ class StdoutWavOutputStream : public AudioOutputStream
};
State
m_state
=
State
::
NEW
;
std
::
vector
<
unsigned
char
>
m_output_bytes
;
std
::
unique_ptr
<
RawConverter
>
m_raw_converter
;
public
:
...
...
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