RE: Simple filtering in realtime - again...

Carlos Alberto Hernández <[email protected]>
Newsgroups gmane.comp.lib.openal
Message-ID <[email protected]>

You are right, I'm capturing 16bit stereo data. I separate channels in order to use them later as a carrier and modulator each one. But for the testing I'm only keeping the left channel. 

lBlockAlignment is 4. BUFFERSIZE is 1764, and it's the number of samples in the stereo signal. 

 

When removing the DCfilter, capturing and playing are working fine, even using the conversion, just like this:

 

for(i=0;i<BUFFERSIZE/2;i++){

entport[i]=Buffer[2*i];

entport[i]=entport[i]/32768.0f;

} 

 



//DCfilter(entport,portnodc,BUFFERSIZE/2);





for(i=0;i<BUFFERSIZE/2;i++){

BufferSalida[i]=ALshort(32767*entport[i]); //Output buffer
}

 

And it sounds good, no noise, and more or less good latency.

 

I have something in mind: in wich way does OpenAL sort the data when retrieved, in the array? Could this be a problem when filtering?

 

And again, thanks.

 





Subject: RE: [Openal] Simple filtering in realtime - again...
To: [email protected]
CC: [email protected]
From: [email protected]
Date: Tue, 20 Apr 2010 08:27:08 -0700



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 <[email protected]>










Carlos Alberto Hernández <[email protected]> 
20/04/2010 15:34







To

<[email protected]>, <[email protected]>



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 

Fruskus <[email protected]>













Fruskus <[email protected]> 
Sent by: [email protected] 19/04/2010 10:41





To

[email protected]


cc



Subject

[Openal] Simple filtering in realtime - again...






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:NT0007A376 
 		 	   		  
_________________________________________________________________
Aprende los trucos de Windows 7 con la gente que ya lo han probado Windows 7.
http://www.sietesunpueblodeexpertos.com/index_windows7.html

_______________________________________________
Openal mailing list
[email protected]
http://opensource.creative.com/mailman/listinfo/openal
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.