A simple question about recording
-
I follow the following steps to write a simple record program waveInOpen waveInPrepareHeader waveInAddBuffer waveInStart waveInGetPosition waveInReset waveInUnprepareHeader waveInClose The program runs with no errors. But I create a file to record the voice. HANDLE FileHandle = CreateFile( L"myTest.wav", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); The wav file was created. But I play rhe wav file by windows media player. It says there is an error. Is there any problem with my code? My part code is below.
HANDLE FileHandle = CreateFile( L"myTest.wav", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile(FileHandle, &dwNumber, 4, &NumToWrite, NULL); SetEndOfFile(FileHandle); CloseHandle( FileHandle ); FileHandle = INVALID_HANDLE_VALUE;
Can somebody help me? Thanks a lot. minihotto -
I follow the following steps to write a simple record program waveInOpen waveInPrepareHeader waveInAddBuffer waveInStart waveInGetPosition waveInReset waveInUnprepareHeader waveInClose The program runs with no errors. But I create a file to record the voice. HANDLE FileHandle = CreateFile( L"myTest.wav", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); The wav file was created. But I play rhe wav file by windows media player. It says there is an error. Is there any problem with my code? My part code is below.
HANDLE FileHandle = CreateFile( L"myTest.wav", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile(FileHandle, &dwNumber, 4, &NumToWrite, NULL); SetEndOfFile(FileHandle); CloseHandle( FileHandle ); FileHandle = INVALID_HANDLE_VALUE;
Can somebody help me? Thanks a lot. minihottominihotto wrote:
WriteFile(FileHandle, &dwNumber, 4, &NumToWrite, NULL);
You know that your file will only be 4 bytes ? I hardly believe this a valid file format for a wav file. Check the documentation of the WriteFile[^] function. Also, you will need to follow the format reaquired for a wav file (I don't know it but if you search on google, you could find it).
minihotto wrote:
SetEndOfFile(FileHandle);
What are you trying to do here ?
Cédric Moonen Software developer
Charting control [Updated - v1.1] -
I follow the following steps to write a simple record program waveInOpen waveInPrepareHeader waveInAddBuffer waveInStart waveInGetPosition waveInReset waveInUnprepareHeader waveInClose The program runs with no errors. But I create a file to record the voice. HANDLE FileHandle = CreateFile( L"myTest.wav", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); The wav file was created. But I play rhe wav file by windows media player. It says there is an error. Is there any problem with my code? My part code is below.
HANDLE FileHandle = CreateFile( L"myTest.wav", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile(FileHandle, &dwNumber, 4, &NumToWrite, NULL); SetEndOfFile(FileHandle); CloseHandle( FileHandle ); FileHandle = INVALID_HANDLE_VALUE;
Can somebody help me? Thanks a lot. minihottominihotto wrote:
HANDLE FileHandle = CreateFile( L"myTest.wav", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile(FileHandle, &dwNumber, 4, &NumToWrite, NULL); SetEndOfFile(FileHandle); CloseHandle( FileHandle ); FileHandle = INVALID_HANDLE_VALUE;
This file doesn't even have a header, and your code wrote only 4 bytes of data to it, so how would you want it to be played? Regards
-
I follow the following steps to write a simple record program waveInOpen waveInPrepareHeader waveInAddBuffer waveInStart waveInGetPosition waveInReset waveInUnprepareHeader waveInClose The program runs with no errors. But I create a file to record the voice. HANDLE FileHandle = CreateFile( L"myTest.wav", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); The wav file was created. But I play rhe wav file by windows media player. It says there is an error. Is there any problem with my code? My part code is below.
HANDLE FileHandle = CreateFile( L"myTest.wav", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile(FileHandle, &dwNumber, 4, &NumToWrite, NULL); SetEndOfFile(FileHandle); CloseHandle( FileHandle ); FileHandle = INVALID_HANDLE_VALUE;
Can somebody help me? Thanks a lot. minihottoIn addition use of
CREATE_ALWAYS
overwrite your file if its exist
WhiteSky
-
minihotto wrote:
WriteFile(FileHandle, &dwNumber, 4, &NumToWrite, NULL);
You know that your file will only be 4 bytes ? I hardly believe this a valid file format for a wav file. Check the documentation of the WriteFile[^] function. Also, you will need to follow the format reaquired for a wav file (I don't know it but if you search on google, you could find it).
minihotto wrote:
SetEndOfFile(FileHandle);
What are you trying to do here ?
Cédric Moonen Software developer
Charting control [Updated - v1.1]I see. thnaks. this is the example I find from internet
HANDLE FileHandle = CreateFile( "Test.wav", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); dwNumber = FCC("RIFF"); WriteFile(FileHandle, &dwNumber, 4, &NumToWrite, NULL);
what is FCC? I cant find it in the msdn. can somebody help me ? thanks a lot. minihotto -
I see. thnaks. this is the example I find from internet
HANDLE FileHandle = CreateFile( "Test.wav", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); dwNumber = FCC("RIFF"); WriteFile(FileHandle, &dwNumber, 4, &NumToWrite, NULL);
what is FCC? I cant find it in the msdn. can somebody help me ? thanks a lot. minihottoIt's probably a function that they developed themselves. But anyway, you first need to understand the file structure of the wav file in order to have something that can be played.
Cédric Moonen Software developer
Charting control [Updated - v1.1] -
I follow the following steps to write a simple record program waveInOpen waveInPrepareHeader waveInAddBuffer waveInStart waveInGetPosition waveInReset waveInUnprepareHeader waveInClose The program runs with no errors. But I create a file to record the voice. HANDLE FileHandle = CreateFile( L"myTest.wav", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); The wav file was created. But I play rhe wav file by windows media player. It says there is an error. Is there any problem with my code? My part code is below.
HANDLE FileHandle = CreateFile( L"myTest.wav", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile(FileHandle, &dwNumber, 4, &NumToWrite, NULL); SetEndOfFile(FileHandle); CloseHandle( FileHandle ); FileHandle = INVALID_HANDLE_VALUE;
Can somebody help me? Thanks a lot. minihottoMicrosoft's WAV file format is well documented. A quick GOOGLEY search found this one WaveFormat[^] By the way, FCC() is just somebody's function for dealing with FOURCC codes - four characters which need to be written in order in a big-endian/little-endian integer world. Mark