native_audio 0.5.1 → 0.5.2

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/ext/audio/audio.c +13 -0
  3. data/ext/audio/audio.h +2 -0
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0dd09de66ecf033b152768c52c807b025e05f1a7a3cbbc5b0b15bab85746a42
4
- data.tar.gz: 4af9bdb8da0bcb06d75335a69d56f5a513206ce06f5a849c7837f5bf713aa2cf
3
+ metadata.gz: 8d7a019f96cab6e7939d9c7cd4ab6c238712dd7e973b9a5ded1ad565a6156af7
4
+ data.tar.gz: 6e5c823010843c54a0225433a1cd59e7980739e16ff5d607e23395da04316941
5
5
  SHA512:
6
- metadata.gz: 84abd6f60b5f33320866d5ad74aac58c604236322fe9d62c1894502ca531b203148631588dcd2d41afc63e4da08aa75805145eb951ce839dcc1e5eeaa8f18577
7
- data.tar.gz: f37a3d01e2fba67d3b34c9b830ff53907b02a9a64d47df968c97365866d8b58a1870baa672cf0c553739bb58120646b16b68ecadec5224056c1d3384a90c4415
6
+ metadata.gz: d9b89059a4f4668c9a230f3cf543f281fa2930fee6773ab09790995deb22b454125ba50e81fec46edea5c19e61571b46f5589ffd45730e3ad0ecf12e092ff7aa
7
+ data.tar.gz: b2819672ad24fc89fccef79131eaee9711148d5b0ce608a681671d872706ef144d51053d04059e7fe523e5fdb3e0fc93815527e574161da8f8fd78c3bed3d893
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
  }
@@ -579,6 +591,7 @@ void Init_audio(void)
579
591
  channels[i] = NULL;
580
592
  delay_nodes[i] = NULL;
581
593
  reverb_nodes[i] = NULL;
594
+ drain_until_frame[i] = 0;
582
595
  }
583
596
 
584
597
  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;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: native_audio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Hatfull