Пример #1
0
        /// <summary>
        /// Writes an audio buffer to the specified instance of a cExternalAudioSource component.
        /// The data must match the specified data format for the component (sample size, number of channels, etc.).
        /// </summary>
        /// <param name="componentName">Instance name of the cExternalAudioSource component to write to.</param>
        /// <param name="data">Audio frames to write.</param>
        /// <returns>
        /// Returns true if the data was written successfully, otherwise returns false
        /// (e.g. if the internal buffer of the component is full).
        /// </returns>
        /// <exception cref="ObjectDisposedException">
        /// Thrown if the object has already been disposed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// Thrown if openSMILE has not been initialized yet.
        /// </exception>
        /// <exception cref="OpenSmileException">
        /// Thrown for internal openSMILE errors.
        /// </exception>
        public bool ExternalAudioSourceWriteData(string componentName, double[] data)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(typeof(OpenSMILE).FullName);
            }
            if (smileObj == IntPtr.Zero)
            {
                throw new InvalidOperationException("openSMILE must be initialized first.");
            }

            OpenSmileResult result = OpenSmileApi.Smile_extaudiosource_write_data(smileObj, componentName, data, data.Length * sizeof(double));

            if (result == OpenSmileResult.SMILE_SUCCESS)
            {
                return(true);
            }
            else if (result == OpenSmileResult.SMILE_NOT_WRITTEN)
            {
                return(false);
            }
            else
            {
                CheckSmileResult(result);
                throw new Exception(); // unreachable as CheckSmileResult will throw, just to make compiler happy
            }
        }
Пример #2
0
 private void CheckSmileResult(OpenSmileResult result)
 {
     if (result != OpenSmileResult.SMILE_SUCCESS)
     {
         string message = OpenSmileApi.Smile_error_msg(smileObj);
         throw new OpenSmileException(result, message);
     }
 }
Пример #3
0
 public OpenSmileException(OpenSmileResult code, string message)
     : base(message)
 {
     Code = code;
 }
Пример #4
0
 public OpenSmileException(OpenSmileResult code)
 {
     Code = code;
 }