Note that there are some explanatory texts on larger screens.

plurals
  1. POplaying created Audio-Data has noise and periodical clicking in sound
    primarykey
    data
    text
    <p>I write an application, which plays a sound getting from Hardware (like a ring buffer filled with a sinus wave with certain frequency). Everything works fine, and I can playback the created sound correctly except a periodical clicking (maybe at the end of buffer?) and noise.</p> <p>I initialize and run the Buffer:</p> <pre><code>void Audiooutput::InitializeAudioParameters() { Audio_DataWritten = 0; Audio_fragments = 4; Audio_channels = 2; Audio_BufferSize = 256; Audio_Samplerate = 8000; Audio_ResamplingFactor = 1; Audio_Framesize = 2; // (SND_PCM_FORMAT_S16_LE / 8); Audio_frames = Audio_BufferSize / Audio_Framesize * Audio_fragments; snd_pcm_uframes_t size; err = snd_pcm_hw_params_any(pcmPlaybackHandle, hw_params); err = snd_pcm_hw_params_set_rate_resample(pcmPlaybackHandle, hw_params, 1); // qDebug()&lt;&lt;a1.sprintf(" % d \t snd_pcm_hw_params_set_rate: %s",Audio_Samplerate,snd_strerror(err)); err = snd_pcm_hw_params_set_format(pcmPlaybackHandle, hw_params, SND_PCM_FORMAT_S16_LE); err = snd_pcm_hw_params_set_channels(pcmPlaybackHandle, hw_params, Audio_channels); err = snd_pcm_hw_params_set_rate_near(pcmPlaybackHandle, hw_params, &amp;Audio_Samplerate, 0); // qDebug()&lt;&lt;a1.sprintf(" % d \t snd_pcm_hw_params_set_rate: %s",Audio_Samplerate,snd_strerror(err)); if ((err = snd_pcm_hw_params_set_periods_near(pcmPlaybackHandle, hw_params, &amp;Audio_fragments, 0)) &lt; 0) { qDebug() &lt;&lt; a1.sprintf("Error setting # fragments to %d: %s\n", Audio_fragments, snd_strerror(err)); } else qDebug() &lt;&lt; a1.sprintf("setting # fragments to %d: %s\n", Audio_fragments, snd_strerror(err)); err = snd_pcm_hw_params_get_buffer_size(hw_params, &amp;size); if ((err = snd_pcm_hw_params_set_buffer_size_near(pcmPlaybackHandle, hw_params, &amp;Audio_frames)) &lt; 0) { qDebug() &lt;&lt; a1. sprintf("Error setting buffer_size %d frames: %s", Audio_frames, snd_strerror(err)); } else qDebug() &lt;&lt; a1.sprintf("setting Buffersize to %d --&gt; %d: %s\n", Audio_BufferSize, Audio_frames, snd_strerror(err)); Audio_BufferSize = Audio_frames; if ((err = snd_pcm_hw_params(pcmPlaybackHandle, hw_params)) &lt; 0) { qDebug() &lt;&lt; a1.sprintf("Error setting HW params: %s", snd_strerror(err)); } Q_ASSERT(err &gt;= 0); } void Audiooutput::ProduceAudioOutput(int n, int mmodes, int totalMModeGates, short *sinusValue, short *cosinusValue) { for (int audioSample = 0; audioSample &lt; n; audioSample += Audio_ResamplingFactor) { currentposition = (int)(m_Audio.generalPos % (Audio_BufferSize / 2)); if (currentposition == 0) { QueueAudioBuffer(); m_Audio.currentPos = 0; } m_Audio.generalPos++; AudioData[currentposition * 2] = (short)(sinusValue[audioSample]); AudioData[currentposition * 2 + 1] = (short)(cosinusValue[audioSample]); } } void Audiooutput::QueueAudioBuffer() { snd_pcm_prepare(pcmPlaybackHandle); Audio_DataWritten += snd_pcm_writei(pcmPlaybackHandle, AudioData, Audio_BufferSize); } </code></pre> <p>Changing the audiobuffer size or fragments changes also the clicking period. Can anyone help me with this issue ? I checked also the first and Last Values. Thy are always difference. </p> <h2>OS: Ubuntu 11</h2> <p>more detail.</p> <p>the count of received data is dynamically, and changes depend of different parameters. But I play always a certain part e.g. 128 values or 256 or 512....</p> <p>// I get the Audiodata from a hardware (in a Timerloop)</p> <pre><code> audiobuffersize = 256; short *AudioData = new short[256]; int generalAudioSample = 0; void CollectDataFromHw() { ... int n = 0; n = GetData(buf1,buf2);//buf1 = new short[MAX_SHRT] if(n &gt; 0) FillAudioBuffer(n,buf1,buf2) ... } ------------------------------------------- void FillAudioBuffer(int n, short*buf1, short*buf2) { for(int audioSample = 0;audioSample &lt; n; audioSample++){ iCurrentAudioSample = (int)(generalAudioSample % (audiobuffersize/2)); if(iCurrentAudioSample == 0) { snd_pcm_writei(pcmPlaybackHandle,AudioData,audiobuffersize ); memset(AudioData,0x00,audiobuffersize*sizeof(short)); } generalAudioSample++; AudioData[iCurrentAudioSample * 2] = (short)(buf1[audioSample]; AudioData[iCurrentAudioSample * 2 +1] = (short)(buf2[audioSample]; } } </code></pre> <hr> <p>I changed the audiobuffersize also. If I set it to a bigger size, I have some Echo additional to clicks.</p> <p>any Idea ? //----------------------- the Problem is </p> <pre><code>snd_pcm_prepare(pcmPlaybackHandle); </code></pre> <p>every call of this function produce a click in sound !</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload