• Create Account

# 3D sound with SDL_Mixer and convolution with a HRTF

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

No replies to this topic

### #1CruzWoman  Members   -  Reputation: 150

Like
0Likes
Like

Posted 06 November 2012 - 10:13 AM

Hello,

I'm new to SDL and also new to audioprocessing and have problems by generating 3D sound. I'using SDL_Mixer for the sound output and I'm trying to make 3D sound by convolution of a Mix_Chunk with a head related transfer function (HRTF). I tried it by registering an effect and make the convolution with the hrtf in the callback function of the effect. But I got no 3D sound, just the originally sound. Then I tried to make the convolution before playing the sound. I make the convolution of the HRTF directly with the Mix_Chunk->abuf. But when I play the sound, there is only noise...?

Is there a possibility to make 3D sound with my approach at all? I've loaded my wav file in Matlab and compared it with my loaded wav file by using Mix_LoadWav and wrote it in a .txt file. The data is not the same...?

Here's my convolution of the second approach (Mix_Chunk with HRTF):
Mix_Chunk* PlaySDLAudio::makeConvolution(LeftRightHRTF myHRTFs, Mix_Chunk* audioChunk){
short* Y;
short* HL;
short* HR;
int m = audioChunk->alen/2;// ? alen in byte, so /2 because short 16 bit = 2 byte ?
int n = myHRTFs.nTaps;
short* X = (short*)audioChunk->abuf;
HL = new short[n+m];
HR = new short[n+m];
Y = new short[n+m-1];
for( int i = 0 ; i < n; i++ ){
HL[i] = *myHRTFs.leftHRTF;
myHRTFs.leftHRTF++;
HR[i] = *myHRTFs.rightHRTF;
myHRTFs.rightHRTF++;
}
for ( int i = n; i < n+m; i++ ){//fill rest with 0
HL[i] = 0;
HR[i] = 0;
}
//convolution
for ( int i = 0; i < (n+m-1)/2; i++ ) {
Y[i*2] = 0;
Y[i*2+1] = 0;
for ( int j = 0; j < m/2; j++ ) {
if (i-j>=0){
Y[i*2] = Y[i*2] + X[j*2] * HL[i-j];
Y[i*2+1] = Y[i*2+1] + X[j*2+1] * HR[i-j];
}
}
}

Mix_Chunk *wave_chunk;
}
return wave_chunk;
}


I hope that someone has an idea where's my mistake or knows whether my first or second approach is a dead-end road...
Thanks a lot.
Greetings.