beats 1.3.0 → 2.0.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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.markdown +22 -42
  4. data/bin/beats +6 -7
  5. data/lib/beats.rb +2 -1
  6. data/lib/beats/audioengine.rb +13 -13
  7. data/lib/beats/beatsrunner.rb +7 -8
  8. data/lib/beats/kit.rb +12 -156
  9. data/lib/beats/kit_builder.rb +74 -0
  10. data/lib/beats/pattern.rb +2 -22
  11. data/lib/beats/song.rb +5 -55
  12. data/lib/beats/songoptimizer.rb +3 -3
  13. data/lib/beats/songparser.rb +25 -46
  14. data/lib/beats/track.rb +20 -31
  15. data/lib/beats/transforms/song_swinger.rb +2 -4
  16. data/lib/wavefile/cachingwriter.rb +2 -2
  17. data/test/audioengine_test.rb +22 -24
  18. data/test/audioutils_test.rb +1 -1
  19. data/test/cachingwriter_test.rb +13 -12
  20. data/test/fixtures/invalid/leading_bar_line.txt +15 -0
  21. data/test/fixtures/{valid → invalid}/with_structure.txt +2 -2
  22. data/test/fixtures/valid/multiple_tracks_same_sound.txt +2 -1
  23. data/test/fixtures/valid/optimize_pattern_collision.txt +4 -5
  24. data/test/fixtures/valid/track_with_spaces.txt +13 -0
  25. data/test/includes.rb +1 -4
  26. data/test/integration_test.rb +5 -5
  27. data/test/kit_builder_test.rb +52 -0
  28. data/test/kit_test.rb +18 -141
  29. data/test/pattern_test.rb +66 -1
  30. data/test/song_swinger_test.rb +2 -2
  31. data/test/song_test.rb +9 -33
  32. data/test/songoptimizer_test.rb +18 -18
  33. data/test/songparser_test.rb +20 -10
  34. data/test/track_test.rb +23 -9
  35. metadata +26 -31
  36. data/ext/mkrf_conf.rb +0 -28
  37. data/test/fixtures/invalid/template.txt +0 -31
  38. data/test/fixtures/valid/foo.txt +0 -18
  39. data/test/sounds/bass.wav +0 -0
  40. data/test/sounds/bass2.wav +0 -0
  41. data/test/sounds/sine-mono-8bit.wav +0 -0
  42. data/test/sounds/tone.wav +0 -0
@@ -1,15 +1,13 @@
1
1
  module Beats
2
2
  module Transforms
3
- class InvalidSwingRateError < RuntimeError; end
4
-
5
3
  class SongSwinger
4
+ class InvalidSwingRateError < RuntimeError; end
5
+
6
6
  def self.transform(song, swing_rate)
7
7
  validate_swing_rate(swing_rate)
8
8
 
9
9
  song.patterns.values.each do |pattern|
10
10
  pattern.tracks.values.each do |track|
11
- original_rhythm = track.rhythm
12
-
13
11
  if swing_rate == 8
14
12
  track.rhythm = swing_8(track.rhythm)
15
13
  elsif swing_rate == 16
@@ -11,7 +11,7 @@ module WaveFile
11
11
 
12
12
  def write(buffer)
13
13
  packed_buffer_data = {}
14
-
14
+
15
15
  key = buffer.hash
16
16
  if @buffer_cache.member?(key)
17
17
  packed_buffer_data = @buffer_cache[key]
@@ -29,7 +29,7 @@ module WaveFile
29
29
  @buffer_cache[key] = packed_buffer_data
30
30
  end
31
31
 
32
- @file.syswrite(packed_buffer_data[:data])
32
+ @io.write(packed_buffer_data[:data])
33
33
  @total_sample_frames += packed_buffer_data[:sample_count]
34
34
  end
35
35
  end
@@ -15,10 +15,10 @@ end
15
15
 
16
16
  # Allow setting sample data directly, instead of loading from a file
17
17
  class MockKit < Kit
18
- attr_accessor :sound_bank, :num_channels
18
+ attr_accessor :items
19
19
  end
20
20
 
21
- class AudioEngineTest < Test::Unit::TestCase
21
+ class AudioEngineTest < Minitest::Test
22
22
  FIXTURES = [:repeats_not_specified,
23
23
  :pattern_with_overflow,
24
24
  :example_no_kit,
@@ -29,7 +29,7 @@ class AudioEngineTest < Test::Unit::TestCase
29
29
  base_path = File.dirname(__FILE__) + "/.."
30
30
  song_parser = SongParser.new
31
31
 
32
- test_engines[:blank] = AudioEngine.new(Song.new, Kit.new(base_path, {}))
32
+ test_engines[:blank] = AudioEngine.new(Song.new, KitBuilder.new(base_path).build_kit)
33
33
 
34
34
  FIXTURES.each do |fixture_name|
35
35
  song, kit = song_parser.parse(base_path, File.read("test/fixtures/valid/#{fixture_name}.txt"))
@@ -56,27 +56,25 @@ class AudioEngineTest < Test::Unit::TestCase
56
56
  # TS A step with no sound, shorter than full sound length
57
57
  # Z A zero sample
58
58
 
59
- MONO_KIT = MockKit.new(".", {})
60
- MONO_KIT.sound_bank = { "S" => [-100, 200, 300, -400],
61
- "SL" => [-100, 200, 300, -400, 0, 0],
62
- "SS" => [-100, 200],
63
- "SO" => [300, -400],
64
- "TE" => [0, 0, 0, 0],
65
- "TL" => [0, 0, 0, 0, 0, 0],
66
- "TS" => [0, 0],
67
- "Z" => [0] }
68
- MONO_KIT.num_channels = 1
69
-
70
- STEREO_KIT = MockKit.new(".", {})
71
- STEREO_KIT.sound_bank = { "S" => [[-100, 800], [200, -700], [300, -600], [-400, 400]],
72
- "SL" => [[-100, 800], [200, -700], [300, -600], [-400, 400], [0, 0], [0, 0]],
73
- "SS" => [[-100, 800], [200, -700]],
74
- "SO" => [[300, -600], [-400, 400]],
75
- "TE" => [[0, 0], [0, 0], [0, 0], [0, 0]],
76
- "TL" => [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]],
77
- "TS" => [[0, 0], [0, 0]],
78
- "Z" => [[0, 0]] }
79
- STEREO_KIT.num_channels = 2
59
+ MONO_KIT = MockKit.new({}, 1, 16)
60
+ MONO_KIT.items = { "S" => [-100, 200, 300, -400],
61
+ "SL" => [-100, 200, 300, -400, 0, 0],
62
+ "SS" => [-100, 200],
63
+ "SO" => [300, -400],
64
+ "TE" => [0, 0, 0, 0],
65
+ "TL" => [0, 0, 0, 0, 0, 0],
66
+ "TS" => [0, 0],
67
+ "Z" => [0] }
68
+
69
+ STEREO_KIT = MockKit.new({}, 2, 16)
70
+ STEREO_KIT.items = { "S" => [[-100, 800], [200, -700], [300, -600], [-400, 400]],
71
+ "SL" => [[-100, 800], [200, -700], [300, -600], [-400, 400], [0, 0], [0, 0]],
72
+ "SS" => [[-100, 800], [200, -700]],
73
+ "SO" => [[300, -600], [-400, 400]],
74
+ "TE" => [[0, 0], [0, 0], [0, 0], [0, 0]],
75
+ "TL" => [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]],
76
+ "TS" => [[0, 0], [0, 0]],
77
+ "Z" => [[0, 0]] }
80
78
 
81
79
 
82
80
  # These tests use unrealistically short sounds and step sample lengths, to make tests easier to work with.
@@ -1,6 +1,6 @@
1
1
  require 'includes'
2
2
 
3
- class AudioUtilsTest < Test::Unit::TestCase
3
+ class AudioUtilsTest < Minitest::Test
4
4
  def test_composite
5
5
  # Mono empty arrays
6
6
  assert_equal([], AudioUtils.composite([], 1))
@@ -1,20 +1,18 @@
1
1
  require 'includes'
2
2
 
3
- # Makes @file writable so it can be replaced with StringIO for testing
4
- class StringCachingWriter < WaveFile::CachingWriter
5
- attr_writer :file
6
- end
7
-
8
3
  # Basic tests for CachingWriter; the integration tests test it more thoroughly.
