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.

136 lines
4.1KB

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