2 * Copyright (C) 2012 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __AUDIO_UTIL_SNDFILE_H
18 #define __AUDIO_UTIL_SNDFILE_H
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.
27 #include <sys/cdefs.h>
34 typedef int sf_count_t;
44 typedef struct SNDFILE_ SNDFILE;
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
61 SNDFILE *sf_open(const char *path, int mode, SF_INFO *info);
64 void sf_close(SNDFILE *handle);
67 * Read interleaved frames
68 * \return actual number of frames read
70 sf_count_t sf_readf_short(SNDFILE *handle, short *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);
75 * Write interleaved frames
76 * \return actual number of frames written
78 sf_count_t sf_writef_short(SNDFILE *handle, const short *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);
86 #endif /* __AUDIO_UTIL_SNDFILE_H */