@@ -1572,48 +1572,59 @@ mod tests {
15721572 }
15731573
15741574 #[ test]
1575- // @todo - test all conditions
15761575 fn test_loop_out_of_bounds ( ) {
1577- let sample_rate = 48_000. ;
1578- let length = sample_rate as usize / 10 ;
1579- let mut context = OfflineAudioContext :: new ( 1 , length, sample_rate) ;
1576+ [
1577+ ( -2. , -1. ) ,
1578+ ( -1. , -2. ) ,
1579+ ( 0. , 0. ) ,
1580+ ( -1. , 2. ) ,
1581+ ( 2. , -1. ) ,
1582+ ( 1. , 1. ) ,
1583+ ( 2. , 3. ) ,
1584+ ( 3. , 2. ) ,
1585+ ]
1586+ . iter ( )
1587+ . for_each ( |( loop_start, loop_end) | {
1588+ let sample_rate = 48_000. ;
1589+ let length = sample_rate as usize / 10 ;
1590+ let mut context = OfflineAudioContext :: new ( 1 , length, sample_rate) ;
1591+
1592+ let buffer_size = 500 ;
1593+ let mut buffer = context. create_buffer ( 1 , buffer_size, sample_rate) ;
1594+ let data = vec ! [ 1. ; 1 ] ;
1595+ buffer. copy_to_channel ( & data, 0 ) ;
15801596
1581- let buffer_size = 500 ;
1582- let mut buffer = context. create_buffer ( 1 , buffer_size, sample_rate) ;
1583- let data = vec ! [ 1. ; 1 ] ;
1584- buffer. copy_to_channel ( & data, 0 ) ;
1597+ let mut src = context. create_buffer_source ( ) ;
1598+ src. connect ( & context. destination ( ) ) ;
1599+ src. set_buffer ( buffer) ;
15851600
1586- let mut src = context. create_buffer_source ( ) ;
1587- src. connect ( & context. destination ( ) ) ;
1588- src. set_buffer ( buffer) ;
1601+ src. set_loop ( true ) ;
1602+ src. set_loop_start ( * loop_start) ; // outside of buffer duration
1603+ src. set_loop_end ( * loop_end) ; // outside of buffer duration
1604+ src. start ( ) ;
15891605
1590- src. set_loop ( true ) ;
1591- src. set_loop_start ( 0.5 ) ; // outside of buffer duration
1592- src. set_loop_end ( 1.5 ) ; // outside of buffer duration
1593- src. start ( ) ;
1606+ let result = context. start_rendering_sync ( ) ; // should terminate
1607+ let channel = result. get_channel_data ( 0 ) ;
15941608
1595- let result = context. start_rendering_sync ( ) ; // should terminate
1596- let channel = result. get_channel_data ( 0 ) ;
1609+ // Both loop points will be clamped to buffer duration due to rules defined at
1610+ // https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loopstart
1611+ // https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loopend
1612+ // Thus it violates the rule defined in
1613+ // https://webaudio.github.io/web-audio-api/#playback-AudioBufferSourceNode
1614+ // `loopStart >= 0 && loopEnd > 0 && loopStart < loopEnd`
1615+ // Hence the whole buffer should be looped
15971616
1598- // Both loop points will be clamped to buffer duration due to rules defined at
1599- // https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loopstart
1600- // https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loopend
1601- // Thus it violates the rule defined in
1602- // https://webaudio.github.io/web-audio-api/#playback-AudioBufferSourceNode
1603- // `loopStart >= 0 && loopEnd > 0 && loopStart < loopEnd`
1604- // Hence the whole buffer should be looped
1605-
1606- let mut expected = vec ! [ 0. ; length] ;
1607- for i in ( 0 ..length) . step_by ( buffer_size) {
1608- expected[ i] = 1. ;
1609- }
1617+ let mut expected = vec ! [ 0. ; length] ;
1618+ for i in ( 0 ..length) . step_by ( buffer_size) {
1619+ expected[ i] = 1. ;
1620+ }
16101621
1611- assert_float_eq ! ( channel[ ..] , expected[ ..] , abs_all <= 0. ) ;
1622+ assert_float_eq ! ( channel[ ..] , expected[ ..] , abs_all <= 0. ) ;
1623+ } ) ;
16121624 }
16131625
16141626 #[ test]
16151627 // regression test for #452
1616- // - fast track
16171628 // - duration not set so `self.duration` is `f64::MAX`
16181629 // - stop time is > buffer length
16191630 fn test_end_of_file_fast_track_2 ( ) {
@@ -1643,7 +1654,6 @@ mod tests {
16431654
16441655 #[ test]
16451656 // regression test for #452
1646- // - fals track
16471657 // - duration not set so `self.duration` is `f64::MAX`
16481658 // - stop time is > buffer length
16491659 fn test_end_of_file_slow_track_2 ( ) {
0 commit comments