annotate Plugins/Input/wav/wav-sndfile.c @ 1218:aaf012a5529c trunk

[svn] - more Makefile conversion
author nenolod
date Wed, 14 Jun 2006 01:16:45 -0700
parents 8bdcd65a57b7
children f12d7e208b43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
155
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
1 /* Audacious - Cross-platform multimedia player
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
2 * Copyright (C) 2005 Audacious development team.
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
3 *
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
4 * Based on the xmms_sndfile input plugin:
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
5 * Copyright (C) 2000, 2002 Erik de Castro Lopo
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
6 *
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
10 * (at your option) any later version.
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
11 *
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
15 * GNU General Public License for more details.
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
16 *
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
20 */
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
21
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
22 #include <glib.h>
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
23 #include <glib/gi18n.h>
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
24 #include <string.h>
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
25 #include <math.h>
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
26 #include <stdio.h>
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
27
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
28 #include <libaudacious/util.h>
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
29 #include <libaudacious/titlestring.h>
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
30 #include "audacious/output.h"
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
31 #include "wav-sndfile.h"
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
32
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
33 #include <sndfile.h>
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
34
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
35 static SNDFILE *sndfile = NULL;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
36 static SF_INFO sfinfo;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
37
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
38 static int song_length;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
39 static int bit_rate = 0;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
40 static int decoding;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
41 static int seek_time = -1;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
42
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
43 static GThread *decode_thread;
264
852a1455dfb7 [svn] Use a mutex, lower timeouts. Do not spin waiting for playback to start.
chainsaw
parents: 257
diff changeset
44 GStaticMutex decode_mutex = G_STATIC_MUTEX_INIT;
155
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
45
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
46 InputPlugin wav_ip = {
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
47 NULL,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
48 NULL,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
49 NULL,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
50 plugin_init,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
51 wav_about,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
52 NULL,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
53 is_our_file,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
54 NULL,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
55 play_start,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
56 play_stop,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
57 NULL, /* Could call do_pause here, but it will cause auto-stop anyway */
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
58 file_seek,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
59 NULL,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
60 get_time,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
61 NULL,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
62 NULL,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
63 NULL,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
64 NULL,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
65 NULL,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
66 NULL,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
67 NULL,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
68 get_song_info,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
69 NULL,
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
70 NULL
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
71 };
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
72
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
73 int
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
74 get_song_length (char *filename)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
75 { SNDFILE *tmp_sndfile;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
76 SF_INFO tmp_sfinfo;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
77
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
78 if (! (tmp_sndfile = sf_open (filename, SFM_READ, &tmp_sfinfo)))
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
79 return 0;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
80
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
81 sf_close (tmp_sndfile);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
82 tmp_sndfile = NULL;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
83
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
84 if (tmp_sfinfo.samplerate <= 0)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
85 return 0;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
86
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
87 return (int) ceil (1000.0 * tmp_sfinfo.frames / tmp_sfinfo.samplerate);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
88 } /* get_song_length */
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
89
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
90 static gchar *get_title(char *filename)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
91 {
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
92 gchar *title;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
93 title = g_path_get_basename(filename);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
94 return title;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
95 }
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
96
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
97 static void
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
98 plugin_init (void)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
99 {
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
100 decoding = FALSE;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
101 seek_time = -1;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
102 } /* plugin_int */
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
103
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
104 static int
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
105 is_our_file (char *filename)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
106 { SNDFILE *tmp_sndfile;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
107 SF_INFO tmp_sfinfo;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
108
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
109 /* Have to open the file to see if libsndfile can handle it. */
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
110 if (! (tmp_sndfile = sf_open (filename, SFM_READ, &tmp_sfinfo)))
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
111 return FALSE;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
112
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
113 /* It can so close file and return TRUE. */
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
114 sf_close (tmp_sndfile);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
115 tmp_sndfile = NULL;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
116
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
117 return TRUE;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
118 } /* is_our_file */
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
119
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
120 static void*
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
121 play_loop (void *arg)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
122 { static short buffer [BUFFER_SIZE];
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
123 int samples;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
124
264
852a1455dfb7 [svn] Use a mutex, lower timeouts. Do not spin waiting for playback to start.
chainsaw
parents: 257
diff changeset
125 g_static_mutex_lock(&decode_mutex);
852a1455dfb7 [svn] Use a mutex, lower timeouts. Do not spin waiting for playback to start.
chainsaw
parents: 257
diff changeset
126
155
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
127 decoding = TRUE;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
128 while (decoding)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
129 {
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
130 /* sf_read_short will return 0 for all reads at EOF. */
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
131 samples = sf_read_short (sndfile, buffer, BUFFER_SIZE);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
132
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
133 if (samples > 0 && decoding)
416
cb00a4b01302 [svn] Convert to produce_audio usage.
chainsaw
parents: 415
diff changeset
134 { while ((wav_ip.output->buffer_free () < (samples * sizeof (short))) && decoding)
264
852a1455dfb7 [svn] Use a mutex, lower timeouts. Do not spin waiting for playback to start.
chainsaw
parents: 257
diff changeset
135 xmms_usleep (10000);
416
cb00a4b01302 [svn] Convert to produce_audio usage.
chainsaw
parents: 415
diff changeset
136
cb00a4b01302 [svn] Convert to produce_audio usage.
chainsaw
parents: 415
diff changeset
137 produce_audio (wav_ip.output->written_time (), FMT_S16_NE, sfinfo.channels,
cb00a4b01302 [svn] Convert to produce_audio usage.
chainsaw
parents: 415
diff changeset
138 samples * sizeof (short), buffer, &decoding);
cb00a4b01302 [svn] Convert to produce_audio usage.
chainsaw
parents: 415
diff changeset
139 }
155
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
140 else
416
cb00a4b01302 [svn] Convert to produce_audio usage.
chainsaw
parents: 415
diff changeset
141 xmms_usleep (10000);
155
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
142
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
143 /* Do seek if seek_time is valid. */
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
144 if (seek_time > 0)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
145 { sf_seek (sndfile, seek_time * sfinfo.samplerate, SEEK_SET);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
146 wav_ip.output->flush (seek_time * 1000);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
147 seek_time = -1;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
148 };
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
149
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
150 }; /* while (decoding) */
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
151
264
852a1455dfb7 [svn] Use a mutex, lower timeouts. Do not spin waiting for playback to start.
chainsaw
parents: 257
diff changeset
152 g_static_mutex_unlock(&decode_mutex);
155
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
153 g_thread_exit (NULL);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
154 return NULL;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
155 } /* play_loop */
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
156
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
157 static void
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
158 play_start (char *filename)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
159 {
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
160 int pcmbitwidth;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
161 gchar *song_title;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
162
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
163 if (sndfile)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
164 return;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
165
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
166 pcmbitwidth = 32;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
167
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
168 song_title = get_title(filename);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
169
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
170 if (! (sndfile = sf_open (filename, SFM_READ, &sfinfo)))
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
171 return;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
172
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
173 bit_rate = sfinfo.samplerate * pcmbitwidth * sfinfo.channels;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
174
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
175 if (sfinfo.samplerate > 0)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
176 song_length = (int) ceil (1000.0 * sfinfo.frames / sfinfo.samplerate);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
177 else
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
178 song_length = 0;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
179
415
d55ffce8b1ba [svn] Use FMT_S16_NE instead of unnecessary #ifdef WORDS_BIGENDIAN trickery.
chainsaw
parents: 264
diff changeset
180 if (! wav_ip.output->open_audio (FMT_S16_NE, sfinfo.samplerate, sfinfo.channels))
155
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
181 { sf_close (sndfile);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
182 sndfile = NULL;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
183 return;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
184 };
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
185
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
186 wav_ip.set_info (song_title, song_length, bit_rate, sfinfo.samplerate, sfinfo.channels);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
187 g_free (song_title);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
188
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
189 decode_thread = g_thread_create ((GThreadFunc)play_loop, NULL, TRUE, NULL);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
190
264
852a1455dfb7 [svn] Use a mutex, lower timeouts. Do not spin waiting for playback to start.
chainsaw
parents: 257
diff changeset
191 xmms_usleep (40000);
155
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
192 } /* play_start */
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
193
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
194 static void
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
195 play_stop (void)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
196 {
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
197 if (decode_thread == NULL)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
198 return;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
199
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
200 decoding = FALSE;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
201
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
202 g_thread_join (decode_thread);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
203 wav_ip.output->close_audio ();
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
204
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
205 sf_close (sndfile);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
206 sndfile = NULL;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
207 decode_thread = NULL;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
208
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
209 seek_time = -1;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
210 } /* play_stop */
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
211
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
212 static void
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
213 file_seek (int time)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
214 {
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
215 if (! sfinfo.seekable)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
216 return;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
217
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
218 seek_time = time;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
219
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
220 while (seek_time != -1)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
221 xmms_usleep (80000);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
222 } /* file_seek */
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
223
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
224 static int
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
225 get_time (void)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
226 {
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
227 if ( ! (wav_ip.output->buffer_playing () && decoding))
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
228 return -1;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
229
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
230 return wav_ip.output->output_time ();
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
231 } /* get_time */
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
232
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
233 static void
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
234 get_song_info (char *filename, char **title, int *length)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
235 {
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
236 (*length) = get_song_length(filename);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
237 (*title) = get_title(filename);
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
238 } /* get_song_info */
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
239
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
240 static void wav_about(void)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
241 {
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
242 static GtkWidget *box;
868
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
243 if (!box)
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
244 {
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
245 box = xmms_show_message(
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
246 _("About sndfile WAV support"),
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
247 _("Adapted for Audacious usage by Tony Vroon <chainsaw@gentoo.org>\n"
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
248 "from the xmms_sndfile plugin which is:\n"
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
249 "Copyright (C) 2000, 2002 Erik de Castro Lopo\n\n"
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
250 "This program is free software ; you can redistribute it and/or modify \n"
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
251 "it under the terms of the GNU General Public License as published by \n"
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
252 "the Free Software Foundation ; either version 2 of the License, or \n"
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
253 "(at your option) any later version. \n \n"
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
254 "This program is distributed in the hope that it will be useful, \n"
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
255 "but WITHOUT ANY WARRANTY ; without even the implied warranty of \n"
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
256 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. \n"
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
257 "See the GNU General Public License for more details. \n\n"
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
258 "You should have received a copy of the GNU General Public \n"
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
259 "License along with this program ; if not, write to \n"
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
260 "the Free Software Foundation, Inc., \n"
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
261 "59 Temple Place, Suite 330, \n"
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
262 "Boston, MA 02111-1307 USA"),
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
263 _("Ok"), FALSE, NULL, NULL);
1103
8bdcd65a57b7 [svn] Updating of some deprecated GTK functions.
nemo
parents: 868
diff changeset
264 g_signal_connect(G_OBJECT(box), "destroy",
868
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
265 (GCallback)gtk_widget_destroyed, &box);
29132467a450 [svn] fixed multiple spawns of wav-sndfile aboutbox
giacomo
parents: 416
diff changeset
266 }
155
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
267 }
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
268
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
269
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
270 InputPlugin *get_iplugin_info(void)
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
271 {
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
272 wav_ip.description = g_strdup_printf(_("sndfile WAV plugin"));
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
273 return &wav_ip;
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
274 }
2746c4cadd07 [svn] Add sndfile version of the wav plugin. Not integrated into buildsystem yet.
chainsaw
parents:
diff changeset
275