1 #include "aattachmentpoint.h"
11 #include "edlsession.h"
14 #include "floatautos.h"
18 #include "preferences.h"
19 #include "renderengine.h"
20 #include "mainsession.h"
21 #include "sharedlocation.h"
23 #include "transition.h"
24 #include "transportque.h"
28 #define _(String) gettext(String)
29 #define gettext_noop(String) String
30 #define N_(String) gettext_noop (String)
33 AModule::AModule(RenderEngine *renderengine,
34 CommonRender *commonrender,
35 PluginArray *plugin_array,
37 : Module(renderengine, commonrender, plugin_array, track)
39 data_type = TRACK_AUDIO;
50 if(transition_temp) delete [] transition_temp;
53 delete [] level_history;
54 delete [] level_samples;
58 AttachmentPoint* AModule::new_attachment(Plugin *plugin)
60 return new AAttachmentPoint(renderengine, plugin);
64 void AModule::create_objects()
66 Module::create_objects();
67 // Not needed in pluginarray
70 level_history = new double[((ARender*)commonrender)->history_size()];
71 level_samples = new int64_t[((ARender*)commonrender)->history_size()];
74 for(int i = 0; i < ((ARender*)commonrender)->history_size(); i++)
77 level_samples[i] = -1;
82 int AModule::get_buffer_size()
84 //printf("AModule::get_buffer_size 1 %p\n", get_edl());
85 return get_edl()->session->audio_module_fragment;
88 void AModule::reverse_buffer(double *buffer, int64_t len)
90 register int64_t start, end;
93 for(start = 0, end = len - 1; end > start; start++, end--)
96 buffer[start] = buffer[end];
102 CICache* AModule::get_cache()
105 return renderengine->get_acache();
110 int AModule::render(double *buffer,
112 int64_t input_position,
115 AEdit *playable_edit;
116 int64_t start_project = input_position;
117 int64_t end_project = input_position + input_len;
118 int64_t buffer_offset = 0;
122 //printf("AModule::render 1 %d %d\n", input_position, input_len);
124 // Flip range around so start_project < end_project
125 if(direction == PLAY_REVERSE)
127 start_project -= input_len;
128 end_project -= input_len;
131 bzero(buffer, input_len * sizeof(double));
133 //printf("AModule::render 2\n");
135 // Get first edit containing range
136 for(playable_edit = (AEdit*)track->edits->first;
138 playable_edit = (AEdit*)playable_edit->next)
140 double edit_start = playable_edit->startproject;
141 double edit_end = playable_edit->startproject + playable_edit->length;
143 if(start_project < edit_end && start_project + input_len > edit_start)
153 //printf("AModule::render 3\n");
156 // Fill output one fragment at a time
157 while(start_project < end_project)
159 int64_t fragment_len = input_len;
161 //printf("AModule::render 4 %d\n", fragment_len);
162 if(fragment_len + start_project > end_project)
163 fragment_len = end_project - start_project;
165 //printf("AModule::render 5 %d\n", fragment_len);
166 update_transition(start_project, PLAY_FORWARD);
171 //printf("AModule::render 6\n");
175 if(fragment_len + start_project >
176 playable_edit->startproject + playable_edit->length)
177 fragment_len = playable_edit->startproject +
178 playable_edit->length - start_project;
180 //printf("AModule::render 8 %d\n", fragment_len);
182 if(playable_edit->asset)
186 //printf("AModule::render 9\n");
189 if(!(source = get_cache()->check_out(playable_edit->asset)))
191 // couldn't open source file / skip the edit
193 printf(_("VirtualAConsole::load_track Couldn't open %s.\n"), playable_edit->asset->path);
199 //printf("AModule::render 10\n");
201 //printf("AModule::load_track 7 %d\n", start_project -
202 // playable_edit->startproject +
203 // playable_edit->startsource);
205 result = source->set_audio_position(start_project -
206 playable_edit->startproject +
207 playable_edit->startsource,
208 get_edl()->session->sample_rate);
209 //printf("AModule::render 10\n");
211 if(result) printf("AModule::render start_project=%d playable_edit->startproject=%d playable_edit->startsource=%d\n"
212 "source=%p playable_edit=%p edl=%p edlsession=%p sample_rate=%d\n",
213 start_project, playable_edit->startproject, playable_edit->startsource,
214 source, playable_edit, get_edl(), get_edl()->session, get_edl()->session->sample_rate);
216 source->set_channel(playable_edit->channel);
218 // printf("AModule::render 11 %p %p %d %d\n",
223 //printf("AModule::render 10 %p %p\n", source, playable_edit);
224 source->read_samples(buffer + buffer_offset,
226 get_edl()->session->sample_rate);
228 //printf("AModule::render 12 %d %d\n", fragment_len, get_edl()->session->sample_rate);
229 get_cache()->check_in(playable_edit->asset);
230 //printf("AModule::render 13\n");
239 // Read transition into temp and render
240 AEdit *previous_edit = (AEdit*)playable_edit->previous;
241 if(transition && previous_edit)
244 // Read into temp buffers
245 // Temp + master or temp + temp ? temp + master
248 transition_temp = new double[get_edl()->session->audio_read_length];
253 // Trim transition_len
254 int transition_len = fragment_len;
255 if(fragment_len + start_project >
256 playable_edit->startproject + transition->length)
257 fragment_len = playable_edit->startproject +
258 playable_edit->transition->length -
261 if(transition_len > 0)
263 if(previous_edit->asset)
266 if(!(source = get_cache()->check_out(previous_edit->asset)))
268 // couldn't open source file / skip the edit
269 printf(_("VirtualAConsole::load_track Couldn't open %s.\n"), playable_edit->asset->path);
276 result = source->set_audio_position(start_project -
277 previous_edit->startproject +
278 previous_edit->startsource,
279 get_edl()->session->sample_rate);
281 if(result) printf("AModule::render start_project=%d playable_edit->startproject=%d playable_edit->startsource=%d\n"
282 "source=%p playable_edit=%p edl=%p edlsession=%p sample_rate=%d\n",
284 previous_edit->startproject,
285 previous_edit->startsource,
290 get_edl()->session->sample_rate);
292 source->set_channel(previous_edit->channel);
294 source->read_samples(transition_temp,
296 get_edl()->session->sample_rate);
298 get_cache()->check_in(previous_edit->asset);
303 bzero(transition_temp, transition_len * sizeof(double));
306 double *output = buffer + buffer_offset;
307 transition_server->process_realtime(
310 start_project - playable_edit->startproject,
317 //printf("AModule::render 13\n");
318 buffer_offset += fragment_len;
319 start_project += fragment_len;
321 start_project >= playable_edit->startproject + playable_edit->length)
322 playable_edit = (AEdit*)playable_edit->next;
325 //printf("AModule::render 14\n");
327 // Reverse buffer here so plugins always render forward.
328 if(direction == PLAY_REVERSE)
329 reverse_buffer(buffer, input_len);
331 //printf("AModule::render 15\n");