From 22e767792b7fdb2411c7e11ddbc9a2f3ffcc1170 Mon Sep 17 00:00:00 2001 From: "K.Ohta" Date: Sun, 14 Oct 2018 16:32:40 +0900 Subject: [PATCH] [COMMON][FILEIO] common.h : Fix pair16_t and pair64_t to fileio.cpp . --- source/src/common.cpp | 54 +++++++++++++++++++++++++-------------------------- source/src/common.h | 27 +++++++++++++------------- source/src/fileio.cpp | 4 ++++ 3 files changed, 45 insertions(+), 40 deletions(-) diff --git a/source/src/common.cpp b/source/src/common.cpp index 148885a21..6eeaa8b3d 100644 --- a/source/src/common.cpp +++ b/source/src/common.cpp @@ -1574,12 +1574,12 @@ bool DLL_PREFIX set_wav_header(wav_header_t *header, wav_chunk_t *first_chunk, u __riff_chunk_size.d = length - 8; __fmt_chunk_size.d = 16; - __fmt_id.w = 1; - __channels.w = channels; + __fmt_id.u16 = 1; + __channels.u16 = channels; __sample_rate.d = rate; - __block_size.w = (uint16_t)((channels * bits) / 8); - __sample_bits.w = bits; - __data_speed.d = rate * (uint32_t)(__block_size.w); + __block_size.u16 = (uint16_t)((channels * bits) / 8); + __sample_bits.u16 = bits; + __data_speed.d = rate * (uint32_t)(__block_size.u16); memcpy(&(header->riff_chunk.id), "RIFF", 4); header->riff_chunk.size = __riff_chunk_size.get_4bytes_le_to(); @@ -1636,7 +1636,7 @@ bool DLL_PREFIX load_wav_to_stereo(void *__fio, int16_t **left_buf, int16_t **ri __channels.set_2bytes_le_from(header.channels); __sample_rate.set_4bytes_le_from(header.sample_rate); - if((__fmt_id.w == 1) && ((__sample_bits.w == 8) || (__sample_bits.w == 16) || (__sample_bits.w == 32))) { + if((__fmt_id.u16 == 1) && ((__sample_bits.u16 == 8) || (__sample_bits.u16 == 16) || (__sample_bits.u16 == 32))) { fio->Fseek(__chunk_size.d - 16, FILEIO_SEEK_CUR); bool is_eof = false; while(1) { @@ -1657,7 +1657,7 @@ bool DLL_PREFIX load_wav_to_stereo(void *__fio, int16_t **left_buf, int16_t **ri return false; } - samples = (size_t)(__chunk_size.d / __channels.w); + samples = (size_t)(__chunk_size.d / __channels.u16); int16_t data_l, data_r; union { int16_t s16; @@ -1673,9 +1673,9 @@ bool DLL_PREFIX load_wav_to_stereo(void *__fio, int16_t **left_buf, int16_t **ri } pair32; if(samples > 0) { - if(__sample_bits.w == 16) { + if(__sample_bits.u16 == 16) { samples /= 2; - } else if(__sample_bits.w == 32) { + } else if(__sample_bits.u16 == 32) { samples /= 4; } if(samples == 0) return false; @@ -1691,16 +1691,16 @@ bool DLL_PREFIX load_wav_to_stereo(void *__fio, int16_t **left_buf, int16_t **ri if(left_buffer != NULL) free(left_buffer); return false; } - switch(__sample_bits.w) { + switch(__sample_bits.u16) { case 8: - if(__channels.sw == 1) { + if(__channels.s16 == 1) { for(int i = 0; i < samples; i++) { data_l = (int16_t)(fio->FgetUint8()); data_l = (data_l - 128) * 256; left_buffer[i] = data_l; right_buffer[i] = data_l; } - } else if(__channels.sw == 2) { + } else if(__channels.s16 == 2) { for(int i = 0; i < samples; i++) { data_l = (int16_t)(fio->FgetUint8()); data_l = (data_l - 128) * 256; @@ -1712,7 +1712,7 @@ bool DLL_PREFIX load_wav_to_stereo(void *__fio, int16_t **left_buf, int16_t **ri } break; case 16: - if(__channels.sw == 1) { + if(__channels.s16 == 1) { for(int i = 0; i < samples; i++) { pair16.b.l = fio->FgetUint8(); pair16.b.h = fio->FgetUint8(); @@ -1721,7 +1721,7 @@ bool DLL_PREFIX load_wav_to_stereo(void *__fio, int16_t **left_buf, int16_t **ri left_buffer[i] = data_l; right_buffer[i] = data_l; } - } else if(__channels.sw == 2) { + } else if(__channels.s16 == 2) { for(int i = 0; i < samples; i++) { pair16.b.l = fio->FgetUint8(); pair16.b.h = fio->FgetUint8(); @@ -1736,7 +1736,7 @@ bool DLL_PREFIX load_wav_to_stereo(void *__fio, int16_t **left_buf, int16_t **ri } break; case 32: - if(__channels.sw == 1) { + if(__channels.s16 == 1) { for(int i = 0; i < samples; i++) { pair32.b.l = fio->FgetUint8(); pair32.b.h = fio->FgetUint8(); @@ -1747,7 +1747,7 @@ bool DLL_PREFIX load_wav_to_stereo(void *__fio, int16_t **left_buf, int16_t **ri left_buffer[i] = data_l; right_buffer[i] = data_l; } - } else if(__channels.sw == 2) { + } else if(__channels.s16 == 2) { for(int i = 0; i < samples; i++) { pair32.b.l = fio->FgetUint8(); pair32.b.h = fio->FgetUint8(); @@ -1813,7 +1813,7 @@ bool DLL_PREFIX load_wav_to_monoral(void *__fio, int16_t **buffer, uint32_t *rat __channels.set_2bytes_le_from(header.channels); __sample_rate.set_4bytes_le_from(header.sample_rate); - if((__fmt_id.w == 1) && ((__sample_bits.w == 8) || (__sample_bits.w == 16) || (__sample_bits.w == 32))) { + if((__fmt_id.u16 == 1) && ((__sample_bits.u16 == 8) || (__sample_bits.u16 == 16) || (__sample_bits.u16 == 32))) { fio->Fseek(__chunk_size.d - 16, FILEIO_SEEK_CUR); bool is_eof = false; while(1) { @@ -1834,7 +1834,7 @@ bool DLL_PREFIX load_wav_to_monoral(void *__fio, int16_t **buffer, uint32_t *rat return false; } - samples = (size_t)(__chunk_size.d / __channels.w); + samples = (size_t)(__chunk_size.d / __channels.u16); int16_t data_l, data_r; int32_t data32_l, data32_r; union { @@ -1851,9 +1851,9 @@ bool DLL_PREFIX load_wav_to_monoral(void *__fio, int16_t **buffer, uint32_t *rat } pair32; if(samples > 0) { - if(__sample_bits.w == 16) { + if(__sample_bits.u16 == 16) { samples /= 2; - } else if(__sample_bits.w == 32) { + } else if(__sample_bits.u16 == 32) { samples /= 4; } if(samples == 0) return false; @@ -1863,15 +1863,15 @@ bool DLL_PREFIX load_wav_to_monoral(void *__fio, int16_t **buffer, uint32_t *rat if(left_buffer == NULL) { return false; } - switch(__sample_bits.w) { + switch(__sample_bits.u16) { case 8: - if(__channels.sw == 1) { + if(__channels.s16 == 1) { for(int i = 0; i < samples; i++) { data_l = (int16_t)(fio->FgetUint8()); data_l = (data_l - 128) * 256; left_buffer[i] = data_l; } - } else if(__channels.sw == 2) { + } else if(__channels.s16 == 2) { for(int i = 0; i < samples; i++) { data_l = (int16_t)(fio->FgetUint8()); data_l = (data_l - 128) * 256; @@ -1882,7 +1882,7 @@ bool DLL_PREFIX load_wav_to_monoral(void *__fio, int16_t **buffer, uint32_t *rat } break; case 16: - if(__channels.sw == 1) { + if(__channels.s16 == 1) { for(int i = 0; i < samples; i++) { pair16.b.l = fio->FgetUint8(); pair16.b.h = fio->FgetUint8(); @@ -1890,7 +1890,7 @@ bool DLL_PREFIX load_wav_to_monoral(void *__fio, int16_t **buffer, uint32_t *rat left_buffer[i] = data_l; } - } else if(__channels.sw == 2) { + } else if(__channels.s16 == 2) { for(int i = 0; i < samples; i++) { pair16.b.l = fio->FgetUint8(); pair16.b.h = fio->FgetUint8(); @@ -1904,7 +1904,7 @@ bool DLL_PREFIX load_wav_to_monoral(void *__fio, int16_t **buffer, uint32_t *rat } break; case 32: - if(__channels.sw == 1) { + if(__channels.s16 == 1) { for(int i = 0; i < samples; i++) { pair32.b.l = fio->FgetUint8(); pair32.b.h = fio->FgetUint8(); @@ -1914,7 +1914,7 @@ bool DLL_PREFIX load_wav_to_monoral(void *__fio, int16_t **buffer, uint32_t *rat left_buffer[i] = data_l; } - } else if(__channels.sw == 2) { + } else if(__channels.s16 == 2) { for(int i = 0; i < samples; i++) { pair32.b.l = fio->FgetUint8(); pair32.b.h = fio->FgetUint8(); diff --git a/source/src/common.h b/source/src/common.h index 5b1122ed5..46f441f65 100644 --- a/source/src/common.h +++ b/source/src/common.h @@ -279,8 +279,8 @@ typedef union { int8_t l, h; #endif } sb; - uint16_t w; - int16_t sw; + uint16_t u16; + int16_t s16; inline void read_2bytes_le_from(uint8_t *t) { @@ -384,6 +384,7 @@ typedef union { } p16; uint32_t d; int32_t sd; + float f; inline void read_2bytes_le_from(uint8_t *t) { b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0; @@ -568,9 +569,9 @@ typedef union { pair_t l, h; #endif } p32; - uint64_t q; - int64_t sq; - + uint64_t u64; + int64_t s64; + double d64; inline void read_2bytes_le_from(uint8_t *t) { b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0; @@ -992,7 +993,7 @@ uint16_t DLL_PREFIX EndianFromBig_WORD(uint16_t x); inline uint64_t ExchangeEndianU64(uint64_t __in) { pair64_t __i, __o; - __i.q = __in; + __i.u64 = __in; __o.b.h7 = __i.b.l; __o.b.h6 = __i.b.h; __o.b.h5 = __i.b.h2; @@ -1001,13 +1002,13 @@ inline uint64_t ExchangeEndianU64(uint64_t __in) __o.b.h2 = __i.b.h5; __o.b.h = __i.b.h6; __o.b.l = __i.b.h7; - return __o.q; + return __o.u64; } inline int64_t ExchangeEndianS64(uint64_t __in) { pair64_t __i, __o; - __i.q = __in; + __i.u64 = __in; __o.b.h7 = __i.b.l; __o.b.h6 = __i.b.h; __o.b.h5 = __i.b.h2; @@ -1016,7 +1017,7 @@ inline int64_t ExchangeEndianS64(uint64_t __in) __o.b.h2 = __i.b.h5; __o.b.h = __i.b.h6; __o.b.l = __i.b.h7; - return __o.sq; + return __o.s64; } inline uint32_t ExchangeEndianU32(uint32_t __in) { @@ -1043,19 +1044,19 @@ inline int32_t ExchangeEndianS32(uint32_t __in) inline uint16_t ExchangeEndianU16(uint16_t __in) { pair16_t __i, __o; - __i.w = __in; + __i.u16 = __in; __o.b.h = __i.b.l; __o.b.l = __i.b.h; - return __o.w; + return __o.u16; } inline int16_t ExchangeEndianS16(uint16_t __in) { pair16_t __i, __o; - __i.w = __in; + __i.u16 = __in; __o.b.h = __i.b.l; __o.b.l = __i.b.h; - return __o.sw; + return __o.s16; } // wav file header diff --git a/source/src/fileio.cpp b/source/src/fileio.cpp index 58d3dae90..d84025c06 100644 --- a/source/src/fileio.cpp +++ b/source/src/fileio.cpp @@ -397,6 +397,7 @@ void FILEIO::FputDouble(double val) PUT_VALUE(double, val); } +#if 0 typedef union { struct { #ifdef __BIG_ENDIAN__ @@ -408,6 +409,7 @@ typedef union { uint16_t u16; int16_t s16; } pair16_t; +#endif typedef union { struct { @@ -422,6 +424,7 @@ typedef union { float f32; } pair32_t; +#if 0 typedef union { struct { #ifdef __BIG_ENDIAN__ @@ -434,6 +437,7 @@ typedef union { int64_t s64; double d64; } pair64_t; +#endif uint16_t FILEIO::FgetUint16_LE() { -- 2.11.0