jack2 codebase
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.

101 lines
2.5KB

  1. /*
  2. Copyright (C) 2006 Jesse Chappell <jesse@essej.net> (AC3Jack)
  3. Copyright (C) 2012 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #ifndef __JackAC3Encoder__
  17. #define __JackAC3Encoder__
  18. #include <aften/aften.h>
  19. #include <aften/aften-types.h>
  20. #include "ringbuffer.h"
  21. #include "types.h"
  22. #define MAX_AC3_CHANNELS 6
  23. #define SPDIF_HEADER_SIZE 8
  24. #define SPDIF_FRAME_SIZE 6144
  25. #define SAMPLE_MAX_16BIT 32768.0f
  26. #define SAMPLE_MAX_24BIT 8388608.0f
  27. namespace Jack
  28. {
  29. struct JackAC3EncoderParams
  30. {
  31. int64_t duration;
  32. unsigned int channels;
  33. int bitdepth;
  34. int bitrate;
  35. unsigned int sample_rate;
  36. bool lfe;
  37. };
  38. class JackAC3Encoder
  39. {
  40. private:
  41. AftenContext fAftenContext;
  42. jack_ringbuffer_t* fRingBuffer;
  43. float* fSampleBuffer;
  44. unsigned char* fAC3Buffer;
  45. unsigned char* fZeroBuffer;
  46. int fOutSizeByte;
  47. jack_nframes_t fFramePos;
  48. jack_nframes_t fSampleRate;
  49. jack_nframes_t fByteRate;
  50. void FillSpdifHeader(unsigned char* buf, int outsize);
  51. int Output2Driver(float** outputs, jack_nframes_t nframes);
  52. void sample_move_dS_s16(jack_default_audio_sample_t* dst, char *src, jack_nframes_t nsamples, unsigned long src_skip);
  53. void sample_move_dS_s16_24ph(jack_default_audio_sample_t* dst, char *src, jack_nframes_t nsamples, unsigned long src_skip);
  54. public:
  55. #ifdef __ppc__
  56. JackAC3Encoder(const JackAC3EncoderParams& params) {}
  57. virtual ~JackAC3Encoder() {}
  58. bool Init(jack_nframes_t sample_rate) {return false;}
  59. void Process(float** inputs, float** outputs, int nframes) {}
  60. void GetChannelName(const char* name, const char* alias, char* portname, int channel) {}
  61. #else
  62. JackAC3Encoder(const JackAC3EncoderParams& params);
  63. virtual ~JackAC3Encoder();
  64. bool Init(jack_nframes_t sample_rate);
  65. void Process(float** inputs, float** outputs, int nframes);
  66. void GetChannelName(const char* name, const char* alias, char* portname, int channel);
  67. #endif
  68. };
  69. typedef JackAC3Encoder * JackAC3EncoderPtr;
  70. } // end of namespace
  71. #endif