/* * codec.h * * Definitions of data types and constants. * Useful debugging functions. * * TODO: Move some of this stuff out into files for the specific features * * Scott Wilson * rswilson@ccrma.stanford.edu * last updated: June 15, 2003 * */ #ifndef _CODEC_H #define _CODEC_H #include #include #include typedef uint8_t codec_byte_t; typedef uint64_t codec_long_t; typedef int codec_err_t; #ifdef CODEC_USE_FLOATS typedef float codec_float_t; #else typedef double codec_float_t; #endif #define CODEC_EPSILON 1e-12 #define LOG2(x) (log(x) / log(2)) #define TWOPOW(x) (1 << (x)) /* x power of 2 */ #define ABS(x) (x >= 0 ? x : -x) // Debug enable variable - see codec_debug below. extern uint8_t g_codec_debug; // Error handling constants #define ERR_NONE (codec_err_t) 0 #define ERR_BADARRAY -1 #define ERR_NOMEM -2 #define ERR_MISC -3 #define ERR_FILEIO -4 // prints out the binary and hex codes for a byte void codec_char_dump(char c); // prints out the binary and hex codes for a 16-bit word void codec_short_dump(uint16_t s); void codec_error(const char *component, const char *fn, const char *msg); void codec_debug(const char *component, const char *fn, const char *msg); // warning - these only work for names in the format name.ext - // // more than one (or less than one) dot will cause breakage #define GENERATE_CODED_FILENAME(ifname, params, cfname) { \ char *ext, tmp[256]; \ strncpy(tmp, ifname, 255); \ strtok(tmp, "."); ext = strtok(0,"."); \ if (params->quantization_type == FLOAT_QUANTIZE) \ sprintf(cfname, "%s.%s.%s_%us_%um.enc", tmp, ext, \ qstyle_short_string(params->quantization_type), params->scale_bits, params->mantissa_bits); \ else \ sprintf(cfname, "%s.%s.%s_%uu.enc", tmp, ext, \ qstyle_short_string(params->quantization_type), params->uniform_bits); \ } #define GENERATE_DECODED_FILENAME(ifname, params, ofname) { \ char *ext, tmp[256]; \ strncpy(tmp, ifname, 255); \ strtok(tmp, "."); ext = strtok(0,"."); \ if (params->quantization_type == FLOAT_QUANTIZE) \ sprintf(ofname, "%s.dec.%s_%us_%um.%s", tmp, \ qstyle_short_string(params->quantization_type), params->scale_bits, params->mantissa_bits, ext); \ else \ sprintf(ofname, "%s.dec.%s_%uu.%s", tmp, \ qstyle_short_string(params->quantization_type), params->uniform_bits, ext); \ } #endif