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
fb503349
Commit
fb503349
authored
Dec 09, 2019
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup old mp3 loader.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
b0b7371e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
95 deletions
+24
-95
mp3.cc
src/mp3.cc
+0
-89
mp3.hh
src/mp3.hh
+0
-1
mp3inputstream.cc
src/mp3inputstream.cc
+3
-1
testmp3.cc
src/testmp3.cc
+12
-3
wavdata.cc
src/wavdata.cc
+7
-1
wavdata.hh
src/wavdata.hh
+2
-0
No files found.
src/mp3.cc
View file @
fb503349
...
...
@@ -92,92 +92,3 @@ mp3_detect (const string& filename)
}
return
true
;
}
string
mp3_load
(
const
string
&
filename
,
WavData
&
wav_data
)
{
int
err
=
0
;
mp3_init
();
mpg123_handle
*
mh
=
mpg123_new
(
NULL
,
&
err
);
if
(
err
!=
MPG123_OK
)
return
"mpg123_new failed"
;
auto
smh
=
ScopedMHandle
{
mh
};
// cleanup on return
err
=
mpg123_param
(
mh
,
MPG123_ADD_FLAGS
,
MPG123_QUIET
,
0
);
if
(
err
!=
MPG123_OK
)
return
"setting quiet mode failed"
;
// allow arbitary amount of data for resync */
err
=
mpg123_param
(
mh
,
MPG123_RESYNC_LIMIT
,
-
1
,
0
);
if
(
err
!=
MPG123_OK
)
return
"setting resync limit parameter failed"
;
// force floating point output
{
const
long
*
rates
;
size_t
rate_count
;
mpg123_format_none
(
mh
);
mpg123_rates
(
&
rates
,
&
rate_count
);
for
(
size_t
i
=
0
;
i
<
rate_count
;
i
++
)
{
err
=
mpg123_format
(
mh
,
rates
[
i
],
MPG123_MONO
|
MPG123_STEREO
,
MPG123_ENC_FLOAT_32
);
if
(
err
!=
MPG123_OK
)
return
mpg123_strerror
(
mh
);
}
}
err
=
mpg123_open
(
mh
,
filename
.
c_str
());
if
(
err
!=
MPG123_OK
)
return
mpg123_strerror
(
mh
);
smh
.
need_close
=
true
;
long
rate
;
int
channels
;
int
encoding
;
err
=
mpg123_getformat
(
mh
,
&
rate
,
&
channels
,
&
encoding
);
if
(
err
!=
MPG123_OK
)
return
mpg123_strerror
(
mh
);
/* ensure that the format will not change */
mpg123_format_none
(
mh
);
mpg123_format
(
mh
,
rate
,
channels
,
encoding
);
size_t
buffer_bytes
=
mpg123_outblock
(
mh
);
assert
(
buffer_bytes
%
sizeof
(
float
)
==
0
);
vector
<
float
>
buffer
(
buffer_bytes
/
sizeof
(
float
));
vector
<
float
>
samples
;
while
(
true
)
{
size_t
done
=
0
;
err
=
mpg123_read
(
mh
,
reinterpret_cast
<
unsigned
char
*>
(
&
buffer
[
0
]),
buffer_bytes
,
&
done
);
if
(
err
==
MPG123_OK
)
{
const
size_t
n_values
=
done
/
sizeof
(
float
);
samples
.
insert
(
samples
.
end
(),
buffer
.
begin
(),
buffer
.
begin
()
+
n_values
);
}
else
if
(
err
==
MPG123_DONE
)
{
wav_data
=
WavData
(
samples
,
channels
,
rate
,
24
);
return
""
;
/* success */
}
else
if
(
err
==
MPG123_NEED_MORE
)
{
// some mp3s have this error before reaching eof -> harmless
}
else
{
return
mpg123_strerror
(
mh
);
}
}
}
src/mp3.hh
View file @
fb503349
...
...
@@ -6,7 +6,6 @@
#include "wavdata.hh"
bool
mp3_detect
(
const
std
::
string
&
filename
);
std
::
string
mp3_load
(
const
std
::
string
&
filename
,
WavData
&
wav_data
);
void
mp3_init
();
#endif
/* AUDIOWMARK_MP3_HH */
src/mp3inputstream.cc
View file @
fb503349
...
...
@@ -54,7 +54,9 @@ MP3InputStream::open (const std::string& filename)
m_need_close
=
true
;
/* scan headers to get best possible length estimate */
mpg123_scan
(
m_handle
);
err
=
mpg123_scan
(
m_handle
);
if
(
err
!=
MPG123_OK
)
return
Error
(
mpg123_strerror
(
m_handle
));
long
rate
;
int
channels
;
...
...
src/testmp3.cc
View file @
fb503349
#include "mp3.hh"
#include "mp3inputstream.hh"
using
std
::
string
;
...
...
@@ -10,8 +11,16 @@ main (int argc, char **argv)
{
if
(
mp3_detect
(
argv
[
1
]))
{
string
error
=
mp3_load
(
argv
[
1
],
wd
);
if
(
error
==
""
)
MP3InputStream
m3i
;
Error
err
=
m3i
.
open
(
argv
[
1
]);
if
(
err
)
{
printf
(
"mp3 open %s failed: %s
\n
"
,
argv
[
1
],
err
.
message
());
return
1
;
}
err
=
wd
.
load
(
&
m3i
);
if
(
!
err
)
{
int
sec
=
wd
.
n_values
()
/
wd
.
n_channels
()
/
wd
.
sample_rate
();
...
...
@@ -24,7 +33,7 @@ main (int argc, char **argv)
}
else
{
printf
(
"mp3 load %s failed: %s
\n
"
,
argv
[
1
],
err
or
.
c_str
());
printf
(
"mp3 load %s failed: %s
\n
"
,
argv
[
1
],
err
.
message
());
return
1
;
}
}
...
...
src/wavdata.cc
View file @
fb503349
...
...
@@ -44,10 +44,16 @@ WavData::load (const string& filename)
else
if
(
err
)
return
err
;
return
load
(
in_stream
.
get
());
}
Error
WavData
::
load
(
AudioInputStream
*
in_stream
)
{
vector
<
float
>
m_buffer
;
while
(
true
)
{
err
=
in_stream
->
read_frames
(
m_buffer
,
1024
);
Error
err
=
in_stream
->
read_frames
(
m_buffer
,
1024
);
if
(
err
)
return
err
;
...
...
src/wavdata.hh
View file @
fb503349
...
...
@@ -5,6 +5,7 @@
#include <vector>
#include "utils.hh"
#include "audiostream.hh"
class
WavData
{
...
...
@@ -17,6 +18,7 @@ public:
WavData
();
WavData
(
const
std
::
vector
<
float
>&
samples
,
int
n_channels
,
int
sample_rate
,
int
bit_depth
);
Error
load
(
AudioInputStream
*
in_stream
);
Error
load
(
const
std
::
string
&
filename
);
Error
save
(
const
std
::
string
&
filename
);
...
...
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