beeps 0.1.11 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/.doc/ext/beeps/beeps.cpp +2 -5
  3. data/.doc/ext/beeps/file_in.cpp +0 -5
  4. data/.doc/ext/beeps/native.cpp +0 -4
  5. data/.doc/ext/beeps/processor.cpp +1 -5
  6. data/.doc/ext/beeps/sawtooth_wave.cpp +0 -5
  7. data/.doc/ext/beeps/sine_wave.cpp +0 -5
  8. data/.doc/ext/beeps/sound.cpp +0 -5
  9. data/.doc/ext/beeps/square_wave.cpp +0 -5
  10. data/README.md +1 -1
  11. data/Rakefile +15 -12
  12. data/VERSION +1 -1
  13. data/beeps.gemspec +5 -7
  14. data/ext/beeps/beeps.cpp +2 -5
  15. data/ext/beeps/defs.h +3 -2
  16. data/ext/beeps/extconf.rb +2 -3
  17. data/ext/beeps/file_in.cpp +0 -5
  18. data/ext/beeps/native.cpp +0 -4
  19. data/ext/beeps/processor.cpp +1 -5
  20. data/ext/beeps/sawtooth_wave.cpp +0 -5
  21. data/ext/beeps/sine_wave.cpp +0 -5
  22. data/ext/beeps/sound.cpp +0 -5
  23. data/ext/beeps/square_wave.cpp +0 -5
  24. data/include/beeps.h +5 -0
  25. data/include/beeps/debug.h +23 -0
  26. data/include/beeps/exception.h +6 -2
  27. data/include/beeps/processor.h +9 -6
  28. data/include/beeps/ruby/beeps.h +1 -0
  29. data/include/beeps/signals.h +2 -9
  30. data/include/beeps/sound.h +2 -1
  31. data/lib/beeps/module.rb +4 -19
  32. data/lib/beeps/processor.rb +16 -20
  33. data/src/beeps.cpp +3 -64
  34. data/src/exception.cpp +0 -3
  35. data/src/openal.cpp +63 -174
  36. data/src/openal.h +15 -4
  37. data/src/processor.cpp +5 -5
  38. data/src/signals.cpp +21 -19
  39. data/src/signals.h +23 -0
  40. data/src/sound.cpp +173 -14
  41. data/src/sound.h +17 -0
  42. metadata +30 -73
  43. data/include/beeps/openal.h +0 -34
  44. data/src/stk/include/Blit.h +0 -151
  45. data/src/stk/include/BlitSaw.h +0 -148
  46. data/src/stk/include/BlitSquare.h +0 -170
  47. data/src/stk/include/FileRead.h +0 -141
  48. data/src/stk/include/FileWvIn.h +0 -195
  49. data/src/stk/include/Generator.h +0 -50
  50. data/src/stk/include/SineWave.h +0 -159
  51. data/src/stk/include/Stk.h +0 -589
  52. data/src/stk/include/WvIn.h +0 -46
  53. data/src/stk/src/Blit.cpp +0 -78
  54. data/src/stk/src/BlitSaw.cpp +0 -91
  55. data/src/stk/src/BlitSquare.cpp +0 -95
  56. data/src/stk/src/FileRead.cpp +0 -903
  57. data/src/stk/src/FileWvIn.cpp +0 -260
  58. data/src/stk/src/SineWave.cpp +0 -78
  59. data/src/stk/src/Stk.cpp +0 -395
@@ -5,6 +5,7 @@
5
5
 
6
6
 
7
7
  #include <rucy/module.h>
8
+ #include <beeps/beeps.h>
8
9
 
9
10
 
10
11
  namespace Beeps
@@ -8,9 +8,6 @@
8
8
  #include <beeps/defs.h>
9
9
 
10
10
 
11
- namespace stk {class StkFrames;};
12
-
13
-
14
11
  namespace Beeps
