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.

141 lines
4.2KB

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