コード例 #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);
            }
        }
コード例 #2
0
        internal virtual void Read(BinaryReader reader)
        {
            try
            {
                formatTag             = (WaveFormatTag)reader.ReadUInt16();
                channels              = reader.ReadInt16();
                samplesPerSecond      = reader.ReadInt32();
                averageBytesPerSecond = reader.ReadInt32();
                blockAlign            = reader.ReadInt16();
                bitsPerSample         = reader.ReadInt16();
                extraDataSize         = reader.ReadInt16();

                if (extraDataSize != 0 && extraDataSize != StandardSizeExtensible - StandardSize)
                {
                    switch (formatTag)
                    {
                    case WaveFormatTag.Pcm:
                        extraDataSize = 0;
                        reader.BaseStream.Seek(-2, SeekOrigin.Current);
                        break;

                    case WaveFormatTag.Extensible:
                        extraDataSize = (short)(StandardSizeExtensible - StandardSize);
                        break;
                    }
                }

                CalculateValues();
            }
            catch (Exception ex)
            {
                throw new IOException("Failed to read WaveFormat data from stream", ex);
            }
        }
コード例 #3
0
        public static WaveFormat smethod_0(IntPtr intptr_0)
        {
            WaveFormat    waveFormat    = (WaveFormat)Marshal.PtrToStructure(intptr_0, typeof(WaveFormat));
            WaveFormatTag waveFormatTag = waveFormat.waveFormatTag_0;

            switch (waveFormatTag)
            {
            case WaveFormatTag.PCM:
                waveFormat.short_3 = 0;
                break;

            case WaveFormatTag.Adpcm:
                waveFormat = (Form2)Marshal.PtrToStructure(intptr_0, typeof(Form2));
                break;

            default:
                if (waveFormatTag != WaveFormatTag.Extensible)
                {
                    if (waveFormat.short_3 > 0)
                    {
                        waveFormat = (Form0)Marshal.PtrToStructure(intptr_0, typeof(Form0));
                    }
                }
                else
                {
                    waveFormat = (Form1)Marshal.PtrToStructure(intptr_0, typeof(Form1));
                }
                break;
            }
            return(waveFormat);
        }
コード例 #4
0
        /// <summary>
        ///   Converts a <see cref="WaveFormatTag"/> and bits per sample information
        ///   into an appropriate <see cref="SampleFormat"/>.
        /// </summary>
        ///
        /// <param name="tag">The wave format tag.</param>
        /// <param name="bitsPerSample">The bits per sample.</param>
        ///
        public static SampleFormat ToSampleFormat(this WaveFormatTag tag, int bitsPerSample)
        {
            if (tag == WaveFormatTag.Pcm)
            {
                if (bitsPerSample == 16)
                {
                    return(SampleFormat.Format16Bit);
                }
                else if (bitsPerSample == 32)
                {
                    return(SampleFormat.Format32Bit);
                }
            }
            else if (tag == WaveFormatTag.IeeeFloat)
            {
                if (bitsPerSample == 32)
                {
                    return(SampleFormat.Format32BitIeeeFloat);
                }
                else if (bitsPerSample == 64)
                {
                    return(SampleFormat.Format64BitIeeeFloat);
                }
            }

            throw new ArgumentOutOfRangeException("tag", "Unsupported format tag.");
        }
コード例 #5
0
        //public override AudioBuffer CreateBuffer(IAudioStream source)
        //{
        //    WaveFormatEx fmt = new WaveFormatEx(source.Format, source.Channels, source.Frequency, source.BitsPerSample);
        //    DS.DSBufferCapsFlags flags = DS.DSBufferCapsFlags.CtrlVolume | DS.DSBufferCapsFlags.LocDefer |DS.DSBufferCapsFlags.GlobalFocus | DS.DSBufferCapsFlags.GetCurrentPosition2;
        //    DS.DSBufferDesc desc = new DS.DSBufferDesc(AudioBuffer.DefaultBufferSpan * fmt.nAvgBytesPerSec, flags, &fmt, Guid.Empty);

        //    AudioBuffer buf = CreateBuffer(ref desc);
        //    buf._source = source;
        //    return buf;
        //}

        public override AudioBuffer CreateBuffer(WaveFormatTag format, int channels, int bps, int frequency, int size)
        {
            WaveFormatEx fmt = new WaveFormatEx(format, channels, frequency, bps);

            DS.DSBufferCapsFlags flags = DS.DSBufferCapsFlags.CtrlVolume | DS.DSBufferCapsFlags.LocDefer | DS.DSBufferCapsFlags.GlobalFocus | DS.DSBufferCapsFlags.GetCurrentPosition2;
            DS.DSBufferDesc      desc  = new DS.DSBufferDesc((uint)size, flags, &fmt, Guid.Empty);

            return(new wAudioBuffer(this, ref desc));
        }