15
12
  {
16
13
 
@@ -24,7 +21,7 @@ namespace Beeps
24
21
 
25
22
  ~Signals ();
26
23
 
27
- Signals copy () const;
24
+ Signals dup () const;
28
25
 
29
26
  float seconds () const;
30
27
 
@@ -32,17 +29,13 @@ namespace Beeps
32
29
 
33
30
  uint channels () const;
34
31
 
35
- stk::StkFrames* frames ();
36
-
37
- const stk::StkFrames* frames () const;
38
-
39
32
  operator bool () const;
40
33
 
41
34
  bool operator ! () const;
42
35
 
43
36
  struct Data;
44
37
 
45
- Xot::PImpl<Data, true> self;
38
+ Xot::PSharedImpl<Data> self;
46
39
 
47
40
  };// Signals
48
41
 
@@ -5,6 +5,7 @@
5
5
 
6
6
 
7
7
  #include <xot/pimpl.h>
8
+ #include <beeps/defs.h>
8
9
 
9
10
 
10
11
  namespace Beeps
@@ -33,7 +34,7 @@ namespace Beeps
33
34
 
34
35
  struct Data;
35
36
 
36
- Xot::PImpl<Data, true> self;
37
+ Xot::PSharedImpl<Data> self;
37
38
 
38
39
  };// Sound
39
40
 
@@ -6,6 +6,8 @@ module Beeps
6
6
 
7
7
  module Module
8
8
 
9
+ module_function
10
+
9
11
  def name ()
10
12
  super.split('::')[-2]
11
13
  end
@@ -15,10 +17,10 @@ module Beeps
15
17
  end
16
18
 
17
19
  def root_dir (path = '')
18
- File.expand_path "../../../#{path}", __FILE__
20
+ File.expand_path "../../#{path}", __dir__
19
21
  end
20
22
 
21
- def include_dir ()
23
+ def inc_dir ()
22
24
  root_dir 'include'
23
25
  end
24
26
 
@@ -26,23 +28,6 @@ module Beeps
26
28
  root_dir 'lib'
27
29
  end
28
30
 
29
- def task_dir ()
30
- root_dir 'task'
31
- end
32
-
33
- def load_tasks (*names)
34
- if names.empty?
35
- Dir["#{task_dir}/**/*.rake"].each {|path| load path}
36
- else
37
- names.each do |name|
38
- path = "#{task_dir}/#{name}.rake"
39
- load path if File.exist? path
40
- end
41
- end
42
- end
43
-
44
- extend self
45
-
46
31
  end# Module
47
32
 
48
33
 
@@ -2,6 +2,7 @@
2
2
 
3
3
 
4
4
  require 'xot/setter'
5
+ require 'xot/universal_accessor'
5
6
  require 'xot/block_util'
6
7
  require 'beeps/ext'
7
8
 
@@ -9,50 +10,45 @@ require 'beeps/ext'
9
10
  module Beeps
10
11
 
11
12
 
12
- class SineWave
13
+ class Processor
13
14
 
14
15
  include Xot::Setter
15
16
 
16
- alias freq= frequency=
17
- alias freq frequency
18
-
19
- def initialize (opts = {}, &block)
17
+ def initialize (options = nil, &block)
20
18
  super()
21
- set opts
19
+ set options if options
22
20
  Xot::BlockUtil.instance_eval_or_block_call self, &block if block
23
21
  end
24
22
 
23
+ end# Processor
24
+
25
+
26
+ class SineWave
27
+
28
+ alias freq= frequency=
29
+ alias freq frequency
30
+
31
+ universal_accessor :frequency, :freq
32
+
25
33
  end# SineWave
26
34
 
27
35
 
28
36
  class SquareWave
29
37
 
30
- include Xot::Setter
31
-
32
38
  alias freq= frequency=
33
39
  alias freq frequency
34
40
 
35
- def initialize (opts = {}, &block)
36
- super()
37
- set opts
38
- Xot::BlockUtil.instance_eval_or_block_call self, &block if block
39
- end
41
+ universal_accessor :frequency, :freq
40
42
 
