bool is_big_endian = (stream_info->is_wave_out? false : stream_info->is_big_endian);
bool is_unsigned_samples = (stream_info->is_wave_out? bps<=8 : stream_info->is_unsigned_samples);
unsigned wide_samples = frame->header.blocksize, wide_sample, sample, channel, byte;
- static signed char scbuffer[FLAC__MAX_BLOCK_SIZE * FLAC__MAX_CHANNELS * ((FLAC__MAX_BITS_PER_SAMPLE+7)>>3)]; /* WATCHOUT: can be up to 2 megs */
- unsigned char *ucbuffer = (unsigned char *)scbuffer;
- signed short *ssbuffer = (signed short *)scbuffer;
- unsigned short *usbuffer = (unsigned short *)scbuffer;
- signed *slbuffer = (signed *)scbuffer;
- unsigned *ulbuffer = (unsigned *)scbuffer;
+ static int8 s8buffer[FLAC__MAX_BLOCK_SIZE * FLAC__MAX_CHANNELS * ((FLAC__MAX_BITS_PER_SAMPLE+7)>>3)]; /* WATCHOUT: can be up to 2 megs */
+ uint8 *u8buffer = (uint8 *)s8buffer;
+ int16 *s16buffer = (int16 *)s8buffer;
+ uint16 *u16buffer = (uint16 *)s8buffer;
+ int32 *s32buffer = (int32 *)s8buffer;
+ uint32 *u32buffer = (uint32 *)s8buffer;
(void)decoder;
if(is_unsigned_samples) {
for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++)
for(channel = 0; channel < channels; channel++, sample++)
- ucbuffer[sample] = buffer[channel][wide_sample] + 0x80;
+ u8buffer[sample] = buffer[channel][wide_sample] + 0x80;
}
else {
for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++)
for(channel = 0; channel < channels; channel++, sample++)
- scbuffer[sample] = buffer[channel][wide_sample];
+ s8buffer[sample] = buffer[channel][wide_sample];
}
- if(fwrite(ucbuffer, 1, sample, fout) != sample)
+ if(fwrite(u8buffer, 1, sample, fout) != sample)
return FLAC__STREAM_DECODER_WRITE_ABORT;
}
else if(bps == 16) {
if(is_unsigned_samples) {
for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++)
for(channel = 0; channel < channels; channel++, sample++)
- usbuffer[sample] = buffer[channel][wide_sample] + 0x8000;
+ u16buffer[sample] = buffer[channel][wide_sample] + 0x8000;
}
else {
for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++)
for(channel = 0; channel < channels; channel++, sample++)
- ssbuffer[sample] = buffer[channel][wide_sample];
+ s16buffer[sample] = buffer[channel][wide_sample];
}
if(is_big_endian != is_big_endian_host) {
unsigned char tmp;
const unsigned bytes = sample * 2;
for(byte = 0; byte < bytes; byte += 2) {
- tmp = ucbuffer[byte];
- ucbuffer[byte] = ucbuffer[byte+1];
- ucbuffer[byte+1] = tmp;
+ tmp = u8buffer[byte];
+ u8buffer[byte] = u8buffer[byte+1];
+ u8buffer[byte+1] = tmp;
}
}
- if(fwrite(usbuffer, 2, sample, fout) != sample)
+ if(fwrite(u16buffer, 2, sample, fout) != sample)
return FLAC__STREAM_DECODER_WRITE_ABORT;
}
else if(bps == 24) {
if(is_unsigned_samples) {
for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++)
for(channel = 0; channel < channels; channel++, sample++)
- ulbuffer[sample] = buffer[channel][wide_sample] + 0x800000;
+ u32buffer[sample] = buffer[channel][wide_sample] + 0x800000;
}
else {
for(sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++)
for(channel = 0; channel < channels; channel++, sample++)
- slbuffer[sample] = buffer[channel][wide_sample];
+ s32buffer[sample] = buffer[channel][wide_sample];
}
-/*@@@
- if(is_big_endian != is_big_endian_host) {
- unsigned char tmp;
- unsigned lbyte;
- const unsigned bytes = sample * 4;
- for(lbyte = byte = 0; byte < bytes; byte += 4, lbyte += 3) {
- tmp = ucbuffer[byte];
- ucbuffer[lbyte] = ucbuffer[byte+2];
- ucbuffer[lbyte+2] = tmp;
- ucbuffer[lbyte+1] = ucbuffer[byte+1];
- }
- }
- else {
- unsigned lbyte;
- const unsigned bytes = sample * 4;
- for(lbyte = byte = 0; byte < bytes; ) {
- ucbuffer[lbyte++] = ucbuffer[byte++];
- ucbuffer[lbyte++] = ucbuffer[byte++];
- ucbuffer[lbyte++] = ucbuffer[byte++];
- byte++;
- }
- }
-*/
if(is_big_endian != is_big_endian_host) {
unsigned char tmp;
const unsigned bytes = sample * 4;
for(byte = 0; byte < bytes; byte += 4) {
- tmp = ucbuffer[byte];
- ucbuffer[byte] = ucbuffer[byte+3];
- ucbuffer[byte+3] = tmp;
- tmp = ucbuffer[byte+1];
- ucbuffer[byte+1] = ucbuffer[byte+2];
- ucbuffer[byte+2] = tmp;
+ tmp = u8buffer[byte];
+ u8buffer[byte] = u8buffer[byte+3];
+ u8buffer[byte+3] = tmp;
+ tmp = u8buffer[byte+1];
+ u8buffer[byte+1] = u8buffer[byte+2];
+ u8buffer[byte+2] = tmp;
}
}
if(is_big_endian) {
const unsigned bytes = sample * 4;
for(lbyte = byte = 0; byte < bytes; ) {
byte++;
- ucbuffer[lbyte++] = ucbuffer[byte++];
- ucbuffer[lbyte++] = ucbuffer[byte++];
- ucbuffer[lbyte++] = ucbuffer[byte++];
+ u8buffer[lbyte++] = u8buffer[byte++];
+ u8buffer[lbyte++] = u8buffer[byte++];
+ u8buffer[lbyte++] = u8buffer[byte++];
}
}
else {
unsigned lbyte;
const unsigned bytes = sample * 4;
for(lbyte = byte = 0; byte < bytes; ) {
- ucbuffer[lbyte++] = ucbuffer[byte++];
- ucbuffer[lbyte++] = ucbuffer[byte++];
- ucbuffer[lbyte++] = ucbuffer[byte++];
+ u8buffer[lbyte++] = u8buffer[byte++];
+ u8buffer[lbyte++] = u8buffer[byte++];
+ u8buffer[lbyte++] = u8buffer[byte++];
byte++;
}
}
- if(fwrite(ucbuffer, 3, sample, fout) != sample)
+ if(fwrite(u8buffer, 3, sample, fout) != sample)
return FLAC__STREAM_DECODER_WRITE_ABORT;
}
else {