Commit 7f4d81ed authored by Jörg Höhle's avatar Jörg Höhle Committed by Alexandre Julliard

mciwave: Fix wave format first, then compute position.

nAvgBytesPerSec is the better factor in the presence of ADPCM, MPEG3 and other wave formats.
parent b188cb13
...@@ -216,8 +216,8 @@ static DWORD WAVE_ConvertByteToTimeFormat(WINE_MCIWAVE* wmw, DWORD val, LPDWORD ...@@ -216,8 +216,8 @@ static DWORD WAVE_ConvertByteToTimeFormat(WINE_MCIWAVE* wmw, DWORD val, LPDWORD
case MCI_FORMAT_BYTES: case MCI_FORMAT_BYTES:
ret = val; ret = val;
break; break;
case MCI_FORMAT_SAMPLES: /* FIXME: is this correct ? */ case MCI_FORMAT_SAMPLES:
ret = (val * 8) / (wmw->lpWaveFormat->wBitsPerSample ? wmw->lpWaveFormat->wBitsPerSample : 1); ret = MulDiv(val,wmw->lpWaveFormat->nSamplesPerSec,wmw->lpWaveFormat->nAvgBytesPerSec);
break; break;
default: default:
WARN("Bad time format %u!\n", wmw->dwMciTimeFormat); WARN("Bad time format %u!\n", wmw->dwMciTimeFormat);
...@@ -236,13 +236,13 @@ static DWORD WAVE_ConvertTimeFormatToByte(WINE_MCIWAVE* wmw, DWORD val) ...@@ -236,13 +236,13 @@ static DWORD WAVE_ConvertTimeFormatToByte(WINE_MCIWAVE* wmw, DWORD val)
switch (wmw->dwMciTimeFormat) { switch (wmw->dwMciTimeFormat) {
case MCI_FORMAT_MILLISECONDS: case MCI_FORMAT_MILLISECONDS:
ret = (val * wmw->lpWaveFormat->nAvgBytesPerSec) / 1000; ret = MulDiv(val,wmw->lpWaveFormat->nAvgBytesPerSec,1000);
break; break;
case MCI_FORMAT_BYTES: case MCI_FORMAT_BYTES:
ret = val; ret = val;
break; break;
case MCI_FORMAT_SAMPLES: /* FIXME: is this correct ? */ case MCI_FORMAT_SAMPLES:
ret = (val * wmw->lpWaveFormat->wBitsPerSample) / 8; ret = MulDiv(val,wmw->lpWaveFormat->nAvgBytesPerSec,wmw->lpWaveFormat->nSamplesPerSec);
break; break;
default: default:
WARN("Bad time format %u!\n", wmw->dwMciTimeFormat); WARN("Bad time format %u!\n", wmw->dwMciTimeFormat);
...@@ -514,20 +514,26 @@ static LRESULT WAVE_mciOpen(MCIDEVICEID wDevID, DWORD dwFlags, LPMCI_WAVE_OPEN_P ...@@ -514,20 +514,26 @@ static LRESULT WAVE_mciOpen(MCIDEVICEID wDevID, DWORD dwFlags, LPMCI_WAVE_OPEN_P
dwRet = WAVE_mciDefaultFmt(wmw); dwRet = WAVE_mciDefaultFmt(wmw);
if (dwRet == 0) { if (dwRet == 0) {
if (wmw->lpWaveFormat) { if (wmw->lpWaveFormat->wFormatTag == WAVE_FORMAT_PCM) {
switch (wmw->lpWaveFormat->wFormatTag) { if (wmw->lpWaveFormat->nBlockAlign !=
case WAVE_FORMAT_PCM: wmw->lpWaveFormat->nChannels * wmw->lpWaveFormat->wBitsPerSample/8) {
if (wmw->lpWaveFormat->nAvgBytesPerSec != WARN("Incorrect nBlockAlign (%d), setting it to %d\n",
wmw->lpWaveFormat->nSamplesPerSec * wmw->lpWaveFormat->nBlockAlign) { wmw->lpWaveFormat->nBlockAlign,
WARN("Incorrect nAvgBytesPerSec (%d), setting it to %d\n", wmw->lpWaveFormat->nChannels *
wmw->lpWaveFormat->nAvgBytesPerSec, wmw->lpWaveFormat->wBitsPerSample/8);
wmw->lpWaveFormat->nSamplesPerSec * wmw->lpWaveFormat->nBlockAlign =
wmw->lpWaveFormat->nBlockAlign); wmw->lpWaveFormat->nChannels *
wmw->lpWaveFormat->nAvgBytesPerSec = wmw->lpWaveFormat->wBitsPerSample/8;
wmw->lpWaveFormat->nSamplesPerSec * }
wmw->lpWaveFormat->nBlockAlign; if (wmw->lpWaveFormat->nAvgBytesPerSec !=
} wmw->lpWaveFormat->nSamplesPerSec * wmw->lpWaveFormat->nBlockAlign) {
break; WARN("Incorrect nAvgBytesPerSec (%d), setting it to %d\n",
wmw->lpWaveFormat->nAvgBytesPerSec,
wmw->lpWaveFormat->nSamplesPerSec *
wmw->lpWaveFormat->nBlockAlign);
wmw->lpWaveFormat->nAvgBytesPerSec =
wmw->lpWaveFormat->nSamplesPerSec *
wmw->lpWaveFormat->nBlockAlign;
} }
} }
wmw->dwPosition = 0; wmw->dwPosition = 0;
...@@ -716,7 +722,7 @@ static DWORD WAVE_mciPlay(MCIDEVICEID wDevID, DWORD_PTR dwFlags, DWORD_PTR pmt, ...@@ -716,7 +722,7 @@ static DWORD WAVE_mciPlay(MCIDEVICEID wDevID, DWORD_PTR dwFlags, DWORD_PTR pmt,
LPMCI_PLAY_PARMS lpParms = (void*)pmt; LPMCI_PLAY_PARMS lpParms = (void*)pmt;
DWORD end; DWORD end;
LONG bufsize, count, left; LONG bufsize, count, left;
DWORD dwRet = 0; DWORD dwRet;
LPWAVEHDR waveHdr = NULL; LPWAVEHDR waveHdr = NULL;
WINE_MCIWAVE* wmw = WAVE_mciGetOpenDev(wDevID); WINE_MCIWAVE* wmw = WAVE_mciGetOpenDev(wDevID);
int whidx; int whidx;
...@@ -753,6 +759,30 @@ static DWORD WAVE_mciPlay(MCIDEVICEID wDevID, DWORD_PTR dwFlags, DWORD_PTR pmt, ...@@ -753,6 +759,30 @@ static DWORD WAVE_mciPlay(MCIDEVICEID wDevID, DWORD_PTR dwFlags, DWORD_PTR pmt,
(DWORD_PTR)lpParms, sizeof(MCI_PLAY_PARMS)); (DWORD_PTR)lpParms, sizeof(MCI_PLAY_PARMS));
} }
if (!wmw->lpWaveFormat) return MCIERR_WAVE_INPUTUNSPECIFIED;
if (wmw->lpWaveFormat->wFormatTag == WAVE_FORMAT_PCM) {
if (wmw->lpWaveFormat->nBlockAlign !=
wmw->lpWaveFormat->nChannels * wmw->lpWaveFormat->wBitsPerSample/8) {
WARN("Incorrect nBlockAlign (%d), setting it to %d\n",
wmw->lpWaveFormat->nBlockAlign,
wmw->lpWaveFormat->nChannels *
wmw->lpWaveFormat->wBitsPerSample/8);
wmw->lpWaveFormat->nBlockAlign =
wmw->lpWaveFormat->nChannels *
wmw->lpWaveFormat->wBitsPerSample/8;
}
if (wmw->lpWaveFormat->nAvgBytesPerSec !=
wmw->lpWaveFormat->nSamplesPerSec * wmw->lpWaveFormat->nBlockAlign) {
WARN("Incorrect nAvgBytesPerSec (%d), setting it to %d\n",
wmw->lpWaveFormat->nAvgBytesPerSec,
wmw->lpWaveFormat->nSamplesPerSec *
wmw->lpWaveFormat->nBlockAlign);
wmw->lpWaveFormat->nAvgBytesPerSec =
wmw->lpWaveFormat->nSamplesPerSec *
wmw->lpWaveFormat->nBlockAlign;
}
}
end = 0xFFFFFFFF; end = 0xFFFFFFFF;
if (lpParms && (dwFlags & MCI_FROM)) { if (lpParms && (dwFlags & MCI_FROM)) {
wmw->dwPosition = WAVE_ConvertTimeFormatToByte(wmw, lpParms->dwFrom); wmw->dwPosition = WAVE_ConvertTimeFormatToByte(wmw, lpParms->dwFrom);
...@@ -773,28 +803,6 @@ static DWORD WAVE_mciPlay(MCIDEVICEID wDevID, DWORD_PTR dwFlags, DWORD_PTR pmt, ...@@ -773,28 +803,6 @@ static DWORD WAVE_mciPlay(MCIDEVICEID wDevID, DWORD_PTR dwFlags, DWORD_PTR pmt,
wmw->dwPosition = WAVE_ALIGN_ON_BLOCK(wmw, wmw->dwPosition); wmw->dwPosition = WAVE_ALIGN_ON_BLOCK(wmw, wmw->dwPosition);
wmw->ckWaveData.cksize = WAVE_ALIGN_ON_BLOCK(wmw, wmw->ckWaveData.cksize); wmw->ckWaveData.cksize = WAVE_ALIGN_ON_BLOCK(wmw, wmw->ckWaveData.cksize);
if (dwRet == 0) {
if (wmw->lpWaveFormat) {
switch (wmw->lpWaveFormat->wFormatTag) {
case WAVE_FORMAT_PCM:
if (wmw->lpWaveFormat->nAvgBytesPerSec !=
wmw->lpWaveFormat->nSamplesPerSec * wmw->lpWaveFormat->nBlockAlign) {
WARN("Incorrect nAvgBytesPerSec (%d), setting it to %d\n",
wmw->lpWaveFormat->nAvgBytesPerSec,
wmw->lpWaveFormat->nSamplesPerSec *
wmw->lpWaveFormat->nBlockAlign);
wmw->lpWaveFormat->nAvgBytesPerSec =
wmw->lpWaveFormat->nSamplesPerSec *
wmw->lpWaveFormat->nBlockAlign;
}
break;
}
}
} else {
TRACE("can't retrieve wave format %d\n", dwRet);
goto cleanUp;
}
/* go back to beginning of chunk plus the requested position */ /* go back to beginning of chunk plus the requested position */
/* FIXME: I'm not sure this is correct, notably because some data linked to /* FIXME: I'm not sure this is correct, notably because some data linked to
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment