Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / cinelerra / aattachmentpoint.C
blob450da51962b8b5826b4b790d7c81321fc1a6abe0
1 #include "aattachmentpoint.h"
2 #include "datatype.h"
3 #include "edl.h"
4 #include "edlsession.h"
5 #include "playbackconfig.h"
6 #include "plugin.h"
7 #include "pluginserver.h"
8 #include "renderengine.h"
9 #include "transportque.h"
11 AAttachmentPoint::AAttachmentPoint(RenderEngine *renderengine, Plugin *plugin)
12 : AttachmentPoint(renderengine, plugin, TRACK_AUDIO)
14         buffer_vector = 0;
15         buffer_allocation = 0;
18 AAttachmentPoint::~AAttachmentPoint()
20         delete_buffer_vector();
23 void AAttachmentPoint::delete_buffer_vector()
25         if(buffer_vector)
26         {
27                 for(int i = 0; i < virtual_plugins.total; i++)
28                         delete [] buffer_vector[i];
29                 delete [] buffer_vector;
30         }
31         buffer_vector = 0;
32         buffer_allocation = 0;
35 void AAttachmentPoint::new_buffer_vector(int total, int size)
37         if(buffer_vector && size > buffer_allocation)
38                 delete_buffer_vector();
40         if(!buffer_vector)
41         {
42                 buffer_allocation = size;
43                 buffer_vector = new double*[virtual_plugins.total];
44                 for(int i = 0; i < virtual_plugins.total; i++)
45                 {
46                         buffer_vector[i] = new double[buffer_allocation];
47                 }
48         }
51 int AAttachmentPoint::get_buffer_size()
53         return renderengine->config->aconfig->fragment_size;
54 // must be greater than value audio_read_length, calculated in PackageRenderer::create_engine
55 // if it is not, plugin's PluginClient::in_buffer_size is below the real maximum and
56 // we get a crush on rendering of audio plugins!
57 //      int audio_read_length = renderengine->command->get_edl()->session->sample_rate;
58 //      int fragment_size = renderengine->config->aconfig->fragment_size;
59 //      if(audio_read_length > fragment_size)
60 //              return audio_read_length;
61 //      else
62 //              return fragment_size;
65 void AAttachmentPoint::render(double *output, 
66         int buffer_number,
67         int64_t start_position, 
68         int64_t len,
69         int64_t sample_rate)
71         if(!plugin_server || !plugin->on) return;
73         if(plugin_server->multichannel)
74         {
75 // Test against previous parameters for reuse of previous data
76                 if(is_processed &&
77                         this->start_position == start_position && 
78                         this->len == len && 
79                         this->sample_rate == sample_rate)
80                 {
81                         memcpy(output, buffer_vector[buffer_number], sizeof(double) * len);
82                         return;
83                 }
85 // Update status
86                 this->start_position = start_position;
87                 this->len = len;
88                 this->sample_rate = sample_rate;
89                 is_processed = 1;
91 // Allocate buffer vector
92                 new_buffer_vector(virtual_plugins.total, len);
94 // Create temporary buffer vector with output argument substituted in
95                 double **output_temp = new double*[virtual_plugins.total];
96                 for(int i = 0; i < virtual_plugins.total; i++)
97                 {
98                         if(i == buffer_number)
99                                 output_temp[i] = output;
100                         else
101                                 output_temp[i] = buffer_vector[i];
102                 }
104 // Process plugin
105                 plugin_servers.values[0]->process_buffer(output_temp,
106                         start_position,
107                         len,
108                         sample_rate,
109                         plugin->length *
110                                 sample_rate /
111                                 renderengine->edl->session->sample_rate,
112                         renderengine->command->get_direction());
114 // Delete temporary buffer vector
115                 delete [] output_temp;
116         }
117         else
118         {
119 // Process plugin
120                 double *output_temp[1];
121                 output_temp[0] = output;
122 //printf("AAttachmentPoint::render 1\n");
123                 plugin_servers.values[buffer_number]->process_buffer(output_temp,
124                         start_position,
125                         len,
126                         sample_rate,
127                         plugin->length *
128                                 sample_rate /
129                                 renderengine->edl->session->sample_rate,
130                         renderengine->command->get_direction());
131 //printf("AAttachmentPoint::render 10\n");
132         }
137 //      Local Variables:
138 //      mode: C++
139 //      c-file-style: "linux"
140 //      End: