-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathApp.Sounds.cs
More file actions
131 lines (98 loc) · 3.53 KB
/
Copy pathApp.Sounds.cs
File metadata and controls
131 lines (98 loc) · 3.53 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System.Windows;
using NAudio.Wave;
using NAudio.Wave.SampleProviders;
namespace MarvinsAIRA
{
public partial class App : Application
{
private readonly WaveOutEvent _sounds_clickWaveOutEvent = new();
private WaveStream? _sounds_clickWaveStream;
private VolumeSampleProvider? _sounds_clickVolumeSampleProvider;
private readonly WaveOutEvent _sounds_absWaveOutEvent = new();
private LoopStream? _sounds_absLoopStream;
private SmbPitchShiftingSampleProvider? _sounds_absPitchShiftingSampleProvider;
private VolumeSampleProvider? _sounds_absVolumeSampleProvider;
private bool _sounds_initialized = false;
private void InitializeSounds()
{
WriteLine( "InitializeSounds called.", true );
_sounds_initialized = false;
WriteLine( "...loading click sound..." );
var resourceStream = GetResourceStream( new Uri( "pack://application:,,,/click.wav" ) );
_sounds_clickWaveStream = new WaveFileReader( resourceStream.Stream );
_sounds_clickVolumeSampleProvider = new VolumeSampleProvider( _sounds_clickWaveStream.ToSampleProvider() );
WriteLine( "...click sound loaded..." );
try
{
WriteLine( "...initializing click wave out event..." );
_sounds_clickWaveOutEvent.Init( _sounds_clickVolumeSampleProvider );
_sounds_clickWaveOutEvent.Volume = 1;
WriteLine( "...click wave out event initialized." );
}
catch ( Exception exception )
{
WriteLine( $"Failed to create click wave out event: {exception.Message.Trim()}" );
}
WriteLine( "...loading ABS sound..." );
resourceStream = GetResourceStream( new Uri( "pack://application:,,,/abs.wav" ) );
_sounds_absLoopStream = new LoopStream( new WaveFileReader( resourceStream.Stream ) );
_sounds_absPitchShiftingSampleProvider = new SmbPitchShiftingSampleProvider( _sounds_absLoopStream.ToSampleProvider() );
_sounds_absVolumeSampleProvider = new VolumeSampleProvider( _sounds_absPitchShiftingSampleProvider );
WriteLine( "...ABS sound loaded..." );
try
{
WriteLine( "...initializing ABS wave out event..." );
_sounds_absWaveOutEvent.Init( _sounds_absVolumeSampleProvider );
_sounds_absWaveOutEvent.Volume = 1;
WriteLine( "...ABS wave out event initialized." );
}
catch ( Exception exception )
{
WriteLine( $"Failed to create click wave out event: {exception.Message.Trim()}" );
}
_sounds_initialized = true;
}
public void PlayClick()
{
if ( _sounds_initialized )
{
if ( Settings.EnableClickSound )
{
if ( ( _sounds_clickWaveStream != null ) && ( _sounds_clickVolumeSampleProvider != null ) )
{
_sounds_clickWaveStream.Seek( 0, System.IO.SeekOrigin.Begin );
_sounds_clickVolumeSampleProvider.Volume = Settings.ClickSoundVolume / 100f;
_sounds_clickWaveOutEvent.Play();
}
}
}
}
public void PlayABS()
{
if ( _sounds_initialized )
{
if ( Settings.EnableABSSound )
{
if ( ( _sounds_absLoopStream != null ) && ( _sounds_absPitchShiftingSampleProvider != null ) && ( _sounds_absVolumeSampleProvider != null ) )
{
_sounds_absLoopStream.Seek( 0, System.IO.SeekOrigin.Begin );
_sounds_absVolumeSampleProvider.Volume = Settings.ABSSoundVolume / 100f;
_sounds_absPitchShiftingSampleProvider.PitchFactor = Settings.ABSSoundPitch;
_sounds_absWaveOutEvent.Play();
}
}
}
}
public void StopABS()
{
if ( _sounds_initialized )
{
if ( ( _sounds_absLoopStream != null ) && ( _sounds_absPitchShiftingSampleProvider != null ) )
{
_sounds_absWaveOutEvent.Stop();
}
}
}
}
}