private void WriteStreamPrivate(PaBuffer buffer, bool isUnsafe = false, bool isNonInterleaved = false)
 {
     if (numOutputChannels == 0)
     {
         throw new InvalidOperationException("Cannot write to a stream with no output channels.");
     }
     if (numOutputChannels != buffer.Channels)
     {
         throw new ArgumentException(
                   $"Expected buffer with {numOutputChannels} channels but got {buffer.Channels}.",
                   nameof(buffer));
     }
     if (!isUnsafe)
     {
         var expectedType = SampleFormatToType(outputSampleFormat);
         if (expectedType == typeof(PaBuffer))
         {
             throw new InvalidOperationException(
                       "To ensure memory safety, this overload of WriteStream is not supported for streams with " +
                       "custom sample formats. Use WriteStream(PaBuffer) instead.");
         }
         var formatNonInterleaved = (outputSampleFormat & PaSampleFormat.paNonInterleaved) != 0;
         if (isNonInterleaved && !formatNonInterleaved)
         {
             throw new InvalidOperationException(
                       "Only streams with non-interleaved sample formats support this overload of WriteStream, " +
                       "Use WriteStream(PaBuffer<T>) instead.");
         }
         if (!isNonInterleaved && formatNonInterleaved)
         {
             throw new InvalidOperationException(
                       "Only streams with interleaved sample formats suppoort this overload of WriteStream. " +
                       "Use WriteStream(PaNonInterleavedBuffer<T>) instead.");
         }
         if (expectedType != buffer.GetType())
         {
             throw new ArgumentException(
                       $"Expected a buffer of type {expectedType} for the sample format, but got {buffer.GetType()}.",
                       nameof(buffer));
         }
     }
     PaBindings.Pa_ReadStream(stream, buffer.Pointer, (unsigned_long_t)buffer.Frames);
 }