Exemplo n.º 1
0
        /// <summary>
        /// Attempts to open an audio file at the <paramref name="path"/> location 
        /// with <paramref name="mode"/> based file access.
        /// </summary>
        /// <param name="path">Fully qualified path to location of audio file.</param>
        /// <param name="mode">File access to use when opening this file. ReadItems/Write/ReadWrite.</param>
        /// <param name="info"><see cref="LibsndfileInfo"/> structure contains information about the file we are opening.</param>
        /// <returns>Returns pointer to an internal object used by libsndfile that we can interact with.</returns>
        public IntPtr Open(string path, LibsndfileMode mode, ref LibsndfileInfo info)
        {
            if (string.IsNullOrEmpty(path))
                throw new ArgumentNullException("path", "Path cannot be null/empty.");

            return m_Api.Open(path, mode, ref info);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attempts to open an audio file with the <paramref name="handle"/> file descriptor
        /// using <paramref name="mode"/> based file access.
        /// </summary>
        /// <param name="handle">File descriptor handle</param>
        /// <param name="mode">File access to use when opening this file. ReadItems/Write/ReadWrite</param>
        /// <param name="info"><see cref="LibsndfileInfo"/> structure contains information about the file we are opening.</param>
        /// <param name="closeHandle">Decide if we want libsndfile to close the file descriptor for us.</param>
        /// <returns>Returns pointer to an internal object used by libsndfile that we can interact with.</returns>
        public IntPtr OpenFileDescriptor(int handle, LibsndfileMode mode, ref LibsndfileInfo info, int closeHandle)
        {
            if (handle <= 0)
            {
                throw new ArgumentOutOfRangeException("handle", "File handle cannot be zero/non-negative.");
            }

            return(m_Api.OpenFileDescriptor(handle, mode, ref info, closeHandle));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Attempts to open an audio file at the <paramref name="path"/> location
        /// with <paramref name="mode"/> based file access.
        /// </summary>
        /// <param name="path">Fully qualified path to location of audio file.</param>
        /// <param name="mode">File access to use when opening this file. ReadItems/Write/ReadWrite.</param>
        /// <param name="info"><see cref="LibsndfileInfo"/> structure contains information about the file we are opening.</param>
        /// <returns>Returns pointer to an internal object used by libsndfile that we can interact with.</returns>
        public IntPtr Open(string path, LibsndfileMode mode, ref LibsndfileInfo info)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path", "Path cannot be null/empty.");
            }

            return(m_Api.Open(path, mode, ref info));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Check to see if the parameters in the <paramref name="info"/> struct are
        /// valid and supported by libsndfile.
        /// </summary>
        /// <param name="info"><see cref="LibsndfileInfo"/> struct contains information about a target file.</param>
        /// <returns>Returns TRUE if the parameters are valid, FALSE otherwise.</returns>
        public bool FormatCheck(ref LibsndfileInfo info)
        {
            if (!info.IsSet)
            {
                throw new ArgumentException("LibsndfileInfo structure must be initialized.");
            }

            return(m_Api.FormatCheck(ref info));
        }
Exemplo n.º 5
0
        public static bool FillALBuffer(uint bufNumber, IntPtr wavFile, long bufSize, LibsndfileInfo sfInfo)
        {
            if (sfInfo.Channels > 1) // We can't use non-mono samples
            {
                Sys.DebugLog(LOG_FILENAME, "Error: sample {0:D3} is not mono!", bufNumber);
                return false;
            }

            if (AUDIO_OPENAL_FLOAT)
            {
                var frames = new float[bufSize / sizeof (float)];
                sndFileApi.ReadFrames(wavFile, frames, frames.Length);
                AL.BufferData((int) bufNumber, ALFormat.MonoFloat32Ext, frames, (int) bufSize, sfInfo.SampleRate);
            }
            else
            {
                var frames = new short[bufSize / sizeof(short)];
                sndFileApi.ReadFrames(wavFile, frames, frames.Length);
                AL.BufferData((int)bufNumber, ALFormat.Mono16, frames, (int)bufSize, sfInfo.SampleRate);
            }

            LogALError();
            return true;
        }
Exemplo n.º 6
0
 internal static extern unsafe IntPtr sf_open_virtual(ref SF_VIRTUAL_IO sfvirtual, LibsndfileMode mode, ref LibsndfileInfo info, void* userData);
 /// <summary>
 /// Attempts to open an audio file with the <paramref name="handle"/> file descriptor 
 /// using <paramref name="mode"/> based file access.
 /// </summary>
 /// <param name="handle">File descriptor handle</param>
 /// <param name="mode">File access to use when opening this file. ReadItems/Write/ReadWrite</param>
 /// <param name="info"><see cref="LibsndfileInfo"/> structure contains information about the file we are opening.</param>
 /// <param name="closeHandle">Decide if we want libsndfile to close the file descriptor for us.</param>
 /// <returns>Returns pointer to an internal object used by libsndfile that we can interact with.</returns>
 public IntPtr OpenFileDescriptor(int handle, LibsndfileMode mode, ref LibsndfileInfo info, int closeHandle)
 {
     return LibsndfileApiNative.sf_open_fd(handle, mode, ref info, closeHandle);
 }
 /// <summary>
 /// Attempts to open an audio file at the <paramref name="path"/> location 
 /// with <paramref name="mode"/> based file access.
 /// </summary>
 /// <param name="path">Fully qualified path to location of audio file.</param>
 /// <param name="mode">File access to use when opening this file. ReadItems/Write/ReadWrite.</param>
 /// <param name="info"><see cref="LibsndfileInfo"/> structure contains information about the file we are opening.</param>
 /// <returns>Returns pointer to an internal object used by libsndfile that we can interact with.</returns>
 public IntPtr Open(string path, LibsndfileMode mode, ref LibsndfileInfo info)
 {
     return LibsndfileApiNative.sf_open(path, mode, ref info);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Check to see if the parameters in the <paramref name="info"/> struct are
        /// valid and supported by libsndfile.
        /// </summary>
        /// <param name="info"><see cref="LibsndfileInfo"/> struct contains information about a target file.</param>
        /// <returns>Returns TRUE if the parameters are valid, FALSE otherwise.</returns>
        public bool FormatCheck(ref LibsndfileInfo info)
        {
            if (!info.IsSet)
                throw new ArgumentException("LibsndfileInfo structure must be initialized.");

            return m_Api.FormatCheck(ref info);
        }
Exemplo n.º 10
0
 internal static extern IntPtr sf_open_fd(int handle, LibsndfileMode mode, ref LibsndfileInfo info, int closeHandle);
Exemplo n.º 11
0
 internal static extern IntPtr sf_open_fd(int handle, LibsndfileMode mode, ref LibsndfileInfo info, int closeHandle);
Exemplo n.º 12
0
 internal static extern int sf_format_check(ref LibsndfileInfo info);
Exemplo n.º 13
0
 internal static unsafe extern IntPtr sf_open_fd(int handle, int mode, LibsndfileInfo* info, int closeHandle);
Exemplo n.º 14
0
        /// <summary>
        /// Track loading
        /// </summary>
        private bool loadTrack(string path)
        {
            sfInfo = new LibsndfileInfo();
            if((sndFile = sndFileApi.Open(path, LibsndfileMode.Read, ref sfInfo)) == IntPtr.Zero)
            {
                Sys.DebugLog(LOG_FILENAME, "Load_Track: Couldn't open file: {0}.", path);
                Sys.DebugLog(LOG_FILENAME, $"Libsndfile error: {sndFileApi.Error(IntPtr.Zero):G} ({sndFileApi.ErrorString(IntPtr.Zero)})");
                method = TR_AUDIO_STREAM_METHOD.Unknown; // T4Larson <*****@*****.**>: stream is uninitialised, avoid clear.
                return false;
            }

            ConsoleInfo.Instance.Notify(Strings.SYSNOTE_TRACK_OPENED, path, sfInfo.Channels, sfInfo.SampleRate);

            if (AUDIO_OPENAL_FLOAT)
                format = sfInfo.Channels == 1 ? ALFormat.MonoFloat32Ext : ALFormat.StereoFloat32Ext;
            else
                format = sfInfo.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16;

            rate = sfInfo.SampleRate;

            return true; // Success!
        }
 /// <summary>
 /// Check to see if the parameters in the <paramref name="info"/> struct are
 /// valid and supported by libsndfile.
 /// </summary>
 /// <param name="info"><see cref="LibsndfileInfo"/> struct contains information about a target file.</param>
 /// <returns>Returns TRUE if the parameters are valid, FALSE otherwise.</returns>
 public bool FormatCheck(ref LibsndfileInfo info)
 {
     return(Convert.ToBoolean(LibsndfileApiNative.sf_format_check(ref info)));
 }
 /// <summary>
 /// Attempts to open an audio file with the <paramref name="handle"/> file descriptor
 /// using <paramref name="mode"/> based file access.
 /// </summary>
 /// <param name="handle">File descriptor handle</param>
 /// <param name="mode">File access to use when opening this file. ReadItems/Write/ReadWrite</param>
 /// <param name="info"><see cref="LibsndfileInfo"/> structure contains information about the file we are opening.</param>
 /// <param name="closeHandle">Decide if we want libsndfile to close the file descriptor for us.</param>
 /// <returns>Returns pointer to an internal object used by libsndfile that we can interact with.</returns>
 public IntPtr OpenFileDescriptor(int handle, LibsndfileMode mode, ref LibsndfileInfo info, int closeHandle)
 {
     return(LibsndfileApiNative.sf_open_fd(handle, mode, ref info, closeHandle));
 }
 /// <summary>
 /// Attempts to open an audio file at the <paramref name="path"/> location
 /// with <paramref name="mode"/> based file access.
 /// </summary>
 /// <param name="path">Fully qualified path to location of audio file.</param>
 /// <param name="mode">File access to use when opening this file. ReadItems/Write/ReadWrite.</param>
 /// <param name="info"><see cref="LibsndfileInfo"/> structure contains information about the file we are opening.</param>
 /// <returns>Returns pointer to an internal object used by libsndfile that we can interact with.</returns>
 public IntPtr Open(string path, LibsndfileMode mode, ref LibsndfileInfo info)
 {
     return(LibsndfileApiNative.sf_open(path, mode, ref info));
 }
Exemplo n.º 18
0
        /// <summary>
        /// Attempts to open an audio file with the <paramref name="handle"/> file descriptor 
        /// using <paramref name="mode"/> based file access.
        /// </summary>
        /// <param name="handle">File descriptor handle</param>
        /// <param name="mode">File access to use when opening this file. ReadItems/Write/ReadWrite</param>
        /// <param name="info"><see cref="LibsndfileInfo"/> structure contains information about the file we are opening.</param>
        /// <param name="closeHandle">Decide if we want libsndfile to close the file descriptor for us.</param>
        /// <returns>Returns pointer to an internal object used by libsndfile that we can interact with.</returns>
        public IntPtr OpenFileDescriptor(int handle, LibsndfileMode mode, ref LibsndfileInfo info, int closeHandle)
        {
            if (handle <= 0)
                throw new ArgumentOutOfRangeException("handle", "File handle cannot be zero/non-negative.");

            return m_Api.OpenFileDescriptor(handle, mode, ref info, closeHandle);
        }
Exemplo n.º 19
0
        public static unsafe int LoadALBufferFromMem(uint bufNumber, byte* samplePointer, uint sampleSize,
            uint uncompSampleSize = 0)
        {
            var wavMem = new MemBufferFileIo(samplePointer, sampleSize);
            var tmp = wavMem.ToSfVirtualIo();
            var sfInfo = new LibsndfileInfo();
            var sample = sndFileApi.OpenVirtual(ref tmp, LibsndfileMode.Read, ref sfInfo, &wavMem);

            if(sample == IntPtr.Zero)
            {
                Sys.DebugLog(LOG_FILENAME, "Error: can't load sample #{0:D3} from sample block!", bufNumber);
                Sys.DebugLog(LOG_FILENAME, $"Libsndfile error: {sndFileApi.Error(IntPtr.Zero):G} ({sndFileApi.ErrorString(IntPtr.Zero)})");
                return -1;
            }

            // Uncomp_sample_size explicitly specifies amount of raw sample data
            // to load into buffer. It is only used in TR4/5 with ADPCM samples,
            // because full-sized ADPCM sample contains a bit of silence at the end,
            // which should be removed. That's where uncomp_sample_size comes into
            // business.
            // Note that we also need to compare if uncomp_sample_size is smaller
            // than native wav length, because for some reason many TR5 uncomp sizes
            // are messed up and actually more than actual sample size.

            var realSize = sfInfo.Frames * sizeof(ushort);

            if (uncompSampleSize == 0 || realSize < uncompSampleSize)
            {
                uncompSampleSize = (uint)realSize;
            }

            // We need to change buffer size, as we're using floats here.

            if (AUDIO_OPENAL_FLOAT)
                uncompSampleSize = (uncompSampleSize / sizeof(ushort)) * sizeof(float);
            else
                uncompSampleSize = uncompSampleSize / sizeof(ushort) * sizeof(short);

            // Find out sample format and load it correspondingly.
            // Note that with OpenAL, we can have samples of different formats in same level.

            var result = FillALBuffer(bufNumber, sample, uncompSampleSize, sfInfo);

            sndFileApi.Close(sample);

            return result ? 0 : -3; // Zero means success
        }
Exemplo n.º 20
0
        public static int LoadALBufferFromFile(uint bufNumber, string filename)
        {
            var sfInfo = new LibsndfileInfo();
            var file = sndFileApi.Open(filename, LibsndfileMode.Read, ref sfInfo);

            if(file == IntPtr.Zero)
            {
                ConsoleInfo.Instance.Warning(Strings.SYSWARN_CANT_OPEN_FILE);
                Sys.DebugLog(LOG_FILENAME, $"Libsndfile error: {sndFileApi.Error(IntPtr.Zero):G} ({sndFileApi.ErrorString(IntPtr.Zero)})");
                return -1;
            }

            bool result;

            if(AUDIO_OPENAL_FLOAT)
            {
                result = FillALBuffer(bufNumber, file, sfInfo.Frames * sizeof (float), sfInfo);
            }
            else
            {
                result = FillALBuffer(bufNumber, file, sfInfo.Frames * sizeof(short), sfInfo);
            }

            sndFileApi.Close(file);

            return result ? 0 : -3; // Zero means success.
        }
Exemplo n.º 21
0
 internal static extern IntPtr sf_open(string path, LibsndfileMode mode, ref LibsndfileInfo info);
Exemplo n.º 22
0
 public static float GetByteDepth(LibsndfileInfo sfInfo)
 {
     switch ((LibsndfileFormat) (sfInfo.Format & LibsndfileFormat.Submask))
     {
         case LibsndfileFormat.PcmS8:
         case LibsndfileFormat.PcmU8:
             return 1;
         case LibsndfileFormat.Pcm16:
             return 2;
         case LibsndfileFormat.Pcm24:
             return 3;
         case LibsndfileFormat.Pcm32:
         case LibsndfileFormat.Float:
             return 4;
         case LibsndfileFormat.Double:
             return 8;
         case LibsndfileFormat.MsAdpcm:
             return 0.5f;
         default:
             return 1;
     }
 }
Exemplo n.º 23
0
 internal static extern IntPtr sf_open(string path, LibsndfileMode mode, ref LibsndfileInfo info);
Exemplo n.º 24
0
 /// <summary>
 /// Check to see if the parameters in the <paramref name="info"/> struct are
 /// valid and supported by libsndfile.
 /// </summary>
 /// <param name="info"><see cref="LibsndfileInfo"/> struct contains information about a target file.</param>
 /// <returns>Returns TRUE if the parameters are valid, FALSE otherwise.</returns>
 public bool FormatCheck(ref LibsndfileInfo info)
 {
     return Convert.ToBoolean(LibsndfileApiNative.sf_format_check(ref info));
 }
Exemplo n.º 25
0
 internal static extern int sf_format_check(ref LibsndfileInfo info);
Exemplo n.º 26
0
 public unsafe IntPtr OpenVirtual(ref SF_VIRTUAL_IO sfvirtual, LibsndfileMode mode, ref LibsndfileInfo info, void* userData)
 {
     return m_Api.OpenVirtual(ref sfvirtual, mode, ref info, userData);
 }