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
@@ -4,19 +4,30 @@
4
4
  #define __BEEPS_SRC_OPENAL_H__
5
5
 
6
6
 
7
- #include <beeps/openal.h>
7
+ #if defined(OSX) || defined(IOS)
8
+ #include <OpenAL/al.h>
9
+ #include <OpenAL/alc.h>
10
+ #else
11
+ #include <AL/al.h>
12
+ #include <AL/alc.h>
13
+ #endif
14
+
15
+ #include <beeps/defs.h>
8
16
 
9
17
 
10
18
  namespace Beeps
11
19
  {
12
20
 
13
21
 
14
- class Sound;
22
+ void OpenAL_init ();
23
+
24
+ void OpenAL_fin ();
15
25
 
26
+ ALCenum OpenAL_get_error();
16
27
 
17
- void play_sound (const Sound& sound);
28
+ bool OpenAL_no_error();
18
29
 
19
- ALuint get_sound_buffer_id (const Sound& sound);
30
+ void OpenAL_check_error(const char* file, int line);
20
31
 
21
32
 
22
33
  }// Beeps
@@ -5,8 +5,8 @@
5
5
  #include "BlitSaw.h"
6
6
  #include "BlitSquare.h"
7
7
  #include "FileWvIn.h"
8
- #include "beeps/signals.h"
9
8
  #include "beeps/exception.h"
9
+ #include "signals.h"
10
10
 
11
11
 
12
12
  namespace Beeps
@@ -80,7 +80,7 @@ namespace Beeps
80
80
  {
81
81
  Super::process(signals);
82
82
 
83
- self->oscillator.tick(*signals->frames());
83
+ self->oscillator.tick(*Signals_get_frames(signals));
84
84
  }
85
85
 
86
86
 
@@ -121,7 +121,7 @@ namespace Beeps
121
121
  {
122
122
  Super::process(signals);
123
123
 
124
- self->oscillator.tick(*signals->frames());
124
+ self->oscillator.tick(*Signals_get_frames(signals));
125
125
  }
126
126
 
127
127
 
@@ -162,7 +162,7 @@ namespace Beeps
162
162
  {
163
163
  Super::process(signals);
164
164
 
165
- self->oscillator.tick(*signals->frames());
165
+ self->oscillator.tick(*Signals_get_frames(signals));
166
166
  }
167
167
 
168
168
 
@@ -189,7 +189,7 @@ namespace Beeps
189
189
  {
190
190
  Super::process(signals);
191
191
 
192
- self->input.tick(*signals->frames());
192
+ self->input.tick(*Signals_get_frames(signals));
193
193
  }
194
194
 
195
195
  FileIn::operator bool () const
@@ -1,8 +1,7 @@
1
- #include "beeps/signals.h"
1
+ #include "signals.h"
2
2
 
3
3
 
4
- #include <boost/scoped_ptr.hpp>
5
- #include "Stk.h"
4
+ #include <memory>
6
5
  #include "beeps/beeps.h"
7
6
  #include "beeps/exception.h"
8
7
 
@@ -14,11 +13,27 @@ namespace Beeps
14
13
  struct Signals::Data
15
14
  {
16
15
 
17
- boost::scoped_ptr<stk::StkFrames> frames;
16
+ std::unique_ptr<stk::StkFrames> frames;
18
17
 
19
18
  };// Signals::Data
20
19
 
21
20
 
21
+ stk::StkFrames*
22
+ Signals_get_frames (Signals* signals)
23
+ {
24
+ if (!signals)
25
+ argument_error(__FILE__, __LINE__);
26
+
27
+ return signals->self->frames.get();
28
+ }
29
+
30
+ const stk::StkFrames*
31
+ Signals_get_frames (const Signals* signals)
32
+ {
33
+ return Signals_get_frames(const_cast<Signals*>(signals));
34
+ }
35
+
36
+
22
37
  Signals::Signals (float seconds, uint channels)
23
38
  {
24
39
  if (seconds <= 0 || channels <= 0)
@@ -32,7 +47,7 @@ namespace Beeps
32
47
  }
33
48
 
34
49
  Signals
35
- Signals::copy () const
50
+ Signals::dup () const
36
51
  {
37
52
  Signals t;
38
53
  if (self->frames)
@@ -61,22 +76,9 @@ namespace Beeps
61
76
  return p ? p->frames->channels() : 0;
62
77
  }
63
78
 
64
- stk::StkFrames*
65
- Signals::frames ()
66
- {
67
- Data* p = self.get();
68
- return p ? p->frames.get() : NULL;
69
- }
70
-
71
- const stk::StkFrames*
72
- Signals::frames () const
73
- {
74
- return const_cast<Signals*>(this)->frames();
75
- }
76
-
77
79
  Signals::operator bool () const
78
80
  {
79
- const stk::StkFrames* f = frames();
81
+ const stk::StkFrames* f = Signals_get_frames(this);
80
82
  return f && f->frames() > 0 && f->channels() > 0;
81
83
  }
82
84
 
@@ -0,0 +1,23 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __BEEPS_SRC_SIGNALS_H__
4
+ #define __BEEPS_SRC_SIGNALS_H__
5
+
6
+
7
+ #include <Stk.h>
8
+ #include <beeps/signals.h>
9
+
10
+
11
+ namespace Beeps
12
+ {
13
+
14
+
15
+ stk::StkFrames* Signals_get_frames ( Signals* signals);
16
+
17
+ const stk::StkFrames* Signals_get_frames (const Signals* signals);
18
+
19
+
20
+ }// Beeps
21
+
22
+
23
+ #endif//EOH
@@ -3,17 +3,162 @@
3
3
 
4
4
  #include <limits.h>
5
5
  #include "Stk.h"
6
- #include "beeps/openal.h"
7
- #include "beeps/signals.h"
8
6
  #include "beeps/processor.h"
9
7
  #include "beeps/exception.h"
10
8
  #include "openal.h"
9
+ #include "signals.h"
10
+
11
+
12
+ #if 0
13
+ #define LOG(...) doutln(__VA_ARGS__)
14
+ #else
15
+ #define LOG(...)
16
+ #endif
11
17
 
12
18
 
13
19
  namespace Beeps
14
20
  {
15
21
 
16
22
 
23
+ static ALuint get_buffer_id (const Sound& sound);
24
+
25
+
26
+ struct SoundSource
27
+ {
28
+
29
+ typedef SoundSource This;
30
+
31
+ typedef std::shared_ptr<This> Ptr;
32
+
33
+ ALint id;
34
+
35
+ static Ptr create ()
36
+ {
37
+ ALuint id_;
38
+ alGenSources(1, &id_);
39
+ if (!OpenAL_no_error()) return Ptr();
40
+
41
+ return Ptr(new This(id_));
42
+ }
43
+
44
+ ~SoundSource ()
45
+ {
46
+ if (!*this) return;
47
+
48
+ ALuint id_ = id;
49
+ alDeleteSources(1, &id_);
50
+ OpenAL_check_error(__FILE__, __LINE__);
51
+ }
52
+
53
+ void play (const Sound& sound)
54
+ {
55
+ assert(sound);
56
+
57
+ if (!*this)
58
+ invalid_state_error(__FILE__, __LINE__);
59
+
60
+ alSourcei(id, AL_BUFFER, get_buffer_id(sound));
61
+ alSourcePlay(id);
62
+ OpenAL_check_error(__FILE__, __LINE__);
63
+ }
64
+
65
+ void stop ()
66
+ {
67
+ if (!*this)
68
+ invalid_state_error(__FILE__, __LINE__);
69
+
70
+ alSourceStop(id);
71
+ OpenAL_check_error(__FILE__, __LINE__);
72
+ }
73
+
74
+ bool is_playing () const
75
+ {
76
+ if (!*this) return false;
77
+
78
+ ALint state = 0;
79
+ alGetSourcei(id, AL_SOURCE_STATE, &state);
80
+ OpenAL_check_error(__FILE__, __LINE__);
81
+
82
+ return state == AL_PLAYING;
83
+ }
84
+
85
+ operator bool () const
86
+ {
87
+ return id >= 0;
88
+ }
89
+
90
+ bool operator ! () const
91
+ {
92
+ return !operator bool();
93
+ }
94
+
95
+ private:
96
+
97
+ SoundSource (ALint id = -1)
98
+ : id(id)
99
+ {
100
+ }
101
+
102
+ };// SoundSource
103
+
104
+
105
+ typedef std::vector<SoundSource::Ptr> SoundSourceList;
106
+
107
+
108
+ namespace global
109
+ {
110
+
111
+ static SoundSourceList sources;
112
+
113
+ }// global
114
+
115
+
116
+ void
117
+ Sound_cleanup_sources ()
118
+ {
119
+ global::sources.clear();
120
+ }
121
+
122
+ static SoundSource*
123
+ get_next_source ()
124
+ {
125
+ SoundSource::Ptr source;
126
+
127
+ auto end = global::sources.end();
128
+ for (auto it = global::sources.begin(); it != end; ++it)
129
+ {
130
+ const SoundSource::Ptr& p = *it;
131
+ if (p && *p && !p->is_playing())
132
+ {
133
+ source = p;
134
+ global::sources.erase(it);
135
+ LOG("reuse source");
136
+ break;
137
+ }
138
+ }
139
+
140
+ if (!source)
141
+ {
142
+ source = SoundSource::create();
143
+ LOG("new source");
144
+ }
145
+
146
+ if (!source)
147
+ {
148
+ source = *global::sources.begin();
149
+ if (source) source->stop();
150
+ global::sources.erase(global::sources.begin());
151
+ LOG("stop and reuse oldest source");
152
+ }
153
+
154
+ if (!source)
155
+ return NULL;
156
+
157
+ global::sources.push_back(source);
158
+ return source.get();
159
+ }
160
+
161
+
17
162
  struct Sound::Data
18
163
  {
19
164
 
@@ -35,7 +180,7 @@ namespace Beeps
35
180
 
36
181
  ALuint id_ = 0;
37
182
  alGenBuffers(1, &id_);
38
- check_error(__FILE__, __LINE__);
183
+ OpenAL_check_error(__FILE__, __LINE__);
39
184
 
40
185
  id = id_;
41
186
  }
@@ -46,7 +191,7 @@ namespace Beeps
46
191
  {
47
192
  ALuint id_ = id;
48
193
  alDeleteBuffers(1, &id_);
49
- check_error(__FILE__, __LINE__);
194
+ OpenAL_check_error(__FILE__, __LINE__);
50
195
  }
51
196
 
52
197
  id = -1;
@@ -60,6 +205,13 @@ namespace Beeps
60
205
  };// Sound::Data
