NewTOAPIA.Media.WinMM.WaveOutputPort.CreateOutputPort C# (CSharp) Method

CreateOutputPort() public static method

Help the user create an output device by specifying a few key parameters.
public static CreateOutputPort ( int deviceID, int channels, int sampleRate, int bitsPerSample ) : WaveOutputPort
deviceID int
channels int
sampleRate int
bitsPerSample int
return WaveOutputPort
        public static WaveOutputPort CreateOutputPort(int deviceID, int channels, int sampleRate, int bitsPerSample)
        {
            int bytesPerSample = bitsPerSample / 8;

            WAVEFORMATEX wfx = WAVEFORMATEX.CreatePCMFormat(channels, sampleRate, bitsPerSample);

            // Query to see if the specified format is supported
            IntPtr tmpHandle = new IntPtr();
            MMSYSERROR result = winmm.waveOutOpen(ref tmpHandle, deviceID, wfx, null, IntPtr.Zero, winmm.WAVE_FORMAT_QUERY);

            // If there was any error, return null
            if (winmm.MMSYSERR_NOERROR != result)
                return null;

            WaveOutputPort outPort = new WaveOutputPort(deviceID, wfx);
            
            return outPort;
        }