0
$\begingroup$

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?

Thanks.

$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$
    – Hilmar
    Commented Nov 5, 2012 at 22:36
  • 1
    $\begingroup$ 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. $\endgroup$ Commented Nov 5, 2012 at 23:09

1 Answer 1

1
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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