Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.9KB

  1. /**
  2. @brief audio-decoder - wrapper around libsndfile and libav*
  3. @file ad.h
  4. @author Robin Gareus <robin@gareus.org>
  5. Copyright (C) 2011-2013 Robin Gareus <robin@gareus.org>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU Lesser Public License as published by
  8. the Free Software Foundation; either version 2.1, or (at your option)
  9. any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU Lesser Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef __AD_H__
  19. #define __AD_H__
  20. #include <unistd.h>
  21. #include <stdint.h>
  22. struct adinfo {
  23. unsigned int sample_rate;
  24. unsigned int channels;
  25. int64_t length; //milliseconds
  26. int64_t frames; //total number of frames (eg a frame for 16bit stereo is 4 bytes).
  27. int bit_rate;
  28. int bit_depth;
  29. char * meta_data;
  30. };
  31. /* global init function - register codecs */
  32. void ad_init();
  33. /* --- public API --- */
  34. /** open an audio file
  35. * @param fn file-name
  36. * @param nfo pointer to a adinfo struct which will hold information about the file.
  37. * @return NULL on error, a pointer to an opaque soundfile-decoder object on success.
  38. */
  39. void * ad_open (const char *fn, struct adinfo *nfo);
  40. /** close an audio file and release decoder structures
  41. * @param sf decoder handle
  42. * @return 0 on succees, -1 if sf was invalid or not open (return value can usually be ignored)
  43. */
  44. int ad_close (void *sf);
  45. /** seel to a given position in the file
  46. * @param sf decoder handle
  47. * @param pos frame position to seek to in frames (1 frame = number-of-channel samples) from the start of the file.
  48. * @return the current position in frames (multi-channel samples) from the start of the file. On error this function returns -1.
  49. */
  50. int64_t ad_seek (void *sf, int64_t pos);
  51. /** decode audio data chunk to raw interleaved channel floating point data
  52. *
  53. * @param sf decoder handle
  54. * @param out place to store data -- must be large enough to hold (sizeof(float) * len) bytes.
  55. * @param len number of samples (!) to read (should be a multiple of nfo->channels).
  56. * @return the number of read samples.
  57. */
  58. ssize_t ad_read (void *sf, float* out, size_t len);
  59. /** re-read the file information and meta-data.
  60. *
  61. * this is not neccesary in general \ref ad_open includes an inplicit call
  62. * but meta-data may change in live-stream in which case en explicit call to
  63. * ad_into is needed to update the inforation
  64. *
  65. * @param fn file-name
  66. * @param nfo pointer to a adinfo struct which will hold information about the file.
  67. * @return 0 on succees, -1 if sf was invalid or not open
  68. */
  69. int ad_info (void *sf, struct adinfo *nfo);
  70. /** zero initialize the information struct. * (does not free nfo->meta_data)
  71. * @param nfo pointer to a adinfo struct
  72. */
  73. void ad_clear_nfo (struct adinfo *nfo);
  74. /** free possibly allocated meta-data text
  75. * @param nfo pointer to a adinfo struct
  76. */
  77. void ad_free_nfo (struct adinfo *nfo);
  78. /* --- helper functions --- */
  79. /** read file info
  80. * combines ad_open() and ad_close()
  81. */
  82. int ad_finfo (const char *, struct adinfo *);
  83. /**
  84. * wrapper around \ref ad_read, downmixes all channels to mono
  85. */
  86. ssize_t ad_read_mono_dbl (void *, struct adinfo *, double*, size_t);
  87. /**
  88. * calls dbg() to print file info to stderr.
  89. *
  90. * @param dbglvl
  91. * @param nfo
  92. */
  93. void ad_dump_nfo (int dbglvl, struct adinfo *nfo);
  94. /** set audio-decoder debug level -- all info is printed to stderr.
  95. *
  96. * @param lvl debug-level threshold
  97. * -1: absolutley silent
  98. * 0: errors only
  99. * 1: errors + info
  100. * 2: + debug
  101. * 3: + low-level-debug info
  102. */
  103. void ad_set_debuglevel(int lvl);
  104. #endif