2 * Copyright (C) 2003-2009 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef MPD_PCM_RESAMPLE_H
21 #define MPD_PCM_RESAMPLE_H
23 #include "pcm_buffer.h"
30 #ifdef HAVE_LIBSAMPLERATE
31 #include <samplerate.h>
35 * This object is statically allocated (within another struct), and
36 * holds buffer allocations and the state for the resampler.
38 struct pcm_resample_state
{
39 #ifdef HAVE_LIBSAMPLERATE
43 struct pcm_buffer in
, out
;
54 struct pcm_buffer buffer
;
58 * Initializes a pcm_resample_state object.
60 void pcm_resample_init(struct pcm_resample_state
*state
);
63 * Deinitializes a pcm_resample_state object and frees allocated
66 void pcm_resample_deinit(struct pcm_resample_state
*state
);
69 * Resamples 16 bit PCM data.
71 * @param state an initialized pcm_resample_state object
72 * @param channels the number of channels
73 * @param src_rate the source sample rate
74 * @param src the source PCM buffer
75 * @param src_size the size of #src in bytes
76 * @param dest_rate the requested destination sample rate
77 * @param dest_size_r returns the number of bytes of the destination buffer
78 * @return the destination buffer
81 pcm_resample_16(struct pcm_resample_state
*state
,
84 const int16_t *src_buffer
, size_t src_size
,
85 unsigned dest_rate
, size_t *dest_size_r
,
89 * Resamples 32 bit PCM data.
91 * @param state an initialized pcm_resample_state object
92 * @param channels the number of channels
93 * @param src_rate the source sample rate
94 * @param src the source PCM buffer
95 * @param src_size the size of #src in bytes
96 * @param dest_rate the requested destination sample rate
97 * @param dest_size_r returns the number of bytes of the destination buffer
98 * @return the destination buffer
101 pcm_resample_32(struct pcm_resample_state
*state
,
104 const int32_t *src_buffer
, size_t src_size
,
105 unsigned dest_rate
, size_t *dest_size_r
,
109 * Resamples 24 bit PCM data.
111 * @param state an initialized pcm_resample_state object
112 * @param channels the number of channels
113 * @param src_rate the source sample rate
114 * @param src the source PCM buffer
115 * @param src_size the size of #src in bytes
116 * @param dest_rate the requested destination sample rate
117 * @param dest_size_r returns the number of bytes of the destination buffer
118 * @return the destination buffer
120 static inline const int32_t *
121 pcm_resample_24(struct pcm_resample_state
*state
,
124 const int32_t *src_buffer
, size_t src_size
,
125 unsigned dest_rate
, size_t *dest_size_r
,
128 /* reuse the 32 bit code - the resampler code doesn't care if
129 the upper 8 bits are actually used */
130 return pcm_resample_32(state
, channels
,
131 src_rate
, src_buffer
, src_size
,
132 dest_rate
, dest_size_r
, error_r
);