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
99 if( !is_processed || this->start_position != start_position ||
100 this->len != len || this->sample_rate != sample_rate ) {
102 this->start_position = start_position;
104 this->sample_rate = sample_rate;
107 // Allocate buffer vector
108 new_buffer_vector(virtual_plugins.total, len);
111 plugin_servers.values[0]->process_buffer(
112 buffer_vector, start_position, len, sample_rate,
113 plugin->length * sample_rate /
114 renderengine->get_edl()->session->sample_rate,
115 renderengine->command->get_direction());
117 memcpy(output->get_data(),
118 buffer_vector[buffer_number]->get_data(),
119 sizeof(double) * len);
124 Samples *output_temp[1];
125 output_temp[0] = output;
127 if(0) printf("AAttachmentPoint::render %d buffer_number=%d renderengine=%p plugin_server=%p\n",
131 plugin_servers.values[buffer_number]);
132 plugin_servers.values[buffer_number]->process_buffer(output_temp,
138 renderengine->get_edl()->session->sample_rate,
139 renderengine->command->get_direction());