Пример #1
0
        /// <summary>
        /// Create a MOD music form a file.
        /// </summary>
        /// <param name="file">File name. </param>
        /// <param name="offset">File offset to load the MOD music from. </param>
        /// <param name="length">Data length... 0 = use all data up to the end of file. </param>
        /// <param name="freq">Sample rate to render/play the MOD music at... 0 = the rate specified in the <see cref="Initialize"/> call, 1 = the device's current output rate (or the <see cref="Initialize"/> rate if that is not available). </param>
        /// <param name="config">Some configures of MOD music.</param>
        public ModMusic(String file, ulong offset, uint length, uint freq, MusicLoadConfig config)
        {
            config |= MusicLoadConfig.Unicode;

            using (var fileHandle = InteropHelper.StringToPtr(file))
            {
                Handle = ModMusicModule.MusicLoadFunction.CheckResult(
                    ModMusicModule.MusicLoadFunction.Delegate(false, fileHandle.Handle, offset, length, config, freq));
            }
        }
Пример #2
0
        /// <summary>
        /// Create a MOD music form a .NET memory stream.
        /// </summary>
        /// <param name="stream">A .NET memory stream. </param>
        /// <param name="freq">Sample rate to render/play the MOD music at... 0 = the rate specified in the <see cref="Initialize"/> call, 1 = the device's current output rate (or the <see cref="Initialize"/> rate if that is not available). </param>
        /// <param name="config">Some configures of MOD music.</param>
        public ModMusic(MemoryStream stream, uint freq, MusicLoadConfig config)
        {
            ArraySegment <byte> bufferSegment;

            byte[] buffer = stream.TryGetBuffer(out bufferSegment) ? bufferSegment.Array : stream.ToArray();

            GCHandle bufferHandle = GCHandle.Alloc(buffer);

            Handle = ModMusicModule.MusicLoadFunction.CheckResult(
                ModMusicModule.MusicLoadFunction.Delegate(true, bufferHandle.AddrOfPinnedObject(), 0,
                                                          (uint)stream.Length, config, freq));

            bufferHandle.Free();
        }