MPD
pcm_resample.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2010 The Music Player Daemon Project
3  * http://www.musicpd.org
4  *
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.
9  *
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.
14  *
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.
18  */
19 
20 #ifndef MPD_PCM_RESAMPLE_H
21 #define MPD_PCM_RESAMPLE_H
22 
23 #include "check.h"
24 #include "pcm_buffer.h"
25 
26 #include <stdint.h>
27 #include <stddef.h>
28 #include <stdbool.h>
29 
30 #ifdef HAVE_LIBSAMPLERATE
31 #include <samplerate.h>
32 #endif
33 
39 #ifdef HAVE_LIBSAMPLERATE
40  SRC_STATE *state;
41  SRC_DATA data;
42 
43  struct pcm_buffer in, out;
44 
45  struct {
46  unsigned src_rate;
47  unsigned dest_rate;
48  uint8_t channels;
49  } prev;
50 
51  int error;
52 #endif
53 
55 };
56 
60 void pcm_resample_init(struct pcm_resample_state *state);
61 
66 void pcm_resample_deinit(struct pcm_resample_state *state);
67 
80 const int16_t *
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);
87 
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);
107 
120 static inline const int32_t *
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)
127 {
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);
133 }
134 
135 #endif