Merge branch 'master' into develop
[jack2.git] / common / JackAC3Encoder.h
blobd897586308e92b7be43baef350c77ac6dcbf5097
1 /*
2 Copyright (C) 2006 Jesse Chappell <jesse@essej.net> (AC3Jack)
3 Copyright (C) 2012 Grame
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.
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.
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.
21 #ifndef __JackAC3Encoder__
22 #define __JackAC3Encoder__
24 #include <aften/aften.h>
25 #include <aften/aften-types.h>
27 #include "ringbuffer.h"
28 #include "types.h"
30 #define MAX_AC3_CHANNELS 6
32 #define SPDIF_HEADER_SIZE 8
33 #define SPDIF_FRAME_SIZE 6144
35 #define SAMPLE_MAX_16BIT 32768.0f
36 #define SAMPLE_MAX_24BIT 8388608.0f
38 namespace Jack
41 struct JackAC3EncoderParams
43 int64_t duration;
44 unsigned int channels;
45 int bitdepth;
46 int bitrate;
47 unsigned int sample_rate;
48 bool lfe;
51 class JackAC3Encoder
54 private:
56 AftenContext fAftenContext;
57 jack_ringbuffer_t* fRingBuffer;
59 float* fSampleBuffer;
60 unsigned char* fAC3Buffer;
61 unsigned char* fZeroBuffer;
63 int fOutSizeByte;
65 jack_nframes_t fFramePos;
66 jack_nframes_t fSampleRate;
67 jack_nframes_t fByteRate;
69 void FillSpdifHeader(unsigned char* buf, int outsize);
70 int Output2Driver(float** outputs, jack_nframes_t nframes);
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);
75 public:
77 #ifdef __ppc__
78 JackAC3Encoder(const JackAC3EncoderParams& params) {}
79 virtual ~JackAC3Encoder() {}
81 bool Init(jack_nframes_t sample_rate) {return false;}
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();
89 bool Init(jack_nframes_t sample_rate);
91 void Process(float** inputs, float** outputs, int nframes);
92 void GetChannelName(const char* name, const char* alias, char* portname, int channel);
93 #endif
96 typedef JackAC3Encoder * JackAC3EncoderPtr;
98 } // end of namespace
100 #endif