RE: Simple filtering in realtime - again...
Daniel PEACOCK <[email protected]>
| Newsgroups | gmane.comp.lib.openal |
|---|---|
| Message-ID | <OF26A86795.9AFCAD9E-ON8825770B.0051576E-8025770B.0054E19D@cli.creaf.com> |
I'm assuming that Buffer is defined as an array of shorts, you are
capturing 16bit stereo, and therefore lBlockAlignment is 4, is that right?
BUFFERSIZE appears to be the size in bytes of the captured audio. So,
BUFFERSIZE / 2 is the number of Samples, and BUFFERSIZE / 4 is the number
of samples on each channel (i.e the number of 'blocks' or 'frames').
Assuming you want to capture 16bit stereo data, and you only want the left
channel data converted to floats. I think you need something like this ...
#define BUFFERSIZE 1024 // Bytes
ALshort Buffer[BUFFERSIZE/2]; // Samples (left + right channel samples)
ALfloat flOutputSamples[BUFFERSIZE/4]; // Output Samples (only left channel
is kept)
// capture samples here ...
for (i = 0; i < BUFFERSIZE/4; i++)
flOutputSamples[i] = Buffer[i*2]/32768.0f;
Notice that you only have BUFFERSIZE/4 samples now.
To convert it back to shorts to pass to alBufferData ...
for (i = 0; i < BUFFERSIZE/4; i++)
Buffer[i] = (ALshort)(flOutputSamples[i]*32767.0f);
NOTE : You should really add a check to make sure that flOutputSample[i]
is within -1.0 to +1.0 of else you may get clamping - which will sound bad.
I would try and solve this problem one step at a time. e.g. confirm
capturing and playback are working, then add the conversion to float and
back to short, and then finally apply your filter.
Dan
Creative Labs (UK) Ltd.
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.
Creative Labs UK Ltd company number 2658256 registered in England and Wales
at 79 Knightsbridge, London SW1X 7RB
Carlos Alberto
Hernández
<karlonchiz@hotma To
il.com> <[email protected]>,
<[email protected]>
20/04/2010 15:34 cc
Subject
RE: [Openal] Simple filtering in
realtime - again...
Thank you Dan, but I'm afraid that didn't work. I think there's something
wrong with de casting, but I'm not very sure what is it, or how to fix it.
Subject: Re: [Openal] Simple filtering in realtime - again...
To: [email protected]; [email protected]
From: [email protected]
Date: Tue, 20 Apr 2010 09:38:40 +0100
I think this line is wrong ...
entport[i]=float((Buffer[2*i])/32768);
because you are doing an integer division and then casting the result to a
float. It should be something like ...
entport[i]=Buffer[2*i]/32768.0f;
Dan
Creative Labs (UK) Ltd.
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.
Creative Labs UK Ltd company number 2658256 registered in England and Wales
at 79 Knightsbridge, London SW1X 7RB
(Embedded image moved to file: pic18467.gif)Inactive hide details for
Fruskus <[email protected]>Fruskus <[email protected]>
Fruskus
<karlonchiz@hotmail.
com> (Embedded image moved to
Sent by: file: pic06334.gif)
openal-bounces@opens To
ource.creative.com (Embedded image
19/04/2010 10:41 moved to file:
pic26500.gif)
[email protected]
eative.com
(Embedded image moved to
file: pic19169.gif)
cc
(Embedded image
moved to file:
pic15724.gif)
(Embedded image moved to
file: pic11478.gif)
Subject
(Embedded image
moved to file:
pic29358.gif)
[Openal] Simple
filtering in
realtime - again...
(Embedded image moved to
file: pic26962.gif)
(Embedded image moved
to file:
pic24464.gif)
Hi,
I keep working on my realtime app.
I've been trying to find the cause of the troubles I had, but I'm still
stuck.
I'm testing now a simple DC blocking filter (just a high pass filter); it
seems to work in terms of frequency, but it adds a very loud constant
noise.
Here's a piece of the code - the rest of the main code is the
capture-playback routine with queue- :
...
alcCaptureSamples(pCaptureDevice, Buffer,BUFFERSIZE / lBlockAlignment);
// This part is for separating left-right channels
int i;
for(i=0;i<BUFFERSIZE/2;i++){
entport[i]=float((Buffer[2*i])/32768); // entport: input signal - left
channel
//right channel not needed right now
}
DCfilter(entport,portnodc,BUFFERSIZE/2); // portnodc: input signal no dc
for(i=0;i<BUFFERSIZE/2;i++){
BufferSalida[i]=ALshort(32767*portnodc.y[i]); // BufferSalida: Output
buffer
}
// Attaching data to buffer
alBufferData(BufferID[ulQueueCount], PlayFormat, BufferSalida,
BUFFERSIZE/2,
lFrequency);
...
----------------------------------------
void DCfilter(samplesvector &x, nodctype &y, int size){
int i;
float a=0.995;
for (i=0;i<size;i++){
y.y[i]=x[i]-(y.xdcant)+(a*y.ydcant); //xdcant, ydcant: previous signal
values.
y.xdcant=x[i];
y.ydcant=y.y[i];
}
}
----------------------------------------
where:
typedef float samplesvector[BUFFERSIZE/2];
typedef struct {
samplesvector y;
float xdcant;
float ydcant;
}nodctype;
----------------------------------------
I'm a little bit overwhelmed about not being able to make this work, so,
any
help will be appreciated.
Any ideas?
Thanks in advance.
--
View this message in context:
http://old.nabble.com/Simple-filtering-in-realtime---again...-tp28287632p28287632.html
Sent from the OpenAL - User mailing list archive at Nabble.com.
_______________________________________________
Openal mailing list
[email protected]
http://opensource.creative.com/mailman/listinfo/openal
ForwardSourceID:NT0007A2DE
Tus datos personales, más seguros con Internet Explorer 8. ¡Descárgatelo
gratis!(See attached file: pic09514.gif)
ForwardSourceID:NT0007A376
_______________________________________________
Openal mailing list
[email protected]
http://opensource.creative.com/mailman/listinfo/openal
pic18467.gif
(image/gif, 105 B) - not displayed
pic06334.gif
(image/gif, 45 B) - not displayed
pic26500.gif
(image/gif, 45 B) - not displayed
pic19169.gif
(image/gif, 45 B) - not displayed
pic15724.gif
(image/gif, 45 B) - not displayed
pic11478.gif
(image/gif, 45 B) - not displayed
pic29358.gif
(image/gif, 45 B) - not displayed
pic26962.gif
(image/gif, 45 B) - not displayed
pic24464.gif
(image/gif, 45 B) - not displayed
pic09514.gif
(image/gif, 1.2 KB) - not displayed