API for capturing sound on Windows

后端 未结 2 1254
一个人的身影
一个人的身影 2021-01-03 17:41

I need a C++ API to enumerate input devices and capture sound for Windows Vista, Windows 7 and Windows 8. If there is no common API I can use OS specific API for different v

相关标签:
2条回答
  • 2021-01-03 17:57

    For waveIn API use waveInGetNumDevs() and waveInGetDevCaps(). For Core Audio API use IMMDeviceEnumerator. For DirectShow read this: http://msdn.microsoft.com/en-us/library/windows/desktop/dd377566(v=vs.85).aspx

    It all depends on the rest of the architecture. You have to do something with the captured PCM and you probably know what. That should help you decide what technology to use.

    0 讨论(0)
  • 2021-01-03 18:02

    Take a look at the BASS library.

    It is:

    • cross-platform;
    • well documented;
    • has a great support;
    • easy to use;
    • has lots of plugins;
    • free for non-commercial use.

    Get the total number of recording devices currently present:

    int a, count=0;
    BASS_DEVICEINFO info;
    for (a=0; BASS_RecordGetDeviceInfo(a, &info); a++)
        if (info.flags&BASS_DEVICE_ENABLED) // device is enabled
            count++; // count it
    

    Start recording at 44100hz 16-bit stereo:

    FILE *file;
    ...
    // the recording callback
    BOOL CALLBACK MyRecordingWriter(HRECORD handle, void *buf, DWORD len, void *user)
    {
        fwrite(buf, 1, len, file); // write the buffer to the file
        return TRUE; // continue recording
    }
    ...
    HRECORD record=BASS_RecordStart(44100, 2, 0, MyRecordingWriter, 0); // start recording
    
    0 讨论(0)
提交回复
热议问题