9
- class CachingWriterTest < Test::Unit::TestCase
4
+ class CachingWriterTest < Minitest::Test
10
5
  def test_mono
11
6
  buffer1_bytes = [0, 0, 1, 0, 2, 0]
12
7
  buffer2_bytes = [3, 0, 4, 0, 5, 0]
13
8
 
14
- format = WaveFile::Format.new(:mono, 16, 44100)
15
- writer = StringCachingWriter.new("does_not_matter", format)
9
+ format = WaveFile::Format.new(:mono, :pcm_16, 44100)
16
10
  string_io = StringIO.new
17
- writer.file = string_io
11
+ writer = WaveFile::CachingWriter.new(string_io, format)
12
+
13
+ # Remove WaveFile header to make test assertions simpler
14
+ string_io.truncate(0)
15
+ string_io.rewind
18
16
 
19
17
  assert_equal(format, writer.format)
20
18
 
@@ -35,10 +33,13 @@ class CachingWriterTest < Test::Unit::TestCase
35
33
  buffer1_bytes = [0, 0, 3, 0, 1, 0, 2, 0]
36
34
  buffer2_bytes = [9, 0, 6, 0, 8, 0, 7, 0]
37
35
 
38
- format = WaveFile::Format.new(:stereo, 16, 44100)
39
- writer = StringCachingWriter.new("does_not_matter", format)
36
+ format = WaveFile::Format.new(:stereo, :pcm_16, 44100)
40
37
  string_io = StringIO.new
41
- writer.file = string_io
38
+ writer = WaveFile::CachingWriter.new(string_io, format)
39
+
40
+ # Remove WaveFile header to make test assertions simpler
41
+ string_io.truncate(0)
42
+ string_io.rewind
42
43
 
43
44
  assert_equal(format, writer.format)
44
45
 
@@ -0,0 +1,15 @@
1
+ # Support for tracks that start with a | character are no longer supported
2
+ # as of v2.0.0. The reason is that this is not valid YAML, and only worked
3
+ # due to a bug in Syck. Now that Beats is using Psych, this is invalid.
4
+
5
+ Song:
6
+ Tempo: 120
7
+ Kit:
8
+ - bass: test/sounds/bass_mono_8.wav
9
+ - snare: test/sounds/snare_mono_8.wav
10
+ Flow:
11
+ - Verse: x1
12
+
13
+ Verse:
14
+ - bass: X...X...
15
+ - snare: |..X...X.
@@ -1,5 +1,5 @@
1
1
  # Header contains a "Structure" section instead of a "Flow" section.
2
- # This is valid for now, but is deprecated.
2
+ # Support for this section was removed in v2.0.0.
3
3
 
4
4
  Song:
5
5
  Tempo: 100
@@ -7,4 +7,4 @@ Song:
7
7
  - Verse: x2
8
8
 
9
9
  Verse:
10
- - test/sounds/bass_mono_8.wav: X...X...
10
+ - test/sounds/bass_mono_8.wav: X...X...
@@ -29,5 +29,6 @@ Chorus:
29
29
  - bass: X...X...XX..X...
30
30
  - snare: ....X.......X...
31
31
  - hh_closed: X.XXX.XXX.XX..X.
32
+ - bass: ..X..X..X..X..X.
32
33
  - test/sounds/tom4_mono_16.wav: ...........X....
33
- - test/sounds/tom2_mono_16.wav: ..............X.
34
+ - test/sounds/tom2_mono_16.wav: ..............X.
@@ -6,7 +6,7 @@
6
6
  # the other one leading to incorrect song output.
7
7
  #
8
8
  # In the example below, when sub-dividing patterns with a max size of 4 steps, the new patterns
9
- # highlighted with !!!! would both be called Verse20, causing a collision.
9
+ # highlighted with !!!! would both be called Verse20, causing a collision.
10
10
 
11
11
 
12
12
  Song:
@@ -18,11 +18,10 @@ Song:
18
18
  Verse:
19
19
  # 0 4 8 12 16 20
20
20
  # !!!!
21
- - test/sounds/bass_mono_8.wav: |X...|X...|X...|X...|X...|X.XX|
21
+ - test/sounds/bass_mono_8.wav: X...|X...|X...|X...|X...|X.XX|
22
22
 