コード例 #6
0
        static WMAEncodeFlags ToWmaEncodeFlags(WaveFormatTag WfTag, int BitsPerSample)
        {
            if (WfTag == WaveFormatTag.Pcm && BitsPerSample == 8)
                return WMAEncodeFlags.Byte;
            if (WfTag == WaveFormatTag.IeeeFloat && BitsPerSample == 32)
                return WMAEncodeFlags.Float;

            return 0;
        }
コード例 #7
0
        static BassFlags ToBassFlags(WaveFormatTag WfTag, int BitsPerSample)
        {
            if (WfTag == WaveFormatTag.Pcm && BitsPerSample == 8)
                return BassFlags.Byte;
            if (WfTag == WaveFormatTag.IeeeFloat && BitsPerSample == 32)
                return BassFlags.Float;

            return 0;
        }
コード例 #8
0
 public WaveFormat(WaveFormatTag formatTag, int channels, int samplesPerSecond, int bitsPerSample)
 {
     this.formatTag        = formatTag;
     this.channels         = (short)channels;
     this.samplesPerSecond = samplesPerSecond;
     this.bitsPerSample    = (short)bitsPerSample;
     this.extraDataSize    = 0;
     CalculateValues();
 }
コード例 #9
0
 public WaveFormat(int int_2, int int_3)
 {
     this.waveFormatTag_0 = WaveFormatTag.IEEEFloat;
     this.short_0         = (short)int_3;
     this.short_2         = 32;
     this.int_0           = int_2;
     this.short_1         = (short)(4 * int_3);
     this.int_1           = int_2 * (int)this.short_1;
     this.short_3         = 0;
 }
コード例 #10
0
ファイル: WaveFormat.cs プロジェクト: uwx/Open-GHTCP
 public WaveFormat(int int2, int int3)
 {
     waveFormatTag_0 = WaveFormatTag.IeeeFloat;
     short_0         = (short)int3;
     short_2         = 32;
     int_0           = int2;
     short_1         = (short)(4 * int3);
     int_1           = int2 * short_1;
     short_3         = 0;
 }
コード例 #11
0
 public WaveFormatEx(WaveFormatTag format, int channels, int frequency, int bitsPerSample)
 {
     wFormatTag      = format;
     nChannels       = (ushort)channels;
     nSamplesPerSec  = (uint)frequency;
     nBlockAlign     = (ushort)(bitsPerSample * channels / 8);
     nAvgBytesPerSec = nBlockAlign * nSamplesPerSec;
     wBitsPerSample  = (ushort)bitsPerSample;
     cbSize          = 0;
 }
コード例 #12
0
ファイル: WaveFormat.cs プロジェクト: ExileLord/Open-GHTCP
 public WaveFormat(int int_2, int int_3)
 {
     this.waveFormatTag_0 = WaveFormatTag.IEEEFloat;
     this.short_0 = (short)int_3;
     this.short_2 = 32;
     this.int_0 = int_2;
     this.short_1 = (short)(4 * int_3);
     this.int_1 = int_2 * (int)this.short_1;
     this.short_3 = 0;
 }
