-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathOpenALSound.cs
93 lines (77 loc) · 1.99 KB
/
OpenALSound.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// <copyright file="OpenALSound.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>
namespace FinalEngine.Audio.OpenAL;
using System;
using System.Diagnostics.CodeAnalysis;
using CASLSound = CASL.Sound;
using ICASLSound = CASL.ISound;
internal sealed class OpenALSound : ISound, IDisposable
{
private bool isDisposed;
private ICASLSound? sound;
[ExcludeFromCodeCoverage]
internal OpenALSound(string filePath)
: this(new CASLSound(filePath))
{
ArgumentException.ThrowIfNullOrWhiteSpace(filePath, nameof(filePath));
}
internal OpenALSound(ICASLSound sound)
{
this.sound = sound ?? throw new ArgumentNullException(nameof(sound));
}
public bool IsLooping
{
get
{
ObjectDisposedException.ThrowIf(this.isDisposed, this);
return this.sound!.IsLooping;
}
set
{
ObjectDisposedException.ThrowIf(this.isDisposed, this);
this.sound!.IsLooping = value;
}
}
public float Volume
{
get
{
ObjectDisposedException.ThrowIf(this.isDisposed, this);
return this.sound!.Volume;
}
set
{
ObjectDisposedException.ThrowIf(this.isDisposed, this);
this.sound!.Volume = value;
}
}
public void Dispose()
{
if (this.isDisposed)
{
return;
}
if (this.sound != null)
{
this.sound.Dispose();
this.sound = null;
}
this.isDisposed = true;
}
public void Pause()
{
ObjectDisposedException.ThrowIf(this.isDisposed, this);
this.sound!.Pause();
}
public void Play()
{
ObjectDisposedException.ThrowIf(this.isDisposed, this);
this.sound!.Play();
}
public void Stop()
{
ObjectDisposedException.ThrowIf(this.isDisposed, this);
this.sound!.Stop();
}
}