UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
crsfade.inl
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#ifdef DO_SCALAR
4#undef DO_SCALAR
5#endif
6
7#if defined(__RADX86__)
8
9// for sse intrinsics.
10#include <emmintrin.h>
11#include <mmintrin.h>
12
13#if defined (__RAD64__) || (_M_IX86_FP>=2) //win64 or arch:SSE2 specified
14 #define CallCrossFade CrossFadeSSE2
15#else
16 // x86 32-bit try sse or fallback to mmx
17 #define CallCrossFade CrossFadeDispatch
18
19 static void CrossFadeMMX(S16* outp,S16* overlap, U32 windowsize, S32 windowshift)
20 {
21 U32 i;
22 {
23 __m64 IVec = _mm_setr_pi16(0, 1, 2, 3);
26 __m64 ZeroVec = _mm_setzero_si64();
28
29 // linearly blend the sample over the window size
30 for ( i = 0; i < windowsize ; i+=8 )
31 {
32 __m64 OutpVec = *(__m64*)((char*)outp + i);
33 __m64 OverlapVec = *(__m64*)((char*)overlap + i);
35 __m64 Temp;
37
38 // outp - overlap
40
41 // *i
44
45 // move to something useful.
48
49 // /ws
52
53 // overlap -> 32 bit
56
59
60 // Add overlap
63
64 // back to 16 bit
66
67 // inc i.
69
70
71 *(__m64*)((char*)outp + i) = OutpVec;
72 }
73 _mm_empty();
74 }
75 }
76
77 static void CrossFadeSSE2(S16* outp,S16* overlap, U32 windowsize, S32 windowshift);
78 static void CrossFadeDispatch(S16* outp,S16* overlap, U32 windowsize, S32 windowshift)
79 {
81 {
83 return;
84 }
85
87 return;
88 }
89
90#endif
91
92static void CrossFadeSSE2(S16* outp,S16* overlap, U32 windowsize, S32 windowshift)
93{
94 U32 i;
95 {
96 __m128i IVec = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
100
101 // linearly blend the sample over the window size
102 for ( i = 0; i < windowsize ; i+=16 )
103 {
104 __m128i OutpVec = _mm_load_si128((__m128i*)((char*)outp + i));
105 __m128i OverlapVec = _mm_load_si128((__m128i*)((char*)overlap + i));
106
108
109 // Outp * i
112
113 // Overlap * (ws - i)
116
117 // Interleave in to 32 bit values.
120 OutpHigh = Temp;
121
124 OverlapHigh = Temp;
125
126 // (outp[i] * i + overlap[i] * (ws - i))
129
130 // / ws
133
134 // -> 16 bit
136
138
139 _mm_store_si128((__m128i*)((char*)outp + i), OutpVec);
140 }
141 }
142}
143
144#elif defined(__RADNEON__)
145
146#include <arm_neon.h>
147
148#define CallCrossFade CrossFadeNeon
149
150static RAD_ALIGN( S16, starting_blend[ 8 ], 16 ) = { 0, 1, 2, 3, 4, 5, 6, 7 };
151
152static void CrossFadeNeon(S16* outp,S16* overlap, U32 windowsize, S32 windowshift)
153{
158
159 // linearly blend the sample over the window size
160 for ( U32 i = 0; i < windowsize ; i += 16 )
161 {
162 int16x8_t OutpVec = vld1q_s16((S16*)((char*)outp + i));
163 int16x8_t OverlapVec = vld1q_s16((S16*)((char*)overlap + i));
164
166
167 // Outp * i
170
171 // Overlap * (ws - i)
174
175 // (outp[i] * i + overlap[i] * (ws - i))
178
179 // / ws
182
183 // -> 16 bit
185
187
188 vst1q_s16((S16*)((char*)outp + i), OutpVec);
189 }
190}
191
192#elif defined(__RADBIGENDIAN__)
193
194#include RR_PLATFORM_PATH_STR( __RAD_NDA_PLATFORM__, _crsfade.inl )
195
196#elif defined( __RADEMSCRIPTEN__ )
197
198// this is just emscripten currently
199#define CallCrossFade CrossFade
200static void CrossFade(S16* outp,S16* overlap, U32 windowsize, S32 windowshift)
201{
202 U32 i;
203 U32 ws = windowsize / 2; // convert from bytes to samples
204 // bi-linearly blend the sample over the window size
205 for ( i = 0; i < ws ; i++ )
206 {
207 outp[i] = (S16) (((((S32)outp[i] - (S32)overlap[i]) * i) >> windowshift ) + (S32) overlap[i] );
208 }
209}
210
211#else
212
213#error crsfade.inl platform
214
215#endif
RAD_S16 S16
Definition egttypes.h:486
RAD_U32 U32
Definition egttypes.h:501
RAD_S32 S32
Definition egttypes.h:496
RAD_U16 U16
Definition egttypes.h:491
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
RRSTRIPPABLEPUB RADDEFINEDATA const RAD_ALIGN(U32, VarBitsLens[33], 32)