[Openal] Re: Problems with microphone input
dpeacock at creativelabs.com
dpeacock at creativelabs.com
Tue Jan 24 09:40:36 PST 2006
Firstly I would recommend removing all calls to alutInit and alutExit (it
is better to handle initialization and shutdown yourself).
e.g Initialization of the default *Play back* device can be done like this
ALCdevice *pDevice = NULL;
ALCcontext *pContext = NULL;
pDevice = alcOpenDevice(NULL);
pContext = alcCreateContext(pDevice, NULL);
// init successful ...
and shutdown (after a successful initialization) looks like this ...
The *Capture Device* needs to be initialized separately using the
alcCaptureOpenDevice call as you are doing below ... BUT the last parameter
is NOT in bytes - it is in SAMPLES. So for 16 bit mono data you are
actually requesting a buffer size of 220500 * 2 = 441000 bytes (which is 5
seconds of audio data in 16bit mono 44.1KHz).
Also I would change your routine that checks for captured audio data so
that you do not assume that you will be getting less than a particular
number of samples (especially when that is so low (only 11.6
milliseconds)). I would write the code like this :-
// Sleep call here perhaps ?
alcGetIntegerv(pCaptureDevice, ALC_CAPTURE_SAMPLES, 1,
if (lSamplesAvailable > MyBufferSizeInSamples)
// Consume MyBufferSizeInSamples samples
alcCaptureSamples( .... )
The Windows Open AL SDK includes example code for using the
CaptureDevice,so it might be worth downloading that and checking it out.
The information in this message is confidential and may be legally
privileged. It is intended solely for the addressee. Access to this
message by anyone else is unauthorized. If you are not the intended
recipient, any disclosure, copying or distribution of the message, or
any action taken by you in reliance on it, is prohibited and may be
unlawful. If you have received this message in error, please delete it
and contact the sender immediately. Thank you.
<runeedge at gmail.c
Sent by: openal at opensource.creative.com
openal-admin at open cc
Re: [Openal] Re: Problems with
Here is the function before hand that initializes the audio input and
static ALCuint inputfreq = 44100; //I'M ASSUMING THIS IS IN HERTZ?
ALCenum inputfmt = AL_FORMAT_MONO16;
ALCsizei inputbuffersize = 220500; //I'M ASSUMING THIS IS IN BYTES?
inputdevice = alcCaptureOpenDevice(NULL, inputfreq, inputfmt,
if(inputdevice == NULL)
cout << "No microphone detected" << endl;
microphonesupport = false;
cout << "Microphone dectected :)" << endl;
microphonesupport = true;
//THE REST OF THIS FUNCTION INITIALIZES AND LOADS ANY SOUNDS TO BE
PLAYED AND THAT PART WORKS FINE
Does that help? I did have a few questions. For example, in my main, I
void main(int argc, char**argv)
// alutInit(NULL, 0);
I actually don't understand the parameters for alutInit; I have seen
some people use NULL, 0 and glutInit uses argc, argv, as passed into
main, but I don't understand them either. And here is the problem,
alutInit() is causing my program to crash after a given number of
lines. If I use (NULL, 0), then it crashes sooner and if I use
(&argc, argv) it crashes later. However, if I call alutExit() before
it crashes, it seems to save the program.
Any help you can provide would be useful.
And maybe this will help in figuring out the problem. At the moment,
the way I have it set up is that if a key is pressed, a sound is
played. Then, if another key is pressed, the sound is recorded over
the original buffer, so that when the playback key is pressed, they
don't hear the original sound, but the recorded one. Now, in actual
implementation this is what happens: pressing the playback key works
with the original sound file. If we remove the loop with the
non-incrementing counter, the whole thing runs without crashing. When
we go to record, everything is fine, but when we try to play back the
recorded sound, it is now silence; the original soundfile has been
overwritten by the recorded buffer, which is 99% empty. This makes me
think that everything is working, except this non-incrementing counter
I hope that might be useful.
Thanks for your help.
On 1/23/06, dpeacock at creativelabs.com <dpeacock at creativelabs.com> wrote:
> Hi Tim,
> I don't see the alcCaptureOpenDevice call in this code. Assuming you are
> making this call somewhere else ... what parameters are you passing to
> and is the function call succeeding ?
> The information in this message is confidential and may be legally
> privileged. It is intended solely for the addressee. Access to this
> message by anyone else is unauthorized. If you are not the intended
> recipient, any disclosure, copying or distribution of the message, or
> any action taken by you in reliance on it, is prohibited and may be
> unlawful. If you have received this message in error, please delete it
> and contact the sender immediately. Thank you.
> Tim Mahrt
> <runeedge at gmail.c
> Sent by: openal at opensource.creative.com
> openal-admin at open
> [Openal] Re: Problems with
> microphone input
> 01/22/2006 07:53
> I'm working on getting microphone support in OpenAL and I'm running into
> some problems.
> Here is the situation:
> My code compiles and runs fine, until it gets to alGetIntegerv(), which
> not updating the accumulation variable. Any ideas?
> Here is my function:
> void beginGetMicData()
> cout << "Getting data from microphone" << endl;
> ALint samples = 0;
> ALint samp = 0;
> cout << "Start recording" << endl;
> cout << "Start agregating..." << endl;
> while (samples < 1024) //'samples' IS NOT ACCUMULATING
> alcGetIntegerv(inputdevice, ALC_CAPTURE_SAMPLES,
> inputfmt, &samples);
> cout << samples << endl;
> cout << "Finished agregating" << endl;
> alcCaptureSamples(inputdevice, inputbuffer, inputbuffersize);
> alGenSources(1, &sourceID);
> alGenBuffers(1, &bufferID);
> alBufferData(bufferID, inputfmt, inputbuffer, sizeof
> (inputbuffer), inputfreq);
> alSourcei(sourceID, AL_BUFFER, bufferID);
> openal mailing list
> openal at opensource.creative.com
openal mailing list
openal at opensource.creative.com
More information about the Openal