📄 answer.c
字号:
mmioGetInfo(hmmioOut, &mmioinfoOut, 0);
setMessageCount();
answerReplay();
answerPlayPos = msgTable[currentMessage];
sfp = answerPlayPos;
replaying = TRUE;
firstPacket = TRUE;
while ((answerRead(&IPaddr, &t, hostName, &ebuf))
&& (firstPacket || !(ebuf.compression & fAnsNewMsg))) {
firstPacket = FALSE;
// Transform packet into device-compatible PCM encoding
decodeAnswerPacket(&ebuf, aboutOutBits, aboutOutSamples, &pcmdata, &dwPCMBytes);
// Write packet to file
for (write_pos = 0; write_pos < dwPCMBytes; write_pos++) {
// Check if we are at the end of the output buffer.
// If so, flush it.
if (mmioinfoOut.pchNext == mmioinfoOut.pchEndWrite) {
mmioinfoOut.dwFlags |= MMIO_DIRTY;
if (mmioAdvance(hmmioOut, &mmioinfoOut, MMIO_WRITE) != MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
}
// Copy one byte
*mmioinfoOut.pchNext++ = pcmdata[write_pos];
}
// Free up the PCM buffer.
GlobalFreePtr(pcmdata);
}
answerPlayPos = sfp;
replaying = FALSE;
answerReplayDone();
// Mark the current chunk as dirty and flush it
mmioinfoOut.dwFlags |= MMIO_DIRTY;
if (mmioSetInfo(hmmioOut, &mmioinfoOut, 0) != MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
// Ascend out of data chunk
if (mmioAscend(hmmioOut, &ckOut, 0) != MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
// Ascend out of RIFF chunk
if (mmioAscend(hmmioOut, &ckOutRIFF, 0) != MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
// Close the file
if (mmioClose(hmmioOut, 0) != MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
SetCursor(LoadCursor(NULL, IDC_ARROW));
}
break;
}
case IDC_RP_SAVE_ALL:
{
OPENFILENAME ofn;
char szWaveMessage[MAX_PATH];
struct in_addr IPaddr;
char hostName[userIdMax];
time_t t;
long sfp;
int ateof = FALSE;
DWORD write_pos;
char szError[200];
HMMIO hmmioOut;
MMIOINFO mmioinfoOut;
MMCKINFO ckOutRIFF;
MMCKINFO ckOut;
LPSTR pcmdata;
DWORD dwPCMBytes;
WAVEFORMATEX pwf;
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = rfilter(IDS_T_WAVE_FILE_FILTER);
ofn.lpstrCustomFilter = NULL;
szWaveMessage[0] = '\0';
ofn.lpstrFile = (LPSTR) szWaveMessage;
ofn.nMaxFile = sizeof(szWaveMessage);
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = rstring(IDS_T_ANSWER_SAVE_TITLE);
ofn.Flags = OFN_SHOWHELP;
fileHelpKey = rstring(IDS_HELP_ANSWER);
if (GetOpenFileName((LPOPENFILENAME) &ofn)) {
if (!strchr(szWaveMessage, '.')) {
strcat(szWaveMessage, ".wav");
}
SetCursor(LoadCursor(NULL, IDC_WAIT));
hmmioOut = mmioOpen(szWaveMessage, NULL,
MMIO_ALLOCBUF | MMIO_WRITE | MMIO_CREATE);
if (!hmmioOut) {
sprintf(szError,rstring(IDS_T_OPEN_WAVE_FILE_ERR), szWaveMessage);
MessageBox(NULL, szError, NULL, MB_OK | MB_ICONEXCLAMATION);
break;
}
// Create the output file RIFF chunk of form type WAVE.
ckOutRIFF.fccType = mmioFOURCC('W', 'A', 'V', 'E');
ckOutRIFF.cksize = 0;
if (mmioCreateChunk(hmmioOut, &ckOutRIFF, MMIO_CREATERIFF)
!= MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
// Initialize the WAVEFORMATEX structure
pwf.nChannels = audioChannels;
pwf.nSamplesPerSec = samplesPerSecond;
pwf.nAvgBytesPerSec = bytesPerSecond;
pwf.nBlockAlign = sampleAlignment;
pwf.wBitsPerSample = bitsPerSample;
pwf.wFormatTag = WAVE_FORMAT_PCM;
pwf.cbSize = 0;
// Create the fmt chunk
ckOut.ckid = mmioFOURCC('f', 'm', 't', ' ');
ckOut.cksize = sizeof(pwf);
if (mmioCreateChunk(hmmioOut, &ckOut, 0) != MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
// Write the WAVEFORMATEX structure to the fmt chunk.
if (mmioWrite(hmmioOut, (HPSTR) &pwf, sizeof(pwf)) != sizeof(pwf)) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
// Ascend out of the fmt chunk, back into the RIFF chunk.
if (mmioAscend(hmmioOut, &ckOut, 0) != MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
// Create the data chunk that holds the waveform samples.
ckOut.ckid = mmioFOURCC('d', 'a', 't', 'a');
ckOut.cksize = 0;
if (mmioCreateChunk(hmmioOut, &ckOut, 0) != MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
mmioGetInfo(hmmioOut, &mmioinfoOut, 0);
setMessageCount();
answerReplay();
answerPlayPos = msgTable[0];
sfp = msgTable[currentMessage];
replaying = TRUE;
firstPacket = TRUE;
while ((answerRead(&IPaddr, &t, hostName, &ebuf))) {
firstPacket = FALSE;
// Transform packet into device-compatible PCM format
decodeAnswerPacket(&ebuf, aboutOutBits, aboutOutSamples, &pcmdata, &dwPCMBytes);
// Write packet to file
for (write_pos = 0; write_pos < dwPCMBytes; write_pos++) {
// Check if we are at the end of the output buffer.
// If so, flush it.
if (mmioinfoOut.pchNext == mmioinfoOut.pchEndWrite) {
mmioinfoOut.dwFlags |= MMIO_DIRTY;
if (mmioAdvance(hmmioOut, &mmioinfoOut, MMIO_WRITE)
!= MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
}
// Copy one byte
*mmioinfoOut.pchNext++ = pcmdata[write_pos];
}
// Free up the PCM buffer.
GlobalFreePtr(pcmdata);
}
answerPlayPos = sfp;
replaying = FALSE;
answerReplayDone();
// Mark the current chunk as dirty and flush it
mmioinfoOut.dwFlags |= MMIO_DIRTY;
if (mmioSetInfo(hmmioOut, &mmioinfoOut, 0) != MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
// Ascend out of data chunk
if (mmioAscend(hmmioOut, &ckOut, 0) != MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
// Ascend out of RIFF chunk
if (mmioAscend(hmmioOut, &ckOutRIFF, 0) != MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
// Close the file
if (mmioClose(hmmioOut, 0) != MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
SetCursor(LoadCursor(NULL, IDC_ARROW));
}
break;
}
case IDOK:
answerRecord = IsDlgButtonChecked(hwnd, IDC_RP_RECORD);
PostMessage(hwnd, WM_CLOSE, 0, 0L);
break;
case ID_HELP:
displayHelpTopic(IDS_HELP_ANSWER);
break;
}
return FALSE;
case WM_DESTROY:
if (replaying) {
KillTimer(hwnd, 5);
}
if (msgTable != NULL) {
GlobalFreePtr(msgTable);
msgTable = NULL;
}
hDlgAnswer = NULL;
return 0;
case WM_TIMER:
{
struct in_addr IPaddr;
char hostName[userIdMax];
time_t t;
DWORD startTicks = GetTickCount();
long et, sfp;
int ateof = FALSE;
if (replaying) {
sfp = answerPlayPos;
if (answerRead(&IPaddr, &t, hostName, &ebuf)) {
if (firstPacket || !(ebuf.compression & fAnsNewMsg)) {
firstPacket = FALSE;
playSound(hwndMDIFrame, NULL, &ebuf, aboutOutBits, aboutOutSamples);
if (!hostShown) {
// Update host when definitive name seen
if (hostName[0] != '(') {
hostShown = TRUE;
hostPrelim = FALSE;
}
if (!hostPrelim) {
answerUpdateMessageInfo(hwnd, &t, &IPaddr, hostName);
hostPrelim = TRUE;
}
}
/* The following code is needed because when we're reading
sound from a file, as opposed to receiving it in real
time from the CODEC, we must meter out the samples
at the rate they will actually be played by the destination
machine. For 8000 samples per second, this amounts
to 125 microseconds per sample. */
#define kOverhead 30000L
et = ((ebuf.buffer.buffer_len * 125L) - kOverhead) -
((GetTickCount() - startTicks) * 1000);
if (et <= 0) {
et = 1;
}
SetTimer(hwnd, 5, (UINT) (et / 1000), NULL);
} else {
answerPlayPos = sfp;
replaying = FALSE;
}
} else {
replaying = FALSE;
ateof = TRUE;
}
}
if (!replaying) {
answerReplayDone();
KillTimer(hwnd, 5);
EnableWindow(GetDlgItem(hwnd, IDC_RP_PREV), currentMessage > 0);
EnableWindow(GetDlgItem(hwnd, IDC_RP_NEXT), !ateof);
EnableWindow(GetDlgItem(hwnd, IDC_RP_REPLAY), currentMessage >= 0);
EnableWindow(GetDlgItem(hwnd, IDC_RP_REWIND), TRUE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_ERASE), TRUE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_BROWSE), TRUE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_SAVE), currentMessage >= 0);
/* Restore focus to the button we pushed, or the logical
successor if it isn't enabled any more. */
if (buttonPushed != 0 && !IsWindowEnabled(GetDlgItem(hwnd, buttonPushed))) {
answerResetFocus(hwnd);
} else {
SetFocus(GetDlgItem(hwnd, buttonPushed));
}
}
}
break;
default:
if (nMessage == fileOpenHelpButton && fileHelpKey != NULL) {
displayHelpTopicString(fileHelpKey);
}
break;
}
return FALSE;
}
// ANSWERDIALOGUE -- Answering machine dialogue
VOID answerDialogue(HWND hwndParent)
{
CreateDialog(hInst, MAKEINTRESOURCE(IDD_REPONDEUR), hwndParent, answerDlgProc);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -