Skip to content

Commit

Permalink
SoundTransform: clean up docs and add a couple of examples
Browse files Browse the repository at this point in the history
It's easy to try soundChannel.soundTransform.volume = value and think it is broken, so these examples show that you need to set soundChannel.soundTransform to a value
  • Loading branch information
joshtynjala committed Jun 6, 2024
1 parent 534ddfe commit e2a297d
Showing 1 changed file with 47 additions and 13 deletions.
60 changes: 47 additions & 13 deletions src/openfl/media/SoundTransform.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,74 @@ package openfl.media;
@:final class SoundTransform
{
/**
A value, from 0(none) to 1(all), specifying how much of the left input
A value, from 0 (none) to 1 (all), specifying how much of the left input
is played in the left speaker.
**/
public var leftToLeft:Float;

/**
A value, from 0(none) to 1(all), specifying how much of the left input
A value, from 0 (none) to 1 (all), specifying how much of the left input
is played in the right speaker.
**/
public var leftToRight:Float;

/**
The left-to-right panning of the sound, ranging from -1(full pan left) to
1(full pan right). A value of 0 represents no panning(balanced center
between right and left).
The left-to-right panning of the sound, ranging from -1 (full pan left)
to 1 (full pan right). A value of 0 represents no panning (balanced
center between right and left).
The following example sets the pan to 0.5 (half pan right) when
starting to play a Sound.
```haxe
var transform = new SoundTransform(1.0, 0.5);
var soundChannel = sound.play(0, 0, transform);
```
The following example sets the pan to -1 (full pan left) for a
SoundChannel that is currently playing.
```haxe
var transform = soundChannel.soundTransform;
transform.pan = -1.0;
soundChannel.soundTransform = transform;
```
@see [Controlling sound volume and panning](https://books.openfl.org/openfl-developers-guide/working-with-sound/controlling-sound-volume-and-panning.html)
**/
public var pan:Float;

/**
A value, from 0(none) to 1(all), specifying how much of the right input
is played in the left speaker.
A value, from 0 (none) to 1 (all), specifying how much of the right
input is played in the left speaker.
**/
public var rightToLeft:Float;

/**
A value, from 0(none) to 1(all), specifying how much of the right input
is played in the right speaker.
A value, from 0 (none) to 1 (all), specifying how much of the right
input is played in the right speaker.
**/
public var rightToRight:Float;

/**
The volume, ranging from 0(silent) to 1(full volume).
The volume, ranging from 0 (silent) to 1 (full volume).
The following example sets the volume to 0.5 (half volume) when
starting to play a Sound.
```haxe
var transform = new SoundTransform(0.5);
var soundChannel = sound.play(0, 0, transform);
```
The following example sets the volume to 0.0 (silent) for a
SoundChannel that is currently playing.
```haxe
var transform = soundChannel.soundTransform;
transform.volume = 0.0;
soundChannel.soundTransform = transform;
```
@see [Controlling sound volume and panning](https://books.openfl.org/openfl-developers-guide/working-with-sound/controlling-sound-volume-and-panning.html)
**/
Expand All @@ -57,10 +91,10 @@ package openfl.media;
/**
Creates a SoundTransform object.
@param vol The volume, ranging from 0(silent) to 1(full volume).
@param vol The volume, ranging from 0 (silent) to 1 (full volume).
@param panning The left-to-right panning of the sound, ranging from -1
(full pan left) to 1(full pan right). A value of 0
represents no panning(center).
(full pan left) to 1 (full pan right). A value of 0
represents no panning (center).
**/
public function new(vol:Float = 1, panning:Float = 0)
{
Expand Down

0 comments on commit e2a297d

Please sign in to comment.