コード例 #13
0
ファイル: BassEnc.cs プロジェクト: Gohla/ManagedBass.PInvoke
        /// <summary>
        /// Presents the user with a list of available ACM (Audio Compression Manager) codec output formats to choose from.
        /// </summary>
        /// <param name="Handle">The channel handle... a HSTREAM, HMUSIC, or HRECORD.</param>
        /// <param name="Format">Pointer to the format buffer.</param>
        /// <param name="FormatLength">Size of the format buffer. If this is 0, then a suggested format buffer length is returned (which is the maximum length of all installed codecs), without displaying the codec selector.</param>
        /// <param name="Title">Window title for the selector... <see langword="null" /> = "Choose the output format".</param>
        /// <param name="Flags">A combination of <see cref="ACMFormatFlags"/>.</param>
        /// <param name="Encoding">Can be used to restrict the choice to a particular format tag. This is required with <see cref="ACMFormatFlags.Suggest"/>, and is optional otherwise.</param>
        /// <returns>
        /// If successful, the user-selected codec format details are put in the provided buffer and the length of the format details is returned, else 0 is returned.
        /// Use <see cref="Bass.LastError" /> to get the error code.
        /// If <paramref name="FormatLength"/> is 0, then the suggested format buffer size is returned.
        /// </returns>
        /// <remarks>
        /// This function presents the user with a list of available ACM codecs to choose from, given the sample format of the channel.
        /// The details of the chosen codec's output are returned in the Format buffer, which can then be used with <see cref="EncodeStartACM(int,IntPtr,EncodeFlags,EncodeProcedure,IntPtr)" /> or <see cref="EncodeStartACM(int,IntPtr,EncodeFlags,string)" /> to begin encoding.
        /// <para>
        /// The <paramref name="Format" /> buffer contents are actually a WAVEFORMATEX or ACMFORMAT structure.
        /// If writing the encoder output to a WAVE file, the Format buffer contents would be the format chunk ("fmt") of the file.
        /// </para>
        /// </remarks>
        /// <exception cref="Errors.Handle"><paramref name="Handle" /> is not valid.</exception>
        /// <exception cref="Errors.NotAvailable">There are no codecs available that will accept the channel's format.</exception>
        /// <exception cref="Errors.AcmCancel">The user pressed the "cancel" button.</exception>
        /// <exception cref="Errors.Unknown">Some other mystery problem!</exception>
        public static int GetACMFormat(int Handle,
                                       IntPtr Format          = default(IntPtr),
                                       int FormatLength       = 0,
                                       string Title           = null,
                                       ACMFormatFlags Flags   = ACMFormatFlags.Default,
                                       WaveFormatTag Encoding = WaveFormatTag.Unknown)
        {
            var acMflags = BitHelper.MakeLong((short)(Flags | ACMFormatFlags.Unicode), (short)Encoding);

            return(BASS_Encode_GetACMFormat(Handle, Format, FormatLength, Title, acMflags));
        }
コード例 #14
0
        public WaveFormat(uint sampleRate, ushort bitsPerSample, ushort channelCount)
        {
            _formatTag     = WaveFormatTag.Pcm; // PCM (uncompressed)
            _channelCount  = channelCount;
            _sampleRate    = sampleRate;
            _bitsPerSample = bitsPerSample;

            uint bytesPerSample = ((uint)bitsPerSample + 7) / 8;

            _blockAlign            = (ushort)(bytesPerSample * channelCount);
            _averageBytesPerSecond = _blockAlign * sampleRate;
        }
コード例 #15
0
 /// <summary>
 /// Creates a new instance of the <see cref="WaveFormat"/> class.
 /// </summary>
 /// <param name="formatTag">The format tag</param>
 /// <param name="samplingRate">The sampling frequency</param>
 /// <param name="bitsPerSample">The number of bits per channel sample</param>
 /// <param name="channels">The number of audio channels</param>
 /// <param name="blockAlign">The block alignment</param>
 /// <param name="avgBytesPerSecond">The average number of bytes per second</param>
 /// <returns>The WaveFormat object</returns>
 public static WaveFormat Create(WaveFormatTag formatTag, int samplingRate, int bitsPerSample, int channels, int blockAlign, int avgBytesPerSecond)
 {
     return(new WaveFormat()
     {
         FormatTag = formatTag,
         SamplesPerSec = (uint)samplingRate,
         BitsPerSample = (ushort)bitsPerSample,
         Channels = (ushort)channels,
         BlockAlign = (ushort)blockAlign,
         AvgBytesPerSec = (uint)avgBytesPerSecond
     });
 }
コード例 #16
0
        public WAVEFORMATEX(int rate, int bits, int channels)
        {
            formatTag      = WaveFormatTag.PCM;
            nChannels      = (short)channels;
            nSamplesPerSec = rate;
            wBitsPerSample = (short)bits;
            cbSize         = 0;

            nBlockAlign     = (short)(channels * (bits / 8));
            nAvgBytesPerSec = nSamplesPerSec * nBlockAlign;
            extraInfo       = 0;
        }
コード例 #17
0
 public WAVEFORMATEXTENSIBLE(WAVEFORMATEXTENSIBLE o)
 {
     wFormatTag          = o.wFormatTag;
     nChannels           = o.nChannels;
     nSamplesPerSec      = o.nSamplesPerSec;
     nAvgBytesPerSec     = o.nAvgBytesPerSec;
     nBlockAlign         = o.nBlockAlign;
     wBitsPerSample      = o.wBitsPerSample;
     cbSize              = o.cbSize;
     wValidBitsPerSample = o.wValidBitsPerSample;
     dwChannelMask       = o.dwChannelMask;
     SubFormat           = o.SubFormat;
 }
コード例 #18
0
        static WMAEncodeFlags ToWmaEncodeFlags(WaveFormatTag WfTag, int BitsPerSample)
        {
            if (WfTag == WaveFormatTag.Pcm && BitsPerSample == 8)
            {
                return(WMAEncodeFlags.Byte);
            }
            if (WfTag == WaveFormatTag.IeeeFloat && BitsPerSample == 32)
            {
                return(WMAEncodeFlags.Float);
            }

            return(0);
        }
コード例 #19
0
        public override string ToString()
        {
            WaveFormatTag waveFormatTag = this.waveFormatTag_0;

            if (waveFormatTag != WaveFormatTag.PCM)
            {
                if (waveFormatTag != WaveFormatTag.Extensible)
                {
                    return(this.waveFormatTag_0.ToString());
                }
            }
            return(string.Format("{0} bit PCM: {1}kHz {2} channels", this.short_2, this.int_0 / 1000, this.short_0));
        }
コード例 #20
0
ファイル: WaveFormat.cs プロジェクト: uwx/Open-GHTCP
 public WaveFormat(int int2, int int3, int int4)
 {
     if (int4 < 1)
     {
         throw new ArgumentOutOfRangeException("Channels must be 1 or greater.", "channels");
     }
     waveFormatTag_0 = WaveFormatTag.Pcm;
     short_0         = (short)int4;
     int_0           = int2;
     short_2         = (short)int3;
     short_3         = 0;
     short_1         = (short)(int4 * (int3 / 8));
     int_1           = int_0 * short_1;
 }
コード例 #21
0
 public WaveFormat(int int_2, int int_3, int int_4)
 {
     if (int_4 < 1)
     {
         throw new ArgumentOutOfRangeException("Channels must be 1 or greater.", "channels");
     }
     this.waveFormatTag_0 = WaveFormatTag.PCM;
     this.short_0         = (short)int_4;
     this.int_0           = int_2;
     this.short_2         = (short)int_3;
     this.short_3         = 0;
     this.short_1         = (short)(int_4 * (int_3 / 8));
     this.int_1           = this.int_0 * (int)this.short_1;
 }
コード例 #22
0
ファイル: WaveFormat.cs プロジェクト: ExileLord/Open-GHTCP
 public WaveFormat(int int_2, int int_3, int int_4)
 {
     if (int_4 < 1)
     {
         throw new ArgumentOutOfRangeException("Channels must be 1 or greater.", "channels");
     }
     this.waveFormatTag_0 = WaveFormatTag.PCM;
     this.short_0 = (short)int_4;
     this.int_0 = int_2;
     this.short_2 = (short)int_3;
     this.short_3 = 0;
     this.short_1 = (short)(int_4 * (int_3 / 8));
     this.int_1 = this.int_0 * (int)this.short_1;
 }
