MPD

src/pcm_resample.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003-2010 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                 uint8_t channels;
00049         } prev;
00050 
00051         int error;
00052 #endif
00053 
00054         struct pcm_buffer buffer;
00055 };
00056 
00060 void pcm_resample_init(struct pcm_resample_state *state);
00061 
00066 void pcm_resample_deinit(struct pcm_resample_state *state);
00067 
00080 const int16_t *
00081 pcm_resample_16(struct pcm_resample_state *state,
00082                 uint8_t channels,
00083                 unsigned src_rate,
00084                 const int16_t *src_buffer, size_t src_size,
00085                 unsigned dest_rate, size_t *dest_size_r,
00086                 GError **error_r);
00087 
00100 const int32_t *
00101 pcm_resample_32(struct pcm_resample_state *state,
00102                 uint8_t channels,
00103                 unsigned src_rate,
00104                 const int32_t *src_buffer, size_t src_size,
00105                 unsigned dest_rate, size_t *dest_size_r,
00106                 GError **error_r);
00107 
00120 static inline const int32_t *
00121 pcm_resample_24(struct pcm_resample_state *state,
00122                 uint8_t channels,
00123                 unsigned src_rate,
00124                 const int32_t *src_buffer, size_t src_size,
00125                 unsigned dest_rate, size_t *dest_size_r,
00126                 GError **error_r)
00127 {
00128         /* reuse the 32 bit code - the resampler code doesn't care if
00129            the upper 8 bits are actually used */
00130         return pcm_resample_32(state, channels,
00131                                src_rate, src_buffer, src_size,
00132                                dest_rate, dest_size_r, error_r);
00133 }
00134 
00135 #endif