Beispiel #1
0
        /// <summary>
        /// Creates a new instance of <see cref="AcmFileWriter"/>.
        /// </summary>
        /// <param name="FileName">Path to the file to write.</param>
        /// <param name="Encoding"><see cref="WaveFormatTag"/> for written audio.</param>
        /// <param name="Format"><see cref="WaveFormat"/> of input audio.</param>
        public AcmFileWriter(string FileName, WaveFormatTag Encoding, WaveFormat Format)
        {
            if (FileName == null)
            {
                throw new ArgumentNullException(nameof(FileName));
            }

            _channel = GetDummyChannel(Format);

            // Get the Length of the ACMFormat structure
            var suggestedFormatLength = BassEnc.GetACMFormat(0);
            var acmFormat             = Marshal.AllocHGlobal(suggestedFormatLength);

            try
            {
                // Retrieve ACMFormat and Init Encoding
                if (BassEnc.GetACMFormat(_channel,
                                         acmFormat,
                                         suggestedFormatLength,
                                         null,
                                         // If encoding is Unknown, then let the User choose encoding.
                                         Encoding == WaveFormatTag.Unknown ? 0 : ACMFormatFlags.Suggest,
                                         Encoding) != 0)
                {
                    _handle = BassEnc.EncodeStartACM(_channel, acmFormat, 0, FileName);
                }
                else
                {
                    throw new Exception(Bass.LastError.ToString());
                }
            }
            finally
            {
                // Free the ACMFormat structure
                Marshal.FreeHGlobal(acmFormat);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose() => BassEnc.EncodeStop(_handle, true);