diff --git a/binding/dotnet/PvSpeaker/PvSpeaker.cs b/binding/dotnet/PvSpeaker/PvSpeaker.cs index adcfc85..9671a2b 100644 --- a/binding/dotnet/PvSpeaker/PvSpeaker.cs +++ b/binding/dotnet/PvSpeaker/PvSpeaker.cs @@ -107,28 +107,6 @@ private static IntPtr ImportResolver(string libraryName, Assembly assembly, DllI [DllImport(LIBRARY, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr pv_speaker_version(); - /// - /// Factory method for creating instances of PvSpeaker. - /// - /// - /// The sample rate of the audio to be played. - /// - /// - /// The number of bits per sample of the audio to be played. - /// - /// - /// The size in seconds of the internal buffer used to buffer PCM data - /// - i.e. internal circular buffer will be of size `sampleRate` * `bufferSizeSecs`. - /// - /// - /// The index of the audio device to play audio from. A value of (-1) will use the default audio device. - /// - /// An instance of PvSpeaker. - public static PvSpeaker Create(int sampleRate, int bitsPerSample, int bufferSizeSecs = 20, int deviceIndex = -1) - { - return new PvSpeaker(sampleRate, bitsPerSample, bufferSizeSecs, deviceIndex); - } - /// /// Constructor for PvSpeaker. /// @@ -145,7 +123,7 @@ public static PvSpeaker Create(int sampleRate, int bitsPerSample, int bufferSize /// /// The index of the audio device to play audio from. A value of (-1) will use the default audio device. /// - private PvSpeaker(int sampleRate, int bitsPerSample, int bufferSizeSecs, int deviceIndex) + public PvSpeaker(int sampleRate, int bitsPerSample, int bufferSizeSecs = 20, int deviceIndex = -1) { if (sampleRate <= 0) { @@ -213,7 +191,6 @@ public void Stop() /// Number of samples that were successfully written. public int Write(byte[] pcm) { - // Create a pointer to the byte array to pass to `pv_speaker_write` . GCHandle pinnedArray = GCHandle.Alloc(pcm, GCHandleType.Pinned); IntPtr pcmPtr = pinnedArray.AddrOfPinnedObject(); @@ -236,8 +213,6 @@ public int Write(byte[] pcm) public int Flush(byte[] pcm = null) { pcm = pcm ?? Array.Empty(); - - // Create a pointer to the byte array to pass to `pv_speaker_flush`. GCHandle pinnedArray = GCHandle.Alloc(pcm, GCHandleType.Pinned); IntPtr pcmPtr = pinnedArray.AddrOfPinnedObject(); diff --git a/binding/dotnet/PvSpeakerTest/MainTest.cs b/binding/dotnet/PvSpeakerTest/MainTest.cs index 58950f8..c6499b6 100644 --- a/binding/dotnet/PvSpeakerTest/MainTest.cs +++ b/binding/dotnet/PvSpeakerTest/MainTest.cs @@ -27,7 +27,7 @@ public class MainTest [TestMethod] public void TestInit() { - PvSpeaker speaker = PvSpeaker.Create(SAMPLE_RATE, BITS_PER_SAMPLE, BUFFER_SIZE_SECS, deviceIndex: 0); + var speaker = new PvSpeaker(SAMPLE_RATE, BITS_PER_SAMPLE, BUFFER_SIZE_SECS, deviceIndex: 0); Assert.IsNotNull(speaker); Assert.IsTrue(speaker.SampleRate == SAMPLE_RATE); Assert.IsTrue(speaker.BitsPerSample == BITS_PER_SAMPLE); @@ -40,7 +40,7 @@ public void TestInit() [TestMethod] public void TestStartStop() { - using (PvSpeaker speaker = PvSpeaker.Create(SAMPLE_RATE, BITS_PER_SAMPLE, BUFFER_SIZE_SECS, deviceIndex: 0)) + using (var speaker = new PvSpeaker(SAMPLE_RATE, BITS_PER_SAMPLE, BUFFER_SIZE_SECS, deviceIndex: 0)) { Assert.IsFalse(speaker.IsStarted); speaker.Start(); @@ -72,7 +72,7 @@ public void TestStartStop() [TestMethod] public void TestWriteFlush() { - using (PvSpeaker speaker = PvSpeaker.Create(SAMPLE_RATE, BITS_PER_SAMPLE, BUFFER_SIZE_SECS, deviceIndex: 0)) + using (var speaker = new PvSpeaker(SAMPLE_RATE, BITS_PER_SAMPLE, BUFFER_SIZE_SECS, deviceIndex: 0)) { speaker.Start(); diff --git a/demo/dotnet/PvSpeakerDemo/PvSpeakerDemo.cs b/demo/dotnet/PvSpeakerDemo/PvSpeakerDemo.cs index 6fb2407..0955f83 100644 --- a/demo/dotnet/PvSpeakerDemo/PvSpeakerDemo.cs +++ b/demo/dotnet/PvSpeakerDemo/PvSpeakerDemo.cs @@ -214,7 +214,7 @@ static void Main(string[] args) { WavFileInfo wavInfo = GetWavFileInfo(inputWavPath); - using (PvSpeaker speaker = PvSpeaker.Create( + using (var speaker = new PvSpeaker( sampleRate: wavInfo.SampleRate, bitsPerSample: wavInfo.BitsPerSample, bufferSizeSecs: bufferSizeSecs,