Re: alcCaptureSamples crashes on stereo capturing
Philipp Kraus <[email protected]> Fri, 10 Aug 2012 10:35:35 +0200
| Newsgroups | gmane.comp.lib.openal |
|---|---|
| Message-ID | <[email protected]> |
On 2012-08-10 05:20:44 +0200, Chris Robinson said:
> On 08/09/2012 07:14 AM, Philipp Kraus wrote:
>> Hello,
>>
>> I have got this code for capturing mono 8 bit data, the code works
>> without any error:
>>
>> m_device = alcCaptureOpenDevice( p_device.c_str(),
>> static_cast<ALCuint>(p_sampingfrequency), AL_FORMAT_MONO8,
>> static_cast<ALCsizei>(p_buffersize));
>>
>> ublas::vector<ALubyte> l_buffer(m_buffersize);
>> alcCaptureStart(m_device);
>> while(m_capturing)
>> {
>> alcGetIntegerv(...)
>> l_samplesread = std::min(
>> static_cast<std::size_t>(l_samplesread), l_buffer.size()-i);
>> alcCaptureSamples(m_device, (ALCvoid*)(&l_buffer[i]),
>> l_samplesread);
>> }
>>
>> If I switch the the AL_FORMAT_MONO8 to AL_FORMAT_STEREO8 and change the
>> p_buffersize to 2*p_buffersize & m_buffersize to 2*m_buffersize the code
>> crashes
>> on the alcCaptureSamples line and the buffer is not filled.
>
> It looks like you're not accounting for the count being in sample
> frames, so you're asking for n sample frames, but only have enough
> space for n/2 (since it needs two channels for each sample frame).
> l_buffer.size() is samples*channels, not the number of samples.
>
> l_buffer.size()/2 is the number of samples to fill for stereo.
Yes, my code shows exactly;
m_device = alcCaptureOpenDevice( p_device.c_str(),
static_cast<ALCuint>(m_samplingfrequency), AL_FORMAT_STEREO8,
static_cast<ALCsizei>(m_buffersize));
ublas::vector<ALubyte> l_buffer(2*m_buffersize);
alcCaptureStart
wile(m_capturing)
{
for(std::size_t i=0; i < l_buffer.size(); )
{
ALint l_samplesread = 0;
alcGetIntegerv(m_device, ALC_CAPTURE_SAMPLES,
static_cast<ALCsizei>(sizeof(ALint)), &l_samplesread);
i if ( (!l_samplesread) && (alcIsExtensionPresent(m_device,
"ALC_EXT_disconnect")) )
{
stop capturing
}
if (l_samplesread > 0)
{
l_samplesread = std::min(
static_cast<std::size_t>(l_samplesread), l_buffer.size()-i);
alcCaptureSamples(m_device, (ALCvoid*)(&l_buffer(i)),
l_samplesread);
i += l_samplesread;
}
}
}
alcCaptureStop
I think this correct, because the buffer has got the double size, so
left / right channel are correct stored. If I write the l_buffer down
to std::cout the values are correct, but
on calling the dtor of my object, I get the same error.
My l_samples is the number of samples that are read or is it on stereo
the number of frames?
IMHO a frame stores 2 elements of ALubyte, so my buffer must have
2*m_buffersize
Thanks
Phil
_______________________________________________
Openal mailing list
[email protected]
http://opensource.creative.com/mailman/listinfo/openal