Author Topic: Click, Crackles, Pops, Grr...  (Read 3055 times)

CakeDeath

  • Guest
Click, Crackles, Pops, Grr...
« on: 31 Mar '03 - 02:21 »
I know clicks seem to come up quite a bit, but I've searched these forums a few times with little luck. Any help on the following would be much appreciated...

My Sample is a sine wave. It is played using sample.Play() and it cliks. Fine, that's because it starts playing at full amplitude. I can avoid that.

Add envelope filter so the sine wave fades in and out at the start and end. (Play around between 5mS fade and 50mS fade, using a linear fade, then a parabolic curve fade). Check shaped in Excel, no harsh sharp changes.

Crackles much reduced (almost gone), but they are still there. Play with sine frequency, sample length, resolution, concurrent samples playing number, no help. Samples are never stopped in the middle. Test if they might be overlapping - I don't think they are.

Clicks are irregular and unpredictable, so I don't think they are due to my sample. Try Software mixing flag, change BASS properties like sampling frequency, update sound drivers, change to directX 9.

I can't use a custom stream (I don't know how I would, and they aren't supported yet in nBASS, I think).

Where are these coming from?!  Ack.
They aren't every time the sample is played, don't seem to be always at the start or end, having other sound playing doesn't make any difference...


(WindowsXP, SBLive! Value, C#, nBASS)

Much thanks in advance.

Ingolf

  • Posts: 81
Re: Click, Crackles, Pops, Grr...
« Reply #1 on: 31 Mar '03 - 13:07 »
maybe posting some code here helps?

Ian @ un4seen

  • Administrator
  • Posts: 26083
Re: Click, Crackles, Pops, Grr...
« Reply #2 on: 31 Mar '03 - 18:28 »
Have you made sure that the samples you generate contain exactly a whole number of sine waves? If not, it'll click on looping.

CakeDeath

  • Guest
Re: Click, Crackles, Pops, Grr...
« Reply #3 on: 31 Mar '03 - 19:18 »
They aren't looping samples, but no - there is no whole-number garauntee.

It's quite a lot of code, and as the clicks aren't regular, I wonder if it is the sample(s), but the framework is;
1) create sample of chosen sine wave frequency, sampleRate and length;

Code: [Select]

int volume = 15000;
int numSamples = (int)Math.Ceiling(sampleRate * length);
result = new short[numSamples];
for(int curSample = 0; curSample < numSamples; curSample++) {
   result[curSample] = (short)(volume * Math.Sin(frequency * (curSample * 2.0 * Math.PI / sampleRate)));
}


2) Apply envelope of chosen length in S (0.015s here), to smooth start and end; (The equation is... y = -(aX-b)^2+c which I sort of pulled out of thin air because it makes a nice looking curve).

Code: [Select]

int sampleCount = (int) Math.Ceiling(sampleRate*0.015);
double mult = 1.0 / sampleCount;
     
for (int curSample=0; curSample<sampleCount; curSample++) {
   double y = -(Math.Pow((mult*curSample-1.0),2.0))+1.0;
   result[curSample] = (short) (result[curSample]*y);
   result[result.Length-curSample-1] = (short)(result[result.Length-curSample-1]*y);
}


3) Convert to a Sample;
Code: [Select]

Sample Tone = bass.CreateSample(result, sampleRate, 2, SampleInfoFlags.Mono);


4) Set up a Timer to play the sound every other tick. If the sound is 20mS long, the timer calls every 40mS, etc.
Code: [Select]

Tone.Play();


In this quick test, I got about 8 loud clicks in ~130 plays. (it's a morse code program, so it plays a lot of sounds quite fast).

I'll see if I can cut it down to a simple project to link to later.

Thanks for reading though.