Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/audio buffer #105

Merged
merged 31 commits into from
Sep 4, 2024
Merged

Feat/audio buffer #105

merged 31 commits into from
Sep 4, 2024

Conversation

maciejmakowski2003
Copy link
Collaborator

@maciejmakowski2003 maciejmakowski2003 commented Aug 30, 2024

  • Implement AudioBuffer on Android
  • Introduce AudioBuffer to audio processing flow on Android
  • Implement AudioBufferSourceNode on Android
  • Implement getters for channelCount, channelCountMode, channelInterpretation properties of AudioNode on Android
  • Fix HiHat bug on IOS
  • Implement Clap sound

Closes #101
Closes #97
Closes #89

val pan = pan.getValueAtTime(context.getCurrentTime())
val x = (pan + 1) / 2;
val x = (pan + 1) / 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val x = (pan + 1) / 2
val x = (if (pan <= 0) pan + 1 else pan) * PI / 2

Comment on lines 34 to 35
playbackParameters.leftPan *= gainL
playbackParameters.rightPan *= gainR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
playbackParameters.leftPan *= gainL
playbackParameters.rightPan *= gainR
// TODO: This assumes both channels play the same sound (buffer)
// but it should mix the channels. F.e. pan < 0: leftChannel = leftChannel + leftGain * rightChannel
if (pan <= 0) {
playbackParameters.leftPan *= (1+gainL)
playbackParameters.rightPan *= gainR
} else {
playbackParameters.leftPan *= gainL
playbackParameters.rightPan *= (1+gainR)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't find any better source that ppl arguing on online forums, but it seems that:

  • doing a "gain change" on single channel aka left = left * gainL is called balancing
  • doing a "gain change" when mixing the other(s?) channels is called panning

https://www.kvraudio.com/forum/viewtopic.php?t=148865
https://www.reddit.com/r/synthesizers/comments/14fqq4t/whats_the_difference_between_pan_and_balance/


for (int frame = 0; frame < frameCount; frame++) {
double input = bufferL[frame];
// double output = _b0 * input + _b1 * _x1 + _b2 * _x2 - _a1 * _y1 - _a2 * _y2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// double output = _b0 * input + _b1 * _x1 + _b2 * _x2 - _a1 * _y1 - _a2 * _y2;

float *bufferL = (float *)bufferList->mBuffers[0].mData;
float *bufferR = (float *)bufferList->mBuffers[1].mData;

for (int frame = 0; frame < frameCount; frame += 1) {
double pan = [_panParam getValueAtTime:[self.context getCurrentTime]];
double x = (pan + 1) / 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
double x = (pan + 1) / 2;
double x = ((pan <= 0) ? pan + 1 : pan) * M_PI / 2;

Comment on lines 33 to 34
bufferL[frame] *= cos(x * M_PI / 2);
bufferR[frame] *= sin(x * M_PI / 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bufferL[frame] *= cos(x * M_PI / 2);
bufferR[frame] *= sin(x * M_PI / 2);
double gainL = cos(x);
double gainR = sin(x);
if (pan <= 0) {
bufferL[frame] += bufferR[frame] * gainL;
bufferR[frame] *= gainR;
} else {
bufferL[frame] *= gainL;
bufferR[frame] += bufferL * gainR;
}

@michalsek michalsek self-requested a review September 2, 2024 12:30
@maciejmakowski2003 maciejmakowski2003 merged commit fec8936 into main Sep 4, 2024
2 checks passed
@maciejmakowski2003 maciejmakowski2003 deleted the feat/audio-buffer branch September 4, 2024 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants