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
f139f169
Commit
f139f169
authored
Dec 13, 2019
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unify audio input stream creation.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
627a6734
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
52 deletions
+57
-52
Makefile.am
src/Makefile.am
+2
-2
audiostream.cc
src/audiostream.cc
+41
-0
audiostream.hh
src/audiostream.hh
+3
-0
utils.hh
src/utils.hh
+1
-1
wavdata.cc
src/wavdata.cc
+3
-14
wmadd.cc
src/wmadd.cc
+7
-35
No files found.
src/Makefile.am
View file @
f139f169
...
...
@@ -3,10 +3,10 @@ bin_PROGRAMS = audiowmark
COMMON_SRC
=
utils.hh utils.cc convcode.hh convcode.cc random.hh random.cc mp3.cc mp3.hh wavdata.cc wavdata.hh
\
audiostream.cc audiostream.hh sfinputstream.cc sfinputstream.hh stdoutwavoutputstream.cc stdoutwavoutputstream.hh
\
sfoutputstream.cc sfoutputstream.hh rawinputstream.cc rawinputstream.hh rawoutputstream.cc rawoutputstream.hh
\
rawconverter.cc rawconverter.hh mp3inputstream.cc mp3inputstream.hh
rawconverter.cc rawconverter.hh mp3inputstream.cc mp3inputstream.hh
wmcommon.cc wmcommon.hh fft.cc fft.hh
COMMON_LIBS
=
$(SNDFILE_LIBS)
$(FFTW_LIBS)
$(LIBGCRYPT_LIBS)
$(LIBMPG123_LIBS)
audiowmark_SOURCES
=
audiowmark.cc
fft.cc fft.hh wmget.cc wmadd.cc wmcommon.hh wmcommon
.cc
$(COMMON_SRC)
audiowmark_SOURCES
=
audiowmark.cc
wmget.cc wmadd
.cc
$(COMMON_SRC)
audiowmark_LDFLAGS
=
$(COMMON_LIBS)
noinst_PROGRAMS
=
testconvcode testrandom testmp3 teststream
...
...
src/audiostream.cc
View file @
f139f169
#include "audiostream.hh"
#include "wmcommon.hh"
#include "sfinputstream.hh"
#include "mp3.hh"
#include "mp3inputstream.hh"
#include "rawconverter.hh"
using
std
::
string
;
AudioStream
::~
AudioStream
()
{
}
std
::
unique_ptr
<
AudioInputStream
>
AudioInputStream
::
create
(
const
string
&
filename
,
Error
&
err
)
{
std
::
unique_ptr
<
AudioInputStream
>
in_stream
;
if
(
Params
::
input_format
==
Format
::
AUTO
)
{
SFInputStream
*
sistream
=
new
SFInputStream
();
in_stream
.
reset
(
sistream
);
Error
err
=
sistream
->
open
(
filename
);
if
(
err
&&
mp3_detect
(
filename
))
{
MP3InputStream
*
mistream
=
new
MP3InputStream
();
in_stream
.
reset
(
mistream
);
err
=
mistream
->
open
(
filename
);
if
(
err
)
return
nullptr
;
}
else
if
(
err
)
return
nullptr
;
}
else
{
RawInputStream
*
ristream
=
new
RawInputStream
();
in_stream
.
reset
(
ristream
);
err
=
ristream
->
open
(
filename
,
Params
::
raw_input_format
);
if
(
err
)
return
nullptr
;
}
return
in_stream
;
}
src/audiostream.hh
View file @
f139f169
...
...
@@ -2,6 +2,7 @@
#define AUDIOWMARK_AUDIO_STREAM_HH
#include <vector>
#include <memory>
#include "utils.hh"
class
AudioStream
...
...
@@ -17,6 +18,8 @@ public:
class
AudioInputStream
:
public
AudioStream
{
public
:
static
std
::
unique_ptr
<
AudioInputStream
>
create
(
const
std
::
string
&
filename
,
Error
&
err
);
// for streams that do not know the number of frames in advance (i.e. raw input stream)
static
constexpr
size_t
N_FRAMES_UNKNOWN
=
~
size_t
(
0
);
virtual
size_t
n_frames
()
const
=
0
;
...
...
src/utils.hh
View file @
f139f169
...
...
@@ -48,7 +48,7 @@ public:
NONE
,
STR
};
Error
(
Code
code
)
:
Error
(
Code
code
=
Code
::
NONE
)
:
m_code
(
code
)
{
switch
(
code
)
...
...
src/wavdata.cc
View file @
f139f169
...
...
@@ -27,21 +27,10 @@ WavData::WavData (const vector<float>& samples, int n_channels, int sample_rate,
Error
WavData
::
load
(
const
string
&
filename
)
{
std
::
unique_ptr
<
AudioInputStream
>
in_stream
;
// FIXME: virtual constructor
Error
err
;
SFInputStream
*
sistream
=
new
SFInputStream
();
in_stream
.
reset
(
sistream
);
Error
err
=
sistream
->
open
(
filename
);
if
(
err
&&
mp3_detect
(
filename
))
{
MP3InputStream
*
mistream
=
new
MP3InputStream
();
in_stream
.
reset
(
mistream
);
err
=
mistream
->
open
(
filename
);
if
(
err
)
return
err
;
}
else
if
(
err
)
std
::
unique_ptr
<
AudioInputStream
>
in_stream
=
AudioInputStream
::
create
(
filename
,
err
);
if
(
err
)
return
err
;
return
load
(
in_stream
.
get
());
...
...
src/wmadd.cc
View file @
f139f169
...
...
@@ -593,40 +593,12 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
auto
bitvec_a
=
randomize_bit_order
(
conv_encode
(
ConvBlockType
::
a
,
bitvec
),
/* encode */
true
);
auto
bitvec_b
=
randomize_bit_order
(
conv_encode
(
ConvBlockType
::
b
,
bitvec
),
/* encode */
true
);
std
::
unique_ptr
<
AudioInputStream
>
in_stream
;
// FIXME: virtual constructor
if
(
Params
::
input_format
==
Format
::
AUTO
)
{
SFInputStream
*
sistream
=
new
SFInputStream
();
in_stream
.
reset
(
sistream
);
Error
err
=
sistream
->
open
(
infile
);
if
(
err
&&
mp3_detect
(
infile
))
{
MP3InputStream
*
mistream
=
new
MP3InputStream
();
in_stream
.
reset
(
mistream
);
err
=
mistream
->
open
(
infile
);
if
(
err
)
{
error
(
"audiowmark: error opening mp3 %s: %s
\n
"
,
infile
.
c_str
(),
err
.
message
());
return
1
;
}
}
else
if
(
err
)
{
error
(
"audiowmark: error opening %s: %s
\n
"
,
infile
.
c_str
(),
err
.
message
());
return
1
;
}
}
else
Error
err
;
std
::
unique_ptr
<
AudioInputStream
>
in_stream
=
AudioInputStream
::
create
(
infile
,
err
);
if
(
err
)
{
RawInputStream
*
ristream
=
new
RawInputStream
();
in_stream
.
reset
(
ristream
);
Error
err
=
ristream
->
open
(
infile
,
Params
::
raw_input_format
);
if
(
err
)
{
error
(
"audiowmark: error opening %s: %s
\n
"
,
infile
.
c_str
(),
err
.
message
());
return
1
;
}
error
(
"audiowmark: error opening %s: %s
\n
"
,
infile
.
c_str
(),
err
.
message
());
return
1
;
}
if
(
in_stream
->
n_frames
()
==
AudioInputStream
::
N_FRAMES_UNKNOWN
)
{
...
...
@@ -646,7 +618,7 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
{
RawOutputStream
*
rostream
=
new
RawOutputStream
();
out_stream
.
reset
(
rostream
);
Error
err
=
rostream
->
open
(
outfile
,
Params
::
raw_output_format
);
err
=
rostream
->
open
(
outfile
,
Params
::
raw_output_format
);
if
(
err
)
{
error
(
"audiowmark: error opening %s: %s
\n
"
,
outfile
.
c_str
(),
err
.
message
());
...
...
@@ -756,7 +728,7 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
}
}
Error
err
=
out_stream
->
close
();
err
=
out_stream
->
close
();
if
(
err
)
error
(
"audiowmark: closing output stream failed: %s
\n
"
,
err
.
message
());
...
...
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