예제 #1
0
        /// <summary>
        /// Returns true if the <paramref name="result"/> value is valid for the <paramref name="command"/>.
        /// </summary>
        /// <param name="sndfile">Pointer to the soundfile that was used when executing the command.</param>
        /// <param name="command">LibsndfileCommand type used.</param>
        /// <param name="result">Result returned from sf_command.</param>
        /// <returns>True/False based on the success of the call for the given result value.</returns>
        internal static bool IsValidResult(IntPtr sndfile, LibsndfileCommand command, int result)
        {
            switch (command)
            {
            case LibsndfileCommand.GetLibVersion:
                return(result > 0);

            case LibsndfileCommand.GetLogInfo:
                return(sndfile != IntPtr.Zero ? result > 0 : result == 0);

            case LibsndfileCommand.CalcSignalMax:
            case LibsndfileCommand.CalcNormSignalMax:
            case LibsndfileCommand.CalcMaxAllChannels:
            case LibsndfileCommand.CalcNormMaxAllChannels:
            case LibsndfileCommand.GetSimpleFormatCount:
            case LibsndfileCommand.GetSimpleFormat:
            case LibsndfileCommand.GetFormatInfo:
            case LibsndfileCommand.GetFormatMajorCount:
            case LibsndfileCommand.GetFormatMajor:
            case LibsndfileCommand.GetFormatSubtypeCount:
            case LibsndfileCommand.GetFormatSubtype:
            case LibsndfileCommand.UpdateHeaderNow:
            case LibsndfileCommand.FileTruncate:
            case LibsndfileCommand.SetRawStartOffset:
            case LibsndfileCommand.GetEmbedFileInfo:
            case LibsndfileCommand.SetVbrEncodingQuality:
                return(result == 0);

            case LibsndfileCommand.GetSignalMax:
            case LibsndfileCommand.GetMaxAllChannels:
            case LibsndfileCommand.SetNormFloat:
            case LibsndfileCommand.SetNormDouble:
            case LibsndfileCommand.GetNormFloat:
            case LibsndfileCommand.GetNormDouble:
            case LibsndfileCommand.SetScaleFloatIntRead:
            case LibsndfileCommand.SetScaleIntFloatWrite:
            case LibsndfileCommand.SetAddPeakChunk:
            case LibsndfileCommand.SetUpdateHeaderAuto:
            case LibsndfileCommand.SetClipping:
            case LibsndfileCommand.GetClipping:
            case LibsndfileCommand.RawDataNeedsEndswap:
            case LibsndfileCommand.GetBroadcastInfo:
            case LibsndfileCommand.SetBroadcastInfo:
            case LibsndfileCommand.GetLoopInfo:
            case LibsndfileCommand.GetInstrument:
            case LibsndfileCommand.SetInstrument:
                return(result == 0 || result == 1);

            case LibsndfileCommand.WavexGetAmbisonic:
            case LibsndfileCommand.WavexSetAmbisonic:
                return((LibsndfileMode)result == LibsndfileMode.AmbisonicNone ||
                       (LibsndfileMode)result == LibsndfileMode.AmbisonicBFormat ||
                       (LibsndfileMode)result == LibsndfileMode.False);
            }
            return(false);
        }
        /// <summary>
        /// Returns true if the <paramref name="result"/> value is valid for the <paramref name="command"/>.
        /// </summary>
        /// <param name="sndfile">Pointer to the soundfile that was used when executing the command.</param>
        /// <param name="command">LibsndfileCommand type used.</param>
        /// <param name="result">Result returned from sf_command.</param>
        /// <returns>True/False based on the success of the call for the given result value.</returns>
        internal static bool IsValidResult(IntPtr sndfile, LibsndfileCommand command, int result)
        {
            switch (command)
            {
                case LibsndfileCommand.GetLibVersion:
                    return result > 0;

                case LibsndfileCommand.GetLogInfo:
                    return sndfile != IntPtr.Zero ? result > 0 : result == 0;

                case LibsndfileCommand.CalcSignalMax:
                case LibsndfileCommand.CalcNormSignalMax:
                case LibsndfileCommand.CalcMaxAllChannels:
                case LibsndfileCommand.CalcNormMaxAllChannels:
                case LibsndfileCommand.GetSimpleFormatCount:
                case LibsndfileCommand.GetSimpleFormat:
                case LibsndfileCommand.GetFormatInfo:
                case LibsndfileCommand.GetFormatMajorCount:
                case LibsndfileCommand.GetFormatMajor:
                case LibsndfileCommand.GetFormatSubtypeCount:
                case LibsndfileCommand.GetFormatSubtype:
                case LibsndfileCommand.UpdateHeaderNow:
                case LibsndfileCommand.FileTruncate:
                case LibsndfileCommand.SetRawStartOffset:
                case LibsndfileCommand.GetEmbedFileInfo:
                case LibsndfileCommand.SetVbrEncodingQuality:
                    return result == 0;

                case LibsndfileCommand.GetSignalMax:
                case LibsndfileCommand.GetMaxAllChannels:
                case LibsndfileCommand.SetNormFloat:
                case LibsndfileCommand.SetNormDouble:
                case LibsndfileCommand.GetNormFloat:
                case LibsndfileCommand.GetNormDouble:
                case LibsndfileCommand.SetScaleFloatIntRead:
                case LibsndfileCommand.SetScaleIntFloatWrite:
                case LibsndfileCommand.SetAddPeakChunk:
                case LibsndfileCommand.SetUpdateHeaderAuto:
                case LibsndfileCommand.SetClipping:
                case LibsndfileCommand.GetClipping:
                case LibsndfileCommand.RawDataNeedsEndswap:
                case LibsndfileCommand.GetBroadcastInfo:
                case LibsndfileCommand.SetBroadcastInfo:
                case LibsndfileCommand.GetLoopInfo:
                case LibsndfileCommand.GetInstrument:
                case LibsndfileCommand.SetInstrument:
                    return result == 0 || result == 1;

                case LibsndfileCommand.WavexGetAmbisonic:
                case LibsndfileCommand.WavexSetAmbisonic:
                    return ((LibsndfileMode)result == LibsndfileMode.AmbisonicNone ||
                            (LibsndfileMode)result == LibsndfileMode.AmbisonicBFormat ||
                            (LibsndfileMode)result == LibsndfileMode.False);
            }
            return false;
        }
