@@ -14,40 +14,50 @@ namespace osu.Android.Native
1414 /// </summary>
1515 public sealed class OboeAudioBridge : IDisposable
1616 {
17- private long nativePtr ;
17+ private const string lib_name = "osu_native" ;
18+
19+ private IntPtr nativePtr ;
1820 private volatile bool disposed ;
1921
22+ private static readonly bool native_loaded ;
23+
24+ static OboeAudioBridge ( )
25+ {
26+ native_loaded = NativeLibrary . TryLoad ( lib_name , typeof ( OboeAudioBridge ) . Assembly , null , out _ ) ;
27+
28+ if ( ! native_loaded )
29+ Debug . WriteLine ( "[osu!] Native library not found, Oboe unavailable" ) ;
30+ }
31+
2032 /// <summary>
2133 /// Creates and opens a new low-latency Oboe audio stream.
2234 /// Returns null if native library or stream creation fails.
2335 /// </summary>
2436 public static OboeAudioBridge ? Create ( )
2537 {
38+ if ( ! native_loaded )
39+ return null ;
40+
2641 try
2742 {
28- long ptr = nOboeCreate ( ) ;
43+ IntPtr ptr = nOboeCreate ( ) ;
2944
30- if ( ptr == 0 )
45+ if ( ptr == IntPtr . Zero )
3146 {
3247 Debug . WriteLine ( "[osu!] Oboe stream creation failed (native returned null)" ) ;
3348 return null ;
3449 }
3550
3651 return new OboeAudioBridge ( ptr ) ;
3752 }
38- catch ( DllNotFoundException )
39- {
40- Debug . WriteLine ( "[osu!] Native library not found, Oboe unavailable" ) ;
41- return null ;
42- }
4353 catch ( Exception e )
4454 {
4555 Debug . WriteLine ( $ "[osu!] Oboe creation failed: { e . Message } ") ;
4656 return null ;
4757 }
4858 }
4959
50- private OboeAudioBridge ( long ptr )
60+ private OboeAudioBridge ( IntPtr ptr )
5161 {
5262 nativePtr = ptr ;
5363 }
@@ -58,7 +68,7 @@ private OboeAudioBridge(long ptr)
5868 /// <returns>True if the stream started successfully.</returns>
5969 public bool Start ( )
6070 {
61- if ( disposed || nativePtr == 0 ) return false ;
71+ if ( disposed || nativePtr == IntPtr . Zero ) return false ;
6272
6373 try
6474 {
@@ -76,7 +86,7 @@ public bool Start()
7686 /// </summary>
7787 public void Stop ( )
7888 {
79- if ( disposed || nativePtr == 0 ) return ;
89+ if ( disposed || nativePtr == IntPtr . Zero ) return ;
8090
8191 try
8292 {
@@ -94,7 +104,7 @@ public void Stop()
94104 /// </summary>
95105 public double GetOutputLatencyMs ( )
96106 {
97- if ( disposed || nativePtr == 0 ) return - 1 ;
107+ if ( disposed || nativePtr == IntPtr . Zero ) return - 1 ;
98108
99109 try
100110 {
@@ -113,7 +123,7 @@ public bool IsActive
113123 {
114124 get
115125 {
116- if ( disposed || nativePtr == 0 ) return false ;
126+ if ( disposed || nativePtr == IntPtr . Zero ) return false ;
117127
118128 try
119129 {
@@ -133,7 +143,7 @@ public int SampleRate
133143 {
134144 get
135145 {
136- if ( disposed || nativePtr == 0 ) return 0 ;
146+ if ( disposed || nativePtr == IntPtr . Zero ) return 0 ;
137147
138148 try
139149 {
@@ -154,7 +164,7 @@ public int FramesPerBurst
154164 {
155165 get
156166 {
157- if ( disposed || nativePtr == 0 ) return 0 ;
167+ if ( disposed || nativePtr == IntPtr . Zero ) return 0 ;
158168
159169 try
160170 {
@@ -175,7 +185,7 @@ public int BufferSizeInFrames
175185 {
176186 get
177187 {
178- if ( disposed || nativePtr == 0 ) return 0 ;
188+ if ( disposed || nativePtr == IntPtr . Zero ) return 0 ;
179189
180190 try
181191 {
@@ -196,7 +206,7 @@ public bool IsAAudio
196206 {
197207 get
198208 {
199- if ( disposed || nativePtr == 0 ) return false ;
209+ if ( disposed || nativePtr == IntPtr . Zero ) return false ;
200210
201211 try
202212 {
@@ -215,7 +225,7 @@ public void Dispose()
215225
216226 disposed = true ;
217227
218- if ( nativePtr != 0 )
228+ if ( nativePtr != IntPtr . Zero )
219229 {
220230 try
221231 {
@@ -226,7 +236,7 @@ public void Dispose()
226236 Debug . WriteLine ( $ "[osu!] Oboe dispose failed: { e . Message } ") ;
227237 }
228238
229- nativePtr = 0 ;
239+ nativePtr = IntPtr . Zero ;
230240 }
231241
232242 GC . SuppressFinalize ( this ) ;
@@ -237,34 +247,34 @@ public void Dispose()
237247 Dispose ( ) ;
238248 }
239249
240- [ DllImport ( "osu_native" ) ]
241- private static extern long nOboeCreate ( ) ;
250+ [ DllImport ( lib_name ) ]
251+ private static extern IntPtr nOboeCreate ( ) ;
242252
243- [ DllImport ( "osu_native" ) ]
244- private static extern void nOboeDestroy ( long ptr ) ;
253+ [ DllImport ( lib_name ) ]
254+ private static extern void nOboeDestroy ( IntPtr ptr ) ;
245255
246- [ DllImport ( "osu_native" ) ]
247- private static extern byte nOboeStart ( long ptr ) ;
256+ [ DllImport ( lib_name ) ]
257+ private static extern byte nOboeStart ( IntPtr ptr ) ;
248258
249- [ DllImport ( "osu_native" ) ]
250- private static extern void nOboeStop ( long ptr ) ;
259+ [ DllImport ( lib_name ) ]
260+ private static extern void nOboeStop ( IntPtr ptr ) ;
251261
252- [ DllImport ( "osu_native" ) ]
253- private static extern double nOboeGetLatencyMs ( long ptr ) ;
262+ [ DllImport ( lib_name ) ]
263+ private static extern double nOboeGetLatencyMs ( IntPtr ptr ) ;
254264
255- [ DllImport ( "osu_native" ) ]
256- private static extern byte nOboeIsActive ( long ptr ) ;
265+ [ DllImport ( lib_name ) ]
266+ private static extern byte nOboeIsActive ( IntPtr ptr ) ;
257267
258- [ DllImport ( "osu_native" ) ]
259- private static extern int nOboeGetSampleRate ( long ptr ) ;
268+ [ DllImport ( lib_name ) ]
269+ private static extern int nOboeGetSampleRate ( IntPtr ptr ) ;
260270
261- [ DllImport ( "osu_native" ) ]
262- private static extern int nOboeGetFramesPerBurst ( long ptr ) ;
271+ [ DllImport ( lib_name ) ]
272+ private static extern int nOboeGetFramesPerBurst ( IntPtr ptr ) ;
263273
264- [ DllImport ( "osu_native" ) ]
265- private static extern int nOboeGetBufferSizeInFrames ( long ptr ) ;
274+ [ DllImport ( lib_name ) ]
275+ private static extern int nOboeGetBufferSizeInFrames ( IntPtr ptr ) ;
266276
267- [ DllImport ( "osu_native" ) ]
268- private static extern byte nOboeIsAAudio ( long ptr ) ;
277+ [ DllImport ( lib_name ) ]
278+ private static extern byte nOboeIsAAudio ( IntPtr ptr ) ;
269279 }
270280}
0 commit comments