[Openal-devel] Need help with clicking sound.

Alfred Hawk hkgi at hotmail.com
Mon Mar 9 14:30:58 PDT 2009








Dear All,

 

I have just started to use openal for sound synthesis and I guess that is what it is made for. I have made a simple program using two buffers, in which a sine wave is generated, in other words a single frequency sound. Now if I change the frequency I hear a clicking sound that is due to the fact when the second buffer is played, it starts playing the waveform from the beginning. I have tried using a single buffer and AL_LOOP function but of no vain. Please see the code below. Is there any way or function in openal that can remove this clicking sound. I have tried changing Sampling frequency but of no vain. 

I am not sure whether it makes any sense or I am going in right direction but I need to remove this clicking sound in order to proceed with sound synthesis.

Cheers,
Alfred







                                                                       ==Code==


// Buffers hold sound data.
ALuint Buffers[2];

// Sources are points of emitting sound.
ALuint Sources;

ALuint Buffersize=50000;

ALint iState;

char data[Buffersize];

char data2[Buffersize];

// Initialize OpenAL and clear the error bit.
    alutInit(NULL, 0);
    alGetError();

//Generating buffers.
    alGenBuffers(2, Buffers);   
                                //'NUM_BUFFERS' is number of buffers that will be generated. 
                               //'Buffers' is pointer to an array of ALuint values that will store the names of new buufers.


    double pi = 3.141592654;
    double freq=1800;                      // frequency
    double sfreq=2000;                    // sampling frequency
    int z;

    for (z=0;z<Buffersize;z++)
    data[z]=50*sin(2*pi*z*freq/sfreq);

    for (z=0;z<Buffersize;z++)
    data2[z]=50*sin(2*pi*freq*(Buffersize+z))/sfreq;

        if (alGetError() != AL_NO_ERROR)
        return AL_FALSE;

// Load wav data into buffers.
    alBufferData(Buffers[0],AL_FORMAT_MONO8,data,sizeof(data),sfreq);
    alBufferData(Buffers[1],AL_FORMAT_MONO8,data2,sizeof(data2),sfreq);

    // Generate a source.
    alGenSources(1, &Sources);

//Bind buffer to the source.
    alSourceQueueBuffers(Sources,2,Buffers);

    if (alGetError()!=AL_NO_ERROR)
        return AL_FALSE;

    alSourceUnqueueBuffers(Sources,2,Buffers);    
 
    alSourcePlay(Sources); 

    alSourcei(Sources,AL_LOOPING,AL_TRUE); 
    
    sleep(10);

_________________________________________________________________
 25GB of FREE Online Storage – Find out more
http://clk.atdmt.com/UKM/go/134665320/direct/01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://opensource.creative.com/pipermail/openal-devel/attachments/20090309/da5b6f3c/attachment.html


More information about the Openal-devel mailing list