google / oboe

Oboe is a C++ library that makes it easy to build high-performance audio apps on Android.
Apache License 2.0
3.72k stars 571 forks source link

In LiveEffect Sample increase volume like booster from a seekbar #848

Closed ghanimkhan closed 4 years ago

ghanimkhan commented 4 years ago

I want to increase volume from seekbar , not from the audio manager , it's like increasing amplitude or a multiplayer ,idont know how to in LiveEffect Sample echo

philburk commented 4 years ago

Here is a pull request for DrumThumper that uses a slider to modify the gain of an audio signal. https://github.com/google/oboe/pull/825

Basically you convert the slider position to a gain value between 0.0 and 1.0. Then pass that value to the C++ code using JNI. Then multiply every sample value by that gain value before it is output.

The multiply could be done in https://github.com/google/oboe/blob/master/samples/LiveEffect/src/main/cpp/FullDuplexPass.h

But unfortunately that code uses a memcpy() to copy the data between input and output. It would be more helpful if it read each sample from the input and then wrote it to the output. I started a new Issue for that: #852

ghanimkhan commented 4 years ago

`#ifndef SAMPLES_FULLDUPLEXPASS_H

define SAMPLES_FULLDUPLEXPASS_H

include "FullDuplexStream.h"

class FullDuplexPass : public FullDuplexStream { public: virtual oboe::DataCallbackResult onBothStreamsReady(const void inputData, int numInputFrames, void outputData, int numOutputFrames) { size_t bytesPerFrame = this->getOutputStream()->getBytesPerFrame(); size_t bytesToWrite = numInputFrames bytesPerFrame; size_t byteDiff = (numOutputFrames - numInputFrames) bytesPerFrame; size_t bytesToZero = (byteDiff > 0) ? byteDiff : 0; memcpy(outputData, inputData, bytesToWrite); memset((u_char*) outputData + bytesToWrite, 0, bytesToZero); return oboe::DataCallbackResult::Continue; } };

endif //SAMPLES_FULLDUPLEXPASS_H`

I am not able to figure out which value to increase to get the output