native_audio 0.1.0 → 0.2.0

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 (147) hide show
  1. checksums.yaml +4 -4
  2. data/assets/include/GL/glew.h +26427 -26427
  3. data/assets/include/GLES2/gl2.h +656 -656
  4. data/assets/include/GLES2/gl2ext.h +3949 -3949
  5. data/assets/include/GLES2/gl2ext_angle.h +701 -701
  6. data/assets/include/GLES2/gl2platform.h +27 -27
  7. data/assets/include/GLES3/gl3.h +1192 -1192
  8. data/assets/include/GLES3/gl31.h +1507 -1507
  9. data/assets/include/GLES3/gl32.h +1808 -1808
  10. data/assets/include/GLES3/gl3platform.h +27 -27
  11. data/assets/include/KHR/khrplatform.h +290 -290
  12. data/assets/include/SDL2/SDL.h +233 -233
  13. data/assets/include/SDL2/SDL_assert.h +326 -326
  14. data/assets/include/SDL2/SDL_atomic.h +415 -415
  15. data/assets/include/SDL2/SDL_audio.h +1500 -1500
  16. data/assets/include/SDL2/SDL_bits.h +126 -126
  17. data/assets/include/SDL2/SDL_blendmode.h +198 -198
  18. data/assets/include/SDL2/SDL_clipboard.h +141 -141
  19. data/assets/include/SDL2/SDL_config.h +61 -61
  20. data/assets/include/SDL2/SDL_config_android.h +194 -194
  21. data/assets/include/SDL2/SDL_config_emscripten.h +218 -218
  22. data/assets/include/SDL2/SDL_config_iphoneos.h +217 -217
  23. data/assets/include/SDL2/SDL_config_macosx.h +277 -277
  24. data/assets/include/SDL2/SDL_config_minimal.h +95 -95
  25. data/assets/include/SDL2/SDL_config_ngage.h +89 -89
  26. data/assets/include/SDL2/SDL_config_os2.h +207 -207
  27. data/assets/include/SDL2/SDL_config_pandora.h +141 -141
  28. data/assets/include/SDL2/SDL_config_windows.h +331 -331
  29. data/assets/include/SDL2/SDL_config_wingdk.h +253 -253
  30. data/assets/include/SDL2/SDL_config_winrt.h +220 -220
  31. data/assets/include/SDL2/SDL_config_xbox.h +235 -235
  32. data/assets/include/SDL2/SDL_copying.h +20 -20
  33. data/assets/include/SDL2/SDL_cpuinfo.h +594 -594
  34. data/assets/include/SDL2/SDL_egl.h +2352 -2352
  35. data/assets/include/SDL2/SDL_endian.h +348 -348
  36. data/assets/include/SDL2/SDL_error.h +163 -163
  37. data/assets/include/SDL2/SDL_events.h +1166 -1166
  38. data/assets/include/SDL2/SDL_filesystem.h +149 -149
  39. data/assets/include/SDL2/SDL_gamecontroller.h +1074 -1074
  40. data/assets/include/SDL2/SDL_gesture.h +117 -117
  41. data/assets/include/SDL2/SDL_guid.h +100 -100
  42. data/assets/include/SDL2/SDL_haptic.h +1341 -1341
  43. data/assets/include/SDL2/SDL_hidapi.h +451 -451
  44. data/assets/include/SDL2/SDL_hints.h +2569 -2569
  45. data/assets/include/SDL2/SDL_image.h +2173 -2173
  46. data/assets/include/SDL2/SDL_joystick.h +1066 -1066
  47. data/assets/include/SDL2/SDL_keyboard.h +353 -353
  48. data/assets/include/SDL2/SDL_keycode.h +358 -358
  49. data/assets/include/SDL2/SDL_loadso.h +115 -115
  50. data/assets/include/SDL2/SDL_locale.h +103 -103
  51. data/assets/include/SDL2/SDL_log.h +404 -404
  52. data/assets/include/SDL2/SDL_main.h +275 -275
  53. data/assets/include/SDL2/SDL_messagebox.h +193 -193
  54. data/assets/include/SDL2/SDL_metal.h +113 -113
  55. data/assets/include/SDL2/SDL_misc.h +79 -79
  56. data/assets/include/SDL2/SDL_mixer.h +2784 -2784
  57. data/assets/include/SDL2/SDL_mouse.h +465 -465
  58. data/assets/include/SDL2/SDL_mutex.h +471 -471
  59. data/assets/include/SDL2/SDL_name.h +33 -33
  60. data/assets/include/SDL2/SDL_opengl.h +2132 -2132
  61. data/assets/include/SDL2/SDL_opengl_glext.h +13209 -13209
  62. data/assets/include/SDL2/SDL_opengles.h +39 -39
  63. data/assets/include/SDL2/SDL_opengles2.h +52 -52
  64. data/assets/include/SDL2/SDL_opengles2_gl2.h +656 -656
  65. data/assets/include/SDL2/SDL_opengles2_gl2ext.h +4033 -4033
  66. data/assets/include/SDL2/SDL_opengles2_gl2platform.h +27 -27
  67. data/assets/include/SDL2/SDL_opengles2_khrplatform.h +311 -311
  68. data/assets/include/SDL2/SDL_pixels.h +644 -644
  69. data/assets/include/SDL2/SDL_platform.h +261 -261
  70. data/assets/include/SDL2/SDL_power.h +88 -88
  71. data/assets/include/SDL2/SDL_quit.h +58 -58
  72. data/assets/include/SDL2/SDL_rect.h +376 -376
  73. data/assets/include/SDL2/SDL_render.h +1919 -1919
  74. data/assets/include/SDL2/SDL_revision.h +6 -6
  75. data/assets/include/SDL2/SDL_rwops.h +841 -841
  76. data/assets/include/SDL2/SDL_scancode.h +438 -438
  77. data/assets/include/SDL2/SDL_sensor.h +322 -322
  78. data/assets/include/SDL2/SDL_shape.h +155 -155
  79. data/assets/include/SDL2/SDL_stdinc.h +830 -830
  80. data/assets/include/SDL2/SDL_surface.h +997 -997
  81. data/assets/include/SDL2/SDL_system.h +623 -623
  82. data/assets/include/SDL2/SDL_syswm.h +386 -386
  83. data/assets/include/SDL2/SDL_test.h +69 -69
  84. data/assets/include/SDL2/SDL_test_assert.h +105 -105
  85. data/assets/include/SDL2/SDL_test_common.h +236 -236
  86. data/assets/include/SDL2/SDL_test_compare.h +69 -69
  87. data/assets/include/SDL2/SDL_test_crc32.h +124 -124
  88. data/assets/include/SDL2/SDL_test_font.h +168 -168
  89. data/assets/include/SDL2/SDL_test_fuzzer.h +386 -386
  90. data/assets/include/SDL2/SDL_test_harness.h +134 -134
  91. data/assets/include/SDL2/SDL_test_images.h +78 -78
  92. data/assets/include/SDL2/SDL_test_log.h +67 -67
  93. data/assets/include/SDL2/SDL_test_md5.h +129 -129
  94. data/assets/include/SDL2/SDL_test_memory.h +63 -63
  95. data/assets/include/SDL2/SDL_test_random.h +115 -115
  96. data/assets/include/SDL2/SDL_thread.h +464 -464
  97. data/assets/include/SDL2/SDL_timer.h +222 -222
  98. data/assets/include/SDL2/SDL_touch.h +150 -150
  99. data/assets/include/SDL2/SDL_ttf.h +2316 -2316
  100. data/assets/include/SDL2/SDL_types.h +29 -29
  101. data/assets/include/SDL2/SDL_version.h +204 -204
  102. data/assets/include/SDL2/SDL_video.h +2150 -2150
  103. data/assets/include/SDL2/SDL_vulkan.h +215 -215
  104. data/assets/include/SDL2/begin_code.h +187 -187
  105. data/assets/include/SDL2/close_code.h +40 -40
  106. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libFLAC.a +0 -0
  107. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2.a +0 -0
  108. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2_mixer.a +0 -0
  109. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libglew32.a +0 -0
  110. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libmodplug.a +0 -0
  111. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libmpg123.a +0 -0
  112. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libogg.a +0 -0
  113. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libopus.a +0 -0
  114. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libopusfile.a +0 -0
  115. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libsndfile.a +0 -0
  116. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libssp.a +1 -1
  117. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libstdc++.a +0 -0
  118. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libvorbis.a +0 -0
  119. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libvorbisfile.a +0 -0
  120. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libz.a +0 -0
  121. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libzstd.a +0 -0
  122. data/assets/windows/mingw-w64-x86_64/lib/libFLAC.a +0 -0
  123. data/assets/windows/mingw-w64-x86_64/lib/libSDL2.a +0 -0
  124. data/assets/windows/mingw-w64-x86_64/lib/libSDL2_mixer.a +0 -0
  125. data/assets/windows/mingw-w64-x86_64/lib/libglew32.a +0 -0
  126. data/assets/windows/mingw-w64-x86_64/lib/libmodplug.a +0 -0
  127. data/assets/windows/mingw-w64-x86_64/lib/libmpg123.a +0 -0
  128. data/assets/windows/mingw-w64-x86_64/lib/libogg.a +0 -0
  129. data/assets/windows/mingw-w64-x86_64/lib/libopus.a +0 -0
  130. data/assets/windows/mingw-w64-x86_64/lib/libopusfile.a +0 -0
  131. data/assets/windows/mingw-w64-x86_64/lib/libsndfile.a +0 -0
  132. data/assets/windows/mingw-w64-x86_64/lib/libssp.a +1 -1
  133. data/assets/windows/mingw-w64-x86_64/lib/libstdc++.a +0 -0
  134. data/assets/windows/mingw-w64-x86_64/lib/libvorbis.a +0 -0
  135. data/assets/windows/mingw-w64-x86_64/lib/libvorbisfile.a +0 -0
  136. data/assets/windows/mingw-w64-x86_64/lib/libz.a +0 -0
  137. data/assets/windows/mingw-w64-x86_64/lib/libzstd.a +0 -0
  138. data/ext/audio.c +80 -80
  139. data/ext/extconf.h +3 -3
  140. data/ext/extconf.rb +173 -177
  141. data/lib/audio.bundle +0 -0
  142. data/lib/audio.so +0 -0
  143. data/lib/native_audio.rb +50 -50
  144. metadata +4 -9
  145. data/ext/Makefile +0 -270
  146. data/ext/audio.o +0 -0
  147. data/ext/mkmf.log +0 -7
