fmod-ruby 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -33,6 +33,8 @@ No formal test suite yet. However, the +examples/+ directory includes several e
33
33
  History
34
34
  =======
35
35
 
36
+ * release 0.3.0 - added FMOD::Error, more detailed error reporting
37
+ * release 0.2.0 - added Convert.samples_to_ms
36
38
  * release 0.1.1 - added Channel#set_volume, Sound#release
37
39
  * release 0.1.0 - added keyword options to System#initialize and whatnot to support offline wav creation (examples write.rb and contact.rb)
38
40
 
@@ -26,4 +26,7 @@ module FMOD
26
26
  def self.system_pointer
27
27
  @system.pointer
28
28
  end
29
+
30
+ class Error < ::RuntimeError
31
+ end
29
32
  end
@@ -21,51 +21,51 @@ module FMOD
21
21
  # result = FMOD_Channel_IsPlaying(channel, &playing);
22
22
  def playing?
23
23
  FFI::MemoryPointer.new(:int) do |ptr|
24
- error_check FMOD_Channel_IsPlaying(pointer, ptr)
24
+ error_check(:FMOD_Channel_IsPlaying, pointer, ptr)
25
25
  return ptr.read_int == 1
26
26
  end
27
27
  end
28
28
 
29
29
  def pause
30
- error_check FMOD_Channel_SetPaused(pointer, ((paused?) ? 0 : 1))
30
+ error_check(:FMOD_Channel_SetPaused, pointer, ((paused?) ? 0 : 1))
31
31
  end
32
32
 
33
33
  def set_paused(bool)
34
- error_check FMOD_Channel_SetPaused(pointer, (bool ? 1 : 0))
34
+ error_check(:FMOD_Channel_SetPaused, pointer, (bool ? 1 : 0))
35
35
  end
36
36
 
37
37
  def paused?
38
38
  FFI::MemoryPointer.new(:int) do |ptr|
39
- error_check FMOD_Channel_GetPaused(pointer, ptr)
39
+ error_check(:FMOD_Channel_GetPaused, pointer, ptr)
40
40
  return ptr.read_int == 1
41
41
  end
42
42
  end
43
43
 
44
44
  def set_position(int = 0)
45
- error_check FMOD_Channel_SetPosition(pointer, int, FMOD_TIMEUNIT_MS)
45
+ error_check(:FMOD_Channel_SetPosition, pointer, int, FMOD_TIMEUNIT_MS)
46
46
  end
47
47
 
48
48
  def pan=(float)
49
49
  float = 1.0 if float > 1.0
50
50
  float = 0.0 if float < 0.0
51
- error_check FMOD_Channel_SetPan(pointer, float)
51
+ error_check(:FMOD_Channel_SetPan, pointer, float)
52
52
  end
53
53
 
54
54
  def frequency
55
55
  FFI::MemoryPointer.new(:float) do |ptr|
56
- error_check FMOD_Channel_GetFrequency(pointer, ptr)
56
+ error_check(:FMOD_Channel_GetFrequency, pointer, ptr)
57
57
  return ptr.read_float
58
58
  end
59
59
  end
60
60
 
61
61
  def frequency=(float)
62
- error_check FMOD_Channel_SetFrequency(pointer, float)
62
+ error_check(:FMOD_Channel_SetFrequency, pointer, float)
63
63
  end
64
64
 
65
65
  def set_delay(samples, opts={})
66
66
  opts = opts.keyword_args(:delaytype => :required)
67
67
  hi, lo = Convert.int64_to_32(samples)
68
- error_check FMOD_Channel_SetDelay(pointer, opts.delaytype, hi, lo)
68
+ error_check(:FMOD_Channel_SetDelay, pointer, opts.delaytype, hi, lo)
69
69
  end
70
70
 
71
71
  def get_delay(opts={})
@@ -73,14 +73,14 @@ module FMOD
73
73
 
74
74
  FFI::MemoryPointer.new(:int) { |hi|
75
75
  FFI::MemoryPointer.new(:int) { |lo|
76
- error_check FMOD_Channel_GetDelay(pointer, opts.delaytype, hi, lo)
76
+ error_check(:FMOD_Channel_GetDelay, pointer, opts.delaytype, hi, lo)
77
77
  return Convert.int32_to_64(hi.read_int, lo.read_int)
78
78
  }
79
79
  }
80
80
  end
81
81
 
82
82
  def set_volume(volume)
83
- error_check FMOD_Channel_SetVolume(pointer, volume)
83
+ error_check(:FMOD_Channel_SetVolume, pointer, volume)
84
84
  end
85
85
 
86
86
  end
@@ -95,8 +95,10 @@ module FMOD
95
95
  attach_function :FMOD_Sound_Release, [:pointer], FMOD_RESULT
96
96
 
97
97
 
98
- def error_check(result)
99
- raise "FMOD error! #{result}" if result != :FMOD_OK
98
+ def error_check(msg, *args)
99
+ if (result = send msg, *args) != :FMOD_OK
100
+ raise FMOD::Error, "Error in #{msg}(#{args.map(&:inspect).join(', ')}): #{result}"
101
+ end
100
102
  end
101
103
  end
102
104
  end
@@ -12,7 +12,7 @@ module FMOD
12
12
 
13
13
  def length(unit = FMOD_TIMEUNIT_MS)
14
14
  FFI::MemoryPointer.new(:int) do |ptr|
15
- error_check FMOD_Sound_GetLength(sound_ptr, ptr, FMOD_TIMEUNIT_MS)
15
+ error_check(:FMOD_Sound_GetLength, sound_ptr, ptr, FMOD_TIMEUNIT_MS)
16
16
  return ptr.read_int
17
17
  end
18
18
  end
@@ -20,13 +20,13 @@ module FMOD
20
20
  def play(opts={})
21
21
  opts = opts.keyword_args(:paused)
22
22
  # FMOD_RESULT = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, 0, &channel);
23
- error_check FMOD_System_PlaySound(FMOD.system.pointer, :FMOD_CHANNEL_FREE, sound_ptr, opts.paused ? 1 : 0, @channel.pointer_addr);
23
+ error_check(:FMOD_System_PlaySound, FMOD.system.pointer, :FMOD_CHANNEL_FREE, sound_ptr, opts.paused ? 1 : 0, @channel.pointer_addr)
24
24
  true
25
25
  end
26
26
 
27
27
  def release
28
28
  return unless @sound_ptr
29
- error_check FMOD_Sound_Release(@sound_ptr)
29
+ error_check(:FMOD_Sound_Release, @sound_ptr)
30
30
  @sound_ptr = nil
31
31
  end
32
32
 
@@ -37,7 +37,7 @@ module FMOD
37
37
 
38
38
  @memory = FFI::MemoryPointer.new(:pointer)
39
39
  # FMOD_RESULT = FMOD_System_CreateSound(system, "drumloop.wav", FMOD_SOFTWARE, 0, &sound);
40
- error_check FMOD_System_CreateSound(@system_pointer, @file, FMOD_DEFAULT, 0, @memory);
40
+ error_check(:FMOD_System_CreateSound, @system_pointer, @file, FMOD_DEFAULT, 0, @memory)
41
41
 
42
42
  @sound_ptr = @memory.read_pointer
43
43
  end
@@ -12,16 +12,16 @@ module FMOD
12
12
  @sample_rate = opts.sample_rate
13
13
 
14
14
  @memory = FFI::MemoryPointer.new(:pointer)
15
- error_check FMOD_System_Create(@memory)
15
+ error_check(:FMOD_System_Create, @memory)
16
16
  @pointer = @memory.read_pointer
17
17
 
18
18
  case
19
19
  when opts.output_wav
20
- error_check FMOD_System_SetOutput(@pointer, :FMOD_OUTPUTTYPE_WAVWRITER_NRT)
21
- error_check FMOD_System_SetSoftwareFormat(@pointer, sample_rate, :FMOD_SOUND_FORMAT_PCM16, 2, 6, :FMOD_DSP_RESAMPLER_LINEAR)
22
- error_check FMOD_System_Init(@pointer, 100, FMOD_INIT_STREAM_FROM_UPDATE, opts.output_wav)
20
+ error_check(:FMOD_System_SetOutput, @pointer, :FMOD_OUTPUTTYPE_WAVWRITER_NRT)
21
+ error_check(:FMOD_System_SetSoftwareFormat, @pointer, sample_rate, :FMOD_SOUND_FORMAT_PCM16, 2, 6, :FMOD_DSP_RESAMPLER_LINEAR)
22
+ error_check(:FMOD_System_Init, @pointer, 100, FMOD_INIT_STREAM_FROM_UPDATE, opts.output_wav)
23
23
  else
24
- error_check FMOD_System_Init(@pointer, 32, FMOD_INIT_NORMAL, nil)
24
+ error_check(:FMOD_System_Init, @pointer, 32, FMOD_INIT_NORMAL, nil)
25
25
  end
26
26
  end
27
27
 
@@ -29,7 +29,7 @@ module FMOD
29
29
  # unsigned int version;
30
30
  # result = FMOD_System_GetVersion(system, &version);
31
31
  FFI::MemoryPointer.new(:int) { |version_ptr|
32
- error_check FMOD_System_GetVersion(@pointer, version_ptr);
32
+ error_check(:FMOD_System_GetVersion, @pointer, version_ptr)
33
33
  return version_ptr.read_int
34
34
  }
35
35
  end
@@ -38,14 +38,14 @@ module FMOD
38
38
  # unsigned int numdrivers;
39
39
  # result = FMOD_System_GetNumDrivers(system, &numdrivers);
40
40
  FFI::MemoryPointer.new(:int) { |count_ptr|
41
- error_check FMOD_System_GetNumDrivers(@pointer, count_ptr)
41
+ error_check(:FMOD_System_GetNumDrivers, @pointer, count_ptr)
42
42
  count_ptr.read_int
43
43
  }
44
44
  end
45
45
 
46
46
  def software_channels
47
47
  FFI::MemoryPointer.new(:int) { |num_ptr|
48
- error_check FMOD_System_GetSoftwareChannels(@pointer, num_ptr)
48
+ error_check(:FMOD_System_GetSoftwareChannels, @pointer, num_ptr)
49
49
  num_ptr.read_int
50
50
  }
51
51
  end
@@ -54,8 +54,7 @@ module FMOD
54
54
  FFI::MemoryPointer.new(:int) { |num2d|
55
55
  FFI::MemoryPointer.new(:int) { |num3d|
56
56
  FFI::MemoryPointer.new(:int) { |total|
57
- error_check FMOD_System_GetHardwareChannels(@pointer, num2d, num3d, total)
58
-
57
+ error_check(:FMOD_System_GetHardwareChannels, @pointer, num2d, num3d, total)
59
58
  {
60
59
  :num2d => num2d.read_int,
61
60
  :num3d => num3d.read_int,
@@ -69,7 +68,7 @@ module FMOD
69
68
  def dsp_clock
70
69
  FFI::MemoryPointer.new(:int) { |hi|
71
70
  FFI::MemoryPointer.new(:int) { |lo|
72
- error_check FMOD_System_GetDSPClock(@pointer, hi, lo)
71
+ error_check(:FMOD_System_GetDSPClock, @pointer, hi, lo)
73
72
  return Convert.int32_to_64(hi.read_int, lo.read_int)
74
73
  }
75
74
  }
@@ -77,17 +76,17 @@ module FMOD
77
76
 
78
77
  def buffer_size
79
78
  FFI::MemoryPointer.new(:int) { |size|
80
- error_check FMOD_System_GetDSPBufferSize(@pointer, size, nil)
79
+ error_check(:FMOD_System_GetDSPBufferSize, @pointer, size, nil)
81
80
  return size.read_int
82
81
  }
83
82
  end
84
83
 
85
84
  def update
86
- error_check FMOD_System_Update(@pointer)
85
+ error_check(:FMOD_System_Update, @pointer)
87
86
  end
88
87
 
89
88
  def release
90
- error_check FMOD_System_Release(@pointer)
89
+ error_check(:FMOD_System_Release, @pointer)
91
90
  end
92
91
  end
93
92
  end
@@ -1,3 +1,3 @@
1
1
  module Fmod
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fmod-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-01 00:00:00.000000000 Z
12
+ date: 2012-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
16
- requirement: &70100818011000 !ruby/object:Gem::Requirement
16
+ requirement: &70299865565260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70100818011000
24
+ version_requirements: *70299865565260
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hash_keyword_args
27
- requirement: &70100818010440 !ruby/object:Gem::Requirement
27
+ requirement: &70299865564080 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70100818010440
35
+ version_requirements: *70299865564080
36
36
  description: Wrapper for the FMOD audio library
37
37
  email:
38
38
  - ronen@barzel.org