annotate src/wavpack/libwavpack.cxx @ 130:16e2c64d8b2b trunk

[svn] - provide a complete tuple (fixes albumart and such; path was missing.)
author nenolod
date Fri, 27 Oct 2006 11:58:34 -0700
parents 2e77e3fdd3c1
children 7b7660c9f31c
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>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
13 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
14 #include <glib.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
15 #include <gtk/gtk.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
16 #include <iconv.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
17 #include <math.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
18 #include "tags.h"
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
19 #ifndef M_LN10
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
20 #define M_LN10 2.3025850929940456840179914546843642
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
21 #endif
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
22
112
5755fb99ddab [svn] - make debugging notices optional
nenolod
parents: 111
diff changeset
23 #ifdef DEBUG
5755fb99ddab [svn] - make debugging notices optional
nenolod
parents: 111
diff changeset
24 # define DBG(format, args...) fprintf(stderr, format, ## args)
5755fb99ddab [svn] - make debugging notices optional
nenolod
parents: 111
diff changeset
25 #else
5755fb99ddab [svn] - make debugging notices optional
nenolod
parents: 111
diff changeset
26 # define DBG(format, args...)
5755fb99ddab [svn] - make debugging notices optional
nenolod
parents: 111
diff changeset
27 #endif
5755fb99ddab [svn] - make debugging notices optional
nenolod
parents: 111
diff changeset
28
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
29 #define BUFFER_SIZE 256 // read buffer size, in samples
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
30
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
31 extern "C" InputPlugin * get_iplugin_info(void);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
32 static void wv_load_config();
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
33 static int wv_is_our_file(char *);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
34 static void wv_play(char *);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
35 static void wv_stop(void);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
36 static void wv_pause(short);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
37 static void wv_seek(int);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
38 static int wv_get_time(void);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
39 static void wv_get_song_info(char *, char **, int *);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
40 static char *generate_title(const char *, WavpackContext *ctx);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
41 static double isSeek;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
42 static short paused;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
43 static bool killDecodeThread;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
44 static bool AudioError;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
45 static GThread *thread_handle;
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
46 static TitleInput *wv_get_song_tuple(char *);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
47
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
48 // in ui.cpp
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
49 void wv_configure();
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
50 void wv_about_box(void);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
51 void wv_file_info_box(char *);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
52 extern gboolean clipPreventionEnabled;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
53 extern gboolean dynBitrateEnabled;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
54 extern gboolean replaygainEnabled;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
55 extern gboolean albumReplaygainEnabled;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
56 extern gboolean openedAudio;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
57
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
58 InputPlugin mod = {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
59 NULL, //handle
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
60 NULL, //filename
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
61 NULL,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
62 wv_load_config,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
63 wv_about_box,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
64 wv_configure,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
65 wv_is_our_file,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
66 NULL, //no use
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
67 wv_play,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
68 wv_stop,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
69 wv_pause,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
70 wv_seek,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
71 NULL, //set eq
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
72 wv_get_time,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
73 NULL, //get volume
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
74 NULL, //set volume
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
75 NULL, //cleanup
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
76 NULL, //obsolete
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
77 NULL, //add_vis
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
78 NULL,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
79 NULL,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
80 wv_get_song_info,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
81 wv_file_info_box, //info box
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
82 NULL, //output
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
83 wv_get_song_tuple,
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
84 };
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
85
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
86 class WavpackDecoder
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
87 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
88 public:
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
89 InputPlugin *mod;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
90 int32_t *input;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
91 int16_t *output;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
92 int sample_rate;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
93 int num_channels;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
94 WavpackContext *ctx;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
95 char error_buff[4096]; // TODO: fixme!
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
96
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
97 WavpackDecoder(InputPlugin *mod) : mod(mod)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
98 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
99 ctx = NULL;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
100 input = NULL;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
101 output = NULL;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
102 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
103
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
104 ~WavpackDecoder()
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
105 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
106 if (input != NULL) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
107 free(input);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
108 input = NULL;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
109 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
110 if (output != NULL) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
111 free(output);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
112 output = NULL;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
113 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
114 if (ctx != NULL) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
115 WavpackCloseFile(ctx);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
116 ctx = NULL;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
117 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
118 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
119
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
120 bool attach(const char *filename)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
121 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
122 ctx = WavpackOpenFileInput(filename, error_buff, OPEN_TAGS | OPEN_WVC, 0);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
123
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
124 if (ctx == NULL) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
125 return false;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
126 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
127
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
128 sample_rate = WavpackGetSampleRate(ctx);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
129 num_channels = WavpackGetNumChannels(ctx);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
130 input = (int32_t *)calloc(BUFFER_SIZE, num_channels * sizeof(int32_t));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
131 output = (int16_t *)calloc(BUFFER_SIZE, num_channels * sizeof(int16_t));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
132 mod->set_info(generate_title(filename, ctx),
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
133 (int) (WavpackGetNumSamples(ctx) / sample_rate) * 1000,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
134 (int) WavpackGetAverageBitrate(ctx, num_channels),
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
135 (int) sample_rate, num_channels);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
136 return true;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
137 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
138
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
139 bool open_audio()
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
140 {
112
5755fb99ddab [svn] - make debugging notices optional
nenolod
parents: 111
diff changeset
141 return mod->output->open_audio(FMT_S16_NE, sample_rate, num_channels);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
142 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
143
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
144 void process_buffer(size_t num_samples)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
145 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
146 for (int i = 0; i < num_samples * num_channels; i++) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
147 output[i] = input[i];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
148 }
112
5755fb99ddab [svn] - make debugging notices optional
nenolod
parents: 111
diff changeset
149 produce_audio(mod->output->output_time(), FMT_S16_NE,
111
5745352e0c88 [svn] - hey, this compiles now. neat :P
nenolod
parents: 109
diff changeset
150 num_channels,
5745352e0c88 [svn] - hey, this compiles now. neat :P
nenolod
parents: 109
diff changeset
151 num_samples * num_channels * sizeof(int16_t),
5745352e0c88 [svn] - hey, this compiles now. neat :P
nenolod
parents: 109
diff changeset
152 output,
5745352e0c88 [svn] - hey, this compiles now. neat :P
nenolod
parents: 109
diff changeset
153 NULL);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
154 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
155 };
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
156
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
157 extern "C" InputPlugin *
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
158 get_iplugin_info(void)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
159 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
160 mod.description =
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
161 g_strdup_printf(("Wavpack Decoder Plugin %s"), VERSION);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
162 return &mod;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
163 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
164
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
165 static int
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
166 wv_is_our_file(char *filename)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
167 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
168 char *ext;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
169
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
170 ext = strrchr(filename, '.');
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
171 if (ext) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
172 if (!strcasecmp(ext, ".wv")) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
173 return TRUE;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
174 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
175 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
176 return FALSE;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
177 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
178
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
179 void
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
180 load_tag(ape_tag *tag, WavpackContext *ctx)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
181 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
182 memset(tag, 0, sizeof(ape_tag));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
183 WavpackGetTagItem(ctx, "Album", tag->album, sizeof(tag->album));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
184 WavpackGetTagItem(ctx, "Artist", tag->artist, sizeof(tag->artist));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
185 WavpackGetTagItem(ctx, "Comment", tag->comment, sizeof(tag->comment));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
186 WavpackGetTagItem(ctx, "Genre", tag->genre, sizeof(tag->genre));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
187 WavpackGetTagItem(ctx, "Title", tag->title, sizeof(tag->title));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
188 WavpackGetTagItem(ctx, "Track", tag->track, sizeof(tag->track));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
189 WavpackGetTagItem(ctx, "Year", tag->year, sizeof(tag->year));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
190 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
191
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
192 static char *
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
193 convertUTF8toLocale(char *utf8)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
194 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
195 // note - opens a new iconv descriptor for each call
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
196 // will have to find a way to reuse the descriptor if this turns
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
197 // out to be too slow
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
198 iconv_t idesc = iconv_open("", "UTF-8");
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
199 if (idesc == (iconv_t) -1) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
200 perror("iconv_open failed");
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
201 return g_strdup(utf8);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
202 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
203
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
204 size_t in_left = strlen(utf8);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
205 size_t out_left = 2 * in_left + 1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
206 char *buf = (char *)g_malloc(out_left);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
207 char *in = utf8;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
208 char *out = buf;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
209
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
210 memset(buf, 0, out_left);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
211 size_t err = iconv(idesc, &in, &in_left, &out, &out_left);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
212 iconv_close(idesc);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
213 return buf;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
214 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
215
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
216 static void *
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
217 end_thread()
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
218 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
219 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
220 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
221
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
222 static void *
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
223 DecodeThread(void *a)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
224 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
225 ape_tag tag;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
226 char *filename = (char *) a;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
227 int bps_updateCounter = 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
228 int bps;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
229 int i;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
230 WavpackDecoder d(&mod);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
231
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
232 if (!d.attach(filename)) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
233 printf("wavpack: Error opening file: \"%s\"\n", filename);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
234 killDecodeThread = true;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
235 return end_thread();
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
236 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
237 bps = WavpackGetBytesPerSample(d.ctx) * d.num_channels;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
238 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
239
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
240 if (!d.open_audio()) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
241 DBG("error opening xmms audio channel\n");
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
242 killDecodeThread = true;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
243 AudioError = true;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
244 openedAudio = false;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
245 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
246 else {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
247 DBG("opened xmms audio channel\n");
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
248 openedAudio = true;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
249 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
250 unsigned status;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
251 char *display = generate_title(filename, d.ctx);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
252 int length = (int) (1000 * WavpackGetNumSamples(d.ctx));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
253
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
254 while (!killDecodeThread) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
255 if (isSeek != -1) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
256 DBG("seeking to position %d\n", isSeek);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
257 WavpackSeekSample(d.ctx, isSeek * d.sample_rate);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
258 isSeek = -1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
259 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
260 if (paused == 0
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
261 && (mod.output->buffer_free() >=
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
262 (1152 * 2 *
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
263 (16 / 8)) << (mod.output->buffer_playing()? 1 : 0))) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
264 status =
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
265 WavpackUnpackSamples(d.ctx, d.input, BUFFER_SIZE);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
266 if (status == (unsigned) (-1)) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
267 printf("wavpack: Error decoding file.\n");
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
268 break;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
269 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
270 else if (status == 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
271 killDecodeThread = true;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
272 break;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
273 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
274 else {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
275 d.process_buffer(status);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
276 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
277 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
278 else {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
279 xmms_usleep(10000);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
280 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
281 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
282 return end_thread();
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
283 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
284
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
285 static void
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
286 wv_play(char *filename)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
287 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
288 paused = 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
289 isSeek = -1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
290 killDecodeThread = false;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
291 AudioError = false;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
292 thread_handle = g_thread_create(DecodeThread, (void *) filename, TRUE, NULL);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
293 return;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
294 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
295
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
296 static TitleInput *
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
297 tuple_from_WavpackContext(const char *fn, WavpackContext *ctx)
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
298 {
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
299 ape_tag tag;
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
300 TitleInput *ti;
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
301 int sample_rate = WavpackGetSampleRate(ctx);
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
302
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
303 ti = bmp_title_input_new();
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
304
130
16e2c64d8b2b [svn] - provide a complete tuple (fixes albumart and such; path was missing.)
nenolod
parents: 115
diff changeset
305 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
306 ti->file_path = g_path_get_dirname(fn);
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
307 ti->file_ext = "wv";
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
308
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
309 load_tag(&tag, ctx);
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
310
115
2e77e3fdd3c1 [svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents: 114
diff changeset
311 ti->track_name = g_strdup(tag.title);
2e77e3fdd3c1 [svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents: 114
diff changeset
312 ti->performer = g_strdup(tag.artist);
2e77e3fdd3c1 [svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents: 114
diff changeset
313 ti->album_name = g_strdup(tag.album);
2e77e3fdd3c1 [svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents: 114
diff changeset
314 ti->date = g_strdup(tag.year);
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
315 ti->track_number = atoi(tag.track);
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
316 if (ti->track_number < 0)
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
317 ti->track_number = 0;
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
318 ti->year = atoi(tag.year);
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
319 if (ti->year < 0)
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
320 ti->year = 0;
115
2e77e3fdd3c1 [svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents: 114
diff changeset
321 ti->genre = g_strdup(tag.genre);
2e77e3fdd3c1 [svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents: 114
diff changeset
322 ti->comment = g_strdup(tag.comment);
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
323 ti->length = (int)(WavpackGetNumSamples(ctx) / sample_rate) * 1000;
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
324
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
325 return ti;
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
326 }
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
327
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
328 static char *
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
329 generate_title(const char *fn, WavpackContext *ctx)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
330 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
331 static char *displaytitle = NULL;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
332 TitleInput *ti;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
333
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
334 ti = tuple_from_WavpackContext(fn, ctx);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
335
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
336 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
337 if (!displaytitle || *displaytitle == '\0')
2e77e3fdd3c1 [svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents: 114
diff changeset
338 displaytitle = g_strdup(fn);
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
339
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
340 bmp_title_input_free(ti);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
341
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
342 return displaytitle;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
343 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
344
114
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
345 static TitleInput *
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
346 wv_get_song_tuple(char *filename)
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
347 {
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
348 TitleInput *ti;
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
349 char error_buff[4096]; // TODO: fixme!
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
350 WavpackContext *ctx = WavpackOpenFileInput(filename, error_buff, OPEN_TAGS | OPEN_WVC, 0);
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
351
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
352 if (ctx == NULL) {
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
353 printf("wavpack: Error opening file: \"%s: %s\"\n", filename, error_buff);
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
354 return NULL;
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
355 }
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
356
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
357 ti = tuple_from_WavpackContext(filename, ctx);
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
358
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
359 WavpackCloseFile(ctx);
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
360
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
361 return ti;
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
362 }
9bb02321f986 [svn] - tuple support
nenolod
parents: 112
diff changeset
363
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
364 static void
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
365 wv_get_song_info(char *filename, char **title, int *length)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
366 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
367 assert(filename != NULL);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
368 char error_buff[4096]; // TODO: fixme!
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
369 WavpackContext *ctx = WavpackOpenFileInput(filename, error_buff, OPEN_TAGS | OPEN_WVC, 0);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
370 if (ctx == NULL) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
371 printf("wavpack: Error opening file: \"%s: %s\"\n", filename, error_buff);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
372 return;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
373 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
374 int sample_rate = WavpackGetSampleRate(ctx);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
375 int num_channels = WavpackGetNumChannels(ctx);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
376 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
377
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
378 *length = (int)(WavpackGetNumSamples(ctx) / sample_rate) * 1000,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
379 *title = generate_title(filename, ctx);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
380 DBG("title for %s = %s\n", filename, *title);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
381 WavpackCloseFile(ctx);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
382 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
383
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
384 static int
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
385 wv_get_time(void)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
386 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
387 if (!mod.output)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
388 return -1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
389 if (AudioError)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
390 return -2;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
391 if (killDecodeThread && !mod.output->buffer_playing())
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
392 return -1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
393 return mod.output->output_time();
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
394 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
395
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
396
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
397 static void
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
398 wv_seek(int sec)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
399 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
400 isSeek = sec;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
401 mod.output->flush((int) (1000 * isSeek));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
402 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
403
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
404 static void
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
405 wv_pause(short pause)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
406 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
407 mod.output->pause(paused = pause);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
408 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
409
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
410 static void
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
411 wv_stop(void)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
412 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
413 killDecodeThread = true;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
414 if (thread_handle != 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
415 g_thread_join(thread_handle);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
416 if (openedAudio) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
417 mod.output->buffer_free();
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
418 mod.output->close_audio();
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
419 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
420 openedAudio = false;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
421 if (AudioError)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
422 printf("Could not open Audio\n");
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
423 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
424
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
425 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
426
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
427 static void
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
428 wv_load_config()
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
429 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
430 ConfigDb *cfg;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
431
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
432 cfg = bmp_cfg_db_open();
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
433
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
434 bmp_cfg_db_get_bool(cfg, "wavpack", "clip_prevention",
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
435 &clipPreventionEnabled);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
436 bmp_cfg_db_get_bool(cfg, "wavpack", "album_replaygain",
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
437 &albumReplaygainEnabled);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
438 bmp_cfg_db_get_bool(cfg, "wavpack", "dyn_bitrate", &dynBitrateEnabled);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
439 bmp_cfg_db_get_bool(cfg, "wavpack", "replaygain", &replaygainEnabled);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
440 bmp_cfg_db_close(cfg);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
441
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
442 openedAudio = false;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
443 }