upgraded x265,ffmpeg,tdb,it.po fixed tab armed toggle
[goodguy/history.git] / cinelerra-5.1 / cinelerra / aattachmentpoint.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
5  * 
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.
10  * 
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.
15  * 
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
19  * 
20  */
21
22 #include "aattachmentpoint.h"
23 #include "bcsignals.h"
24 #include "datatype.h"
25 #include "edl.h"
26 #include "edlsession.h"
27 #include "playbackconfig.h"
28 #include "plugin.h"
29 #include "pluginserver.h"
30 #include "renderengine.h"
31 #include "samples.h"
32 #include "transportque.h"
33
34 AAttachmentPoint::AAttachmentPoint(RenderEngine *renderengine, Plugin *plugin)
35 : AttachmentPoint(renderengine, plugin, TRACK_AUDIO)
36 {
37         buffer_vector = 0;
38         buffer_allocation = 0;
39 }
40
41 AAttachmentPoint::~AAttachmentPoint()
42 {
43         delete_buffer_vector();
44 }
45
46 void AAttachmentPoint::delete_buffer_vector()
47 {
48         if(buffer_vector)
49         {
50                 for(int i = 0; i < virtual_plugins.total; i++)
51                         delete buffer_vector[i];
52                 delete [] buffer_vector;
53         }
54         buffer_vector = 0;
55         buffer_allocation = 0;
56 }
57
58 void AAttachmentPoint::new_buffer_vector(int total, int size)
59 {
60         if(buffer_vector && size > buffer_allocation)
61                 delete_buffer_vector();
62
63         if(!buffer_vector)
64         {
65                 buffer_allocation = size;
66                 buffer_vector = new Samples*[virtual_plugins.total];
67                 for(int i = 0; i < virtual_plugins.total; i++)
68                 {
69                         buffer_vector[i] = new Samples(buffer_allocation);
70                 }
71         }
72 }
73
74 int AAttachmentPoint::get_buffer_size()
75 {
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;
84 //      else
85 //              return fragment_size;
86 }
87
88 void AAttachmentPoint::render(Samples *output, 
89         int buffer_number,
90         int64_t start_position, 
91         int64_t len,
92         int64_t sample_rate)
93 {
94         if(!plugin_server || !plugin->on) return;
95
96         if(plugin_server->multichannel)
97         {
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 ) {
101 // Update status
102                         this->start_position = start_position;
103                         this->len = len;
104                         this->sample_rate = sample_rate;
105                         is_processed = 1;
106
107 // Allocate buffer vector
108                         new_buffer_vector(virtual_plugins.total, len);
109
110 // Process plugin
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());
116                 }
117                 memcpy(output->get_data(), 
118                         buffer_vector[buffer_number]->get_data(), 
119                         sizeof(double) * len);
120         }
121         else
122         {
123 // Process plugin
124                 Samples *output_temp[1];
125                 output_temp[0] = output;
126
127 if(0) printf("AAttachmentPoint::render %d buffer_number=%d renderengine=%p plugin_server=%p\n", 
128 __LINE__, 
129 buffer_number,
130 renderengine,
131 plugin_servers.values[buffer_number]);
132                 plugin_servers.values[buffer_number]->process_buffer(output_temp,
133                         start_position,
134                         len,
135                         sample_rate,
136                         plugin->length *
137                                 sample_rate /
138                                 renderengine->get_edl()->session->sample_rate,
139                         renderengine->command->get_direction());
140         }
141 }
142
143