missing commit in generator.h
[galan.git] / plugins / libpowerspectrum.c
blob1501c686e7c84cf146c6a7ab8db40ead01ecfbb2
1 /* gAlan - Graphical Audio Language
2 * Copyright (C) 1999 Tony Garnock-Jones
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <stdlib.h>
20 #include <string.h>
21 #include <stdio.h>
22 #include <stddef.h>
24 #include <gdk/gdk.h>
25 #include <gtk/gtk.h>
27 #include "global.h"
28 #include "generator.h"
29 #include "comp.h"
30 #include "control.h"
31 #include "gencomp.h"
34 #define GENERATOR_CLASS_NAME "power_spec"
35 #define GENERATOR_CLASS_PATH "Misc/PowerSpectrum"
37 #define SIG_INPUT 0
38 #define SIG_OUTPUT 0
40 #define EVT_INPUT 0
41 #define NUM_EVENT_INPUTS 1
43 #define EVT_OUTPUT 0
44 #define NUM_EVENT_OUTPUTS 1
46 typedef struct Data {
47 } Data;
49 PRIVATE int init_instance(Generator *g) {
50 //Data *data = safe_malloc(sizeof(Data));
51 //g->data = data;
53 return 1;
56 PRIVATE void destroy_instance(Generator *g) {
58 //Data *data = g->data;
60 //free(data);
63 PRIVATE void unpickle_instance(Generator *g, ObjectStoreItem *item, ObjectStore *db) {
64 //Data *data = safe_malloc(sizeof(Data));
66 //g->data = data;
69 PRIVATE void pickle_instance(Generator *g, ObjectStoreItem *item, ObjectStore *db) {
70 //Data *data = g->data;
73 PRIVATE void evt_input_handler(Generator *g, AEvent *event) {
74 //Data *data = g->data;
75 int i,len;
76 SAMPLE *out, *in;
77 AEvent send_ev;
79 RETURN_UNLESS( event->kind == AE_NUMARRAY );
80 //RETURN_UNLESS( (event->d.array.len & 1) == 0 );
82 in = event->d.array.numbers;
83 len = event->d.array.len;
85 out = g_alloca( sizeof( SAMPLE ) * (len/2+1) );
87 out[0] = in[0] * in [0];
88 for( i=1; i<(len+1)/2; i++ )
89 out[i] = in[i]*in[i] + in[len-i] * in[len-i];
91 if( (len & 1) == 0 )
92 out[len/2] = in[len/2] * in[len/2];
95 gen_init_aevent(&send_ev, AE_NUMARRAY, NULL, 0, NULL, 0, event->time);
97 send_ev.d.array.len = len/2+1;
98 send_ev.d.array.numbers = out;
101 gen_send_events(g, EVT_OUTPUT, -1, &send_ev);
104 PRIVATE ControlDescriptor controls[] = {
105 /* { kind, name, min,max,step,page, size,editable, is_dst,queue_number,
106 init,destroy,refresh,refresh_data }, */
107 { CONTROL_KIND_NONE, },
110 PRIVATE void setup_class(void) {
111 GeneratorClass *k = gen_new_generatorclass(GENERATOR_CLASS_NAME, FALSE,
112 NUM_EVENT_INPUTS, NUM_EVENT_OUTPUTS,
113 NULL, NULL, controls,
114 init_instance, destroy_instance,
115 unpickle_instance, pickle_instance);
117 gen_configure_event_input(k, EVT_INPUT, "Input", evt_input_handler);
118 gen_configure_event_output(k, EVT_OUTPUT, "Output" );
120 gencomp_register_generatorclass(k, FALSE, GENERATOR_CLASS_PATH, NULL, NULL);
123 PUBLIC void init_plugin(void) {
124 setup_class();