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.

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