Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mmio....reading in a stereo wav file

Status
Not open for further replies.

rdalton

Programmer
Dec 5, 2002
24
US
I'm using mmioRead to read in the data chunk of a wav file, but if the file has two channels I want to seperate each channels data, which is interlaced. Does anyone know any function that will seperate the channels data? Right now I'm reading everything, then looping through the returned array and splitting it that way. That's ok for small files, but much larger files take a long time to process. Any ideas? thanks.

Bob
 
You're reading mono wav files with MVC++ ? But how???
 
The header file is <mmsystem.h>. It has many different functions defined for MultiMedia Input/Output (mmio). There are specific function for parsing RIFF filetypes. A good link is:


My problem is that I want to strip off the left and right channel sample data from a stereo wav file. In a stereo wav file the sample data is stored as left sample data then right sample data. I'm trying to figure out how to read just the left data into an array and the right sample data into its own array. And I'm trying to do this quickly. Currently I'm reading the entire sample data then parsing through and building my seperate arrays, but when the wave file is 80MB this takes too long...way too long.
 
If you allready know the structure of the header, simply read samples one by one. The data follows right after the header, for stereo files samples are located in pairs. Length of one sample is 1 or 2 bytes - depending of encoding depth, follow information in header.
 
Oh thanks rdalton but for some reason I cant run it? Should I include <windows.h> too? Compiling example source code went ok, but I got 6 error linking it like : &quot;wave.obj : error LNK2001: unresolved external symbol __imp__mmioAscend@12&quot; . What is the problem? Is it ok for you running mono wave file through MVC++? It should be done in C++ Source File, right?..not in the ones using windows ? Could you please show me your testing code 'only' reading and playing that wave file?
 
H3R0:

You have to make sure to link the library.
Project->Settings...(Link tab), then under
Object/Libraray modules, add winmm.lib

Here's the code for getting the wave header info,
and the wave sample data...my playback code is very
long and is not using typical playback methods. I hope this helps...


short* WavFileToArray(CString ptr, long *size)
{
HMMIO hmmio;
// for the Group Header
MMCKINFO mmckinfoParent;
// for finding chunks within the Group
MMCKINFO mmckinfoSubchunk;
// for reading a fmt chunk's data
WAVEFORMATEX waveFormat;
DWORD WaveDataSize;

short *track = NULL;

if (!(hmmio = mmioOpen(ptr.GetBuffer(ptr.GetLength()), 0, MMIO_READ|MMIO_ALLOCBUF)))
AfxMessageBox(&quot;Error opening the .WAV file!\n&quot;);
else
{
mmckinfoParent.fccType = mmioFOURCC('W', 'A', 'V', 'E');
if (mmioDescend(hmmio, (LPMMCKINFO)&mmckinfoParent, 0, MMIO_FINDRIFF))
printf(&quot;ERROR: This file doesn't contain a WAVE!\n&quot;);
else
{
mmckinfoSubchunk.ckid = mmioFOURCC('f', 'm', 't', ' ');
if (mmioDescend(hmmio, &mmckinfoSubchunk, &mmckinfoParent, MMIO_FINDCHUNK))
printf(&quot;ERROR: Required fmt chunk was not found!\n&quot;);
else
{
if (mmioRead(hmmio, (HPSTR)&waveFormat, mckinfoSubchunk.cksize) != (LRESULT)mmckinfoSubchunk.cksize)
printf(&quot;ERROR: reading the fmt chunk!\n&quot;);
else
mmioAscend(hmmio, &mmckinfoSubchunk, 0);
}

mmckinfoSubchunk.ckid = mmioFOURCC('d', 'a', 't', 'a');
if (mmioDescend(hmmio, &mmckinfoSubchunk, &mmckinfoParent, MMIO_FINDCHUNK))
printf(&quot;An erroring reading the data chunk!\n&quot;);
else
{
WaveDataSize = mmckinfoSubchunk.cksize;
*size = (long)WaveDataSize;
track = new short[*size];
mmioRead(hmmio, (char *)track, *size);
}
}
mmioClose(hmmio, 0);
}
return track;
}
 
mingis:

I have the header information...mainly the filesize and sample size (2 bytes). The problem is that it's taking too long to either 1:Read all the data (both left and right channels) then parse through the array and split into two seperate arrays. 2: Loop through the filesize and read 2bytes into the left array, then two bytes into the right array. For files that are 80,000,000 bytes, this takes too long. Do you know any way to speed up the process. Loops just won't cut it. thanks.
 
Why do you load data to arrays? Why not operate directly to files? What actions do you want to perform? Simply split channels to two mono files? Just read input file sample by sample and write two output files &quot;on-the fly&quot; then. On the other hand - what time do you expect to spend for even simply copying of 80 MB of data? It cannot be quick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top