Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hwsmm committed Oct 24, 2024
1 parent cc00d81 commit 9887f9c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
12 changes: 0 additions & 12 deletions osu.Framework.Tests/Audio/SampleBassTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,5 @@ public void TestPlayingUpdatedAfterInlineStop()
bass.RunOnAudioThread(() => channel.Stop());
Assert.That(channel.Playing, Is.False);
}

[Test]
public void TestChannelLifetime()
{
channel = sample.Play();
bass.Update();

bass.RunOnAudioThread(() => channel.Stop());
bass.Update();

Assert.That(channel.IsDisposed, Is.True);
}
}
}
5 changes: 2 additions & 3 deletions osu.Framework.Tests/Visual/Audio/TestSceneSampleChannels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ public void TestPlay()
}

[Test]
public void TestDoesNotRestart()
public void TestChannelLifetime()
{
SampleChannel channel = null;

AddStep("play channel 1 sample", () => channel = sample.Play());
AddUntilStep("wait for channel 1 to end", () => !channel.Playing);
AddStep("play channel 1 again", () => channel.Play());

int audioFrames = 0;
AddStep("begin tracking audio frames", () =>
Expand All @@ -58,7 +57,7 @@ public void TestDoesNotRestart()
});

AddUntilStep("wait for two audio frames", () => audioFrames >= 2);
AddAssert("channel 1 not playing", () => !channel.Playing);
AddAssert("channel 1 disposed", () => channel.IsDisposed);
}

[Test]
Expand Down
2 changes: 0 additions & 2 deletions osu.Framework/Audio/Sample/SampleChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ protected override void UpdateState()

public virtual bool Looping { get; set; }

public override bool IsAlive => base.IsAlive && Playing;

public virtual ChannelAmplitudes CurrentAmplitudes { get; } = ChannelAmplitudes.Empty;

#region Mixing
Expand Down
17 changes: 17 additions & 0 deletions osu.Framework/Audio/Sample/SampleChannelBass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public override bool Playing
/// </summary>
private volatile bool userRequestedPlay;

/// <summary>
/// <c>true</c> if the user last called <see cref="Stop"/>.
/// <c>false</c> if the user last called <see cref="Play"/> or this channel finished playback.
/// </summary>
private volatile bool userRequestedStop;

/// <summary>
/// Whether the playback start has been enqueued.
/// </summary>
Expand All @@ -55,6 +61,8 @@ public override bool Looping
}
}

public override bool IsAlive => base.IsAlive && (Playing || userRequestedStop);

private bool hasChannel => channel != 0;

public override ChannelAmplitudes CurrentAmplitudes => (bassAmplitudeProcessor ??= new BassAmplitudeProcessor(this)).CurrentAmplitudes;
Expand Down Expand Up @@ -99,8 +107,13 @@ protected override void UpdateState()
playing = true;
break;

case PlaybackState.Paused when userRequestedStop:
playing = false;
break;

default:
playing = false;
userRequestedStop = false;
break;
}
}
Expand All @@ -119,6 +132,8 @@ public override void Play()
{
userRequestedPlay = true;

userRequestedStop = false;

// Pin Playing and IsAlive to true so that the channel isn't killed by the next update. This is only reset after playback is started.
enqueuedPlaybackStart = true;

Expand All @@ -138,6 +153,8 @@ public override void Stop()
{
userRequestedPlay = false;

userRequestedStop = true;

base.Stop();

EnqueueAction(() =>
Expand Down

0 comments on commit 9887f9c

Please sign in to comment.