MPD 0.17~git
|
00001 /* 00002 * Copyright (C) 2003-2011 The Music Player Daemon Project 00003 * http://www.musicpd.org 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 00020 #ifndef MPD_PCM_RESAMPLE_H 00021 #define MPD_PCM_RESAMPLE_H 00022 00023 #include "check.h" 00024 #include "pcm_buffer.h" 00025 00026 #include <stdint.h> 00027 #include <stddef.h> 00028 #include <stdbool.h> 00029 00030 #ifdef HAVE_LIBSAMPLERATE 00031 #include <samplerate.h> 00032 #endif 00033 00038 struct pcm_resample_state { 00039 #ifdef HAVE_LIBSAMPLERATE 00040 SRC_STATE *state; 00041 SRC_DATA data; 00042 00043 struct pcm_buffer in, out; 00044 00045 struct { 00046 unsigned src_rate; 00047 unsigned dest_rate; 00048 unsigned channels; 00049 } prev; 00050 00051 int error; 00052 #endif 00053 00054 struct pcm_buffer buffer; 00055 }; 00056 00057 bool 00058 pcm_resample_global_init(GError **error_r); 00059 00063 void pcm_resample_init(struct pcm_resample_state *state); 00064 00069 void pcm_resample_deinit(struct pcm_resample_state *state); 00070 00083 const float * 00084 pcm_resample_float(struct pcm_resample_state *state, 00085 unsigned channels, 00086 unsigned src_rate, 00087 const float *src_buffer, size_t src_size, 00088 unsigned dest_rate, size_t *dest_size_r, 00089 GError **error_r); 00090 00103 const int16_t * 00104 pcm_resample_16(struct pcm_resample_state *state, 00105 unsigned channels, 00106 unsigned src_rate, 00107 const int16_t *src_buffer, size_t src_size, 00108 unsigned dest_rate, size_t *dest_size_r, 00109 GError **error_r); 00110 00123 const int32_t * 00124 pcm_resample_32(struct pcm_resample_state *state, 00125 unsigned channels, 00126 unsigned src_rate, 00127 const int32_t *src_buffer, size_t src_size, 00128 unsigned dest_rate, size_t *dest_size_r, 00129 GError **error_r); 00130 00143 static inline const int32_t * 00144 pcm_resample_24(struct pcm_resample_state *state, 00145 unsigned channels, 00146 unsigned src_rate, 00147 const int32_t *src_buffer, size_t src_size, 00148 unsigned dest_rate, size_t *dest_size_r, 00149 GError **error_r) 00150 { 00151 /* reuse the 32 bit code - the resampler code doesn't care if 00152 the upper 8 bits are actually used */ 00153 return pcm_resample_32(state, channels, 00154 src_rate, src_buffer, src_size, 00155 dest_rate, dest_size_r, error_r); 00156 } 00157 00158 #endif