1

I'm using oboe library in my app to generate sound. Their example SineGenerator is pretty much exactly what I need, just a simple sine wave that generates a frequency that I need. This generated sine wave is later user in the PlayAudioEngine.

The problem is that more often than not, there's a clicking sound at the beginning or at the end of the audio I play. I play the sounds in short consecutive bursts, usually between 50 - 150ms in length.

I don't really have experience in generating audio waves, so maybe this is just me not seeing something very obvious. I've tried optimizing the performance (compiler flags + code) as suggested in this article but that yielded no results. I've also tried ramping down the amplitude, but no noticeable results.

Any suggestions are appreciated. Thanks!

Stefan
  • 700
  • 10
  • 22
  • 2
    Problems like this are usually due to a phase discontinuity that causes a sharp jump in amplitude, from 0 to `sinf(mPhase) * mAmplitude`. For example, if you reset `mPhase` to 0 before attempting to render the sound, that'll get rid of the click at the start. Then you just have a find a way to _end_ the wave at a phase of 0. – greeble31 Dec 17 '18 at 14:22

1 Answers1

1

A click when starting the oscillator is caused by not resetting the phase in Oscillator::setWaveOn(true) (as mentioned by @greeble31 in comments). It's a simple fix for the "wave on" scenario, just set mPhase to zero.

For "wave off" a solution would be to have a very short ramp down in amplitude rather than just cutting the sound off.

You could do this in Oscillator::renderAudio, however, it'd probably be more flexible to implement a separate Envelope class which can handle the ramp down independently.

donturner
  • 17,867
  • 8
  • 59
  • 81
  • To be fair, this issue could be classed as bug in the samples so if you file an issue (https://github.com/google/oboe/issues/new) I'll try to add an `Envelope` class which would fix it. – donturner Dec 17 '18 at 18:09
  • Thanks for the answer! I didn't have time to try and implement this solution, but will look into this. Thanks again! – Stefan Dec 19 '18 at 14:20