private void TestLength() { int l; m_pSample.SetLength(12); m_pSample.GetLength(out l); Debug.Assert(l == 12); m_pSample.GetMaxLength(out l); Debug.Assert(l == MAXLENGTH); }
public int Read(AudioBuffer buff, int maxLength) { buff.Prepare(this, maxLength); int buff_offset = 0; int buff_size = buff.ByteLength; while (m_pSampleSize < buff_size) { if (m_pSampleSize > 0) { IntPtr pdwBuffer; m_pSample.GetBuffer(out pdwBuffer); Marshal.Copy((IntPtr)(pdwBuffer.ToInt64() + m_pSampleOffset), buff.Bytes, buff_offset, m_pSampleSize); buff_size -= m_pSampleSize; buff_offset += m_pSampleSize; m_sampleOffset += m_pSampleSize; m_pSampleSize = 0; Marshal.ReleaseComObject(m_pSample); m_pSample = null; } long cnsSampleTime; long cnsDuration; SampleFlag flags; int dwOutputNum; short wStreamNum; try { m_syncReader.GetNextSample(m_wStreamNum, out m_pSample, out cnsSampleTime, out cnsDuration, out flags, out dwOutputNum, out wStreamNum); } catch (COMException ex) { // EOF if (ex.ErrorCode == NSResults.E_NO_MORE_SAMPLES) { if ((m_sampleOffset % PCM.BlockAlign) != 0) { throw new Exception("(m_sampleOffset % PCM.BlockAlign) != 0"); } m_sampleCount = m_sampleOffset / PCM.BlockAlign; if ((buff_offset % PCM.BlockAlign) != 0) { throw new Exception("(buff_offset % PCM.BlockAlign) != 0"); } return(buff.Length = buff_offset / PCM.BlockAlign); } throw ex; } //if (dwOutputNum != m_dwAudioOutputNum || wStreamNum != m_wStreamNum) //{ //} m_pSampleOffset = 0; m_pSample.GetLength(out m_pSampleSize); } if (buff_size > 0) { IntPtr pdwBuffer; m_pSample.GetBuffer(out pdwBuffer); Marshal.Copy((IntPtr)(pdwBuffer.ToInt64() + m_pSampleOffset), buff.Bytes, buff_offset, buff_size); m_pSampleOffset += buff_size; m_pSampleSize -= buff_size; m_sampleOffset += buff_size; buff_offset += buff_size; buff_size = 0; } if ((buff_offset % PCM.BlockAlign) != 0) { throw new Exception("(buff_offset % PCM.BlockAlign) != 0"); } return(buff.Length = buff_offset / PCM.BlockAlign); }