• Advertisement
Sign in to follow this  

3D sound with SDL_Mixer and convolution with a HRTF

This topic is 1901 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


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;
HR[i] = *myHRTFs.rightHRTF;
for ( int i = n; i < n+m; i++ ){//fill rest with 0
HL[i] = 0;
HR[i] = 0;
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];

//load result in new Mix_Chunk
Mix_Chunk *wave_chunk;
if(!(wave_chunk=Mix_QuickLoad_RAW((Uint8*)Y,m+n))) {
printf("Mix_QuickLoad_WAV: %s\n", Mix_GetError());// handle error
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement