beeps 0.1.10

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 (69) hide show
  1. checksums.yaml +7 -0
  2. data/.doc/ext/beeps/beeps.cpp +46 -0
  3. data/.doc/ext/beeps/file_in.cpp +59 -0
  4. data/.doc/ext/beeps/native.cpp +41 -0
  5. data/.doc/ext/beeps/processor.cpp +49 -0
  6. data/.doc/ext/beeps/sawtooth_wave.cpp +66 -0
  7. data/.doc/ext/beeps/sine_wave.cpp +66 -0
  8. data/.doc/ext/beeps/sound.cpp +69 -0
  9. data/.doc/ext/beeps/square_wave.cpp +66 -0
  10. data/README.md +4 -0
  11. data/Rakefile +27 -0
  12. data/VERSION +1 -0
  13. data/beeps.gemspec +43 -0
  14. data/ext/beeps/beeps.cpp +48 -0
  15. data/ext/beeps/defs.h +13 -0
  16. data/ext/beeps/extconf.rb +25 -0
  17. data/ext/beeps/file_in.cpp +61 -0
  18. data/ext/beeps/native.cpp +41 -0
  19. data/ext/beeps/processor.cpp +50 -0
  20. data/ext/beeps/sawtooth_wave.cpp +69 -0
  21. data/ext/beeps/sine_wave.cpp +69 -0
  22. data/ext/beeps/sound.cpp +72 -0
  23. data/ext/beeps/square_wave.cpp +69 -0
  24. data/include/beeps.h +12 -0
  25. data/include/beeps/beeps.h +25 -0
  26. data/include/beeps/defs.h +23 -0
  27. data/include/beeps/exception.h +47 -0
  28. data/include/beeps/openal.h +34 -0
  29. data/include/beeps/processor.h +132 -0
  30. data/include/beeps/ruby.h +10 -0
  31. data/include/beeps/ruby/beeps.h +21 -0
  32. data/include/beeps/ruby/processor.h +86 -0
  33. data/include/beeps/ruby/sound.h +42 -0
  34. data/include/beeps/signals.h +53 -0
  35. data/include/beeps/sound.h +44 -0
  36. data/lib/beeps.rb +9 -0
  37. data/lib/beeps/autoinit.rb +10 -0
  38. data/lib/beeps/beeps.rb +49 -0
  39. data/lib/beeps/ext.rb +4 -0
  40. data/lib/beeps/module.rb +49 -0
  41. data/lib/beeps/processor.rb +60 -0
  42. data/lib/beeps/sound.rb +19 -0
  43. data/src/beeps.cpp +93 -0
  44. data/src/exception.cpp +43 -0
  45. data/src/openal.cpp +216 -0
  46. data/src/openal.h +25 -0
  47. data/src/processor.cpp +201 -0
  48. data/src/signals.cpp +90 -0
  49. data/src/sound.cpp +125 -0
  50. data/src/stk/include/Blit.h +151 -0
  51. data/src/stk/include/BlitSaw.h +148 -0
  52. data/src/stk/include/BlitSquare.h +170 -0
  53. data/src/stk/include/FileRead.h +141 -0
  54. data/src/stk/include/FileWvIn.h +195 -0
  55. data/src/stk/include/Generator.h +50 -0
  56. data/src/stk/include/SineWave.h +159 -0
  57. data/src/stk/include/Stk.h +589 -0
  58. data/src/stk/include/WvIn.h +46 -0
  59. data/src/stk/src/Blit.cpp +78 -0
  60. data/src/stk/src/BlitSaw.cpp +91 -0
  61. data/src/stk/src/BlitSquare.cpp +95 -0
  62. data/src/stk/src/FileRead.cpp +903 -0
  63. data/src/stk/src/FileWvIn.cpp +260 -0
  64. data/src/stk/src/SineWave.cpp +78 -0
  65. data/src/stk/src/Stk.cpp +395 -0
  66. data/test/helper.rb +17 -0
  67. data/test/test_beeps.rb +18 -0
  68. data/test/test_sound.rb +26 -0
  69. metadata +177 -0
