88use Exception ;
99use FFI ;
1010use FFI \CData ;
11+ use FFI \CType ;
1112
1213class FastTransformersUtils
1314{
@@ -36,18 +37,32 @@ protected static function ffi(): FFI
3637 /**
3738 * Creates a new instance of the specified type.
3839 *
39- * @param string $type The type of the instance to create.
40+ * @param CType| string $type The type of the instance to create.
4041 * @param bool $owned Whether the instance should be owned. Default is true.
4142 * @param bool $persistent Whether the instance should be persistent. Default is false.
4243 *
4344 * @return CData|null The created instance, or null if the creation failed.
4445 * @throws Exception
4546 */
46- public static function new (string $ type , bool $ owned = true , bool $ persistent = false ): ?CData
47+ public static function new (CType | string $ type , bool $ owned = true , bool $ persistent = false ): ?CData
4748 {
4849 return self ::ffi ()->new ($ type , $ owned , $ persistent );
4950 }
5051
52+ /**
53+ * Casts a pointer to a different type.
54+ *
55+ * @param CType|string $type The type to cast to.
56+ * @param CData|int|float|bool|null $ptr The pointer to cast.
57+ *
58+ * @return ?CData The cast pointer, or null if the cast failed.
59+ * @throws Exception
60+ */
61+ public static function cast (CType |string $ type , CData |int |float |bool |null $ ptr ): ?CData
62+ {
63+ return self ::ffi ()->cast ($ type , $ ptr );
64+ }
65+
5166 /**
5267 * Retrieves the value of the enum constant with the given name.
5368 *
@@ -74,7 +89,7 @@ public static function version(): string
7489
7590 public static function padReflect ($ input , int $ length , int $ paddedLength ): CData
7691 {
77- $ padded = FFI ::new ("float[ $ paddedLength] " );
92+ $ padded = self ::new ("float[ $ paddedLength] " );
7893 self ::ffi ()->pad_reflect ($ input , $ length , $ padded , $ paddedLength );
7994
8095 return $ padded ;
@@ -87,7 +102,7 @@ public static function spectrogram(
87102 bool $ doPad , bool $ transpose
88103 ): CData
89104 {
90- $ spectrogram = FFI ::new ("float[ $ spectrogramLength] " );
105+ $ spectrogram = self ::new ("float[ $ spectrogramLength] " );
91106
92107 self ::ffi ()->spectrogram (
93108 $ waveform , $ waveformLength , $ spectrogram , $ spectrogramLength , $ hopLength , $ fftLength , $ window ,
0 commit comments