Problems saving audio files
I'm writing a sound recording application in borland. It is a form with 4 buttons. record, play stop and save. Unfortunately while the program records the sound correctly it does not save it in the required format. The program saves the file with a filename looking like this 整瑳䌀尺整瑳眮癡匀癡牅潲r instead of the filename.wav if the filename is given a .wav extension then it plays the sound correctly however this is not suitable for the application.
Any help on why this happens would be gratefully received.
Code:
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
m_hMCIWnd = NULL;
/* create window needed for sound recording */
m_hMCIWnd = MCIWndCreate(Handle, g_hInstance, WS_CHILD | WS_OVERLAPPED, NULL);
if(m_hMCIWnd == NULL) // check window was created correctly
{
MessageBox(Handle, "Error Creating Sound Record Window", NULL, MB_OK);
return;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnRecordClick(TObject *Sender)
{
// create new .WAV file
if(MCIWndNew(m_hMCIWnd, "waveaudio") != 0)
{
MessageBox(Handle, "Error Starting Record", NULL, MB_OK);
}
// begin recording
MCIWndSeek(m_hMCIWnd, MCIWND_START);
MCIWndRecord(m_hMCIWnd);
/* disable buttons */
btnRecord->Enabled = false;
btnPlay->Enabled = false;
btnStop->Enabled = true;
btnSave->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
MCIWndClose(m_hMCIWnd);
MCIWndDestroy(m_hMCIWnd); // close mci now finished with
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnStopClick(TObject *Sender)
{
// stop recording and save file
MCIWndStop(m_hMCIWnd);
/* enable buttons */
btnRecord->Enabled = true;
btnPlay->Enabled = true;
btnStop->Enabled = false;
btnSave->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnPlayClick(TObject *Sender)
{
MCIWndSeek(m_hMCIWnd, MCIWND_START); // seek back to the start to play the sound
MCIWndPlay(m_hMCIWnd);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnSaveClick(TObject *Sender)
{
/* save the file */
if(edtFileName->Text == "")
{
ShowMessage("Please enter the word to save"); // check somewhere to save to
}
else
{
MCIWndSave(m_hMCIWnd, "test");
if(MCIWndSave(m_hMCIWnd, "C:\\test.wav") != 0)
{
ShowMessage("Save Error");
}
}
}
//---------------------------------------------------------------------------