Ticket #9989: 28-audio5chan

File 28-audio5chan, 7.5 KB (added by Mark Spieth, 14 years ago)
Line 
1handle 5 channel audio, no LFE
2
3From: Mark Spieth <mspieth@digivation.com.au>
4
5
6---
7 mythtv/libs/libmyth/audio/audiooutputbase.cpp | 10 ++-
8 mythtv/libs/libmythfreesurround/freesurround.cpp | 78 +++++++++++++++++-----
9 mythtv/libs/libmythfreesurround/freesurround.h | 1
10 3 files changed, 70 insertions(+), 19 deletions(-)
11
12diff --git a/mythtv/libs/libmyth/audio/audiooutputbase.cpp b/mythtv/libs/libmyth/audio/audiooutputbase.cpp
13index 81579cb..5f40d88 100644
14--- a/mythtv/libs/libmyth/audio/audiooutputbase.cpp
15+++ b/mythtv/libs/libmyth/audio/audiooutputbase.cpp
16@@ -33,6 +33,10 @@
17 #define QUALITY_MEDIUM 1
18 #define QUALITY_HIGH 2
19
20+// 1,2 and 5 channels are currently valid for upmixing if required
21+#define UPMIX_CHANNEL_MASK ((1<<1)|(1<<2)|(1<<5))
22+#define IS_VALID_UPMIX_CHANNEL(ch) ((1 << (ch)) & UPMIX_CHANNEL_MASK)
23+
24 static const char *quality_string(int q)
25 {
26 switch(q) {
27@@ -469,7 +473,7 @@ void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings)
28 configured_channels = 2;
29 }
30 else
31- configured_channels = (upmix_default && lsource_channels == 2) ?
32+ configured_channels = (upmix_default && IS_VALID_UPMIX_CHANNEL(lsource_channels)) ?
33 max_channels : lsource_channels;
34 }
35
36@@ -482,7 +486,7 @@ void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings)
37 }
38
39 // Enough channels? Upmix if not, but only from mono/stereo to 5.1
40- if (settings.channels <= 2 && settings.channels < configured_channels)
41+ if (IS_VALID_UPMIX_CHANNEL(settings.channels) && (settings.channels < configured_channels))
42 {
43 int conf_channels = (configured_channels > 6) ?
44 6 : configured_channels;
45@@ -739,7 +743,7 @@ void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings)
46 VolumeBase::UpdateVolume();
47
48 // Upmix Stereo to 5.1
49- if (needs_upmix && source_channels == 2 && configured_channels > 2)
50+ if (needs_upmix && IS_VALID_UPMIX_CHANNEL(source_channels) && (configured_channels > source_channels))
51 {
52 surround_mode = gCoreContext->GetNumSetting("AudioUpmixType", QUALITY_HIGH);
53 if ((upmixer = new FreeSurround(samplerate, source == AUDIOOUTPUT_VIDEO,
54diff --git a/mythtv/libs/libmythfreesurround/freesurround.cpp b/mythtv/libs/libmythfreesurround/freesurround.cpp
55index 004cecd..ae4ecf7 100644
56--- a/mythtv/libs/libmythfreesurround/freesurround.cpp
57+++ b/mythtv/libs/libmythfreesurround/freesurround.cpp
58@@ -137,7 +137,8 @@ FreeSurround::FreeSurround(uint srate, bool moviemode, SurroundMode smode) :
59 out_count(0),
60 processed(true),
61 processed_size(0),
62- surround_mode(smode)
63+ surround_mode(smode),
64+ latency_frames(0)
65 {
66 LOG(VB_AUDIO, LOG_DEBUG,
67 QString("FreeSurround::FreeSurround rate %1 moviemode %2")
68@@ -161,6 +162,7 @@ FreeSurround::FreeSurround(uint srate, bool moviemode, SurroundMode smode) :
69 break;
70 case SurroundModeActiveLinear:
71 params.steering = 1;
72+ latency_frames = block_size/2;
73 break;
74 default:
75 break;
76@@ -242,6 +244,22 @@ uint FreeSurround::putFrames(void* buffer, uint numFrames, uint numChannels)
77 bufs->ls[ic] = bufs->rs[ic] = (lt-rt) * center_level;
78 }
79 break;
80+ case 5:
81+ for (i = 0; i < numFrames && ic < bs; i++,ic++)
82+ {
83+ float lt = *samples++;
84+ float rt = *samples++;
85+ float c = *samples++;
86+ //float lfe = *samples++;
87+ float ls = *samples++;
88+ float rs = *samples++;
89+ bufs->l[ic] = lt;
90+ bufs->lfe[ic] = bufs->c[ic] = c;
91+ bufs->r[ic] = rt;
92+ bufs->ls[ic] = ls;
93+ bufs->rs[ic] = rs;
94+ }
95+ break;
96 }
97 in_count = 0;
98 out_count = processed_size = ic;
99@@ -267,23 +285,51 @@ uint FreeSurround::putFrames(void* buffer, uint numFrames, uint numChannels)
100 *rt++ = *samples++;
101 }
102 break;
103+ case 5:
104+ // 5 ch is always passive mode, lfe is c
105+ for (i = 0; i < numFrames && ic < bs; i++,ic++)
106+ {
107+ float l = *samples++;
108+ float r = *samples++;
109+ float c = *samples++;
110+ //float lfe = *samples++;
111+ float ls = *samples++;
112+ float rs = *samples++;
113+ bufs->l[ic] = l;
114+ bufs->lfe[ic] = bufs->c[ic] = c;
115+ bufs->r[ic] = r;
116+ bufs->ls[ic] = ls;
117+ bufs->rs[ic] = rs;
118+ }
119+ process = false;
120+ break;
121 }
122- ic += numFrames;
123- processed = process;
124- if (ic != bs)
125- {
126- // dont modify unless no processing is to be done
127- // for audiotime consistency
128- in_count = ic;
129- break;
130- }
131- // process_block takes some time so dont update in and out count
132- // before its finished so that Audiotime is correctly calculated
133 if (process)
134+ {
135+ ic += numFrames;
136+ if (ic != bs)
137+ {
138+ // dont modify unless no processing is to be done
139+ // for audiotime consistency
140+ in_count = ic;
141+ break;
142+ }
143+ processed = process;
144+ // process_block takes some time so dont update in and out count
145+ // before its finished so that Audiotime is correctly calculated
146 process_block();
147- in_count = 0;
148- out_count = bs;
149- processed_size = bs;
150+ in_count = 0;
151+ out_count = bs;
152+ processed_size = bs;
153+ latency_frames = block_size/2;
154+ }
155+ else
156+ {
157+ in_count = 0;
158+ out_count = processed_size = ic;
159+ processed = false;
160+ latency_frames = 0;
161+ }
162 break;
163 }
164
165@@ -388,7 +434,7 @@ long long FreeSurround::getLatency()
166 // returns in usec
167 if (surround_mode == SurroundModePassive)
168 return 0;
169- return decoder ? ((block_size/2 + in_count)*1000000)/(2*srate) : 0;
170+ return decoder ? ((latency_frames + in_count)*1000000)/(2*srate) : 0;
171 }
172
173 void FreeSurround::flush()
174diff --git a/mythtv/libs/libmythfreesurround/freesurround.h b/mythtv/libs/libmythfreesurround/freesurround.h
175index 837bc0a..a8631c2 100644
176--- a/mythtv/libs/libmythfreesurround/freesurround.h
177+++ b/mythtv/libs/libmythfreesurround/freesurround.h
178@@ -85,6 +85,7 @@ private:
179 bool processed; // whether processing is enabled for latency calc
180 int processed_size; // amount processed
181 SurroundMode surround_mode; // 1 of 3 surround modes supported
182+ int latency_frames; // number of frames of incurred latency
183 };
184
185 #endif