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
d06fdbfb
Commit
d06fdbfb
authored
Dec 03, 2019
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanups in MP3InputStream.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
70ee91d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
15 deletions
+8
-15
mp3inputstream.cc
src/mp3inputstream.cc
+7
-15
mp3inputstream.hh
src/mp3inputstream.hh
+1
-0
No files found.
src/mp3inputstream.cc
View file @
d06fdbfb
...
...
@@ -79,8 +79,7 @@ MP3InputStream::open (const std::string& filename)
Error
MP3InputStream
::
read_frames
(
std
::
vector
<
float
>&
samples
,
size_t
count
)
{
bool
eof
=
false
;
while
(
m_read_buffer
.
size
()
<
count
*
m_n_channels
)
while
(
!
m_eof
&&
m_read_buffer
.
size
()
<
count
*
m_n_channels
)
{
size_t
buffer_bytes
=
mpg123_outblock
(
m_handle
);
assert
(
buffer_bytes
%
sizeof
(
float
)
==
0
);
...
...
@@ -96,14 +95,12 @@ MP3InputStream::read_frames (std::vector<float>& samples, size_t count)
}
else
if
(
err
==
MPG123_DONE
)
{
eof
=
true
;
break
;
m_eof
=
true
;
}
else
if
(
err
==
MPG123_NEED_MORE
)
{
// some mp3s have this error before reaching eof -> harmless
eof
=
true
;
break
;
m_eof
=
true
;
}
else
{
...
...
@@ -111,17 +108,12 @@ MP3InputStream::read_frames (std::vector<float>& samples, size_t count)
}
}
/* pad zero samples at end if necessary to match the number of frames we promised to deliver */
if
(
eof
&&
m_read_buffer
.
size
()
<
m_frames_left
*
m_n_channels
)
{
fprintf
(
stderr
,
"mp3: padding %zd frames at end
\n
"
,
m_frames_left
-
m_read_buffer
.
size
()
/
m_n_channels
);
m_read_buffer
.
resize
(
m_frames_left
*
m_n_channels
);
}
if
(
m_eof
&&
m_read_buffer
.
size
()
<
m_frames_left
*
m_n_channels
)
m_read_buffer
.
resize
(
m_frames_left
*
m_n_channels
);
/* never read past the promised number of frames */
if
(
count
>
m_frames_left
)
{
fprintf
(
stderr
,
"mp3: ignoring read request: %zd frames at end
\n
"
,
count
-
m_frames_left
);
count
=
m_frames_left
;
}
count
=
m_frames_left
;
const
auto
begin
=
m_read_buffer
.
begin
();
const
auto
end
=
begin
+
min
(
count
*
m_n_channels
,
m_read_buffer
.
size
());
...
...
src/mp3inputstream.hh
View file @
d06fdbfb
...
...
@@ -18,6 +18,7 @@ class MP3InputStream : public AudioInputStream
int
m_sample_rate
=
0
;
int
m_frames_left
=
0
;
bool
m_need_close
=
false
;
bool
m_eof
=
false
;
State
m_state
=
State
::
NEW
;
mpg123_handle
*
m_handle
=
nullptr
;
...
...
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