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
e5270756
Commit
e5270756
authored
Dec 01, 2019
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use RawConverter in RawInputStream.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
9c595731
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
14 deletions
+32
-14
rawconverter.cc
src/rawconverter.cc
+17
-4
rawinputstream.cc
src/rawinputstream.cc
+10
-10
rawinputstream.hh
src/rawinputstream.hh
+5
-0
rawoutputstream.o
src/rawoutputstream.o
+0
-0
No files found.
src/rawconverter.cc
View file @
e5270756
...
...
@@ -9,10 +9,7 @@ class RawConverterImpl : public RawConverter
{
public
:
void
to_raw
(
const
std
::
vector
<
float
>&
samples
,
std
::
vector
<
unsigned
char
>&
bytes
);
void
from_raw
(
const
std
::
vector
<
unsigned
char
>&
bytes
,
std
::
vector
<
float
>&
samples
)
{
}
void
from_raw
(
const
std
::
vector
<
unsigned
char
>&
bytes
,
std
::
vector
<
float
>&
samples
);
};
RawConverter
*
...
...
@@ -57,3 +54,19 @@ RawConverterImpl<BIT_DEPTH>::to_raw (const vector<float>& samples, vector<unsign
}
}
}
template
<
int
BIT_DEPTH
>
void
RawConverterImpl
<
BIT_DEPTH
>::
from_raw
(
const
vector
<
unsigned
char
>&
input_bytes
,
vector
<
float
>&
samples
)
{
const
unsigned
char
*
ptr
=
input_bytes
.
data
();
samples
.
resize
(
input_bytes
.
size
()
/
(
BIT_DEPTH
/
8
));
const
double
norm
=
1.0
/
0x80000000LL
;
for
(
size_t
i
=
0
;
i
<
samples
.
size
();
i
++
)
{
int
s32
=
(
ptr
[
1
]
<<
24
)
+
(
ptr
[
0
]
<<
16
);
samples
[
i
]
=
s32
*
norm
;
ptr
+=
2
;
}
}
src/rawinputstream.cc
View file @
e5270756
#include "rawinputstream.hh"
#include "rawconverter.hh"
#include <assert.h>
...
...
@@ -51,6 +52,13 @@ RawInputStream::open (const string& filename, const RawFormat& format)
if
(
!
format
.
sample_rate
())
return
Error
(
"RawInputStream: input format: missing sample rate"
);
Error
err
=
Error
::
Code
::
NONE
;
RawConverter
*
rc
=
RawConverter
::
create
(
format
,
err
);
if
(
err
)
return
err
;
assert
(
rc
);
m_raw_converter
.
reset
(
rc
);
if
(
filename
==
"-"
)
{
m_input_file
=
stdin
;
...
...
@@ -101,17 +109,9 @@ RawInputStream::read_frames (vector<float>& samples, size_t count)
vector
<
unsigned
char
>
input_bytes
(
count
*
n_channels
*
sample_width
);
size_t
r_count
=
fread
(
input_bytes
.
data
(),
n_channels
*
sample_width
,
count
,
m_input_file
);
input_bytes
.
resize
(
r_count
*
n_channels
*
sample_width
);
unsigned
char
*
ptr
=
reinterpret_cast
<
unsigned
char
*>
(
input_bytes
.
data
());
samples
.
resize
(
r_count
*
n_channels
);
const
double
norm
=
1.0
/
0x80000000LL
;
for
(
size_t
i
=
0
;
i
<
samples
.
size
();
i
++
)
{
int
s32
=
(
ptr
[
1
]
<<
24
)
+
(
ptr
[
0
]
<<
16
);
samples
[
i
]
=
s32
*
norm
;
ptr
+=
2
;
}
m_raw_converter
->
from_raw
(
input_bytes
,
samples
);
return
Error
::
Code
::
NONE
;
}
...
...
src/rawinputstream.hh
View file @
e5270756
...
...
@@ -2,6 +2,7 @@
#define AUDIOWMARK_RAW_INPUT_STREAM_HH
#include <string>
#include <memory>
#include <sndfile.h>
...
...
@@ -25,6 +26,8 @@ public:
void
set_bit_depth
(
int
bits
);
};
class
RawConverter
;
class
RawInputStream
:
public
AudioInputStream
{
enum
class
State
{
...
...
@@ -37,6 +40,8 @@ class RawInputStream : public AudioInputStream
FILE
*
m_input_file
=
nullptr
;
bool
m_close_file
=
false
;
std
::
unique_ptr
<
RawConverter
>
m_raw_converter
;
public
:
~
RawInputStream
();
...
...
src/rawoutputstream.o
deleted
100644 → 0
View file @
9c595731
File deleted
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