annotate src/wavpack/libwavpack.cxx @ 264:1e6e497e039f trunk

[svn] - add missing vfs_fclose().
author nenolod
date Sat, 18 Nov 2006 19:00:23 -0800
parents 7e1d5cc9ef1b
children 72f0de06bb56
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
1 #include <assert.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
2 #include <string.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
3 #include <stdio.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
4 #include <stdlib.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
5 #include <unistd.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
6 #include <wavpack/wputils.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
7 extern "C" {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
8 #include <audacious/plugin.h>
111
5745352e0c88 [svn] - hey, this compiles now. neat :P
nenolod
parents: 109
diff changeset
9 #include <audacious/output.h>
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
10 #include <audacious/configdb.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
11 #include <audacious/titlestring.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
12 #include <audacious/util.h>
233
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
13 #include <audacious/vfs.h>
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
14 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
15 #include <glib.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
16 #include <gtk/gtk.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
17 #include <iconv.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
18 #include <math.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
19 #include "tags.h"
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
20 #ifndef M_LN10
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
21 #define M_LN10 2.3025850929940456840179914546843642
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
22 #endif
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
23
112
5755fb99ddab [svn] - make debugging notices optional
nenolod
parents: 111
diff changeset
24 #ifdef DEBUG
5755fb99ddab [svn] - make debugging notices optional
nenolod
parents: 111
diff changeset
25 # define DBG(format, args...) fprintf(stderr, format, ## args)
5755fb99ddab [svn] - make debugging notices optional
nenolod
parents: 111
diff changeset
26 #else
5755fb99ddab [svn] - make debugging notices optional
nenolod
parents: 111
diff changeset
27 # define DBG(format, args...)
5755fb99ddab [svn] - make debugging notices optional
nenolod
parents: 111
diff changeset
28 #endif
5755fb99ddab [svn] - make debugging notices optional
nenolod
parents: 111
diff changeset
29
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
30 #define BUFFER_SIZE 256 // read buffer size, in samples
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
31
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
32 extern "C" InputPlugin * get_iplugin_info(void);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
33 static void wv_load_config();
263
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
34 static int wv_is_our_file(gchar *filename);
253
ab24cfe495e0 [svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents: 247
diff changeset
35 static int wv_is_our_fd(gchar *filename, VFSFile *file);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
36 static void wv_play(char *);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
37 static void wv_stop(void);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
38 static void wv_pause(short);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
39 static void wv_seek(int);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
40 static int wv_get_time(void);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
41 static void wv_get_song_info(char *, char **, int *);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
42 static char *generate_title(const char *, WavpackContext *ctx);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
43 static double isSeek;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
44 static short paused;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
45 static bool killDecodeThread;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
46 static bool AudioError;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
47 static GThread *thread_handle;
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
48 static TitleInput *wv_get_song_tuple(char *);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
49
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
50 // in ui.cpp
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
51 void wv_configure();
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
52 void wv_about_box(void);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
53 void wv_file_info_box(char *);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
54 extern gboolean clipPreventionEnabled;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
55 extern gboolean dynBitrateEnabled;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
56 extern gboolean replaygainEnabled;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
57 extern gboolean albumReplaygainEnabled;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
58 extern gboolean openedAudio;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
59
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
60 InputPlugin mod = {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
61 NULL, //handle
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
62 NULL, //filename
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
63 NULL,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
64 wv_load_config,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
65 wv_about_box,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
66 wv_configure,
263
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
67 wv_is_our_file, //old style is_our_file
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
68 NULL, //no use
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
69 wv_play,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
70 wv_stop,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
71 wv_pause,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
72 wv_seek,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
73 NULL, //set eq
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
74 wv_get_time,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
75 NULL, //get volume
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
76 NULL, //set volume
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
77 NULL, //cleanup
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
78 NULL, //obsolete
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
79 NULL, //add_vis
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
80 NULL,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
81 NULL,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
82 wv_get_song_info,
263
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
83 wv_file_info_box, //info box
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
84 NULL, //output
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
85 wv_get_song_tuple,
253
ab24cfe495e0 [svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents: 247
diff changeset
86 NULL,
ab24cfe495e0 [svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents: 247
diff changeset
87 NULL,
ab24cfe495e0 [svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents: 247
diff changeset
88 wv_is_our_fd,
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
89 };
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
90
233
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
91 int32_t read_bytes (void *id, void *data, int32_t bcount)
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
92 {
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
93 return vfs_fread (data, 1, bcount, (VFSFile *) id);
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
94 }
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
95
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
96 uint32_t get_pos (void *id)
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
97 {
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
98 return vfs_ftell ((VFSFile *) id);
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
99 }
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
100
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
101 int set_pos_abs (void *id, uint32_t pos)
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
102 {
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
103 return vfs_fseek ((VFSFile *) id, pos, SEEK_SET);
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
104 }
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
105
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
106 int set_pos_rel (void *id, int32_t delta, int mode)
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
107 {
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
108 return vfs_fseek ((VFSFile *) id, delta, mode);
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
109 }
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
110
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
111 int push_back_byte (void *id, int c)
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
112 {
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
113 return vfs_ungetc (c, (VFSFile *) id);
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
114 }
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
115
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
116 uint32_t get_length (void *id)
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
117 {
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
118 VFSFile *file = (VFSFile *) id;
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
119 uint32_t sz = 0;
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
120
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
121 if (file == NULL)
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
122 return 0;
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
123
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
124 vfs_fseek(file, 0, SEEK_END);
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
125 sz = vfs_ftell(file);
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
126 vfs_fseek(file, 0, SEEK_SET);
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
127
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
128 return sz;
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
129 }
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
130
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
131 /* XXX streams?? */
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
132 int can_seek (void *id)
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
133 {
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
134 return 1;
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
135 }
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
136
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
137 int32_t write_bytes (void *id, void *data, int32_t bcount)
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
138 {
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
139 return vfs_fwrite (data, 1, bcount, (VFSFile *) id);
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
140 }
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
141
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
142 WavpackStreamReader reader = {
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
143 read_bytes, get_pos, set_pos_abs, set_pos_rel, push_back_byte, get_length, can_seek,
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
144 write_bytes
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
145 };
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
146
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
147 class WavpackDecoder
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
148 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
149 public:
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
150 InputPlugin *mod;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
151 int32_t *input;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
152 int16_t *output;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
153 int sample_rate;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
154 int num_channels;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
155 WavpackContext *ctx;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
156 char error_buff[4096]; // TODO: fixme!
233
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
157 VFSFile *wv_Input, *wvc_Input;
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
158
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
159 WavpackDecoder(InputPlugin *mod) : mod(mod)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
160 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
161 ctx = NULL;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
162 input = NULL;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
163 output = NULL;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
164 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
165
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
166 ~WavpackDecoder()
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
167 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
168 if (input != NULL) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
169 free(input);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
170 input = NULL;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
171 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
172 if (output != NULL) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
173 free(output);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
174 output = NULL;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
175 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
176 if (ctx != NULL) {
233
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
177 vfs_fclose(wv_Input);
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
178 vfs_fclose(wvc_Input);
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
179 g_free(ctx);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
180 ctx = NULL;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
181 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
182 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
183
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
184 bool attach(const char *filename)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
185 {
233
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
186 wv_Input = vfs_fopen(filename, "rb");
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
187
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
188 char *corrFilename = g_strconcat(filename, "c", NULL);
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
189
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
190 wvc_Input = vfs_fopen(corrFilename, "rb");
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
191
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
192 g_free(corrFilename);
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
193
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
194 ctx = WavpackOpenFileInputEx(&reader, wv_Input, wvc_Input, error_buff, OPEN_TAGS | OPEN_WVC, 0);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
195
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
196 if (ctx == NULL) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
197 return false;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
198 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
199
237
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
200 return true;
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
201 }
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
202
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
203 bool attach_to_play(const char *filename)
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
204 {
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
205 wv_Input = vfs_fopen(filename, "rb");
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
206
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
207 char *corrFilename = g_strconcat(filename, "c", NULL);
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
208
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
209 wvc_Input = vfs_fopen(corrFilename, "rb");
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
210
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
211 g_free(corrFilename);
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
212
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
213 ctx = WavpackOpenFileInputEx(&reader, wv_Input, wvc_Input, error_buff, OPEN_TAGS | OPEN_WVC, 0);
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
214
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
215 if (ctx == NULL) {
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
216 return false;
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
217 }
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
218
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
219 sample_rate = WavpackGetSampleRate(ctx);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
220 num_channels = WavpackGetNumChannels(ctx);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
221 input = (int32_t *)calloc(BUFFER_SIZE, num_channels * sizeof(int32_t));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
222 output = (int16_t *)calloc(BUFFER_SIZE, num_channels * sizeof(int16_t));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
223 mod->set_info(generate_title(filename, ctx),
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
224 (int) (WavpackGetNumSamples(ctx) / sample_rate) * 1000,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
225 (int) WavpackGetAverageBitrate(ctx, num_channels),
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
226 (int) sample_rate, num_channels);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
227 return true;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
228 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
229
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
230 bool open_audio()
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
231 {
112
5755fb99ddab [svn] - make debugging notices optional
nenolod
parents: 111
diff changeset
232 return mod->output->open_audio(FMT_S16_NE, sample_rate, num_channels);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
233 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
234
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
235 void process_buffer(size_t num_samples)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
236 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
237 for (int i = 0; i < num_samples * num_channels; i++) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
238 output[i] = input[i];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
239 }
112
5755fb99ddab [svn] - make debugging notices optional
nenolod
parents: 111
diff changeset
240 produce_audio(mod->output->output_time(), FMT_S16_NE,
111
5745352e0c88 [svn] - hey, this compiles now. neat :P
nenolod
parents: 109
diff changeset
241 num_channels,
5745352e0c88 [svn] - hey, this compiles now. neat :P
nenolod
parents: 109
diff changeset
242 num_samples * num_channels * sizeof(int16_t),
5745352e0c88 [svn] - hey, this compiles now. neat :P
nenolod
parents: 109
diff changeset
243 output,
5745352e0c88 [svn] - hey, this compiles now. neat :P
nenolod
parents: 109
diff changeset
244 NULL);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
245 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
246 };
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
247
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
248 extern "C" InputPlugin *
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
249 get_iplugin_info(void)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
250 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
251 mod.description =
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
252 g_strdup_printf(("Wavpack Decoder Plugin %s"), VERSION);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
253 return &mod;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
254 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
255
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
256 static int
253
ab24cfe495e0 [svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents: 247
diff changeset
257 wv_is_our_fd(gchar *filename, VFSFile *file)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
258 {
253
ab24cfe495e0 [svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents: 247
diff changeset
259 gchar magic[4];
ab24cfe495e0 [svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents: 247
diff changeset
260 vfs_fread(magic,1,4,file);
ab24cfe495e0 [svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents: 247
diff changeset
261 if (!memcmp(magic,"wvpk",4))
ab24cfe495e0 [svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents: 247
diff changeset
262 return TRUE;
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
263 return FALSE;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
264 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
265
263
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
266 static int
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
267 wv_is_our_file(gchar *filename)
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
268 {
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
269 VFSFile *file = vfs_fopen(filename, "rb");
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
270 gchar magic[4];
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
271
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
272 if (!file)
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
273 return FALSE;
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
274
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
275 vfs_fread(magic,1,4,file);
264
1e6e497e039f [svn] - add missing vfs_fclose().
nenolod
parents: 263
diff changeset
276 vfs_fclose(file);
263
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
277
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
278 if (!memcmp(magic,"wvpk",4))
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
279 return TRUE;
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
280
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
281 return FALSE;
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
282 }
7e1d5cc9ef1b [svn] - fix wavpack plugin
nenolod
parents: 253
diff changeset
283
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
284 void
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
285 load_tag(ape_tag *tag, WavpackContext *ctx)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
286 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
287 memset(tag, 0, sizeof(ape_tag));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
288 WavpackGetTagItem(ctx, "Album", tag->album, sizeof(tag->album));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
289 WavpackGetTagItem(ctx, "Artist", tag->artist, sizeof(tag->artist));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
290 WavpackGetTagItem(ctx, "Comment", tag->comment, sizeof(tag->comment));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
291 WavpackGetTagItem(ctx, "Genre", tag->genre, sizeof(tag->genre));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
292 WavpackGetTagItem(ctx, "Title", tag->title, sizeof(tag->title));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
293 WavpackGetTagItem(ctx, "Track", tag->track, sizeof(tag->track));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
294 WavpackGetTagItem(ctx, "Year", tag->year, sizeof(tag->year));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
295 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
296
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
297 static void *
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
298 end_thread()
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
299 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
300 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
301 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
302
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
303 static void *
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
304 DecodeThread(void *a)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
305 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
306 ape_tag tag;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
307 char *filename = (char *) a;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
308 int bps_updateCounter = 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
309 int bps;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
310 int i;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
311 WavpackDecoder d(&mod);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
312
237
f0117679cd26 [svn] - a slightly better way of doing things here
nenolod
parents: 233
diff changeset
313 if (!d.attach_to_play(filename)) {
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
314 printf("wavpack: Error opening file: \"%s\"\n", filename);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
315 killDecodeThread = true;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
316 return end_thread();
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
317 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
318 bps = WavpackGetBytesPerSample(d.ctx) * d.num_channels;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
319 DBG("reading %s at %d rate with %d channels\n", filename, d.sample_rate, d.num_channels);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
320
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
321 if (!d.open_audio()) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
322 DBG("error opening xmms audio channel\n");
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
323 killDecodeThread = true;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
324 AudioError = true;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
325 openedAudio = false;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
326 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
327 else {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
328 DBG("opened xmms audio channel\n");
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
329 openedAudio = true;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
330 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
331 unsigned status;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
332 char *display = generate_title(filename, d.ctx);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
333 int length = (int) (1000 * WavpackGetNumSamples(d.ctx));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
334
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
335 while (!killDecodeThread) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
336 if (isSeek != -1) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
337 DBG("seeking to position %d\n", isSeek);
253
ab24cfe495e0 [svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents: 247
diff changeset
338 WavpackSeekSample(d.ctx, (int)(isSeek * d.sample_rate));
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
339 isSeek = -1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
340 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
341 if (paused == 0
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
342 && (mod.output->buffer_free() >=
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
343 (1152 * 2 *
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
344 (16 / 8)) << (mod.output->buffer_playing()? 1 : 0))) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
345 status =
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
346 WavpackUnpackSamples(d.ctx, d.input, BUFFER_SIZE);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
347 if (status == (unsigned) (-1)) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
348 printf("wavpack: Error decoding file.\n");
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
349 break;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
350 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
351 else if (status == 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
352 killDecodeThread = true;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
353 break;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
354 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
355 else {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
356 d.process_buffer(status);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
357 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
358 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
359 else {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
360 xmms_usleep(10000);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
361 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
362 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
363 return end_thread();
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
364 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
365
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
366 static void
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
367 wv_play(char *filename)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
368 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
369 paused = 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
370 isSeek = -1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
371 killDecodeThread = false;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
372 AudioError = false;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
373 thread_handle = g_thread_create(DecodeThread, (void *) filename, TRUE, NULL);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
374 return;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
375 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
376
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
377 static TitleInput *
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
378 tuple_from_WavpackContext(const char *fn, WavpackContext *ctx)
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
379 {
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
380 ape_tag tag;
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
381 TitleInput *ti;
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
382 int sample_rate = WavpackGetSampleRate(ctx);
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
383
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
384 ti = bmp_title_input_new();
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
385
130
16e2c64d8b2b [svn] - provide a complete tuple (fixes albumart and such; path was missing.)
nenolod
parents: 115
diff changeset
386 ti->file_name = g_path_get_basename(fn);
16e2c64d8b2b [svn] - provide a complete tuple (fixes albumart and such; path was missing.)
nenolod
parents: 115
diff changeset
387 ti->file_path = g_path_get_dirname(fn);
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
388 ti->file_ext = "wv";
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
389
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
390 load_tag(&tag, ctx);
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
391
115
2e77e3fdd3c1 [svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents: 114
diff changeset
392 ti->track_name = g_strdup(tag.title);
2e77e3fdd3c1 [svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents: 114
diff changeset
393 ti->performer = g_strdup(tag.artist);
2e77e3fdd3c1 [svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents: 114
diff changeset
394 ti->album_name = g_strdup(tag.album);
2e77e3fdd3c1 [svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents: 114
diff changeset
395 ti->date = g_strdup(tag.year);
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
396 ti->track_number = atoi(tag.track);
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
397 if (ti->track_number < 0)
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
398 ti->track_number = 0;
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
399 ti->year = atoi(tag.year);
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
400 if (ti->year < 0)
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
401 ti->year = 0;
115
2e77e3fdd3c1 [svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents: 114
diff changeset
402 ti->genre = g_strdup(tag.genre);
2e77e3fdd3c1 [svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents: 114
diff changeset
403 ti->comment = g_strdup(tag.comment);
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
404 ti->length = (int)(WavpackGetNumSamples(ctx) / sample_rate) * 1000;
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
405
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
406 return ti;
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
407 }
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
408
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
409 static char *
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
410 generate_title(const char *fn, WavpackContext *ctx)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
411 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
412 static char *displaytitle = NULL;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
413 TitleInput *ti;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
414
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
415 ti = tuple_from_WavpackContext(fn, ctx);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
416
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
417 displaytitle = xmms_get_titlestring(xmms_get_gentitle_format(), ti);
115
2e77e3fdd3c1 [svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents: 114
diff changeset
418 if (!displaytitle || *displaytitle == '\0')
2e77e3fdd3c1 [svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents: 114
diff changeset
419 displaytitle = g_strdup(fn);
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
420
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
421 bmp_title_input_free(ti);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
422
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
423 return displaytitle;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
424 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
425
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
426 static TitleInput *
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
427 wv_get_song_tuple(char *filename)
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
428 {
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
429 TitleInput *ti;
233
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
430 WavpackDecoder d(&mod);
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
431
233
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
432 if (!d.attach(filename)) {
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
433 printf("wavpack: Error opening file: \"%s\"\n", filename);
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
434 return NULL;
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
435 }
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
436
233
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
437 ti = tuple_from_WavpackContext(filename, d.ctx);
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
438
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
439 return ti;
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
440 }
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
441
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
442 static void
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
443 wv_get_song_info(char *filename, char **title, int *length)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
444 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
445 assert(filename != NULL);
233
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
446 WavpackDecoder d(&mod);
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
447
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
448 if (!d.attach(filename)) {
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
449 printf("wavpack: Error opening file: \"%s\"\n", filename);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
450 return;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
451 }
233
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
452
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
453 int sample_rate = WavpackGetSampleRate(d.ctx);
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
454 int num_channels = WavpackGetNumChannels(d.ctx);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
455 DBG("reading %s at %d rate with %d channels\n", filename, sample_rate, num_channels);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
456
233
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
457 *length = (int)(WavpackGetNumSamples(d.ctx) / sample_rate) * 1000,
7b7660c9f31c [svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents: 130
diff changeset
458 *title = generate_title(filename, d.ctx);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
459 DBG("title for %s = %s\n", filename, *title);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
460 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
461
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
462 static int
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
463 wv_get_time(void)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
464 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
465 if (!mod.output)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
466 return -1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
467 if (AudioError)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
468 return -2;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
469 if (killDecodeThread && !mod.output->buffer_playing())
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
470 return -1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
471 return mod.output->output_time();
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
472 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
473
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
474
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
475 static void
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
476 wv_seek(int sec)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
477 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
478 isSeek = sec;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
479 mod.output->flush((int) (1000 * isSeek));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
480 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
481
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
482 static void
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
483 wv_pause(short pause)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
484 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
485 mod.output->pause(paused = pause);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
486 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
487
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
488 static void
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
489 wv_stop(void)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
490 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
491 killDecodeThread = true;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
492 if (thread_handle != 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
493 g_thread_join(thread_handle);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
494 if (openedAudio) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
495 mod.output->buffer_free();
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
496 mod.output->close_audio();
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
497 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
498 openedAudio = false;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
499 if (AudioError)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
500 printf("Could not open Audio\n");
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
501 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
502
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
503 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
504
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
505 static void
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
506 wv_load_config()
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
507 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
508 ConfigDb *cfg;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
509
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
510 cfg = bmp_cfg_db_open();
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
511
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
512 bmp_cfg_db_get_bool(cfg, "wavpack", "clip_prevention",
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
513 &clipPreventionEnabled);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
514 bmp_cfg_db_get_bool(cfg, "wavpack", "album_replaygain",
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
515 &albumReplaygainEnabled);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
516 bmp_cfg_db_get_bool(cfg, "wavpack", "dyn_bitrate", &dynBitrateEnabled);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
517 bmp_cfg_db_get_bool(cfg, "wavpack", "replaygain", &replaygainEnabled);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
518 bmp_cfg_db_close(cfg);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
519
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
520 openedAudio = false;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
521 }