コード例 #23
0
 /// <summary>
 /// Creates a new instance of the <see cref="WaveFormatEx"/> class.
 /// </summary>
 /// <param name="formatTag">The format tag</param>
 /// <param name="samplingRate">The sampling frequency</param>
 /// <param name="bitsPerSample">The number of bits per channel sample</param>
 /// <param name="channels">The number of audio channels</param>
 /// <param name="blockAlign">The block alignment</param>
 /// <param name="avgBytesPerSecond">The average number of bytes per second</param>
 /// <param name="extraInfo">An array containing extra format-specific information</param>
 /// <returns>The WaveFormat object</returns>
 public static WaveFormatEx Create(WaveFormatTag formatTag, int samplingRate, int bitsPerSample, int channels, int blockAlign, int avgBytesPerSecond, byte[] extraInfo = null)
 {
     return(new WaveFormatEx()
     {
         FormatTag = formatTag,
         SamplesPerSec = (uint)samplingRate,
         BitsPerSample = (ushort)bitsPerSample,
         Channels = (ushort)channels,
         BlockAlign = (ushort)blockAlign,
         AvgBytesPerSec = (uint)avgBytesPerSecond,
         ExtraSize = (ushort)(extraInfo?.Length ?? 0),
         ExtraInfo = extraInfo
     });
 }
コード例 #24
0
ファイル: AcmFileWriter.cs プロジェクト: barjonas/ManagedBass
        /// <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);
            }
        }
コード例 #25
0
 public WaveFormatEx(WaveFormatTag format, int channels, int frequency, int bitsPerSample)
 {
     wFormatTag = format;
     nChannels = (ushort)channels;
     nSamplesPerSec = (uint)frequency;
     nBlockAlign = (ushort)(bitsPerSample * channels / 8);
     nAvgBytesPerSec = nBlockAlign * nSamplesPerSec;
     wBitsPerSample = (ushort)bitsPerSample;
     cbSize = 0;
 }
コード例 #26
0
ファイル: WAVEFORMATEX.cs プロジェクト: hirekoke/CoreAudioApi
 public WAVEFORMATEXTENSIBLE(WAVEFORMATEXTENSIBLE o)
 {
     wFormatTag = o.wFormatTag;
     nChannels = o.nChannels;
     nSamplesPerSec = o.nSamplesPerSec;
     nAvgBytesPerSec = o.nAvgBytesPerSec;
     nBlockAlign = o.nBlockAlign;
     wBitsPerSample = o.wBitsPerSample;
     cbSize = o.cbSize;
     wValidBitsPerSample = o.wValidBitsPerSample;
     dwChannelMask = o.dwChannelMask;
     SubFormat = o.SubFormat;
 }
コード例 #27
0
        /// <summary>
        /// Initializes a new instance of the FontVersion class.
        /// </summary>
        /// <param name="name">Voice font name.</param>
        /// <param name="compress">Compress mode.</param>
        /// <param name="encoding">Encoding.</param>
        /// <param name="samplesPerSecond">Samples per second.</param>
        /// <param name="bytesPerSample">Bytes per second.</param>
        public FontVersion(string name, WaveCompressCatalog compress, WaveFormatTag encoding,
            int samplesPerSecond, int bytesPerSample)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            if (samplesPerSecond != 16000 && samplesPerSecond != 8000)
            {
                string message = string.Format(CultureInfo.InvariantCulture,
                    "Only 16k Hz (16000) and 8K hz (8000) sampling rate are supported");
                throw new ArgumentException(message);
            }

            if (bytesPerSample != 2 && bytesPerSample != 1)
            {
                string message = string.Format(CultureInfo.InvariantCulture,
                    "Only 1 and 2 bytesPerSample are supported");
                throw new ArgumentException(message);
            }

            _name = name;
            _compressCatalog = compress;
            _pcmCategory = encoding;
            _samplesPerSecond = samplesPerSecond;
            _bytesPerSample = bytesPerSample;

            Validate();
        }
コード例 #28
0
        public WAVEFORMATEX(int rate, int bits, int channels)
        {
            formatTag		= WaveFormatTag.PCM;
            nChannels		= (short)channels;
            nSamplesPerSec	= rate;
            wBitsPerSample	= (short)bits;
            cbSize			= 0;

            nBlockAlign		= (short)(channels * (bits / 8));
            nAvgBytesPerSec = nSamplesPerSec * nBlockAlign;
            extraInfo		= 0;
        }
コード例 #29
0
 public abstract AudioBuffer CreateBuffer(WaveFormatTag format, int channels, int bps, int frequency, int size);