missing commit in generator.h
[galan.git] / patches / galan-esd.patch
blobcf490240ca6cf40e089fee283b3988171f9eae0a
1 --- galan-0.2.0/plugins/Makefile.am.sopwith Fri Sep 17 22:05:52 1999
2 +++ galan-0.2.0/plugins/Makefile.am Sat Sep 18 21:32:17 1999
3 @@ -6,11 +6,15 @@
5 plugin_PROGRAMS = osc.so oss_output.so random.so rart.so voice.so ctrl.so gain.so \
6 clock.so vca.so delay.so patsel.so trigseq.so vcf.so sig2evt.so dcbias.so \
7 - resample.so xfade.so atan.so evtadd.so evtmul.so seqnum.so adsr.so seqnote.so
8 + resample.so xfade.so atan.so evtadd.so evtmul.so seqnum.so adsr.so seqnote.so \
9 + esd_output.so
11 LDFLAGS = -shared
12 LDADD = @GTK_LIBS@
14 +esd_output_so_INCLUDES=`esd-config --cflags`
15 +esd_output_so_LDFLAGS=`esd-config --libs`
17 osc_so_SOURCES = osc.c
18 oss_output_so_SOURCES = oss_output.c
19 random_so_SOURCES = random.c
20 @@ -34,5 +38,6 @@
21 seqnum_so_SOURCES = seqnum.c
22 adsr_so_SOURCES = adsr.c
23 seqnote_so_SOURCES = seqnote.c
24 +esd_output_so_SOURCES = esd_output.c
26 INCLUDES = -I.. -I$(srcdir)/../include @GTK_CFLAGS@ -DSITE_PKGLIB_DIR=\"$(pkglibdir)\"
27 --- galan-0.2.0/plugins/esd_output.c.sopwith Sat Sep 18 21:30:19 1999
28 +++ galan-0.2.0/plugins/esd_output.c Sat Sep 18 21:37:56 1999
29 @@ -0,0 +1,194 @@
30 +/* gAlan - Graphical Audio Language
31 + * Copyright (C) 1999 Tony Garnock-Jones
32 + * Copyright (C) 1999 Elliot Lee
33 + *
34 + * This program is free software; you can redistribute it and/or modify
35 + * it under the terms of the GNU General Public License as published by
36 + * the Free Software Foundation; either version 2 of the License, or
37 + * (at your option) any later version.
38 + *
39 + * This program is distributed in the hope that it will be useful,
40 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
41 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 + * GNU General Public License for more details.
43 + *
44 + * You should have received a copy of the GNU General Public License
45 + * along with this program; if not, write to the Free Software
46 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
47 + */
48 +/* esd_output.c - gAlan filter to output to the Enlightened (NOT!) sound daemon */
50 +#include <stdlib.h>
51 +#include <string.h>
52 +#include <stdio.h>
54 +#include <sys/types.h>
55 +#include <sys/ioctl.h>
56 +#include <fcntl.h>
57 +#include <unistd.h>
59 +#include <esd.h>
61 +#include <gtk/gtk.h>
63 +#include "global.h"
64 +#include "generator.h"
65 +#include "comp.h"
66 +#include "control.h"
67 +#include "gencomp.h"
68 +#include "msgbox.h"
70 +#define SIG_LEFT_CHANNEL 0
71 +#define SIG_RIGHT_CHANNEL 1
73 +#define AUDIO_FRAGMENT_EXPONENT 12
74 +#define AUDIO_FRAGMENT_LENGTH (1<<AUDIO_FRAGMENT_EXPONENT)
76 +typedef signed short OUTPUTSAMPLE;
78 +typedef struct OSSData {
79 + int audiofd;
80 + gint input_tag;
81 + AClock *clock;
82 +} OSSData;
84 +PRIVATE int instance_count = 0;
86 +PRIVATE void audio_play_fragment(int audiofd, SAMPLE *left, SAMPLE *right, int length) {
87 + OUTPUTSAMPLE *outbuf;
88 + int buflen = length * sizeof(OUTPUTSAMPLE) * 2;
89 + int i;
91 + if (length <= 0)
92 + return;
94 + outbuf = malloc(buflen);
95 + g_return_if_fail(outbuf != NULL);
97 + for (i = 0; i < length; i++) {
98 + outbuf[i<<1] = (OUTPUTSAMPLE) MIN(MAX(left[i] * 32767, -32768), 32767);
99 + outbuf[(i<<1) + 1] = (OUTPUTSAMPLE) MIN(MAX(right[i] * 32767, -32768), 32767);
102 + write(audiofd, outbuf, buflen);
103 + free(outbuf);
106 +PRIVATE int open_audiofd(void) {
107 + return esd_play_stream_fallback(ESD_BITS16|ESD_STEREO, 44100, NULL, "esd_output");
110 +PRIVATE void clock_handler(AClock *clock, AClockReason reason) {
111 + OSSData *data = clock->gen->data;
113 + switch (reason) {
114 + case CLOCK_DISABLE:
115 + gdk_input_remove(data->input_tag);
116 + data->input_tag = -1;
117 + break;
119 + case CLOCK_ENABLE:
120 + if (data->input_tag == -1)
121 + data->input_tag = gdk_input_add(data->audiofd, GDK_INPUT_WRITE,
122 + (GdkInputFunction) gen_clock_mainloop, NULL);
123 + break;
125 + default:
126 + g_message("Unreachable code reached (esd_output)... reason = %d", reason);
127 + break;
131 +PRIVATE void realtime_handler(Generator *g, AEvent *event) {
132 + OSSData *data = g->data;
134 + switch (event->kind) {
135 + case AE_REALTIME: {
136 + SAMPLE *l_buf, *r_buf;
138 + l_buf = calloc(event->d.integer, sizeof(SAMPLE));
139 + r_buf = calloc(event->d.integer, sizeof(SAMPLE));
141 + gen_read_realtime_input(g, SIG_LEFT_CHANNEL, -1, l_buf, event->d.integer);
142 + gen_read_realtime_input(g, SIG_RIGHT_CHANNEL, -1, r_buf, event->d.integer);
144 + audio_play_fragment(data->audiofd, l_buf, r_buf, event->d.integer);
145 + free(l_buf);
146 + free(r_buf);
148 + break;
151 + default:
152 + g_warning("esd_output module doesn't care for events of kind %d.", event->kind);
153 + break;
157 +PRIVATE int init_instance(Generator *g) {
158 + OSSData *data;
160 + instance_count++;
161 + if (instance_count > 1)
162 + /* Not allowed more than one of these things. */
163 + return 0;
165 + data = malloc(sizeof(OSSData));
166 + g_return_val_if_fail(data != NULL, 0);
168 + data->audiofd = open_audiofd();
170 + if (data->audiofd < 0) {
171 + free(data);
172 + popup_msgbox("Error", MSGBOX_OK, 120000, MSGBOX_OK, "Could not open audio subsystem.");
173 + return 0;
176 + data->input_tag = -1;
177 + data->clock = gen_register_clock(g, "ESD Output Clock", clock_handler);
179 + g->data = data;
181 + gen_register_realtime_fn(g, realtime_handler);
182 + gen_select_clock(data->clock); /* a not unreasonable assumption? */
184 + return 1;
187 +PRIVATE void destroy_instance(Generator *g) {
188 + OSSData *data = g->data;
190 + gen_deregister_realtime_fn(g, realtime_handler);
192 + if (data != NULL) {
193 + gen_deregister_clock(data->clock);
194 + if (data->input_tag != -1)
195 + gdk_input_remove(data->input_tag);
196 + close(data->audiofd);
198 + free(data);
201 + instance_count--;
204 +PRIVATE InputSignalDescriptor input_sigs[] = {
205 + { "Left Channel", SIG_FLAG_REALTIME },
206 + { "Right Channel", SIG_FLAG_REALTIME },
207 + { NULL, }
210 +PRIVATE void setup_class(void) {
211 + GeneratorClass *k = gen_new_generatorclass("audio_out", 0, 0,
212 + input_sigs, NULL, NULL,
213 + init_instance, destroy_instance,
214 + (AGenerator_pickle_t) init_instance, NULL);
216 + gencomp_register_generatorclass(k, "Outputs/ESound Output",
217 + PIXMAPDIRIFY("oss_output.xpm"),
218 + NULL);
221 +PUBLIC void init_plugin_esd_output(void) {
222 + setup_class();