Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
662cc5fe
Commit
662cc5fe
authored
Aug 24, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decoder/mad: make variables more local
parent
e1e62d97
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
60 deletions
+31
-60
MadDecoderPlugin.cxx
src/decoder/plugins/MadDecoderPlugin.cxx
+31
-60
No files found.
src/decoder/plugins/MadDecoderPlugin.cxx
View file @
662cc5fe
...
@@ -96,12 +96,9 @@ mad_fixed_to_24_buffer(int32_t *dest, const struct mad_synth *synth,
...
@@ -96,12 +96,9 @@ mad_fixed_to_24_buffer(int32_t *dest, const struct mad_synth *synth,
unsigned
int
start
,
unsigned
int
end
,
unsigned
int
start
,
unsigned
int
end
,
unsigned
int
num_channels
)
unsigned
int
num_channels
)
{
{
unsigned
int
i
,
c
;
for
(
unsigned
i
=
start
;
i
<
end
;
++
i
)
for
(
unsigned
c
=
0
;
c
<
num_channels
;
++
c
)
for
(
i
=
start
;
i
<
end
;
++
i
)
{
for
(
c
=
0
;
c
<
num_channels
;
++
c
)
*
dest
++
=
mad_fixed_to_24_sample
(
synth
->
pcm
.
samples
[
c
][
i
]);
*
dest
++
=
mad_fixed_to_24_sample
(
synth
->
pcm
.
samples
[
c
][
i
]);
}
}
}
static
bool
static
bool
...
@@ -254,22 +251,19 @@ static bool
...
@@ -254,22 +251,19 @@ static bool
parse_id3_replay_gain_info
(
ReplayGainInfo
&
rgi
,
parse_id3_replay_gain_info
(
ReplayGainInfo
&
rgi
,
struct
id3_tag
*
tag
)
struct
id3_tag
*
tag
)
{
{
int
i
;
char
*
key
;
char
*
value
;
struct
id3_frame
*
frame
;
bool
found
=
false
;
bool
found
=
false
;
rgi
.
Clear
();
rgi
.
Clear
();
for
(
i
=
0
;
(
frame
=
id3_tag_findframe
(
tag
,
"TXXX"
,
i
));
i
++
)
{
struct
id3_frame
*
frame
;
for
(
unsigned
i
=
0
;
(
frame
=
id3_tag_findframe
(
tag
,
"TXXX"
,
i
));
i
++
)
{
if
(
frame
->
nfields
<
3
)
if
(
frame
->
nfields
<
3
)
continue
;
continue
;
key
=
(
char
*
)
char
*
const
key
=
(
char
*
)
id3_ucs4_latin1duplicate
(
id3_field_getstring
id3_ucs4_latin1duplicate
(
id3_field_getstring
(
&
frame
->
fields
[
1
]));
(
&
frame
->
fields
[
1
]));
value
=
(
char
*
)
char
*
const
value
=
(
char
*
)
id3_ucs4_latin1duplicate
(
id3_field_getstring
id3_ucs4_latin1duplicate
(
id3_field_getstring
(
&
frame
->
fields
[
2
]));
(
&
frame
->
fields
[
2
]));
...
@@ -302,21 +296,17 @@ gcc_pure
...
@@ -302,21 +296,17 @@ gcc_pure
static
MixRampInfo
static
MixRampInfo
parse_id3_mixramp
(
struct
id3_tag
*
tag
)
parse_id3_mixramp
(
struct
id3_tag
*
tag
)
{
{
int
i
;
char
*
key
;
char
*
value
;
struct
id3_frame
*
frame
;
MixRampInfo
result
;
MixRampInfo
result
;
for
(
i
=
0
;
(
frame
=
id3_tag_findframe
(
tag
,
"TXXX"
,
i
));
i
++
)
{
struct
id3_frame
*
frame
;
for
(
unsigned
i
=
0
;
(
frame
=
id3_tag_findframe
(
tag
,
"TXXX"
,
i
));
i
++
)
{
if
(
frame
->
nfields
<
3
)
if
(
frame
->
nfields
<
3
)
continue
;
continue
;
key
=
(
char
*
)
char
*
const
key
=
(
char
*
)
id3_ucs4_latin1duplicate
(
id3_field_getstring
id3_ucs4_latin1duplicate
(
id3_field_getstring
(
&
frame
->
fields
[
1
]));
(
&
frame
->
fields
[
1
]));
value
=
(
char
*
)
char
*
const
value
=
(
char
*
)
id3_ucs4_latin1duplicate
(
id3_field_getstring
id3_ucs4_latin1duplicate
(
id3_field_getstring
(
&
frame
->
fields
[
2
]));
(
&
frame
->
fields
[
2
]));
...
@@ -338,13 +328,11 @@ inline void
...
@@ -338,13 +328,11 @@ inline void
MadDecoder
::
ParseId3
(
size_t
tagsize
,
Tag
**
mpd_tag
)
MadDecoder
::
ParseId3
(
size_t
tagsize
,
Tag
**
mpd_tag
)
{
{
#ifdef HAVE_ID3TAG
#ifdef HAVE_ID3TAG
struct
id3_tag
*
id3_tag
=
nullptr
;
id3_length_t
count
;
id3_byte_t
const
*
id3_data
;
id3_byte_t
*
allocated
=
nullptr
;
id3_byte_t
*
allocated
=
nullptr
;
count
=
stream
.
bufend
-
stream
.
this_frame
;
co
nst
id3_length_t
co
unt
=
stream
.
bufend
-
stream
.
this_frame
;
const
id3_byte_t
*
id3_data
;
if
(
tagsize
<=
count
)
{
if
(
tagsize
<=
count
)
{
id3_data
=
stream
.
this_frame
;
id3_data
=
stream
.
this_frame
;
mad_stream_skip
(
&
(
stream
),
tagsize
);
mad_stream_skip
(
&
(
stream
),
tagsize
);
...
@@ -363,7 +351,7 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag)
...
@@ -363,7 +351,7 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag)
id3_data
=
allocated
;
id3_data
=
allocated
;
}
}
id3_tag
=
id3_tag_parse
(
id3_data
,
tagsize
);
struct
id3_tag
*
const
id3_tag
=
id3_tag_parse
(
id3_data
,
tagsize
);
if
(
id3_tag
==
nullptr
)
{
if
(
id3_tag
==
nullptr
)
{
delete
[]
allocated
;
delete
[]
allocated
;
return
;
return
;
...
@@ -558,17 +546,12 @@ struct lame {
...
@@ -558,17 +546,12 @@ struct lame {
static
bool
static
bool
parse_xing
(
struct
xing
*
xing
,
struct
mad_bitptr
*
ptr
,
int
*
oldbitlen
)
parse_xing
(
struct
xing
*
xing
,
struct
mad_bitptr
*
ptr
,
int
*
oldbitlen
)
{
{
unsigned
long
bits
;
int
bitlen
=
*
oldbitlen
;
int
bitlen
;
int
bitsleft
;
int
i
;
bitlen
=
*
oldbitlen
;
if
(
bitlen
<
16
)
if
(
bitlen
<
16
)
return
false
;
return
false
;
bits
=
mad_bit_read
(
ptr
,
16
);
const
unsigned
long
bits
=
mad_bit_read
(
ptr
,
16
);
bitlen
-=
16
;
bitlen
-=
16
;
if
(
bits
==
XI_MAGIC
)
{
if
(
bits
==
XI_MAGIC
)
{
...
@@ -617,7 +600,8 @@ parse_xing(struct xing *xing, struct mad_bitptr *ptr, int *oldbitlen)
...
@@ -617,7 +600,8 @@ parse_xing(struct xing *xing, struct mad_bitptr *ptr, int *oldbitlen)
if
(
xing
->
flags
&
XING_TOC
)
{
if
(
xing
->
flags
&
XING_TOC
)
{
if
(
bitlen
<
800
)
if
(
bitlen
<
800
)
return
false
;
return
false
;
for
(
i
=
0
;
i
<
100
;
++
i
)
xing
->
toc
[
i
]
=
mad_bit_read
(
ptr
,
8
);
for
(
unsigned
i
=
0
;
i
<
100
;
++
i
)
xing
->
toc
[
i
]
=
mad_bit_read
(
ptr
,
8
);
bitlen
-=
800
;
bitlen
-=
800
;
}
}
...
@@ -630,7 +614,7 @@ parse_xing(struct xing *xing, struct mad_bitptr *ptr, int *oldbitlen)
...
@@ -630,7 +614,7 @@ parse_xing(struct xing *xing, struct mad_bitptr *ptr, int *oldbitlen)
/* Make sure we consume no less than 120 bytes (960 bits) in hopes that
/* Make sure we consume no less than 120 bytes (960 bits) in hopes that
* the LAME tag is found there, and not right after the Xing header */
* the LAME tag is found there, and not right after the Xing header */
bitsleft
=
960
-
((
*
oldbitlen
)
-
bitlen
);
const
int
bitsleft
=
960
-
(
*
oldbitlen
-
bitlen
);
if
(
bitsleft
<
0
)
if
(
bitsleft
<
0
)
return
false
;
return
false
;
else
if
(
bitsleft
>
0
)
{
else
if
(
bitsleft
>
0
)
{
...
@@ -646,19 +630,12 @@ parse_xing(struct xing *xing, struct mad_bitptr *ptr, int *oldbitlen)
...
@@ -646,19 +630,12 @@ parse_xing(struct xing *xing, struct mad_bitptr *ptr, int *oldbitlen)
static
bool
static
bool
parse_lame
(
struct
lame
*
lame
,
struct
mad_bitptr
*
ptr
,
int
*
bitlen
)
parse_lame
(
struct
lame
*
lame
,
struct
mad_bitptr
*
ptr
,
int
*
bitlen
)
{
{
int
adj
=
0
;
int
name
;
int
orig
;
int
sign
;
int
gain
;
int
i
;
/* Unlike the xing header, the lame tag has a fixed length. Fail if
/* Unlike the xing header, the lame tag has a fixed length. Fail if
* not all 36 bytes (288 bits) are there. */
* not all 36 bytes (288 bits) are there. */
if
(
*
bitlen
<
288
)
if
(
*
bitlen
<
288
)
return
false
;
return
false
;
for
(
i
=
0
;
i
<
9
;
i
++
)
for
(
unsigned
i
=
0
;
i
<
9
;
i
++
)
lame
->
encoder
[
i
]
=
(
char
)
mad_bit_read
(
ptr
,
8
);
lame
->
encoder
[
i
]
=
(
char
)
mad_bit_read
(
ptr
,
8
);
lame
->
encoder
[
9
]
=
'\0'
;
lame
->
encoder
[
9
]
=
'\0'
;
...
@@ -684,6 +661,7 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
...
@@ -684,6 +661,7 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
* it's impossible to make the proper adjustment for 3.95.
* it's impossible to make the proper adjustment for 3.95.
* Fortunately, 3.95 was only out for about a day before 3.95.1 was
* Fortunately, 3.95 was only out for about a day before 3.95.1 was
* released. -- tmz */
* released. -- tmz */
int
adj
=
0
;
if
(
lame
->
version
.
major
<
3
||
if
(
lame
->
version
.
major
<
3
||
(
lame
->
version
.
major
==
3
&&
lame
->
version
.
minor
<
95
))
(
lame
->
version
.
major
==
3
&&
lame
->
version
.
minor
<
95
))
adj
=
6
;
adj
=
6
;
...
@@ -694,10 +672,10 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
...
@@ -694,10 +672,10 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
FormatDebug
(
mad_domain
,
"LAME peak found: %f"
,
lame
->
peak
);
FormatDebug
(
mad_domain
,
"LAME peak found: %f"
,
lame
->
peak
);
lame
->
track_gain
=
0
;
lame
->
track_gain
=
0
;
name
=
mad_bit_read
(
ptr
,
3
);
/* gain name */
unsigned
name
=
mad_bit_read
(
ptr
,
3
);
/* gain name */
orig
=
mad_bit_read
(
ptr
,
3
);
/* gain originator */
unsigned
orig
=
mad_bit_read
(
ptr
,
3
);
/* gain originator */
sign
=
mad_bit_read
(
ptr
,
1
);
/* sign bit */
unsigned
sign
=
mad_bit_read
(
ptr
,
1
);
/* sign bit */
gain
=
mad_bit_read
(
ptr
,
9
);
/* gain*10 */
unsigned
gain
=
mad_bit_read
(
ptr
,
9
);
/* gain*10 */
if
(
gain
&&
name
==
1
&&
orig
!=
0
)
{
if
(
gain
&&
name
==
1
&&
orig
!=
0
)
{
lame
->
track_gain
=
((
sign
?
-
gain
:
gain
)
/
10.0
)
+
adj
;
lame
->
track_gain
=
((
sign
?
-
gain
:
gain
)
/
10.0
)
+
adj
;
FormatDebug
(
mad_domain
,
"LAME track gain found: %f"
,
FormatDebug
(
mad_domain
,
"LAME track gain found: %f"
,
...
@@ -785,17 +763,13 @@ MadDecoder::FileSizeToSongLength()
...
@@ -785,17 +763,13 @@ MadDecoder::FileSizeToSongLength()
inline
bool
inline
bool
MadDecoder
::
DecodeFirstFrame
(
Tag
**
tag
)
MadDecoder
::
DecodeFirstFrame
(
Tag
**
tag
)
{
{
struct
xing
xing
;
struct
lame
lame
;
struct
mad_bitptr
ptr
;
int
bitlen
;
enum
mp3_action
ret
;
/* stfu gcc */
/* stfu gcc */
struct
xing
xing
;
memset
(
&
xing
,
0
,
sizeof
(
struct
xing
));
memset
(
&
xing
,
0
,
sizeof
(
struct
xing
));
xing
.
flags
=
0
;
xing
.
flags
=
0
;
while
(
true
)
{
while
(
true
)
{
enum
mp3_action
ret
;
do
{
do
{
ret
=
DecodeNextFrameHeader
(
tag
);
ret
=
DecodeNextFrameHeader
(
tag
);
}
while
(
ret
==
DECODE_CONT
);
}
while
(
ret
==
DECODE_CONT
);
...
@@ -811,8 +785,8 @@ MadDecoder::DecodeFirstFrame(Tag **tag)
...
@@ -811,8 +785,8 @@ MadDecoder::DecodeFirstFrame(Tag **tag)
if
(
ret
==
DECODE_OK
)
break
;
if
(
ret
==
DECODE_OK
)
break
;
}
}
ptr
=
stream
.
anc_ptr
;
struct
mad_bitptr
ptr
=
stream
.
anc_ptr
;
bitlen
=
stream
.
anc_bitlen
;
int
bitlen
=
stream
.
anc_bitlen
;
FileSizeToSongLength
();
FileSizeToSongLength
();
...
@@ -830,6 +804,7 @@ MadDecoder::DecodeFirstFrame(Tag **tag)
...
@@ -830,6 +804,7 @@ MadDecoder::DecodeFirstFrame(Tag **tag)
max_frames
=
xing
.
frames
;
max_frames
=
xing
.
frames
;
}
}
struct
lame
lame
;
if
(
parse_lame
(
&
lame
,
&
ptr
,
&
bitlen
))
{
if
(
parse_lame
(
&
lame
,
&
ptr
,
&
bitlen
))
{
if
(
gapless_playback
&&
input_stream
.
IsSeekable
())
{
if
(
gapless_playback
&&
input_stream
.
IsSeekable
())
{
drop_start_samples
=
lame
.
encoder_delay
+
drop_start_samples
=
lame
.
encoder_delay
+
...
@@ -931,9 +906,7 @@ MadDecoder::UpdateTimerNextFrame()
...
@@ -931,9 +906,7 @@ MadDecoder::UpdateTimerNextFrame()
DecoderCommand
DecoderCommand
MadDecoder
::
SendPCM
(
unsigned
i
,
unsigned
pcm_length
)
MadDecoder
::
SendPCM
(
unsigned
i
,
unsigned
pcm_length
)
{
{
unsigned
max_samples
;
unsigned
max_samples
=
sizeof
(
output_buffer
)
/
max_samples
=
sizeof
(
output_buffer
)
/
sizeof
(
output_buffer
[
0
])
/
sizeof
(
output_buffer
[
0
])
/
MAD_NCHANNELS
(
&
frame
.
header
);
MAD_NCHANNELS
(
&
frame
.
header
);
...
@@ -1128,9 +1101,7 @@ static bool
...
@@ -1128,9 +1101,7 @@ static bool
mad_decoder_scan_stream
(
InputStream
&
is
,
mad_decoder_scan_stream
(
InputStream
&
is
,
const
struct
tag_handler
*
handler
,
void
*
handler_ctx
)
const
struct
tag_handler
*
handler
,
void
*
handler_ctx
)
{
{
int
total_time
;
const
int
total_time
=
mad_decoder_total_file_time
(
is
);
total_time
=
mad_decoder_total_file_time
(
is
);
if
(
total_time
<
0
)
if
(
total_time
<
0
)
return
false
;
return
false
;
...
...
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