Thread: Audio input/output

  1. #1
    Registered User
    Join Date
    Dec 2014
    Posts
    143

    Audio input/output

    So I want to start working on a project I know will take awhile. I want to create some effects for my guitar using real-time DSP. Since C/C++ are obviously fast languages they are ideal for this. I'm using Visual Studio 2013 pro and I want to know how to get input from a microphone and output directly to the speakers. I just want to make sure my process is working so I can begin making algorithms.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    One obvious candidate is directshow. There may be other audio libraries out there if you google.
    Capturing and outputting audio is not something that's directly supported by the language. So you will have to look into windows api or find some 3rd party library that does this for you.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Dec 2014
    Posts
    143
    https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx I found this but I'm not exactly sure how this works or how to implement it. And from the looks of it, it also has an output stream function and others.

  4. #4
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877
    Quote Originally Posted by cmajor28 View Post
    https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx I found this but I'm not exactly sure how this works or how to implement it. And from the looks of it, it also has an output stream function and others.
    The win32 API gets pretty complex when working with audio (it lets you specify so much information).

    First you need to call waveInOpen(), the third parameter is a WAVEFORMATEX structure where you specify samples per second (ect), the first parameter should return a handle to the open audio input device.
    https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

    This causes a MM_WIM_OPEN message to be sent to the user function specified in the waveInOpen() call. During this time you prepare a buffer to receive the audio data with a function called waveInPrepareHeader(). The second parameter is a pointer to WAVEHDR that should be initialized with data before the call to waveInPrepareHeader().
    https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

    Then you add the prepared WAVEHDR to the open device with a call to waveInAddBuffer(), and you are finally ready to begin recording with a call to waveInStart() (it takes a single argument, the handle to the open input device).
    https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
    https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

    You might be able to do this without using the window events system in Win32, but I think you will need at least some event library (although maybe not, it might be possible to do it through the console, I don't know). Hopefully this information is at least a beginning point. Good luck!

    Edit: Keep in mind this is just getting the audio data into a buffer in a state usable by the program. (Also, I added some links that I forgot).

    Edit2: Also an example of the wave API, I didn't compile or check it, but it shows the functions and structures used. Also "Windows Programming 5th ed." has some great examples near the end of the book.
    http://vismod.media.mit.edu/vismod/d...dioCapture.txt
    Last edited by Alpo; 01-25-2015 at 01:53 AM.
    WndProc = (2[b] || !(2[b])) ? SufferNobly : TakeArms;

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I guess you could use DirectSound too (DirectX).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Dec 2014
    Posts
    143
    Yeah, DirectX is pretty common. Does DirectX support Mac/Linux and Windows or no? If it does that would be an obvious advantage over the win32 API.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, it's Windows only. But so in Win32 api.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Dec 2014
    Posts
    143
    I'm definitely going with DirectX because the Win32 API seems very complex.

    I just don't know where to start.
    Last edited by cmajor28; 01-25-2015 at 09:27 AM.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Dec 2014
    Posts
    143
    I think my problem is I have minimal knowledge of how audio is handled in Windows.

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    And that would be a problem... how? DirectSound handles all the stuff for you. You only need to know how DirectSound works.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Registered User
    Join Date
    Dec 2014
    Posts
    143
    Well I'm trying to read some stuff about DirectSound but none of it really explains the basics. And most of the things are geared towards streaming .wav files and not streaming the default recording device.

  13. #13
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Do not use DirectSound, it's depreciated.

    If you want your program to be cross-platform, use OpenAL or SDL_sound. If you're sure you want to exclusively support Windows, use WASAPI.

  14. #14
    Registered User
    Join Date
    Dec 2014
    Posts
    143
    I don't necessary need it to be cross platform. And how hard is WASAPI to use?

  15. #15
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by cmajor28 View Post
    I don't necessary need it to be cross platform. And how hard is WASAPI to use?
    Harder than OpenAL or SDL.
    There's no harm in using a cross-platform library in a Windows exclusive program, if you so wish.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copying input to output K&R there is no output
    By amadeus111 in forum C Programming
    Replies: 5
    Last Post: 02-24-2013, 05:09 AM
  2. input/output
    By chris04585 in forum C Programming
    Replies: 16
    Last Post: 02-13-2011, 08:31 AM
  3. Replies: 1
    Last Post: 09-24-2009, 01:28 AM
  4. REQ: Change Audio Input Device?
    By Geolingo in forum Windows Programming
    Replies: 0
    Last Post: 09-01-2006, 01:24 PM
  5. Controling a process's audio output
    By Gravedigga in forum Windows Programming
    Replies: 0
    Last Post: 05-13-2005, 10:44 AM