6 #include "audiodevice.h"
11 #include "edlsession.h"
13 #include "levelwindow.h"
14 #include "playabletracks.h"
16 #include "preferences.h"
17 #include "renderengine.h"
20 #include "transportque.h"
21 #include "virtualaconsole.h"
22 #include "virtualanode.h"
23 #include "virtualnode.h"
26 VirtualAConsole::VirtualAConsole(RenderEngine *renderengine, ARender *arender)
27 : VirtualConsole(renderengine, arender, TRACK_AUDIO)
29 this->arender = arender;
31 output_allocation = 0;
34 VirtualAConsole::~VirtualAConsole()
36 if(output_temp) delete [] output_temp;
40 void VirtualAConsole::get_playable_tracks()
43 playable_tracks = new PlayableTracks(renderengine,
44 commonrender->current_position,
50 VirtualNode* VirtualAConsole::new_entry_node(Track *track,
54 return new VirtualANode(renderengine,
65 int VirtualAConsole::process_buffer(int64_t len,
66 int64_t start_position,
68 int64_t absolute_position)
73 // clear output buffers
74 for(int i = 0; i < MAX_CHANNELS; i++)
76 // printf("VirtualAConsole::process_buffer 2 %d %p %lld\n",
78 // arender->audio_out[i],
80 if(arender->audio_out[i])
82 bzero(arender->audio_out[i], len * sizeof(double));
86 // Create temporary output
87 if(output_temp && output_allocation < len)
89 delete [] output_temp;
95 output_temp = new double[len];
96 output_allocation = len;
99 // Reset plugin rendering status
101 //printf("VirtualAConsole::process_buffer 1 %p\n", output_temp);
104 for(int i = 0; i < exit_nodes.total; i++)
106 VirtualANode *node = (VirtualANode*)exit_nodes.values[i];
107 Track *track = node->track;
109 //printf("VirtualAConsole::process_buffer 2 %d %p\n", i, output_temp);
110 result |= node->render(output_temp,
111 start_position + track->nudge,
113 renderengine->edl->session->sample_rate);
114 //printf("VirtualAConsole::process_buffer 3 %p\n", output_temp);
116 //printf("VirtualAConsole::process_buffer 4\n");
119 // get peaks and limit volume in the fragment
120 for(int i = 0; i < MAX_CHANNELS; i++)
122 double *current_buffer = arender->audio_out[i];
126 for(int j = 0; j < len; )
128 int meter_render_end;
129 // Get length to test for meter and limit
130 if(renderengine->command->realtime)
131 meter_render_end = j + arender->meter_render_fragment;
133 meter_render_end = len;
135 if(meter_render_end > len)
136 meter_render_end = len;
140 for( ; j < meter_render_end; j++)
142 // Level history comes before clipping to get over status
143 double *sample = ¤t_buffer[j];
146 if(fabs(*sample) > peak) peak = fabs(*sample);
147 // Make the output device clip it
148 // if(*sample > 1) *sample = 1;
150 // if(*sample < -1) *sample = -1;
154 if(renderengine->command->realtime)
156 arender->level_history[i][arender->current_level[i]] = peak;
157 arender->level_samples[arender->current_level[i]] =
158 renderengine->command->get_direction() == PLAY_REVERSE ?
161 arender->current_level[i] = arender->get_next_peak(arender->current_level[i]);
169 //printf("VirtualAConsole::process_buffer 5\n");
172 // Pack channels, fix speed and send to device.
173 if(renderengine->command->realtime && !interrupt)
176 // length compensated for speed
181 double *audio_out_packed[MAX_CHANNELS];
183 for(int i = 0, j = 0; i < MAX_CHANNELS; i++)
185 if(renderengine->config->aconfig->do_channel[i])
187 audio_out_packed[j++] = arender->audio_out[i];
192 i < renderengine->config->aconfig->total_playable_channels();
198 double *current_buffer = audio_out_packed[i];
200 // Time stretch the fragment to the real_output size
201 if(renderengine->command->get_speed() > 1)
203 // Number of samples in real output buffer for each to sample rendered.
204 int interpolate_len = (int)renderengine->command->get_speed();
205 for(in = 0, out = 0; in < len; )
208 for(k = 0; k < interpolate_len; k++)
210 sample += current_buffer[in++];
212 sample /= renderengine->command->get_speed();
213 current_buffer[out++] = sample;
215 real_output_len = out;
218 if(renderengine->command->get_speed() < 1)
220 // number of samples to skip
221 int interpolate_len = (int)(1.0 / renderengine->command->get_speed());
222 real_output_len = len * interpolate_len;
224 for(in = len - 1, out = real_output_len - 1; in >= 0; )
226 for(k = 0; k < interpolate_len; k++)
228 current_buffer[out--] = current_buffer[in];
234 real_output_len = len;
237 // Wait until video is ready
238 if(arender->first_buffer)
240 renderengine->first_frame_lock->lock("VirtualAConsole::process_buffer");
241 arender->first_buffer = 0;
243 if(!renderengine->audio->get_interrupted())
245 renderengine->audio->write_buffer(audio_out_packed,
247 renderengine->config->aconfig->total_playable_channels());
250 if(renderengine->audio->get_interrupted()) interrupt = 1;
256 //printf("VirtualAConsole::process_buffer 100\n");
288 int VirtualAConsole::init_rendering(int duplicate)
294 int VirtualAConsole::send_last_output_buffer()
296 renderengine->audio->set_last_buffer();