#!ruby # -*- mode: ruby; coding: utf-8 -*- # Last updated: <2021/08/15 05:47:26 +0900> # # Bass.rb sample play (ogg play example) # # it worked. # Windows10 x64 21H1 and # Ruby 1.8.7 p330 x86 (i386-mswin32) + DXRuby 1.0.9 x86 # Ruby 1.9.3 p551 x86 (i386-mingw32) + DXRuby 1.4.1 x86 # Ruby 2.3.3 p222 x86 (i386-mingw32) + DXRuby 1.4.6 x86 # Ruby 2.6.8 p205 x86 (i386-mingw32) + DXRuby 1.4.7 x86 # Ruby 2.7.4 p191 x86 (i386-mingw32) + DXRuby 1.4.7 x86 # Ruby 3.0.2 p107 x86 (i386-mingw32) + DXRuby 1.4.7 x86 require "dxruby" if RUBY_VERSION.to_f <= 1.8 require "Bass" else require_relative "Bass" end Window.caption = "Ogg sample play example with Bass.rb" fnt = Font.new(24) Bass.init(Window.hWnd) # init Bass s = Bass.loadSample("jingle.ogg") # load ogg pan = 0.0 volume = 1.0 ch = s.play(:loop => false, :pan => pan, :volume => volume) # play Window.loop do break if Input.keyPush?(K_ESCAPE) # reset pan and volume if Input.keyPush?(K_R) pan = 0.0 volume = 1.0 s.setPan(ch, pan) s.setVolume(ch, volume) end # pan (Left, Right) if Input.x != 0 pan += Input.x * 0.02 pan = -1.0 if pan < -1.0 pan = 1.0 if pan > 1.0 s.setPan(ch, pan) end # volume (0.0 - 1.0) if Input.y != 0 volume -= Input.y * 0.01 volume = 0.0 if volume < 0.0 volume = 1.0 if volume > 1.0 s.setVolume(ch, volume) end ch = s.play(:loop => true, :pan => pan, :volume => volume) if Input.keyPush?(K_Z) # play s.stop if Input.keyPush?(K_X) # pause s.setFade(ch, 0.0, 750) if Input.keyPush?(K_C) # fadeout s.setFade(ch, 1.0, 750) if Input.keyPush?(K_V) # fadein y = 8 dy = 30 [ "Ogg sample play example with Bass.rb", "", "Z: Play", "X: Stop", "C: Fadeout", "V: Fadein", "R: Reset pan, volume", "Left Right: pan", "Up Down: volume", ].each do |m| Window.draw_font(8, y, m, fnt) y += dy end y += dy Window.draw_font(8, y, "pan : #{pan}", fnt) y += dy Window.draw_font(8, y, "volume : #{volume}", fnt) end s.free Bass.free