Re: how to adjust capture level
Chris Robinson <[email protected]>
| Newsgroups | gmane.comp.lib.openal |
|---|---|
| Message-ID | <[email protected]> |
On Thursday, December 02, 2010 7:59:38 pm Bruce Clay wrote:
> I am trying to adjust the input level of a capture device but I can't find
> how to do so.
OpenAL doesn't have any controls for the capture volume. The volume you get
out of OpenAL is what's set by the OS/drivers. It's not too difficult to do it
manually, though how to do it depends on what you're doing with the audio. If
you're feeding it into a source's buffer queue, you can simply set the gain of
the source it's playing back on (though this may not work well if you're
trying to increase the volume). Otherwise, you can do something this:
alcCaptureSamples(device, buffer, samples);
if(capture_bits == 8)
{
for(i = 0;i < samples*capture_channels;i++)
{
int sample = (((ALubyte*)buffer)[i]-128) * capture_gain + 128;
if(sample < 0) sample = 0;
else if(sample > 255) sample = 255;
((ALubyte*)buffer)[i] = sample;
}
}
else if(capture_bits == 16)
{
for(i = 0;i < samples*capture_channels;i++)
{
int sample = ((ALshort*)buffer)[i] * capture_gain;
if(sample < -32768) sample = -32768;
else if(sample > 32767) sample = 32767;
((ALshort*)buffer)[i] = sample;
}
}
..where capture_bits and capture_channels are derived from the format given to
alcCaptureOpenDevice, and capture_gain is a float value of the gain you want
to apply.
_______________________________________________
Openal mailing list
[email protected]
http://opensource.creative.com/mailman/listinfo/openal