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
c9d43b4d
Commit
c9d43b4d
authored
Jul 19, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
git://git.infradead.org/users/dwmw2/mpd
Conflicts: Makefile.am
parents
c5ec035f
49ede858
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
254 additions
and
81 deletions
+254
-81
Makefile.am
Makefile.am
+3
-1
audio_format.h
src/audio_format.h
+13
-1
audio_parser.c
src/audio_parser.c
+7
-3
_flac_common.c
src/decoder/_flac_common.c
+2
-3
audiofile_plugin.c
src/decoder/audiofile_plugin.c
+3
-5
faad_plugin.c
src/decoder/faad_plugin.c
+1
-5
ffmpeg_plugin.c
src/decoder/ffmpeg_plugin.c
+5
-4
mad_plugin.c
src/decoder/mad_plugin.c
+2
-8
mikmod_plugin.c
src/decoder/mikmod_plugin.c
+1
-3
modplug_plugin.c
src/decoder/modplug_plugin.c
+1
-3
mp4ff_plugin.c
src/decoder/mp4ff_plugin.c
+1
-5
mpcdec_plugin.c
src/decoder/mpcdec_plugin.c
+1
-3
sidplay_plugin.cxx
src/decoder/sidplay_plugin.cxx
+1
-3
sndfile_decoder_plugin.c
src/decoder/sndfile_decoder_plugin.c
+1
-3
vorbis_plugin.c
src/decoder/vorbis_plugin.c
+1
-2
wavpack_plugin.c
src/decoder/wavpack_plugin.c
+3
-3
convert_filter_plugin.c
src/filter/convert_filter_plugin.c
+1
-0
alsa_plugin.c
src/output/alsa_plugin.c
+50
-2
output_thread.c
src/output_thread.c
+6
-4
pcm_byteswap.c
src/pcm_byteswap.c
+71
-0
pcm_byteswap.h
src/pcm_byteswap.h
+50
-0
pcm_convert.c
src/pcm_convert.c
+19
-0
run_encoder.c
test/run_encoder.c
+3
-5
run_filter.c
test/run_filter.c
+3
-5
run_output.c
test/run_output.c
+3
-5
software_volume.c
test/software_volume.c
+2
-5
No files found.
Makefile.am
View file @
c9d43b4d
...
...
@@ -113,6 +113,7 @@ mpd_headers = \
src/pcm_convert.h
\
src/pcm_volume.h
\
src/pcm_mix.h
\
src/pcm_byteswap.h
\
src/pcm_channels.h
\
src/pcm_format.h
\
src/pcm_resample.h
\
...
...
@@ -217,6 +218,7 @@ src_mpd_SOURCES = \
src/pcm_convert.c
\
src/pcm_volume.c
\
src/pcm_mix.c
\
src/pcm_byteswap.c
\
src/pcm_channels.c
\
src/pcm_format.c
\
src/pcm_resample.c
\
...
...
@@ -708,7 +710,7 @@ test_run_filter_SOURCES = test/run_filter.c \
src/filter_plugin.c
\
src/filter_registry.c
\
src/conf.c src/tokenizer.c src/utils.c
\
src/pcm_volume.c src/pcm_convert.c
\
src/pcm_volume.c src/pcm_convert.c
src/pcm_byteswap.c
\
src/pcm_format.c src/pcm_channels.c src/pcm_dither.c
\
src/pcm_resample.c src/pcm_resample_fallback.c
\
src/audio_parser.c
\
...
...
src/audio_format.h
View file @
c9d43b4d
...
...
@@ -27,6 +27,7 @@ struct audio_format {
uint32_t
sample_rate
;
uint8_t
bits
;
uint8_t
channels
;
uint8_t
reverse_endian
;
};
static
inline
void
audio_format_clear
(
struct
audio_format
*
af
)
...
...
@@ -34,6 +35,16 @@ static inline void audio_format_clear(struct audio_format *af)
af
->
sample_rate
=
0
;
af
->
bits
=
0
;
af
->
channels
=
0
;
af
->
reverse_endian
=
0
;
}
static
inline
void
audio_format_init
(
struct
audio_format
*
af
,
uint32_t
sample_rate
,
uint8_t
bits
,
uint8_t
channels
)
{
af
->
sample_rate
=
sample_rate
;
af
->
bits
=
bits
;
af
->
channels
=
channels
;
}
static
inline
bool
audio_format_defined
(
const
struct
audio_format
*
af
)
...
...
@@ -88,7 +99,8 @@ static inline bool audio_format_equals(const struct audio_format *a,
{
return
a
->
sample_rate
==
b
->
sample_rate
&&
a
->
bits
==
b
->
bits
&&
a
->
channels
==
b
->
channels
;
a
->
channels
==
b
->
channels
&&
a
->
reverse_endian
==
b
->
reverse_endian
;
}
/**
...
...
src/audio_parser.c
View file @
c9d43b4d
...
...
@@ -41,6 +41,8 @@ audio_format_parse(struct audio_format *dest, const char *src, GError **error)
{
char
*
endptr
;
unsigned
long
value
;
uint32_t
rate
;
uint8_t
bits
,
channels
;
audio_format_clear
(
dest
);
...
...
@@ -61,7 +63,7 @@ audio_format_parse(struct audio_format *dest, const char *src, GError **error)
return
false
;
}
dest
->
sample_
rate
=
value
;
rate
=
value
;
/* parse sample format */
...
...
@@ -81,7 +83,7 @@ audio_format_parse(struct audio_format *dest, const char *src, GError **error)
return
false
;
}
dest
->
bits
=
value
;
bits
=
value
;
/* parse channel count */
...
...
@@ -93,7 +95,9 @@ audio_format_parse(struct audio_format *dest, const char *src, GError **error)
return
false
;
}
dest
->
channels
=
value
;
channels
=
value
;
audio_format_init
(
dest
,
rate
,
bits
,
channels
);
return
true
;
}
src/decoder/_flac_common.c
View file @
c9d43b4d
...
...
@@ -195,9 +195,8 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
switch
(
block
->
type
)
{
case
FLAC__METADATA_TYPE_STREAMINFO
:
data
->
audio_format
.
bits
=
(
int8_t
)
si
->
bits_per_sample
;
data
->
audio_format
.
sample_rate
=
si
->
sample_rate
;
data
->
audio_format
.
channels
=
(
int8_t
)
si
->
channels
;
audio_format_init
(
&
data
->
audio_format
,
si
->
sample_rate
,
si
->
bits_per_sample
,
si
->
channels
);
data
->
total_time
=
((
float
)
si
->
total_samples
)
/
(
si
->
sample_rate
);
break
;
case
FLAC__METADATA_TYPE_VORBIS_COMMENT
:
...
...
src/decoder/audiofile_plugin.c
View file @
c9d43b4d
...
...
@@ -136,11 +136,9 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is)
afSetVirtualSampleFormat
(
af_fp
,
AF_DEFAULT_TRACK
,
AF_SAMPFMT_TWOSCOMP
,
bits
);
afGetVirtualSampleFormat
(
af_fp
,
AF_DEFAULT_TRACK
,
&
fs
,
&
bits
);
audio_format
.
bits
=
(
uint8_t
)
bits
;
audio_format
.
sample_rate
=
(
unsigned
int
)
afGetRate
(
af_fp
,
AF_DEFAULT_TRACK
);
audio_format
.
channels
=
(
uint8_t
)
afGetVirtualChannels
(
af_fp
,
AF_DEFAULT_TRACK
);
audio_format_init
(
&
audio_format
,
afGetRate
(
af_fp
,
AF_DEFAULT_TRACK
),
bits
,
afGetVirtualChannels
(
af_fp
,
AF_DEFAULT_TRACK
));
if
(
!
audio_format_valid
(
&
audio_format
))
{
g_warning
(
"Invalid audio format: %u:%u:%u
\n
"
,
...
...
src/decoder/faad_plugin.c
View file @
c9d43b4d
...
...
@@ -262,11 +262,7 @@ faad_decoder_init(faacDecHandle decoder, struct decoder_buffer *buffer,
decoder_buffer_consume
(
buffer
,
nbytes
);
*
audio_format
=
(
struct
audio_format
){
.
bits
=
16
,
.
channels
=
channels
,
.
sample_rate
=
sample_rate
,
};
audio_format_init
(
audio_format
,
sample_rate
,
16
,
channels
);
return
true
;
}
...
...
src/decoder/ffmpeg_plugin.c
View file @
c9d43b4d
...
...
@@ -267,6 +267,7 @@ ffmpeg_decode_internal(struct ffmpeg_context *ctx)
struct
audio_format
audio_format
;
enum
decoder_command
cmd
;
int
total_time
;
uint8_t
bits
;
total_time
=
0
;
...
...
@@ -275,13 +276,13 @@ ffmpeg_decode_internal(struct ffmpeg_context *ctx)
}
#if LIBAVCODEC_VERSION_INT >= ((51<<16)+(41<<8)+0)
audio_format
.
bits
=
(
uint8_t
)
av_get_bits_per_sample_format
(
codec_context
->
sample_fmt
);
bits
=
(
uint8_t
)
av_get_bits_per_sample_format
(
codec_context
->
sample_fmt
);
#else
/* XXX fixme 16-bit for older ffmpeg (13 Aug 2007) */
audio_format
.
bits
=
(
uint8_t
)
16
;
bits
=
(
uint8_t
)
16
;
#endif
audio_format
.
sample_rate
=
(
unsigned
int
)
codec_context
->
sample_rate
;
audio_format
.
channels
=
codec_context
->
channels
;
audio_format
_init
(
&
audio_format
,
codec_context
->
sample_rate
,
bits
,
codec_context
->
channels
)
;
if
(
!
audio_format_valid
(
&
audio_format
))
{
g_warning
(
"Invalid audio format: %u:%u:%u
\n
"
,
...
...
src/decoder/mad_plugin.c
View file @
c9d43b4d
...
...
@@ -1148,13 +1148,6 @@ mp3_read(struct mp3_data *data, struct replay_gain_info **replay_gain_info_r)
return
ret
!=
DECODE_BREAK
;
}
static
void
mp3_audio_format
(
struct
mp3_data
*
data
,
struct
audio_format
*
af
)
{
af
->
bits
=
24
;
af
->
sample_rate
=
(
data
->
frame
).
header
.
samplerate
;
af
->
channels
=
MAD_NCHANNELS
(
&
(
data
->
frame
).
header
);
}
static
void
mp3_decode
(
struct
decoder
*
decoder
,
struct
input_stream
*
input_stream
)
{
...
...
@@ -1170,7 +1163,8 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream)
return
;
}
mp3_audio_format
(
&
data
,
&
audio_format
);
audio_format_init
(
&
audio_format
,
data
.
frame
.
header
.
samplerate
,
24
,
MAD_NCHANNELS
(
&
data
.
frame
.
header
));
decoder_initialized
(
decoder
,
&
audio_format
,
data
.
input_stream
->
seekable
,
data
.
total_time
);
...
...
src/decoder/mikmod_plugin.c
View file @
c9d43b4d
...
...
@@ -175,9 +175,7 @@ mod_decode(struct decoder *decoder, const char *path)
return
;
}
audio_format
.
bits
=
16
;
audio_format
.
sample_rate
=
44100
;
audio_format
.
channels
=
2
;
audio_format_init
(
&
audio_format
,
44100
,
16
,
2
);
secPerByte
=
1
.
0
/
((
audio_format
.
bits
*
audio_format
.
channels
/
8
.
0
)
*
...
...
src/decoder/modplug_plugin.c
View file @
c9d43b4d
...
...
@@ -121,9 +121,7 @@ mod_decode(struct decoder *decoder, struct input_stream *is)
return
;
}
audio_format
.
bits
=
16
;
audio_format
.
sample_rate
=
44100
;
audio_format
.
channels
=
2
;
audio_format_init
(
&
audio_format
,
44100
,
16
,
2
);
sec_perbyte
=
1
.
0
/
((
audio_format
.
bits
*
audio_format
.
channels
/
8
.
0
)
*
...
...
src/decoder/mp4ff_plugin.c
View file @
c9d43b4d
...
...
@@ -131,11 +131,7 @@ mp4_faad_new(mp4ff_t *mp4fh, int *track_r, struct audio_format *audio_format)
}
*
track_r
=
track
;
*
audio_format
=
(
struct
audio_format
){
.
bits
=
16
,
.
channels
=
channels
,
.
sample_rate
=
sample_rate
,
};
audio_format_init
(
audio_format
,
sample_rate
,
16
,
channels
);
if
(
!
audio_format_valid
(
audio_format
))
{
g_warning
(
"Invalid audio format: %u:%u:%u
\n
"
,
...
...
src/decoder/mpcdec_plugin.c
View file @
c9d43b4d
...
...
@@ -193,9 +193,7 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is)
mpc_demux_get_info
(
demux
,
&
info
);
#endif
audio_format
.
bits
=
24
;
audio_format
.
channels
=
info
.
channels
;
audio_format
.
sample_rate
=
info
.
sample_freq
;
audio_format_init
(
&
audio_format
,
info
.
sample_freq
,
24
,
info
.
channels
);
if
(
!
audio_format_valid
(
&
audio_format
))
{
#ifndef MPC_IS_OLD_API
...
...
src/decoder/sidplay_plugin.cxx
View file @
c9d43b4d
...
...
@@ -103,9 +103,7 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs)
/* initialize the MPD decoder */
struct
audio_format
audio_format
;
audio_format
.
sample_rate
=
48000
;
audio_format
.
bits
=
16
;
audio_format
.
channels
=
2
;
audio_format_init
(
&
audio_format
,
48000
,
16
,
2
);
decoder_initialized
(
decoder
,
&
audio_format
,
false
,
-
1
);
...
...
src/decoder/sndfile_decoder_plugin.c
View file @
c9d43b4d
...
...
@@ -124,12 +124,10 @@ sndfile_stream_decode(struct decoder *decoder, struct input_stream *is)
return
;
}
audio_format
.
sample_rate
=
info
.
samplerate
;
/* for now, always read 32 bit samples. Later, we could lower
MPD's CPU usage by reading 16 bit samples with
sf_readf_short() on low-quality source files. */
audio_format
.
bits
=
32
;
audio_format
.
channels
=
info
.
channels
;
audio_format_init
(
&
audio_format
,
info
.
samplerate
,
32
,
info
.
channels
);
if
(
!
audio_format_valid
(
&
audio_format
))
{
g_warning
(
"invalid audio format"
);
...
...
src/decoder/vorbis_plugin.c
View file @
c9d43b4d
...
...
@@ -324,8 +324,7 @@ vorbis_stream_decode(struct decoder *decoder,
vorbis_info
*
vi
=
ov_info
(
&
vf
,
-
1
);
struct
replay_gain_info
*
new_rgi
;
audio_format
.
channels
=
vi
->
channels
;
audio_format
.
sample_rate
=
vi
->
rate
;
audio_format_init
(
&
audio_format
,
vi
->
rate
,
16
,
vi
->
channels
);
if
(
!
audio_format_valid
(
&
audio_format
))
{
g_warning
(
"Invalid audio format: %u:%u:%u
\n
"
,
...
...
src/decoder/wavpack_plugin.c
View file @
c9d43b4d
...
...
@@ -145,9 +145,9 @@ wavpack_decode(struct decoder *decoder, WavpackContext *wpc, bool can_seek,
int
bytes_per_sample
,
output_sample_size
;
int
position
;
audio_format
.
sample_rate
=
WavpackGetSampleRate
(
wpc
);
audio_format
.
channels
=
WavpackGetReducedChannels
(
wpc
);
audio_format
.
bits
=
WavpackGetBitsPerSample
(
wpc
);
audio_format
_init
(
&
audio_format
,
WavpackGetSampleRate
(
wpc
),
WavpackGetBitsPerSample
(
wpc
),
WavpackGetReducedChannels
(
wpc
)
);
/* round bitwidth to 8-bit units */
audio_format
.
bits
=
(
audio_format
.
bits
+
7
)
&
(
~
7
);
...
...
src/filter/convert_filter_plugin.c
View file @
c9d43b4d
...
...
@@ -149,6 +149,7 @@ convert_filter_set(struct filter *_filter,
assert
(
audio_format_valid
(
&
filter
->
out_audio_format
));
assert
(
out_audio_format
!=
NULL
);
assert
(
audio_format_valid
(
out_audio_format
));
assert
(
filter
->
in_audio_format
.
reverse_endian
==
0
);
filter
->
out_audio_format
=
*
out_audio_format
;
}
src/output/alsa_plugin.c
View file @
c9d43b4d
...
...
@@ -183,6 +183,19 @@ get_bitformat(const struct audio_format *af)
return
SND_PCM_FORMAT_UNKNOWN
;
}
static
snd_pcm_format_t
byteswap_bitformat
(
snd_pcm_format_t
fmt
)
{
switch
(
fmt
)
{
case
SND_PCM_FORMAT_S16_LE
:
return
SND_PCM_FORMAT_S16_BE
;
case
SND_PCM_FORMAT_S24_LE
:
return
SND_PCM_FORMAT_S24_BE
;
case
SND_PCM_FORMAT_S32_LE
:
return
SND_PCM_FORMAT_S32_BE
;
case
SND_PCM_FORMAT_S16_BE
:
return
SND_PCM_FORMAT_S16_LE
;
case
SND_PCM_FORMAT_S24_BE
:
return
SND_PCM_FORMAT_S24_LE
;
case
SND_PCM_FORMAT_S32_BE
:
return
SND_PCM_FORMAT_S32_LE
;
default:
return
SND_PCM_FORMAT_UNKNOWN
;
}
}
/**
* Set up the snd_pcm_t object which was opened by the caller. Set up
* the configured settings and the audio format.
...
...
@@ -208,7 +221,6 @@ alsa_setup(struct alsa_data *ad, struct audio_format *audio_format,
configure_hw:
/* configure HW params */
snd_pcm_hw_params_alloca
(
&
hwparams
);
cmd
=
"snd_pcm_hw_params_any"
;
err
=
snd_pcm_hw_params_any
(
ad
->
pcm
,
hwparams
);
if
(
err
<
0
)
...
...
@@ -236,13 +248,38 @@ configure_hw:
}
err
=
snd_pcm_hw_params_set_format
(
ad
->
pcm
,
hwparams
,
bitformat
);
if
(
err
==
-
EINVAL
&&
byteswap_bitformat
(
bitformat
)
!=
SND_PCM_FORMAT_UNKNOWN
)
{
err
=
snd_pcm_hw_params_set_format
(
ad
->
pcm
,
hwparams
,
byteswap_bitformat
(
bitformat
));
if
(
err
==
0
)
{
g_debug
(
"ALSA device
\"
%s
\"
: converting %u bit to reverse-endian
\n
"
,
alsa_device
(
ad
),
audio_format
->
bits
);
audio_format
->
reverse_endian
=
1
;
}
}
if
(
err
==
-
EINVAL
&&
(
audio_format
->
bits
==
24
||
audio_format
->
bits
==
16
))
{
/* fall back to 32 bit, let pcm_convert.c do the conversion */
err
=
snd_pcm_hw_params_set_format
(
ad
->
pcm
,
hwparams
,
SND_PCM_FORMAT_S32
);
if
(
err
==
0
)
if
(
err
==
0
)
{
g_debug
(
"ALSA device
\"
%s
\"
: converting %u bit to 32 bit
\n
"
,
alsa_device
(
ad
),
audio_format
->
bits
);
audio_format
->
bits
=
32
;
}
}
if
(
err
==
-
EINVAL
&&
(
audio_format
->
bits
==
24
||
audio_format
->
bits
==
16
))
{
/* fall back to 32 bit, let pcm_convert.c do the conversion */
err
=
snd_pcm_hw_params_set_format
(
ad
->
pcm
,
hwparams
,
byteswap_bitformat
(
SND_PCM_FORMAT_S32
));
if
(
err
==
0
)
{
g_debug
(
"ALSA device
\"
%s
\"
: converting %u bit to 32 bit backward-endian
\n
"
,
alsa_device
(
ad
),
audio_format
->
bits
);
audio_format
->
bits
=
32
;
audio_format
->
reverse_endian
=
1
;
}
}
if
(
err
==
-
EINVAL
&&
audio_format
->
bits
!=
16
)
{
...
...
@@ -255,6 +292,17 @@ configure_hw:
audio_format
->
bits
=
16
;
}
}
if
(
err
==
-
EINVAL
&&
audio_format
->
bits
!=
16
)
{
/* fall back to 16 bit, let pcm_convert.c do the conversion */
err
=
snd_pcm_hw_params_set_format
(
ad
->
pcm
,
hwparams
,
byteswap_bitformat
(
SND_PCM_FORMAT_S16
));
if
(
err
==
0
)
{
g_debug
(
"ALSA device
\"
%s
\"
: converting %u bit to 16 bit backward-endian
\n
"
,
alsa_device
(
ad
),
audio_format
->
bits
);
audio_format
->
bits
=
16
;
audio_format
->
reverse_endian
=
1
;
}
}
if
(
err
<
0
)
{
g_set_error
(
error
,
alsa_output_quark
(),
err
,
...
...
src/output_thread.c
View file @
c9d43b4d
...
...
@@ -93,18 +93,20 @@ ao_open(struct audio_output *ao)
g_mutex_unlock
(
ao
->
mutex
);
g_debug
(
"opened plugin=%s name=
\"
%s
\"
"
"audio_format=%u:%u:%u"
,
"audio_format=%u:%u:%u
:%u
"
,
ao
->
plugin
->
name
,
ao
->
name
,
ao
->
out_audio_format
.
sample_rate
,
ao
->
out_audio_format
.
bits
,
ao
->
out_audio_format
.
channels
);
ao
->
out_audio_format
.
channels
,
ao
->
out_audio_format
.
reverse_endian
);
if
(
!
audio_format_equals
(
&
ao
->
in_audio_format
,
&
ao
->
out_audio_format
))
g_debug
(
"converting from %u:%u:%u"
,
g_debug
(
"converting from %u:%u:%u
:%u
"
,
ao
->
in_audio_format
.
sample_rate
,
ao
->
in_audio_format
.
bits
,
ao
->
in_audio_format
.
channels
);
ao
->
in_audio_format
.
channels
,
ao
->
in_audio_format
.
reverse_endian
);
}
static
void
...
...
src/pcm_byteswap.c
0 → 100644
View file @
c9d43b4d
/*
* Copyright (C) 2003-2009 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "pcm_byteswap.h"
#include "pcm_buffer.h"
#include <glib.h>
#include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "pcm"
static
inline
uint16_t
swab16
(
uint16_t
x
)
{
return
(
x
<<
8
)
|
(
x
>>
8
);
}
const
int16_t
*
pcm_byteswap_16
(
struct
pcm_buffer
*
buffer
,
const
int16_t
*
src
,
size_t
len
)
{
unsigned
i
;
int16_t
*
buf
=
pcm_buffer_get
(
buffer
,
len
);
if
(
!
buf
)
return
NULL
;
for
(
i
=
0
;
i
<
len
/
2
;
i
++
)
buf
[
i
]
=
swab16
(
src
[
i
]);
return
buf
;
}
static
inline
uint32_t
swab32
(
uint32_t
x
)
{
return
(
x
<<
24
)
|
((
x
&
0xff00
)
<<
8
)
|
((
x
&
0xff0000
)
>>
8
)
|
(
x
>>
24
);
}
const
int32_t
*
pcm_byteswap_32
(
struct
pcm_buffer
*
buffer
,
const
int32_t
*
src
,
size_t
len
)
{
unsigned
i
;
int32_t
*
buf
=
pcm_buffer_get
(
buffer
,
len
);
if
(
!
buf
)
return
NULL
;
for
(
i
=
0
;
i
<
len
/
4
;
i
++
)
buf
[
i
]
=
swab32
(
src
[
i
]);
return
buf
;
}
src/pcm_byteswap.h
0 → 100644
View file @
c9d43b4d
/*
* Copyright (C) 2003-2009 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_PCM_BYTESWAP_H
#define MPD_PCM_BYTESWAP_H
#include <stdint.h>
#include <stddef.h>
struct
pcm_buffer
;
/**
* Changes the endianness of 16 bit PCM data.
*
* @param buffer the destination pcm_buffer object
* @param src the source PCM buffer
* @param src_size the number of bytes in #src
* @return the destination buffer
*/
const
int16_t
*
pcm_byteswap_16
(
struct
pcm_buffer
*
buffer
,
const
int16_t
*
src
,
size_t
len
);
/**
* Changes the endianness of 32-bit (or 24-bit) PCM data.
*
* @param buffer the destination pcm_buffer object
* @param src the source PCM buffer
* @param src_size the number of bytes in #src
* @return the destination buffer
*/
const
int32_t
*
pcm_byteswap_32
(
struct
pcm_buffer
*
buffer
,
const
int32_t
*
src
,
size_t
len
);
#endif
src/pcm_convert.c
View file @
c9d43b4d
...
...
@@ -20,6 +20,7 @@
#include "pcm_convert.h"
#include "pcm_channels.h"
#include "pcm_format.h"
#include "pcm_byteswap.h"
#include "audio_format.h"
#include <assert.h>
...
...
@@ -83,6 +84,12 @@ pcm_convert_16(struct pcm_convert_state *state,
dest_format
->
sample_rate
,
&
len
);
if
(
dest_format
->
reverse_endian
)
{
buf
=
pcm_byteswap_16
(
&
state
->
format_buffer
,
buf
,
len
);
if
(
!
buf
)
g_error
(
"pcm_byteswap_16() failed"
);
}
*
dest_size_r
=
len
;
return
buf
;
}
...
...
@@ -120,6 +127,12 @@ pcm_convert_24(struct pcm_convert_state *state,
dest_format
->
sample_rate
,
&
len
);
if
(
dest_format
->
reverse_endian
)
{
buf
=
pcm_byteswap_32
(
&
state
->
format_buffer
,
buf
,
len
);
if
(
!
buf
)
g_error
(
"pcm_byteswap_32() failed"
);
}
*
dest_size_r
=
len
;
return
buf
;
}
...
...
@@ -157,6 +170,12 @@ pcm_convert_32(struct pcm_convert_state *state,
dest_format
->
sample_rate
,
&
len
);
if
(
dest_format
->
reverse_endian
)
{
buf
=
pcm_byteswap_32
(
&
state
->
format_buffer
,
buf
,
len
);
if
(
!
buf
)
g_error
(
"pcm_byteswap_32() failed"
);
}
*
dest_size_r
=
len
;
return
buf
;
}
...
...
test/run_encoder.c
View file @
c9d43b4d
...
...
@@ -41,11 +41,7 @@ encoder_to_stdout(struct encoder *encoder)
int
main
(
int
argc
,
char
**
argv
)
{
GError
*
error
=
NULL
;
struct
audio_format
audio_format
=
{
.
sample_rate
=
44100
,
.
bits
=
16
,
.
channels
=
2
,
};
struct
audio_format
audio_format
;
bool
ret
;
const
char
*
encoder_name
;
const
struct
encoder_plugin
*
plugin
;
...
...
@@ -66,6 +62,8 @@ int main(int argc, char **argv)
else
encoder_name
=
"vorbis"
;
audio_format_init
(
&
audio_format
,
44100
,
16
,
2
);
/* create the encoder */
plugin
=
encoder_plugin_get
(
encoder_name
);
...
...
test/run_filter.c
View file @
c9d43b4d
...
...
@@ -70,11 +70,7 @@ load_filter(const char *name)
int
main
(
int
argc
,
char
**
argv
)
{
struct
audio_format
audio_format
=
{
.
sample_rate
=
44100
,
.
bits
=
16
,
.
channels
=
2
,
};
struct
audio_format
audio_format
;
bool
success
;
GError
*
error
=
NULL
;
struct
filter
*
filter
;
...
...
@@ -87,6 +83,8 @@ int main(int argc, char **argv)
return
1
;
}
audio_format_init
(
&
audio_format
,
44100
,
16
,
2
);
g_thread_init
(
NULL
);
/* read configuration file (mpd.conf) */
...
...
test/run_output.c
View file @
c9d43b4d
...
...
@@ -100,11 +100,7 @@ load_audio_output(struct audio_output *ao, const char *name)
int
main
(
int
argc
,
char
**
argv
)
{
struct
audio_output
ao
;
struct
audio_format
audio_format
=
{
.
sample_rate
=
44100
,
.
bits
=
16
,
.
channels
=
2
,
};
struct
audio_format
audio_format
;
bool
success
;
GError
*
error
=
NULL
;
char
buffer
[
4096
];
...
...
@@ -116,6 +112,8 @@ int main(int argc, char **argv)
return
1
;
}
audio_format_init
(
&
audio_format
,
44100
,
16
,
2
);
g_thread_init
(
NULL
);
/* read configuration file (mpd.conf) */
...
...
test/software_volume.c
View file @
c9d43b4d
...
...
@@ -35,11 +35,7 @@
int
main
(
int
argc
,
char
**
argv
)
{
GError
*
error
=
NULL
;
struct
audio_format
audio_format
=
{
.
sample_rate
=
48000
,
.
bits
=
16
,
.
channels
=
2
,
};
struct
audio_format
audio_format
;
bool
ret
;
static
char
buffer
[
4096
];
ssize_t
nbytes
;
...
...
@@ -57,6 +53,7 @@ int main(int argc, char **argv)
return
1
;
}
}
audio_format_init
(
&
audio_format
,
48000
,
16
,
2
);
while
((
nbytes
=
read
(
0
,
buffer
,
sizeof
(
buffer
)))
>
0
)
{
pcm_volume
(
buffer
,
nbytes
,
&
audio_format
,
PCM_VOLUME_1
/
2
);
...
...
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