Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. A simple question about recording

A simple question about recording

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    minihotto
    wrote on last edited by
    #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. minihotto

    C G H M 4 Replies Last reply
    0
    • M 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. minihotto

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      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]

      M 1 Reply Last reply
      0
      • M 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. minihotto

        G Offline
        G Offline
        Galatei
        wrote on last edited by
        #3

        minihotto 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

        1 Reply Last reply
        0
        • M 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. minihotto

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          In addition use of CREATE_ALWAYSoverwrite your file if its exist


          WhiteSky


          1 Reply Last reply
          0
          • C Cedric Moonen

            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]

            M Offline
            M Offline
            minihotto
            wrote on last edited by
            #5

            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

            C 1 Reply Last reply
            0
            • M 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. minihotto

              C Offline
              C Offline
              Cedric Moonen
              wrote on last edited by
              #6

              It'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]

              1 Reply Last reply
              0
              • M 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. minihotto

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                Microsoft'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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups