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.

133 lines
4.0KB

  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. int can_seek;
  31. };
  32. /* --- public API --- */
  33. /** open an audio file
  34. * @param fn file-name
  35. * @param nfo pointer to a adinfo struct which will hold information about the file.
  36. * @return NULL on error, a pointer to an opaque soundfile-decoder object on success.
  37. */
  38. void * ad_open (const char *fn, struct adinfo *nfo);
  39. /** close an audio file and release decoder structures
  40. * @param sf decoder handle
  41. * @return 0 on succees, -1 if sf was invalid or not open (return value can usually be ignored)
  42. */
  43. int ad_close (void *sf);
  44. /** seel to a given position in the file
  45. * @param sf decoder handle
  46. * @param pos frame position to seek to in frames (1 frame = number-of-channel samples) from the start of the file.
  47. * @return the current position in frames (multi-channel samples) from the start of the file. On error this function returns -1.
  48. */
  49. int64_t ad_seek (void *sf, int64_t pos);
  50. /** decode audio data chunk to raw interleaved channel floating point data
  51. *
  52. * @param sf decoder handle
  53. * @param out place to store data -- must be large enough to hold (sizeof(float) * len) bytes.
  54. * @param len number of samples (!) to read (should be a multiple of nfo->channels).
  55. * @return the number of read samples.
  56. */
  57. ssize_t ad_read (void *sf, float* out, size_t len);
  58. /** get the current playing bit_rate
  59. *
  60. * @param sf decoder handle
  61. * @return the bitrate in kbps or -1 on error.
  62. */
  63. int ad_get_bitrate(void *sf);
  64. /** re-read the file information and meta-data.
  65. *
  66. * this is not neccesary in general \ref ad_open includes an inplicit call
  67. * but meta-data may change in live-stream in which case en explicit call to
  68. * ad_into is needed to update the inforation
  69. *
  70. * @param fn file-name
  71. * @param nfo pointer to a adinfo struct which will hold information about the file.
  72. * @return 0 on succees, -1 if sf was invalid or not open
  73. */
  74. int ad_info (void *sf, struct adinfo *nfo);
  75. /** zero initialize the information struct. * (does not free nfo->meta_data)
  76. * @param nfo pointer to a adinfo struct
  77. */
  78. void ad_clear_nfo (struct adinfo *nfo);
  79. /** free possibly allocated meta-data text
  80. * @param nfo pointer to a adinfo struct
  81. */
  82. void ad_free_nfo (struct adinfo *nfo);
  83. /* --- helper functions --- */
  84. /** read file info
  85. * combines ad_open() and ad_close()
  86. */
  87. int ad_finfo (const char *, struct adinfo *);
  88. /**
  89. * wrapper around \ref ad_read, downmixes all channels to mono
  90. */
  91. ssize_t ad_read_mono_dbl (void *, struct adinfo *, double*, size_t);
  92. /**
  93. * calls dbg() to print file info to stderr.
  94. *
  95. * @param dbglvl
  96. * @param nfo
  97. */
  98. void ad_dump_nfo (int dbglvl, struct adinfo *nfo);
  99. /** set audio-decoder debug level -- all info is printed to stderr.
  100. *
  101. * @param lvl debug-level threshold
  102. * -1: absolutley silent
  103. * 0: errors only
  104. * 1: errors + info
  105. * 2: + debug
  106. * 3: + low-level-debug info
  107. */
  108. void ad_set_debuglevel(int lvl);
  109. #endif