0

How can I capture an audio input of a WAV file through microphone in c for windows 8 ? I have searched for,but i couldn't find one the way i looked for. I do not want to use any additional software tool and I want it in C programming language. My friends advised to me to use a different language like java or change the IDE. i want to be sure first that it is not done in C, using Dev-C++ and with out any additional tool. Now am wondering if this is available at all because i couldn't find such C-functions to capture audio from live input. am using Dev-C++ IDE. I can read and process if it is from stored file in HDD. I appreciate any hint

for files already stored in a disc, i have the following snippet:

 if ((wptr1 = fopen(wavContent1, "rb")) == NULL)
 {
 printf("Cannot open the input file\n");
 ret = FAIL;
 }
 else if ( (wptr2 = fopen((wavContentout), "wb")) == NULL )
 {
 printf("Cannot open the output file\n");
 ret = FAIL;
 }
 else {
   hdInfo=malloc(sizeof(header)) ;      
   writeReadable(wptr1,wptr2);
   fclose(wptr2);
   fclose(wptr1);

  }

and for the function writeReadable() i have the following shortened code:

  void writeReadable(FILE *wavin, FILE *wavout){
  int BUFSIZE=128;      
  int buff[BUFSIZE];
  int* buf=buff;

    fread(hdInfo, sizeof(header), 1, wavin);
    fwrite(hdInfo, sizeof(*hdInfo), 1, wavout);

   while (!feof(wavin))
   {
    fread(buff, BUFSIZE, 1, wavin);
    fwrite(buff, BUFSIZE, 1, wavout);
    size= size + BUFSIZE;
    count++;           
    } 
   size=size + sizeof(*hdInfo);
  }
Josh
  • 11
  • 3
  • For Windows, look up the waveIn API. (It's a bit old, but it's for C and pretty simple, and as far as I know it still works perfectly well) – user253751 Dec 09 '15 at 08:55
  • Please alse see [Why is “while ( !feof (file) )” always wrong?](http://stackoverflow.com/questions/5431941/why-is-while-feof-file-always-wrong) It is better to control the loop with the number of items returned by `fread()`. – Weather Vane Dec 09 '15 at 09:14
  • @immibis and Weather Vane, thank you for replying. the code I posted works right for a saved wav file in my laptop. and it is clear i can use fread() and fwrite() to access block by block. my sole problem is what built in functions in C can i use to capture the mic input. – Josh Dec 09 '15 at 09:46
  • Maybe see: http://stackoverflow.com/questions/2010400/best-api-for-low-level-audio-in-windows – Toby Dec 09 '15 at 10:06
  • @Toby Thanks. I had seen the link. its good except it suggests PortAudio. Is C language unable to handle audio input with out the support of some tools/software? – Josh Dec 09 '15 at 11:39
  • @Josh I was thinking more the wavein API which is *essentially* the most basic interface that MS Windows provides to allow you to interact with the sound input to the OS. At some point your program will need to request outside code (i.e. the OS) to get data from the audio source for you. This will of course then be platform dependent. At a normal level there will always be outside code (even if it's just the OS) that your program will need to interact with to talk to H/W. The extra packages mentioned can make this interaction simpler. – Toby Dec 09 '15 at 12:06
  • To satisfy the pedantic: I imagine there are all sorts of lower-level ways you could interact with audio H/W, such as directly to audio driver API's, low-level I/O or what-have you but this will always still require some level of dealing with the OS, so you'd really be making things much more difficult for close to zero gain. – Toby Dec 09 '15 at 12:09
  • @Toby you are welcome. You are persuading me. and am getting open to use some tools or a different language. What good option of such tools do I have? and if i change language, would it be easier in C++ or java? one more thing, does it all depend on the IDE i use? – Josh Dec 09 '15 at 12:14
  • @Josh you can still use C with the wavein API or DirectX (see: http://stackoverflow.com/questions/4696079/directx-programming-in-c). although some say C++ maybe easier to use with the APIs mentioned. The IDE shouldn't really matter, Dev-C++ should handle stuff fine, you just need to make sure you link to the API correctly (using the correct includes, etc) to be able to program using it. – Toby Dec 09 '15 at 13:28
  • @Toby Thank you! I will go through – Josh Dec 09 '15 at 13:57

0 Answers0