data/ext/audio.c CHANGED
@@ -1,80 +1,80 @@
1
- #include <ruby.h>
2
- #include "extconf.h"
3
- #include <SDL2/SDL.h>
4
- #include <SDL2/SDL_mixer.h>
5
-
6
- Mix_Chunk *sounds[1024];
7
- int sound_count = 0;
8
-
9
- VALUE audio_play(VALUE self, VALUE channel_id, VALUE clip)
10
- {
11
- Mix_Chunk *sound = sounds[NUM2INT(clip)];
12
- int channel = Mix_PlayChannel(NUM2INT(channel_id), sound, 0);
13
- return rb_int2inum(channel);
14
- }
15
-
16
- VALUE audio_load(VALUE self, VALUE file)
17
- {
18
- Mix_Chunk *sound = NULL;
19
- sound = Mix_LoadWAV(StringValueCStr(file));
20
- if(sound == NULL)
21
- {
22
- fprintf(stderr, "Unable to load WAV file: %s\n", Mix_GetError());
23
- }
24
-
25
- sounds[0] = sound;
26
- sound_count++;
27
-
28
- return rb_int2inum(sound_count - 1);
29
- }
30
-
31
- VALUE audio_set_pos(VALUE self, VALUE channel_id, VALUE angle, VALUE distance)
32
- {
33
- Mix_SetPosition(NUM2INT(channel_id), NUM2INT(angle), NUM2INT(distance));
34
- return Qnil;
35
- }
36
-
37
- VALUE audio_stop(VALUE self, VALUE channel_id)
38
- {
39
- Mix_HaltChannel(NUM2INT(channel_id));
40
- return Qnil;
41
- }
42
-
43
- VALUE audio_pause(VALUE self, VALUE channel_id)
44
- {
45
- Mix_Pause(NUM2INT(channel_id));
46
- return Qnil;
47
- }
48
-
49
- VALUE audio_resume(VALUE self, VALUE channel_id)
50
- {
51
- Mix_Resume(NUM2INT(channel_id));
52
- return Qnil;
53
- }
54
-
55
- VALUE audio_set_volume(VALUE self, VALUE channel_id, VALUE volume)
56
- {
57
- Mix_Volume(NUM2INT(channel_id), NUM2INT(volume));
58
- return Qnil;
59
- }
60
-
61
- void Init_audio()
62
- {
63
- if (SDL_Init(SDL_INIT_AUDIO) != 0) { exit(1); }
64
-
65
- int audio_rate = 22050;
66
- Uint16 audio_format = AUDIO_S16SYS;
67
- int audio_channels = 2;
68
- int audio_buffers = 4096;
69
-
70
- if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0) { exit(1); }
71
-
72
- VALUE mAudio = rb_define_module("Audio");
73
- rb_define_singleton_method(mAudio, "load", audio_load, 1);
74
- rb_define_singleton_method(mAudio, "play", audio_play, 2);
75
- rb_define_singleton_method(mAudio, "set_pos", audio_set_pos, 3);
76
- rb_define_singleton_method(mAudio, "stop", audio_stop, 1);
77
- rb_define_singleton_method(mAudio, "pause", audio_pause, 1);
78
- rb_define_singleton_method(mAudio, "resume", audio_resume, 1);
79
- rb_define_singleton_method(mAudio, "set_volume", audio_set_volume, 2);
80
- }
1
+ #include <ruby.h>
2
+ #include "extconf.h"
3
+ #include <SDL2/SDL.h>
4
+ #include <SDL2/SDL_mixer.h>
5
+
6
+ Mix_Chunk *sounds[1024];
7
+ int sound_count = 0;
8
+
9
+ VALUE audio_play(VALUE self, VALUE channel_id, VALUE clip)
10
+ {
11
+ Mix_Chunk *sound = sounds[NUM2INT(clip)];
12
+ int channel = Mix_PlayChannel(NUM2INT(channel_id), sound, 0);
13
+ return rb_int2inum(channel);
14
+ }
15
+
16
+ VALUE audio_load(VALUE self, VALUE file)
17
+ {
18
+ Mix_Chunk *sound = NULL;
19
+ sound = Mix_LoadWAV(StringValueCStr(file));
20
+ if(sound == NULL)
21
+ {
22
+ fprintf(stderr, "Unable to load WAV file: %s\n", Mix_GetError());
23
+ }
24
+
25
+ sounds[0] = sound;
26
+ sound_count++;
27
+
28
+ return rb_int2inum(sound_count - 1);
29
+ }
30
+
31
+ VALUE audio_set_pos(VALUE self, VALUE channel_id, VALUE angle, VALUE distance)
32
+ {
33
+ Mix_SetPosition(NUM2INT(channel_id), NUM2INT(angle), NUM2INT(distance));
34
+ return Qnil;
35
+ }
36
+
37
+ VALUE audio_stop(VALUE self, VALUE channel_id)
38
+ {
39
+ Mix_HaltChannel(NUM2INT(channel_id));
40
+ return Qnil;
41
+ }
42
+
43
+ VALUE audio_pause(VALUE self, VALUE channel_id)
44
+ {
45
+ Mix_Pause(NUM2INT(channel_id));
46
+ return Qnil;
47
+ }
48
+
49
+ VALUE audio_resume(VALUE self, VALUE channel_id)
50
+ {
51
+ Mix_Resume(NUM2INT(channel_id));
52
+ return Qnil;
53
+ }
54
+
55
+ VALUE audio_set_volume(VALUE self, VALUE channel_id, VALUE volume)
56
+ {
57
+ Mix_Volume(NUM2INT(channel_id), NUM2INT(volume));
58
+ return Qnil;
59
+ }
60
+
61
+ void Init_audio()
62
+ {
63
+ if (SDL_Init(SDL_INIT_AUDIO) != 0) { exit(1); }
64
+
65
+ int audio_rate = 22050;
66
+ Uint16 audio_format = AUDIO_S16SYS;
67
+ int audio_channels = 2;
68
+ int audio_buffers = 4096;
69
+
70
+ if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0) { exit(1); }
71
+
72
+ VALUE mAudio = rb_define_module("Audio");
73
+ rb_define_singleton_method(mAudio, "load", audio_load, 1);
74
+ rb_define_singleton_method(mAudio, "play", audio_play, 2);
75
+ rb_define_singleton_method(mAudio, "set_pos", audio_set_pos, 3);
76
+ rb_define_singleton_method(mAudio, "stop", audio_stop, 1);
77
+ rb_define_singleton_method(mAudio, "pause", audio_pause, 1);
78
+ rb_define_singleton_method(mAudio, "resume", audio_resume, 1);
79
+ rb_define_singleton_method(mAudio, "set_volume", audio_set_volume, 2);
80
+ }
data/ext/extconf.h CHANGED
@@ -1,3 +1,3 @@
1
- #ifndef EXTCONF_H
2
- #define EXTCONF_H
3
- #endif
1
+ #ifndef EXTCONF_H
2
+ #define EXTCONF_H
3
+ #endif
data/ext/extconf.rb CHANGED
@@ -1,177 +1,173 @@
1
-
2
- require 'mkmf'
3
-
4
- case RUBY_PLATFORM
5
- when /darwin/
6
- $PLATFORM = :macos
7
- when /linux/
8
- $PLATFORM = :linux
9
- if `cat /etc/os-release` =~ /raspbian/
10
- $PLATFORM = :linux_rpi
11
- end
12
- when /bsd/
13
- $PLATFORM = :bsd
14
- when /mingw/
15
- $PLATFORM = :windows
16
- else
17
- $PLATFORM = nil
18
- end
19
- $errors = [] # Holds errors
20
-
21
- # Helper functions #############################################################
22
-
23
- # Print installation errors
24
- def print_errors
25
- puts "
26
- #{"== #{"Ruby 2D Installation Errors".error} =======================================\n"}
27
- #{$errors.join("\n ")}\n
28
- #{"======================================================================"}"
29
- end
30
-
31
- # Add compiler and linker flags
32
- def add_flags(type, flags)
33
- case type
34
- when :c
35
- $CFLAGS << " #{flags} "
36
- when :ld
37
- $LDFLAGS << " #{flags} "
38
- end
39
- end
40
-
41
- # Check for SDL libraries
42
- def check_sdl
43
- unless have_library('SDL2') && have_library('SDL2_mixer')
44
-
45
- $errors << "Couldn't find packages needed."
46
-
47
- case $platform
48
- when :linux, :linux_rpi
49
- # Fedora and CentOS
50
- if system('which yum')
51
- $errors << "Install the following packages using `yum` (or `dnf`) and try again:\n" <<
52
- " SDL2-devel SDL2_mixer-devel".bold
53
-
54
- # Arch
55
- elsif system('which pacman')
56
- $errors << "Install the following packages using `pacman` and try again:\n" <<
57
- " sdl2 sdl2_mixer".bold
58
-
59
- # openSUSE
60
- elsif system('which zypper')
61
- $errors << "Install the following packages using `zypper` and try again:\n" <<
62
- " libSDL2-devel libSDL2_mixer-devel".bold
63
-
64
- # Ubuntu, Debian, and Mint
65
- # `apt` must be last because openSUSE has it aliased to `zypper`
66
- elsif system('which apt')
67
- $errors << "Install the following packages using `apt` and try again:\n" <<
68
- " libsdl2-dev libsdl2-mixer-dev".bold
69
- end
70
- when :bsd
71
- $errors << "Install the following packages using `pkg` and try again:\n" <<
72
- " sdl2 sdl2_mixer".bold
73
- end
74
-
75
- $errors << "" << "See #{"ruby2d.com".bold} for additional help."
76
- print_errors; exit
77
- end
78
- end
79
-
80
- # Set Raspberry Pi flags
81
- def set_rpi_flags
82
- if $platform == :linux_rpi
83
- add_flags(:c, '-I/opt/vc/include')
84
- add_flags(:ld, '-L/opt/vc/lib -lbrcmGLESv2')
85
- end
86
- end
87
-
88
- # Set flags for Linux and BSD
89
- def set_linux_bsd_flags
90
- check_sdl
91
- set_rpi_flags
92
- add_flags(:ld, "-lSDL2 -lSDL2_mixer -lm")
93
- if $PLATFORM == :linux then add_flags(:ld, '-lGL') end
94
- end
95
-
96
-
97
- # Use SDL and other libraries installed by the user (not those bundled with the gem)
98
- def use_usr_libs
99
- case $PLATFORM
100
- when :macos
101
- add_flags(:c, `sdl2-config --cflags`)
102
- add_flags(:c, '-I/opt/homebrew/include')
103
- add_flags(:ld, `sdl2-config --libs`)
104
- add_flags(:ld, '-lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf')
105
- add_flags(:ld, '-Wl,-framework,OpenGL')
106
- when :windows
107
- add_flags(:ld, '-lSDL2 -lSDL2_mixer')
108
- add_flags(:ld, '-lopengl32 -lglew32')
109
- when :linux_rpi
110
- set_linux_bsd_flags
111
- end
112
- end
113
-
114
-
115
- # Configure native extension ###################################################
116
-
117
- # Build Ruby 2D native extention using libraries installed by user
118
- # To use install flag: `gem install ruby2d -- dev`
119
- if ARGV.include? 'dev'
120
- use_usr_libs
121
-
122
- # Use libraries provided by the gem (default)
123
- else
124
- add_flags(:c, '-std=c11')
125
-
126
- case $PLATFORM
127
- when :macos
128
- add_flags(:c, '-I../assets/include')
129
- ldir = "#{Dir.pwd}/../assets/macos/universal/lib"
130
-
131
- add_flags(:ld, "#{ldir}/libSDL2.a #{ldir}/libSDL2_mixer.a")
132
- add_flags(:ld, "#{ldir}/libmpg123.a #{ldir}/libogg.a #{ldir}/libFLAC.a #{ldir}/libvorbis.a #{ldir}/libvorbisfile.a #{ldir}/libmodplug.a")
133
- add_flags(:ld, "-lz -liconv -lstdc++")
134
- add_flags(:ld, "-Wl,-framework,Cocoa -Wl,-framework,Carbon -Wl,-framework,GameController -Wl,-framework,ForceFeedback -Wl,-framework,OpenGL -Wl,-framework,AudioToolbox -Wl,-framework,CoreAudio -Wl,-framework,IOKit -Wl,-framework,CoreHaptics -Wl,-framework,CoreVideo -Wl,-framework,Metal")
135
-
136
- when :windows
137
- add_flags(:c, '-I../assets/include')
138
-
139
- if RUBY_PLATFORM =~ /ucrt/
140
- ldir = "#{Dir.pwd}/../assets/windows/mingw-w64-ucrt-x86_64/lib"
141
- else
142
- ldir = "#{Dir.pwd}/../assets/windows/mingw-w64-x86_64/lib"
143
- end
144
-
145
- # Start linker flags (needed to avoid circular dependencies)
146
- add_flags(:ld, "-Wl,--start-group")
147
-
148
- # SDL2
149
- add_flags(:ld, "#{ldir}/libSDL2.a")
150
-
151
- # SDL2_mixer
152
- add_flags(:ld, "#{ldir}/libSDL2_mixer.a")
153
- add_flags(:ld, "#{ldir}/libmpg123.a #{ldir}/libFLAC.a #{ldir}/libvorbis.a #{ldir}/libvorbisfile.a #{ldir}/libogg.a "\
154
- "#{ldir}/libmodplug.a #{ldir}/libopus.a #{ldir}/libopusfile.a #{ldir}/libsndfile.a")
155
-
156
- # Other dependencies
157
- add_flags(:ld, "#{ldir}/libglew32.a #{ldir}/libstdc++.a #{ldir}/libz.a")
158
- add_flags(:ld, '-lmingw32 -lopengl32 -lole32 -loleaut32 -limm32 -lversion -lwinmm -lrpcrt4 -mwindows -lsetupapi -ldwrite')
159
-
160
- # End linker flags
161
- add_flags(:ld, "-Wl,--end-group")
162
-
163
- when :linux, :linux_rpi, :bsd
164
- set_linux_bsd_flags
165
-
166
- # If can't detect the platform, use libraries installed by the user
167
- else
168
- use_usr_libs
169
- end
170
- end
171
-
172
- $CFLAGS.gsub!(/\n/, ' ') # remove newlines in flags, they can cause problems
173
- $LDFLAGS.gsub!(/\n/, ' ') # remove newlines in flags, they can cause problems
174
-
175
- # Create Makefile
176
- create_header
177
- create_makefile('audio')
1
+
2
+ require 'mkmf'
3
+
4
+ case RUBY_PLATFORM
5
+ when /darwin/
6
+ $PLATFORM = :macos
7
+ when /linux/
8
+ $PLATFORM = :linux
9
+ if `cat /etc/os-release` =~ /raspbian/
10
+ $PLATFORM = :linux_rpi
11
+ end
12
+ when /bsd/
13
+ $PLATFORM = :bsd
14
+ when /mingw/
15
+ $PLATFORM = :windows
16
+ else
17
+ $PLATFORM = nil
18
+ end
19
+ $errors = [] # Holds errors
20
+
21
+ # Helper functions #############################################################
22
+
23
+ # Print installation errors
24
+ def print_errors
25
+ puts "
26
+ #{"== #{"Ruby 2D Installation Errors".error} =======================================\n"}
27
+ #{$errors.join("\n ")}\n
28
+ #{"======================================================================"}"
29
+ end
30
+
31
+ # Add compiler and linker flags
32
+ def add_flags(type, flags)
33
+ case type
34
+ when :c
35
+ $CFLAGS << " #{flags} "
36
+ when :ld
37
+ $LDFLAGS << " #{flags} "
38
+ end
39
+ end
40
+
41
+ # Check for SDL libraries
42
+ def check_sdl
43
+ unless have_library('SDL2') && have_library('SDL2_mixer')
44
+
45
+ $errors << "Couldn't find packages needed."
46
+
47
+ case $platform
48
+ when :linux, :linux_rpi
49
+ # Fedora and CentOS
50
+ if system('which yum')
51
+ $errors << "Install the following packages using `yum` (or `dnf`) and try again:\n" <<
52
+ " SDL2-devel SDL2_mixer-devel".bold
53
+
54
+ elsif system('which pacman') # Arch
55
+ $errors << "Install the following packages using `pacman` and try again:\n" <<
56
+ " sdl2 sdl2_mixer".bold
57
+
58
+ elsif system('which zypper') # openSUSE
59
+ $errors << "Install the following packages using `zypper` and try again:\n" <<
60
+ " libSDL2-devel libSDL2_mixer-devel".bold
61
+
62
+ # Ubuntu, Debian, and Mint
63
+ # `apt` must be last because openSUSE has it aliased to `zypper`
64
+ elsif system('which apt')
65
+ $errors << "Install the following packages using `apt` and try again:\n" <<
66
+ " libsdl2-dev libsdl2-mixer-dev".bold
67
+ end
68
+ when :bsd
69
+ $errors << "Install the following packages using `pkg` and try again:\n" <<
70
+ " sdl2 sdl2_mixer".bold
71
+ end
72
+
73
+ $errors << "" << "See #{"ruby2d.com".bold} for additional help."
74
+ print_errors; exit
75
+ end
76
+ end
77
+
78
+ # Set Raspberry Pi flags
79
+ def set_rpi_flags
80
+ if $platform == :linux_rpi
81
+ add_flags(:c, '-I/opt/vc/include')
82
+ add_flags(:ld, '-L/opt/vc/lib -lbrcmGLESv2')
83
+ end
84
+ end
85
+
86
+ # Set flags for Linux and BSD
87
+ def set_linux_bsd_flags
88
+ check_sdl
89
+ set_rpi_flags
90
+ add_flags(:ld, "-lSDL2 -lSDL2_mixer -lm")
91
+ if $PLATFORM == :linux then add_flags(:ld, '-lGL') end
92
+ end
93
+
94
+
95
+ # Use SDL and other libraries installed by the user (not those bundled with the gem)
96
+ def use_usr_libs
97
+ case $PLATFORM
98
+ when :macos
99
+ add_flags(:c, `sdl2-config --cflags`)
100
+ add_flags(:c, '-I/opt/homebrew/include')
101
+ add_flags(:ld, `sdl2-config --libs`)
102
+ add_flags(:ld, '-lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf')
103
+ add_flags(:ld, '-Wl,-framework,OpenGL')
104
+ when :windows
105
+ add_flags(:ld, '-lSDL2 -lSDL2_mixer')
106
+ add_flags(:ld, '-lopengl32 -lglew32')
107
+ when :linux_rpi
108
+ set_linux_bsd_flags
109
+ end
110
+ end
111
+
112
+
113
+ # Configure native extension ###################################################
114
+
115
+ # Build Ruby 2D native extention using libraries installed by user
116
+ # To use install flag: `gem install ruby2d -- dev`
117
+ if ARGV.include? 'dev'
118
+ use_usr_libs
119
+
120
+ else # Use libraries provided by the gem (default)
121
+ add_flags(:c, '-std=c11')
122
+
123
+ case $PLATFORM
124
+ when :macos
125
+ add_flags(:c, '-I../assets/include')
126
+ ldir = "#{Dir.pwd}/../assets/macos/universal/lib"
127
+
128
+ add_flags(:ld, "#{ldir}/libSDL2.a #{ldir}/libSDL2_mixer.a")
129
+ add_flags(:ld, "#{ldir}/libmpg123.a #{ldir}/libogg.a #{ldir}/libFLAC.a #{ldir}/libvorbis.a #{ldir}/libvorbisfile.a #{ldir}/libmodplug.a")
130
+ add_flags(:ld, "-lz -liconv -lstdc++")
131
+ add_flags(:ld, "-Wl,-framework,Cocoa -Wl,-framework,Carbon -Wl,-framework,GameController -Wl,-framework,ForceFeedback -Wl,-framework,OpenGL -Wl,-framework,AudioToolbox -Wl,-framework,CoreAudio -Wl,-framework,IOKit -Wl,-framework,CoreHaptics -Wl,-framework,CoreVideo -Wl,-framework,Metal")
132
+
133
+ when :windows
134
+ add_flags(:c, '-I../assets/include')
135
+
136
+ if RUBY_PLATFORM =~ /ucrt/
137
+ ldir = "#{Dir.pwd}/../assets/windows/mingw-w64-ucrt-x86_64/lib"
138
+ else
139
+ ldir = "#{Dir.pwd}/../assets/windows/mingw-w64-x86_64/lib"
140
+ end
141
+
142
+ # Start linker flags (needed to avoid circular dependencies)
143
+ add_flags(:ld, "-Wl,--start-group")
144
+
145
+ # SDL2
146
+ add_flags(:ld, "#{ldir}/libSDL2.a")
147
+
148
+ # SDL2_mixer
149
+ add_flags(:ld, "#{ldir}/libSDL2_mixer.a")
150
+ add_flags(:ld, "#{ldir}/libmpg123.a #{ldir}/libFLAC.a #{ldir}/libvorbis.a #{ldir}/libvorbisfile.a #{ldir}/libogg.a "\
151
+ "#{ldir}/libmodplug.a #{ldir}/libopus.a #{ldir}/libopusfile.a #{ldir}/libsndfile.a")
152
+
153
+ # Other dependencies
154
+ add_flags(:ld, "#{ldir}/libglew32.a #{ldir}/libstdc++.a #{ldir}/libz.a")
155
+ add_flags(:ld, '-lmingw32 -lopengl32 -lole32 -loleaut32 -limm32 -lversion -lwinmm -lrpcrt4 -mwindows -lsetupapi -ldwrite')
156
+
157
+ # End linker flags
158
+ add_flags(:ld, "-Wl,--end-group")
159
+
160
+ when :linux, :linux_rpi, :bsd
161
+ set_linux_bsd_flags
162
+
163
+ else # If can't detect the platform, use libraries installed by the user
164
+ use_usr_libs
165
+ end
166
+ end
167
+
168
+ $CFLAGS.gsub!(/\n/, ' ') # remove newlines in flags, they can cause problems
169
+ $LDFLAGS.gsub!(/\n/, ' ') # remove newlines in flags, they can cause problems
170
+
171
+ # Create Makefile
172
+ create_header
173
+ create_makefile('audio')
data/lib/audio.bundle CHANGED
File without changes
data/lib/audio.so ADDED
Binary file
data/lib/native_audio.rb CHANGED
@@ -1,50 +1,50 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './audio'
4
-
5
- module NativeAudio
6
- class Clip
7
- attr_reader :clip
8
-
9
- def initialize(path)
10
- @path = path
11
- @clip = Audio.load(path)
12
- end
13
- end
14
-
15
- class AudioSource
16
- def initialize(clip)
17
- @clip = clip
18
- @channel = AudioSource.channels.count
19
- AudioSource.channels << self
20
- end
21
-
22
- def play
23
- Audio.play(@channel, @clip.clip)
24
- end
25
-
26
- def stop
27
- Audio.stop(@channel)
28
- end
29
-
30
- def pause
31
- Audio.pause(@channel)
32
- end
33
-
34
- def resume
35
- Audio.resume(@channel)
36
- end
37
-
38
- def set_pos(angle, distance)
39
- Audio.set_pos(@channel, angle, distance)
40
- end
41
-
42
- def set_volume(volume)
43
- Audio.set_volume(@channel, volume)
44
- end
45
-
46
- def self.channels
47
- @channels ||= []
48
- end
49
- end
50
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './audio'
4
+
5
+ module NativeAudio
6
+ class Clip
7
+ attr_reader :clip
8
+
9
+ def initialize(path)
10
+ @path = path
11
+ @clip = Audio.load(path)
12
+ end
13
+ end
14
+
15
+ class AudioSource
16
+ def initialize(clip)
17
+ @clip = clip
18
+ @channel = AudioSource.channels.count
19
+ AudioSource.channels << self
20
+ end
21
+
22
+ def play
23
+ Audio.play(@channel, @clip.clip)
24
+ end
25
+
26
+ def stop
27
+ Audio.stop(@channel)
28
+ end
29
+
30
+ def pause
31
+ Audio.pause(@channel)
32
+ end
33
+
34
+ def resume
35
+ Audio.resume(@channel)
36
+ end
37
+
38
+ def set_pos(angle, distance)
39
+ Audio.set_pos(@channel, angle, distance)
40
+ end
41
+
42
+ def set_volume(volume)
43
+ Audio.set_volume(@channel, volume)
44
+ end
45
+
46
+ def self.channels
47
+ @channels ||= []
48
+ end
49
+ end
50
+ end