[Openal] Re: Problems with microphone input
dpeacock at creativelabs.com
dpeacock at creativelabs.com
Tue Jan 24 09:40:36 PST 2006
Hi Tim,
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);
if (pDevice)
{
pContext = alcCreateContext(pDevice, NULL);
if (pContext)
{
alcMakeContextCurrent(pContext);
// init successful ...
}
}
and shutdown (after a successful initialization) looks like this ...
alcMakeContextCurrent(NULL);
alcDestroyContext(pContext);
alcCloseDevice(pDevice);
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 :-
ALint MyBufferSizeInSamples;
while (1)
{
// Sleep call here perhaps ?
alcGetIntegerv(pCaptureDevice, ALC_CAPTURE_SAMPLES, 1,
&lSamplesAvailable);
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.
Thanks,
Dan
Notice
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
om> To
Sent by: openal at opensource.creative.com
openal-admin at open cc
source.creative.c
om Subject
Re: [Openal] Re: Problems with
microphone input
01/23/2006 12:49
PM
Here is the function before hand that initializes the audio input and
output:
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?
void audioInit()
{
inputdevice = alcCaptureOpenDevice(NULL, inputfreq, inputfmt,
inputbuffersize);
if(inputdevice == NULL)
{
cout << "No microphone detected" << endl;
microphonesupport = false;
}
else
{
cout << "Microphone dectected :)" << endl;
microphonesupport = true;
}
alutExit(); //HMMMMM??
alGetError();
//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
called:
void main(int argc, char**argv)
{
// alutInit(NULL, 0);
alutInit(&argc, argv);
glutInit(&argc, argv);
audioInit();
}
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.
Tim
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
it,
> and is the function call succeeding ?
>
> Thanks,
>
> Dan
>
> Notice
> 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
> om>
To
> Sent by: openal at opensource.creative.com
> openal-admin at open
cc
> source.creative.c
> om
Subject
> [Openal] Re: Problems with
> microphone input
> 01/22/2006 07:53
> PM
>
>
>
>
>
>
>
>
> 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
is
> not updating the accumulation variable. Any ideas?
> Thanks,
> Tim
> Here is my function:
>
> void beginGetMicData()
> {
> if(microphonesupport)
> {
> alcCaptureStart(inputdevice);
> 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);
> alcCaptureStop(inputdevice);
>
> alcCaptureCloseDevice(inputdevi
> ce);
>
> alGenSources(1, &sourceID[0]);
> alGenBuffers(1, &bufferID[0]);
>
> alBufferData(bufferID[0], inputfmt, inputbuffer, sizeof
> (inputbuffer), inputfreq);
> alSourcei(sourceID[0], AL_BUFFER, bufferID[0]);
>
> }
> return();
> }
> ForwardSourceID:NT0002CA5E
>
> _______________________________________________
> openal mailing list
> openal at opensource.creative.com
> http://opensource.creative.com/mailman/listinfo/openal
>
_______________________________________________
openal mailing list
openal at opensource.creative.com
http://opensource.creative.com/mailman/listinfo/openal
ForwardSourceID:NT0002CABA
More information about the Openal
mailing list