### First post, by clearcase

Hello,

New around here. I'd like to decode some Roland PCM ROMs in a perfect, bit accurate way.

I'm currently using this code which is a combination of code posted on this forum modified a little:

`for (int i = 0; i < file_size / 2; i++) {`

`int16_t raw_sample;`

`*(((int8_t *) &raw_sample) + 1) = fgetc(fp);`

`*(((int8_t *) &raw_sample) + 0) = fgetc(fp);`

`int16_t ordered_sample;`

`// the bits have to be moved to these positions`

`// 15, 06, 14, 13, 12, 11, 10, 09, 08, 05, 04, 03, 02, 01, 00, 07`

`// EG: bit 15 stays, bit 6 moves to 14, bit 14 moves to bit 13...`

`ordered_sample = raw_sample & 0x8000;`

`ordered_sample |= raw_sample << 8 & 0x4000;`

`ordered_sample |= raw_sample >> 1 & 0x3F80;`

`ordered_sample |= raw_sample << 1 & 0x007E;`

`// decode the data`

`double float_sample = pow(2.0f, (((ordered_sample & 0x7FFF) - 32767.0f) / 2048.0f));`

`sample_data[i] = (int16_t)(float_sample * 32768.0f * ((ordered_sample & 0x8000) ? -1.0f : 1.0f));`

`}`

This code produces almost perfect results but not bit accurate.

*sergm* said in another thread that I'd need to loose the float calculations and use a LUT and pointed me to the Tables.cpp file in mt32emu. Not sure how to procede from there. Any help or hints would be welcome.