1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef __AUDIO_UTIL_SNDFILE_H 18 #define __AUDIO_UTIL_SNDFILE_H 19 20 // This is a C library for reading and writing PCM .wav files. It is 21 // influenced by other libraries such as libsndfile and audiofile, except is 22 // much smaller and has an Apache 2.0 license. 23 // The API should be familiar to clients of similar libraries, but there is 24 // no guarantee that it will stay exactly source-code compatible with other libraries. 25 26 #include <stdio.h> 27 #include <sys/cdefs.h> 28 29 /** \cond */ 30 __BEGIN_DECLS 31 /** \endcond */ 32 33 // visible to clients 34 typedef int sf_count_t; 35 36 typedef struct { 37 sf_count_t frames; 38 int samplerate; 39 int channels; 40 int format; 41 } SF_INFO; 42 43 // opaque to clients 44 typedef struct SNDFILE_ SNDFILE; 45 46 // Access modes 47 #define SFM_READ 1 48 #define SFM_WRITE 2 49 50 // Format 51 #define SF_FORMAT_TYPEMASK 1 52 #define SF_FORMAT_WAV 1 53 #define SF_FORMAT_SUBMASK 14 54 #define SF_FORMAT_PCM_16 2 55 #define SF_FORMAT_PCM_U8 4 56 #define SF_FORMAT_FLOAT 6 57 #define SF_FORMAT_PCM_32 8 58 #define SF_FORMAT_PCM_24 10 59 60 /** Open stream */ 61 SNDFILE *sf_open(const char *path, int mode, SF_INFO *info); 62 63 /** Close stream */ 64 void sf_close(SNDFILE *handle); 65 66 /** 67 * Read interleaved frames 68 * \return actual number of frames read 69 */ 70 sf_count_t sf_readf_short(SNDFILE *handle, int16_t *ptr, sf_count_t desired); 71 sf_count_t sf_readf_float(SNDFILE *handle, float *ptr, sf_count_t desired); 72 sf_count_t sf_readf_int(SNDFILE *handle, int *ptr, sf_count_t desired); 73 74 /** 75 * Write interleaved frames 76 * \return actual number of frames written 77 */ 78 sf_count_t sf_writef_short(SNDFILE *handle, const int16_t *ptr, sf_count_t desired); 79 sf_count_t sf_writef_float(SNDFILE *handle, const float *ptr, sf_count_t desired); 80 sf_count_t sf_writef_int(SNDFILE *handle, const int *ptr, sf_count_t desired); 81 82 /** \cond */ 83 __END_DECLS 84 /** \endcond */ 85 86 #endif /* __AUDIO_UTIL_SNDFILE_H */ 87