1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include <windows.h>
#include <iostream>
#pragma comment(lib, "winmm.lib")
using namespace std;
int main(){
// I understand what's going on here. Open up the file.
// I was told to use CreateFile() instead, oops. I will fix later.
HMMIO handle = mmioOpen(L"C:\\WINDOWS\\MEDIA\\TADA.WAV", 0, MMIO_READ);
// Create ChunkInfo structure to store the RIFF chunk info
MMCKINFO ChunkInfo;
// My guess is this is to allocate memory for the ChunkInfo structure.
// Why is this only done here, and only for ChunkInfo, or am I
// really confused on what's going on here??
memset(&ChunkInfo,0, sizeof(MMCKINFO));
// Descend into the RIFF chunk and store the info in the
// ChunkInfo structure
mmioDescend(handle, &ChunkInfo, 0, MMIO_FINDRIFF);
// I wanted to see what these were.
cout<<"ChunkInfo.ckid: " <<ChunkInfo.ckid<< endl;
cout<<"ChunkInfo.cksize: " <<ChunkInfo.cksize<< endl;
cout<<"ChunkInfo.dwDataOffset: " <<ChunkInfo.dwDataOffset<< endl;
cout<<"ChunkInfo.dwFlags: " <<ChunkInfo.dwFlags<< endl;
cout<<"ChunkInfo.fccType: " <<ChunkInfo.fccType<< endl;
// Create another structure to store the fmt chunk info
MMCKINFO FormatChunkInfo;
// Assign the ckid of FormatChunkInfo to the result of mmioStringToFOURCC()
FormatChunkInfo.ckid = mmioStringToFOURCC(L"fmt", 0);
// Descend into the fmt chunk, whose parent chunk is RIFF.
// The flag MMIO_FINDCHUNK says to find the chunk with the ckid "fmt".
mmioDescend(handle, &FormatChunkInfo, &ChunkInfo, MMIO_FINDCHUNK);
// Create another structure waveFmt to store the wav format info.
WAVEFORMATEX waveFmt;
// Not sure how this is playing out.
// handle is the handle of the file to be read.
// (char*)&waveFmt is the pointer to a buffer to contain the data read from the file.
// FormatChunkInfo.cksize is being used as the number of bytes to read from the file.
// Pointers throw me off sometimes. How is this a pointer (char*)&waveFmt?
// Is it casting the address of waveFmt as a char* (pointer to a char)??
mmioRead(handle, (char*)&waveFmt, FormatChunkInfo.cksize);
// Same as before creating a structure to store the DataChunkInfo
MMCKINFO DataChunkInfo;
// Because we descended deep into the RIFF chunk,
// we need to ascend out of it before we descend to a new chunk.
mmioAscend(handle, &FormatChunkInfo, 0);
// Assign the ckid of DataChunkInfo to the result of mmioStringToFOURCC()
DataChunkInfo.ckid = mmioStringToFOURCC(L"data", 0);
// Descend into the data chunk, whose parent chunk is RIFF.
// The flag MMIO_FINDCHUNK says to find the chunk with the ckid "data".
mmioDescend(handle, &DataChunkInfo, &ChunkInfo, MMIO_FINDCHUNK);
// Assigning the DataChunkInfo.cksize to a new int size.
unsigned int size = DataChunkInfo.cksize;
// Using "size" to allocate memory for the data to be read into.
char* data1 = new char[size];
// Read from the file, from the chunk we've descended to into data1
mmioRead(handle, data1, size);
// Close the file
mmioClose(handle, 0);
// I tried to use cout to read the data stored in data1
// but got a bunch a big mess of crazy symbols.
system("pause");
return 0;
}
|