1 /*
2  * Sweep, a sound wave editor.
3  *
4  * Copyright (C) 2000 Conrad Parker
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 #include <stdio.h>
22 #include <string.h>
23 #include <gdk/gdkkeysyms.h>
24 
25 #include <sweep/sweep.h>
26 
27 
28 #define NR_PARAMS 2
29 
30 #ifndef __GNUC__
31 #error GCCisms used here. Please report this error to \
32 sweep-devel@lists.sourceforge.net stating your versions of sweep \
33 and your operating system and compiler.
34 #endif
35 
36 
37 static sw_param_range delay_range = {
38   SW_RANGE_LOWER_BOUND_VALID|SW_RANGE_STEP_VALID,
39   lower: {f: 0.0},
40   step:  {f: 0.001}
41 };
42 
43 static sw_param_range gain_range = {
44   SW_RANGE_ALL_VALID,
45   lower: {f: 0.0},
46   upper: {f: 1.0},
47   step: {f: 0.01}
48 };
49 
50 
51 static sw_param_spec param_specs[] = {
52   {
53     N_("Delay"),
54     N_("Time to delay by"),
55     SWEEP_TYPE_FLOAT,
56     SW_PARAM_CONSTRAINED_RANGE,
57     {range: &delay_range},
58     SW_PARAM_HINT_TIME
59   },
60   {
61     N_("Gain"),
62     N_("Gain with which to mix in delayed signal"),
63     SWEEP_TYPE_FLOAT,
64     SW_PARAM_CONSTRAINED_RANGE,
65     {range: &gain_range},
66     SW_PARAM_HINT_DEFAULT
67   },
68 };
69 
70 static void
echo_suggest(sw_sample * sample,sw_param_set pset,gpointer custom_data)71 echo_suggest (sw_sample * sample, sw_param_set pset, gpointer custom_data)
72 {
73   pset[0].f = 0.0;
74   pset[1].f = 0.0;
75 }
76 
77 static void
region_echo(gpointer data,sw_format * format,sw_framecount_t nr_frames,sw_param_set pset,gpointer custom_data)78 region_echo (gpointer data, sw_format * format, sw_framecount_t nr_frames,
79 	     sw_param_set pset, gpointer custom_data)
80 {
81   gfloat delay = pset[0].f;
82   gfloat gain = pset[1].f;
83 
84   sw_framecount_t i, delay_f, dlen_s;
85   sw_audio_t * d, * e;
86   gpointer ep;
87 
88   delay_f = time_to_frames (format, delay);
89 
90   d = (sw_audio_t *)data;
91   ep = data + frames_to_bytes (format, delay_f);
92   e = (sw_audio_t *)ep;
93 
94   if (delay > nr_frames) return;
95 
96   dlen_s = frames_to_samples (format, nr_frames - delay_f);
97 
98   for (i = 0; i < dlen_s; i++) {
99     e[i] += (sw_audio_t)((gfloat)(d[i]) * gain);
100   }
101 }
102 
103 static sw_op_instance *
echo_apply(sw_sample * sample,sw_param_set pset,gpointer custom_data)104 echo_apply (sw_sample * sample, sw_param_set pset, gpointer custom_data)
105 {
106   return
107     perform_filter_region_op (sample, _("Echo"),
108 			      (SweepFilterRegion)region_echo, pset, NULL);
109 }
110 
111 
112 static sw_procedure proc_echo = {
113   N_("Echo"),
114   N_("Apply an echo to selected regions of a sample"),
115   "Conrad Parker",
116   "Copyright (C) 2000",
117   "http://sweep.sourceforge.net/plugins/echo",
118   "Filters/Echo", /* identifier */
119   GDK_e, /* accel_key */
120   GDK_SHIFT_MASK, /* accel_mods */
121   NR_PARAMS, /* nr_params */
122   param_specs, /* param_specs */
123   echo_suggest, /* suggests() */
124   echo_apply,
125   NULL, /* custom_data */
126 };
127 
128 static GList *
echo_init(void)129 echo_init (void)
130 {
131   return g_list_append ((GList *)NULL, &proc_echo);
132 }
133 
134 
135 sw_plugin plugin = {
136   echo_init, /* plugin_init */
137   NULL, /* plugin_cleanup */
138 };
139