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
e9127523
Commit
e9127523
authored
Nov 30, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pcm/PcmConvert: move code to new class GluePcmResampler
parent
92004f2e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
153 additions
and
139 deletions
+153
-139
Makefile.am
Makefile.am
+1
-0
GlueResampler.cxx
src/pcm/GlueResampler.cxx
+94
-0
GlueResampler.hxx
src/pcm/GlueResampler.hxx
+44
-0
PcmConvert.cxx
src/pcm/PcmConvert.cxx
+12
-122
PcmConvert.hxx
src/pcm/PcmConvert.hxx
+2
-17
No files found.
Makefile.am
View file @
e9127523
...
@@ -339,6 +339,7 @@ libpcm_a_SOURCES = \
...
@@ -339,6 +339,7 @@ libpcm_a_SOURCES = \
src/pcm/PcmFormat.cxx src/pcm/PcmFormat.hxx
\
src/pcm/PcmFormat.cxx src/pcm/PcmFormat.hxx
\
src/pcm/FormatConverter.cxx src/pcm/FormatConverter.hxx
\
src/pcm/FormatConverter.cxx src/pcm/FormatConverter.hxx
\
src/pcm/ChannelsConverter.cxx src/pcm/ChannelsConverter.hxx
\
src/pcm/ChannelsConverter.cxx src/pcm/ChannelsConverter.hxx
\
src/pcm/GlueResampler.cxx src/pcm/GlueResampler.hxx
\
src/pcm/PcmResample.cxx src/pcm/PcmResample.hxx
\
src/pcm/PcmResample.cxx src/pcm/PcmResample.hxx
\
src/pcm/PcmResampleFallback.cxx
\
src/pcm/PcmResampleFallback.cxx
\
src/pcm/PcmResampleInternal.hxx
\
src/pcm/PcmResampleInternal.hxx
\
...
...
src/pcm/GlueResampler.cxx
0 → 100644
View file @
e9127523
/*
* Copyright (C) 2003-2013 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 "config.h"
#include "GlueResampler.hxx"
#include "PcmConvert.hxx"
#include "PcmFormat.hxx"
#include "util/ConstBuffer.hxx"
#include "util/Error.hxx"
bool
GluePcmResampler
::
Open
(
AudioFormat
_src_format
,
unsigned
_new_sample_rate
,
gcc_unused
Error
&
error
)
{
src_format
=
_src_format
;
new_sample_rate
=
_new_sample_rate
;
return
true
;
}
void
GluePcmResampler
::
Close
()
{
resampler
.
Reset
();
}
ConstBuffer
<
void
>
GluePcmResampler
::
Resample
(
ConstBuffer
<
void
>
src
,
Error
&
error
)
{
const
void
*
result
;
size_t
size
;
switch
(
src_format
.
format
)
{
case
SampleFormat
:
:
S16
:
result
=
resampler
.
Resample16
(
src_format
.
channels
,
src_format
.
sample_rate
,
(
const
int16_t
*
)
src
.
data
,
src
.
size
,
new_sample_rate
,
&
size
,
error
);
break
;
case
SampleFormat
:
:
S24_P32
:
result
=
resampler
.
Resample24
(
src_format
.
channels
,
src_format
.
sample_rate
,
(
const
int32_t
*
)
src
.
data
,
src
.
size
,
new_sample_rate
,
&
size
,
error
);
break
;
case
SampleFormat
:
:
S32
:
result
=
resampler
.
Resample24
(
src_format
.
channels
,
src_format
.
sample_rate
,
(
const
int32_t
*
)
src
.
data
,
src
.
size
,
new_sample_rate
,
&
size
,
error
);
break
;
case
SampleFormat
:
:
FLOAT
:
result
=
resampler
.
ResampleFloat
(
src_format
.
channels
,
src_format
.
sample_rate
,
(
const
float
*
)
src
.
data
,
src
.
size
,
new_sample_rate
,
&
size
,
error
);
break
;
default
:
error
.
Format
(
pcm_convert_domain
,
"Resampling %s is not implemented"
,
sample_format_to_string
(
src_format
.
format
));
return
nullptr
;
}
return
{
result
,
size
};
}
src/pcm/GlueResampler.hxx
0 → 100644
View file @
e9127523
/*
* Copyright (C) 2003-2013 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_GLUE_RESAMPLER_HXX
#define MPD_GLUE_RESAMPLER_HXX
#include "check.h"
#include "AudioFormat.hxx"
#include "PcmResample.hxx"
class
Error
;
template
<
typename
T
>
struct
ConstBuffer
;
class
GluePcmResampler
{
PcmResampler
resampler
;
AudioFormat
src_format
;
unsigned
new_sample_rate
;
public
:
bool
Open
(
AudioFormat
src_format
,
unsigned
new_sample_rate
,
Error
&
error
);
void
Close
();
ConstBuffer
<
void
>
Resample
(
ConstBuffer
<
void
>
src
,
Error
&
error
);
};
#endif
src/pcm/PcmConvert.cxx
View file @
e9127523
...
@@ -78,6 +78,10 @@ PcmConvert::Open(AudioFormat _src_format, AudioFormat _dest_format,
...
@@ -78,6 +78,10 @@ PcmConvert::Open(AudioFormat _src_format, AudioFormat _dest_format,
return
false
;
return
false
;
}
}
if
(
format
.
sample_rate
!=
dest_format
.
sample_rate
&&
!
resampler
.
Open
(
format
,
dest_format
.
sample_rate
,
error
))
return
false
;
return
true
;
return
true
;
}
}
...
@@ -91,7 +95,9 @@ PcmConvert::Close()
...
@@ -91,7 +95,9 @@ PcmConvert::Close()
format_converter
.
Close
();
format_converter
.
Close
();
dsd
.
Reset
();
dsd
.
Reset
();
resampler
.
Reset
();
if
(
src_format
.
sample_rate
!=
dest_format
.
sample_rate
)
resampler
.
Close
();
#ifndef NDEBUG
#ifndef NDEBUG
src_format
.
Clear
();
src_format
.
Clear
();
...
@@ -99,102 +105,6 @@ PcmConvert::Close()
...
@@ -99,102 +105,6 @@ PcmConvert::Close()
#endif
#endif
}
}
inline
ConstBuffer
<
int16_t
>
PcmConvert
::
Convert16
(
ConstBuffer
<
int16_t
>
src
,
AudioFormat
format
,
Error
&
error
)
{
assert
(
format
.
format
==
SampleFormat
::
S16
);
assert
(
dest_format
.
format
==
SampleFormat
::
S16
);
assert
(
format
.
channels
==
dest_format
.
channels
);
auto
buf
=
src
.
data
;
size_t
len
=
src
.
size
*
sizeof
(
*
src
.
data
);
if
(
format
.
sample_rate
!=
dest_format
.
sample_rate
)
{
buf
=
resampler
.
Resample16
(
dest_format
.
channels
,
format
.
sample_rate
,
buf
,
len
,
dest_format
.
sample_rate
,
&
len
,
error
);
if
(
buf
==
nullptr
)
return
nullptr
;
}
return
ConstBuffer
<
int16_t
>::
FromVoid
({
buf
,
len
});
}
inline
ConstBuffer
<
int32_t
>
PcmConvert
::
Convert24
(
ConstBuffer
<
int32_t
>
src
,
AudioFormat
format
,
Error
&
error
)
{
assert
(
format
.
format
==
SampleFormat
::
S24_P32
);
assert
(
dest_format
.
format
==
SampleFormat
::
S24_P32
);
assert
(
format
.
channels
==
dest_format
.
channels
);
auto
buf
=
src
.
data
;
size_t
len
=
src
.
size
*
sizeof
(
*
src
.
data
);
if
(
format
.
sample_rate
!=
dest_format
.
sample_rate
)
{
buf
=
resampler
.
Resample24
(
dest_format
.
channels
,
format
.
sample_rate
,
buf
,
len
,
dest_format
.
sample_rate
,
&
len
,
error
);
if
(
buf
==
nullptr
)
return
nullptr
;
}
return
ConstBuffer
<
int32_t
>::
FromVoid
({
buf
,
len
});
}
inline
ConstBuffer
<
int32_t
>
PcmConvert
::
Convert32
(
ConstBuffer
<
int32_t
>
src
,
AudioFormat
format
,
Error
&
error
)
{
assert
(
format
.
format
==
SampleFormat
::
S32
);
assert
(
dest_format
.
format
==
SampleFormat
::
S32
);
assert
(
format
.
channels
==
dest_format
.
channels
);
auto
buf
=
src
.
data
;
size_t
len
=
src
.
size
*
sizeof
(
*
src
.
data
);
if
(
format
.
sample_rate
!=
dest_format
.
sample_rate
)
{
buf
=
resampler
.
Resample32
(
dest_format
.
channels
,
format
.
sample_rate
,
buf
,
len
,
dest_format
.
sample_rate
,
&
len
,
error
);
if
(
buf
==
nullptr
)
return
nullptr
;
}
return
ConstBuffer
<
int32_t
>::
FromVoid
({
buf
,
len
});
}
inline
ConstBuffer
<
float
>
PcmConvert
::
ConvertFloat
(
ConstBuffer
<
float
>
src
,
AudioFormat
format
,
Error
&
error
)
{
assert
(
format
.
format
==
SampleFormat
::
FLOAT
);
assert
(
dest_format
.
format
==
SampleFormat
::
FLOAT
);
assert
(
format
.
channels
==
dest_format
.
channels
);
auto
buffer
=
src
.
data
;
size_t
size
=
src
.
size
*
sizeof
(
*
src
.
data
);
/* resample with float, because this is the best format for
libsamplerate */
if
(
format
.
sample_rate
!=
dest_format
.
sample_rate
)
{
buffer
=
resampler
.
ResampleFloat
(
dest_format
.
channels
,
format
.
sample_rate
,
buffer
,
size
,
dest_format
.
sample_rate
,
&
size
,
error
);
if
(
buffer
==
nullptr
)
return
nullptr
;
}
return
ConstBuffer
<
float
>::
FromVoid
({
buffer
,
size
});
}
const
void
*
const
void
*
PcmConvert
::
Convert
(
const
void
*
src
,
size_t
src_size
,
PcmConvert
::
Convert
(
const
void
*
src
,
size_t
src_size
,
size_t
*
dest_size_r
,
size_t
*
dest_size_r
,
...
@@ -233,32 +143,12 @@ PcmConvert::Convert(const void *src, size_t src_size,
...
@@ -233,32 +143,12 @@ PcmConvert::Convert(const void *src, size_t src_size,
format
.
channels
=
dest_format
.
channels
;
format
.
channels
=
dest_format
.
channels
;
}
}
switch
(
dest_format
.
format
)
{
if
(
format
.
sample_rate
!=
dest_format
.
sample_rate
)
{
case
SampleFormat
:
:
S16
:
buffer
=
resampler
.
Resample
(
buffer
,
error
);
buffer
=
Convert16
(
ConstBuffer
<
int16_t
>::
FromVoid
(
buffer
),
if
(
buffer
.
IsNull
())
format
,
error
).
ToVoid
();
return
nullptr
;
break
;
case
SampleFormat
:
:
S24_P32
:
buffer
=
Convert24
(
ConstBuffer
<
int32_t
>::
FromVoid
(
buffer
),
format
,
error
).
ToVoid
();
break
;
case
SampleFormat
:
:
S32
:
buffer
=
Convert32
(
ConstBuffer
<
int32_t
>::
FromVoid
(
buffer
),
format
,
error
).
ToVoid
();
break
;
case
SampleFormat
:
:
FLOAT
:
buffer
=
ConvertFloat
(
ConstBuffer
<
float
>::
FromVoid
(
buffer
),
format
,
error
).
ToVoid
();
break
;
default
:
format
.
sample_rate
=
dest_format
.
sample_rate
;
error
.
Format
(
pcm_convert_domain
,
"PCM conversion to %s is not implemented"
,
sample_format_to_string
(
dest_format
.
format
));
return
nullptr
;
}
}
*
dest_size_r
=
buffer
.
size
;
*
dest_size_r
=
buffer
.
size
;
...
...
src/pcm/PcmConvert.hxx
View file @
e9127523
...
@@ -21,10 +21,10 @@
...
@@ -21,10 +21,10 @@
#define PCM_CONVERT_HXX
#define PCM_CONVERT_HXX
#include "PcmDsd.hxx"
#include "PcmDsd.hxx"
#include "PcmResample.hxx"
#include "PcmBuffer.hxx"
#include "PcmBuffer.hxx"
#include "FormatConverter.hxx"
#include "FormatConverter.hxx"
#include "ChannelsConverter.hxx"
#include "ChannelsConverter.hxx"
#include "GlueResampler.hxx"
#include "AudioFormat.hxx"
#include "AudioFormat.hxx"
#include <stddef.h>
#include <stddef.h>
...
@@ -41,10 +41,9 @@ class Domain;
...
@@ -41,10 +41,9 @@ class Domain;
class
PcmConvert
{
class
PcmConvert
{
PcmDsd
dsd
;
PcmDsd
dsd
;
PcmResampler
resampler
;
PcmFormatConverter
format_converter
;
PcmFormatConverter
format_converter
;
PcmChannelsConverter
channels_converter
;
PcmChannelsConverter
channels_converter
;
GluePcmResampler
resampler
;
AudioFormat
src_format
,
dest_format
;
AudioFormat
src_format
,
dest_format
;
...
@@ -79,20 +78,6 @@ public:
...
@@ -79,20 +78,6 @@ public:
const
void
*
Convert
(
const
void
*
src
,
size_t
src_size
,
const
void
*
Convert
(
const
void
*
src
,
size_t
src_size
,
size_t
*
dest_size_r
,
size_t
*
dest_size_r
,
Error
&
error
);
Error
&
error
);
private
:
ConstBuffer
<
int16_t
>
Convert16
(
ConstBuffer
<
int16_t
>
src
,
AudioFormat
format
,
Error
&
error
);
ConstBuffer
<
int32_t
>
Convert24
(
ConstBuffer
<
int32_t
>
src
,
AudioFormat
format
,
Error
&
error
);
ConstBuffer
<
int32_t
>
Convert32
(
ConstBuffer
<
int32_t
>
src
,
AudioFormat
format
,
Error
&
error
);
ConstBuffer
<
float
>
ConvertFloat
(
ConstBuffer
<
float
>
src
,
AudioFormat
format
,
Error
&
error
);
};
};
extern
const
Domain
pcm_convert_domain
;
extern
const
Domain
pcm_convert_domain
;
...
...
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