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
361404fd
Commit
361404fd
authored
Jan 30, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pcm_convert: convert to C++
parent
762c91b7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
174 additions
and
170 deletions
+174
-170
Makefile.am
Makefile.am
+1
-1
DecoderAPI.cxx
src/DecoderAPI.cxx
+5
-4
DecoderInternal.cxx
src/DecoderInternal.cxx
+0
-2
DecoderInternal.hxx
src/DecoderInternal.hxx
+2
-3
PcmConvert.cxx
src/PcmConvert.cxx
+84
-86
PcmConvert.hxx
src/PcmConvert.hxx
+60
-46
ConvertFilterPlugin.cxx
src/filter/ConvertFilterPlugin.cxx
+9
-8
run_convert.cxx
test/run_convert.cxx
+5
-6
run_output.cxx
test/run_output.cxx
+8
-14
No files found.
Makefile.am
View file @
361404fd
...
...
@@ -331,7 +331,7 @@ libevent_a_SOURCES = \
libpcm_a_SOURCES
=
\
src/pcm_buffer.c src/pcm_buffer.h
\
src/pcm_export.c src/pcm_export.h
\
src/
pcm_convert.c src/pcm_convert.h
\
src/
PcmConvert.cxx src/PcmConvert.hxx
\
src/dsd2pcm/dsd2pcm.c src/dsd2pcm/dsd2pcm.h
\
src/pcm_dsd.c src/pcm_dsd.h
\
src/pcm_dsd_usb.c src/pcm_dsd_usb.h
\
...
...
src/DecoderAPI.cxx
View file @
361404fd
...
...
@@ -402,10 +402,11 @@ decoder_data(struct decoder *decoder,
}
if
(
!
audio_format_equals
(
&
dc
->
in_audio_format
,
&
dc
->
out_audio_format
))
{
data
=
pcm_convert
(
&
decoder
->
conv_state
,
&
dc
->
in_audio_format
,
data
,
length
,
&
dc
->
out_audio_format
,
&
length
,
&
error
);
data
=
decoder
->
conv_state
.
Convert
(
&
dc
->
in_audio_format
,
data
,
length
,
&
dc
->
out_audio_format
,
&
length
,
&
error
);
if
(
data
==
NULL
)
{
/* the PCM conversion has failed - stop
playback, since we have no better way to
...
...
src/DecoderInternal.cxx
View file @
361404fd
...
...
@@ -40,8 +40,6 @@ decoder::~decoder()
if
(
decoder_tag
!=
nullptr
)
tag_free
(
decoder_tag
);
pcm_convert_deinit
(
&
conv_state
);
}
/**
...
...
src/DecoderInternal.hxx
View file @
361404fd
...
...
@@ -21,7 +21,7 @@
#define MPD_DECODER_INTERNAL_HXX
#include "decoder_command.h"
#include "
pcm_convert.h
"
#include "
PcmConvert.hxx
"
#include "replay_gain_info.h"
struct
input_stream
;
...
...
@@ -29,7 +29,7 @@ struct input_stream;
struct
decoder
{
struct
decoder_control
*
dc
;
struct
pcm_convert_state
conv_state
;
PcmConvert
conv_state
;
/**
* The time stamp of the next data chunk, in seconds.
...
...
@@ -91,7 +91,6 @@ struct decoder {
song_tag
(
_tag
),
stream_tag
(
nullptr
),
decoder_tag
(
nullptr
),
chunk
(
nullptr
),
replay_gain_serial
(
0
)
{
pcm_convert_init
(
&
conv_state
);
}
~
decoder
();
...
...
src/
pcm_convert.c
→
src/
PcmConvert.cxx
View file @
361404fd
This diff is collapsed.
Click to expand it.
src/
pcm_convert.h
→
src/
PcmConvert.hxx
View file @
361404fd
...
...
@@ -17,13 +17,15 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef PCM_CONVERT_H
#define PCM_CONVERT_H
#ifndef PCM_CONVERT_H
XX
#define PCM_CONVERT_H
XX
extern
"C"
{
#include "pcm_dsd.h"
#include "pcm_resample.h"
#include "pcm_dither.h"
#include "pcm_buffer.h"
}
#include <glib.h>
...
...
@@ -34,7 +36,7 @@ struct audio_format;
* holds buffer allocations and the state for all kinds of PCM
* conversions.
*/
struct
pcm_convert_state
{
class
PcmConvert
{
struct
pcm_dsd
dsd
;
struct
pcm_resample_state
resample
;
...
...
@@ -46,6 +48,61 @@ struct pcm_convert_state {
/** the buffer for converting the channel count */
struct
pcm_buffer
channels_buffer
;
public
:
PcmConvert
();
~
PcmConvert
();
/**
* Reset the pcm_convert_state object. Use this at the
* boundary between two distinct songs and each time the
* format changes.
*/
void
Reset
();
/**
* Converts PCM data between two audio formats.
*
* @param src_format the source audio format
* @param src the source PCM buffer
* @param src_size the size of #src in bytes
* @param dest_format the requested destination audio format
* @param dest_size_r returns the number of bytes of the destination buffer
* @param error_r location to store the error occurring, or NULL to
* ignore errors
* @return the destination buffer, or NULL on error
*/
const
void
*
Convert
(
const
audio_format
*
src_format
,
const
void
*
src
,
size_t
src_size
,
const
audio_format
*
dest_format
,
size_t
*
dest_size_r
,
GError
**
error_r
);
private
:
const
int16_t
*
Convert16
(
const
audio_format
*
src_format
,
const
void
*
src_buffer
,
size_t
src_size
,
const
audio_format
*
dest_format
,
size_t
*
dest_size_r
,
GError
**
error_r
);
const
int32_t
*
Convert24
(
const
audio_format
*
src_format
,
const
void
*
src_buffer
,
size_t
src_size
,
const
audio_format
*
dest_format
,
size_t
*
dest_size_r
,
GError
**
error_r
);
const
int32_t
*
Convert32
(
const
audio_format
*
src_format
,
const
void
*
src_buffer
,
size_t
src_size
,
const
audio_format
*
dest_format
,
size_t
*
dest_size_r
,
GError
**
error_r
);
const
float
*
ConvertFloat
(
const
audio_format
*
src_format
,
const
void
*
src_buffer
,
size_t
src_size
,
const
audio_format
*
dest_format
,
size_t
*
dest_size_r
,
GError
**
error_r
);
};
static
inline
GQuark
...
...
@@ -54,47 +111,4 @@ pcm_convert_quark(void)
return
g_quark_from_static_string
(
"pcm_convert"
);
}
G_BEGIN_DECLS
/**
* Initializes a pcm_convert_state object.
*/
void
pcm_convert_init
(
struct
pcm_convert_state
*
state
);
/**
* Deinitializes a pcm_convert_state object and frees allocated
* memory.
*/
void
pcm_convert_deinit
(
struct
pcm_convert_state
*
state
);
/**
* Reset the pcm_convert_state object. Use this at the boundary
* between two distinct songs and each time the format changes.
*/
void
pcm_convert_reset
(
struct
pcm_convert_state
*
state
);
/**
* Converts PCM data between two audio formats.
*
* @param state an initialized pcm_convert_state object
* @param src_format the source audio format
* @param src the source PCM buffer
* @param src_size the size of #src in bytes
* @param dest_format the requested destination audio format
* @param dest_size_r returns the number of bytes of the destination buffer
* @param error_r location to store the error occurring, or NULL to
* ignore errors
* @return the destination buffer, or NULL on error
*/
const
void
*
pcm_convert
(
struct
pcm_convert_state
*
state
,
const
struct
audio_format
*
src_format
,
const
void
*
src
,
size_t
src_size
,
const
struct
audio_format
*
dest_format
,
size_t
*
dest_size_r
,
GError
**
error_r
);
G_END_DECLS
#endif
src/filter/ConvertFilterPlugin.cxx
View file @
361404fd
...
...
@@ -23,7 +23,8 @@
#include "filter_internal.h"
#include "filter_registry.h"
#include "conf.h"
#include "pcm_convert.h"
#include "PcmConvert.hxx"
#include "util/Manual.hxx"
#include "audio_format.h"
#include "poison.h"
...
...
@@ -51,7 +52,7 @@ struct ConvertFilter {
*/
struct
audio_format
out_audio_format
;
struct
pcm_convert_state
state
;
Manual
<
PcmConvert
>
state
;
ConvertFilter
()
{
filter_init
(
&
base
,
&
convert_filter_plugin
);
...
...
@@ -81,7 +82,7 @@ convert_filter_open(struct filter *_filter, struct audio_format *audio_format,
assert
(
audio_format_valid
(
audio_format
));
filter
->
in_audio_format
=
filter
->
out_audio_format
=
*
audio_format
;
pcm_convert_init
(
&
filter
->
state
);
filter
->
state
.
Construct
(
);
return
&
filter
->
in_audio_format
;
}
...
...
@@ -91,7 +92,7 @@ convert_filter_close(struct filter *_filter)
{
ConvertFilter
*
filter
=
(
ConvertFilter
*
)
_filter
;
pcm_convert_deinit
(
&
filter
->
state
);
filter
->
state
.
Destruct
(
);
poison_undefined
(
&
filter
->
in_audio_format
,
sizeof
(
filter
->
in_audio_format
));
...
...
@@ -113,10 +114,10 @@ convert_filter_filter(struct filter *_filter, const void *src, size_t src_size,
return
src
;
}
dest
=
pcm_convert
(
&
filter
->
state
,
&
filter
->
in_audio_format
,
src
,
src_size
,
&
filter
->
out_audio_format
,
dest_size_r
,
error_r
);
dest
=
filter
->
state
->
Convert
(
&
filter
->
in_audio_format
,
src
,
src_size
,
&
filter
->
out_audio_format
,
dest_size_r
,
error_r
);
if
(
dest
==
NULL
)
return
NULL
;
...
...
test/run_convert.cxx
View file @
361404fd
...
...
@@ -26,7 +26,7 @@
#include "config.h"
#include "AudioParser.hxx"
#include "audio_format.h"
#include "
pcm_convert.h
"
#include "
PcmConvert.hxx
"
#include "conf.h"
#include "util/fifo_buffer.h"
#include "stdbin.h"
...
...
@@ -58,7 +58,6 @@ int main(int argc, char **argv)
{
GError
*
error
=
NULL
;
struct
audio_format
in_audio_format
,
out_audio_format
;
struct
pcm_convert_state
state
;
const
void
*
output
;
ssize_t
nbytes
;
size_t
length
;
...
...
@@ -90,7 +89,7 @@ int main(int argc, char **argv)
const
size_t
in_frame_size
=
audio_format_frame_size
(
&
in_audio_format
);
pcm_convert_init
(
&
state
)
;
PcmConvert
state
;
struct
fifo_buffer
*
buffer
=
fifo_buffer_new
(
4096
);
...
...
@@ -113,8 +112,8 @@ int main(int argc, char **argv)
fifo_buffer_consume
(
buffer
,
length
);
output
=
pcm_convert
(
&
state
,
&
in_audio_format
,
src
,
length
,
&
out_audio_format
,
&
length
,
&
error
);
output
=
state
.
Convert
(
&
in_audio_format
,
src
,
length
,
&
out_audio_format
,
&
length
,
&
error
);
if
(
output
==
NULL
)
{
g_printerr
(
"Failed to convert: %s
\n
"
,
error
->
message
);
return
2
;
...
...
@@ -123,5 +122,5 @@ int main(int argc, char **argv)
G_GNUC_UNUSED
ssize_t
ignored
=
write
(
1
,
output
,
length
);
}
pcm_convert_deinit
(
&
state
)
;
return
EXIT_SUCCESS
;
}
test/run_output.cxx
View file @
361404fd
...
...
@@ -27,12 +27,12 @@
#include "IOThread.hxx"
#include "fs/Path.hxx"
#include "AudioParser.hxx"
#include "PcmConvert.hxx"
extern
"C"
{
#include "output_plugin.h"
#include "output_internal.h"
#include "filter_registry.h"
#include "pcm_convert.h"
}
#include "PlayerControl.hxx"
...
...
@@ -52,21 +52,15 @@ GlobalEvents::Emit(gcc_unused Event event)
{
}
void
pcm_convert_init
(
G_GNUC_UNUSED
struct
pcm_convert_state
*
state
)
{
}
void
pcm_convert_deinit
(
G_GNUC_UNUSED
struct
pcm_convert_state
*
state
)
{
}
PcmConvert
::
PcmConvert
()
{}
PcmConvert
::~
PcmConvert
()
{}
const
void
*
pcm_convert
(
G_GNUC_UNUSED
struct
pcm_convert_state
*
state
,
G_GNUC_UNUSED
const
struct
audio_format
*
src_format
,
G_GNUC_UNUSED
const
void
*
src
,
G_GNUC_UNUSED
size_t
src_size
,
G_GNUC_UNUSED
const
struct
audio_format
*
dest_format
,
G_GNUC_UNUSED
size_t
*
dest_size_r
,
GError
**
error_r
)
PcmConvert
::
Convert
(
gcc_unused
const
audio_format
*
src_format
,
gcc_unused
const
void
*
src
,
gcc_unused
size_t
src_size
,
gcc_unused
const
audio_format
*
dest_format
,
gcc_unused
size_t
*
dest_size_r
,
gcc_unused
GError
**
error_r
)
{
g_set_error
(
error_r
,
pcm_convert_quark
(),
0
,
"Not implemented"
);
...
...
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