Jack2  1.9.9
JackAC3Encoder.h
1 /*
2 Copyright (C) 2006 Jesse Chappell <jesse@essej.net> (AC3Jack)
3 Copyright (C) 2012 Grame
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
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 General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 
19 */
20 
21 #ifndef __JackAC3Encoder__
22 #define __JackAC3Encoder__
23 
24 #include <aften/aften.h>
25 #include <aften/aften-types.h>
26 
27 #include "ringbuffer.h"
28 #include "types.h"
29 
30 #define MAX_AC3_CHANNELS 6
31 
32 #define SPDIF_HEADER_SIZE 8
33 #define SPDIF_FRAME_SIZE 6144
34 
35 #define SAMPLE_MAX_16BIT 32768.0f
36 #define SAMPLE_MAX_24BIT 8388608.0f
37 
38 namespace Jack
39 {
40 
42 {
43  int64_t duration;
44  unsigned int channels;
45  int bitdepth;
46  int bitrate;
47  unsigned int sample_rate;
48  bool lfe;
49 };
50 
52 {
53 
54  private:
55 
56  AftenContext fAftenContext;
57  jack_ringbuffer_t* fRingBuffer;
58 
59  float* fSampleBuffer;
60  unsigned char* fAC3Buffer;
61  unsigned char* fZeroBuffer;
62 
63  int fOutSizeByte;
64 
65  jack_nframes_t fFramePos;
66  jack_nframes_t fSampleRate;
67  jack_nframes_t fByteRate;
68 
69  void FillSpdifHeader(unsigned char* buf, int outsize);
70  int Output2Driver(float** outputs, jack_nframes_t nframes);
71 
72  void sample_move_dS_s16(jack_default_audio_sample_t* dst, char *src, jack_nframes_t nsamples, unsigned long src_skip);
73  void sample_move_dS_s16_24ph(jack_default_audio_sample_t* dst, char *src, jack_nframes_t nsamples, unsigned long src_skip);
74 
75  public:
76 
77  #ifdef __ppc__
78  JackAC3Encoder(const JackAC3EncoderParams& params) {}
79  virtual ~JackAC3Encoder() {}
80 
81  bool Init(jack_nframes_t sample_rate) {return false;}
82 
83  void Process(float** inputs, float** outputs, int nframes) {}
84  void GetChannelName(const char* name, const char* alias, char* portname, int channel) {}
85  #else
86  JackAC3Encoder(const JackAC3EncoderParams& params);
87  virtual ~JackAC3Encoder();
88 
89  bool Init(jack_nframes_t sample_rate);
90 
91  void Process(float** inputs, float** outputs, int nframes);
92  void GetChannelName(const char* name, const char* alias, char* portname, int channel);
93  #endif
94 };
95 
97 
98 } // end of namespace
99 
100 #endif