GetSampleTypeCode() public method

Determines sample data type code based on defined BitsPerSample and AudioFormat.
public GetSampleTypeCode ( ) : TypeCode
return TypeCode
Beispiel #1
0
        /// <summary>Reads a new WAVE format section from the specified stream.</summary>
        /// <param name="preRead">Pre-parsed <see cref="RiffChunk"/> header.</param>
        /// <param name="source">Source stream to read data from.</param>
        /// <param name="waveFormat">Format of the data section to be parsed.</param>
        /// <exception cref="InvalidOperationException">WAVE format or extra parameters section too small, wave file corrupted.</exception>
        public WaveDataChunk(RiffChunk preRead, Stream source, WaveFormatChunk waveFormat)
            : base(preRead, RiffTypeID)
        {
            m_waveFormat   = waveFormat;
            m_sampleBlocks = new List <LittleBinaryValue[]>();
            m_chunkSize    = -1;

            int      blockSize      = waveFormat.BlockAlignment;
            int      sampleSize     = waveFormat.BitsPerSample / 8;
            int      channels       = waveFormat.Channels;
            TypeCode sampleTypeCode = m_waveFormat.GetSampleTypeCode();

            LittleBinaryValue[] sampleBlock;
            byte[] buffer = new byte[blockSize];

            int bytesRead = source.Read(buffer, 0, blockSize);

            while (bytesRead == blockSize)
            {
                // Create a new sample block, one little-endian formatted binary sample value for each channel
                sampleBlock = new LittleBinaryValue[channels];

                for (int x = 0; x < channels; x++)
                {
                    sampleBlock[x] = new LittleBinaryValue(sampleTypeCode, buffer, x * sampleSize, sampleSize);
                }

                m_sampleBlocks.Add(sampleBlock);

                bytesRead = source.Read(buffer, 0, blockSize);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Creates a new instance of the <see cref="WaveDataReader"/> class.
 /// </summary>
 /// <param name="waveFormat">The format of the wave stream.</param>
 /// <param name="waveStream">The stream containing wave data.</param>
 public WaveDataReader(WaveFormatChunk waveFormat, Stream waveStream)
 {
     m_format     = waveFormat ?? DEFAULT_WAVE_FORMAT_CHUNK;
     m_waveStream = waveStream;
     m_blockSize  = m_format.BlockAlignment;
     m_sampleSize = m_format.BitsPerSample / 8;
     m_channels   = m_format.Channels;
     m_sampleType = m_format.GetSampleTypeCode();
 }
Beispiel #3
0
        /// <summary>Reads a new WAVE format section from the specified stream.</summary>
        /// <param name="preRead">Pre-parsed <see cref="RiffChunk"/> header.</param>
        /// <param name="source">Source stream to read data from.</param>
        /// <param name="waveFormat">Format of the data section to be parsed.</param>
        /// <exception cref="InvalidOperationException">WAVE format or extra parameters section too small, wave file corrupted.</exception>
        public WaveDataChunk(RiffChunk preRead, Stream source, WaveFormatChunk waveFormat)
            : base(preRead, RiffTypeID)
        {
            m_waveFormat = waveFormat;
            m_sampleBlocks = new List<LittleBinaryValue[]>();
            m_chunkSize = -1;

            int blockSize = waveFormat.BlockAlignment;
            int sampleSize = waveFormat.BitsPerSample / 8;
            int channels = waveFormat.Channels;
            TypeCode sampleTypeCode = m_waveFormat.GetSampleTypeCode();
            LittleBinaryValue[] sampleBlock;
            byte[] buffer = new byte[blockSize];

            int bytesRead = source.Read(buffer, 0, blockSize);

            while (bytesRead == blockSize)
            {
                // Create a new sample block, one little-endian formatted binary sample value for each channel
                sampleBlock = new LittleBinaryValue[channels];

                for (int x = 0; x < channels; x++)
                {
                    sampleBlock[x] = new LittleBinaryValue(sampleTypeCode, buffer, x * sampleSize, sampleSize);
                }

                m_sampleBlocks.Add(sampleBlock);

                bytesRead = source.Read(buffer, 0, blockSize);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Creates a new instance of the <see cref="WaveDataReader"/> class.
 /// </summary>
 /// <param name="waveFormat">The format of the wave stream.</param>
 /// <param name="waveStream">The stream containing wave data.</param>
 public WaveDataReader(WaveFormatChunk waveFormat, Stream waveStream)
 {
     m_format = waveFormat ?? DEFAULT_WAVE_FORMAT_CHUNK;
     m_waveStream = waveStream;
     m_blockSize = m_format.BlockAlignment;
     m_sampleSize = m_format.BitsPerSample / 8;
     m_channels = m_format.Channels;
     m_sampleType = m_format.GetSampleTypeCode();
 }