winapi音频输出 [英] winapi audio output

查看:416
本文介绍了winapi音频输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一些替代的pulseaudio的窗口。
在linux下有非常简单的方式输出原始声音(使用pulseaudio):

I am searching some alternative of pulseaudio for windows. Under linux there is very simple way to output raw sound (with pulseaudio):

pa_simple_write(pulse, data, bufferSize, &error);

用小缓冲区工作,我在循环中发送函数。

It's work perfect with small buffers, that i send to function in the loop.

在windows下,我使用这样的东西:

Under windows i use something like this:

void writeAudioBlock(HWAVEOUT hWaveOut, LPSTR block, DWORD size)
{
    WAVEHDR header;

    ZeroMemory(&header, sizeof(WAVEHDR));
    header.dwBufferLength = size;
    header.lpData = block;

    waveOutPrepareHeader(hWaveOut, &header, sizeof(WAVEHDR));

    ResetEvent(waveDone);

    waveOutWrite(hWaveOut, &header, sizeof(WAVEHDR));

    WaitForSingleObject(waveDone, INFINITE);

    waveOutUnprepareHeader(
        hWaveOut, 
        &header, 
        sizeof(WAVEHDR)
    );
}

它工作,但是当我发送另一个数据时,件。

It's working, but when i send another piece of data i hear small delay between pieces. Any other way to output small chunks of data buffer to sound device?

推荐答案

如果你想播放一些音频文件,你可以使用Windows API中的PlaySound函数。

If you want to play some audio file, you can use the PlaySound function in windows API.

对于存储在内存中的数据块,您必须使用Waveform API - waveOutXXX函数。

For chunks of data stored in memory you have to use the Waveform API - waveOutXXX functions.

对于音频块之间的延迟的问题,你必须使用一些双缓冲机制。

For the problems with the delay between chunks of audio you have to use some double buffering mechanism.

您可以在这里找到一个例子:
双缓冲

You can find an example here: double buffering

这篇关于winapi音频输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