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
4f76ba5a
Commit
4f76ba5a
authored
May 10, 2004
by
Warren Dukes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
format conversion for 8->16 bis and mono->stereo
git-svn-id:
https://svn.musicpd.org/mpd/trunk@973
09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent
872af207
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
12 deletions
+75
-12
pcm_utils.c
src/pcm_utils.c
+75
-12
No files found.
src/pcm_utils.c
View file @
4f76ba5a
...
@@ -138,27 +138,92 @@ void pcm_mix(char * buffer1, char * buffer2, size_t bufferSize1,
...
@@ -138,27 +138,92 @@ void pcm_mix(char * buffer1, char * buffer2, size_t bufferSize1,
pcm_add
(
buffer1
,
buffer2
,
bufferSize1
,
bufferSize2
,
vol1
,
1000
-
vol1
,
format
);
pcm_add
(
buffer1
,
buffer2
,
bufferSize1
,
bufferSize2
,
vol1
,
1000
-
vol1
,
format
);
}
}
/* outFormat bits must be 16 and channels must be 2! */
void
pcm_convertAudioFormat
(
AudioFormat
*
inFormat
,
char
*
inBuffer
,
size_t
void
pcm_convertAudioFormat
(
AudioFormat
*
inFormat
,
char
*
inBuffer
,
size_t
inSize
,
AudioFormat
*
outFormat
,
char
*
outBuffer
)
inSize
,
AudioFormat
*
outFormat
,
char
*
outBuffer
)
{
{
/*int inSampleSize = inFormat->bits*inFormat->channels/8;
static
char
*
bitConvBuffer
=
NULL
;
int outSampleSize = outFormat->bits*outFormat->channels/8;*/
static
int
bitConvBufferLength
=
0
;
static
char
*
channelConvBuffer
=
NULL
;
static
int
channelConvBufferLength
=
0
;
char
*
dataChannelConv
;
int
dataChannelLen
;
char
*
dataBitConv
;
int
dataBitLen
;
assert
(
inFormat
->
bits
==
16
);
assert
(
outFormat
->
bits
==
16
);
assert
(
outFormat
->
bits
==
16
);
assert
(
inFormat
->
channels
==
2
);
assert
(
outFormat
->
channels
==
2
);
assert
(
outFormat
->
channels
==
2
);
if
(
inFormat
->
sampleRate
==
outFormat
->
sampleRate
)
return
;
/* converts */
switch
(
inFormat
->
bits
)
{
case
8
:
dataBitLen
=
inSize
<<
1
;
if
(
dataBitLen
>
bitConvBufferLength
)
{
bitConvBuffer
=
realloc
(
bitConvBuffer
,
dataBitLen
);
bitConvBufferLength
=
dataBitLen
;
}
dataBitConv
=
bitConvBuffer
;
{
mpd_sint8
*
in
=
(
mpd_sint8
*
)
inBuffer
;
mpd_sint16
*
out
=
(
mpd_sint16
*
)
dataBitConv
;
int
i
;
for
(
i
=
0
;
i
<
inSize
;
i
++
)
{
*
out
++
=
(
*
in
++
)
<<
8
;
}
}
break
;
case
16
:
dataBitConv
=
inBuffer
;
dataBitLen
=
inSize
;
break
;
case
24
:
/* put dithering code from mp3_decode here */
default:
ERROR
(
"only 8 or 16 bits are supported for conversion!
\n
"
);
exit
(
EXIT_FAILURE
);
}
/* only works if outFormat is 16-bit stereo! */
/* converts only between 16 bit audio between mono and stereo */
/* resampling code blatantly ripped from XMMS */
switch
(
inFormat
->
channels
)
{
{
case
1
:
dataChannelLen
=
(
dataBitLen
>>
1
)
<<
2
;
if
(
dataChannelLen
>
channelConvBufferLength
)
{
channelConvBuffer
=
realloc
(
channelConvBuffer
,
dataChannelLen
);
channelConvBufferLength
=
dataChannelLen
;
}
dataChannelConv
=
channelConvBuffer
;
{
mpd_sint16
*
in
=
(
mpd_sint16
*
)
dataBitConv
;
mpd_sint16
*
out
=
(
mpd_sint16
*
)
dataChannelConv
;
int
i
,
inSamples
=
dataChannelLen
>>
1
;
for
(
i
=
0
;
i
<
inSamples
;
i
++
)
{
*
out
++
=
*
in
;
*
out
++
=
*
in
++
;
}
}
break
;
case
2
:
dataChannelConv
=
dataBitConv
;
dataChannelLen
=
dataBitLen
;
break
;
default:
ERROR
(
"only 1 or 2 channels are supported for conversion!
\n
"
);
exit
(
EXIT_FAILURE
);
}
if
(
inFormat
->
sampleRate
==
outFormat
->
sampleRate
)
{
memcpy
(
outBuffer
,
dataChannelConv
,
dataChannelLen
);
}
else
{
/* only works if outFormat is 16-bit stereo! */
/* resampling code blatantly ripped from XMMS */
const
int
shift
=
sizeof
(
mpd_sint16
);
const
int
shift
=
sizeof
(
mpd_sint16
);
mpd_sint32
i
,
in_samples
,
out_samples
,
x
,
delta
;
mpd_sint32
i
,
in_samples
,
out_samples
,
x
,
delta
;
mpd_sint16
*
inptr
=
(
mpd_sint16
*
)
inBuffer
;
mpd_sint16
*
inptr
=
(
mpd_sint16
*
)
dataChannelConv
;
mpd_sint16
*
outptr
=
(
mpd_sint16
*
)
outBuffer
;
mpd_sint16
*
outptr
=
(
mpd_sint16
*
)
outBuffer
;
mpd_uint32
nlen
=
(((
inSize
>>
shift
)
*
mpd_uint32
nlen
=
(((
dataChannelLen
>>
shift
)
*
(
mpd_uint32
)(
outFormat
->
sampleRate
))
/
(
mpd_uint32
)(
outFormat
->
sampleRate
))
/
inFormat
->
sampleRate
);
inFormat
->
sampleRate
);
nlen
<<=
shift
;
nlen
<<=
shift
;
...
@@ -197,9 +262,7 @@ size_t pcm_sizeOfOutputBufferForAudioFormatConversion(AudioFormat * inFormat,
...
@@ -197,9 +262,7 @@ size_t pcm_sizeOfOutputBufferForAudioFormatConversion(AudioFormat * inFormat,
nlen
<<=
shift
;
nlen
<<=
shift
;
assert
(
inFormat
->
bits
==
16
);
assert
(
outFormat
->
bits
==
16
);
assert
(
outFormat
->
bits
==
16
);
assert
(
inFormat
->
channels
==
2
);
assert
(
outFormat
->
channels
==
2
);
assert
(
outFormat
->
channels
==
2
);
return
nlen
;
return
nlen
;
...
...
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