doc: Remove superfluous comment already described in footnotes.
[mpd-mk.git] / src / pcm_resample.h
blob9d03bbfbf45cc62b4c3ab0fde35de9b2dc3229ac
1 /*
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"
24 #include "config.h"
26 #include <stdint.h>
27 #include <stddef.h>
28 #include <stdbool.h>
30 #ifdef HAVE_LIBSAMPLERATE
31 #include <samplerate.h>
32 #endif
34 /**
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
40 SRC_STATE *state;
41 SRC_DATA data;
43 struct pcm_buffer in, out;
45 struct {
46 unsigned src_rate;
47 unsigned dest_rate;
48 uint8_t channels;
49 } prev;
51 int error;
52 #endif
54 struct pcm_buffer buffer;
57 /**
58 * Initializes a pcm_resample_state object.
60 void pcm_resample_init(struct pcm_resample_state *state);
62 /**
63 * Deinitializes a pcm_resample_state object and frees allocated
64 * memory.
66 void pcm_resample_deinit(struct pcm_resample_state *state);
68 /**
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
80 const int16_t *
81 pcm_resample_16(struct pcm_resample_state *state,
82 uint8_t channels,
83 unsigned src_rate,
84 const int16_t *src_buffer, size_t src_size,
85 unsigned dest_rate, size_t *dest_size_r,
86 GError **error_r);
88 /**
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
100 const int32_t *
101 pcm_resample_32(struct pcm_resample_state *state,
102 uint8_t channels,
103 unsigned src_rate,
104 const int32_t *src_buffer, size_t src_size,
105 unsigned dest_rate, size_t *dest_size_r,
106 GError **error_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,
122 uint8_t channels,
123 unsigned src_rate,
124 const int32_t *src_buffer, size_t src_size,
125 unsigned dest_rate, size_t *dest_size_r,
126 GError **error_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);
135 #endif