@@ -6,11 +6,31 @@ use std::ffi::CString;
6
6
use std:: marker:: PhantomData ;
7
7
use std:: path:: Path ;
8
8
9
- make_thin_wrapper_lifetime ! ( Wave , ffi:: Wave , RaylibAudio , ffi:: UnloadWave ) ;
9
+ make_thin_wrapper_lifetime ! (
10
+ /// Wave, audio wave data
11
+ Wave ,
12
+ ffi:: Wave ,
13
+ RaylibAudio ,
14
+ ffi:: UnloadWave
15
+ ) ;
10
16
11
- make_thin_wrapper_lifetime ! ( Sound , ffi:: Sound , RaylibAudio , ( ffi:: UnloadSound ) , true ) ;
12
- make_thin_wrapper_lifetime ! ( Music , ffi:: Music , RaylibAudio , ffi:: UnloadMusicStream ) ;
13
17
make_thin_wrapper_lifetime ! (
18
+ /// Sound
19
+ Sound ,
20
+ ffi:: Sound ,
21
+ RaylibAudio ,
22
+ ( ffi:: UnloadSound ) ,
23
+ true
24
+ ) ;
25
+ make_thin_wrapper_lifetime ! (
26
+ /// Music, audio stream, anything longer than ~10 seconds should be streamed
27
+ Music ,
28
+ ffi:: Music ,
29
+ RaylibAudio ,
30
+ ffi:: UnloadMusicStream
31
+ ) ;
32
+ make_thin_wrapper_lifetime ! (
33
+ /// AudioStream, custom audio stream
14
34
AudioStream ,
15
35
ffi:: AudioStream ,
16
36
RaylibAudio ,
@@ -87,14 +107,14 @@ impl RaylibAudio {
87
107
pub fn set_master_volume ( & self , volume : f32 ) {
88
108
unsafe { ffi:: SetMasterVolume ( volume) }
89
109
}
90
-
110
+
91
111
/// Sets default audio buffer size for new audio streams.
92
112
#[ inline]
93
113
pub fn set_audio_stream_buffer_size_default ( & self , size : i32 ) {
94
114
unsafe {
95
115
ffi:: SetAudioStreamBufferSizeDefault ( size) ;
96
116
}
97
- }
117
+ }
98
118
99
119
/// Loads a new sound from file.
100
120
#[ inline]
@@ -199,16 +219,24 @@ impl<'aud> Drop for RaylibAudio {
199
219
}
200
220
201
221
impl < ' aud > Wave < ' aud > {
202
- pub fn frame_count ( & self ) -> u32 {
222
+ /// Total number of frames (considering channels)
223
+ #[ inline]
224
+ pub const fn frame_count ( & self ) -> u32 {
203
225
self . 0 . frameCount
204
226
}
205
- pub fn sample_rate ( & self ) -> u32 {
227
+ /// Frequency (samples per second)
228
+ #[ inline]
229
+ pub const fn sample_rate ( & self ) -> u32 {
206
230
self . 0 . sampleRate
207
231
}
208
- pub fn sample_size ( & self ) -> u32 {
232
+ /// Bit depth (bits per sample): 8, 16, 32 (24 not supported)
233
+ #[ inline]
234
+ pub const fn sample_size ( & self ) -> u32 {
209
235
self . 0 . sampleSize
210
236
}
211
- pub fn channels ( & self ) -> u32 {
237
+ /// Number of channels (1-mono, 2-stereo, ...)
238
+ #[ inline]
239
+ pub const fn channels ( & self ) -> u32 {
212
240
self . 0 . channels
213
241
}
214
242
pub unsafe fn inner ( self ) -> ffi:: Wave {
@@ -217,6 +245,7 @@ impl<'aud> Wave<'aud> {
217
245
inner
218
246
}
219
247
248
+ /// Checks if wave data is valid (data loaded and parameters)
220
249
#[ inline]
221
250
pub fn is_wave_valid ( & self ) -> bool {
222
251
unsafe { ffi:: IsWaveValid ( self . 0 ) }
@@ -229,8 +258,8 @@ impl<'aud> Wave<'aud> {
229
258
unsafe { ffi:: ExportWave ( self . 0 , c_filename. as_ptr ( ) ) }
230
259
}
231
260
232
- /// Export wave sample data to code (.h)
233
- /* #[inline]
261
+ /*/ // Export wave sample data to code (.h)
262
+ #[inline]
234
263
pub fn export_wave_as_code(&self, filename: &str) -> bool {
235
264
let c_filename = CString::new(filename).unwrap();
236
265
unsafe { ffi::ExportWaveAsCode(self.0, c_filename.as_ptr()) }
@@ -279,11 +308,15 @@ impl<'aud> AsMut<ffi::AudioStream> for Sound<'aud> {
279
308
}
280
309
281
310
impl < ' aud > Sound < ' aud > {
311
+ /// Checks if a sound is valid (data loaded and buffers initialized)
312
+ #[ inline]
282
313
pub fn is_sound_valid ( & self ) -> bool {
283
314
unsafe { ffi:: IsSoundValid ( self . 0 ) }
284
315
}
285
316
286
- pub fn frame_count ( & self ) -> u32 {
317
+ /// Total number of frames (considering channels)
318
+ #[ inline]
319
+ pub const fn frame_count ( & self ) -> u32 {
287
320
self . 0 . frameCount
288
321
}
289
322
pub unsafe fn inner ( self ) -> ffi:: Sound {
@@ -334,6 +367,7 @@ impl<'aud> Sound<'aud> {
334
367
unsafe { ffi:: SetSoundPitch ( self . 0 , pitch) }
335
368
}
336
369
370
+ /// Set pan for a sound (0.5 is center)
337
371
#[ inline]
338
372
pub fn set_pan ( & self , pan : f32 ) {
339
373
unsafe { ffi:: SetSoundPan ( self . 0 , pan) }
@@ -354,11 +388,15 @@ impl<'aud> Sound<'aud> {
354
388
}
355
389
356
390
impl < ' aud , ' bind > SoundAlias < ' aud , ' bind > {
391
+ /// Checks if a sound is valid (data loaded and buffers initialized)
392
+ #[ inline]
357
393
pub fn is_sound_valid ( & self ) -> bool {
358
394
unsafe { ffi:: IsSoundValid ( self . 0 ) }
359
395
}
360
396
361
- pub fn frame_count ( & self ) -> u32 {
397
+ /// Total number of frames (considering channels)
398
+ #[ inline]
399
+ pub const fn frame_count ( & self ) -> u32 {
362
400
self . 0 . frameCount
363
401
}
364
402
pub unsafe fn inner ( self ) -> ffi:: Sound {
@@ -409,6 +447,7 @@ impl<'aud, 'bind> SoundAlias<'aud, 'bind> {
409
447
unsafe { ffi:: SetSoundPitch ( self . 0 , pitch) }
410
448
}
411
449
450
+ /// Set pan for a sound (0.5 is center)
412
451
#[ inline]
413
452
pub fn set_pan ( & self , pan : f32 ) {
414
453
unsafe { ffi:: SetSoundPan ( self . 0 , pan) }
@@ -482,33 +521,44 @@ impl<'aud> Music<'aud> {
482
521
unsafe { ffi:: GetMusicTimePlayed ( self . 0 ) }
483
522
}
484
523
524
+ /// Seek music to a position (in seconds)
485
525
#[ inline]
486
526
pub fn seek_stream ( & self , position : f32 ) {
487
527
unsafe { ffi:: SeekMusicStream ( self . 0 , position) }
488
528
}
489
529
530
+ /// Set pan for a music (0.5 is center)
490
531
#[ inline]
491
532
pub fn set_pan ( & self , pan : f32 ) {
492
533
unsafe { ffi:: SetMusicPan ( self . 0 , pan) }
493
534
}
494
535
536
+ /// Checks if a music stream is valid (context and buffers initialized)
495
537
#[ inline]
496
538
pub fn is_music_valid ( & self ) -> bool {
497
539
unsafe { ffi:: IsMusicValid ( self . 0 ) }
498
540
}
499
541
}
500
542
501
543
impl < ' aud > AudioStream < ' aud > {
544
+ /// Checks if an audio stream is valid (buffers initialized)
545
+ #[ inline]
502
546
pub fn is_audio_stream_valid ( & self ) -> bool {
503
547
unsafe { ffi:: IsAudioStreamValid ( self . 0 ) }
504
548
}
505
- pub fn sample_rate ( & self ) -> u32 {
549
+ /// Frequency (samples per second)
550
+ #[ inline]
551
+ pub const fn sample_rate ( & self ) -> u32 {
506
552
self . 0 . sampleRate
507
553
}
508
- pub fn sample_size ( & self ) -> u32 {
554
+ /// Bit depth (bits per sample): 8, 16, 32 (24 not supported)
555
+ #[ inline]
556
+ pub const fn sample_size ( & self ) -> u32 {
509
557
self . 0 . sampleSize
510
558
}
511
- pub fn channels ( & self ) -> u32 {
559
+ /// Number of channels (1-mono, 2-stereo, ...)
560
+ #[ inline]
561
+ pub const fn channels ( & self ) -> u32 {
512
562
self . 0 . channels
513
563
}
514
564
@@ -590,6 +640,8 @@ impl<'aud> AudioStream<'aud> {
590
640
unsafe { ffi:: IsAudioStreamProcessed ( self . 0 ) }
591
641
}
592
642
643
+ /// Set pan for audio stream (0.5 is centered)
644
+ #[ inline]
593
645
pub fn set_pan ( & self , pan : f32 ) {
594
646
unsafe {
595
647
ffi:: SetAudioStreamPan ( self . 0 , pan) ;
@@ -598,6 +650,8 @@ impl<'aud> AudioStream<'aud> {
598
650
}
599
651
600
652
impl < ' bind > Sound < ' _ > {
653
+ /// Clone sound from existing sound data, clone does not own wave data
654
+ // NOTE: Wave data must be unallocated manually and will be shared across all clones
601
655
pub fn alias < ' snd > ( & ' snd self ) -> Result < SoundAlias < ' bind , ' snd > , Error > {
602
656
let s = unsafe { ffi:: LoadSoundAlias ( self . 0 ) } ;
603
657
if s. stream . buffer . is_null ( ) {
0 commit comments