hallon-openal 1.0.0 → 1.0.1

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.
@@ -1,3 +1,6 @@
1
+ # v1.0.1
2
+ - Fix bug when stopping while trying to find an empty buffer.
3
+
1
4
  # v1.0.0
2
5
  - Fix bug when stopping audio when currently playing (see #1)
3
6
  - Bumped to v1.0.0. The API is stable, even though the gem is not. :p
@@ -32,7 +32,7 @@ else
32
32
  end
33
33
 
34
34
  %w[alcOpenDevice alGetError].each do |func|
35
- abort "Missing function #{func}" unless have_func(func)
35
+ error "Missing function #{func}" unless have_func(func)
36
36
  end
37
37
 
38
38
  create_makefile('openal_ext')
@@ -103,8 +103,6 @@ static inline VALUE _oa_format_type(VALUE self)
103
103
 
104
104
  static void oa_free(oa_struct_t *data_ptr)
105
105
  {
106
- int i;
107
-
108
106
  // exit early if we have no data_ptr at all
109
107
  if ( ! data_ptr) return;
110
108
 
@@ -139,7 +137,6 @@ static VALUE oa_allocate(VALUE klass)
139
137
  static VALUE oa_initialize(VALUE self)
140
138
  {
141
139
  oa_struct_t *data_ptr;
142
- ALenum error = AL_NO_ERROR;
143
140
 
144
141
  // initialize openal
145
142
  Data_Get_Struct(self, oa_struct_t, data_ptr);
@@ -174,6 +171,8 @@ static VALUE oa_initialize(VALUE self)
174
171
  // generate our source
175
172
  alGenSources(1, &data_ptr->source);
176
173
  OA_CHECK_ERRORS("gen sources");
174
+
175
+ return self;
177
176
  }
178
177
 
179
178
  static VALUE oa_play(VALUE self)
@@ -220,29 +219,48 @@ static ALuint find_empty_buffer(VALUE self)
220
219
  ALuint source = data_ptr->source;
221
220
  ALuint *buffers = data_ptr->buffers;
222
221
 
223
- ALint num_queued = 0;
224
- alGetSourcei(source, AL_BUFFERS_QUEUED, &num_queued);
225
- OA_CHECK_ERRORS("AL_BUFFERS_QUEUED");
222
+ struct timeval poll_time;
223
+ poll_time.tv_sec = 0;
224
+ poll_time.tv_usec = 100; /* 0.000100 sec */
226
225
 
227
- if (num_queued < NUM_BUFFERS)
228
- {
229
- empty_buffer = buffers[num_queued];
230
- }
231
- else
226
+ /* infinite loop until we break */
227
+ for (;;rb_thread_wait_for(poll_time))
232
228
  {
233
- int processed;
234
- struct timeval poll_time;
235
- poll_time.tv_sec = 0;
236
- poll_time.tv_usec = 100; /* 0.000100 sec */
229
+ ALint num_queued = 0;
230
+ alGetSourcei(source, AL_BUFFERS_QUEUED, &num_queued);
231
+ OA_CHECK_ERRORS("AL_BUFFERS_QUEUED");
237
232
 
238
- for (processed = 0; processed == 0; rb_thread_wait_for(poll_time))
233
+ if (num_queued < NUM_BUFFERS)
239
234
  {
240
- alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
241
- OA_CHECK_ERRORS("AL_BUFFERS_PROCESSED");
235
+ empty_buffer = buffers[num_queued];
236
+ DEBUG("Q/B: %d/%d\n", num_queued, NUM_BUFFERS);
237
+ break;
238
+ }
239
+ else
240
+ {
241
+ ALint state;
242
+ alGetSourcei(source, AL_SOURCE_STATE, &state);
243
+ OA_CHECK_ERRORS("AL_SOURCE_STATE");
244
+
245
+ /* there is an openal bug that appears to assume
246
+ * all queued buffers are processed when the source
247
+ * is not playing */
248
+ if (state == AL_PLAYING)
249
+ {
250
+ int processed = 0;
251
+
252
+ alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
253
+ OA_CHECK_ERRORS("AL_BUFFERS_PROCESSED");
254
+
255
+ if (processed > 0)
256
+ {
257
+ DEBUG("processed: %d\n", processed);
258
+ alSourceUnqueueBuffers(source, 1, &empty_buffer);
259
+ OA_CHECK_ERRORS("alSourceUnqueueBuffers");
260
+ break;
261
+ }
262
+ }
242
263
  }
243
-
244
- alSourceUnqueueBuffers(source, 1, &empty_buffer);
245
- OA_CHECK_ERRORS("alSourceUnqueueBuffers");
246
264
  }
247
265
 
248
266
  return empty_buffer;
@@ -301,6 +319,9 @@ static VALUE oa_stream(VALUE self)
301
319
 
302
320
  for (;;)
303
321
  {
322
+ ALuint buffer = find_empty_buffer(self);
323
+ OA_CHECK_ERRORS("find_empty_buffer");
324
+
304
325
  // pull some audio out of hallon
305
326
  VALUE frames = rb_yield(INT2FIX(sample_ary_frames));
306
327
 
@@ -311,9 +332,6 @@ static VALUE oa_stream(VALUE self)
311
332
  break;
312
333
  }
313
334
 
314
- ALuint buffer = find_empty_buffer(self);
315
- OA_CHECK_ERRORS("find_empty_buffer");
316
-
317
335
  // convert the frames from ruby to C
318
336
  int num_current_samples = ((int) RARRAY_LEN(frames)) * f_channels;
319
337
 
@@ -1,5 +1,5 @@
1
1
  module Hallon
2
2
  class OpenAL
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hallon-openal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,30 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-08 00:00:00.000000000 Z
12
+ date: 2013-01-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hallon
16
- requirement: &70151857522300 !ruby/object:Gem::Requirement
17
- none: false
16
+ prerelease: false
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0.13'
22
+ none: false
22
23
  type: :runtime
23
- prerelease: false
24
- version_requirements: *70151857522300
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: '0.13'
29
+ none: false
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rspec
27
- requirement: &70151857521660 !ruby/object:Gem::Requirement
28
- none: false
32
+ prerelease: false
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  requirements:
30
35
  - - ~>
31
36
  - !ruby/object:Gem::Version
32
37
  version: '2.7'
38
+ none: false
33
39
  type: :development
34
- prerelease: false
35
- version_requirements: *70151857521660
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: '2.7'
45
+ none: false
36
46
  description:
37
47
  email:
38
48
  - kim@burgestrand.se
@@ -63,20 +73,20 @@ require_paths:
63
73
  - lib
64
74
  - ext
65
75
  required_ruby_version: !ruby/object:Gem::Requirement
66
- none: false
67
76
  requirements:
68
77
  - - ! '>='
69
78
  - !ruby/object:Gem::Version
70
79
  version: '0'
71
- required_rubygems_version: !ruby/object:Gem::Requirement
72
80
  none: false
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
82
  requirements:
74
83
  - - ! '>='
75
84
  - !ruby/object:Gem::Version
76
85
  version: '0'
86
+ none: false
77
87
  requirements: []
78
88
  rubyforge_project:
79
- rubygems_version: 1.8.17
89
+ rubygems_version: 1.8.24
80
90
  signing_key:
81
91
  specification_version: 3
82
92
  summary: ! 'OpenAL audio drivers for Hallon: http://rubygems.org/gems/hallon'