From d992034049811d0bc5c1567f14a4070dc307a679 Mon Sep 17 00:00:00 2001 From: Hannes Date: Fri, 13 Jan 2012 16:58:36 +0100 Subject: [PATCH] changed type to typedefs --- headeredit.cpp | 22 ++++++++++++++++------ ulaw_decode.h | 10 +++++----- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/headeredit.cpp b/headeredit.cpp index 59db65a..2bd610f 100644 --- a/headeredit.cpp +++ b/headeredit.cpp @@ -3,12 +3,14 @@ #include #include #include +#include +//signed short decode(unsigned char t); + int16_t decode(uint8_t t); -signed short decode(unsigned char t); main() { std::vector data; - FILE* f = fopen("outputfileulaw.raw", "rb"); + FILE* f = fopen("outputfileulaw.wav", "rb"); rewind(f); while(!feof(f)) { @@ -16,7 +18,7 @@ main() fread(&s, sizeof s, 1, f); data.push_back(s); } - FILE* o = fopen("outputfileulaw.dec", "wb"); + FILE* o = fopen("outputfileulaw.raw", "wb"); int headersize = 4; int old_header_size = 58; unsigned int samples = data.size() - old_header_size; @@ -39,8 +41,16 @@ main() fwrite(&new_data[0], sizeof(unsigned char), samples_old+headersize, o); } - -signed short decode(unsigned char t) + int16_t decode(uint8_t t) +{ + int16_t exp = 0x8 - (0x7 & (t >> 4)); + uint16_t base = (0x1 << (exp+ 5)) - 34; + int16_t step = 0x1 << exp; + int16_t ret = base - step * (0xf & t); + ret = -ret - 1 + (2 * ret + 1) * (t >> 7); + return ret; +} +/*signed short decode(unsigned char t) { int exp = 0x8 - (0x7 & (t >> 4)); int base = (0x1 << (exp+ 5)) - 34; @@ -48,4 +58,4 @@ signed short decode(unsigned char t) signed short ret = base - step * (0xf & t); ret = -ret - 1 + (2 * ret + 1) * (t >> 7); return ret; -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/ulaw_decode.h b/ulaw_decode.h index 99d86ac..351874a 100644 --- a/ulaw_decode.h +++ b/ulaw_decode.h @@ -1,9 +1,9 @@ - signed short decode(unsigned char t) + int16_t decode(uint8_t t) { - int exp = 0x8 - (0x7 & (t >> 4)); - int base = (0x1 << (exp+ 5)) - 34; - int step = 0x1 << exp; - signed short ret = base - step * (0xf & t); + int16_t exp = 0x8 - (0x7 & (t >> 4)); + uint16_t base = (0x1 << (exp+ 5)) - 34; + int16_t step = 0x1 << exp; + int16_t ret = base - step * (0xf & t); ret = -ret - 1 + (2 * ret + 1) * (t >> 7); return ret; } \ No newline at end of file