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
20c6159c
Commit
20c6159c
authored
Oct 09, 2011
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pcm_dither: pass an "end" pointer instead of a sample count
This is easier and more efficient to loop on, because only two variables get modified (src and dest).
parent
a47e9d1a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
21 deletions
+16
-21
pcm_dither.c
src/pcm_dither.c
+4
-6
pcm_dither.h
src/pcm_dither.h
+2
-4
pcm_format.c
src/pcm_format.c
+8
-9
test_pcm_dither.c
test/test_pcm_dither.c
+2
-2
No files found.
src/pcm_dither.c
View file @
20c6159c
...
...
@@ -72,10 +72,9 @@ pcm_dither_sample_24_to_16(int32_t sample, struct pcm_dither *dither)
void
pcm_dither_24_to_16
(
struct
pcm_dither
*
dither
,
int16_t
*
dest
,
const
int32_t
*
src
,
unsigned
num_samples
)
int16_t
*
dest
,
const
int32_t
*
src
,
const
int32_t
*
src_end
)
{
while
(
num_samples
--
>
0
)
while
(
src
<
src_end
)
*
dest
++
=
pcm_dither_sample_24_to_16
(
*
src
++
,
dither
);
}
...
...
@@ -87,9 +86,8 @@ pcm_dither_sample_32_to_16(int32_t sample, struct pcm_dither *dither)
void
pcm_dither_32_to_16
(
struct
pcm_dither
*
dither
,
int16_t
*
dest
,
const
int32_t
*
src
,
unsigned
num_samples
)
int16_t
*
dest
,
const
int32_t
*
src
,
const
int32_t
*
src_end
)
{
while
(
num_samples
--
>
0
)
while
(
src
<
src_end
)
*
dest
++
=
pcm_dither_sample_32_to_16
(
*
src
++
,
dither
);
}
src/pcm_dither.h
View file @
20c6159c
...
...
@@ -36,12 +36,10 @@ pcm_dither_24_init(struct pcm_dither *dither)
void
pcm_dither_24_to_16
(
struct
pcm_dither
*
dither
,
int16_t
*
dest
,
const
int32_t
*
src
,
unsigned
num_samples
);
int16_t
*
dest
,
const
int32_t
*
src
,
const
int32_t
*
src_end
);
void
pcm_dither_32_to_16
(
struct
pcm_dither
*
dither
,
int16_t
*
dest
,
const
int32_t
*
src
,
unsigned
num_samples
);
int16_t
*
dest
,
const
int32_t
*
src
,
const
int32_t
*
src_end
);
#endif
src/pcm_format.c
View file @
20c6159c
...
...
@@ -35,18 +35,16 @@ pcm_convert_8_to_16(int16_t *out, const int8_t *in,
static
void
pcm_convert_24_to_16
(
struct
pcm_dither
*
dither
,
int16_t
*
out
,
const
int32_t
*
in
,
unsigned
num_samples
)
int16_t
*
out
,
const
int32_t
*
in
,
const
int32_t
*
in_end
)
{
pcm_dither_24_to_16
(
dither
,
out
,
in
,
num_samples
);
pcm_dither_24_to_16
(
dither
,
out
,
in
,
in_end
);
}
static
void
pcm_convert_32_to_16
(
struct
pcm_dither
*
dither
,
int16_t
*
out
,
const
int32_t
*
in
,
unsigned
num_samples
)
int16_t
*
out
,
const
int32_t
*
in
,
const
int32_t
*
in_end
)
{
pcm_dither_32_to_16
(
dither
,
out
,
in
,
num_samples
);
pcm_dither_32_to_16
(
dither
,
out
,
in
,
in_end
);
}
static
int32_t
*
...
...
@@ -63,6 +61,7 @@ pcm_convert_to_16(struct pcm_buffer *buffer, struct pcm_dither *dither,
enum
sample_format
src_format
,
const
void
*
src
,
size_t
src_size
,
size_t
*
dest_size_r
)
{
const
void
*
src_end
=
(
const
char
*
)
src
+
src_size
;
unsigned
num_samples
;
int16_t
*
dest
;
int32_t
*
dest32
;
...
...
@@ -95,7 +94,7 @@ pcm_convert_to_16(struct pcm_buffer *buffer, struct pcm_dither *dither,
/* convert to 16 bit in-place */
*
dest_size_r
=
num_samples
*
sizeof
(
*
dest
);
pcm_convert_24_to_16
(
dither
,
dest
,
dest32
,
num_samples
);
dest32
+
num_samples
);
return
dest
;
case
SAMPLE_FORMAT_S24_P32
:
...
...
@@ -105,7 +104,7 @@ pcm_convert_to_16(struct pcm_buffer *buffer, struct pcm_dither *dither,
pcm_convert_24_to_16
(
dither
,
dest
,
(
const
int32_t
*
)
src
,
num_samples
);
(
const
int32_t
*
)
src_end
);
return
dest
;
case
SAMPLE_FORMAT_S32
:
...
...
@@ -115,7 +114,7 @@ pcm_convert_to_16(struct pcm_buffer *buffer, struct pcm_dither *dither,
pcm_convert_32_to_16
(
dither
,
dest
,
(
const
int32_t
*
)
src
,
num_samples
);
(
const
int32_t
*
)
src_end
);
return
dest
;
}
...
...
test/test_pcm_dither.c
View file @
20c6159c
...
...
@@ -48,7 +48,7 @@ test_pcm_dither_24(void)
int16_t
dest
[
N
];
pcm_dither_24_to_16
(
&
dither
,
dest
,
src
,
N
);
pcm_dither_24_to_16
(
&
dither
,
dest
,
src
,
src
+
N
);
for
(
unsigned
i
=
0
;
i
<
N
;
++
i
)
{
g_assert_cmpint
(
dest
[
i
],
>=
,
(
src
[
i
]
>>
8
)
-
8
);
...
...
@@ -70,7 +70,7 @@ test_pcm_dither_32(void)
int16_t
dest
[
N
];
pcm_dither_32_to_16
(
&
dither
,
dest
,
src
,
N
);
pcm_dither_32_to_16
(
&
dither
,
dest
,
src
,
src
+
N
);
for
(
unsigned
i
=
0
;
i
<
N
;
++
i
)
{
g_assert_cmpint
(
dest
[
i
],
>=
,
(
src
[
i
]
>>
16
)
-
8
);
...
...
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