4 * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "aattachmentpoint.h"
23 #include "bcsignals.h"
26 #include "edlsession.h"
27 #include "playbackconfig.h"
29 #include "pluginserver.h"
30 #include "renderengine.h"
32 #include "transportque.h"
34 AAttachmentPoint::AAttachmentPoint(RenderEngine *renderengine, Plugin *plugin)
35 : AttachmentPoint(renderengine, plugin, TRACK_AUDIO)
38 buffer_allocation = 0;
41 AAttachmentPoint::~AAttachmentPoint()
43 delete_buffer_vector();
46 void AAttachmentPoint::delete_buffer_vector()
50 for(int i = 0; i < virtual_plugins.total; i++)
51 delete buffer_vector[i];
52 delete [] buffer_vector;
55 buffer_allocation = 0;
58 void AAttachmentPoint::new_buffer_vector(int total, int size)
60 if(buffer_vector && size > buffer_allocation)
61 delete_buffer_vector();
65 buffer_allocation = size;
66 buffer_vector = new Samples*[virtual_plugins.total];
67 for(int i = 0; i < virtual_plugins.total; i++)
69 buffer_vector[i] = new Samples(buffer_allocation);
74 int AAttachmentPoint::get_buffer_size()
76 return renderengine->config->aconfig->fragment_size;
77 // must be greater than value audio_read_length, calculated in PackageRenderer::create_engine
78 // if it is not, plugin's PluginClient::in_buffer_size is below the real maximum and
79 // we get a crush on rendering of audio plugins!
80 // int audio_read_length = renderengine->command->get_edl()->session->sample_rate;
81 // int fragment_size = renderengine->config->aconfig->fragment_size;
82 // if(audio_read_length > fragment_size)
83 // return audio_read_length;
85 // return fragment_size;
88 void AAttachmentPoint::render(Samples *output,
90 int64_t start_position,
94 if(!plugin_server || !plugin->on) return;
96 if(plugin_server->multichannel)
98 // Test against previous parameters for reuse of previous data
100 this->start_position == start_position &&
102 this->sample_rate == sample_rate)
104 memcpy(output->get_data(),
105 buffer_vector[buffer_number]->get_data(),
106 sizeof(double) * len);
111 this->start_position = start_position;
113 this->sample_rate = sample_rate;
116 // Allocate buffer vector
117 new_buffer_vector(virtual_plugins.total, len);
119 // Create temporary buffer vector with output argument substituted in
120 Samples **output_temp = new Samples*[virtual_plugins.total];
121 for(int i = 0; i < virtual_plugins.total; i++)
123 if(i == buffer_number)
124 output_temp[i] = output;
126 output_temp[i] = buffer_vector[i];
130 plugin_servers.values[0]->process_buffer(output_temp,
136 renderengine->get_edl()->session->sample_rate,
137 renderengine->command->get_direction());
139 // Delete temporary buffer vector
140 delete [] output_temp;
145 Samples *output_temp[1];
146 output_temp[0] = output;
148 if(0) printf("AAttachmentPoint::render %d buffer_number=%d renderengine=%p plugin_server=%p\n",
152 plugin_servers.values[buffer_number]);
153 plugin_servers.values[buffer_number]->process_buffer(output_temp,
159 renderengine->get_edl()->session->sample_rate,
160 renderengine->command->get_direction());