我想把两个WAV文件合并到一起,文件的DATA已经合并完成了,
 可是还是遇到了一个小问题,
>1,使用mmioRead将l_hFile的数据读出来了
>2,使用mmioSeek将m_hFile的指针移到最后
>3,使用mmioWrite将l_hFile的数据写到m_hFile中
>可写过以后m_hFile中的data部分的.ckSize仍然是原来的值。
>1.wav里面就是一个“1”的声音
2.wav里面就是一个“2”的声音
>所以我将1.wav 写到2.wav后,2.wav的文件DATA部分确实已经合并,但播放时2.wav仍然只发出了"2"这个声音,,
>
>我怎样能够将m_hFile中的data部分的.ckSize重新改过再写进去,谢谢。
>以下是我改过的程序:
>extern "C" long PASCAL EXPORT AppendWaveFile(LPCTSTR SouflName,LPCTSTR DesflName)
>{ 
> HMMIO l_hFile;
> HMMIO m_hFile;
>
>
> MMCKINFO l_MMCKInfoData;
> MMCKINFO l_MMCKInfoParent;
> MMCKINFO l_MMCKInfoChild;
> ZeroMemory(&l_MMCKInfoParent,sizeof(MMCKINFO));
> ZeroMemory(&l_MMCKInfoChild,sizeof(MMCKINFO));
> ZeroMemory(&l_MMCKInfoData,sizeof(MMCKINFO));
> MMIOINFO info;
> memset(&info,0,sizeof(info));
>
> //
> char charSou[128] = {0};
> char charDes[128] = {0};
>
> //strcpy(charSou,"E:\\WORK\\WavAppend\\pig.wav");
> //strcpy(charDes,"E:\\WORK\\WavAppend\\dog.wav");
> strcpy(charSou,SouflName);
> strcpy(charDes,DesflName);
> //
>
> if (!mmioOpen((char *)charSou,NULL,MMIO_EXIST))
> return ERROR_FILE_NOT_EXIST;
> l_hFile = mmioOpen((char*)charSou,NULL,MMIO_READ);
>
> if(l_hFile == NULL) 
> {
> //m_Mode = FILE_ERROR;
> switch (info.wErrorRet )
> { 
> case MMIOERR_ACCESSDENIED ://The file is protected and cannot be opened. 
> return ERROR_FILE_ACEESS_DENIED;
> break;
> case MMIOERR_PATHNOTFOUND:// The directory specification is incorrect. 
> return ERROR_FILE_NOT_EXIST;
> break;
> case MMIOERR_SHARINGVIOLATION: //The file is being used by another application and is unavailable. 
> return ERROR_FILE_SHARING_VIOLATION;
> break;
> case MMIOERR_NETWORKERROR:// The network is not responding to the request to open a remote file. 

> case MMIOERR_INVALIDFILE://Another failure condition occurred. This is the default error for an open-file failure. 

> case MMIOERR_TOOMANYOPENFILES:
> default:

> return ERROR_FILE_ACCESS_ERROR;
> }
> }
> //
> m_hFile = mmioOpen((char*)charDes,NULL,MMIO_WRITE);

> //
>
> if(m_hFile == NULL) 
> {
> //m_Mode = FILE_ERROR;
> switch (info.wErrorRet )
> { 
> case MMIOERR_ACCESSDENIED ://The file is protected and cannot be opened. 
> return ERROR_FILE_ACEESS_DENIED;
> break;
> case MMIOERR_PATHNOTFOUND:// The directory specification is incorrect. 
> return ERROR_FILE_NOT_EXIST;
> break;
> case MMIOERR_SHARINGVIOLATION: //The file is being used by another application and is unavailable. 
> return ERROR_FILE_SHARING_VIOLATION;
> break;
> case MMIOERR_NETWORKERROR:// The network is not responding to the request to open a remote file. 

> case MMIOERR_INVALIDFILE://Another failure condition occurred. This is the default error for an open-file failure. 

> case MMIOERR_TOOMANYOPENFILES:
> default:

> return ERROR_FILE_ACCESS_ERROR;
> }
> }
>
> l_MMCKInfoParent.fccType = mmioFOURCC('W','A','V','E');
> MMRESULT mmResult = ::mmioDescend(l_hFile, &l_MMCKInfoParent,NULL,MMIO_FINDRIFF);
> //mmResult = mmioAscend(l_hFile,&l_MMCKInfoParent,0);
> //mmResult=mmioSeek(l_hFile,0,SEEK_SET);
> if(mmResult)
> {
> AfxMessageBox("Error descending into file");
> mmioClose(m_hFile,0);
> m_hFile = NULL;
> mmioClose(l_hFile,0);
> l_hFile = NULL;
> //m_Mode = FILE_ERROR;
> return ERROR_FILE_ACCESS_ERROR;
> }
> l_MMCKInfoChild.ckid = mmioFOURCC('f','m','t',' ');
> mmResult = mmioDescend(l_hFile,&l_MMCKInfoChild,&l_MMCKInfoParent,MMIO_FINDCHUNK);
> if(mmResult)
> {
> AfxMessageBox("Error descending in wave file");
> mmioClose(m_hFile,0);
> m_hFile = NULL;
> mmioClose(l_hFile,0);
> //m_Mode = FILE_ERROR;
> l_hFile = NULL;
> return ERROR_FILE_ACCESS_ERROR;
> }
> WAVEFORMATEX l_Format;
>
>// WAVEFORMATEX *pOrigFormat=this->GetFormat();
>
> DWORD bytesRead = mmioRead(l_hFile,(LPSTR)&l_Format,sizeof(WAVEFORMATEX));//+m_MMCKInfoChild.cksize);

> /*
> if ((pOrigFormat->nChannels!=l_Format.nChannels)
> ||(pOrigFormat->nSamplesPerSec!=l_Format.nSamplesPerSec)
> ||(pOrigFormat->wBitsPerSample!=l_Format.wBitsPerSample))
> return ERROR_INVALID_WAVE_FORMAT;
> */
>
> if(bytesRead < 0)
> {
> AfxMessageBox("Error reading PCM wave format record");
> mmioClose(m_hFile,0);
> m_hFile = NULL;
> mmioClose(l_hFile,0);
> l_hFile = NULL;
> return ERROR_FILE_ACCESS_ERROR;
> }
>
> // open output sound file
> mmResult = mmioAscend(l_hFile,&l_MMCKInfoChild,0);
> if(mmResult)
> {
> AfxMessageBox("Error ascending in File");
> mmioClose(m_hFile,0);
> m_hFile = NULL;
> mmioClose(l_hFile,0);
> l_hFile = NULL;
>
> return ERROR_FILE_ACCESS_ERROR;
> }
> l_MMCKInfoChild.ckid = mmioFOURCC('d','a','t','a');
> mmResult = mmioDescend(l_hFile,&l_MMCKInfoChild,
> &l_MMCKInfoParent,MMIO_FINDCHUNK);
> if(mmResult)
> {
> AfxMessageBox("error reading data chunk");
> mmioClose(m_hFile,0);
> m_hFile = NULL;
> mmioClose(l_hFile,0);
> l_hFile = NULL;
>
> return ERROR_FILE_ACCESS_ERROR;
> }
>
> BYTE * lpData=(BYTE*)malloc(l_MMCKInfoChild.cksize);
> if(mmioRead(l_hFile,(HPSTR)lpData,l_MMCKInfoChild.cksize)!=l_MMCKInfoChild.cksize)
> return ERROR_FILE_ACCESS_ERROR;
>
> //秦ADD
> LONG m_LSeek;
> m_LSeek = mmioSeek(m_hFile,0,SEEK_END);// Seek End of file
> if (m_LSeek ==-1)
> {
> return ERROR_FILE_ACCESS_ERROR;
> }
>
> //mmRESULT = mmioGetInfo(m_hFile,,)
>
> //秦ADD
> long nBytes;
> nBytes=mmioWrite(m_hFile,(LPCTSTR)lpData,l_MMCKInfoChild.cksize);
> if (nBytes!=l_MMCKInfoChild.cksize)
> { free(lpData);
> mmioClose(m_hFile,0);
> m_hFile = NULL;
> mmioClose(l_hFile,0);
> return ERROR_FILE_ACCESS_ERROR;
> }
> free(lpData);
> mmioClose(m_hFile,0);
> m_hFile = NULL;
> mmioClose(l_hFile,0);
> l_hFile = NULL;
> //m_FilePos=m_FilePos+nBytes;
> //if (m_FilePos>m_FileLen) m_FileLen=m_FilePos;

> return OK_SUCCESS;
>
>
>}
>
>
>
>
>
>

解决方案 »

  1.   

    现在剩下的问题就是如何
    改变WAV文件中data部分的ckSize大小
    难道没有人用过吗?
      

  2.   

    >extern "C" long PASCAL EXPORT AppendWaveFile(LPCTSTR SouflName,LPCTSTR DesflName)
    >{ 
    > HMMIO l_hFile;
    > HMMIO m_hFile;
    >
    >
    > MMCKINFO l_MMCKInfoData;
    > MMCKINFO l_MMCKInfoParent;
    > MMCKINFO l_MMCKInfoChild;
    > ZeroMemory(&l_MMCKInfoParent,sizeof(MMCKINFO));
    > ZeroMemory(&l_MMCKInfoChild,sizeof(MMCKINFO));
    > ZeroMemory(&l_MMCKInfoData,sizeof(MMCKINFO));
    > MMIOINFO info;
    > memset(&info,0,sizeof(info));
    >
    > //
    > char charSou[128] = {0};
    > char charDes[128] = {0};
    >
    > //strcpy(charSou,"E:\\WORK\\WavAppend\\pig.wav");
    > //strcpy(charDes,"E:\\WORK\\WavAppend\\dog.wav");
    > strcpy(charSou,SouflName);
    > strcpy(charDes,DesflName);
    > //
    >
    > if (!mmioOpen((char *)charSou,NULL,MMIO_EXIST))
    > return ERROR_FILE_NOT_EXIST;
    > l_hFile = mmioOpen((char*)charSou,NULL,MMIO_READ);
    >
    > if(l_hFile == NULL) 
    > {
    > //m_Mode = FILE_ERROR;
    > switch (info.wErrorRet )
    > { 
    > case MMIOERR_ACCESSDENIED ://The file is protected and cannot be opened. 
    > return ERROR_FILE_ACEESS_DENIED;
    > break;
    > case MMIOERR_PATHNOTFOUND:// The directory specification is incorrect. 
    > return ERROR_FILE_NOT_EXIST;
    > break;
    > case MMIOERR_SHARINGVIOLATION: //The file is being used by another application and is unavailable. 
    > return ERROR_FILE_SHARING_VIOLATION;
    > break;
    > case MMIOERR_NETWORKERROR:// The network is not responding to the request to open a remote file. 

    > case MMIOERR_INVALIDFILE://Another failure condition occurred. This is the default error for an open-file failure. 

    > case MMIOERR_TOOMANYOPENFILES:
    > default:

    > return ERROR_FILE_ACCESS_ERROR;
    > }
    > }
    > //
    > m_hFile = mmioOpen((char*)charDes,NULL,MMIO_WRITE);

    > //
    >
    > if(m_hFile == NULL) 
    > {
    > //m_Mode = FILE_ERROR;
    > switch (info.wErrorRet )
    > { 
    > case MMIOERR_ACCESSDENIED ://The file is protected and cannot be opened. 
    > return ERROR_FILE_ACEESS_DENIED;
    > break;
    > case MMIOERR_PATHNOTFOUND:// The directory specification is incorrect. 
    > return ERROR_FILE_NOT_EXIST;
    > break;
    > case MMIOERR_SHARINGVIOLATION: //The file is being used by another application and is unavailable. 
    > return ERROR_FILE_SHARING_VIOLATION;
    > break;
    > case MMIOERR_NETWORKERROR:// The network is not responding to the request to open a remote file. 

    > case MMIOERR_INVALIDFILE://Another failure condition occurred. This is the default error for an open-file failure. 

    > case MMIOERR_TOOMANYOPENFILES:
    > default:

    > return ERROR_FILE_ACCESS_ERROR;
    > }
    > }
    >
    > l_MMCKInfoParent.fccType = mmioFOURCC('W','A','V','E');
    > MMRESULT mmResult = ::mmioDescend(l_hFile, &l_MMCKInfoParent,NULL,MMIO_FINDRIFF);
    > //mmResult = mmioAscend(l_hFile,&l_MMCKInfoParent,0);
    > //mmResult=mmioSeek(l_hFile,0,SEEK_SET);
    > if(mmResult)
    > {
    > AfxMessageBox("Error descending into file");
    > mmioClose(m_hFile,0);
    > m_hFile = NULL;
    > mmioClose(l_hFile,0);
    > l_hFile = NULL;
    > //m_Mode = FILE_ERROR;
    > return ERROR_FILE_ACCESS_ERROR;
    > }
    > l_MMCKInfoChild.ckid = mmioFOURCC('f','m','t',' ');
    > mmResult = mmioDescend(l_hFile,&l_MMCKInfoChild,&l_MMCKInfoParent,MMIO_FINDCHUNK);
    > if(mmResult)
    > {
    > AfxMessageBox("Error descending in wave file");
    > mmioClose(m_hFile,0);
    > m_hFile = NULL;
    > mmioClose(l_hFile,0);
    > //m_Mode = FILE_ERROR;
    > l_hFile = NULL;
    > return ERROR_FILE_ACCESS_ERROR;
    > }
    > WAVEFORMATEX l_Format;
    >
    >// WAVEFORMATEX *pOrigFormat=this->GetFormat();
    >
    > DWORD bytesRead = mmioRead(l_hFile,(LPSTR)&l_Format,sizeof(WAVEFORMATEX));//+m_MMCKInfoChild.cksize);

    > /*
    > if ((pOrigFormat->nChannels!=l_Format.nChannels)
    > ||(pOrigFormat->nSamplesPerSec!=l_Format.nSamplesPerSec)
    > ||(pOrigFormat->wBitsPerSample!=l_Format.wBitsPerSample))
    > return ERROR_INVALID_WAVE_FORMAT;
    > */
    >
    > if(bytesRead < 0)
    > {
    > AfxMessageBox("Error reading PCM wave format record");
    > mmioClose(m_hFile,0);
    > m_hFile = NULL;
    > mmioClose(l_hFile,0);
    > l_hFile = NULL;
    > return ERROR_FILE_ACCESS_ERROR;
    > }
    >
    > // open output sound file
    > mmResult = mmioAscend(l_hFile,&l_MMCKInfoChild,0);
    > if(mmResult)
    > {
    > AfxMessageBox("Error ascending in File");
    > mmioClose(m_hFile,0);
    > m_hFile = NULL;
    > mmioClose(l_hFile,0);
    > l_hFile = NULL;
    >
    > return ERROR_FILE_ACCESS_ERROR;
    > }
    > l_MMCKInfoChild.ckid = mmioFOURCC('d','a','t','a');
    > mmResult = mmioDescend(l_hFile,&l_MMCKInfoChild,
    > &l_MMCKInfoParent,MMIO_FINDCHUNK);
    > if(mmResult)
    > {
    > AfxMessageBox("error reading data chunk");
    > mmioClose(m_hFile,0);
    > m_hFile = NULL;
    > mmioClose(l_hFile,0);
    > l_hFile = NULL;
    >
    > return ERROR_FILE_ACCESS_ERROR;
    > }
    >
    > BYTE * lpData=(BYTE*)malloc(l_MMCKInfoChild.cksize);
    > if(mmioRead(l_hFile,(HPSTR)lpData,l_MMCKInfoChild.cksize)!=l_MMCKInfoChild.cksize)
    > return ERROR_FILE_ACCESS_ERROR;
    >
    > //秦ADD
    > LONG m_LSeek;
    > m_LSeek = mmioSeek(m_hFile,0,SEEK_END);// Seek End of file
    > if (m_LSeek ==-1)
    > {
    > return ERROR_FILE_ACCESS_ERROR;
    > }
    >
    > //mmRESULT = mmioGetInfo(m_hFile,,)
    >
    > //秦ADD
    > long nBytes;
    > nBytes=mmioWrite(m_hFile,(LPCTSTR)lpData,l_MMCKInfoChild.cksize);
    > if (nBytes!=l_MMCKInfoChild.cksize)
    > { free(lpData);
    > mmioClose(m_hFile,0);
    > m_hFile = NULL;
    > mmioClose(l_hFile,0);
    > return ERROR_FILE_ACCESS_ERROR;
    > }
    > free(lpData);
    > mmioClose(m_hFile,0);
    > m_hFile = NULL;
    > mmioClose(l_hFile,0);
    > l_hFile = NULL;
    > //m_FilePos=m_FilePos+nBytes;
    > //if (m_FilePos>m_FileLen) m_FileLen=m_FilePos;

    > return OK_SUCCESS;
    >
    >
    >}
    >
    >
    >
    >
    >
    >