comparison src/wavpack/libwavpack.cxx @ 2233:0de647993c2a

- make use of AUDDBG - eliminate warnings
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Sun, 16 Dec 2007 18:18:03 +0900
parents b8da6a0b0da2
children b6f09d280f2c
comparison
equal deleted inserted replaced
2232:9d2d7061caed 2233:0de647993c2a
1 // #define AUD_DEBUG 1
2
1 #include <string> 3 #include <string>
2 4
3 #include <assert.h> 5 #include <assert.h>
4 #include <string.h> 6 #include <string.h>
5 #include <stdio.h> 7 #include <stdio.h>
22 #include "../../config.h" 24 #include "../../config.h"
23 #ifndef M_LN10 25 #ifndef M_LN10
24 #define M_LN10 2.3025850929940456840179914546843642 26 #define M_LN10 2.3025850929940456840179914546843642
25 #endif 27 #endif
26 28
27 #ifdef DEBUG
28 # define DBG(format, args...) fprintf(stderr, format, ## args)
29 #else
30 # define DBG(format, args...)
31 #endif
32
33 #define BUFFER_SIZE 256 // read buffer size, in samples 29 #define BUFFER_SIZE 256 // read buffer size, in samples
34 30
35 static void wv_load_config(); 31 static void wv_load_config();
36 static int wv_is_our_fd(gchar *filename, VFSFile *file); 32 static int wv_is_our_fd(gchar *filename, VFSFile *file);
37 static Tuple *wv_probe_for_tuple(gchar *filename, VFSFile *file); 33 static Tuple *wv_probe_for_tuple(gchar *filename, VFSFile *file);
40 static void wv_pause(InputPlayback *, short); 36 static void wv_pause(InputPlayback *, short);
41 static void wv_seek(InputPlayback *, int); 37 static void wv_seek(InputPlayback *, int);
42 static int wv_get_time(InputPlayback *); 38 static int wv_get_time(InputPlayback *);
43 static void wv_get_song_info(char *, char **, int *); 39 static void wv_get_song_info(char *, char **, int *);
44 static char *generate_title(const char *, WavpackContext *ctx); 40 static char *generate_title(const char *, WavpackContext *ctx);
45 static double isSeek; 41 static int isSeek;
46 static short paused; 42 static short paused;
47 static bool killDecodeThread; 43 static bool killDecodeThread;
48 static bool AudioError; 44 static bool AudioError;
49 static GThread *thread_handle; 45 static GThread *thread_handle;
50 static Tuple *wv_get_song_tuple(char *); 46 static Tuple *wv_get_song_tuple(char *);
303 } 299 }
304 300
305 static void * 301 static void *
306 DecodeThread(InputPlayback *playback) 302 DecodeThread(InputPlayback *playback)
307 { 303 {
308 ape_tag tag; 304 int bps;
305 #ifdef AUD_DEBUG
309 char *filename = playback->filename; 306 char *filename = playback->filename;
310 int bps_updateCounter = 0; 307 #endif
311 int bps;
312 int i;
313 WavpackDecoder d(&mod); 308 WavpackDecoder d(&mod);
314 309
315 if (!d.attach_to_play(playback)) { 310 if (!d.attach_to_play(playback)) {
316 killDecodeThread = true; 311 killDecodeThread = true;
317 return end_thread(); 312 return end_thread();
318 } 313 }
319 bps = WavpackGetBytesPerSample(d.ctx) * d.num_channels; 314 bps = WavpackGetBytesPerSample(d.ctx) * d.num_channels;
320 DBG("reading %s at %d rate with %d channels\n", filename, d.sample_rate, d.num_channels); 315 AUDDBG("reading %s at %d rate with %d channels\n", filename, d.sample_rate, d.num_channels);
321 316
322 if (!d.open_audio()) { 317 if (!d.open_audio()) {
323 DBG("error opening audio channel\n"); 318 AUDDBG("error opening audio channel\n");
324 killDecodeThread = true; 319 killDecodeThread = true;
325 AudioError = true; 320 AudioError = true;
326 openedAudio = false; 321 openedAudio = false;
327 } 322 }
328 else { 323 else {
329 DBG("opened audio channel\n"); 324 AUDDBG("opened audio channel\n");
330 openedAudio = true; 325 openedAudio = true;
331 } 326 }
332 unsigned status; 327 unsigned status;
328 #if 0
333 char *display = generate_title(filename, d.ctx); 329 char *display = generate_title(filename, d.ctx);
334 int length = (int) (1000 * WavpackGetNumSamples(d.ctx)); 330 int length = (int) (1000 * WavpackGetNumSamples(d.ctx));
335 331 #endif
336 while (!killDecodeThread) { 332 while (!killDecodeThread) {
337 if (isSeek != -1) { 333 if (isSeek != -1) {
338 DBG("seeking to position %d\n", isSeek); 334 AUDDBG("seeking to position %d\n", isSeek);
339 WavpackSeekSample(d.ctx, (int)(isSeek * d.sample_rate)); 335 WavpackSeekSample(d.ctx, (int)(isSeek * d.sample_rate));
340 isSeek = -1; 336 isSeek = -1;
341 } 337 }
342 if (paused == 0 338 if (paused == 0
343 && (mod.output->buffer_free() >= 339 && (mod.output->buffer_free() >=
475 printf("wavpack: Error opening file: \"%s\"\n", filename); 471 printf("wavpack: Error opening file: \"%s\"\n", filename);
476 return; 472 return;
477 } 473 }
478 474
479 int sample_rate = WavpackGetSampleRate(d.ctx); 475 int sample_rate = WavpackGetSampleRate(d.ctx);
476 #ifdef AUD_DEBUG
480 int num_channels = WavpackGetNumChannels(d.ctx); 477 int num_channels = WavpackGetNumChannels(d.ctx);
481 DBG("reading %s at %d rate with %d channels\n", filename, sample_rate, num_channels); 478 #endif
479 AUDDBG("reading %s at %d rate with %d channels\n", filename, sample_rate, num_channels);
482 480
483 *length = (int)(WavpackGetNumSamples(d.ctx) / sample_rate) * 1000, 481 *length = (int)(WavpackGetNumSamples(d.ctx) / sample_rate) * 1000,
484 *title = generate_title(filename, d.ctx); 482 *title = generate_title(filename, d.ctx);
485 DBG("title for %s = %s\n", filename, *title); 483 AUDDBG("title for %s = %s\n", filename, *title);
486 } 484 }
487 485
488 static int 486 static int
489 wv_get_time(InputPlayback *data) 487 wv_get_time(InputPlayback *data)
490 { 488 {