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.
- checksums.yaml +4 -4
- data/assets/include/GL/glew.h +26427 -26427
- data/assets/include/GLES2/gl2.h +656 -656
- data/assets/include/GLES2/gl2ext.h +3949 -3949
- data/assets/include/GLES2/gl2ext_angle.h +701 -701
- data/assets/include/GLES2/gl2platform.h +27 -27
- data/assets/include/GLES3/gl3.h +1192 -1192
- data/assets/include/GLES3/gl31.h +1507 -1507
- data/assets/include/GLES3/gl32.h +1808 -1808
- data/assets/include/GLES3/gl3platform.h +27 -27
- data/assets/include/KHR/khrplatform.h +290 -290
- data/assets/include/SDL2/SDL.h +233 -233
- data/assets/include/SDL2/SDL_assert.h +326 -326
- data/assets/include/SDL2/SDL_atomic.h +415 -415
- data/assets/include/SDL2/SDL_audio.h +1500 -1500
- data/assets/include/SDL2/SDL_bits.h +126 -126
- data/assets/include/SDL2/SDL_blendmode.h +198 -198
- data/assets/include/SDL2/SDL_clipboard.h +141 -141
- data/assets/include/SDL2/SDL_config.h +61 -61
- data/assets/include/SDL2/SDL_config_android.h +194 -194
- data/assets/include/SDL2/SDL_config_emscripten.h +218 -218
- data/assets/include/SDL2/SDL_config_iphoneos.h +217 -217
- data/assets/include/SDL2/SDL_config_macosx.h +277 -277
- data/assets/include/SDL2/SDL_config_minimal.h +95 -95
- data/assets/include/SDL2/SDL_config_ngage.h +89 -89
- data/assets/include/SDL2/SDL_config_os2.h +207 -207
- data/assets/include/SDL2/SDL_config_pandora.h +141 -141
- data/assets/include/SDL2/SDL_config_windows.h +331 -331
- data/assets/include/SDL2/SDL_config_wingdk.h +253 -253
- data/assets/include/SDL2/SDL_config_winrt.h +220 -220
- data/assets/include/SDL2/SDL_config_xbox.h +235 -235
- data/assets/include/SDL2/SDL_copying.h +20 -20
- data/assets/include/SDL2/SDL_cpuinfo.h +594 -594
- data/assets/include/SDL2/SDL_egl.h +2352 -2352
- data/assets/include/SDL2/SDL_endian.h +348 -348
- data/assets/include/SDL2/SDL_error.h +163 -163
- data/assets/include/SDL2/SDL_events.h +1166 -1166
- data/assets/include/SDL2/SDL_filesystem.h +149 -149
- data/assets/include/SDL2/SDL_gamecontroller.h +1074 -1074
- data/assets/include/SDL2/SDL_gesture.h +117 -117
- data/assets/include/SDL2/SDL_guid.h +100 -100
- data/assets/include/SDL2/SDL_haptic.h +1341 -1341
- data/assets/include/SDL2/SDL_hidapi.h +451 -451
- data/assets/include/SDL2/SDL_hints.h +2569 -2569
- data/assets/include/SDL2/SDL_image.h +2173 -2173
- data/assets/include/SDL2/SDL_joystick.h +1066 -1066
- data/assets/include/SDL2/SDL_keyboard.h +353 -353
- data/assets/include/SDL2/SDL_keycode.h +358 -358
- data/assets/include/SDL2/SDL_loadso.h +115 -115
- data/assets/include/SDL2/SDL_locale.h +103 -103
- data/assets/include/SDL2/SDL_log.h +404 -404
- data/assets/include/SDL2/SDL_main.h +275 -275
- data/assets/include/SDL2/SDL_messagebox.h +193 -193
- data/assets/include/SDL2/SDL_metal.h +113 -113
- data/assets/include/SDL2/SDL_misc.h +79 -79
- data/assets/include/SDL2/SDL_mixer.h +2784 -2784
- data/assets/include/SDL2/SDL_mouse.h +465 -465
- data/assets/include/SDL2/SDL_mutex.h +471 -471
- data/assets/include/SDL2/SDL_name.h +33 -33
- data/assets/include/SDL2/SDL_opengl.h +2132 -2132
- data/assets/include/SDL2/SDL_opengl_glext.h +13209 -13209
- data/assets/include/SDL2/SDL_opengles.h +39 -39
- data/assets/include/SDL2/SDL_opengles2.h +52 -52
- data/assets/include/SDL2/SDL_opengles2_gl2.h +656 -656
- data/assets/include/SDL2/SDL_opengles2_gl2ext.h +4033 -4033
- data/assets/include/SDL2/SDL_opengles2_gl2platform.h +27 -27
- data/assets/include/SDL2/SDL_opengles2_khrplatform.h +311 -311
- data/assets/include/SDL2/SDL_pixels.h +644 -644
- data/assets/include/SDL2/SDL_platform.h +261 -261
- data/assets/include/SDL2/SDL_power.h +88 -88
- data/assets/include/SDL2/SDL_quit.h +58 -58
- data/assets/include/SDL2/SDL_rect.h +376 -376
- data/assets/include/SDL2/SDL_render.h +1919 -1919
- data/assets/include/SDL2/SDL_revision.h +6 -6
- data/assets/include/SDL2/SDL_rwops.h +841 -841
- data/assets/include/SDL2/SDL_scancode.h +438 -438
- data/assets/include/SDL2/SDL_sensor.h +322 -322
- data/assets/include/SDL2/SDL_shape.h +155 -155
- data/assets/include/SDL2/SDL_stdinc.h +830 -830
- data/assets/include/SDL2/SDL_surface.h +997 -997
- data/assets/include/SDL2/SDL_system.h +623 -623
- data/assets/include/SDL2/SDL_syswm.h +386 -386
- data/assets/include/SDL2/SDL_test.h +69 -69
- data/assets/include/SDL2/SDL_test_assert.h +105 -105
- data/assets/include/SDL2/SDL_test_common.h +236 -236
- data/assets/include/SDL2/SDL_test_compare.h +69 -69
- data/assets/include/SDL2/SDL_test_crc32.h +124 -124
- data/assets/include/SDL2/SDL_test_font.h +168 -168
- data/assets/include/SDL2/SDL_test_fuzzer.h +386 -386
- data/assets/include/SDL2/SDL_test_harness.h +134 -134
- data/assets/include/SDL2/SDL_test_images.h +78 -78
- data/assets/include/SDL2/SDL_test_log.h +67 -67
- data/assets/include/SDL2/SDL_test_md5.h +129 -129
- data/assets/include/SDL2/SDL_test_memory.h +63 -63
- data/assets/include/SDL2/SDL_test_random.h +115 -115
- data/assets/include/SDL2/SDL_thread.h +464 -464
- data/assets/include/SDL2/SDL_timer.h +222 -222
- data/assets/include/SDL2/SDL_touch.h +150 -150
- data/assets/include/SDL2/SDL_ttf.h +2316 -2316
- data/assets/include/SDL2/SDL_types.h +29 -29
- data/assets/include/SDL2/SDL_version.h +204 -204
- data/assets/include/SDL2/SDL_video.h +2150 -2150
- data/assets/include/SDL2/SDL_vulkan.h +215 -215
- data/assets/include/SDL2/begin_code.h +187 -187
- data/assets/include/SDL2/close_code.h +40 -40
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libFLAC.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2_mixer.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libglew32.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libmodplug.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libmpg123.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libogg.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libopus.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libopusfile.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libsndfile.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libssp.a +1 -1
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libstdc++.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libvorbis.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libvorbisfile.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libz.a +0 -0
- data/assets/windows/mingw-w64-ucrt-x86_64/lib/libzstd.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libFLAC.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libSDL2.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libSDL2_mixer.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libglew32.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libmodplug.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libmpg123.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libogg.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libopus.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libopusfile.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libsndfile.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libssp.a +1 -1
- data/assets/windows/mingw-w64-x86_64/lib/libstdc++.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libvorbis.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libvorbisfile.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libz.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libzstd.a +0 -0
- data/ext/audio.c +80 -80
- data/ext/extconf.h +3 -3
- data/ext/extconf.rb +173 -177
- data/lib/audio.bundle +0 -0
- data/lib/audio.so +0 -0
- data/lib/native_audio.rb +50 -50
- metadata +4 -9
- data/ext/Makefile +0 -270
- data/ext/audio.o +0 -0
- 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
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
add_flags(:
|
102
|
-
add_flags(:
|
103
|
-
add_flags(:ld,
|
104
|
-
|
105
|
-
add_flags(:ld, '-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
#
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
add_flags(:
|
129
|
-
ldir
|
130
|
-
|
131
|
-
add_flags(:ld, "
|
132
|
-
|
133
|
-
|
134
|
-
add_flags(:
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
#
|
146
|
-
add_flags(:ld, "
|
147
|
-
|
148
|
-
#
|
149
|
-
add_flags(:ld, "#{ldir}/
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
add_flags(:ld,
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
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
|