@@ -0,0 +1,86 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __BEEPS_RUBY_PROCESSOR_H__
4
+ #define __BEEPS_RUBY_PROCESSOR_H__
5
+
6
+
7
+ #include <rucy/rucy.h>
8
+ #include <rucy/class.h>
9
+ #include <rucy/extension.h>
10
+ #include <rucy/exception.h>
11
+ #include <beeps/processor.h>
12
+
13
+
14
+ namespace Beeps
15
+ {
16
+
17
+
18
+ Rucy::Class processor_class ();
19
+ // class Beeps::Processor
20
+
21
+ Rucy::Class sine_wave_class ();
22
+ // class Beeps::SineWave
23
+
24
+ Rucy::Class square_wave_class ();
25
+ // class Beeps::SineWave
26
+
27
+ Rucy::Class sawtooth_wave_class ();
28
+ // class Beeps::SawtoothWave
29
+
30
+ Rucy::Class file_in_class ();
31
+ // class Beeps::FileIn
32
+
33
+
34
+ }// Beeps
35
+
36
+
37
+ RUCY_DECLARE_VALUE_FROM_TO(Beeps::Processor)
38
+
39
+ RUCY_DECLARE_VALUE_FROM_TO(Beeps::SineWave)
40
+
41
+ RUCY_DECLARE_VALUE_FROM_TO(Beeps::SquareWave)
42
+
43
+ RUCY_DECLARE_VALUE_FROM_TO(Beeps::SawtoothWave)
44
+
45
+ RUCY_DECLARE_VALUE_FROM_TO(Beeps::FileIn)
46
+
47
+
48
+ namespace Rucy
49
+ {
50
+
51
+
52
+ template <> inline Class
53
+ get_ruby_class<Beeps::Processor> ()
54
+ {
55
+ return Beeps::processor_class();
56
+ }
57
+
58
+ template <> inline Class
59
+ get_ruby_class<Beeps::SineWave> ()
60
+ {
61
+ return Beeps::sine_wave_class();
62
+ }
63
+
64
+ template <> inline Class
65
+ get_ruby_class<Beeps::SquareWave> ()
66
+ {
67
+ return Beeps::square_wave_class();
68
+ }
69
+
70
+ template <> inline Class
71
+ get_ruby_class<Beeps::SawtoothWave> ()
72
+ {
73
+ return Beeps::sawtooth_wave_class();
74
+ }
75
+
76
+ template <> inline Class
77
+ get_ruby_class<Beeps::FileIn> ()
78
+ {
79
+ return Beeps::file_in_class();
80
+ }
81
+
82
+
83
+ }// Rucy
84
+
85
+
86
+ #endif//EOH
@@ -0,0 +1,42 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __BEEPS_RUBY_SOUND_H__
4
+ #define __BEEPS_RUBY_SOUND_H__
5
+
6
+
7
+ #include <rucy/rucy.h>
8
+ #include <rucy/class.h>
9
+ #include <rucy/extension.h>
10
+ #include <rucy/exception.h>
11
+ #include <beeps/sound.h>
12
+
13
+
14
+ namespace Beeps
15
+ {
16
+
17
+
18
+ Rucy::Class sound_class ();
19
+ // class Beeps::Sound
20
+
21
+
22
+ }// Beeps
23
+
24
+
25
+ RUCY_DECLARE_VALUE_FROM_TO(Beeps::Sound)
26
+
27
+
28
+ namespace Rucy
29
+ {
30
+
31
+
32
+ template <> inline Class
33
+ get_ruby_class<Beeps::Sound> ()
34
+ {
35
+ return Beeps::sound_class();
36
+ }
37
+
38
+
39
+ }// Rucy
40
+
41
+
42
+ #endif//EOH
@@ -0,0 +1,53 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __BEEPS_SIGNALS_H__
4
+ #define __BEEPS_SIGNALS_H__
5
+
6
+
7
+ #include <xot/pimpl.h>
8
+ #include <beeps/defs.h>
9
+
10
+
11
+ namespace stk {class StkFrames;};
12
+
13
+
14
+ namespace Beeps
15
+ {
16
+
17
+
18
+ class Signals
19
+ {
20
+
21
+ public:
22
+
23
+ Signals (float seconds = 1, uint channels = 1);
24
+
25
+ ~Signals ();
26
+
27
+ Signals copy () const;
28
+
29
+ float seconds () const;
30
+
31
+ uint samples () const;
32
+
33
+ uint channels () const;
34
+
35
+ stk::StkFrames* frames ();
36
+
37
+ const stk::StkFrames* frames () const;
38
+
39
+ operator bool () const;
40
+
41
+ bool operator ! () const;
42
+
43
+ struct Data;
44
+
45
+ Xot::PImpl<Data, true> self;
46
+
47
+ };// Signals
48
+
49
+
50
+ }// Beeps
51
+
52
+
53
+ #endif//EOH
@@ -0,0 +1,44 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __BEEPS_SOUND_H__
4
+ #define __BEEPS_SOUND_H__
5
+
6
+
7
+ #include <xot/pimpl.h>
8
+
9
+
10
+ namespace Beeps
11
+ {
12
+
13
+
14
+ class Processor;
15
+
16
+
17
+ class Sound
18
+ {
19
+
20
+ public:
21
+
22
+ Sound ();
23
+
24
+ Sound (Processor* processor, float seconds);
25
+
26
+ ~Sound ();
27
+
28
+ void play ();
29
+
30
+ operator bool () const;
31
+
32
+ bool operator ! () const;
33
+
34
+ struct Data;
35
+
36
+ Xot::PImpl<Data, true> self;
37
+
38
+ };// Sound
39
+
40
+
41
+ }// Beeps
42
+
43
+
44
+ #endif//EOH
data/lib/beeps.rb ADDED
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'beeps/autoinit'
5
+ require 'beeps/module'
6
+
7
+ require 'beeps/beeps'
8
+ require 'beeps/processor'
9
+ require 'beeps/sound'
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'beeps/ext'
5
+
6
+
7
+ unless $BEEPS_NOAUTOINIT
8
+ Beeps.init!
9
+ at_exit {Beeps.fin!}
10
+ end
@@ -0,0 +1,49 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'beeps/ext'
5
+ require 'beeps/sound'
6
+ require 'beeps/processor'
7
+
8
+
9
+ module Beeps
10
+
11
+
12
+ extend module ClassMethods
13
+
14
+ def be ()
15
+ beep_sound(0.1).play
16
+ end
17
+
18
+ def bee ()
19
+ beep_sound(0.3).play
20
+ end
21
+
22
+ def beep (time = 0.5)
23
+ beep_sound(time).play
24
+ end
25
+
26
+ def beeep ()
27
+ beep_sound(1).play
28
+ end
29
+
30
+ def beeeep ()
31
+ beep_sound(1.5).play
32
+ end
33
+
34
+ def beeeeep ()
35
+ beep_sound(2).play
36
+ end
37
+
38
+ private
39
+
40
+ def beep_sound (time)
41
+ Sound.new SquareWave.new, time
42
+ end
43
+
44
+ self
45
+
46
+ end# ClassMethods
47
+
48
+
49
+ end# Beeps
data/lib/beeps/ext.rb ADDED
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'beeps/native'
@@ -0,0 +1,49 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ module Beeps
5
+
6
+
7
+ module Module
8
+
9
+ def name ()
10
+ super.split('::')[-2]
11
+ end
12
+
13
+ def version ()
14
+ open(root_dir 'VERSION') {|f| f.readline.chomp}
15
+ end
16
+
17
+ def root_dir (path = '')
18
+ File.expand_path "../../../#{path}", __FILE__
19
+ end
20
+
21
+ def include_dir ()
22
+ root_dir 'include'
23
+ end
24
+
25
+ def lib_dir ()
26
+ root_dir 'lib'
27
+ end
28
+
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
+ end# Module
47
+
48
+
49
+ end# Beeps
@@ -0,0 +1,60 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'xot/setter'
5
+ require 'xot/block_util'
6
+ require 'beeps/ext'
7
+
8
+
9
+ module Beeps
10
+
11
+
12
+ class SineWave
13
+
14
+ include Xot::Setter
15
+
16
+ alias freq= frequency=
17
+ alias freq frequency
18
+
19
+ def initialize (opts = {}, &block)
20
+ super()
21
+ set opts
22
+ Xot::BlockUtil.instance_eval_or_block_call self, &block if block
23
+ end
24
+
25
+ end# SineWave
26
+
27
+
28
+ class SquareWave
29
+
30
+ include Xot::Setter
31
+
32
+ alias freq= frequency=
33
+ alias freq frequency
34
+
35
+ def initialize (opts = {}, &block)
36
+ super()
37
+ set opts
38
+ Xot::BlockUtil.instance_eval_or_block_call self, &block if block
39
+ end
40
+
41
+ end# SquareWave
42
+
43
+
44
+ class SawtoothWave
45
+
46
+ include Xot::Setter
47
+
48
+ alias freq= frequency=
49
+ alias freq frequency
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
56
+
57
+ end# SawtoothWave
58
+
59
+
60
+ end# Beeps
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'beeps/ext'
5
+
6
+
7
+ module Beeps
8
+
9
+
10
+ class Sound
11
+
12
+ def self.load (path)
13
+ Sound.new FileIn.new(path), 1
14
+ end
15
+
16
+ end# Sound
17
+
18
+
19
+ end# Beeps
data/src/beeps.cpp ADDED
@@ -0,0 +1,93 @@
1
+ // -*- objc -*-
2
+ #include "beeps/beeps.h"
3
+
4
+
5
+ #include <stdlib.h>
6
+ #include "Stk.h"
7
+ #include "beeps/openal.h"
8
+ #include "beeps/exception.h"
9
+
10
+
11
+ namespace Beeps
12
+ {
13
+
14
+
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
+ alcMakeContextCurrent(NULL);
32
+
33
+ if (g::context)
34
+ {
35
+ alcDestroyContext(g::context);
36
+ g::context = NULL;
37
+ }
38
+
39
+ if (g::device)
40
+ {
41
+ alcCloseDevice(g::device);
42
+ g::device = NULL;
43
+ }
44
+ }
45
+
46
+ void
47
+ init ()
48
+ {
49
+ if (g::device || g::context)
50
+ beeps_error(__FILE__, __LINE__, "Beeps::init(): already initialized.");
51
+
52
+ stk::Stk::setSampleRate(44100);
53
+
54
+ g::device = alcOpenDevice(NULL);
55
+ if (!g::device) goto FAILED;
56
+
57
+ g::context = alcCreateContext(g::device, NULL);
58
+ if (!g::context) goto FAILED;
59
+
60
+ if (!alcMakeContextCurrent(g::context))
61
+ goto FAILED;
62
+
63
+ return;
64
+
65
+ FAILED:
66
+ cleanup();
67
+ openal_error(__FILE__, __LINE__, "failed to setup OpenAL.");
68
+ }
69
+
70
+ void
71
+ fin ()
72
+ {
73
+ if (!g::context)
74
+ beeps_error(__FILE__, __LINE__, "Beeps::fin(): not initialized.");
75
+
76
+ cleanup();
77
+ }
78
+
79
+ ALCdevice*
80
+ get_device ()
81
+ {
82
+ return g::device;
83
+ }
84
+
85
+
86
+ uint
87
+ sampling_rate ()
88
+ {
89
+ return stk::Stk::sampleRate();
90
+ }
91
+
92
+
93
+ }// Beeps