From 08b144b57eeacc6b4f38fc028e6314a36d980ef3 Mon Sep 17 00:00:00 2001 From: David Griffith Date: Wed, 15 Aug 2012 13:48:58 -0700 Subject: [PATCH] Adding ux_blorb.c and ux_blorb.h --- src/curses/ux_blorb.c | 76 +++++++++++++++++++++++++++++++++++++++++++ src/curses/ux_blorb.h | 36 ++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 src/curses/ux_blorb.c create mode 100644 src/curses/ux_blorb.h diff --git a/src/curses/ux_blorb.c b/src/curses/ux_blorb.c new file mode 100644 index 0000000..a71c59f --- /dev/null +++ b/src/curses/ux_blorb.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include + +#include "../common/frotz.h" +#include "../blorb/blorb.h" +#include "../blorb/blorblow.h" +#include "ux_blorb.h" + + +char *findchunk(char *data, char *string, int length) +{ + char *mydata = data+12; + while (TRUE) { + if (strncmp((char*)mydata, string, 4) == 0) + return mydata+8; + + mydata += ReadLong(mydata+4)+8; + + if ((mydata - data) >= length) + break; + } + return NULL; +} + + +unsigned short ReadShort(const unsigned char *bytes) +{ + return (unsigned short)( + ((unsigned short)(bytes[0] & 0xFF) << 8) | + ((unsigned short)(bytes[1] & 0xFF))); +} + +unsigned long ReadLong(const unsigned char *bytes) +{ + return (unsigned long)( + ((unsigned long)(bytes[0] & 0xFF) << 24) | + ((unsigned long)(bytes[1] & 0xFF) << 16) | + ((unsigned long)(bytes[2] & 0xFF) << 8) | + ((unsigned long)(bytes[3] & 0xFF))); +} + +double ReadExtended(const unsigned char *bytes) +{ + double f; + int expon; + unsigned long hiMant, loMant; + + expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF); + hiMant = ReadLong(bytes+2); + loMant = ReadLong(bytes+6); + + if (expon == 0 && hiMant == 0 && loMant == 0) + f = 0; + else { + if (expon == 0x7FFF) /* Infinity or NaN */ + f = -1; + else { + expon -= 16383; + /* must #include or these won't work */ + f = ldexp(UnsignedToFloat(hiMant),expon -= 31); + f += ldexp(UnsignedToFloat(loMant),expon -= 32); + } + } + + if (bytes[0] & 0x80) + return -f; + return f; +} + + +/* /home/dave/zcode/mystory.z5 */ +/* /home/dave/zcode/mystory.blb */ diff --git a/src/curses/ux_blorb.h b/src/curses/ux_blorb.h new file mode 100644 index 0000000..c444b45 --- /dev/null +++ b/src/curses/ux_blorb.h @@ -0,0 +1,36 @@ + +#include "../blorb/blorb.h" +#include "../blorb/blorblow.h" + + +typedef struct sampledata_struct { + unsigned short channels; + unsigned long samples; + unsigned short bits; + double rate; +} sampledata_t; + +/* +typedef struct blorb_data_struct { + bb_map_t map; + bb_result_t result; +} blorb_data_t; +*/ + +bb_err_t blorb_err; +bb_map_t *blorb_map; +bb_result_t blorb_res; + + +/* uint32 *findchunk(uint32 *data, char *chunkID, int length); */ +char *findchunk(char *pstart, char *fourcc, int n); +unsigned short ReadShort(const unsigned char *bytes); +unsigned long ReadLong(const unsigned char *bytes); +double ReadExtended(const unsigned char *bytes); + +#define UnsignedToFloat(u) (((double)((long)(u - 2147483647L - 1))) + 2147483648.0) + + + + + -- 2.34.1