Module: Ray::Audio

Defined in:
ext/audio.c

Constant Summary collapse

FORMAT_U8 =
INT2FIX(AUDIO_U8)
FORMAT_S8 =
INT2FIX(AUDIO_S8)
FORMAT_U16LSB =
INT2FIX(AUDIO_U16LSB)
FORMAT_S16LSB =
INT2FIX(AUDIO_S16LSB)
FORMAT_U16MSB =
INT2FIX(AUDIO_U16MSB)
FORMAT_S16MSB =
INT2FIX(AUDIO_S16MSB)
FORMAT_U16 =
INT2FIX(AUDIO_U16)
FORMAT_S16 =
INT2FIX(AUDIO_S16)
FORMAT_U16SYS =
INT2FIX(AUDIO_U16SYS)
FORMAT_S16SYS =
INT2FIX(AUDIO_S16SYS)

Class Method Summary collapse

Class Method Details

.formatInteger

Returns The audio format.

Returns:

  • (Integer)

    The audio format



19
20
21
22
23
24
25
# File 'ext/audio.c', line 19

VALUE ray_audio_format() {
   int freq = 0, channels = 0;
   uint16_t format = 0;
   Mix_QuerySpec(&freq, &format, &channels);

   return INT2FIX(format);
}

.frequencyInteger

Returns The audio frequency.

Returns:

  • (Integer)

    The audio frequency



10
11
12
13
14
15
16
# File 'ext/audio.c', line 10

VALUE ray_audio_frequency() {
   int freq = 0, channels = 0;
   uint16_t format = 0;
   Mix_QuerySpec(&freq, &format, &channels);

   return INT2FIX(freq);
}

.mono?true, false

Returns true if mono is used.

Returns:

  • (true, false)

    true if mono is used



28
29
30
31
32
33
34
# File 'ext/audio.c', line 28

VALUE ray_audio_mono() {
   int freq = 0, channels = 0;
   uint16_t format = 0;
   Mix_QuerySpec(&freq, &format, &channels);

   return channels == 1 ? Qtrue : Qfalse;
}

.music_pos=(val) ⇒ Object

Sets the position in the current music. May not be implemented for some formats.



148
149
150
151
# File 'ext/audio.c', line 148

VALUE ray_audio_set_music_pos(VALUE self, VALUE val) {
	Mix_SetMusicPosition(NUM2DBL(val));
	return val;
}

.pause(channel = nil) ⇒ Object

If channel is set, pauses a channel. Pauses the current music otherwise.



98
99
100
101
102
103
104
105
106
107
108
109
# File 'ext/audio.c', line 98

VALUE ray_audio_pause(int argc, VALUE *argv, VALUE self) {
   VALUE channel;
   rb_scan_args(argc, argv, "01", &channel);

   if (!NIL_P(channel)) {
      Mix_Pause(NUM2INT(channel));
      return channel;
   }

   Mix_PauseMusic();
   return Qnil;
}

.paused?(channel = nil) ⇒ true, false

True if the channel is paused. If channel isn’t set, returns true if the current music isn’t paused.

Returns:

  • (true, false)

    True if the channel is paused. If channel isn’t set, returns true if the current music isn’t paused.



134
135
136
137
138
139
140
141
# File 'ext/audio.c', line 134

VALUE ray_audio_paused(int argc, VALUE *argv, VALUE self) {
   VALUE channel;
   rb_scan_args(argc, argv, "01", &channel);

   if (!NIL_P(channel))
      return Mix_Paused(NUM2INT(channel)) ? Qtrue : Qfalse;
   return Mix_PausedMusic() ? Qtrue : Qfalse;
}

.playing?(channel = nil) ⇒ true, false

Returns If channel is set, true if something is playing on that channel. If it isn’t, true if a music is currently being played.

Returns:

  • (true, false)

    If channel is set, true if something is playing on that channel. If it isn’t, true if a music is currently being played.



67
68
69
70
71
72
73
74
# File 'ext/audio.c', line 67

VALUE ray_audio_playing(int argc, VALUE *argv, VALUE self) {
   VALUE channel = Qnil;
   rb_scan_args(argc, argv, "01", &channel);

   if (NIL_P(channel))
      return Mix_PlayingMusic() ? Qtrue : Qfalse;
   return Mix_Playing(NUM2INT(channel)) ? Qtrue: Qfalse;
}

.resume(channel = nil) ⇒ Object

If channel is set, resumes a paused channel from pause. Resumes the music otherwise.



116
117
118
119
120
121
122
123
124
125
126
127
# File 'ext/audio.c', line 116

VALUE ray_audio_resume(int argc, VALUE *argv, VALUE self) {
   VALUE channel;
   rb_scan_args(argc, argv, "01", &channel);

   if (!NIL_P(channel)) {
      Mix_Resume(NUM2INT(channel));
      return channel;
   }

   Mix_ResumeMusic();
   return Qnil;
}

.stereo?true, false

Returns true if stereo is used.

Returns:

  • (true, false)

    true if stereo is used



37
38
39
40
41
42
43
# File 'ext/audio.c', line 37

VALUE ray_audio_stereo() {
   int freq = 0, channels = 0;
   uint16_t format = 0;
   Mix_QuerySpec(&freq, &format, &channels);

   return channels == 1 ? Qfalse : Qtrue;
}

.stop(channel = nil) ⇒ Object

If channel is set, stops playback on a channel. Stops playing the current music otherwise.



81
82
83
84
85
86
87
88
89
90
91
92
# File 'ext/audio.c', line 81

VALUE ray_audio_stop(int argc, VALUE *argv, VALUE self) {
   VALUE channel;
   rb_scan_args(argc, argv, "01", &channel);

   if (!NIL_P(channel)) {
      Mix_HaltChannel(NUM2INT(channel));
      return channel;
   }

   Mix_HaltMusic();
   return Qnil;
}

.volumeFloat

Returns The volume for the song which is currently being played. 0 is the minimum volume, whereas 100 is the maximum.

Returns:

  • (Float)

    The volume for the song which is currently being played. 0 is the minimum volume, whereas 100 is the maximum.



49
50
51
52
# File 'ext/audio.c', line 49

VALUE ray_audio_volume(VALUE self) {
   int volume = Mix_VolumeMusic(-1);
   return rb_float_new((volume / 128.0f) * 100.0f);
}

.volume=(value) ⇒ Object

Sets the volume of the song which is currently being played



55
56
57
58
59
60
# File 'ext/audio.c', line 55

VALUE ray_audio_set_volume(VALUE self, VALUE value) {
   float volume = (float)NUM2DBL(value);
   Mix_VolumeMusic((int)((volume / 100.0f) * 128.0f));

   return value;
}