Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Speech / Src / AudioFormat / SpeechAudioFormatInfo.cs / 1 / SpeechAudioFormatInfo.cs
//------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------- using System; using System.ComponentModel; using System.Speech.Internal.Synthesis; namespace System.Speech.AudioFormat { /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo"]/*' /> [Serializable] #if !SPEECHSERVER public #else internal #endif class SpeechAudioFormatInfo { //******************************************************************* // // Constructors // //******************************************************************* #region Constructors private SpeechAudioFormatInfo (EncodingFormat encodingFormat, int samplesPerSecond, short bitsPerSample, short channelCount, byte [] formatSpecificData) { if (encodingFormat == 0) { throw new ArgumentException (SR.Get (SRID.CannotUseCustomFormat), "encodingFormat"); } if (samplesPerSecond <= 0) { throw new ArgumentOutOfRangeException ("samplesPerSecond", SR.Get (SRID.MustBeGreaterThanZero)); } if (bitsPerSample <= 0) { throw new ArgumentOutOfRangeException ("bitsPerSample", SR.Get (SRID.MustBeGreaterThanZero)); } if (channelCount <= 0) { throw new ArgumentOutOfRangeException ("channelCount", SR.Get (SRID.MustBeGreaterThanZero)); } _encodingFormat = encodingFormat; _samplesPerSecond = samplesPerSecond; _bitsPerSample = bitsPerSample; _channelCount = channelCount; if (formatSpecificData == null) { _formatSpecificData = new byte [0]; } else { _formatSpecificData = (byte []) formatSpecificData.Clone (); } switch (encodingFormat) { case EncodingFormat.ALaw: case EncodingFormat.ULaw: if (bitsPerSample != 8) { throw new ArgumentOutOfRangeException ("bitsPerSample"); } if (formatSpecificData != null && formatSpecificData.Length != 0) { throw new ArgumentOutOfRangeException ("formatSpecificData"); } break; } } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.AudioFormatInfo1"]/*' /> [EditorBrowsable (EditorBrowsableState.Advanced)] public SpeechAudioFormatInfo (EncodingFormat encodingFormat, int samplesPerSecond, int bitsPerSample, int channelCount, int averageBytesPerSecond, int blockAlign, byte [] formatSpecificData) : this (encodingFormat, samplesPerSecond, (short) bitsPerSample, (short) channelCount, formatSpecificData) { // Don't explicitly check these are sensible values - allow flexibility here as some formats may do unexpected things here. if (averageBytesPerSecond <= 0) { throw new ArgumentOutOfRangeException ("averageBytesPerSecond", SR.Get (SRID.MustBeGreaterThanZero)); } if (blockAlign <= 0) { throw new ArgumentOutOfRangeException ("blockAlign", SR.Get (SRID.MustBeGreaterThanZero)); } _averageBytesPerSecond = averageBytesPerSecond; _blockAlign = (short) blockAlign; } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.AudioFormatInfo2"]/*' /> public SpeechAudioFormatInfo (int samplesPerSecond, AudioBitsPerSample bitsPerSample, AudioChannel channel) : this (EncodingFormat.Pcm, samplesPerSecond, (short) bitsPerSample, (short) channel, null) { // Don't explicitly check these are sensible values - allow flexibility here as some formats may do unexpected things here. _blockAlign = (short) (_channelCount * (_bitsPerSample / 8)); _averageBytesPerSecond = _samplesPerSecond * _blockAlign; } #endregion //******************************************************************** // // Public Properties // //******************************************************************* #region Public Properties /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.AverageBytesPerSecond"]/*' /> [EditorBrowsable (EditorBrowsableState.Advanced)] public int AverageBytesPerSecond { get { return _averageBytesPerSecond; } } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.BitsPerSample"]/*' /> [EditorBrowsable (EditorBrowsableState.Advanced)] public int BitsPerSample { get { return _bitsPerSample; } } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.BlockAlign"]/*' /> [EditorBrowsable (EditorBrowsableState.Advanced)] public int BlockAlign { get { return _blockAlign; } } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.Format"]/*' /> public EncodingFormat EncodingFormat { get { return _encodingFormat; } } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.NumberOfChannels"]/*' /> public int ChannelCount { get { return _channelCount; } } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.SamplesPerSecond"]/*' /> public int SamplesPerSecond { get { return _samplesPerSecond; } } #endregion //******************************************************************** // // Public Methods // //******************************************************************** #region Public Methods /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.FormatSpecificData"]/*' /> public byte [] FormatSpecificData () { return (byte []) _formatSpecificData.Clone (); } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.Equals"]/*' /> public override bool Equals (object obj) { SpeechAudioFormatInfo refObj = obj as SpeechAudioFormatInfo; if (refObj == null) { return false; } if (!(_averageBytesPerSecond.Equals (refObj._averageBytesPerSecond) && _bitsPerSample.Equals (refObj._bitsPerSample) && _blockAlign.Equals (refObj._blockAlign) && _encodingFormat.Equals (refObj._encodingFormat) && _channelCount.Equals (refObj._channelCount) && _samplesPerSecond.Equals (refObj._samplesPerSecond))) { return false; } if (_formatSpecificData.Length != refObj._formatSpecificData.Length) { return false; } for (int i = 0; i < _formatSpecificData.Length; i++) { if (_formatSpecificData [i] != refObj._formatSpecificData [i]) { return false; } } return true; } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.GetHashCode"]/*' /> public override int GetHashCode () { return _averageBytesPerSecond.GetHashCode (); } #endregion //******************************************************************* // // Internal Methods // //******************************************************************** #region Internal Methods #if !SPEECHSERVER internal byte [] WaveFormat { get { WAVEFORMATEX wfx = new WAVEFORMATEX (); wfx.wFormatTag = (short) EncodingFormat; wfx.nChannels = (short) ChannelCount; wfx.nSamplesPerSec = SamplesPerSecond; wfx.nAvgBytesPerSec = AverageBytesPerSecond; wfx.nBlockAlign = (short) BlockAlign; wfx.wBitsPerSample = (short) BitsPerSample; wfx.cbSize = (short) FormatSpecificData ().Length; byte [] abWfx = wfx.ToBytes (); if (wfx.cbSize > 0) { byte [] wfxTemp = new byte [abWfx.Length + wfx.cbSize]; Array.Copy (abWfx, wfxTemp, abWfx.Length); Array.Copy (FormatSpecificData (), 0, wfxTemp, abWfx.Length, wfx.cbSize); abWfx = wfxTemp; } return abWfx; } } #endif #endregion //******************************************************************* // // Private Fields // //******************************************************************* #region Private Fields private int _averageBytesPerSecond; private short _bitsPerSample; private short _blockAlign; private EncodingFormat _encodingFormat; private short _channelCount; private int _samplesPerSecond; private byte [] _formatSpecificData; #endregion } //******************************************************************* // // Public Properties // //******************************************************************** #region Public Properties ////// TODOC /// #if !SPEECHSERVER public #else internal #endif enum AudioChannel { ////// TODOC /// Mono = 1, ////// TODOC /// Stereo = 2 } ////// TODOC /// #if !SPEECHSERVER public #else internal #endif enum AudioBitsPerSample { ////// TODOC /// Eight = 8, ////// TODOC /// Sixteen = 16 } #endregion } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------- using System; using System.ComponentModel; using System.Speech.Internal.Synthesis; namespace System.Speech.AudioFormat { /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo"]/*' /> [Serializable] #if !SPEECHSERVER public #else internal #endif class SpeechAudioFormatInfo { //******************************************************************* // // Constructors // //******************************************************************* #region Constructors private SpeechAudioFormatInfo (EncodingFormat encodingFormat, int samplesPerSecond, short bitsPerSample, short channelCount, byte [] formatSpecificData) { if (encodingFormat == 0) { throw new ArgumentException (SR.Get (SRID.CannotUseCustomFormat), "encodingFormat"); } if (samplesPerSecond <= 0) { throw new ArgumentOutOfRangeException ("samplesPerSecond", SR.Get (SRID.MustBeGreaterThanZero)); } if (bitsPerSample <= 0) { throw new ArgumentOutOfRangeException ("bitsPerSample", SR.Get (SRID.MustBeGreaterThanZero)); } if (channelCount <= 0) { throw new ArgumentOutOfRangeException ("channelCount", SR.Get (SRID.MustBeGreaterThanZero)); } _encodingFormat = encodingFormat; _samplesPerSecond = samplesPerSecond; _bitsPerSample = bitsPerSample; _channelCount = channelCount; if (formatSpecificData == null) { _formatSpecificData = new byte [0]; } else { _formatSpecificData = (byte []) formatSpecificData.Clone (); } switch (encodingFormat) { case EncodingFormat.ALaw: case EncodingFormat.ULaw: if (bitsPerSample != 8) { throw new ArgumentOutOfRangeException ("bitsPerSample"); } if (formatSpecificData != null && formatSpecificData.Length != 0) { throw new ArgumentOutOfRangeException ("formatSpecificData"); } break; } } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.AudioFormatInfo1"]/*' /> [EditorBrowsable (EditorBrowsableState.Advanced)] public SpeechAudioFormatInfo (EncodingFormat encodingFormat, int samplesPerSecond, int bitsPerSample, int channelCount, int averageBytesPerSecond, int blockAlign, byte [] formatSpecificData) : this (encodingFormat, samplesPerSecond, (short) bitsPerSample, (short) channelCount, formatSpecificData) { // Don't explicitly check these are sensible values - allow flexibility here as some formats may do unexpected things here. if (averageBytesPerSecond <= 0) { throw new ArgumentOutOfRangeException ("averageBytesPerSecond", SR.Get (SRID.MustBeGreaterThanZero)); } if (blockAlign <= 0) { throw new ArgumentOutOfRangeException ("blockAlign", SR.Get (SRID.MustBeGreaterThanZero)); } _averageBytesPerSecond = averageBytesPerSecond; _blockAlign = (short) blockAlign; } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.AudioFormatInfo2"]/*' /> public SpeechAudioFormatInfo (int samplesPerSecond, AudioBitsPerSample bitsPerSample, AudioChannel channel) : this (EncodingFormat.Pcm, samplesPerSecond, (short) bitsPerSample, (short) channel, null) { // Don't explicitly check these are sensible values - allow flexibility here as some formats may do unexpected things here. _blockAlign = (short) (_channelCount * (_bitsPerSample / 8)); _averageBytesPerSecond = _samplesPerSecond * _blockAlign; } #endregion //******************************************************************** // // Public Properties // //******************************************************************* #region Public Properties /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.AverageBytesPerSecond"]/*' /> [EditorBrowsable (EditorBrowsableState.Advanced)] public int AverageBytesPerSecond { get { return _averageBytesPerSecond; } } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.BitsPerSample"]/*' /> [EditorBrowsable (EditorBrowsableState.Advanced)] public int BitsPerSample { get { return _bitsPerSample; } } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.BlockAlign"]/*' /> [EditorBrowsable (EditorBrowsableState.Advanced)] public int BlockAlign { get { return _blockAlign; } } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.Format"]/*' /> public EncodingFormat EncodingFormat { get { return _encodingFormat; } } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.NumberOfChannels"]/*' /> public int ChannelCount { get { return _channelCount; } } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.SamplesPerSecond"]/*' /> public int SamplesPerSecond { get { return _samplesPerSecond; } } #endregion //******************************************************************** // // Public Methods // //******************************************************************** #region Public Methods /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.FormatSpecificData"]/*' /> public byte [] FormatSpecificData () { return (byte []) _formatSpecificData.Clone (); } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.Equals"]/*' /> public override bool Equals (object obj) { SpeechAudioFormatInfo refObj = obj as SpeechAudioFormatInfo; if (refObj == null) { return false; } if (!(_averageBytesPerSecond.Equals (refObj._averageBytesPerSecond) && _bitsPerSample.Equals (refObj._bitsPerSample) && _blockAlign.Equals (refObj._blockAlign) && _encodingFormat.Equals (refObj._encodingFormat) && _channelCount.Equals (refObj._channelCount) && _samplesPerSecond.Equals (refObj._samplesPerSecond))) { return false; } if (_formatSpecificData.Length != refObj._formatSpecificData.Length) { return false; } for (int i = 0; i < _formatSpecificData.Length; i++) { if (_formatSpecificData [i] != refObj._formatSpecificData [i]) { return false; } } return true; } /// TODOC <_include file='doc\SpeechAudioFormatInfo.uex' path='docs/doc[@for="SpeechAudioFormatInfo.GetHashCode"]/*' /> public override int GetHashCode () { return _averageBytesPerSecond.GetHashCode (); } #endregion //******************************************************************* // // Internal Methods // //******************************************************************** #region Internal Methods #if !SPEECHSERVER internal byte [] WaveFormat { get { WAVEFORMATEX wfx = new WAVEFORMATEX (); wfx.wFormatTag = (short) EncodingFormat; wfx.nChannels = (short) ChannelCount; wfx.nSamplesPerSec = SamplesPerSecond; wfx.nAvgBytesPerSec = AverageBytesPerSecond; wfx.nBlockAlign = (short) BlockAlign; wfx.wBitsPerSample = (short) BitsPerSample; wfx.cbSize = (short) FormatSpecificData ().Length; byte [] abWfx = wfx.ToBytes (); if (wfx.cbSize > 0) { byte [] wfxTemp = new byte [abWfx.Length + wfx.cbSize]; Array.Copy (abWfx, wfxTemp, abWfx.Length); Array.Copy (FormatSpecificData (), 0, wfxTemp, abWfx.Length, wfx.cbSize); abWfx = wfxTemp; } return abWfx; } } #endif #endregion //******************************************************************* // // Private Fields // //******************************************************************* #region Private Fields private int _averageBytesPerSecond; private short _bitsPerSample; private short _blockAlign; private EncodingFormat _encodingFormat; private short _channelCount; private int _samplesPerSecond; private byte [] _formatSpecificData; #endregion } //******************************************************************* // // Public Properties // //******************************************************************** #region Public Properties ////// TODOC /// #if !SPEECHSERVER public #else internal #endif enum AudioChannel { ////// TODOC /// Mono = 1, ////// TODOC /// Stereo = 2 } ////// TODOC /// #if !SPEECHSERVER public #else internal #endif enum AudioBitsPerSample { ////// TODOC /// Eight = 8, ////// TODOC /// Sixteen = 16 } #endregion } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- GetPageCompletedEventArgs.cs
- DataControlField.cs
- _TimerThread.cs
- FixedPageAutomationPeer.cs
- Ipv6Element.cs
- SourceItem.cs
- ArgumentException.cs
- SuspendDesigner.cs
- Or.cs
- RSAOAEPKeyExchangeFormatter.cs
- DocumentApplication.cs
- TCPClient.cs
- WebServiceParameterData.cs
- InputLanguageEventArgs.cs
- XsltLoader.cs
- ControlAdapter.cs
- ErrorView.xaml.cs
- UnsafeNetInfoNativeMethods.cs
- Variant.cs
- ContextMenuService.cs
- XmlPropertyBag.cs
- UnsafeNativeMethodsTablet.cs
- SoapFault.cs
- CollectionTraceRecord.cs
- FolderBrowserDialogDesigner.cs
- DataGridViewControlCollection.cs
- SystemIPInterfaceProperties.cs
- UserUseLicenseDictionaryLoader.cs
- NativeMethods.cs
- manifestimages.cs
- MethodBody.cs
- SharedPerformanceCounter.cs
- ProfilePropertyNameValidator.cs
- Base64Encoder.cs
- XmlIncludeAttribute.cs
- State.cs
- TextStore.cs
- SessionStateSection.cs
- DataGridViewLayoutData.cs
- xsdvalidator.cs
- RecordsAffectedEventArgs.cs
- EncodingInfo.cs
- DefaultBindingPropertyAttribute.cs
- SQLByteStorage.cs
- CellIdBoolean.cs
- DataGridViewUtilities.cs
- mda.cs
- mda.cs
- WasHttpModulesInstallComponent.cs
- HMAC.cs
- LicenseContext.cs
- StringUtil.cs
- IDReferencePropertyAttribute.cs
- sitestring.cs
- SessionStateItemCollection.cs
- ListViewGroupItemCollection.cs
- DataGridViewRowsRemovedEventArgs.cs
- PropertyChangedEventArgs.cs
- Rectangle.cs
- OutputCacheSettings.cs
- ManualResetEvent.cs
- AlignmentYValidation.cs
- StringConverter.cs
- DataBoundLiteralControl.cs
- ConfigurationLocation.cs
- ClientFormsAuthenticationMembershipProvider.cs
- LongTypeConverter.cs
- CachedRequestParams.cs
- ProbeDuplex11AsyncResult.cs
- DesignerAdapterAttribute.cs
- MenuAutomationPeer.cs
- AbstractSvcMapFileLoader.cs
- SetStoryboardSpeedRatio.cs
- WorkflowServiceHostFactory.cs
- LoggedException.cs
- DataServices.cs
- DivideByZeroException.cs
- UnaryNode.cs
- HttpServerUtilityWrapper.cs
- DataListItemEventArgs.cs
- ArgumentValue.cs
- XmlSchemaSimpleContentRestriction.cs
- ToolStripProfessionalLowResolutionRenderer.cs
- NativeCompoundFileAPIs.cs
- UnsafeNativeMethods.cs
- EdmSchemaError.cs
- ToolStripArrowRenderEventArgs.cs
- ISCIIEncoding.cs
- DataGridViewBindingCompleteEventArgs.cs
- XmlSchemaSet.cs
- ClientWindowsAuthenticationMembershipProvider.cs
- WinInetCache.cs
- ExpandoClass.cs
- XmlSchemaAnyAttribute.cs
- RecordBuilder.cs
- OracleNumber.cs
- TableColumn.cs
- MultilineStringEditor.cs
- ChangeNode.cs
- SafeProcessHandle.cs