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
c75339ed
Commit
c75339ed
authored
Jan 06, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pcm/Format: change parameters/return values to ConstBuffer
parent
b0b7244b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
87 deletions
+63
-87
FormatConverter.cxx
src/pcm/FormatConverter.cxx
+19
-34
PcmFormat.cxx
src/pcm/PcmFormat.cxx
+0
-0
PcmFormat.hxx
src/pcm/PcmFormat.hxx
+13
-18
test_pcm_format.cxx
test/test_pcm_format.cxx
+21
-35
test_pcm_util.hxx
test/test_pcm_util.hxx
+10
-0
No files found.
src/pcm/FormatConverter.cxx
View file @
c75339ed
...
...
@@ -50,9 +50,6 @@ PcmFormatConverter::Close()
ConstBuffer
<
void
>
PcmFormatConverter
::
Convert
(
ConstBuffer
<
void
>
src
,
Error
&
error
)
{
const
void
*
result
=
nullptr
;
size_t
result_size
=
0
;
switch
(
dest_format
)
{
case
SampleFormat
:
:
UNDEFINED
:
assert
(
false
);
...
...
@@ -60,45 +57,33 @@ PcmFormatConverter::Convert(ConstBuffer<void> src, Error &error)
case
SampleFormat
:
:
S8
:
case
SampleFormat
:
:
DSD
:
result
=
nullptr
;
break
;
error
.
Format
(
pcm_domain
,
"PCM conversion from %s to %s is not implemented"
,
sample_format_to_string
(
src_format
),
sample_format_to_string
(
dest_format
));
return
nullptr
;
case
SampleFormat
:
:
S16
:
result
=
pcm_convert_to_16
(
buffer
,
dither
,
src_format
,
src
.
data
,
src
.
size
,
&
result_size
);
break
;
return
pcm_convert_to_16
(
buffer
,
dither
,
src_format
,
src
).
ToVoid
();
case
SampleFormat
:
:
S24_P32
:
result
=
pcm_convert_to_24
(
buffer
,
src_format
,
src
.
data
,
src
.
size
,
&
result_size
);
break
;
return
pcm_convert_to_24
(
buffer
,
src_format
,
src
).
ToVoid
();
case
SampleFormat
:
:
S32
:
result
=
pcm_convert_to_32
(
buffer
,
src_format
,
src
.
data
,
src
.
size
,
&
result_size
);
break
;
return
pcm_convert_to_32
(
buffer
,
src_format
,
src
).
ToVoid
();
case
SampleFormat
:
:
FLOAT
:
result
=
pcm_convert_to_float
(
buffer
,
src_format
,
src
.
data
,
src
.
size
,
&
result_size
);
break
;
}
if
(
result
==
nullptr
)
{
error
.
Format
(
pcm_domain
,
"PCM conversion from %s to %s is not implemented"
,
sample_format_to_string
(
src_format
),
sample_format_to_string
(
dest_format
));
return
nullptr
;
return
pcm_convert_to_float
(
buffer
,
src_format
,
src
).
ToVoid
();
}
return
{
result
,
result_size
};
assert
(
false
);
gcc_unreachable
();
}
src/pcm/PcmFormat.cxx
View file @
c75339ed
This diff is collapsed.
Click to expand it.
src/pcm/PcmFormat.hxx
View file @
c75339ed
...
...
@@ -25,6 +25,7 @@
#include <stdint.h>
#include <stddef.h>
template
<
typename
T
>
struct
ConstBuffer
;
class
PcmBuffer
;
class
PcmDither
;
...
...
@@ -36,14 +37,12 @@ class PcmDither;
* @param dither a pcm_dither object for 24-to-16 conversion
* @param bits the number of in the source buffer
* @param src the source PCM buffer
* @param src_size the size of #src in bytes
* @param dest_size_r returns the number of bytes of the destination buffer
* @return the destination buffer
*/
const
int16_t
*
gcc_pure
ConstBuffer
<
int16_t
>
pcm_convert_to_16
(
PcmBuffer
&
buffer
,
PcmDither
&
dither
,
SampleFormat
src_format
,
const
void
*
src
,
size_t
src_size
,
size_t
*
dest_size_r
);
SampleFormat
src_format
,
ConstBuffer
<
void
>
src
);
/**
* Converts PCM samples to 24 bit (32 bit alignment).
...
...
@@ -51,14 +50,12 @@ pcm_convert_to_16(PcmBuffer &buffer, PcmDither &dither,
* @param buffer a PcmBuffer object
* @param bits the number of in the source buffer
* @param src the source PCM buffer
* @param src_size the size of #src in bytes
* @param dest_size_r returns the number of bytes of the destination buffer
* @return the destination buffer
*/
const
int32_t
*
gcc_pure
ConstBuffer
<
int32_t
>
pcm_convert_to_24
(
PcmBuffer
&
buffer
,
SampleFormat
src_format
,
const
void
*
src
,
size_t
src_size
,
size_t
*
dest_size_r
);
SampleFormat
src_format
,
ConstBuffer
<
void
>
src
);
/**
* Converts PCM samples to 32 bit.
...
...
@@ -66,14 +63,12 @@ pcm_convert_to_24(PcmBuffer &buffer,
* @param buffer a PcmBuffer object
* @param bits the number of in the source buffer
* @param src the source PCM buffer
* @param src_size the size of #src in bytes
* @param dest_size_r returns the number of bytes of the destination buffer
* @return the destination buffer
*/
const
int32_t
*
gcc_pure
ConstBuffer
<
int32_t
>
pcm_convert_to_32
(
PcmBuffer
&
buffer
,
SampleFormat
src_format
,
const
void
*
src
,
size_t
src_size
,
size_t
*
dest_size_r
);
SampleFormat
src_format
,
ConstBuffer
<
void
>
src
);
/**
* Converts PCM samples to 32 bit floating point.
...
...
@@ -85,9 +80,9 @@ pcm_convert_to_32(PcmBuffer &buffer,
* @param dest_size_r returns the number of bytes of the destination buffer
* @return the destination buffer
*/
const
float
*
gcc_pure
ConstBuffer
<
float
>
pcm_convert_to_float
(
PcmBuffer
&
buffer
,
SampleFormat
src_format
,
const
void
*
src
,
size_t
src_size
,
size_t
*
dest_size_r
);
SampleFormat
src_format
,
ConstBuffer
<
void
>
src
);
#endif
test/test_pcm_format.cxx
View file @
c75339ed
...
...
@@ -29,86 +29,72 @@
void
PcmFormatTest
::
TestFormat8to16
()
{
constexpr
unsigned
N
=
256
;
constexpr
size_t
N
=
256
;
const
auto
src
=
TestDataBuffer
<
int8_t
,
N
>
();
PcmBuffer
buffer
;
size_t
d_size
;
PcmDither
dither
;
auto
d
=
pcm_convert_to_16
(
buffer
,
dither
,
SampleFormat
::
S8
,
src
,
sizeof
(
src
),
&
d_size
);
auto
d_end
=
pcm_end_pointer
(
d
,
d_size
);
CPPUNIT_ASSERT_EQUAL
(
N
,
unsigned
(
d_end
-
d
));
auto
d
=
pcm_convert_to_16
(
buffer
,
dither
,
SampleFormat
::
S8
,
src
);
CPPUNIT_ASSERT_EQUAL
(
N
,
d
.
size
);
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
CPPUNIT_ASSERT_EQUAL
(
int
(
src
[
i
]),
d
[
i
]
>>
8
);
CPPUNIT_ASSERT_EQUAL
(
int
(
src
[
i
]),
d
.
data
[
i
]
>>
8
);
}
void
PcmFormatTest
::
TestFormat16to24
()
{
constexpr
unsigned
N
=
256
;
constexpr
size_t
N
=
256
;
const
auto
src
=
TestDataBuffer
<
int16_t
,
N
>
();
PcmBuffer
buffer
;
size_t
d_size
;
auto
d
=
pcm_convert_to_24
(
buffer
,
SampleFormat
::
S16
,
src
,
sizeof
(
src
),
&
d_size
);
auto
d_end
=
pcm_end_pointer
(
d
,
d_size
);
CPPUNIT_ASSERT_EQUAL
(
N
,
unsigned
(
d_end
-
d
));
auto
d
=
pcm_convert_to_24
(
buffer
,
SampleFormat
::
S16
,
src
);
CPPUNIT_ASSERT_EQUAL
(
N
,
d
.
size
);
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
CPPUNIT_ASSERT_EQUAL
(
int
(
src
[
i
]),
d
[
i
]
>>
8
);
CPPUNIT_ASSERT_EQUAL
(
int
(
src
[
i
]),
d
.
data
[
i
]
>>
8
);
}
void
PcmFormatTest
::
TestFormat16to32
()
{
constexpr
unsigned
N
=
256
;
constexpr
size_t
N
=
256
;
const
auto
src
=
TestDataBuffer
<
int16_t
,
N
>
();
PcmBuffer
buffer
;
size_t
d_size
;
auto
d
=
pcm_convert_to_32
(
buffer
,
SampleFormat
::
S16
,
src
,
sizeof
(
src
),
&
d_size
);
auto
d_end
=
pcm_end_pointer
(
d
,
d_size
);
CPPUNIT_ASSERT_EQUAL
(
N
,
unsigned
(
d_end
-
d
));
auto
d
=
pcm_convert_to_32
(
buffer
,
SampleFormat
::
S16
,
src
);
CPPUNIT_ASSERT_EQUAL
(
N
,
d
.
size
);
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
CPPUNIT_ASSERT_EQUAL
(
int
(
src
[
i
]),
d
[
i
]
>>
16
);
CPPUNIT_ASSERT_EQUAL
(
int
(
src
[
i
]),
d
.
data
[
i
]
>>
16
);
}
void
PcmFormatTest
::
TestFormatFloat
()
{
constexpr
unsigned
N
=
256
;
constexpr
size_t
N
=
256
;
const
auto
src
=
TestDataBuffer
<
int16_t
,
N
>
();
PcmBuffer
buffer1
,
buffer2
;
size_t
f_size
;
auto
f
=
pcm_convert_to_float
(
buffer1
,
SampleFormat
::
S16
,
src
,
sizeof
(
src
),
&
f_size
);
auto
f_end
=
pcm_end_pointer
(
f
,
f_size
);
CPPUNIT_ASSERT_EQUAL
(
N
,
unsigned
(
f_end
-
f
));
auto
f
=
pcm_convert_to_float
(
buffer1
,
SampleFormat
::
S16
,
src
);
CPPUNIT_ASSERT_EQUAL
(
N
,
f
.
size
);
for
(
auto
i
=
f
;
i
!=
f_end
;
++
i
)
{
CPPUNIT_ASSERT
(
*
i
>=
-
1.
);
CPPUNIT_ASSERT
(
*
i
<=
1.
);
for
(
size_t
i
=
0
;
i
!=
f
.
size
;
++
i
)
{
CPPUNIT_ASSERT
(
f
.
data
[
i
]
>=
-
1.
);
CPPUNIT_ASSERT
(
f
.
data
[
i
]
<=
1.
);
}
PcmDither
dither
;
size_t
d_size
;
auto
d
=
pcm_convert_to_16
(
buffer2
,
dither
,
SampleFormat
::
FLOAT
,
f
,
f_size
,
&
d_size
);
auto
d_end
=
pcm_end_pointer
(
d
,
d_size
);
CPPUNIT_ASSERT_EQUAL
(
N
,
unsigned
(
d_end
-
d
));
f
.
ToVoid
());
CPPUNIT_ASSERT_EQUAL
(
N
,
d
.
size
);
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
CPPUNIT_ASSERT_EQUAL
(
src
[
i
],
d
[
i
]);
CPPUNIT_ASSERT_EQUAL
(
src
[
i
],
d
.
data
[
i
]);
}
test/test_pcm_util.hxx
View file @
c75339ed
...
...
@@ -17,6 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "util/ConstBuffer.hxx"
#include <array>
#include <random>
...
...
@@ -76,6 +78,14 @@ public:
operator
typename
std
::
array
<
T
,
N
>::
const_pointer
()
const
{
return
begin
();
}
operator
ConstBuffer
<
T
>
()
const
{
return
{
begin
(),
size
()
};
}
operator
ConstBuffer
<
void
>
()
const
{
return
{
begin
(),
size
()
*
sizeof
(
T
)
};
}
};
template
<
typename
T
>
...
...
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