Signal Processing Stack Exchange is a question and answer site for practitioners of the art and science of signal, image and video processing. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm developing a singing game and I want to output player's voice through speakers. I'm using portaudio for that, I acquire the input signal and just write it to the output buffer. The problem is the voice is bare audible. I tried to write to output buffer multiplying by a constant but that distorted the voice.

How would I do that?


share|improve this question
What OS and what platform? Inspect incoming samples: if below 10,000 you need to crank up the mic gain. If 10,000 or above make sure all subsequent volume controls are up. – Hilmar Nov 5 '12 at 22:36
10,000? that doesn't mean anything unless you specify, at a minimum, the datatype. The original poster may also not know that you mean to look at absolute values and peaks. Audio data is commonly represented as singed or unsigned 8-bit ints, signed 16-bit ints, signed 20 and 24-bit ints, and 32-bit floats. That's just what's common. You, presumably, meant 16-bit ints, but floats are very common with PortAudio. – Bjorn Roche Nov 5 '12 at 23:09
up vote 1 down vote accepted

The first and best solution is to increase the input gain which should be possible on most platforms. If not, then read on...

If multiplying by a constant caused distortion then either:

  1. it is too loud and distortion is inevitable (barring what I'll just call "fancy" signal processing)
  2. you are doing something wrong.

I'll assume #2 since you started with the case of "barely audible", and you should learn how to apply gain before doing anything "fancy" anyway. To apply gain, make sure you multiply each sample individually by the same constant. Remember that the sample count = frames * channels. Loop through each each sample in the buffer and multiply it by the gain.

For this case, you probably want to use the float datatype in PortAudio, but any type will work.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.