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
ca6e613a
Commit
ca6e613a
authored
Oct 21, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pcm_utils: no CamelCase
Renamed all functions which were still in CamelCase.
parent
fb416964
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
88 deletions
+89
-88
decoder_api.c
src/decoder_api.c
+5
-5
output_thread.c
src/output_thread.c
+8
-8
pcm_utils.c
src/pcm_utils.c
+63
-64
pcm_utils.h
src/pcm_utils.h
+11
-9
player_thread.c
src/player_thread.c
+2
-2
No files found.
src/decoder_api.c
View file @
ca6e613a
...
...
@@ -171,8 +171,8 @@ decoder_data(struct decoder *decoder,
data
=
dataIn
;
datalen
=
dataInLen
;
}
else
{
datalen
=
pcm_
sizeOfConvBuffer
(
&
(
dc
.
audioFormat
),
dataInLen
,
&
(
ob
.
audioFormat
));
datalen
=
pcm_
convert_size
(
&
(
dc
.
audioFormat
),
dataInLen
,
&
(
ob
.
audioFormat
));
if
(
datalen
>
convBufferLen
)
{
if
(
convBuffer
!=
NULL
)
free
(
convBuffer
);
...
...
@@ -180,9 +180,9 @@ decoder_data(struct decoder *decoder,
convBufferLen
=
datalen
;
}
data
=
convBuffer
;
datalen
=
pcm_convert
AudioFormat
(
&
(
dc
.
audioFormat
),
dataIn
,
dataInLen
,
&
(
ob
.
audioFormat
),
data
,
&
decoder
->
conv_state
);
datalen
=
pcm_convert
(
&
(
dc
.
audioFormat
),
dataIn
,
dataInLen
,
&
(
ob
.
audioFormat
),
data
,
&
decoder
->
conv_state
);
}
if
(
replayGainInfo
!=
NULL
&&
(
replayGainState
!=
REPLAYGAIN_OFF
))
...
...
src/output_thread.c
View file @
ca6e613a
...
...
@@ -33,9 +33,9 @@ static void ao_command_finished(struct audio_output *ao)
static
void
convertAudioFormat
(
struct
audio_output
*
audioOutput
,
const
char
**
chunkArgPtr
,
size_t
*
sizeArgPtr
)
{
size_t
size
=
pcm_
sizeOfConvBuffer
(
&
(
audioOutput
->
inAudioFormat
),
*
sizeArgPtr
,
&
(
audioOutput
->
outAudioFormat
));
size_t
size
=
pcm_
convert_size
(
&
(
audioOutput
->
inAudioFormat
),
*
sizeArgPtr
,
&
(
audioOutput
->
outAudioFormat
));
if
(
size
>
audioOutput
->
convBufferLen
)
{
if
(
audioOutput
->
convBuffer
!=
NULL
)
...
...
@@ -44,11 +44,11 @@ static void convertAudioFormat(struct audio_output *audioOutput,
audioOutput
->
convBufferLen
=
size
;
}
*
sizeArgPtr
=
pcm_convert
AudioFormat
(
&
(
audioOutput
->
inAudioFormat
),
*
chunkArgPtr
,
*
sizeArgPtr
,
&
(
audioOutput
->
outAudioFormat
),
audioOutput
->
convBuffer
,
&
audioOutput
->
convState
);
*
sizeArgPtr
=
pcm_convert
(
&
(
audioOutput
->
inAudioFormat
),
*
chunkArgPtr
,
*
sizeArgPtr
,
&
(
audioOutput
->
outAudioFormat
),
audioOutput
->
convBuffer
,
&
audioOutput
->
convState
);
*
chunkArgPtr
=
audioOutput
->
convBuffer
;
}
...
...
src/pcm_utils.c
View file @
ca6e613a
...
...
@@ -85,9 +85,9 @@ pcm_volume_change_24(int32_t *buffer, unsigned num_samples, int volume)
}
}
void
pcm_volume
Change
(
char
*
buffer
,
int
bufferSize
,
const
struct
audio_format
*
format
,
int
volume
)
void
pcm_volume
(
char
*
buffer
,
int
bufferSize
,
const
struct
audio_format
*
format
,
int
volume
)
{
if
(
volume
>=
1000
)
return
;
...
...
@@ -113,7 +113,7 @@ void pcm_volumeChange(char *buffer, int bufferSize,
break
;
default:
FATAL
(
"%u bits not supported by pcm_volume
Change
!
\n
"
,
FATAL
(
"%u bits not supported by pcm_volume!
\n
"
,
format
->
bits
);
}
}
...
...
@@ -206,7 +206,7 @@ void pcm_mix(char *buffer1, const char *buffer2, size_t size,
}
#ifdef HAVE_LIBSAMPLERATE
static
int
pcm_
getSampleRateC
onverter
(
void
)
static
int
pcm_
resample_get_c
onverter
(
void
)
{
const
char
*
conf
=
getConfigParamValue
(
CONF_SAMPLERATE_CONVERTER
);
long
convalgo
;
...
...
@@ -244,11 +244,11 @@ out:
#endif
#ifdef HAVE_LIBSAMPLERATE
static
size_t
pcm_
convertSampleRat
e
(
int8_t
channels
,
uint32_t
inSampleRate
,
const
int16_t
*
inBuffer
,
size_t
inS
ize
,
uint32_t
outSampleRate
,
int16_t
*
outBuffer
,
size_t
outSize
,
struct
pcm_convert_state
*
convState
)
static
size_t
pcm_
resampl
e
(
int8_t
channels
,
uint32_t
inSampleRate
,
const
int16_t
*
src
,
size_t
src_s
ize
,
uint32_t
outSampleRate
,
int16_t
*
outBuffer
,
size_t
outSize
,
struct
pcm_convert_state
*
convState
)
{
static
int
convalgo
=
-
1
;
SRC_DATA
*
data
=
&
convState
->
data
;
...
...
@@ -257,7 +257,7 @@ static size_t pcm_convertSampleRate(int8_t channels, uint32_t inSampleRate,
int
error
;
if
(
convalgo
<
0
)
convalgo
=
pcm_
getSampleRateC
onverter
();
convalgo
=
pcm_
resample_get_c
onverter
();
/* (re)set the state/ratio if the in or out format changed */
if
((
channels
!=
convState
->
lastChannels
)
||
...
...
@@ -289,7 +289,7 @@ static size_t pcm_convertSampleRate(int8_t channels, uint32_t inSampleRate,
if
(
convState
->
error
)
return
0
;
data
->
input_frames
=
inS
ize
/
2
/
channels
;
data
->
input_frames
=
src_s
ize
/
2
/
channels
;
dataInSize
=
data
->
input_frames
*
sizeof
(
float
)
*
channels
;
if
(
dataInSize
>
convState
->
dataInSize
)
{
convState
->
dataInSize
=
dataInSize
;
...
...
@@ -303,7 +303,7 @@ static size_t pcm_convertSampleRate(int8_t channels, uint32_t inSampleRate,
data
->
data_out
=
xrealloc
(
data
->
data_out
,
dataOutSize
);
}
src_short_to_float_array
((
const
short
*
)
inBuffer
,
data
->
data_in
,
src_short_to_float_array
((
const
short
*
)
src
,
data
->
data_in
,
data
->
input_frames
*
channels
);
error
=
src_process
(
convState
->
state
,
data
);
...
...
@@ -321,16 +321,15 @@ static size_t pcm_convertSampleRate(int8_t channels, uint32_t inSampleRate,
}
#else
/* !HAVE_LIBSAMPLERATE */
/* resampling code blatantly ripped from ESD */
static
size_t
pcm_convertSampleRate
(
int8_t
channels
,
uint32_t
inSampleRate
,
const
int16_t
*
inBuffer
,
mpd_unused
size_t
inSize
,
uint32_t
outSampleRate
,
char
*
outBuffer
,
size_t
outSize
,
mpd_unused
struct
pcm_convert_state
*
convState
)
static
size_t
pcm_resample
(
int8_t
channels
,
uint32_t
inSampleRate
,
const
int16_t
*
src
,
mpd_unused
size_t
src_size
,
uint32_t
outSampleRate
,
char
*
outBuffer
,
size_t
outSize
,
mpd_unused
struct
pcm_convert_state
*
convState
)
{
uint32_t
rd_dat
=
0
;
uint32_t
wr_dat
=
0
;
const
int16_t
*
in
=
(
const
int16_t
*
)
inBuffer
;
const
int16_t
*
in
=
(
const
int16_t
*
)
src
;
int16_t
*
out
=
(
int16_t
*
)
outBuffer
;
uint32_t
nlen
=
outSize
/
2
;
int16_t
lsample
,
rsample
;
...
...
@@ -410,9 +409,9 @@ pcm_convert_channels_n_to_2(int16_t *dest,
}
static
const
int16_t
*
pcm_convert
C
hannels
(
int8_t
dest_channels
,
int8_t
src_channels
,
const
int16_t
*
src
,
size_t
src_size
,
size_t
*
dest_size_r
)
pcm_convert
_c
hannels
(
int8_t
dest_channels
,
int8_t
src_channels
,
const
int16_t
*
src
,
size_t
src_size
,
size_t
*
dest_size_r
)
{
static
int16_t
*
buf
;
static
size_t
len
;
...
...
@@ -463,8 +462,8 @@ pcm_convert_24_to_16(int16_t *out, const int32_t *in,
}
static
const
int16_t
*
pcm_convert
To16bit
(
uint8_t
bits
,
const
void
*
inBuffer
,
size_t
inSize
,
size_t
*
outSize
)
pcm_convert
_to_16
(
uint8_t
bits
,
const
void
*
src
,
size_t
src_size
,
size_t
*
dest_size_r
)
{
static
int16_t
*
buf
;
static
size_t
len
;
...
...
@@ -472,32 +471,32 @@ pcm_convertTo16bit(uint8_t bits, const void *inBuffer,
switch
(
bits
)
{
case
8
:
num_samples
=
inS
ize
;
*
outSize
=
inS
ize
<<
1
;
if
(
*
outSize
>
len
)
{
len
=
*
outSize
;
num_samples
=
src_s
ize
;
*
dest_size_r
=
src_s
ize
<<
1
;
if
(
*
dest_size_r
>
len
)
{
len
=
*
dest_size_r
;
buf
=
xrealloc
(
buf
,
len
);
}
pcm_convert_8_to_16
((
int16_t
*
)
buf
,
(
const
int8_t
*
)
inBuffer
,
(
const
int8_t
*
)
src
,
num_samples
);
return
buf
;
case
16
:
*
outSize
=
inS
ize
;
return
inBuffer
;
*
dest_size_r
=
src_s
ize
;
return
src
;
case
24
:
num_samples
=
inS
ize
/
4
;
*
outSize
=
num_samples
*
2
;
if
(
*
outSize
>
len
)
{
len
=
*
outSize
;
num_samples
=
src_s
ize
/
4
;
*
dest_size_r
=
num_samples
*
2
;
if
(
*
dest_size_r
>
len
)
{
len
=
*
dest_size_r
;
buf
=
xrealloc
(
buf
,
len
);
}
pcm_convert_24_to_16
((
int16_t
*
)
buf
,
(
const
int32_t
*
)
inBuffer
,
(
const
int32_t
*
)
src
,
num_samples
);
return
buf
;
}
...
...
@@ -507,40 +506,40 @@ pcm_convertTo16bit(uint8_t bits, const void *inBuffer,
}
/* outFormat bits must be 16 and channels must be 1 or 2! */
size_t
pcm_convert
AudioFormat
(
const
struct
audio_format
*
inFormat
,
const
char
*
inBuffer
,
size_t
inS
ize
,
const
struct
audio_format
*
outFormat
,
char
*
outBuffer
,
struct
pcm_convert_state
*
convState
)
size_t
pcm_convert
(
const
struct
audio_format
*
inFormat
,
const
char
*
src
,
size_t
src_s
ize
,
const
struct
audio_format
*
outFormat
,
char
*
outBuffer
,
struct
pcm_convert_state
*
convState
)
{
const
int16_t
*
buf
;
size_t
len
=
0
;
size_t
outSize
=
pcm_sizeOfConvBuffer
(
inFormat
,
inS
ize
,
outFormat
);
size_t
dest_size
=
pcm_convert_size
(
inFormat
,
src_s
ize
,
outFormat
);
assert
(
outFormat
->
bits
==
16
);
/* everything else supports 16 bit only, so convert to that first */
buf
=
pcm_convert
To16bit
(
inFormat
->
bits
,
inBuffer
,
inS
ize
,
&
len
);
buf
=
pcm_convert
_to_16
(
inFormat
->
bits
,
src
,
src_s
ize
,
&
len
);
if
(
!
buf
)
exit
(
EXIT_FAILURE
);
if
(
inFormat
->
channels
!=
outFormat
->
channels
)
{
buf
=
pcm_convert
C
hannels
(
outFormat
->
channels
,
inFormat
->
channels
,
buf
,
len
,
&
len
);
buf
=
pcm_convert
_c
hannels
(
outFormat
->
channels
,
inFormat
->
channels
,
buf
,
len
,
&
len
);
if
(
!
buf
)
exit
(
EXIT_FAILURE
);
}
if
(
inFormat
->
sample_rate
==
outFormat
->
sample_rate
)
{
assert
(
outS
ize
>=
len
);
assert
(
dest_s
ize
>=
len
);
memcpy
(
outBuffer
,
buf
,
len
);
}
else
{
len
=
pcm_
convertSampleRat
e
(
outFormat
->
channels
,
inFormat
->
sample_rate
,
buf
,
len
,
outFormat
->
sample_rate
,
(
int16_t
*
)
outBuffer
,
outS
ize
,
convState
);
len
=
pcm_
resampl
e
(
outFormat
->
channels
,
inFormat
->
sample_rate
,
buf
,
len
,
outFormat
->
sample_rate
,
(
int16_t
*
)
outBuffer
,
dest_s
ize
,
convState
);
if
(
len
==
0
)
exit
(
EXIT_FAILURE
);
}
...
...
@@ -548,35 +547,35 @@ size_t pcm_convertAudioFormat(const struct audio_format *inFormat,
return
len
;
}
size_t
pcm_
sizeOfConvBuffer
(
const
struct
audio_format
*
inFormat
,
size_t
inS
ize
,
const
struct
audio_format
*
outFormat
)
size_t
pcm_
convert_size
(
const
struct
audio_format
*
inFormat
,
size_t
src_s
ize
,
const
struct
audio_format
*
outFormat
)
{
const
double
ratio
=
(
double
)
outFormat
->
sample_rate
/
(
double
)
inFormat
->
sample_rate
;
const
int
shift
=
2
*
outFormat
->
channels
;
size_t
outSize
=
inS
ize
;
size_t
dest_size
=
src_s
ize
;
switch
(
inFormat
->
bits
)
{
case
8
:
outS
ize
<<=
1
;
dest_s
ize
<<=
1
;
break
;
case
16
:
break
;
case
24
:
outSize
=
(
outS
ize
/
4
)
*
2
;
dest_size
=
(
dest_s
ize
/
4
)
*
2
;
break
;
default:
FATAL
(
"only 8 or 16 bits are supported for conversion!
\n
"
);
}
if
(
inFormat
->
channels
!=
outFormat
->
channels
)
{
outS
ize
/=
inFormat
->
channels
;
outS
ize
*=
outFormat
->
channels
;
dest_s
ize
/=
inFormat
->
channels
;
dest_s
ize
*=
outFormat
->
channels
;
}
outS
ize
/=
shift
;
outSize
=
floor
(
0
.
5
+
(
double
)
outS
ize
*
ratio
);
outS
ize
*=
shift
;
dest_s
ize
/=
shift
;
dest_size
=
floor
(
0
.
5
+
(
double
)
dest_s
ize
*
ratio
);
dest_s
ize
*=
shift
;
return
outS
ize
;
return
dest_s
ize
;
}
src/pcm_utils.h
View file @
ca6e613a
...
...
@@ -44,18 +44,20 @@ struct pcm_convert_state {
int
error
;
};
void
pcm_volumeChange
(
char
*
buffer
,
int
bufferSize
,
const
struct
audio_format
*
format
,
int
volume
);
void
pcm_volume
(
char
*
buffer
,
int
bufferSize
,
const
struct
audio_format
*
format
,
int
volume
);
void
pcm_mix
(
char
*
buffer1
,
const
char
*
buffer2
,
size_t
size
,
const
struct
audio_format
*
format
,
float
portion1
);
size_t
pcm_convertAudioFormat
(
const
struct
audio_format
*
inFormat
,
const
char
*
inBuffer
,
size_t
inSize
,
const
struct
audio_format
*
outFormat
,
char
*
outBuffer
,
struct
pcm_convert_state
*
convState
);
size_t
pcm_convert
(
const
struct
audio_format
*
inFormat
,
const
char
*
inBuffer
,
size_t
inSize
,
const
struct
audio_format
*
outFormat
,
char
*
outBuffer
,
struct
pcm_convert_state
*
convState
);
size_t
pcm_convert_size
(
const
struct
audio_format
*
inFormat
,
size_t
inSize
,
const
struct
audio_format
*
outFormat
);
size_t
pcm_sizeOfConvBuffer
(
const
struct
audio_format
*
inFormat
,
size_t
inSize
,
const
struct
audio_format
*
outFormat
);
#endif
src/player_thread.c
View file @
ca6e613a
...
...
@@ -213,8 +213,8 @@ static int playChunk(ob_chunk * chunk,
pc
.
elapsedTime
=
chunk
->
times
;
pc
.
bitRate
=
chunk
->
bitRate
;
pcm_volume
Change
(
chunk
->
data
,
chunk
->
chunkSize
,
format
,
pc
.
softwareVolume
);
pcm_volume
(
chunk
->
data
,
chunk
->
chunkSize
,
format
,
pc
.
softwareVolume
);
if
(
playAudio
(
chunk
->
data
,
chunk
->
chunkSize
)
<
0
)
...
...
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