annotate Plugins/Input/tonegen/tonegen.c @ 920:999d1af32ab4 trunk

[svn] Extra_stereo effect plugin ported by deitarion. Some last pointer-related touchups by nemo & me.
author chainsaw
date Sat, 08 Apr 2006 19:44:43 -0700
parents c130ba2a5524
children f12d7e208b43
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"
414
7fa1738514d5 [svn] Convert all input plugins (except timidity & wav-sndfile) to produce_audio.
chainsaw
parents: 209
diff changeset
21 #include "audacious/output.h"
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
22 #include "libaudacious/util.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
23 #include "config.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
24 #include <glib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
25 #include <stdlib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
26 #include <string.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
27 #include <math.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
28 #include <stdio.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
29 #include <glib/gi18n.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
30
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
31 #define MIN_FREQ 10
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
32 #define MAX_FREQ 20000
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
33 #define OUTPUT_FREQ 44100
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
34
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
35 #ifndef PI
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
36 #define PI 3.14159265358979323846
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
37 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
38
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
39 static InputPlugin tone_ip;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
40
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
41 static gboolean going;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
42 static gboolean audio_error;
172
08d65e21e357 [svn] Use GThread instead of pthread.
chainsaw
parents: 61
diff changeset
43 static GThread *play_thread;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
44
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
45 static void tone_about(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
46 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
47 static GtkWidget *box;
902
c130ba2a5524 [svn] prevent tonegen aboutbox from spawning multiple times
giacomo
parents: 747
diff changeset
48 if (!box)
c130ba2a5524 [svn] prevent tonegen aboutbox from spawning multiple times
giacomo
parents: 747
diff changeset
49 {
c130ba2a5524 [svn] prevent tonegen aboutbox from spawning multiple times
giacomo
parents: 747
diff changeset
50 box = xmms_show_message(
c130ba2a5524 [svn] prevent tonegen aboutbox from spawning multiple times
giacomo
parents: 747
diff changeset
51 _("About Tone Generator"),
c130ba2a5524 [svn] prevent tonegen aboutbox from spawning multiple times
giacomo
parents: 747
diff changeset
52 /* I18N: UTF-8 Translation: "Haavard Kvaalen" -> "H\303\245vard Kv\303\245len" */
c130ba2a5524 [svn] prevent tonegen aboutbox from spawning multiple times
giacomo
parents: 747
diff changeset
53 _("Sinus tone generator by Haavard Kvaalen <havardk@xmms.org>\n"
c130ba2a5524 [svn] prevent tonegen aboutbox from spawning multiple times
giacomo
parents: 747
diff changeset
54 "Modified by Daniel J. Peng <danielpeng@bigfoot.com>\n\n"
c130ba2a5524 [svn] prevent tonegen aboutbox from spawning multiple times
giacomo
parents: 747
diff changeset
55 "To use it, add a URL: tone://frequency1;frequency2;frequency3;...\n"
c130ba2a5524 [svn] prevent tonegen aboutbox from spawning multiple times
giacomo
parents: 747
diff changeset
56 "e.g. tone://2000;2005 to play a 2000Hz tone and a 2005Hz tone"),
c130ba2a5524 [svn] prevent tonegen aboutbox from spawning multiple times
giacomo
parents: 747
diff changeset
57 _("Ok"), FALSE, NULL, NULL);
c130ba2a5524 [svn] prevent tonegen aboutbox from spawning multiple times
giacomo
parents: 747
diff changeset
58 g_signal_connect(GTK_OBJECT(box), "destroy",
c130ba2a5524 [svn] prevent tonegen aboutbox from spawning multiple times
giacomo
parents: 747
diff changeset
59 (GCallback)gtk_widget_destroyed, &box);
c130ba2a5524 [svn] prevent tonegen aboutbox from spawning multiple times
giacomo
parents: 747
diff changeset
60 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
61 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
62
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
63 static int tone_is_our_file(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
64 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
65 if (!strncmp(filename, "tone://", 7))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
66 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
67 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
68 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
69
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
70 #define BUF_SAMPLES 512
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
71 #define BUF_BYTES BUF_SAMPLES * 2
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
72
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
73 static void* play_loop(void *arg)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
74 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
75 GArray* frequencies = arg;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
76 gint16 data[BUF_SAMPLES];
701
d539e5c5f730 [svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents: 414
diff changeset
77 gsize i;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
78 struct {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
79 double wd;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
80 unsigned int period, t;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
81 } *tone;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
82
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
83 tone = g_malloc(frequencies->len * sizeof(*tone));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
84
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
85 for (i = 0; i < frequencies->len; i++)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
86 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
87 double f = g_array_index(frequencies, double, i);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
88 tone[i].wd = 2 * PI * f / OUTPUT_FREQ;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
89 tone[i].period = (G_MAXINT * 2U / OUTPUT_FREQ) *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
90 (OUTPUT_FREQ / f);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
91 tone[i].t = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
92 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
93
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
94 while (going)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
95 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
96 for (i = 0; i < BUF_SAMPLES; i++)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
97 {
701
d539e5c5f730 [svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents: 414
diff changeset
98 gsize j;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
99 double sum_sines;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
100
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
101 for (sum_sines = 0, j = 0; j < frequencies->len; j++)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
102 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
103 sum_sines += sin(tone[j].wd * tone[j].t);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
104 if (tone[j].t > tone[j].period)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
105 tone[j].t -= tone[j].period;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
106 tone[j].t++;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
107 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
108 data[i] = rint(((1 << 15) - 1) *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
109 (sum_sines / frequencies->len));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
110 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
111 while (tone_ip.output->buffer_free() < BUF_BYTES && going)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
112 xmms_usleep(30000);
414
7fa1738514d5 [svn] Convert all input plugins (except timidity & wav-sndfile) to produce_audio.
chainsaw
parents: 209
diff changeset
113 produce_audio(tone_ip.output->written_time(), FMT_S16_NE, 1, BUF_BYTES, data, &going);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
114 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
115
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
116 g_array_free(frequencies, TRUE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
117 g_free(tone);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
118
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
119 /* Make sure the output plugin stops prebuffering */
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 tone_ip.output->buffer_free();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
122
172
08d65e21e357 [svn] Use GThread instead of pthread.
chainsaw
parents: 61
diff changeset
123 g_thread_exit(NULL);
190
b0b4f9527eeb [svn] GCC would prefer a return statement here.
chainsaw
parents: 172
diff changeset
124 return(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
125 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
126
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
127 static GArray* tone_filename_parse(const char* filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
128 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
129 GArray *frequencies = g_array_new(FALSE, FALSE, sizeof(double));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
130 char **strings, **ptr;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
131
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
132 if (strncmp(filename,"tone://", 7))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
133 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
134
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
135 filename += 7;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
136 strings = g_strsplit(filename, ";", 100);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
137
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
138 for (ptr = strings; *ptr != NULL; ptr++)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
139 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
140 double freq = strtod(*ptr, NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
141 if (freq >= MIN_FREQ && freq <= MAX_FREQ)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
142 g_array_append_val(frequencies, freq);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
143 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
144 g_strfreev(strings);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
145
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
146 if (frequencies->len == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
147 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
148 g_array_free(frequencies, TRUE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
149 frequencies = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
150 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
151
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
152 return frequencies;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
153 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
154
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
155 static char* tone_title(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
156 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
157 GArray *freqs;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
158 char* title;
701
d539e5c5f730 [svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents: 414
diff changeset
159 gsize i;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
160
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
161 freqs = tone_filename_parse(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
162 if (freqs == NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
163 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
164
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
165 title = g_strdup_printf("%s %.1f Hz", _("Tone Generator: "),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
166 g_array_index(freqs, double, 0));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
167 for (i = 1; i < freqs->len; i++)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
168 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
169 char *old_title;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
170 old_title = title;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
171 title = g_strdup_printf("%s;%.1f Hz", old_title,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
172 g_array_index(freqs, double, i));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
173 g_free(old_title);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
174 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
175 g_array_free(freqs, TRUE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
176
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
177 return title;
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
181 static void tone_play(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
182 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
183 GArray* frequencies;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
184 char *name;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
185
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
186 frequencies = tone_filename_parse(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
187 if (frequencies == NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
188 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
189
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
190 going = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
191 audio_error = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
192 if (tone_ip.output->open_audio(FMT_S16_NE, OUTPUT_FREQ, 1) == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
193 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
194 audio_error = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
195 going = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
196 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
197 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
198
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
199 name = tone_title(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
200 tone_ip.set_info(name, -1, 16 * OUTPUT_FREQ, OUTPUT_FREQ, 1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
201 g_free(name);
172
08d65e21e357 [svn] Use GThread instead of pthread.
chainsaw
parents: 61
diff changeset
202 play_thread = g_thread_create((GThreadFunc)play_loop, frequencies, TRUE, NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
203 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
204
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
205 static void tone_stop(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
206 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
207 if (going)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
208 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
209 going = FALSE;
172
08d65e21e357 [svn] Use GThread instead of pthread.
chainsaw
parents: 61
diff changeset
210 g_thread_join(play_thread);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
211 tone_ip.output->close_audio();
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
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
215 static void tone_pause(short paused)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
216 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
217 tone_ip.output->pause(paused);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
218 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
219
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
220 static int tone_get_time(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
221 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
222 if (audio_error)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
223 return -2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
224 if (!going && !tone_ip.output->buffer_playing())
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
225 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
226 return tone_ip.output->output_time();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
227 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
228
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
229 static void tone_song_info(char *filename, char **title, int *length)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
230 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
231 *length = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
232 *title = tone_title(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
233 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
234
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
235 static InputPlugin tone_ip =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
236 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
237 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
238 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
239 NULL, /* Description */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
240 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
241 tone_about,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
242 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
243 tone_is_our_file,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
244 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
245 tone_play,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
246 tone_stop,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
247 tone_pause,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
248 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
249 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
250 tone_get_time,
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 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
258 tone_song_info,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
259 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
260 NULL
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
261 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
262
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
263 InputPlugin *get_iplugin_info(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
264 {
747
0cf543c6a088 [svn] another kludge for pkgsrc, C++ edition
nenolod
parents: 701
diff changeset
265 tone_ip.description = g_strdup_printf(_("Tone Generator %s"), PACKAGE_VERSION);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
266 return &tone_ip;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
267 }