61
206
 
62
207
 
208
+ ALuint
209
+ get_buffer_id (const Sound& sound)
210
+ {
211
+ return sound.self->id;
212
+ }
213
+
214
+
63
215
  Sound::Sound ()
64
216
  {
65
217
  }
@@ -74,7 +226,7 @@ namespace Beeps
74
226
  Signals signals(seconds, 1);
75
227
  processor->process(&signals);
76
228
 
77
- stk::StkFrames* frames = signals.frames();
229
+ stk::StkFrames* frames = Signals_get_frames(&signals);
78
230
  if (!frames)
79
231
  return;
80
232
 
@@ -90,7 +242,7 @@ namespace Beeps
90
242
  alBufferData(
91
243
  self->id, AL_FORMAT_MONO16, &buffer[0], sizeof(short) * size,
92
244
  frames->dataRate());
93
- check_error(__FILE__, __LINE__);
245
+ OpenAL_check_error(__FILE__, __LINE__);
94
246
  }
95
247
 
96
248
  Sound::~Sound ()
@@ -100,7 +252,21 @@ namespace Beeps
100
252
  void
101
253
  Sound::play ()
102
254
  {
103
- play_sound(*this);
255
+ if (!*this)
256
+ invalid_state_error(__FILE__, __LINE__);
257
+
258
+ SoundSource* source = get_next_source();
259
+ if (!source || !*source)
260
+ invalid_state_error(__FILE__, __LINE__);
261
+
262
+ source->play(*this);
263
+
264
+ #if 0
265
+ std::string ox = "";
266
+ for (size_t i = 0; i < global::sources.size(); ++i)
267
+ ox += global::sources[i]->is_playing() ? 'o' : 'x';
268
+ LOG("playing with %d sources. (%s)", global::sources.size(), ox.c_str());
269
+ #endif
104
270
  }
105
271
 
106
272
  Sound::operator bool () const
@@ -115,11 +281,4 @@ namespace Beeps
115
281
  }
116
282
 
117
283
 
118
- ALuint
119
- get_sound_buffer_id (const Sound& sound)
120
- {
121
- return sound.self->id;
122
- }
123
-
124
-
125
284
  }// Beeps
@@ -0,0 +1,17 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __BEEPS_SRC_SOUND_H__
4
+ #define __BEEPS_SRC_SOUND_H__
5
+
6
+
7
+ namespace Beeps
8
+ {
9
+
10
+
11
+ void Sound_cleanup_sources ();
12
+
13
+
14
+ }// Beeps
15
+
16
+
17
+ #endif//EOH
metadata CHANGED
@@ -1,77 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beeps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
- - snori
8
- autorequire:
7
+ - xordog
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-04 00:00:00.000000000 Z
11
+ date: 2020-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: xot
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - ">="
17
+ - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: '0'
19
+ version: '0.1'
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - ">="
24
+ - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '0.1'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rucy
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - ">="
31
+ - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
33
+ version: '0.1'
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ">="
38
+ - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: gemcutter
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
40
+ version: '0.1'
69
41
  description: Synthesize and play beep sounds.
