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
ad5abba8
Commit
ad5abba8
authored
Dec 09, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decoder/wavpack: move 8 and 16 bit conversion to separate functions
parent
61296ced
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
45 deletions
+38
-45
WavpackDecoderPlugin.cxx
src/decoder/plugins/WavpackDecoderPlugin.cxx
+38
-45
No files found.
src/decoder/plugins/WavpackDecoderPlugin.cxx
View file @
ad5abba8
...
...
@@ -70,59 +70,45 @@ GetDuration(WavpackContext *wpc)
WavpackGetSampleRate
(
wpc
));
}
/** A pointer type for format converter function. */
typedef
void
(
*
format_samples_t
)(
int
bytes_per_sample
,
void
*
buffer
,
uint32_t
count
);
/*
* This function has been borrowed from the tiny player found on
* wavpack.com. Modifications were required because mpd only handles
* max 24-bit samples.
* Convert 8 bit.
*/
static
void
format_samples_
int
(
int
bytes_per_sample
,
void
*
buffer
,
uint32_t
count
)
format_samples_
8
(
void
*
buffer
,
uint32_t
count
)
{
int32_t
*
src
=
(
int32_t
*
)
buffer
;
int8_t
*
dst
=
(
int8_t
*
)
buffer
;
/*
* The asserts like the following one are because we do the
* formatting of samples within a single buffer. The size of
* the output samples never can be greater than the size of
* the input ones. Otherwise we would have an overflow.
*/
static_assert
(
sizeof
(
*
dst
)
<=
sizeof
(
*
src
),
"Wrong size"
);
switch
(
bytes_per_sample
)
{
case
1
:
{
int8_t
*
dst
=
(
int8_t
*
)
buffer
;
/*
* The asserts like the following one are because we do the
* formatting of samples within a single buffer. The size
* of the output samples never can be greater than the size
* of the input ones. Otherwise we would have an overflow.
*/
static_assert
(
sizeof
(
*
dst
)
<=
sizeof
(
*
src
),
"Wrong size"
);
/* pass through and align 8-bit samples */
std
::
copy_n
(
src
,
count
,
dst
);
break
;
}
case
2
:
{
auto
*
dst
=
(
int16_t
*
)
buffer
;
static_assert
(
sizeof
(
*
dst
)
<=
sizeof
(
*
src
),
"Wrong size"
);
/* pass through and align 8-bit samples */
std
::
copy_n
(
src
,
count
,
dst
);
}
/* pass through and align 16-bit samples */
std
::
copy_n
(
src
,
count
,
dst
);
break
;
}
/*
* Convert 16 bit.
*/
static
void
format_samples_16
(
void
*
buffer
,
uint32_t
count
)
{
int32_t
*
src
=
(
int32_t
*
)
buffer
;
int16_t
*
dst
=
(
int16_t
*
)
buffer
;
static_assert
(
sizeof
(
*
dst
)
<=
sizeof
(
*
src
),
"Wrong size"
);
case
3
:
case
4
:
/* do nothing */
break
;
}
/* pass through and align 16-bit samples */
std
::
copy_n
(
src
,
count
,
dst
);
}
/*
* No conversion necessary.
*/
static
void
format_samples_nop
(
gcc_unused
int
bytes_per_sample
,
gcc_unused
void
*
buffer
,
gcc_unused
uint32_t
count
)
format_samples_nop
(
gcc_unused
void
*
buffer
,
gcc_unused
uint32_t
count
)
{
/* do nothing */
}
...
...
@@ -170,13 +156,21 @@ wavpack_decode(DecoderClient &client, WavpackContext *wpc, bool can_seek)
sample_format
,
WavpackGetReducedChannels
(
wpc
));
const
format_samples_t
format_samples
=
is_float
?
format_samples_nop
:
format_samples_int
;
auto
*
format_samples
=
format_samples_nop
;
if
(
!
is_float
)
{
switch
(
WavpackGetBytesPerSample
(
wpc
))
{
case
1
:
format_samples
=
format_samples_8
;
break
;
case
2
:
format_samples
=
format_samples_16
;
break
;
}
}
client
.
Ready
(
audio_format
,
can_seek
,
GetDuration
(
wpc
));
const
int
bytes_per_sample
=
WavpackGetBytesPerSample
(
wpc
);
const
int
output_sample_size
=
audio_format
.
GetFrameSize
();
/* wavpack gives us all kind of samples in a 32-bit space */
...
...
@@ -207,8 +201,7 @@ wavpack_decode(DecoderClient &client, WavpackContext *wpc, bool can_seek)
int
bitrate
=
(
int
)(
WavpackGetInstantBitrate
(
wpc
)
/
1000
+
0.5
);
format_samples
(
bytes_per_sample
,
chunk
,
samples_got
*
audio_format
.
channels
);
format_samples
(
chunk
,
samples_got
*
audio_format
.
channels
);
cmd
=
client
.
SubmitData
(
nullptr
,
chunk
,
samples_got
*
output_sample_size
,
...
...
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