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 __BEGIN_DECLS 30 31 // visible to clients 32 typedef int sf_count_t; 33 34 typedef struct { 35 sf_count_t frames; 36 int samplerate; 37 int channels; 38 int format; 39 } SF_INFO; 40 41 // opaque to clients 42 typedef struct SNDFILE_ SNDFILE; 43 44 // Access modes 45 #define SFM_READ 1 46 #define SFM_WRITE 2 47 48 // Format 49 #define SF_FORMAT_TYPEMASK 1 50 #define SF_FORMAT_WAV 1 51 #define SF_FORMAT_SUBMASK 14 52 #define SF_FORMAT_PCM_16 2 53 #define SF_FORMAT_PCM_U8 4 54 #define SF_FORMAT_FLOAT 6 55 #define SF_FORMAT_PCM_32 8 56 57 // Open stream 58 SNDFILE *sf_open(const char *path, int mode, SF_INFO *info); 59 60 // Close stream 61 void sf_close(SNDFILE *handle); 62 63 // Read interleaved frames and return actual number of frames read 64 sf_count_t sf_readf_short(SNDFILE *handle, short *ptr, sf_count_t desired); 65 sf_count_t sf_readf_float(SNDFILE *handle, float *ptr, sf_count_t desired); 66 sf_count_t sf_readf_int(SNDFILE *handle, int *ptr, sf_count_t desired); 67 68 // Write interleaved frames and return actual number of frames written 69 sf_count_t sf_writef_short(SNDFILE *handle, const short *ptr, sf_count_t desired); 70 sf_count_t sf_writef_float(SNDFILE *handle, const float *ptr, sf_count_t desired); 71 72 __END_DECLS 73 74 #endif /* __AUDIO_UTIL_SNDFILE_H */ 75