23
23
 
24
- Verse2:
24
+ Verse2:
25
25
  # 0 4 8 12 16 20
26
26
  # !!!!
27
- - test/sounds/bass_mono_8.wav: |X..X|X..X|X..X|X..X|X..X|X..X|
28
-
27
+ - test/sounds/bass_mono_8.wav: X..X|X..X|X..X|X..X|X..X|X..X|
@@ -0,0 +1,13 @@
1
+ # An example song that has tracks with the space character in them
2
+
3
+ Song:
4
+ Tempo: 120
5
+ Flow:
6
+ - Verse: x2
7
+ Kit:
8
+ - bass: test/sounds/bass_stereo_16.wav
9
+ - snare: test/sounds/snare_stereo_16.wav
10
+
11
+ Verse:
12
+ - bass: X... X...|X... X...
13
+ - snare: .... X...|.... X...
@@ -1,7 +1,6 @@
1
1
  # Standard Ruby libraries
2
- require 'test/unit'
2
+ require 'minitest/autorun'
3
3
  require 'yaml'
4
- require 'syck'
5
4
  require 'rubygems'
6
5
 
7
6
  # External gems
@@ -11,5 +10,3 @@ require 'wavefile'
11
10
  require 'beats'
12
11
  require 'wavefile/cachingwriter'
13
12
  include Beats
14
-
15
- YAML::ENGINE.yamler = 'syck' if defined?(YAML::ENGINE)
@@ -1,6 +1,6 @@
1
1
  require 'includes'
2
2
 
3
- class IntegrationTest < Test::Unit::TestCase
3
+ class IntegrationTest < Minitest::Test
4
4
  TRACK_NAMES = ["bass", "snare", "hh_closed", "hh_closed2", "agogo", "tom4", "tom2"]
5
5
  OUTPUT_FOLDER = "test/integration_output"
6
6
 
@@ -19,7 +19,7 @@ class IntegrationTest < Test::Unit::TestCase
19
19
  "sound_in_track_not_found.txt"]
20
20
 
21
21
  invalid_fixtures.each do |fixture_name|
22
- assert_raise(SongParseError) do
22
+ assert_raises(SongParser::ParseError) do
23
23
  beats = BeatsRunner.new("test/fixtures/invalid/#{fixture_name}", "doesn't matter", {:split => false})
24
24
  beats.run
25
25
  end
@@ -57,7 +57,7 @@ class IntegrationTest < Test::Unit::TestCase
57
57
 
58
58
  beats = BeatsRunner.new(song_fixture, actual_output_file, options)
59
59
  beats.run
60
- assert(File.exists?(actual_output_file), "Expected file '#{actual_output_file}' to exist, but it doesn't.")
60
+ assert(File.exist?(actual_output_file), "Expected file '#{actual_output_file}' to exist, but it doesn't.")
61
61
 
62
62
  # Reading the files this way instead of a plain File.read() for Windows compatibility with binary files
63
63
  expected_output_file_contents = File.open(expected_output_file, "rb") {|f| f.read() }
@@ -96,7 +96,7 @@ class IntegrationTest < Test::Unit::TestCase
96
96
  end
97
97
  actual_output_file = "#{actual_output_prefix}-#{track_name}.wav"
98
98
  expected_output_file = "#{expected_output_prefix}-#{track_name}.wav"
99
- assert(File.exists?(actual_output_file), "Expected file '#{actual_output_file}' to exist, but it doesn't.")
99
+ assert(File.exist?(actual_output_file), "Expected file '#{actual_output_file}' to exist, but it doesn't.")
100
100
 
101
101
  # Reading the files this way instead of a plain File.read() for Windows compatibility with binary files
102
102
  expected_output_file_contents = File.open(expected_output_file, "rb") {|f| f.read }
@@ -114,7 +114,7 @@ class IntegrationTest < Test::Unit::TestCase
114
114
 
115
115
  def clean_output_folder()
116
116
  # Make the folder if it doesn't already exist
117
- Dir.mkdir(OUTPUT_FOLDER) unless File.exists?(OUTPUT_FOLDER)
117
+ Dir.mkdir(OUTPUT_FOLDER) unless File.exist?(OUTPUT_FOLDER)
118
118
 
119
119
  dir = Dir.new(OUTPUT_FOLDER)
120
120
  file_names = dir.entries
@@ -0,0 +1,52 @@
1
+ require 'includes'
2
+
3
+ class KitBuilderTest < Minitest::Test
4
+ def test_has_label?
5
+ kit_builder = KitBuilder.new("test/sounds")
6
+
7
+ assert_equal(false, kit_builder.has_label?("label1"))
8
+ assert_equal(false, kit_builder.has_label?("label2"))
9
+
10
+ kit_builder.add_item("label1", "bass_mono_8.wav")
11
+ assert_equal(true, kit_builder.has_label?("label1"))
12
+ assert_equal(false, kit_builder.has_label?("label2"))
13
+ end
14
+
15
+ def test_build_kit_happy_path
16
+ kit_builder = KitBuilder.new("test/sounds")
17
+
18
+ kit_builder.add_item("mono8", "bass_stereo_8.wav")
19
+ kit_builder.add_item("bass_mono_16.wav", "bass_mono_16.wav")
20
+
21
+ kit = kit_builder.build_kit
22
+
23
+ assert_equal(Kit, kit.class)
24
+ assert_equal(2, kit.num_channels)
25
+ assert_equal(16, kit.bits_per_sample)
26
+ assert_equal(Array, kit.get_sample_data('mono8').class)
27
+ assert_equal(Array, kit.get_sample_data('bass_mono_16.wav').class)
28
+ end
29
+
30
+ def test_build_kit_no_sounds
31
+ kit_builder = KitBuilder.new("test/sounds")
32
+
33
+ kit = kit_builder.build_kit
34
+ assert_equal(Kit, kit.class)
35
+ assert_equal(1, kit.num_channels)
36
+ assert_equal(16, kit.bits_per_sample)
37
+ end
38
+
39
+ def test_build_kit_with_non_existent_sound_file
40
+ kit_builder = KitBuilder.new("test/sounds")
41
+ kit_builder.add_item("fake", "i_do_not_exist.wav")
42
+
43
+ assert_raises(KitBuilder::SoundFileNotFoundError) { kit_builder.build_kit }
44
+ end
45
+
46
+ def test_build_kit_with_invalid_sound_file
47
+ kit_builder = KitBuilder.new("test/sounds")
48
+ kit_builder.add_item("ruby_file", "../kit_builder_test.rb")
49
+
50
+ assert_raises(KitBuilder::InvalidSoundFormatError) { kit_builder.build_kit }
51
+ end
52
+ end
@@ -1,151 +1,28 @@
1
1
  require 'includes'
2
2
 
3
- # Kit which allows directly changing the sound bank after initialization, to allows tests
4
- # to use fixture data directly in the test instead of loading it from the file system.
5
- class MutableKit < Kit
6
- attr_accessor :sound_bank
7
- end
8
-
9
- class KitTest < Test::Unit::TestCase
10
- MIN_SAMPLE_8BIT = 0
11
- MAX_SAMPLE_8BIT = 255
12
-
13
- def generate_test_data
14
- kits = {}
15
-
16
- # Kit with no sounds
17
- kits[:empty] = Kit.new("test/sounds", {})
18
-
19
- # Kits which only has simple sounds
20
- kits[:mono8] = Kit.new("test/sounds", {"mono8" => "bass_mono_8.wav"})
21
- kits[:mono16] = Kit.new("test/sounds", {"mono8" => "bass_mono_8.wav",
22
- "mono16" => "bass_mono_16.wav"})
23
- kits[:stereo8] = Kit.new("test/sounds", {"mono8" => "bass_mono_8.wav",
24
- "stereo8" => "bass_stereo_8.wav"})
25
- kits[:stereo16] = Kit.new("test/sounds", {"mono8" => "bass_mono_8.wav",
26
- "mono16" => "bass_mono_16.wav",
27
- "stereo16" => "bass_stereo_16.wav"})
28
-
29
- # Kits which contain a composite sound
30
- #kits[:basic_composite] = Kit.new("test/sounds", {"mono8" => "bass_mono_8.wav",
31
- # "composite_mono8" => ["snare_mono_8.wav", "tom3_mono_8.wav"]})
32
- #kits[:mismatched_bps_composite] = Kit.new("test/sounds", {"mono8" => "bass_mono_8.wav",
33
- # "composite_mono16" => ["snare_mono_8.wav", "tom3_mono_16.wav"]})
34
- #kits[:mismatched_channels_composite] = Kit.new("test/sounds", {"mono8" => "bass_mono_8.wav",
35
- # "composite_stereo16" => ["snare_stereo_16.wav", "tom3_mono_16.wav"]})
36
- #kits[:mismatched_everything_composite] = Kit.new("test/sounds", {"mono8" => "bass_mono_8.wav",
37
- # "composite_stereo16" => ["snare_stereo_8.wav", "tom3_mono_16.wav"]})
38
-
39
- kits
3
+ class KitTest < Minitest::Test
4
+ def test_kit_with_items
5
+ kit = Kit.new({'label1' => [1,2,3], 'label2' => [4,5,6], 'label3' => [7,8,9]}, 1, 16)
6
+
7
+ assert_equal([1,2,3], kit.get_sample_data('label1'))
8
+ assert_equal([4,5,6], kit.get_sample_data('label2'))
9
+ assert_raises(Kit::LabelNotFoundError) { kit.get_sample_data('nope') }
10
+ assert_equal([7,8,9], kit.get_sample_data('label3'))
40
11
  end
41
12
 
42
- def test_valid_initialization
43
- kits = generate_test_data
44
-
45
- assert_equal(16, kits[:empty].bits_per_sample)
46
- assert_equal(1, kits[:empty].num_channels)
47
-
48
- assert_equal(16, kits[:mono8].bits_per_sample)
49
- assert_equal(1, kits[:mono8].num_channels)
50
-
51
- assert_equal(16, kits[:mono16].bits_per_sample)
52
- assert_equal(1, kits[:mono16].num_channels)
53
-
54
- assert_equal(16, kits[:stereo8].bits_per_sample)
55
- assert_equal(2, kits[:stereo8].num_channels)
56
-
57
- assert_equal(16, kits[:stereo16].bits_per_sample)
58
- assert_equal(2, kits[:stereo16].num_channels)
59
-
60
- #assert_equal(16, kits[:basic_composite].bits_per_sample)
61
- #assert_equal(1, kits[:basic_composite].num_channels)
62
-
63
- #assert_equal(16, kits[:mismatched_bps_composite].bits_per_sample)
64
- #assert_equal(1, kits[:mismatched_bps_composite].num_channels)
65
-
66
- #assert_equal(16, kits[:mismatched_channels_composite].bits_per_sample)
67
- #assert_equal(2, kits[:mismatched_channels_composite].num_channels)
68
-
69
- #assert_equal(16, kits[:mismatched_everything_composite].bits_per_sample)
70
- #assert_equal(2, kits[:mismatched_everything_composite].num_channels)
13
+ def test_kit_with_no_items
14
+ kit = Kit.new({}, 1, 16)
15
+ assert_raises(Kit::LabelNotFoundError) { kit.get_sample_data('foo') }
71
16
  end
72
17
 
73
- def test_invalid_initialization
74
- # Tests for adding non-existant sound file to Kit
75
- assert_raise(SoundFileNotFoundError) { Kit.new("test/sounds", {"i_do_not_exist" => "i_do_not_exist.wav"}) }
76
-
77
- assert_raise(SoundFileNotFoundError) { Kit.new("test/sounds", {"mono16" => "bass_mono_16.wav",
78
- "i_do_not_exist" => "i_do_not_exist.wav"}) }
79
-
80
- #assert_raise(SoundFileNotFoundError) { Kit.new("test/sounds", {"mono16" => "bass_mono_16.wav",
81
- # "composite" => ["bass_mono_16.wav", "snare_mono_16.wav"],
82
- # "i_do_not_exist" => "i_do_not_exist.wav"}) }
83
-
84
- # Tests for adding invalid sound files to Kit
85
- assert_raise(InvalidSoundFormatError) { Kit.new("test", {"bad" => "kit_test.rb"}) }
86
-
87
- assert_raise(InvalidSoundFormatError) { Kit.new("test", {"mono16" => "sounds/bass_mono_16.wav",
88
- "bad" => "kit_test.rb"}) }
89
-
90
- #assert_raise(InvalidSoundFormatError) { Kit.new("test", {"mono16" => "sounds/bass_mono_16.wav",
91
- # "composite" => ["sounds/bass_mono_16.wav", "sounds/snare_mono_16.wav"],
92
- # "bad" => "kit_test.rb"}) }
93
- end
94
-
95
- def test_get_sample_data
96
- kits = generate_test_data
97
- # Should get an error when trying to get a non-existent sound
98
- assert_raise(StandardError) { kits[:mono8].get_sample_data("nonexistant") }
99
-
100
- [:mono8, :mono16].each do |kit_name|
101
- sample_data = kits[kit_name].get_sample_data("mono8")
102
- # Assert sample data is 16-bit. If max and min samples are outside 0-255 bounds, then it is.
103
- assert(sample_data.max > MAX_SAMPLE_8BIT)
104
- assert(sample_data.min < MIN_SAMPLE_8BIT)
105
- # Assert it has 1 channel. This is true if every item is a Fixnum.
106
- assert_equal([], sample_data.select {|sample| sample.class != Fixnum})
107
- end
108
-
109
- [:stereo8, :stereo16].each do |kit_name|
110
- sample_data = kits[kit_name].get_sample_data("mono8")
111
- # Assert sample data is 16-bit. If max and min samples are outside 0-255 bounds, then it is.
112
- assert(sample_data.flatten.max > MAX_SAMPLE_8BIT)
113
- assert(sample_data.flatten.min < MIN_SAMPLE_8BIT)
114
- # Assert it has 2 channels. This is true if every item is an Array.
115
- assert_equal([], sample_data.select {|sample| sample.class != Array})
116
- end
117
-
118
- #actual_sample_data = kits[:basic_composite].get_sample_data("composite_mono8")
119
- #expected_sample_data = WaveFile.open("test/sounds/composite_snare_mono_8_tom3_mono_8_mono_16.wav").sample_data
120
- #assert_equal(expected_sample_data, actual_sample_data)
121
-
122
- #actual_sample_data = kits[:mismatched_bps_composite].get_sample_data("composite_mono16")
123
- #expected_sample_data = WaveFile.open("test/sounds/composite_snare_mono_8_tom3_mono_16_mono_16.wav").sample_data
124
- #assert_equal(expected_sample_data, actual_sample_data)
125
-
126
- #actual_sample_data = kits[:mismatched_channels_composite].get_sample_data("composite_stereo16")
127
- #expected_sample_data = WaveFile.open("test/sounds/composite_snare_stereo_16_tom3_mono_16_stereo_16.wav").sample_data
128
- #assert_equal(expected_sample_data, actual_sample_data)
129
-
130
- #actual_sample_data = kits[:mismatched_everything_composite].get_sample_data("composite_stereo16")
131
- #expected_sample_data = WaveFile.open("test/sounds/composite_snare_stereo_8_tom3_mono_16_stereo_16.wav").sample_data
132
- #assert_equal(expected_sample_data[0..10], actual_sample_data[0..10])
18
+ def test_num_channels
19
+ kit = Kit.new({}, 2, 16)
20
+ assert_equal(2, kit.num_channels)
133
21
  end
134
22
 
135
- def test_scale!
136
- sound_bank = {"a" => [-10, 0, 20], "b" => [], "c" => [12346, 9999]}
137
-
138
- kit = MutableKit.new(".", {})
139
- kit.sound_bank = sound_bank
140
-
141
- kit.scale!(5)
142
- assert_equal([-2, 0, 4], kit.get_sample_data("a"))
143
- assert_equal([], kit.get_sample_data("b"))
144
- assert_equal([2469, 1999], kit.get_sample_data("c"))
145
-
146
- kit.scale!(2)
147
- assert_equal([-1, 0, 2], kit.get_sample_data("a"))
148
- assert_equal([], kit.get_sample_data("b"))
149
- assert_equal([1234, 999], kit.get_sample_data("c"))
23
+ def test_bits_per_sample
24
+ kit = Kit.new({}, 2, 16)
25
+ assert_equal(16, kit.bits_per_sample)
150
26
  end
151
27
  end
28
+