Remove the -t option. It is not the problem either

if ((wave.GetFormat().nChannels!=1) || (wave.GetFormat().nSamplesPerSec!=16000)
|| (wave.GetFormat().wBitsPerSample!=16) ||(wave.GetFormat().wFormatTag!=1)
|| (wave.m_buffer.GetNumSamples()!=6*16000))
{
MessageBox("Unsupported File Format!");
return;
}

In the above code, I can understand what is the blue part. But i dont get what is the one in Red. I think that is where the problem occurs. Can you explain what is it respective to the wav file format?

Hi, WolfPack, thanks for your reply, appreciate.

About the red line, the software use sampling rate of 16kHz, there are 6 seconds in each sentence. The "Playwave" functions by playing one sentence at each time. Therefore, the number of samples is 16000*6.

OKay remove

|| (wave.m_buffer.GetNumSamples()!=6*16000)

This part from the above code, and try running the program. Tell me if the error stilll comes.

Hi, WolfPack, thanks for your reply.

After I removed that part as suggested, I managed to play the wave without any problem. Thank you, you are so great!

May I ask? Is it possible to directly convert the wave to mp3 when the children click the button "save"? I worried that the small children dont know how to do this and that. We hope to make it as simple as possible. so that they are motivated to use this software.


May I ask? Is it possible to directly convert the wave to mp3 when the children click the button "save"? I worried that the small children dont know how to do this and that. We hope to make it as simple as possible. so that they are motivated to use this software.

Yes it is possible. You will have to add additional code for the save button. Without seeing the code for the save button I can't give anymore advice.

Hi, WolfPack, thanks for your reply.

I think I need to elaborate abit. After a child completes one practice (one practice consists of 15 wave files), he/she will click button "save wave". The software will prompt him to save one by one wave file continuously until the software prompts to save all 15 wave files. (The save location can be chosen by the children, we thought to save it directly to floppy disk to make it simple for children)

Here is the codes for "save button".

void CSpeechDlg::OnSaveWave()
{
// TODO: Add your control notification handler code here


savebuffer.save();
}

Sorry, I dont know do you mean this code. I can send other codes for you if I sent it wrongly.

Send me the code for

savebuffer.save();

Hi, WolfPack, I attached the savebuffer.cpp.

Okay. I had a look at the sourcecode. Now after this part,

try
     {
              wave.Save(savefile.GetPathName());	
              break;
     }

you will get the wave file called filename . So there are two potions for you
1. Call the system( "lame.exe filename "A:\filename.mp3" " ); after the wave.Save(savefile.GetPathName()); and you will get the mp3 file. However you fill see the black command prompt window popping up at that time.
2. Call the functions inthe DLL file to convert the wave file to MP3. You will not see the command prompt here.

In any case, since you will not be using the wav file, save it in a temporary folder in the hard disk. Otherwise you will find there is no room in the floppy disk. You can delete it later. Save the mp3 file in the floppy drive.

Hi, WolfPack, thanks for your reply.

I have tried as suggested in Option 1 but I get three compile errors for the added line. Still searching if I can find out how to fix...

error C2146: syntax error : missing ')' before identifier 'A'
error C2017: illegal escape sequence
error C2059: syntax error : ')'

For the second option, I haven't try yet as I dont know how to call the function in the DLL file.

Change it to

system( "lame.exe filename \"A:\filename.mp3\"" );

. my mistake. sorry.

Hi, WolfPack, thank you very much for your reply. No need to say sorry. I appreciate all your helps.

After I changed as above, I can execute the software and the black command prompt window was popped up. But, after this, I checked at the directory, I only see the filename.wav but didnt see any mp3 file. Correct me if I did any mistake.

Where did you look in? The Floppy Disk?

Hi, WolfPack, thanks for your reply.

