1
- //
1
+ //
2
2
// Copyright (c) .NET Foundation and Contributors
3
3
// See LICENSE file in the project root for full license information.
4
4
//
@@ -16,7 +16,7 @@ namespace AudioPlayer
16
16
/// You have to provide pin configuration for I2S communication and a full path to the
17
17
/// WAV file you want to play.
18
18
/// </summary>
19
- public class I2sWavPlayer : IDisposable
19
+ public class I2SWavPlayer : IDisposable
20
20
{
21
21
public enum Bus
22
22
{
@@ -28,15 +28,15 @@ public enum Bus
28
28
private readonly FileStream _stream ;
29
29
30
30
/// <summary>
31
- /// Creating a new instance of <see cref="I2sWavPlayer " />.
31
+ /// Creating a new instance of <see cref="I2SWavPlayer " />.
32
32
/// </summary>
33
- /// <param name="bus">The I2S bus ID on ESP32 plattforms .</param>
33
+ /// <param name="bus">The I2S bus ID on ESP32 platforms .</param>
34
34
/// <param name="audioFile">Full path to WAV file.</param>
35
35
/// <param name="bckPin">The Pin ID of the BCK pin. (32 for <see cref="Bus.One" />).</param>
36
36
/// <param name="dataPin">The Pin ID of the Data Out pin. (33 for <see cref="Bus.One" />).</param>
37
37
/// <param name="wsPin">The Pin ID of the WS pin. (25 for <see cref="Bus.One" />).</param>
38
38
/// <exception cref="IOException">Throws an IOException if the WAV file provided does not have at least 44 bytes (header).</exception>
39
- public I2sWavPlayer ( Bus bus , string audioFile , int bckPin = 32 , int dataPin = 33 , int wsPin = 25 )
39
+ public I2SWavPlayer ( Bus bus , string audioFile , int bckPin = 32 , int dataPin = 33 , int wsPin = 25 )
40
40
{
41
41
switch ( bus )
42
42
{
@@ -65,9 +65,10 @@ public I2sWavPlayer(Bus bus, string audioFile, int bckPin = 32, int dataPin = 33
65
65
66
66
var headerParser = new WavFileHeader ( header ) ;
67
67
68
- _i2S = new I2sDevice ( new I2sConnectionSettings ( 1 )
68
+ _i2S = new I2sDevice ( new I2sConnectionSettings ( ( int ) bus )
69
69
{
70
70
Mode = I2sMode . Master | I2sMode . Tx ,
71
+ //Mode = I2sMode.Master | I2sMode.Tx | I2sMode.Pdm, // Try this if output contains lots of static and poor audio quality
71
72
CommunicationFormat = I2sCommunicationFormat . I2S ,
72
73
73
74
SampleRate = headerParser . SampleRate ,
@@ -127,7 +128,7 @@ private static I2sChannelFormat ToChannelFormat(short channels)
127
128
{
128
129
1 => I2sChannelFormat . OnlyLeft ,
129
130
2 => I2sChannelFormat . RightLeft ,
130
- _ => throw new ArgumentOutOfRangeException ( " channels" , "Only supports either Mono or Stereo WAV files." )
131
+ _ => throw new ArgumentOutOfRangeException ( nameof ( channels ) , "Only supports either Mono or Stereo WAV files." )
131
132
} ;
132
133
}
133
134
@@ -139,9 +140,8 @@ private static I2sBitsPerSample ToBitsPerSample(short bitsPerSample)
139
140
16 => I2sBitsPerSample . Bit16 ,
140
141
24 => I2sBitsPerSample . Bit24 ,
141
142
32 => I2sBitsPerSample . Bit32 ,
142
- _ => throw new ArgumentOutOfRangeException ( "bitsPerSample" ,
143
- "Only 8, 16, 24 or 32 bits per sample are supported." )
143
+ _ => throw new ArgumentOutOfRangeException ( nameof ( bitsPerSample ) , "Only 8, 16, 24 or 32 bits per sample are supported." )
144
144
} ;
145
145
}
146
146
}
147
- }
147
+ }
0 commit comments