/// <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); } }
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); } }
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); }
/// <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."); }
//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)); }
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; }
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; }
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(); }
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; }
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; }
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; }
/// <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)); }
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; }
/// <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 }); }
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; }
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; }
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); }
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)); }
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; }
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; }
/// <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 }); }
/// <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); } }
/// <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(); }
public abstract AudioBuffer CreateBuffer(WaveFormatTag format, int channels, int bps, int frequency, int size);