Forgive me for being not clever enough :(

I didnt have the floppy disk with me now, I left it at home, so I changed the code of directory from A to C, just for testing at this moment.

I could find the filename.wav at the C drive but didnt see any mp3 file.

Forgive me for being not clever enough :(

No I am not the one who is not clever enough. Sorry I am having a busy day at work today. Here is a version that should work.

char command[ 100 ] = "";
    sprintf (command, "%s \"%s\" \"C:\\%s.mp3\"", "lame.exe" , filename, filename );
    //std::cout << command << std::endl;
    system( command );

Hi, WolfPack, thank you for your post.

I changed as above and the same thing happened. I could only see the wave file and not any mp3 file.

I wonder did I need to run the cmd that you sent me in order to do the conversion?

Yes replace

system( "lame.exe filename \"A:\filename.mp3\"" );

with the code I gave you.

Hi, WolfPack.

I have replaced the code

system( "lame.exe filename \"A:\filename.mp3\"" );

with this code

char command[ 100 ] = "";
sprintf (command, "%s \"%s\" \"C:\\%s.mp3\"", "lame.exe" , filename, filename );
//std::cout << command << std::endl;
system( command );

The same thing happened, I could see the wave files at C drive but there is no mp3 file.

I dont know do I need to run the cmd too?


The same thing happened, I could see the wave files at C drive but there is no mp3 file.

Was there a wave file in the C: drive before? Delete it again and try again.

I dont know do I need to run the cmd too?

What do you mean by run the cmd? what cmd?

Hi, WolfPack, thanks for your reply.

I have deleted and tried again. I still cant get any mp3 file.

I mean I just execute my C++ software, record, and save wave. I didnt run the Convert_Wav_To_MP3.cmd that you sent me yesterday.

1. Was there a wave file in the C: drive before?
2. Delete it again and try again. Do you still get the wave file?
3. Have you enabled the "Show extension for known file types" in "Folder Options" ?

Hi, WolfPack. Thanks for your reply.

1. Yes, there was wave files before in the C directory. After I read your previous post, I deleted all the wave files and execute my software, record and save again in the C drive.

2. After I deleted and tried again, I still can get the new wave file without any mp3 file.

3. I have checked the folder option in control panel, it is already in show extension for known file types.

Hi, WolfPack.

Before that, I put the lame.exe in the folder same with my C++ software folder.

Just now, I tried to put the lame.exe in C drive, same location with the location I want to save the wave file.

It converted the wave file to MP3 file successfully. Sorry, it is my mistake that waste your time to figure the problem. I am sorry.

Hi, WolfPack, thank you very much for your help.

May I ask? Is it possible to implement codes so that the MP3 file can be converted to Wave file when button "Play wave' is clicked?

Should I use the same code as compression?

Hi, WolfPack. I tried to put the codes lines on the button OnPlayWave.

But, I dont think I can do it because the software prompts to select the wave to be played, not the mp3 to be played. So, I dont think I can use the same approach as compression part to do the decompression part.

Maybe the only solution is use your Convert_MP3_To_Wav.cmd to convert the MP3 file to wave file before we can use the software to play the wave.

Before that, I put the lame.exe in the folder same with my C++ software folder.

Just now, I tried to put the lame.exe in C drive, same location with the location I want to save the wave file.

This is a bit troublesome isn't it? You have to copy the lame.exe file to C:\ drive if you want to use the software. And if the wave file is in another directory it will not work. A better approach will be to use GetModuleFileName to get the current module and extract the Pathname to get the installation directory. Then you can put the lame.exe in the same folder as your software and everything will work without any trouble.

char FilePath[ MAX_PATH ] = "";
    DWORD dwLength = GetModuleFileName(NULL, FilePath, MAX_PATH);
    if (dwLength)
    {
        while (dwLength && FilePath[dwLength] != '\\')
            dwLength--;

        if (dwLength)
            FilePath[dwLength + 1] = '\0';
    }

    char command[MAX_PATH] = "";
    sprintf (command, "%s\\lame.exe \"%s\" \"C:\\%s.mp3\"", FilePath, filename, filename);
    system( command );

After adding the above code, try putting the lame.exe file in the software exe file folder and see.

May I ask? Is it possible to implement codes so that the MP3 file can be converted to Wave file when button "Play wave' is clicked?

Should I use the same code as compression?
I tried to put the codes lines on the button OnPlayWave.
But, I dont think I can do it because the software prompts to select the wave to be played, not the mp3 to be played. So, I dont think I can use the same approach as compression part to do the decompression part.
Maybe the only solution is use your Convert_MP3_To_Wav.cmd to convert the MP3 file to wave file before we can use the software to play the wave.

Well after some changes you could do it. But I think that it will be easier to collect the MP3 files to a single folder and converting them all at once. Otherwise you will have to convert them 20 times per child.

HI, WolfPack, thank you very much for your reply, appreciate.

A better approach will be to use GetModuleFileName to get the current module and extract the Pathname to get the installation directory. Then you can put the lame.exe in the same folder as your software and everything will work without any trouble.

Thanks for the good idea, I will do it and tell you how I am going, thanks alot!

Well after some changes you could do it. But I think that it will be easier to collect the MP3 files to a single folder and converting them all at once. Otherwise you will have to convert them 20 times per child.

Can I elaborate a little bit? Originally, the "Play wave" button was designed to function like this: When the child bring the floppy disk back to centre, the therapist will click button "play wave". This button will prompt twice for each click. First prompt is to open wave recorded by therapist's own voice and the second prompt is to open wave recorded by children at home. Therefore, I would like to know is it possible that the software can decompress the MP3 file before play wave when we click "Play wave' button ? Is it a big problem?

Post the code for the PlayWave button.

Hi, WolfPack, thanks for your post. I put the PlayWave codes below.

void CSpeechDlg::OnPlayWave()
{
// TODO: Add your control notification handler code here
//load the file
CFileDialog openfile(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,"Wave File (*.wav)|*.wav|");
if (openfile.DoModal()==IDOK) //prerecorded
{
CWave wave;
wave.Load(openfile.GetFileName());
if ((wave.GetFormat().nChannels!=1) || (wave.GetFormat().nSamplesPerSec!=16000)
|| (wave.GetFormat().wBitsPerSample!=16) ||(wave.GetFormat().wFormatTag!=1)
|| (wave.m_buffer.GetNumSamples()!=6*16000))
{
MessageBox("Unsupported File Format!");
return;
}
memcpy(wavedata1,wave.GetBuffer(),6*16000*2);
}
else
{
return;
}
if (openfile.DoModal()==IDOK)
{
CWave wave;
wave.Load(openfile.GetFileName());
if ((wave.GetFormat().nChannels!=1) || (wave.GetFormat().nSamplesPerSec!=16000)
|| (wave.GetFormat().wBitsPerSample!=16) ||(wave.GetFormat().wFormatTag!=1)
|| (wave.m_buffer.GetNumSamples()!=6*16000))
{
MessageBox("Unsupported File Format!");
return;
}
memcpy(wavedata2,wave.GetBuffer(),6*16000*2);
//open waveform audio for output
waveform.wFormatTag     =   WAVE_FORMAT_PCM;
waveform.nChannels      =   1;
waveform.nSamplesPerSec =16000;
waveform.nAvgBytesPerSec=16000*2;
waveform.nBlockAlign    =2;
waveform.wBitsPerSample =16;
waveform.cbSize         =0;
playtype=2;
if (waveOutOpen(&hWaveOut,WAVE_MAPPER,&waveform,(DWORD)this->m_hWnd,NULL,CALLBACK_WINDOW)) {
MessageBox("Wave Out Error\n");
}
}
//play both of them at one time
}

Try this code. Note however that I didn't test the code. THere maybe some error.

//load the file
CFileDialog openfile(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,"MP3 File (*.mp3)|*.mp3|");

if (openfile.DoModal()==IDOK) //prerecorded
{
	CWave wave;
	char* mp3FileName  = openfile.GetFileName(); 
	char* waveFileName = openfile.GetFileName();
	char* PeriodPos    = waveFileName + strlen(waveFileName);
    if (PeriodPos)
    {
        while (PeriodPos && (*PeriodPos) != '.')
            PeriodPos--;

        if (PeriodPos++)
            PeriodPos = "wav";
    }
	
    char FilePath[ MAX_PATH ] = "";
    DWORD dwLength = GetModuleFileName(NULL, FilePath, MAX_PATH);
    if (dwLength)
    {
        while (dwLength && FilePath[dwLength] != '\\')
            dwLength--;

        if (dwLength)
            FilePath[dwLength + 1] = '\0';
    }

    char command[MAX_PATH] = "";
    sprintf (command, "%s\\lame.exe --decode \"%s\" \"%s\"", FilePath, mp3FileName, waveFileName);
    
    system( command );
	wave.Load(waveFileName);
... // The rest is your code - WolfPack
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.