bformatdec.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef BFORMATDEC_H
  2. #define BFORMATDEC_H
  3. #include "alMain.h"
  4. /* These are the necessary scales for first-order HF responses to play over
  5. * higher-order 2D (non-periphonic) decoders.
  6. */
  7. #define W_SCALE_2H0P 1.224744871f /* sqrt(1.5) */
  8. #define XYZ_SCALE_2H0P 1.0f
  9. #define W_SCALE_3H0P 1.414213562f /* sqrt(2) */
  10. #define XYZ_SCALE_3H0P 1.082392196f
  11. /* These are the necessary scales for first-order HF responses to play over
  12. * higher-order 3D (periphonic) decoders.
  13. */
  14. #define W_SCALE_2H2P 1.341640787f /* sqrt(1.8) */
  15. #define XYZ_SCALE_2H2P 1.0f
  16. #define W_SCALE_3H3P 1.695486018f
  17. #define XYZ_SCALE_3H3P 1.136697713f
  18. /* NOTE: These are scale factors as applied to Ambisonics content. Decoder
  19. * coefficients should be divided by these values to get proper N3D scalings.
  20. */
  21. const ALfloat N3D2N3DScale[MAX_AMBI_COEFFS];
  22. const ALfloat SN3D2N3DScale[MAX_AMBI_COEFFS];
  23. const ALfloat FuMa2N3DScale[MAX_AMBI_COEFFS];
  24. struct AmbDecConf;
  25. struct BFormatDec;
  26. struct AmbiUpsampler;
  27. struct BFormatDec *bformatdec_alloc();
  28. void bformatdec_free(struct BFormatDec **dec);
  29. void bformatdec_reset(struct BFormatDec *dec, const struct AmbDecConf *conf, ALsizei chancount, ALuint srate, const ALsizei chanmap[MAX_OUTPUT_CHANNELS]);
  30. /* Decodes the ambisonic input to the given output channels. */
  31. void bformatdec_process(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo);
  32. /* Up-samples a first-order input to the decoder's configuration. */
  33. void bformatdec_upSample(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei InChannels, ALsizei SamplesToDo);
  34. /* Stand-alone first-order upsampler. Kept here because it shares some stuff
  35. * with bformatdec. Assumes a periphonic (4-channel) input mix!
  36. */
  37. struct AmbiUpsampler *ambiup_alloc();
  38. void ambiup_free(struct AmbiUpsampler **ambiup);
  39. void ambiup_reset(struct AmbiUpsampler *ambiup, const ALCdevice *device, ALfloat w_scale, ALfloat xyz_scale);
  40. void ambiup_process(struct AmbiUpsampler *ambiup, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo);
  41. /* Band splitter. Splits a signal into two phase-matching frequency bands. */
  42. typedef struct BandSplitter {
  43. ALfloat coeff;
  44. ALfloat lp_z1;
  45. ALfloat lp_z2;
  46. ALfloat hp_z1;
  47. } BandSplitter;
  48. void bandsplit_init(BandSplitter *splitter, ALfloat f0norm);
  49. void bandsplit_clear(BandSplitter *splitter);
  50. void bandsplit_process(BandSplitter *splitter, ALfloat *restrict hpout, ALfloat *restrict lpout,
  51. const ALfloat *input, ALsizei count);
  52. /* The all-pass portion of the band splitter. Applies the same phase shift
  53. * without splitting the signal.
  54. */
  55. typedef struct SplitterAllpass {
  56. ALfloat coeff;
  57. ALfloat z1;
  58. } SplitterAllpass;
  59. void splitterap_init(SplitterAllpass *splitter, ALfloat f0norm);
  60. void splitterap_clear(SplitterAllpass *splitter);
  61. void splitterap_process(SplitterAllpass *splitter, ALfloat *restrict samples, ALsizei count);
  62. typedef struct FrontStablizer {
  63. SplitterAllpass APFilter[MAX_OUTPUT_CHANNELS];
  64. BandSplitter LFilter, RFilter;
  65. alignas(16) ALfloat LSplit[2][BUFFERSIZE];
  66. alignas(16) ALfloat RSplit[2][BUFFERSIZE];
  67. } FrontStablizer;
  68. #endif /* BFORMATDEC_H */