/
audio_formats.rb
55 lines (46 loc) · 1.18 KB
/
audio_formats.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Encoding: UTF-8
# Require cutting-edge development Gosu for testing.
$LOAD_PATH << '../lib'
require 'gosu'
Dir.chdir 'audio_formats'
FORMATS_TO_TRY = Dir['*'].sort
FORMAT_NAMES = FORMATS_TO_TRY.map { |fn| fn[/[^\.]*/].gsub('_', ' ') }
def test_sample format
si = Gosu::Sample.new(format).play
sleep 1
si.stop
'✓'
rescue
''
end
def test_song format
Gosu::Song.new(format).play
sleep 1
Gosu::Song::current_song.stop if Gosu::Song::current_song
'✓'
rescue
''
end
class String
def widen(length)
"%#{length}s" % self
end
end
platform = case RUBY_PLATFORM
when /darwin/ then 'OS X'
when /win/, /mingw/ then 'Windows'
else 'Linux'
end
format_length = FORMAT_NAMES.max_by(&:length).length
sample_length = "Sample (#{platform})".length
song_length = "Song (#{platform})".length
puts "#{'Format'.widen(format_length)}|Sample (#{platform})|Song (#{platform})"
puts "#{'-' * format_length}|#{'-' * sample_length}|#{'-' * song_length}"
FORMATS_TO_TRY.each_with_index do |format, i|
print FORMAT_NAMES[i].widen(format_length)
print '|'
print test_sample(format).widen(sample_length)
print '|'
print test_song(format).widen(song_length)
puts
end