You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.0 KiB

#include <stdio.h>
#include <vector>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <stdint.h>
//signed short decode(unsigned char t);
int16_t decode(uint8_t t);
main()
{
/*
* old_headersize, f und o vorher setzen*/
std::vector<unsigned char> data;
FILE* f = fopen("GG_16bit_16khzmono.wav", "rb");
rewind(f);
//int old_header_size = 0;
while(!feof(f))
{
unsigned char s;
fread(&s, sizeof s, 1, f);
data.push_back(s);
int* last_word = (int*)&data[data.size()-4];
}
FILE* o = fopen("BIGENDIAN.raw", "wb");
int headersize = 4;
int old_header_size = 0;
unsigned int samples = data.size() - old_header_size;
unsigned char* new_data = (unsigned char*)malloc(sizeof(char) * (samples + headersize));
//little endian: alles umdrehen...
int samples_old = samples;
new_data[0] = (unsigned char) samples;
printf("value: %#x\n", (unsigned char)samples);
samples >>= 8;
new_data[1] = (unsigned char) samples;
printf("value: %#x\n", (unsigned char)samples);
samples >>= 8;
new_data[2] = (unsigned char) samples;
printf("value: %#x\n", (unsigned char)samples);
samples >>= 8;
new_data[3] = (unsigned char) samples;
printf("value: %#x\n", (unsigned char)samples);
//memcpy(&new_data[0], &samples, sizeof(int));
memcpy(&new_data[4], &data[old_header_size], samples_old);
/*for(int n = 0; n < samples_old-1; n+=2)
{
unsigned char tmp = new_data[3+n];
new_data[3+n] = new_data[4+n];
new_data[4+n] = tmp;
}*/
fwrite(&new_data[0], sizeof(unsigned char), samples_old+headersize, o);
}
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;
int step = 0x1 << exp;
signed short ret = base - step * (0xf & t);
ret = -ret - 1 + (2 * ret + 1) * (t >> 7);
return ret;
}*/