tinysndfile.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #pragma once
  17. // This is a C library for reading and writing PCM .wav files. It is
  18. // influenced by other libraries such as libsndfile and audiofile, except is
  19. // much smaller and has an Apache 2.0 license.
  20. // The API should be familiar to clients of similar libraries, but there is
  21. // no guarantee that it will stay exactly source-code compatible with other libraries.
  22. #include <stdio.h>
  23. #include <sys/cdefs.h>
  24. __BEGIN_DECLS
  25. // visible to clients
  26. typedef int sf_count_t;
  27. typedef struct {
  28. sf_count_t frames;
  29. int samplerate;
  30. int channels;
  31. int format;
  32. } SF_INFO;
  33. // opaque to clients
  34. typedef struct SNDFILE_ SNDFILE;
  35. // Format
  36. #define SF_FORMAT_TYPEMASK 1
  37. #define SF_FORMAT_WAV 1
  38. #define SF_FORMAT_SUBMASK 14
  39. #define SF_FORMAT_PCM_16 2
  40. #define SF_FORMAT_PCM_U8 4
  41. #define SF_FORMAT_FLOAT 6
  42. #define SF_FORMAT_PCM_32 8
  43. #define SF_FORMAT_PCM_24 10
  44. typedef struct {
  45. void* (*open)(const char* path, void* user);
  46. size_t (*read) (void* ptr, size_t size, size_t nmemb, void* datasource);
  47. int (*seek) (void* datasource, long offset, int whence);
  48. int (*close) (void* datasource);
  49. long (*tell) (void* datasource);
  50. } snd_callbacks;
  51. // Open stream
  52. SNDFILE *sf_open_read(const char *path, SF_INFO *info, snd_callbacks* cb, void* user);
  53. // Close stream
  54. void sf_close(SNDFILE *handle);
  55. // Read interleaved frames and return actual number of frames read
  56. sf_count_t sf_readf_short(SNDFILE *handle, short *ptr, sf_count_t desired);
  57. /*
  58. sf_count_t sf_readf_float(SNDFILE *handle, float *ptr, sf_count_t desired);
  59. sf_count_t sf_readf_int(SNDFILE *handle, int *ptr, sf_count_t desired);
  60. */
  61. __END_DECLS