File: JackAC3Encoder.h

package info (click to toggle)
jackd2 1.9.22~dfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,984 kB
  • sloc: cpp: 48,694; ansic: 23,970; python: 13,621; sh: 228; makefile: 31
file content (100 lines) | stat: -rw-r--r-- 2,583 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
Copyright (C) 2006 Jesse Chappell <jesse@essej.net> (AC3Jack)
Copyright (C) 2012 Grame

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#ifndef __JackAC3Encoder__
#define __JackAC3Encoder__

#include <aften/aften.h>
#include <aften/aften-types.h>

#include "ringbuffer.h"
#include "types.h"

#define MAX_AC3_CHANNELS 6

#define SPDIF_HEADER_SIZE 8
#define SPDIF_FRAME_SIZE 6144

#define SAMPLE_MAX_16BIT  32768.0f
#define SAMPLE_MAX_24BIT  8388608.0f

namespace Jack
{

struct JackAC3EncoderParams
{
	int64_t duration;
	unsigned int channels;
	int bitdepth;
	int bitrate;
	unsigned int sample_rate;
	bool lfe;
};

class JackAC3Encoder
{

    private:

	AftenContext fAftenContext;
	jack_ringbuffer_t* fRingBuffer;

	float* fSampleBuffer;
	unsigned char* fAC3Buffer;
	unsigned char* fZeroBuffer;

	int fOutSizeByte;

	jack_nframes_t fFramePos;
	jack_nframes_t fSampleRate;
	jack_nframes_t fByteRate;

	void FillSpdifHeader(unsigned char* buf, int outsize);
	int Output2Driver(float** outputs, jack_nframes_t nframes);

	void sample_move_dS_s16(jack_default_audio_sample_t* dst, char *src, jack_nframes_t nsamples, unsigned long src_skip);
	void sample_move_dS_s16_24ph(jack_default_audio_sample_t* dst, char *src, jack_nframes_t nsamples, unsigned long src_skip);

    public:

    #ifdef __ppc__
	JackAC3Encoder(const JackAC3EncoderParams& params) {}
	virtual ~JackAC3Encoder() {}

	bool Init(jack_nframes_t sample_rate) {return false;}

	void Process(float** inputs, float** outputs, int nframes) {}
	void GetChannelName(const char* name, const char* alias, char* portname, int channel) {}
    #else
	JackAC3Encoder(const JackAC3EncoderParams& params);
	virtual ~JackAC3Encoder();

	bool Init(jack_nframes_t sample_rate);

	void Process(float** inputs, float** outputs, int nframes);
	void GetChannelName(const char* name, const char* alias, char* portname, int channel);
    #endif
};

typedef JackAC3Encoder * JackAC3EncoderPtr;

} // end of namespace

#endif