Continuous WASAPI Ring-Buffer Sampling
up vote
-2
down vote
favorite
How to use WASAPI (or something like it) to continuously sample audio into a (thread-safe) ring-buffer, so that a consumer thread can read from that buffer in an a set interval?
Currently we have a .sample() method that returns a chunk of samples after a set sampling interval, but this has quite the overhead due to memory allocation etc.. maybe this method could be optimized; I'm pretty sure we're doing it wrong.
std::vector<short> sampler2::sample()
{
// prepare header
waveInPrepareHeader(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
// insert a wave input buffer
waveInAddBuffer(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
// commence sampling input
waveInStart(hWaveIn);
// sleep for the duration of a sample interval
std::this_thread::sleep_for(milliseconds(SAMPLE_INTERVAL));
// create vector
std::vector<short> samplesChunk(&waveIn[0], &waveIn[0] + NUMPTS);
// return vector
return samplesChunk;
}
GitHub Links: sampler2.h & sampler2.cpp
The code is very shitty and we have no clue how to properly use WASAPI. Our goal was to (quickly) create a sampler class that can leverage a sampling interval of >10 ms.
c++ winapi audio sampling wasapi
add a comment |
up vote
-2
down vote
favorite
How to use WASAPI (or something like it) to continuously sample audio into a (thread-safe) ring-buffer, so that a consumer thread can read from that buffer in an a set interval?
Currently we have a .sample() method that returns a chunk of samples after a set sampling interval, but this has quite the overhead due to memory allocation etc.. maybe this method could be optimized; I'm pretty sure we're doing it wrong.
std::vector<short> sampler2::sample()
{
// prepare header
waveInPrepareHeader(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
// insert a wave input buffer
waveInAddBuffer(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
// commence sampling input
waveInStart(hWaveIn);
// sleep for the duration of a sample interval
std::this_thread::sleep_for(milliseconds(SAMPLE_INTERVAL));
// create vector
std::vector<short> samplesChunk(&waveIn[0], &waveIn[0] + NUMPTS);
// return vector
return samplesChunk;
}
GitHub Links: sampler2.h & sampler2.cpp
The code is very shitty and we have no clue how to properly use WASAPI. Our goal was to (quickly) create a sampler class that can leverage a sampling interval of >10 ms.
c++ winapi audio sampling wasapi
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
How to use WASAPI (or something like it) to continuously sample audio into a (thread-safe) ring-buffer, so that a consumer thread can read from that buffer in an a set interval?
Currently we have a .sample() method that returns a chunk of samples after a set sampling interval, but this has quite the overhead due to memory allocation etc.. maybe this method could be optimized; I'm pretty sure we're doing it wrong.
std::vector<short> sampler2::sample()
{
// prepare header
waveInPrepareHeader(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
// insert a wave input buffer
waveInAddBuffer(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
// commence sampling input
waveInStart(hWaveIn);
// sleep for the duration of a sample interval
std::this_thread::sleep_for(milliseconds(SAMPLE_INTERVAL));
// create vector
std::vector<short> samplesChunk(&waveIn[0], &waveIn[0] + NUMPTS);
// return vector
return samplesChunk;
}
GitHub Links: sampler2.h & sampler2.cpp
The code is very shitty and we have no clue how to properly use WASAPI. Our goal was to (quickly) create a sampler class that can leverage a sampling interval of >10 ms.
c++ winapi audio sampling wasapi
How to use WASAPI (or something like it) to continuously sample audio into a (thread-safe) ring-buffer, so that a consumer thread can read from that buffer in an a set interval?
Currently we have a .sample() method that returns a chunk of samples after a set sampling interval, but this has quite the overhead due to memory allocation etc.. maybe this method could be optimized; I'm pretty sure we're doing it wrong.
std::vector<short> sampler2::sample()
{
// prepare header
waveInPrepareHeader(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
// insert a wave input buffer
waveInAddBuffer(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
// commence sampling input
waveInStart(hWaveIn);
// sleep for the duration of a sample interval
std::this_thread::sleep_for(milliseconds(SAMPLE_INTERVAL));
// create vector
std::vector<short> samplesChunk(&waveIn[0], &waveIn[0] + NUMPTS);
// return vector
return samplesChunk;
}
GitHub Links: sampler2.h & sampler2.cpp
The code is very shitty and we have no clue how to properly use WASAPI. Our goal was to (quickly) create a sampler class that can leverage a sampling interval of >10 ms.
c++ winapi audio sampling wasapi
c++ winapi audio sampling wasapi
asked 2 days ago
Androvich
123115
123115
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Your sample uses waveout API. You can check MSDN for WASAPI reference and usage.
Here is the basic description of WASAPI usage:
The client calls the methods in the IAudioRenderClient interface to write rendering data to an endpoint buffer.To request an endpoint buffer of a particular size, the client calls the IAudioClient::Initialize method. To get the size of the allocated buffer, which might be different from the requested size, the client calls the IAudioClient::GetBufferSize method.
To move a stream of rendering data through the endpoint buffer, the client alternately calls the IAudioRenderClient::GetBuffer method and the IAudioRenderClient::ReleaseBuffer method. The client accesses the data in the endpoint buffer as a series of data packets. The GetBuffer call retrieves the next packet so that the client can fill it with rendering data. After writing the data to the packet, the client calls ReleaseBuffer to add the completed packet to the rendering queue.
There is also this Microsoft C++ WASAPI example.
What's the difference between the two? And thanks, I'll take a look!
– Androvich
yesterday
1
WaveOut is a legacy API set present in Windows. While WASAPI is a core audio API and is available since Vista. It needs a specific driver implementation.
– VuVirt
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Your sample uses waveout API. You can check MSDN for WASAPI reference and usage.
Here is the basic description of WASAPI usage:
The client calls the methods in the IAudioRenderClient interface to write rendering data to an endpoint buffer.To request an endpoint buffer of a particular size, the client calls the IAudioClient::Initialize method. To get the size of the allocated buffer, which might be different from the requested size, the client calls the IAudioClient::GetBufferSize method.
To move a stream of rendering data through the endpoint buffer, the client alternately calls the IAudioRenderClient::GetBuffer method and the IAudioRenderClient::ReleaseBuffer method. The client accesses the data in the endpoint buffer as a series of data packets. The GetBuffer call retrieves the next packet so that the client can fill it with rendering data. After writing the data to the packet, the client calls ReleaseBuffer to add the completed packet to the rendering queue.
There is also this Microsoft C++ WASAPI example.
What's the difference between the two? And thanks, I'll take a look!
– Androvich
yesterday
1
WaveOut is a legacy API set present in Windows. While WASAPI is a core audio API and is available since Vista. It needs a specific driver implementation.
– VuVirt
yesterday
add a comment |
up vote
0
down vote
Your sample uses waveout API. You can check MSDN for WASAPI reference and usage.
Here is the basic description of WASAPI usage:
The client calls the methods in the IAudioRenderClient interface to write rendering data to an endpoint buffer.To request an endpoint buffer of a particular size, the client calls the IAudioClient::Initialize method. To get the size of the allocated buffer, which might be different from the requested size, the client calls the IAudioClient::GetBufferSize method.
To move a stream of rendering data through the endpoint buffer, the client alternately calls the IAudioRenderClient::GetBuffer method and the IAudioRenderClient::ReleaseBuffer method. The client accesses the data in the endpoint buffer as a series of data packets. The GetBuffer call retrieves the next packet so that the client can fill it with rendering data. After writing the data to the packet, the client calls ReleaseBuffer to add the completed packet to the rendering queue.
There is also this Microsoft C++ WASAPI example.
What's the difference between the two? And thanks, I'll take a look!
– Androvich
yesterday
1
WaveOut is a legacy API set present in Windows. While WASAPI is a core audio API and is available since Vista. It needs a specific driver implementation.
– VuVirt
yesterday
add a comment |
up vote
0
down vote
up vote
0
down vote
Your sample uses waveout API. You can check MSDN for WASAPI reference and usage.
Here is the basic description of WASAPI usage:
The client calls the methods in the IAudioRenderClient interface to write rendering data to an endpoint buffer.To request an endpoint buffer of a particular size, the client calls the IAudioClient::Initialize method. To get the size of the allocated buffer, which might be different from the requested size, the client calls the IAudioClient::GetBufferSize method.
To move a stream of rendering data through the endpoint buffer, the client alternately calls the IAudioRenderClient::GetBuffer method and the IAudioRenderClient::ReleaseBuffer method. The client accesses the data in the endpoint buffer as a series of data packets. The GetBuffer call retrieves the next packet so that the client can fill it with rendering data. After writing the data to the packet, the client calls ReleaseBuffer to add the completed packet to the rendering queue.
There is also this Microsoft C++ WASAPI example.
Your sample uses waveout API. You can check MSDN for WASAPI reference and usage.
Here is the basic description of WASAPI usage:
The client calls the methods in the IAudioRenderClient interface to write rendering data to an endpoint buffer.To request an endpoint buffer of a particular size, the client calls the IAudioClient::Initialize method. To get the size of the allocated buffer, which might be different from the requested size, the client calls the IAudioClient::GetBufferSize method.
To move a stream of rendering data through the endpoint buffer, the client alternately calls the IAudioRenderClient::GetBuffer method and the IAudioRenderClient::ReleaseBuffer method. The client accesses the data in the endpoint buffer as a series of data packets. The GetBuffer call retrieves the next packet so that the client can fill it with rendering data. After writing the data to the packet, the client calls ReleaseBuffer to add the completed packet to the rendering queue.
There is also this Microsoft C++ WASAPI example.
answered yesterday
VuVirt
1,329711
1,329711
What's the difference between the two? And thanks, I'll take a look!
– Androvich
yesterday
1
WaveOut is a legacy API set present in Windows. While WASAPI is a core audio API and is available since Vista. It needs a specific driver implementation.
– VuVirt
yesterday
add a comment |
What's the difference between the two? And thanks, I'll take a look!
– Androvich
yesterday
1
WaveOut is a legacy API set present in Windows. While WASAPI is a core audio API and is available since Vista. It needs a specific driver implementation.
– VuVirt
yesterday
What's the difference between the two? And thanks, I'll take a look!
– Androvich
yesterday
What's the difference between the two? And thanks, I'll take a look!
– Androvich
yesterday
1
1
WaveOut is a legacy API set present in Windows. While WASAPI is a core audio API and is available since Vista. It needs a specific driver implementation.
– VuVirt
yesterday
WaveOut is a legacy API set present in Windows. While WASAPI is a core audio API and is available since Vista. It needs a specific driver implementation.
– VuVirt
yesterday
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364127%2fcontinuous-wasapi-ring-buffer-sampling%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown