I created a function for you that will call speexenc. It needs to be pasted in your source code above the save function.
Code:
/*
* Helper function that finds the last instance of a character in a string.
*/
LPTSTR FindLastOf(LPCTSTR haystack, TCHAR needle)
{
int i = lstrlen(haystack) - 1;
while (i > 0)
{
if (haystack[i] == needle)
return (LPTSTR) &haystack[i];
i--;
}
return (LPTSTR) &haystack[0];
}
/*
* Function to call speexenc.
* First argument is the location of the .wav file. eg. "C:\\Temp\\wave file.wav"
* Second argument is output directory. No trailing backslash should be used. eg. "A:"
*/
BOOL SpeexEncode(LPCTSTR szInputFile, LPCTSTR szOutputPath)
{
STARTUPINFO si = { sizeof(STARTUPINFO) };
PROCESS_INFORMATION pi = { 0 };
TCHAR szCommandLine[MAX_PATH * 4 + 100];
TCHAR szPath[MAX_PATH];
TCHAR szOutputFile[MAX_PATH];
TCHAR* p;
/* Get the path of the currently running executable
* which is where we expect speexenc to be located. */
GetModuleFileName(NULL, szPath, MAX_PATH);
p = FindLastOf(szPath, TEXT('\\')); p[0] = TEXT('\0');
/* Get the input file name (excluding path) so that we can
* use the same file name for the output as the input. */
p = FindLastOf(szInputFile, TEXT('\\'));
lstrcpy(szOutputFile, p + 1);
/* Change extension from .wav to .spx */
p = FindLastOf(szOutputFile, TEXT('.'));
lstrcpy(p, TEXT(".spx"));
/* Create command line. */
wsprintf(szCommandLine, TEXT("\"%s\\speexenc\" \"%s\" \"%s\\%s\""),
szPath, szInputFile, szOutputPath, szOutputFile);
/* Execute command line. */
CreateProcess(NULL, szCommandLine, NULL,
NULL, FALSE, 0, NULL, NULL, &si, &pi);
/* Uncomment this line, if you want to pause here while the command completes. */
// WaitForSingleObject(pi.hProcess, INFINITE);
/* Uncomment this line for debugging, it will show the exact command line used. */
// MessageBox(NULL, szCommandLine, NULL, 0);
/* Cleanup. */
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
return TRUE;
}
You then need to call this function from your save function. It takes two arguments:
- The first is the location of the input wave file. That is, the path where the program has saved the wave recording.
- The second is the output directory. This may be a constant such as "A:" or a location provided by the user.
It is a impossible to provide the exact details of the call without seeing the save function code. If you can't work it out and it is possible, you could post the save function code, or attach the entire project.