예제 #3
0
        /// <summary>
        /// Attempts to execute the <paramref name="command"/> against the <paramref name="sndfile"/> audio
        /// file while either passing or receiving data through the <paramref name="data"/> buffer.
        /// </summary>
        /// <param name="sndfile">Audio file we run this command against.
        /// Use NULL if you wish to run a static command against the library.</param>
        /// <param name="command"><see cref="NLibsndfile.Native.LibsndfileCommand"/> to run against the given audio file.</param>
        /// <param name="data">Ref long(long*) buffer passing or receiving data based on <paramref name="command"/> specifications.</param>
        /// <param name="size">Size, in bytes, of a long.</param>
        /// <returns>Returns a specific value based on the <paramref name="command"/>.</returns>
        public int Command(IntPtr sndfile, LibsndfileCommand command, ref long data, int size)
        {
            if (sndfile == IntPtr.Zero && !LibsndfileCommandUtilities.IsStaticCommand(command))
            {
                throw new ArgumentException("File handle is invalid/closed.");
            }

            var retval = m_Api.Command(sndfile, command, ref data, size);

            if (!LibsndfileCommandUtilities.IsValidResult(sndfile, command, retval))
            {
                throw new LibsndfileException(string.Format("Command {0} returned an invalid result.", command));
            }

            return(retval);
        }
 /// <summary>
 /// Returns true if the <paramref name="command"/> doesn't require a handle to a soundfile. 
 /// </summary>
 /// <param name="command">Command to check soundfile parameter requirements.</param>
 /// <returns>True/False based on whether this command type requires a open soundfile.</returns>
 internal static bool IsStaticCommand(LibsndfileCommand command)
 {
     switch (command)
     {
         case LibsndfileCommand.GetLibVersion:
         case LibsndfileCommand.GetSimpleFormatCount:
         case LibsndfileCommand.GetSimpleFormat:
         case LibsndfileCommand.GetFormatInfo:
         case LibsndfileCommand.GetFormatMajorCount:
         case LibsndfileCommand.GetFormatMajor:
         case LibsndfileCommand.GetFormatSubtypeCount:
         case LibsndfileCommand.GetFormatSubtype:
             return true;
     }
     return false;
 }
예제 #5
0
 /// <summary>
 /// Returns true if the <paramref name="command"/> doesn't require a handle to a soundfile.
 /// </summary>
 /// <param name="command">Command to check soundfile parameter requirements.</param>
 /// <returns>True/False based on whether this command type requires a open soundfile.</returns>
 internal static bool IsStaticCommand(LibsndfileCommand command)
 {
     switch (command)
     {
     case LibsndfileCommand.GetLibVersion:
     case LibsndfileCommand.GetSimpleFormatCount:
     case LibsndfileCommand.GetSimpleFormat:
     case LibsndfileCommand.GetFormatInfo:
     case LibsndfileCommand.GetFormatMajorCount:
     case LibsndfileCommand.GetFormatMajor:
     case LibsndfileCommand.GetFormatSubtypeCount:
     case LibsndfileCommand.GetFormatSubtype:
         return(true);
     }
     return(false);
 }
예제 #6
0
        /// <summary>
        /// Attempts to execute the <paramref name="command"/> against the <paramref name="sndfile"/> audio
        /// file while either passing or receiving data through the <paramref name="data"/> buffer.
        /// </summary>
        /// <param name="sndfile">Audio file we run this command against.
        /// Use NULL if you wish to run a static command against the library.</param>
        /// <param name="command"><see cref="NLibsndfile.Native.LibsndfileCommand"/> to execute</param>
        /// <param name="data">Double[](double*) buffer passing or receiving data based on <paramref name="command"/> specifications.</param>
        /// <param name="size">Size, in bytes, of (double * buffer length)</param>
        /// <returns>Returns a specific value based on the <paramref name="command"/>.</returns>
        public int Command(IntPtr sndfile, LibsndfileCommand command, double[] data, int size)
        {
            if (sndfile == IntPtr.Zero && !LibsndfileCommandUtilities.IsStaticCommand(command))
            {
                throw new ArgumentException("File handle is invalid/closed.");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data", "Data cannot be null.");
            }
            if (data.Length == 0)
            {
                throw new ArgumentNullException("data", "Data must be initialized.");
            }

            var retval = m_Api.Command(sndfile, command, data, size);

            if (!LibsndfileCommandUtilities.IsValidResult(sndfile, command, retval))
            {
                throw new LibsndfileException(string.Format("Command {0} returned an invalid result.", command));
            }

            return(retval);
        }
예제 #7
0
 internal static extern int sf_command(IntPtr sndfile, LibsndfileCommand command, ref int data, int size);
예제 #8
0
 internal static extern int sf_command(IntPtr sndfile, LibsndfileCommand command, double[] data, int size);
예제 #9
0
 internal static extern int sf_command(IntPtr sndfile, LibsndfileCommand command, double[] data, int size);
예제 #10
0
 internal static extern int sf_command(IntPtr sndfile, LibsndfileCommand command, ref long data, int size);
예제 #11
0
 /// <summary>
 /// Attempts to execute the <paramref name="command"/> against the <paramref name="sndfile"/> audio 
 /// file while either passing or receiving data through the <paramref name="data"/> buffer.
 /// </summary>
 /// <param name="sndfile">Audio file we run this command against.
 /// Use NULL if you wish to run a static command against the library.</param>
 /// <param name="command"><see cref="NLibsndfile.Native.LibsndfileCommand"/> to run against the given audio file.</param>
 /// <param name="data">Ref int(int*) buffer for passing or receiving data based on <paramref name="command"/> specifications.</param>
 /// <param name="size">Size, in bytes, of a int.</param>
 /// <returns>Returns a specific value based on the <paramref name="command"/>.</returns>
 public int Command(IntPtr sndfile, LibsndfileCommand command, ref int data, int size)
 {
     return LibsndfileApiNative.sf_command(sndfile, command, ref data, size);
 }
 /// <summary>
 /// Attempts to execute the <paramref name="command"/> against the <paramref name="sndfile"/> audio
 /// file while either passing or receiving data through the <paramref name="data"/> buffer.
 /// </summary>
 /// <param name="sndfile">Audio file we run this command against.
 /// Use NULL if you wish to run a static command against the library.</param>
 /// <param name="command"><see cref="NLibsndfile.Native.LibsndfileCommand"/> to execute</param>
 /// <param name="data">Double[](double*) buffer passing or receiving data based on <paramref name="command"/> specifications.</param>
 /// <param name="size">Size, in bytes, of (double * buffer length)</param>
 /// <returns>Returns a specific value based on the <paramref name="command"/>.</returns>
 public int Command(IntPtr sndfile, LibsndfileCommand command, double[] data, int size)
 {
     return(LibsndfileApiNative.sf_command(sndfile, command, data, size));
 }
예제 #13
0
        /// <summary>
        /// Attempts to execute the <paramref name="command"/> against the <paramref name="sndfile"/> audio 
        /// file while either passing or receiving data through the <paramref name="data"/> buffer.
        /// </summary>
        /// <param name="sndfile">Audio file we run this command against.
        /// Use NULL if you wish to run a static command against the library.</param>
        /// <param name="command"><see cref="NLibsndfile.Native.LibsndfileCommand"/> to execute</param>
        /// <param name="data">Double[](double*) buffer passing or receiving data based on <paramref name="command"/> specifications.</param>
        /// <param name="size">Size, in bytes, of (double * buffer length)</param>
        /// <returns>Returns a specific value based on the <paramref name="command"/>.</returns>
        public int Command(IntPtr sndfile, LibsndfileCommand command, double[] data, int size)
        {
            if (sndfile == IntPtr.Zero && !LibsndfileCommandUtilities.IsStaticCommand(command))
                throw new ArgumentException("File handle is invalid/closed.");
            if (data == null)
                throw new ArgumentNullException("data", "Data cannot be null.");
            if (data.Length == 0)
                throw new ArgumentNullException("data", "Data must be initialized.");

            var retval = m_Api.Command(sndfile, command, data, size);
            if (!LibsndfileCommandUtilities.IsValidResult(sndfile, command, retval))
                throw new LibsndfileException(string.Format("Command {0} returned an invalid result.", command));

            return retval;
        }
예제 #14
0
        /// <summary>
        /// Attempts to execute the <paramref name="command"/> against the <paramref name="sndfile"/> audio 
        /// file while either passing or receiving data through the <paramref name="data"/> buffer.
        /// </summary>
        /// <param name="sndfile">Audio file we run this command against.
        /// Use NULL if you wish to run a static command against the library.</param>
        /// <param name="command"><see cref="NLibsndfile.Native.LibsndfileCommand"/> to run against the given audio file.</param>
        /// <param name="data">Ref long(long*) buffer passing or receiving data based on <paramref name="command"/> specifications.</param>
        /// <param name="size">Size, in bytes, of a long.</param>
        /// <returns>Returns a specific value based on the <paramref name="command"/>.</returns>
        public int Command(IntPtr sndfile, LibsndfileCommand command, ref long data, int size)
        {
            if (sndfile == IntPtr.Zero && !LibsndfileCommandUtilities.IsStaticCommand(command))
                throw new ArgumentException("File handle is invalid/closed.");

            var retval = m_Api.Command(sndfile, command, ref data, size);
            if (!LibsndfileCommandUtilities.IsValidResult(sndfile, command, retval))
                throw new LibsndfileException(string.Format("Command {0} returned an invalid result.", command));

            return retval;
        }