native_audio 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/audio/audio.c +17 -11
- data/ext/audio/audio.h +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8ba1115278418cb8e450777a6f99843bfb5a1510979e2d44979786aef4e0f86d
|
|
4
|
+
data.tar.gz: 903c73d6e09842504d851406db41a18dc7a6f7a3b579092f32a43481438bc205
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e05701f74ee36749bf0fa7c51dc61dd84f79a95c736d59fb7d067507f31b7b4ad4f741b28e1370698a434292110701bb51dcf0fdfcb3076a91e1874a5947c88a
|
|
7
|
+
data.tar.gz: 13226093d8f6923944f1a83ea3651075d1a388c1fb0e5897b15dbd8772dd84de6ab26e6897f39646495ae3b16eeb2a56ac9eb91732b3270e017d974bd2e4daa2
|
data/ext/audio/audio.c
CHANGED
|
@@ -21,6 +21,7 @@ ma_sound *sounds[MAX_SOUNDS];
|
|
|
21
21
|
ma_sound *channels[MAX_CHANNELS];
|
|
22
22
|
multi_tap_delay_node *delay_nodes[MAX_CHANNELS];
|
|
23
23
|
reverb_node *reverb_nodes[MAX_CHANNELS];
|
|
24
|
+
ma_uint64 drain_until_frame[MAX_CHANNELS];
|
|
24
25
|
int sound_count = 0;
|
|
25
26
|
int engine_initialized = 0;
|
|
26
27
|
int context_initialized = 0;
|
|
@@ -182,12 +183,21 @@ VALUE audio_duration(VALUE self, VALUE clip)
|
|
|
182
183
|
|
|
183
184
|
static void cleanup_finished_channels(void)
|
|
184
185
|
{
|
|
186
|
+
ma_uint64 now = ma_engine_get_time_in_pcm_frames(&engine);
|
|
187
|
+
ma_uint32 sample_rate = ma_engine_get_sample_rate(&engine);
|
|
188
|
+
ma_uint64 drain_frames = (ma_uint64)(REVERB_DRAIN_SECONDS * sample_rate);
|
|
189
|
+
|
|
185
190
|
for (int i = 0; i < MAX_CHANNELS; i++) {
|
|
191
|
+
// Phase 1: sound finished - uninit the sound, start drain timer
|
|
186
192
|
if (channels[i] != NULL && ma_sound_at_end(channels[i])) {
|
|
187
193
|
ma_sound_uninit(channels[i]);
|
|
188
194
|
free(channels[i]);
|
|
189
195
|
channels[i] = NULL;
|
|
196
|
+
drain_until_frame[i] = now + drain_frames;
|
|
197
|
+
}
|
|
190
198
|
|
|
199
|
+
// Phase 2: drain timer expired - uninit delay and reverb nodes
|
|
200
|
+
if (drain_until_frame[i] != 0 && now >= drain_until_frame[i]) {
|
|
191
201
|
if (delay_nodes[i] != NULL) {
|
|
192
202
|
multi_tap_delay_uninit(delay_nodes[i]);
|
|
193
203
|
free(delay_nodes[i]);
|
|
@@ -199,6 +209,8 @@ static void cleanup_finished_channels(void)
|
|
|
199
209
|
free(reverb_nodes[i]);
|
|
200
210
|
reverb_nodes[i] = NULL;
|
|
201
211
|
}
|
|
212
|
+
|
|
213
|
+
drain_until_frame[i] = 0;
|
|
202
214
|
}
|
|
203
215
|
}
|
|
204
216
|
}
|
|
@@ -319,22 +331,15 @@ VALUE audio_stop(VALUE self, VALUE channel_id)
|
|
|
319
331
|
return Qnil;
|
|
320
332
|
}
|
|
321
333
|
|
|
334
|
+
ma_uint64 now = ma_engine_get_time_in_pcm_frames(&engine);
|
|
335
|
+
ma_uint32 sample_rate = ma_engine_get_sample_rate(&engine);
|
|
336
|
+
|
|
322
337
|
ma_sound_stop(channels[channel]);
|
|
323
338
|
ma_sound_uninit(channels[channel]);
|
|
324
339
|
free(channels[channel]);
|
|
325
340
|
channels[channel] = NULL;
|
|
326
341
|
|
|
327
|
-
|
|
328
|
-
multi_tap_delay_uninit(delay_nodes[channel]);
|
|
329
|
-
free(delay_nodes[channel]);
|
|
330
|
-
delay_nodes[channel] = NULL;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
if (reverb_nodes[channel] != NULL) {
|
|
334
|
-
reverb_uninit(reverb_nodes[channel]);
|
|
335
|
-
free(reverb_nodes[channel]);
|
|
336
|
-
reverb_nodes[channel] = NULL;
|
|
337
|
-
}
|
|
342
|
+
drain_until_frame[channel] = now + (ma_uint64)(REVERB_DRAIN_SECONDS * sample_rate);
|
|
338
343
|
|
|
339
344
|
return Qnil;
|
|
340
345
|
}
|
|
@@ -579,6 +584,7 @@ void Init_audio(void)
|
|
|
579
584
|
channels[i] = NULL;
|
|
580
585
|
delay_nodes[i] = NULL;
|
|
581
586
|
reverb_nodes[i] = NULL;
|
|
587
|
+
drain_until_frame[i] = 0;
|
|
582
588
|
}
|
|
583
589
|
|
|
584
590
|
VALUE mAudio = rb_define_module("Audio");
|
data/ext/audio/audio.h
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
#define MAX_SOUNDS 1024
|
|
17
17
|
#define MAX_CHANNELS 1024
|
|
18
|
+
#define REVERB_DRAIN_SECONDS 3.0f
|
|
18
19
|
|
|
19
20
|
// ============================================================================
|
|
20
21
|
// Globals (defined in audio.c)
|
|
@@ -26,6 +27,7 @@ extern ma_sound *sounds[MAX_SOUNDS];
|
|
|
26
27
|
extern ma_sound *channels[MAX_CHANNELS];
|
|
27
28
|
extern multi_tap_delay_node *delay_nodes[MAX_CHANNELS];
|
|
28
29
|
extern reverb_node *reverb_nodes[MAX_CHANNELS];
|
|
30
|
+
extern ma_uint64 drain_until_frame[MAX_CHANNELS];
|
|
29
31
|
extern int sound_count;
|
|
30
32
|
extern int engine_initialized;
|
|
31
33
|
extern int context_initialized;
|