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
0086f8ed
Commit
0086f8ed
authored
Nov 29, 2019
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support command line options to set input/output raw stream format.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
19147744
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
10 deletions
+99
-10
audiowmark.cc
src/audiowmark.cc
+32
-1
rawinputstream.cc
src/rawinputstream.cc
+47
-8
rawinputstream.hh
src/rawinputstream.hh
+20
-1
No files found.
src/audiowmark.cc
View file @
0086f8ed
...
...
@@ -60,6 +60,9 @@ namespace Params
static
Format
input_format
=
Format
::
AUTO
;
static
Format
output_format
=
Format
::
AUTO
;
static
RawFormat
raw_input_format
;
static
RawFormat
raw_output_format
;
}
void
...
...
@@ -221,6 +224,34 @@ parse_options (int *argc_p,
{
Params
::
input_format
=
Params
::
output_format
=
parse_format
(
opt_arg
);
}
else
if
(
check_arg
(
argc
,
argv
,
&
i
,
"--raw-input-bits"
,
&
opt_arg
))
{
int
b
=
atoi
(
opt_arg
);
Params
::
raw_input_format
.
set_bit_depth
(
b
);
}
else
if
(
check_arg
(
argc
,
argv
,
&
i
,
"--raw-output-bits"
,
&
opt_arg
))
{
int
b
=
atoi
(
opt_arg
);
Params
::
raw_output_format
.
set_bit_depth
(
b
);
}
else
if
(
check_arg
(
argc
,
argv
,
&
i
,
"--raw-bits"
,
&
opt_arg
))
{
int
b
=
atoi
(
opt_arg
);
Params
::
raw_input_format
.
set_bit_depth
(
b
);
Params
::
raw_output_format
.
set_bit_depth
(
b
);
}
else
if
(
check_arg
(
argc
,
argv
,
&
i
,
"--raw-channels"
,
&
opt_arg
))
{
int
c
=
atoi
(
opt_arg
);
Params
::
raw_input_format
.
set_channels
(
c
);
Params
::
raw_output_format
.
set_channels
(
c
);
}
else
if
(
check_arg
(
argc
,
argv
,
&
i
,
"--raw-rate"
,
&
opt_arg
))
{
int
r
=
atoi
(
opt_arg
);
Params
::
raw_input_format
.
set_sample_rate
(
r
);
Params
::
raw_output_format
.
set_sample_rate
(
r
);
}
}
/* resort argc/argv */
...
...
@@ -1140,7 +1171,7 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
{
RawInputStream
*
ristream
=
new
RawInputStream
();
in_stream
.
reset
(
ristream
);
Error
err
=
ristream
->
open
(
infile
);
Error
err
=
ristream
->
open
(
infile
,
Params
::
raw_input_format
);
if
(
err
)
{
fprintf
(
stderr
,
"audiowmark: error opening %s: %s
\n
"
,
infile
.
c_str
(),
err
.
message
());
...
...
src/rawinputstream.cc
View file @
0086f8ed
...
...
@@ -5,16 +5,51 @@
using
std
::
string
;
using
std
::
vector
;
RawFormat
::
RawFormat
()
{
}
RawFormat
::
RawFormat
(
int
n_channels
,
int
sample_rate
,
int
bit_depth
)
:
m_n_channels
(
n_channels
),
m_sample_rate
(
sample_rate
),
m_bit_depth
(
bit_depth
)
{
}
void
RawFormat
::
set_channels
(
int
channels
)
{
m_n_channels
=
channels
;
}
void
RawFormat
::
set_sample_rate
(
int
rate
)
{
m_sample_rate
=
rate
;
}
void
RawFormat
::
set_bit_depth
(
int
bits
)
{
m_bit_depth
=
bits
;
}
RawInputStream
::~
RawInputStream
()
{
close
();
}
Error
RawInputStream
::
open
(
const
string
&
filename
)
RawInputStream
::
open
(
const
string
&
filename
,
const
RawFormat
&
format
)
{
assert
(
m_state
==
State
::
NEW
);
if
(
!
format
.
n_channels
())
return
Error
(
"RawInputStream: input format: missing number of channels"
);
if
(
!
format
.
bit_depth
())
return
Error
(
"RawInputStream: input format: missing bit depth"
);
if
(
!
format
.
sample_rate
())
return
Error
(
"RawInputStream: input format: missing sample rate"
);
#if 0
SF_INFO sfinfo = { 0, };
...
...
@@ -65,20 +100,21 @@ RawInputStream::open (const string& filename)
}
#endif
m_state
=
State
::
OPEN
;
m_format
=
format
;
m_state
=
State
::
OPEN
;
return
Error
::
Code
::
NONE
;
}
int
RawInputStream
::
sample_rate
()
const
{
return
44100
;
return
m_format
.
sample_rate
()
;
}
int
RawInputStream
::
bit_depth
()
const
{
return
16
;
return
m_format
.
bit_depth
()
;
}
size_t
...
...
@@ -90,7 +126,7 @@ RawInputStream::n_frames() const
int
RawInputStream
::
n_channels
()
const
{
return
2
;
return
m_format
.
n_channels
()
;
}
Error
...
...
@@ -98,12 +134,15 @@ RawInputStream::read_frames (vector<float>& samples, size_t count)
{
assert
(
m_state
==
State
::
OPEN
);
vector
<
unsigned
char
>
input_bytes
(
count
*
n_channels
()
*
(
bit_depth
()
/
8
));
size_t
r_count
=
fread
(
input_bytes
.
data
(),
n_channels
()
*
(
bit_depth
()
/
8
),
count
,
stdin
);
const
int
n_channels
=
m_format
.
n_channels
();
const
int
sample_width
=
m_format
.
bit_depth
()
/
8
;
vector
<
unsigned
char
>
input_bytes
(
count
*
n_channels
*
sample_width
);
size_t
r_count
=
fread
(
input_bytes
.
data
(),
n_channels
*
sample_width
,
count
,
stdin
);
unsigned
char
*
ptr
=
reinterpret_cast
<
unsigned
char
*>
(
input_bytes
.
data
());
samples
.
resize
(
r_count
*
n_channels
()
);
samples
.
resize
(
r_count
*
n_channels
);
const
double
norm
=
1.0
/
0x80000000LL
;
for
(
size_t
i
=
0
;
i
<
samples
.
size
();
i
++
)
{
...
...
src/rawinputstream.hh
View file @
0086f8ed
...
...
@@ -7,6 +7,24 @@
#include "audiostream.hh"
class
RawFormat
{
int
m_n_channels
=
0
;
int
m_sample_rate
=
0
;
int
m_bit_depth
=
0
;
public
:
RawFormat
();
RawFormat
(
int
n_channels
,
int
sample_rate
,
int
bit_depth
);
int
n_channels
()
const
{
return
m_n_channels
;
}
int
sample_rate
()
const
{
return
m_sample_rate
;
}
int
bit_depth
()
const
{
return
m_bit_depth
;
}
void
set_channels
(
int
channels
);
void
set_sample_rate
(
int
rate
);
void
set_bit_depth
(
int
bits
);
};
class
RawInputStream
:
public
AudioInputStream
{
enum
class
State
{
...
...
@@ -15,11 +33,12 @@ class RawInputStream : public AudioInputStream
CLOSED
};
State
m_state
=
State
::
NEW
;
RawFormat
m_format
;
public
:
~
RawInputStream
();
Error
open
(
const
std
::
string
&
filename
);
Error
open
(
const
std
::
string
&
filename
,
const
RawFormat
&
format
);
Error
read_frames
(
std
::
vector
<
float
>&
samples
,
size_t
count
)
override
;
void
close
();
...
...
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