>From 0038b1f0dd619d9cf6aae13097194da9ce560b0f Mon Sep 17 00:00:00 2001
From: toney <to...@jah-data.(none)>
Date: Sat, 24 Oct 2009 12:34:54 -0700
Subject: [PATCH 2/4] Add hively decoder.

---
 src/decoder/hively_plugin.c |  107 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 107 insertions(+), 0 deletions(-)
 create mode 100644 src/decoder/hively_plugin.c

diff --git a/src/decoder/hively_plugin.c b/src/decoder/hively_plugin.c
new file mode 100644
index 0000000..1d654e1
--- /dev/null
+++ b/src/decoder/hively_plugin.c
@@ -0,0 +1,107 @@
+/* Thanks to Pink and Dexter of Abyss for AHX and Xeron for the hively format 
! */
+/* Based on the latest replayer from www.hivelytracker.com */
+
+#include "../decoder_api.h"
+
+#include <glib.h>
+#include "hvl_replay.h"
+
+#undef G_LOG_DOMAIN
+#define G_LOG_DOMAIN "hively"
+
+#define HIVELY_LEN 48000/50
+
+static void
+hvl_file_decode(struct decoder *decoder, const char *path_fs)
+{
+       struct hvl_tune *tune;
+       struct audio_format audio_format;
+       enum decoder_command cmd;
+       size_t hivelyIndex = 0;
+       int16 hivelyLeft[HIVELY_LEN], hivelyRight[HIVELY_LEN];
+
+       int16 out[4096];
+       int i;
+       int streamPos = 0;
+       unsigned short buffersize;
+       int length = 4096;
+
+       tune = hvl_LoadTune(path_fs, 48000, 4);
+
+       if(tune == NULL) {
+               g_warning("failed to load file");
+               return;
+       }
+
+       hvl_InitReplayer();
+
+       /* initialize MPD decoder */
+       audio_format.sample_rate = 48000;
+       audio_format.bits = 16;
+       audio_format.channels = 2;
+
+       decoder_initialized(decoder, &audio_format, false, -1);
+       /* play */
+       //mostly copied from hively replayer_linux/play_hvl.c
+       do {
+               memset(out, 0, sizeof(out));
+               //flush previous frame
+               streamPos = 0;
+               for(i = hivelyIndex; i < (HIVELY_LEN); i++) {
+                       out[streamPos++] = hivelyLeft[i];
+                       out[streamPos++] = hivelyRight[i];
+               }
+
+               while(streamPos < length) {
+                       hvl_DecodeFrame(tune, (int8*)hivelyLeft, 
(int8*)hivelyRight, 2);
+                       for(i = 0; i < (HIVELY_LEN) && streamPos < length; i++) 
{
+                               out[streamPos++] = hivelyLeft[i];
+                               out[streamPos++] = hivelyRight[i];
+                       }
+               }
+               hivelyIndex = i;
+
+               buffersize = sizeof(out);
+               cmd = decoder_data(decoder, NULL,
+                                       out, buffersize,
+                                       0, 0, NULL);
+
+       } while(cmd == DECODE_COMMAND_NONE);
+
+       hvl_FreeTune(tune);
+}
+
+static struct tag *
+hvl_tag_dup(const char *path_fs)
+{
+       struct hvl_tune *tune;
+       struct tag *tag = tag_new();
+       tune = hvl_LoadTune(path_fs, 48000, 4);
+
+       if( !tune ) {
+               return NULL;
+       }
+
+       tag_add_item(tag, TAG_TITLE, tune->ht_Name);
+
+       return tag;
+}
+
+static const char *const hvl_suffixes[] = {
+       "hvl",
+       "ahx",
+       NULL
+};
+
+const struct decoder_plugin hively_decoder_plugin;
+const struct decoder_plugin hively_decoder_plugin = {
+       .name = "hively",
+       NULL, //.init
+       NULL, //.finish
+       NULL, //stream decode
+       .file_decode = hvl_file_decode,
+       .tag_dup = hvl_tag_dup,
+       NULL, //container scan
+       .suffixes = hvl_suffixes,
+       NULL, //mime types
+};
-- 
1.6.3.1


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Musicpd-dev-team mailing list
Musicpd-dev-team@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team

Reply via email to