Example #1
0
        private static unsafe int GetInt(SfCommand command)
        {
            var i = default(int);

            sf_command((SndFile__ *)null, command, &i, sizeof(int));
            return(i);
        }
Example #2
0
 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);
     }
 }
Example #3
0
        private static bool GetBool([NotNull] SndFile sndFile, SfCommand command)
        {
            if (sndFile == null)
            {
                throw new ArgumentNullException(nameof(sndFile));
            }

            return(SetBool(sndFile, command, false));
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }
Example #6
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);
        }
Example #7
0
        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());
            }
        }
Example #8
0
        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);
        }
Example #9
0
        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));
            }
        }
Example #10
0
        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));
            }
        }
Example #11
0
        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);
            }
        }
Example #12
0
 private static extern unsafe int sf_command(SndFile__ *sndFile, SfCommand cmd, void *data, int dataSize);
Example #13
0
 private static SfFormatInfo?GetFormatInfo(SfCommand command, int format)
 {
     return(GetStructure(null, command, new SfFormatInfo(format), 0));
 }