|
1 | 1 | /* |
2 | | - * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> |
3 | | - * (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com> |
| 2 | + * Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 | + * (C) 2025 Vladimir Sadovnikov <sadko4u@gmail.com> |
4 | 4 | * |
5 | 5 | * This file is part of lsp-common-lib |
6 | 6 | * Created on: 1 апр. 2020 г. |
|
24 | 24 |
|
25 | 25 | #include <lsp-plug.in/common/version.h> |
26 | 26 | #include <lsp-plug.in/common/types.h> |
| 27 | +#include <lsp-plug.in/stdlib/string.h> |
27 | 28 |
|
28 | 29 | #define LSP_PLUG_IN_COMMON_ENDIAN_IMPL |
29 | 30 | // Include unsigned functions definition |
|
42 | 43 |
|
43 | 44 | // Define macros |
44 | 45 | #ifdef ARCH_LE |
45 | | - #define LE_TO_CPU(x) (x) |
46 | | - #define CPU_TO_LE(x) (x) |
| 46 | + #define LE_TO_CPU(x) (x) |
| 47 | + #define CPU_TO_LE(x) (x) |
47 | 48 |
|
48 | | - #define BE_TO_CPU(x) ::lsp::byte_swap(x) |
49 | | - #define CPU_TO_BE(x) ::lsp::byte_swap(x) |
| 49 | + #define BE_TO_CPU(x) ::lsp::byte_swap(x) |
| 50 | + #define CPU_TO_BE(x) ::lsp::byte_swap(x) |
50 | 51 |
|
51 | | - #define VLE_TO_CPU(v, n) do {} while(false) |
52 | | - #define CPU_TO_VLE(v, n) do {} while(false) |
| 52 | + #define VLE_TO_CPU(v, n) do {} while(false) |
| 53 | + #define CPU_TO_VLE(v, n) do {} while(false) |
53 | 54 |
|
54 | | - #define VBE_TO_CPU(v, n) ::lsp::byte_swap(v, n) |
55 | | - #define CPU_TO_VBE(v, n) ::lsp::byte_swap(v, n) |
| 55 | + #define VBE_TO_CPU(v, n) ::lsp::byte_swap(v, n) |
| 56 | + #define CPU_TO_VBE(v, n) ::lsp::byte_swap(v, n) |
| 57 | + |
| 58 | + #define VLE_TO_CPU_COPY(d, v, n) ::lsp::no_byte_swap_copy(d, v, n) |
| 59 | + #define CPU_TO_VLE_COPY(d, v, n) ::lsp::no_byte_swap_copy(d, v, n) |
| 60 | + |
| 61 | + #define VBE_TO_CPU_COPY(d, v, n) ::lsp::byte_swap_copy(d, v, n) |
| 62 | + #define CPU_TO_VBE_COPY(d, v, n) ::lsp::byte_swap_copy(d, v, n) |
56 | 63 |
|
57 | 64 | #else |
58 | | - #define LE_TO_CPU(x) ::lsp::byte_swap(x) |
59 | | - #define CPU_TO_LE(x) ::lsp::byte_swap(x) |
| 65 | + #define LE_TO_CPU(x) ::lsp::byte_swap(x) |
| 66 | + #define CPU_TO_LE(x) ::lsp::byte_swap(x) |
| 67 | + |
| 68 | + #define BE_TO_CPU(x) (x) |
| 69 | + #define CPU_TO_BE(x) (x) |
| 70 | + |
| 71 | + #define VLE_TO_CPU(v, n) ::lsp::byte_swap(v, n) |
| 72 | + #define CPU_TO_VLE(v, n) ::lsp::byte_swap(v, n) |
60 | 73 |
|
61 | | - #define BE_TO_CPU(x) (x) |
62 | | - #define CPU_TO_BE(x) (x) |
| 74 | + #define VBE_TO_CPU(v, n) do {} while(false) |
| 75 | + #define CPU_TO_VBE(v, n) do {} while(false) |
63 | 76 |
|
64 | | - #define VLE_TO_CPU(v, n) ::lsp::byte_swap(v, n) |
65 | | - #define CPU_TO_VLE(v, n) ::lsp::byte_swap(v, n) |
| 77 | + #define VLE_TO_CPU_COPY(d, v, n) ::lsp::byte_swap_copy(d, v, n) |
| 78 | + #define CPU_TO_VLE_COPY(d, v, n) ::lsp::byte_swap_copy(d, v, n) |
66 | 79 |
|
67 | | - #define VBE_TO_CPU(v, n) do {} while(false) |
68 | | - #define CPU_TO_VBE(v, n) do {} while(false) |
| 80 | + #define VBE_TO_CPU_COPY(d, v, n) ::lsp::no_byte_swap_copy(d, v, n) |
| 81 | + #define CPU_TO_VBE_COPY(d, v, n) ::lsp::no_byte_swap_copy(d, v, n) |
69 | 82 |
|
70 | 83 | #endif /* */ |
71 | 84 |
|
@@ -121,6 +134,12 @@ namespace lsp |
121 | 134 | for (size_t i=0; i<n; ++i) |
122 | 135 | dst[i] = byte_swap(src[i]); |
123 | 136 | } |
| 137 | + |
| 138 | + template <class T> |
| 139 | + inline void no_byte_swap_copy(T *dst, const T *src, size_t n) |
| 140 | + { |
| 141 | + memcpy(dst, src, n * sizeof(T)); |
| 142 | + } |
124 | 143 | } /* namespace lsp */ |
125 | 144 |
|
126 | 145 | #endif /* LSP_PLUG_IN_COMMON_ENDIAN_H_ */ |
0 commit comments