41
43
  end# SquareWave
42
44
 
43
45
 
44
46
  class SawtoothWave
45
47
 
46
- include Xot::Setter
47
-
48
48
  alias freq= frequency=
49
49
  alias freq frequency
50
50
 
51
- def initialize (opts = {}, &block)
52
- super()
53
- set opts
54
- Xot::BlockUtil.instance_eval_or_block_call self, &block if block
55
- end
51
+ universal_accessor :frequency, :freq
56
52
 
57
53
  end# SawtoothWave
58
54
 
@@ -2,90 +2,29 @@
2
2
  #include "beeps/beeps.h"
3
3
 
4
4
 
5
- #include <stdlib.h>
6
5
  #include "Stk.h"
7
- #include "beeps/openal.h"
8
6
  #include "beeps/exception.h"
7
+ #include "openal.h"
9
8
 
10
9
 
11
10
  namespace Beeps
12
11
  {
13
12
 
14
13
 
15
- namespace global
16
- {
17
-
18
- static ALCdevice* device = NULL;
19
-
20
- static ALCcontext* context = NULL;
21
-
22
- }// global
23
-
24
-
25
- namespace g = global;
26
-
27
-
28
- static void
29
- cleanup ()
30
- {
31
- void cleanup_sources ();
32
- cleanup_sources();
33
-
34
- alcMakeContextCurrent(NULL);
35
-
36
- if (g::context)
37
- {
38
- alcDestroyContext(g::context);
39
- g::context = NULL;
40
- }
41
-
42
- if (g::device)
43
- {
44
- alcCloseDevice(g::device);
45
- g::device = NULL;
46
- }
47
- }
48
-
49
14
  void
50
15
  init ()
51
16
  {
52
- if (g::device || g::context)
53
- beeps_error(__FILE__, __LINE__, "Beeps::init(): already initialized.");
17
+ OpenAL_init();
54
18
 
55
19
  stk::Stk::setSampleRate(44100);
56
-
57
- g::device = alcOpenDevice(NULL);
58
- if (!g::device) goto FAILED;
59
-
60
- g::context = alcCreateContext(g::device, NULL);
61
- if (!g::context) goto FAILED;
62
-
63
- if (!alcMakeContextCurrent(g::context))
64
- goto FAILED;
65
-
66
- return;
67
-
68
- FAILED:
69
- cleanup();
70
- openal_error(__FILE__, __LINE__, "failed to setup OpenAL.");
71
20
  }
72
21
 
73
22
  void
74
23
  fin ()
75
24
  {
76
- if (!g::context)
77
- beeps_error(__FILE__, __LINE__, "Beeps::fin(): not initialized.");
78
-
79
- cleanup();
80
- }
81
-
82
- ALCdevice*
83
- get_device ()
84
- {
85
- return g::device;
25
+ OpenAL_fin();
86
26
  }
87
27
 
88
-
89
28
  uint
90
29
  sampling_rate ()
91
30
  {
@@ -1,9 +1,6 @@
1
1
  #include "beeps/exception.h"
2
2
 
3
3
 
4
- #include <xot/string.h>
5
-
6
-
7
4
  namespace Beeps
8
5
  {
9
6
 
@@ -1,221 +1,110 @@
1
- #include "beeps/openal.h"
2
-
3
-
4
- #include <vector>
5
- #include <xot/debug.h>
6
- #include "beeps/defs.h"
7
- #include "beeps/sound.h"
8
- #include "beeps/exception.h"
9
1
  #include "openal.h"
10
2
 
11
3
 
12
- #if 0
13
- #define LOG(...) doutln(__VA_ARGS__)
14
- #else
15
- #define LOG(...)
16
- #endif
4
+ #include "beeps/exception.h"
5
+ #include "beeps/debug.h"
6
+ #include "sound.h"
17
7
 
18
8
 
19
9
  namespace Beeps
20
10
  {
21
11
 
22
12
 
23
- ALCdevice* get_device ();
24
-
25
-
26
- ALCenum
27
- get_error ()
28
- {
29
- return alcGetError(get_device());
30
- }
31
-
32
- bool
33
- no_error ()
13
+ namespace global
34
14
  {
35
- return get_error() == ALC_NO_ERROR;
36
- }
37
15
 
38
- bool
39
- is_error (ALCenum err)
40
- {
41
- return get_error() == err;
42
- }
43
-
44
- static String
45
- get_error_name (ALenum error)
46
- {
47
- switch (error)
48
- {
49
- case ALC_NO_ERROR: return "ALC_NO_ERROR";
50
- case ALC_INVALID_DEVICE: return "ALC_INVALID_DEVICE";
51
- case ALC_INVALID_CONTEXT: return "ALC_INVALID_CONTEXT";
52
- case ALC_INVALID_ENUM: return "ALC_INVALID_ENUM";
53
- case ALC_OUT_OF_MEMORY: return "ALC_OUT_OF_MEMORY";
54
- }
55
- return "UNKNOWN ERROR";
56
- }
16
+ static ALCdevice* device = NULL;
57
17
 
58
- void
59
- check_error (const char* file, int line)
60
- {
61
- ALCenum e = get_error();
62
- if (e != ALC_NO_ERROR)
63
- openal_error(file, line, "OpenAL error %s", get_error_name(e).c_str());
64
- }
18
+ static ALCcontext* context = NULL;
65
19
 
66
- void
67
- clear_error ()
68
- {
69
- get_error();
70
- }
20
+ }// global
71
21
 
72
22
 
73
- struct SoundSource
23
+ static void
24
+ cleanup ()
74
25
  {
26
+ Sound_cleanup_sources();
75
27
 
76
- typedef SoundSource This;
77
-
78
- typedef boost::shared_ptr<This> Ptr;
79
-
80
- ALint id;
28
+ alcMakeContextCurrent(NULL);
81
29
 
82
- static Ptr create ()
30
+ if (global::context)
83
31
  {
84
- ALuint id_;
85
- alGenSources(1, &id_);
86
- if (!no_error()) return Ptr();
87
-
88
- This* p = new This;
89
- p->id = id_;
90
- return Ptr(p);
32
+ alcDestroyContext(global::context);
33
+ global::context = NULL;
91
34
  }
92
35
 
93
- SoundSource ()
94
- : id(-1)
36
+ if (global::device)
95
37
  {
38
+ alcCloseDevice(global::device);
39
+ global::device = NULL;
96
40
  }
41
+ }
97
42
 
98
- ~SoundSource ()
99
- {
100
- if (!*this) return;
101
-
102
- ALuint id_ = id;
103
- alDeleteSources(1, &id_);
104
- check_error(__FILE__, __LINE__);
105
- }
106
-
107
- void play (const Sound& sound)
108
- {
109
- if (!sound)
110
- argument_error(__FILE__, __LINE__);
111
-
112
- if (!*this)
113
- invalid_state_error(__FILE__, __LINE__);
114
-
115
- alSourcei(id, AL_BUFFER, get_sound_buffer_id(sound));
116
- alSourcePlay(id);
117
- check_error(__FILE__, __LINE__);
118
- }
119
-
120
- void stop ()
121
- {
122
- if (!*this)
123
- invalid_state_error(__FILE__, __LINE__);
124
-
125
- alSourceStop(id);
126
- check_error(__FILE__, __LINE__);
127
- }
43
+ void
44
+ OpenAL_init ()
45
+ {
46
+ if (global::device || global::context)
47
+ beeps_error(__FILE__, __LINE__, "already initialized.");
128
48
 
129
- bool is_playing () const
130
- {
131
- if (!*this) return false;
49
+ global::device = alcOpenDevice(NULL);
50
+ if (!global::device) goto FAILED;
132
51
 
133
- ALint state = 0;
134
- alGetSourcei(id, AL_SOURCE_STATE, &state);
135
- check_error(__FILE__, __LINE__);
52
+ global::context = alcCreateContext(global::device, NULL);
53
+ if (!global::context) goto FAILED;
136
54
 
137
- return state == AL_PLAYING;
138
- }
55
+ if (!alcMakeContextCurrent(global::context))
56
+ goto FAILED;
139
57
 
140
- operator bool () const
141
- {
142
- return id >= 0;
143
- }
58
+ return;
144
59
 
145
- bool operator ! () const
146
- {
147
- return !operator bool();
148
- }
149
-
150
- };// SoundSource
60
+ FAILED:
61
+ cleanup();
62
+ openal_error(__FILE__, __LINE__, "failed to initialize OpenAL.");
63
+ }
151
64
 
65
+ void
66
+ OpenAL_fin ()
67
+ {
68
+ if (!global::context)
69
+ beeps_error(__FILE__, __LINE__, "not initialized.");
152
70
 
153
- typedef std::vector<SoundSource::Ptr> SoundSourceList;
71
+ cleanup();
72
+ }
154
73
 
155
- static SoundSourceList sources;
74
+ ALCenum
75
+ OpenAL_get_error ()
76
+ {
77
+ assert(global::device);
156
78
 
79
+ return alcGetError(global::device);
80
+ }
157
81
 
158
- void
159
- cleanup_sources ()
82
+ bool
83
+ OpenAL_no_error ()
160
84
  {
161
- sources.clear();
85
+ return OpenAL_get_error() == ALC_NO_ERROR;
162
86
  }
163
87
 
164
- static SoundSource*
165
- next_source ()
88
+ static String
89
+ get_error_name (ALenum error)
166
90
  {
167
- SoundSource::Ptr source;
168
- for (SoundSourceList::iterator it = sources.begin(); it != sources.end(); ++it)
169
- {
170
- const SoundSource::Ptr& p = *it;
171
- if (p && *p && !p->is_playing())
172
- {
173
- source = p;
174
- sources.erase(it);
175
- LOG("reuse source");
176
- break;
177
- }
178
- }
179
-
180
- if (!source)
181
- {
182
- source = SoundSource::create();
183
- LOG("new source");
184
- }
185
-
186
- if (!source)
91
+ switch (error)
187
92
  {
188
- source = *sources.begin();
189
- if (source) source->stop();
190
- sources.erase(sources.begin());
191
- LOG("stop and reuse oldest source");
93
+ case ALC_NO_ERROR: return "ALC_NO_ERROR";
94
+ case ALC_INVALID_DEVICE: return "ALC_INVALID_DEVICE";
95
+ case ALC_INVALID_CONTEXT: return "ALC_INVALID_CONTEXT";
96
+ case ALC_INVALID_ENUM: return "ALC_INVALID_ENUM";
97
+ case ALC_OUT_OF_MEMORY: return "ALC_OUT_OF_MEMORY";
98
+ default: return "UNKNOWN ERROR";
192
99
  }
193
-
194
- if (!source)
195
- return NULL;
196
-
197
- sources.push_back(source);
198
- return source.get();
199
100
  }
200
101
 
201
102
  void
202
- play_sound (const Sound& sound)
103
+ OpenAL_check_error (const char* file, int line)
203
104
  {
204
- if (!sound)
205
- argument_error(__FILE__, __LINE__);
206
-
207
- SoundSource* source = next_source();
208
- if (!source || !*source)
209
- invalid_state_error(__FILE__, __LINE__);
210
-
211
- source->play(sound);
212
-
213
- #if 0
214
- std::string ox = "";
215
- for (size_t i = 0; i < sources.size(); ++i)
216
- ox += sources[i]->is_playing() ? 'o' : 'x';
217
- LOG("playing with %d sources. (%s)", sources.size(), ox.c_str());
218
- #endif
105
+ ALCenum e = OpenAL_get_error();
106
+ if (e != ALC_NO_ERROR)
107
+ openal_error(file, line, "OpenAL error %s", get_error_name(e).c_str());
219
108
  }
220
109
 
221
110