private static unsafe int GetInt(SfCommand command) { var i = default(int); sf_command((SndFile__ *)null, command, &i, sizeof(int)); return(i); }
private static bool SetStructure <T>(SndFile sndFile, SfCommand command, T structure, int valid) where T : struct { using (var m = new Marshaller <T>(structure)) { var i = sf_command(sndFile, command, m.Address, m.Size); return(i == valid); } }
private static bool GetBool([NotNull] SndFile sndFile, SfCommand command) { if (sndFile == null) { throw new ArgumentNullException(nameof(sndFile)); } return(SetBool(sndFile, command, false)); }
private static unsafe int sf_command([NotNull] SndFile sndFile, SfCommand cmd, void *data, int dataSize) { if (sndFile == null) { throw new ArgumentNullException(nameof(sndFile)); } var i = sf_command(sndFile.Handle, cmd, data, dataSize); return(i); }
private static unsafe bool SetLong([NotNull] SndFile sndFile, SfCommand command, long value) { if (sndFile == null) { throw new ArgumentNullException(nameof(sndFile)); } var i = sf_command(sndFile, command, &value, sizeof(long)); return(i == 0); }
private static unsafe string GetString([CanBeNull] SndFile__ *sndFile, SfCommand command, int size) { if (size <= 0) { throw new ArgumentOutOfRangeException(nameof(size)); } var ptr = stackalloc sbyte[size]; var cmd = sf_command(sndFile, command, ptr, size); var str = new string(ptr); return(str); }
private static unsafe T?GetStructure <T>([CanBeNull] SndFile sndFile, SfCommand command, T structure, int valid) where T : struct { using (var m = new Marshaller <T>(structure)) { var handle = sndFile != null ? sndFile.Handle : null; var i = sf_command(handle, command, m.Address, m.Size); if (i != valid) { return(null); } return(m.Pop()); } }
private static unsafe double?GetDouble([NotNull] SndFile sndFile, SfCommand command, int match) { if (sndFile == null) { throw new ArgumentNullException(nameof(sndFile)); } var d = default(double); var i = sf_command(sndFile, command, &d, sizeof(double)); if (i != match) { return(null); } return(d); }
private static unsafe bool SetDouble([NotNull] SndFile sndFile, SfCommand command, double value) { if (sndFile == null) { throw new ArgumentNullException(nameof(sndFile)); } var i = sf_command(sndFile, command, &value, sizeof(double)); switch (i) { case SF_TRUE: return(true); case SF_FALSE: return(false); default: throw new ArgumentOutOfRangeException(nameof(i)); } }
private static bool SetBool([NotNull] SndFile sndFile, SfCommand command, bool value) { if (sndFile == null) { throw new ArgumentNullException(nameof(sndFile)); } var i = sf_command(sndFile, command, IntPtr.Zero, value ? SF_TRUE : SF_FALSE); switch (i) { case SF_TRUE: return(true); case SF_FALSE: return(false); default: throw new ArgumentOutOfRangeException(nameof(i)); } }
private static unsafe double[] GetDoubles([NotNull] SndFile sndFile, SfCommand command, int match) { if (sndFile == null) { throw new ArgumentNullException(nameof(sndFile)); } var doubles = new double[sndFile.Format.Channels]; fixed(double *d = doubles) { var i = sf_command(sndFile.Handle, command, d, sizeof(double) * doubles.Length); if (i != match) { return(null); } return(doubles); } }
private static extern unsafe int sf_command(SndFile__ *sndFile, SfCommand cmd, void *data, int dataSize);
private static SfFormatInfo?GetFormatInfo(SfCommand command, int format) { return(GetStructure(null, command, new SfFormatInfo(format), 0)); }