Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ale
imms
Commits
c4ca66f4
Commit
c4ca66f4
authored
Oct 12, 2013
by
ale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add options to control the output format
parent
5e4f3452
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
12 deletions
+53
-12
analyzer/main.cc
analyzer/main.cc
+53
-12
No files found.
analyzer/main.cc
View file @
c4ca66f4
...
...
@@ -4,6 +4,9 @@
#include <sstream>
#include <string>
#include <getopt.h>
#include <unistd.h>
#include <immsutil.h>
#include <appname.h>
#include <base64.h>
...
...
@@ -39,6 +42,19 @@ void dump_features_json(Features *f) {
<<
"}"
<<
endl
;
}
void
dump_features_raw
(
Features
*
f
,
int
do_base64
)
{
int
n
=
Features
::
SerializedSize
;
char
buf
[
n
];
f
->
serialize
(
buf
,
n
);
if
(
do_base64
)
{
cout
<<
base64
::
base64_encode
((
unsigned
char
*
)
buf
,
n
)
<<
endl
;
}
else
{
write
(
1
,
buf
,
n
);
}
}
Features
*
analyze
(
FILE
*
stream
)
{
int
n
;
char
buf
[
1024
];
...
...
@@ -52,18 +68,43 @@ Features *analyze(FILE *stream) {
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
>
1
)
{
cout
<<
"usage: analyzer"
<<
endl
<<
"File data must be passed on standard input as:"
<<
endl
<<
" raw PCM, 16-bit unsigned, mono, "
<<
SAMPLERATE
<<
" Hz"
<<
endl
<<
endl
;
return
-
1
;
int
opt
;
int
output_base64
=
0
;
int
output_json
=
0
;
while
((
opt
=
getopt
(
argc
,
argv
,
"bj"
))
>
0
)
{
switch
(
opt
)
{
case
'b'
:
output_base64
=
1
;
break
;
case
'j'
:
output_json
=
1
;
break
;
}
}
if
(
optind
<
argc
)
{
cout
<<
"usage: analyzer [-b|-j]"
<<
endl
<<
"File data must be passed on standard input as:"
<<
endl
<<
" raw PCM, 16-bit unsigned, mono, "
<<
SAMPLERATE
<<
" Hz"
<<
endl
<<
endl
<<
"The output vector will be dumped on standard output."
<<
endl
<<
"With the -b option, the output will be base64-encoded."
<<
endl
<<
"With the -j option, the output will be a JSON object."
<<
endl
<<
endl
;
return
1
;
}
Features
*
f
=
analyze
(
stdin
);
if
(
!
f
)
{
LOG
(
ERROR
)
<<
"Could not process input data."
<<
endl
;
}
else
{
if
(
output_json
==
1
)
{
dump_features_json
(
f
);
}
else
{
dump_features_raw
(
f
,
output_base64
);
}
}
Features
*
f
=
analyze
(
stdin
);
if
(
!
f
)
LOG
(
ERROR
)
<<
"Could not process input data."
<<
endl
;
else
dump_features_json
(
f
);
return
0
;
}
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