Sign in to follow this  
Concentrate

Question about FFT and audio sample

Recommended Posts

When I get a sample chunk, more specifically, a stream of void* and a length associated with it, for example :
[code]
//usually
void callback(void *stream, int length){
//...
}
[/code]

Supposed the length is 4096 byte, and stream of data supposed to represent a stream of 16 bit data.

I am supposed to split the stream into channels like so :
[source]

//left channel
sampleData[j] = to16Bit(stream[i],stream[i+1])/ scaleFactor;
sampleData[j + 1] =to16Bit(stream[i+2],stream[i+3]) / scaleFactor;
[/source]

Can someone explain to me what these channels are supposed to represent? Also, the sampleData is what I should presumably run FFT on correct?

Share this post


Link to post
Share on other sites
The two samples most likely represent the left and right channel. Don't merge them into a single buffer, just take one of the channels and either ignore the other, or add it to the channel, and do the FFT on that single channel.

Share this post


Link to post
Share on other sites
The left and right channels are the channels going to your left and right speaker. They are two separate audio streams, although you usually play almost the same sound in them. That is why you should not interleave them for the DFT, because your DFT expects a buffer with a single continuous set of data, not two interleaved data sets.

So if you have one DFT and two channels, you must do something; discard one channel or add them are two reasonable options. Another one is to calculate two DFTs; one for each channel.

Share this post


Link to post
Share on other sites
[quote name='Brother Bob' timestamp='1305835249' post='4813161']
The left and right channels are the channels going to your left and right speaker. They are two separate audio streams, although you usually play almost the same sound in them. That is why you should not interleave them for the DFT, because your DFT expects a buffer with a single continuous set of data, not two interleaved data sets.

So if you have one DFT and two channels, you must do something; discard one channel or add them are two reasonable options. Another one is to calculate two DFTs; one for each channel.
[/quote]

Would averaging them two be a viable option? If I sum the two, wouldn't that affect the amplitude or some other property? Thanks.


regards, D.C

Share this post


Link to post
Share on other sites
Averaging and summing are the same, except a linear scale factor. None of them is any more correct than the other, any more than averaging or summing is any more correct than discarding one of the channels or some other method. It's all about what effect you want to achieve.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this