Jack2 1.9.10

JackAC3Encoder.h

00001 /*
00002 Copyright (C) 2006 Jesse Chappell <jesse@essej.net> (AC3Jack)
00003 Copyright (C) 2012 Grame
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 */
00020 
00021 #ifndef __JackAC3Encoder__
00022 #define __JackAC3Encoder__
00023 
00024 #include <aften/aften.h>
00025 #include <aften/aften-types.h>
00026 
00027 #include "ringbuffer.h"
00028 #include "types.h"
00029 
00030 #define MAX_AC3_CHANNELS 6
00031 
00032 #define SPDIF_HEADER_SIZE 8
00033 #define SPDIF_FRAME_SIZE 6144
00034 
00035 #define SAMPLE_MAX_16BIT  32768.0f
00036 #define SAMPLE_MAX_24BIT  8388608.0f
00037 
00038 namespace Jack
00039 {
00040 
00041 struct JackAC3EncoderParams
00042 {
00043         int64_t duration;
00044         unsigned int channels;
00045         int bitdepth;
00046         int bitrate;
00047         unsigned int sample_rate;
00048         bool lfe;
00049 };
00050 
00051 class JackAC3Encoder
00052 {
00053 
00054     private:
00055 
00056                 AftenContext fAftenContext;
00057         jack_ringbuffer_t* fRingBuffer;
00058         
00059         float* fSampleBuffer;
00060         unsigned char* fAC3Buffer;
00061         unsigned char* fZeroBuffer;
00062         
00063         int fOutSizeByte; 
00064         
00065         jack_nframes_t fFramePos;
00066         jack_nframes_t fSampleRate;
00067         jack_nframes_t fByteRate;
00068         
00069         void FillSpdifHeader(unsigned char* buf, int outsize);
00070         int Output2Driver(float** outputs, jack_nframes_t nframes);
00071         
00072         void sample_move_dS_s16(jack_default_audio_sample_t* dst, char *src, jack_nframes_t nsamples, unsigned long src_skip);
00073         void sample_move_dS_s16_24ph(jack_default_audio_sample_t* dst, char *src, jack_nframes_t nsamples, unsigned long src_skip);
00074 
00075     public:
00076     
00077     #ifdef __ppc__
00078         JackAC3Encoder(const JackAC3EncoderParams& params) {}
00079         virtual ~JackAC3Encoder() {}
00080   
00081         bool Init(jack_nframes_t sample_rate) {return false;}
00082   
00083         void Process(float** inputs, float** outputs, int nframes) {}
00084         void GetChannelName(const char* name, const char* alias, char* portname, int channel) {}
00085     #else
00086         JackAC3Encoder(const JackAC3EncoderParams& params);
00087         virtual ~JackAC3Encoder();
00088     
00089         bool Init(jack_nframes_t sample_rate);
00090     
00091         void Process(float** inputs, float** outputs, int nframes);
00092         void GetChannelName(const char* name, const char* alias, char* portname, int channel);
00093     #endif
00094 };
00095 
00096 typedef JackAC3Encoder * JackAC3EncoderPtr;
00097 
00098 } // end of namespace
00099 
00100 #endif