aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/modplug_decoder_plugin.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/decoder/modplug_decoder_plugin.c (renamed from src/decoder/modplug_plugin.c)67
1 files changed, 23 insertions, 44 deletions
diff --git a/src/decoder/modplug_plugin.c b/src/decoder/modplug_decoder_plugin.c
index f636f2fa6..037c2fd74 100644
--- a/src/decoder/modplug_plugin.c
+++ b/src/decoder/modplug_decoder_plugin.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * Copyright (C) 2003-2010 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -17,10 +17,12 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "../decoder_api.h"
+#include "config.h"
+#include "decoder_api.h"
#include <glib.h>
#include <modplug.h>
+#include <assert.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "modplug"
@@ -92,10 +94,8 @@ mod_decode(struct decoder *decoder, struct input_stream *is)
ModPlug_Settings settings;
GByteArray *bdatas;
struct audio_format audio_format;
- float total_time = 0.0;
- int ret, current;
+ int ret;
char audio_buffer[MODPLUG_FRAME_SIZE];
- float sec_perbyte;
enum decoder_command cmd = DECODE_COMMAND_NONE;
bdatas = mod_loadfile(decoder, is);
@@ -121,37 +121,26 @@ mod_decode(struct decoder *decoder, struct input_stream *is)
return;
}
- audio_format.bits = 16;
- audio_format.sample_rate = 44100;
- audio_format.channels = 2;
-
- sec_perbyte =
- 1.0 / ((audio_format.bits * audio_format.channels / 8.0) *
- (float)audio_format.sample_rate);
-
- total_time = ModPlug_GetLength(f) / 1000;
+ audio_format_init(&audio_format, 44100, SAMPLE_FORMAT_S16, 2);
+ assert(audio_format_valid(&audio_format));
decoder_initialized(decoder, &audio_format,
- is->seekable, total_time);
-
- total_time = 0;
+ is->seekable, ModPlug_GetLength(f) / 1000.0);
do {
ret = ModPlug_Read(f, audio_buffer, MODPLUG_FRAME_SIZE);
-
- if (ret == 0) {
+ if (ret <= 0)
break;
- }
- total_time += ret * sec_perbyte;
cmd = decoder_data(decoder, NULL,
audio_buffer, ret,
- total_time, 0, NULL);
+ 0);
if (cmd == DECODE_COMMAND_SEEK) {
- total_time = decoder_seek_where(decoder);
- current = total_time * 1000;
- ModPlug_Seek(f, current);
+ float where = decoder_seek_where(decoder);
+
+ ModPlug_Seek(f, (int)(where * 1000.0));
+
decoder_command_finished(decoder);
}
@@ -160,43 +149,33 @@ mod_decode(struct decoder *decoder, struct input_stream *is)
ModPlug_Unload(f);
}
-static struct tag *mod_tagdup(const char *file)
+static struct tag *
+modplug_stream_tag(struct input_stream *is)
{
ModPlugFile *f;
struct tag *ret = NULL;
GByteArray *bdatas;
char *title;
- struct input_stream is;
- if (!input_stream_open(&is, file)) {
- g_warning("cant open file %s\n", file);
+ bdatas = mod_loadfile(NULL, is);
+ if (!bdatas)
return NULL;
- }
-
- bdatas = mod_loadfile(NULL, &is);
- if (!bdatas) {
- g_warning("cant load file %s\n", file);
- return NULL;
- }
f = ModPlug_Load(bdatas->data, bdatas->len);
g_byte_array_free(bdatas, TRUE);
- if (!f) {
- g_warning("could not decode file %s\n", file);
+ if (f == NULL)
return NULL;
- }
+
ret = tag_new();
- ret->time = 0;
+ ret->time = ModPlug_GetLength(f) / 1000;
title = g_strdup(ModPlug_GetName(f));
if (title)
- tag_add_item(ret, TAG_ITEM_TITLE, title);
+ tag_add_item(ret, TAG_TITLE, title);
g_free(title);
ModPlug_Unload(f);
- input_stream_close(&is);
-
return ret;
}
@@ -210,6 +189,6 @@ static const char *const mod_suffixes[] = {
const struct decoder_plugin modplug_decoder_plugin = {
.name = "modplug",
.stream_decode = mod_decode,
- .tag_dup = mod_tagdup,
+ .stream_tag = modplug_stream_tag,
.suffixes = mod_suffixes,
};