aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/endian.h
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2019-12-30 00:13:23 +0300
committerDaniil Cherednik <dan.cherednik@gmail.com>2020-01-01 22:29:50 +0300
commit3d69df17657c40030fb486a86ef179a42b3873ca (patch)
tree56002a11e97322d6b6360b1479330ba83e87d731 /src/lib/endian.h
parentb58f4dd8353121094acdb41ad96fbdec4a580d79 (diff)
downloadatracdenc-3d69df17657c40030fb486a86ef179a42b3873ca.tar.gz
Initiall support of stdin reading for windows
Expected au(snd) format, 44100hz, 16bit, stereo or mono
Diffstat (limited to 'src/lib/endian.h')
-rw-r--r--src/lib/endian.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/lib/endian.h b/src/lib/endian.h
new file mode 100644
index 0000000..519cca1
--- /dev/null
+++ b/src/lib/endian.h
@@ -0,0 +1,60 @@
+/*
+ * This file is part of AtracDEnc.
+ *
+ * AtracDEnc is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * AtracDEnc is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with AtracDEnc; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef LIB_ENDIAN_H
+#define LIB_ENDIAN_H
+
+#include <stdint.h>
+
+static inline uint32_t swapbyte32_on_le(uint32_t in) {
+#ifdef BIGENDIAN_ORDER
+ return in;
+#else
+ return ((in & 0xff) << 24) | ((in & 0xff00) << 8) | ((in & 0xff0000) >> 8) | ((in & 0xff000000) >> 24);
+#endif
+}
+
+static inline uint16_t swapbyte16_on_le(uint16_t in) {
+#ifdef BIGENDIAN_ORDER
+ return in;
+#else
+ return ((in & 0xff) << 8) | ((in & 0xff00) >> 8);
+#endif
+}
+
+#ifdef __cplusplus
+
+static inline int16_t conv_ntoh(int16_t in) {
+ return (int16_t)swapbyte16_on_le((uint16_t)in);
+}
+
+static inline uint16_t conv_ntoh(uint16_t in) {
+ return swapbyte16_on_le(in);
+}
+
+static inline int32_t conv_ntoh(int32_t in) {
+ return (int32_t)swapbyte32_on_le((uint32_t)in);
+}
+
+static inline uint32_t conv_ntoh(uint32_t in) {
+ return swapbyte32_on_le(in);
+}
+
+#endif
+
+#endif \ No newline at end of file