annotate Plugins/Input/tonegen/tonegen.c @ 334:0daaddb10914 trunk

[svn] Implement GYM playback.
author chainsaw
date Sun, 25 Dec 2005 13:31:46 -0800
parents bd8457b077cf
children 7fa1738514d5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
2 * Copyright 2000,2001 Haavard Kvaalen <havardk@sol.no>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
3 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
4 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
7 * the Free Software Foundation; either version 2 of the License, or
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
8 * (at your option) any later version.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
9 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
13 * GNU General Public License for more details.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
14 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
16 * along with this program; if not, write to the Free Software
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
18 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
19
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
20 #include "audacious/plugin.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
21 #include "libaudacious/util.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
22 #include "config.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
23 #include <glib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
24 #include <stdlib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
25 #include <string.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
26 #include <math.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
27 #include <stdio.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
28 #include <glib/gi18n.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
29
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
30 #define MIN_FREQ 10
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
31 #define MAX_FREQ 20000
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
32 #define OUTPUT_FREQ 44100
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
33
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
34 #ifndef PI
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
35 #define PI 3.14159265358979323846
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
36 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
37
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
38 static InputPlugin tone_ip;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
39
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
40 static gboolean going;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
41 static gboolean audio_error;
172
08d65e21e357 [svn] Use GThread instead of pthread.
chainsaw
parents: 61
diff changeset
42 static GThread *play_thread;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
43
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
44 static void tone_about(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
45 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
46 static GtkWidget *box;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
47 box = xmms_show_message(
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
48 _("About Tone Generator"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
49 /* I18N: UTF-8 Translation: "Haavard Kvaalen" -> "H\303\245vard Kv\303\245len" */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
50 _("Sinus tone generator by Haavard Kvaalen <havardk@xmms.org>\n"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
51 "Modified by Daniel J. Peng <danielpeng@bigfoot.com>\n\n"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
52 "To use it, add a URL: tone://frequency1;frequency2;frequency3;...\n"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
53 "e.g. tone://2000;2005 to play a 2000Hz tone and a 2005Hz tone"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
54 _("Ok"), FALSE, NULL, NULL);
209
bd8457b077cf [svn] Add casts to callbacks in signal handlers to avoid warning. Remove stale pause handler declaration from wav-sndfile.h
chainsaw
parents: 190
diff changeset
55 g_signal_connect(GTK_OBJECT(box), "destroy",
bd8457b077cf [svn] Add casts to callbacks in signal handlers to avoid warning. Remove stale pause handler declaration from wav-sndfile.h
chainsaw
parents: 190
diff changeset
56 (GCallback)gtk_widget_destroyed, &box);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
57 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
58
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
59 static int tone_is_our_file(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
60 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
61 if (!strncmp(filename, "tone://", 7))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
62 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
63 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
64 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
65
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
66 #define BUF_SAMPLES 512
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
67 #define BUF_BYTES BUF_SAMPLES * 2
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
68
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
69 static void* play_loop(void *arg)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
70 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
71 GArray* frequencies = arg;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
72 gint16 data[BUF_SAMPLES];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
73 int i;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
74 struct {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
75 double wd;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
76 unsigned int period, t;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
77 } *tone;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
78
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
79 tone = g_malloc(frequencies->len * sizeof(*tone));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
80
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
81 for (i = 0; i < frequencies->len; i++)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
82 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
83 double f = g_array_index(frequencies, double, i);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
84 tone[i].wd = 2 * PI * f / OUTPUT_FREQ;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
85 tone[i].period = (G_MAXINT * 2U / OUTPUT_FREQ) *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
86 (OUTPUT_FREQ / f);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
87 tone[i].t = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
88 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
89
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
90 while (going)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
91 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
92 for (i = 0; i < BUF_SAMPLES; i++)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
93 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
94 int j;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
95 double sum_sines;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
96
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
97 for (sum_sines = 0, j = 0; j < frequencies->len; j++)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
98 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
99 sum_sines += sin(tone[j].wd * tone[j].t);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
100 if (tone[j].t > tone[j].period)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
101 tone[j].t -= tone[j].period;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
102 tone[j].t++;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
103 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
104 data[i] = rint(((1 << 15) - 1) *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
105 (sum_sines / frequencies->len));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
106 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
107 tone_ip.add_vis_pcm(tone_ip.output->written_time(),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
108 FMT_S16_NE, 1, BUF_BYTES, data);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
109 while (tone_ip.output->buffer_free() < BUF_BYTES && going)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
110 xmms_usleep(30000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
111 if (going)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
112 tone_ip.output->write_audio(data, BUF_BYTES);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
113 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
114
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
115 g_array_free(frequencies, TRUE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
116 g_free(tone);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
117
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
118 /* Make sure the output plugin stops prebuffering */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
119 tone_ip.output->buffer_free();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
120 tone_ip.output->buffer_free();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
121
172
08d65e21e357 [svn] Use GThread instead of pthread.
chainsaw
parents: 61
diff changeset
122 g_thread_exit(NULL);
190
b0b4f9527eeb [svn] GCC would prefer a return statement here.
chainsaw
parents: 172
diff changeset
123 return(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
124 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
125
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
126 static GArray* tone_filename_parse(const char* filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
127 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
128 GArray *frequencies = g_array_new(FALSE, FALSE, sizeof(double));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
129 char **strings, **ptr;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
130
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
131 if (strncmp(filename,"tone://", 7))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
132 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
133
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
134 filename += 7;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
135 strings = g_strsplit(filename, ";", 100);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
136
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
137 for (ptr = strings; *ptr != NULL; ptr++)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
138 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
139 double freq = strtod(*ptr, NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
140 if (freq >= MIN_FREQ && freq <= MAX_FREQ)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
141 g_array_append_val(frequencies, freq);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
142 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
143 g_strfreev(strings);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
144
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
145 if (frequencies->len == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
146 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
147 g_array_free(frequencies, TRUE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
148 frequencies = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
149 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
150
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
151 return frequencies;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
152 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
153
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
154 static char* tone_title(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
155 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
156 GArray *freqs;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
157 char* title;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
158 int i;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
159
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
160 freqs = tone_filename_parse(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
161 if (freqs == NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
162 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
163
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
164 title = g_strdup_printf("%s %.1f Hz", _("Tone Generator: "),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
165 g_array_index(freqs, double, 0));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
166 for (i = 1; i < freqs->len; i++)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
167 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
168 char *old_title;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
169 old_title = title;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
170 title = g_strdup_printf("%s;%.1f Hz", old_title,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
171 g_array_index(freqs, double, i));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
172 g_free(old_title);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
173 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
174 g_array_free(freqs, TRUE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
175
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
176 return title;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
177 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
178
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
179
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
180 static void tone_play(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
181 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
182 GArray* frequencies;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
183 char *name;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
184
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
185 frequencies = tone_filename_parse(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
186 if (frequencies == NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
187 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
188
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
189 going = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
190 audio_error = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
191 if (tone_ip.output->open_audio(FMT_S16_NE, OUTPUT_FREQ, 1) == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
192 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
193 audio_error = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
194 going = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
195 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
196 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
197
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
198 name = tone_title(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
199 tone_ip.set_info(name, -1, 16 * OUTPUT_FREQ, OUTPUT_FREQ, 1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
200 g_free(name);
172
08d65e21e357 [svn] Use GThread instead of pthread.
chainsaw
parents: 61
diff changeset
201 play_thread = g_thread_create((GThreadFunc)play_loop, frequencies, TRUE, NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
202 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
203
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
204 static void tone_stop(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
205 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
206 if (going)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
207 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
208 going = FALSE;
172
08d65e21e357 [svn] Use GThread instead of pthread.
chainsaw
parents: 61
diff changeset
209 g_thread_join(play_thread);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
210 tone_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
211 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
212 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
213
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
214 static void tone_pause(short paused)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
215 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
216 tone_ip.output->pause(paused);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
217 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
218
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
219 static int tone_get_time(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
220 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
221 if (audio_error)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
222 return -2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
223 if (!going && !tone_ip.output->buffer_playing())
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
224 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
225 return tone_ip.output->output_time();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
226 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
227
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
228 static void tone_song_info(char *filename, char **title, int *length)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
229 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
230 *length = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
231 *title = tone_title(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
232 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
233
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
234 static InputPlugin tone_ip =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
235 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
236 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
237 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
238 NULL, /* Description */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
239 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
240 tone_about,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
241 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
242 tone_is_our_file,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
243 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
244 tone_play,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
245 tone_stop,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
246 tone_pause,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
247 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
248 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
249 tone_get_time,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
250 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
251 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
252 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
253 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
254 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
255 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
256 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
257 tone_song_info,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
258 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
259 NULL
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
260 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
261
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
262 InputPlugin *get_iplugin_info(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
263 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
264 tone_ip.description = g_strdup_printf(_("Tone Generator %s"), VERSION);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
265 return &tone_ip;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
266 }