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];
127 for(int j = 0; j < len; )
129 int meter_render_end;
130 // Get length to test for meter and limit
131 if(renderengine->command->realtime)
132 meter_render_end = j + arender->meter_render_fragment;
134 meter_render_end = len;
136 if(meter_render_end > len)
137 meter_render_end = len;
141 for( ; j < meter_render_end; j++)
143 // Level history comes before clipping to get over status
144 double *sample = ¤t_buffer[j];
147 if(fabs(*sample) > peak) peak = fabs(*sample);
148 // Make the output device clip it
149 // if(*sample > 1) *sample = 1;
151 // if(*sample < -1) *sample = -1;
155 if(renderengine->command->realtime)
157 arender->level_history[i][arender->current_level[i]] = peak;
158 arender->level_samples[arender->current_level[i]] =
159 renderengine->command->get_direction() == PLAY_REVERSE ?
162 arender->current_level[i] = arender->get_next_peak(arender->current_level[i]);
170 //printf("VirtualAConsole::process_buffer 5\n");
173 // Pack channels, fix speed and send to device.
174 if(renderengine->command->realtime && !interrupt)
177 // length compensated for speed
182 double *audio_out_packed[MAX_CHANNELS];
183 int audio_channels = renderengine->edl->session->audio_channels;
185 for(int i = 0, j = 0;
189 audio_out_packed[j++] = arender->audio_out[i];
199 double *current_buffer = audio_out_packed[i];
201 // Time stretch the fragment to the real_output size
202 if(renderengine->command->get_speed() > 1)
204 // Number of samples in real output buffer for each to sample rendered.
205 int interpolate_len = (int)renderengine->command->get_speed();
206 for(in = 0, out = 0; in < len; )
209 for(k = 0; k < interpolate_len; k++)
211 sample += current_buffer[in++];
213 sample /= renderengine->command->get_speed();
214 current_buffer[out++] = sample;
216 real_output_len = out;
219 if(renderengine->command->get_speed() < 1)
221 // number of samples to skip
222 int interpolate_len = (int)(1.0 / renderengine->command->get_speed());
223 real_output_len = len * interpolate_len;
225 for(in = len - 1, out = real_output_len - 1; in >= 0; )
227 for(k = 0; k < interpolate_len; k++)
229 current_buffer[out--] = current_buffer[in];
235 real_output_len = len;
238 // Wait until video is ready
239 if(arender->first_buffer)
241 renderengine->first_frame_lock->lock("VirtualAConsole::process_buffer");
242 arender->first_buffer = 0;
244 if(!renderengine->audio->get_interrupted())
246 renderengine->audio->write_buffer(audio_out_packed,
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();