changed type to typedefs

master
Hannes 14 years ago
parent 61ae8456ae
commit d992034049

@ -3,12 +3,14 @@
#include <complex> #include <complex>
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
#include <stdint.h>
//signed short decode(unsigned char t);
int16_t decode(uint8_t t);
signed short decode(unsigned char t);
main() main()
{ {
std::vector<unsigned char> data; std::vector<unsigned char> data;
FILE* f = fopen("outputfileulaw.raw", "rb"); FILE* f = fopen("outputfileulaw.wav", "rb");
rewind(f); rewind(f);
while(!feof(f)) while(!feof(f))
{ {
@ -16,7 +18,7 @@ main()
fread(&s, sizeof s, 1, f); fread(&s, sizeof s, 1, f);
data.push_back(s); data.push_back(s);
} }
FILE* o = fopen("outputfileulaw.dec", "wb"); FILE* o = fopen("outputfileulaw.raw", "wb");
int headersize = 4; int headersize = 4;
int old_header_size = 58; int old_header_size = 58;
unsigned int samples = data.size() - old_header_size; unsigned int samples = data.size() - old_header_size;
@ -39,8 +41,16 @@ main()
fwrite(&new_data[0], sizeof(unsigned char), samples_old+headersize, o); fwrite(&new_data[0], sizeof(unsigned char), samples_old+headersize, o);
} }
int16_t decode(uint8_t t)
signed short decode(unsigned char 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 exp = 0x8 - (0x7 & (t >> 4));
int base = (0x1 << (exp+ 5)) - 34; int base = (0x1 << (exp+ 5)) - 34;
@ -48,4 +58,4 @@ signed short decode(unsigned char t)
signed short ret = base - step * (0xf & t); signed short ret = base - step * (0xf & t);
ret = -ret - 1 + (2 * ret + 1) * (t >> 7); ret = -ret - 1 + (2 * ret + 1) * (t >> 7);
return ret; return ret;
} }*/

@ -1,9 +1,9 @@
signed short decode(unsigned char t) int16_t decode(uint8_t t)
{ {
int exp = 0x8 - (0x7 & (t >> 4)); int16_t exp = 0x8 - (0x7 & (t >> 4));
int base = (0x1 << (exp+ 5)) - 34; uint16_t base = (0x1 << (exp+ 5)) - 34;
int step = 0x1 << exp; int16_t step = 0x1 << exp;
signed short ret = base - step * (0xf & t); int16_t ret = base - step * (0xf & t);
ret = -ret - 1 + (2 * ret + 1) * (t >> 7); ret = -ret - 1 + (2 * ret + 1) * (t >> 7);
return ret; return ret;
} }
Loading…
Cancel
Save