70
- email: snori@xord.org
42
+ email: xordog@gmail.com
71
43
  executables: []
72
44
  extensions:
73
45
  - Rakefile
74
46
  extra_rdoc_files:
47
+ - ".doc/ext/beeps/sawtooth_wave.cpp"
48
+ - ".doc/ext/beeps/processor.cpp"
49
+ - ".doc/ext/beeps/square_wave.cpp"
50
+ - ".doc/ext/beeps/file_in.cpp"
51
+ - ".doc/ext/beeps/native.cpp"
52
+ - ".doc/ext/beeps/sine_wave.cpp"
53
+ - ".doc/ext/beeps/sound.cpp"
54
+ - ".doc/ext/beeps/beeps.cpp"
55
+ files:
75
56
  - ".doc/ext/beeps/beeps.cpp"
76
57
  - ".doc/ext/beeps/file_in.cpp"
77
58
  - ".doc/ext/beeps/native.cpp"
@@ -80,7 +61,6 @@ extra_rdoc_files:
80
61
  - ".doc/ext/beeps/sine_wave.cpp"
81
62
  - ".doc/ext/beeps/sound.cpp"
82
63
  - ".doc/ext/beeps/square_wave.cpp"
83
- files:
84
64
  - README.md
85
65
  - Rakefile
86
66
  - VERSION
@@ -97,9 +77,9 @@ files:
97
77
  - ext/beeps/square_wave.cpp
98
78
  - include/beeps.h
99
79
  - include/beeps/beeps.h
80
+ - include/beeps/debug.h
100
81
  - include/beeps/defs.h
101
82
  - include/beeps/exception.h
102
- - include/beeps/openal.h
103
83
  - include/beeps/processor.h
104
84
  - include/beeps/ruby.h
105
85
  - include/beeps/ruby/beeps.h
@@ -120,55 +100,32 @@ files:
120
100
  - src/openal.h
121
101
  - src/processor.cpp
122
102
  - src/signals.cpp
103
+ - src/signals.h
123
104
  - src/sound.cpp
124
- - src/stk/include/Blit.h
125
- - src/stk/include/BlitSaw.h
126
- - src/stk/include/BlitSquare.h
127
- - src/stk/include/FileRead.h
128
- - src/stk/include/FileWvIn.h
129
- - src/stk/include/Generator.h
130
- - src/stk/include/SineWave.h
131
- - src/stk/include/Stk.h
132
- - src/stk/include/WvIn.h
133
- - src/stk/src/Blit.cpp
134
- - src/stk/src/BlitSaw.cpp
135
- - src/stk/src/BlitSquare.cpp
136
- - src/stk/src/FileRead.cpp
137
- - src/stk/src/FileWvIn.cpp
138
- - src/stk/src/SineWave.cpp
139
- - src/stk/src/Stk.cpp
105
+ - src/sound.h
140
106
  - test/helper.rb
141
107
  - test/test_beeps.rb
142
108
  - test/test_sound.rb
143
- - ".doc/ext/beeps/beeps.cpp"
144
- - ".doc/ext/beeps/file_in.cpp"
145
- - ".doc/ext/beeps/native.cpp"
146
- - ".doc/ext/beeps/processor.cpp"
147
- - ".doc/ext/beeps/sawtooth_wave.cpp"
148
- - ".doc/ext/beeps/sine_wave.cpp"
149
- - ".doc/ext/beeps/sound.cpp"
150
- - ".doc/ext/beeps/square_wave.cpp"
151
109
  homepage: https://github.com/xord/beeps
152
110
  licenses: []
153
111
  metadata: {}
154
- post_install_message:
112
+ post_install_message:
155
113
  rdoc_options: []
156
114
  require_paths:
157
115
  - lib
158
116
  required_ruby_version: !ruby/object:Gem::Requirement
159
117
  requirements:
160
- - - ">="
118
+ - - "~>"
161
119
  - !ruby/object:Gem::Version
162
- version: 1.9.0
120
+ version: '2'
163
121
  required_rubygems_version: !ruby/object:Gem::Requirement
164
122
  requirements:
165
123
  - - ">="
166
124
  - !ruby/object:Gem::Version
167
125
  version: '0'
168
126
  requirements: []
169
- rubyforge_project:
170
- rubygems_version: 2.0.3
171
- signing_key:
127
+ rubygems_version: 3.0.3
128
+ signing_key:
172
129
  specification_version: 4
173
130
  summary: Plays beep sound.
174
131
  test_files: