Hi Justin,

Adding looping is a great idea. I think it should be at the Sound3D
level, not the driver. The drivers are used to calculate
transformation based on the 3D position of the sound and the
listener.

Cheers,

J.

On Feb 28, 12:37 am, "[email protected]" <[email protected]>
wrote:
> Thought this code might be useful.
>
> I gave up trying to extend SimplePanVolumeDriver to allow me access to  
> the sound channel to repeat sound.  I wonder if maybe using 'video'  
> for playing sound is a better approach... but not my code/project so I  
> went for a quick fix to help a friend.  Perhaps amend  
> SimplePanVolumeDriver to provide this functionality, or feel free to  
> add this to the repository as a short term work around for users  
> needing this... it works.
>
> ( PS well done away team on the Molehill code really interested to try  
> it, can't wait for the haXe port )
>
> Cheers Justin
>
> ( ps: sorry - I may have tried to put [haXe] in subject line so this  
> is second attempt ! but it is as3 )
>
> package away3d.audio.drivers
> {
>      import flash.media.*;
>      import flash.geom.*;
>      import flash.events.*;
>
>      public class RepeatPanVolumeDriver extends AbstractSound3DDriver  
> implements ISound3DDriver
>      {
>          private var _sound_chan:SoundChannel;
>          private var _sound_tf:SoundTransform;
>
>          private var _pause_position : Number;
>
>          public function RepeatPanVolumeDriver()
>          {
>              super();
>
>                  _sound_tf = new SoundTransform;
>          }
>
>          public function play() : void
>          {
>              var pos : Number;
>
>              if (!_src)
>                  throw new Error('SimplePanVolumeDriver.play(): No  
> sound source to play.');
>
>              _playing = true;
>
>              // Update sound transform first. This has not happened  
> while
>              // the sound was not playing, so needs to be done now.
>              _updateSoundTransform();
>
>              // Start playing. If paused, resume from pause position.  
> Else,
>              // start from beginning of file.
>              pos = _paused? _pause_position : 0;
>              _sound_chan = _src.play(pos, 0, _sound_tf);
>
>             /*************************************** NEW REPEAT SOUND CODE  
> ****************************************/      
>              _sound_chan.addEventListener( Event.SOUND_COMPLETE,  
> repeatSound );
>
>          }
>
>          private function repeatSound( e: Event )
>          {
>              //trace('repeating');
>              play();
>
>          }
>
>          /
> *************************************************************************** 
> *********/
>
>          public function pause() : void
>          {
>              _paused = true;
>              _pause_position = _sound_chan.position;
>              _sound_chan.stop();
>          }
>
>          public function stop() : void
>          {
>              _sound_chan.stop();
>          }
>
>          public override function updateReferenceVector(v:Vector3D) :  
> void
>          {
>              super.updateReferenceVector(v);
>
>              // Only update sound transform while playing
>              if (_playing)
>                  _updateSoundTransform();
>          }
>
>          private function _updateSoundTransform() : void
>          {
>              var r : Number;
>              var r2 : Number;
>              var azimuth:Number;
>
>              azimuth = Math.atan2(_ref_v.x, _ref_v.z);
>              if (azimuth < -1.5707963)
>                  azimuth = -(1.5707963 + (azimuth % 1.5707963));
>              else if (azimuth > 1.5707963)
>                  azimuth = 1.5707963 - (azimuth % 1.5707963);
>
>              // Divide by a number larger than pi/2, to make sure
>              // that pan is never full +/-1.0, muting one channel
>              // completely, which feels very unnatural.
>              _sound_tf.pan = (azimuth/1.7);
>
>              // Offset radius so that max value for volume curve is 1,
>              // (i.e. y~=1 for r=0.) Also scale according to configured
>              // driver scale value.
>              r = (_ref_v.length / _scale) + 0.28209479;
>              r2 = r*r;
>
>              // Volume is calculated according to the formula for
>              // sound intensity, I = P / (4 * pi * r^2)
>              // Avoid division by zero.
>              if (r2>0)   _sound_tf.volume = (1 / (12.566 *  
> r2));     // 1 / 4pi * r^2
>              else        _sound_tf.volume = 1;
>
>              // Alter according to user-specified volume
>              _sound_tf.volume *= _mute? 0 : _volume;
>
>              if (_sound_chan)
>                  _sound_chan.soundTransform = _sound_tf;
>          }
>      }
>
>
>
>
>
>
>
> }

Reply via email to