r105: This commit was manufactured by cvs2svn to create tag
[cinelerra_cv/mob.git] / hvirtual / plugins / reverseaudio / reverseaudio.C
blob94a8b9e0fabe0f968cf3f70b9336faf87aa2f86c
1 #include "mainprogress.h"
2 #include "reverseaudio.h"
4 #include <stdio.h>
5 #include <string.h>
7 #include <libintl.h>
8 #define _(String) gettext(String)
9 #define gettext_noop(String) String
10 #define N_(String) gettext_noop (String)
13 PluginClient* new_plugin(PluginServer *server)
15         return new ReverseAudio(server);
18 ReverseAudio::ReverseAudio(PluginServer *server)
19  : PluginAClient(server)
23 ReverseAudio::~ReverseAudio()
27 char* ReverseAudio::plugin_title() { return _("Reverse audio"); }
29 int ReverseAudio::is_realtime() { return 0; }
31 VFrame* ReverseAudio::new_picon()
33         return 0;
36 int ReverseAudio::start_loop()
38 //printf("ReverseAudio::start_loop 1\n");
39         if(PluginClient::interactive)
40         {
41                 char string[BCTEXTLEN];
42                 sprintf(string, "%s...", plugin_title());
43                 progress = start_progress(string, 
44                         (PluginClient::end - PluginClient::start));
45         }
47         current_position = PluginClient::end;
48         total_written = 0;
49 //printf("ReverseAudio::start_loop 2\n");
50         return 0;
54 int ReverseAudio::stop_loop()
56         if(PluginClient::interactive)
57         {
58                 progress->stop_progress();
59                 delete progress;
60         }
61         return 0;
64 int ReverseAudio::process_loop(double *buffer, int64_t &write_length)
66         int result = 0;
67         int64_t fragment_len;
68 //printf("ReverseAudio::process_loop 1\n");
70         fragment_len = PluginClient::in_buffer_size;
71 //printf("ReverseAudio::process_loop 2\n");
72         if(current_position - fragment_len < PluginClient::start)
73         {
74                 fragment_len = current_position - PluginClient::start;
75                 result = 1;
76         }
77 //printf("ReverseAudio::process_loop 3 %d %d\n", current_position, fragment_len);
79         read_samples(buffer, current_position - fragment_len, fragment_len);
81 //printf("ReverseAudio::process_loop 4 %p\n", buffer);
82         for(int j = 0; j < fragment_len / 2; j++)
83         {
84                 double sample = buffer[j];
85                 buffer[j] = buffer[fragment_len - 1 - j];
86                 buffer[fragment_len - 1 -j] = sample;
87         }
88 //printf("ReverseAudio::process_loop 5 %d\n", current_position);
90         current_position -= fragment_len;
91 //printf("ReverseAudio::process_loop 6 %d\n", current_position);
92         total_written += fragment_len;
93         write_length = fragment_len;
94         if(PluginClient::interactive) result = progress->update(total_written);
95 //printf("ReverseAudio::process_loop 7 %d\n", current_position);
97         return result;