reading wav files, extract the sub-chunk with data, play wav

Hi there,

I'm a newby, and so I need your help. It's more like a big help I'm looking for.

I have searched for a way to do this:

  • open a *.wav file
  • start reading the sub-chunk containing the wave data
  • generate some data using this chunk
  • play that chunk
  • print a graphic using GDI+
  • go to next chunk
  • etc..

it's, ofcourse, a wave form graphics application.

I am using the wavefile class (I have found many alternatives), and I have these problems:

  • I don't know where exactly is stored the "current"(at some point) data chunk;
  • how can I read what's in the buffer containing this chunk from another .dll (a class witch a function that processes this data)
  • I know that there are 2 buffers when playing: the one containing the chunk that is played (at some point), and another one with the next chunk. WHICH one is the first, and which is the other

I hope I will finf some answers from you, and the code I've used to open the WAV file is (it' not developed by me...):

Private Sub Open(ByVal filename As String)

' Make sure the file exists

If (Not File.Exists(filename)) Then Throw New FileNotFoundException("The media file could not be found.", filename)

' Open the input file

Input = mmioOpen(filename, IntPtr.Zero, MMIO_READ)

If (Input.Equals(IntPtr.Zero)) Then Throw New MediaException("An error occurs while opening the media file.")

' make sure this is a wave file

Dim mmi As New MMCKINFO()

mmi.fccType = mmioStringToFOURCC("WAVE", 0)

If (mmioDescend(Input, mmi, IntPtr.Zero, MMIO_FINDRIFF) <> MMSYSERR_NOERROR) Then

Close()

Throw New MediaException("The media file is invalid.")

End If

' get format info

mmi = New MMCKINFO()

mmi.ckid = mmioStringToFOURCC("fmt", 0)

If (mmioDescend(Input, mmi, IntPtr.Zero, MMIO_FINDCHUNK) <> MMSYSERR_NOERROR) Then

Close()

Throw New MediaException("The format chunk could not be found.")

End If

m_Format = New WAVEFORMAT()

If (mmioRead(Input, m_Format, Marshal.SizeOf(m_Format)) = -1) Then

Close()

Throw New MediaException("An error occurs while reading from the media file.")

End If

mmioAscend(Input, mmi, 0)

' find the data subchunk

mmi.ckid = mmioStringToFOURCC("data", 0)

If (mmioDescend(Input, mmi, IntPtr.Zero, MMIO_FINDCHUNK) <> MMSYSERR_NOERROR) Then

Close()

Throw New MediaException("The data chunk could not be found.")

End If

m_DataOffset = mmioSeek(Input, 0, SEEK_CUR)

' Get the length of the audio

m_AudioLength = mmi.ckSize

' Allocate audio buffers

m_BufferSize = CType(m_Format.nSamplesPerSec * m_Format.nBlockAlign * m_Format.nChannels * BUFFER_SECONDS, Integer)

m_BufferSize = m_BufferSize - (m_BufferSize Mod m_Format.nBlockAlign)

ReDim m_Buffer(m_Buffers - 1)

ReDim m_Header(m_Buffers - 1)

Dim i As Integer

For i = 0 To m_Buffer.Length - 1

m_Buffer(i) = Marshal.AllocHGlobal(m_BufferSize)

Next

End Sub

Thank you !




Answer this question

reading wav files, extract the sub-chunk with data, play wav

  • betamark

    any advice will be good

  • xLogicTalentedx

    OK, it's done!



  • reading wav files, extract the sub-chunk with data, play wav