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

Android: Use common CBuffer instead of custom RingBuffer #1528

Closed
wants to merge 6 commits into from

Conversation

j-santander
Copy link
Contributor

A couple of changes to the android code:

  • When I did my first round of modifications to the already existing android code, I needed some decoupling between receiving samples from the network and copying it to the oboe output buffers. To support that I brought a RingBuffer class without realizing there was already one in the common code (CBuffer class in buffer.h). Later I realized there were some mistakes in my ring buffer... so now I've taken the opportunity to remove it and use the common CBuffer instead.
  • Not sure why we were configuring oboe to use float samples. I believe I recall that at that time there was an ongoing effort to move to float everywhere. That change seems to not have been merged yet, so I've simplified the float to int16_t and int16_t to float code by simply configuring oboe to use int16_t samples.

I've verified the build on my terminal (Google Pixel 3a)

Copy link
Member

@ann0see ann0see left a comment

Choose a reason for hiding this comment

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

Thank you! Didn't check it logic wise, but please have a look at the styling.

static_cast<int16_t>(floatData[frmNum * oboeStream->getChannelCount() + channelNum] * _MAXSHORT);
}
}
memcpy(vecsTmpInputAudioSndCrdStereo.data(),floatData,sizeof(int16_t)*numFrames * oboeStream->getChannelCount());
Copy link
Member

Choose a reason for hiding this comment

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

I think the style is not correct here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, is there a .clang-format I can use? I believe I saw something in the issues/discussions but I don't know if it finally materialized.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it's here: https://github.com/jamulussoftware/jamulus/pull/1127/files#diff-1026e0038b722990204a42bed8a6f7c0ec2302aa79e3fad1959d62ba968edfa2

It's still not merged and done for existing code yet, but new code can certainly be run through this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, new commit after applying .clang-format as indicated by @hoffie
Thanks

", SampleRate: " << sSampleRate <<
", AudioFormat: " << sAudioFormat <<
", FramesPerCallback: " << sFramesPerCallback << "]";
qInfo() << "Stream details: [sDirection: " << sDirection << ", FramesPerBurst: " << sFramesPerBurst << ", BufferSizeInFrames: " << sBufferSizeInFrames
Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, this is a good test for the .clang-format. The width is just a little too high - this exceeds Github's unified diff frame width.


return iOboeBufferSizeMono;
}

// This is the main callback method for when an audio stream is ready to publish data to an output stream
// or has received data on an input stream. As per manual much be very careful not to do anything in this back that
// can cause delays such as sleeping, file processing, allocate memory, etc.
oboe::DataCallbackResult CSound::onAudioReady ( oboe::AudioStream* oboeStream,
Copy link
Collaborator

Choose a reason for hiding this comment

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

And I guess this is one of the things we may have to live with going with the .clang-format.

@pljones
Copy link
Collaborator

pljones commented Apr 25, 2021

@sthenos - as you did the original Android work, is there a chance you could review this, please?

Looks okay to me but I've no Android knowledge.

@pljones
Copy link
Collaborator

pljones commented Jun 26, 2021

OK, one more question raised in the code - but it's probably an example showing clearly someone who knows Android (i.e. not me!) needs to review this.

@j-santander
Copy link
Contributor Author

j-santander commented Jun 26, 2021 via email

@pljones
Copy link
Collaborator

pljones commented Jun 26, 2021

Thanks. It may have been as you say when the original Android branch was taken - it's not that long since Jamulus switched from int to float.

... and I could even be wrong! (I try to avoid the low-level audio stuff as much as I try to avoid the low-level network stuff: break those and you're not jamming :) )

@j-santander
Copy link
Contributor Author

j-santander commented Jun 26, 2021 via email

@j-santander
Copy link
Contributor Author

Oh, well, I'm puzzled.

I see that on soundbase.h there's still

void ProcessCallback ( CVector<int16_t>& psData )

That, I believe, still indicates that (at least the input) is still expected to be int16_t data, not float.

I see that the Issue #544 was closed and the related PR #535 and #627 were merged on a separate branch (no longer active). In PR #660 it is mentioned that a previous attempt (#535) had to be reverted and this PR was closed with

The branch https://github.com/corrados/jamulus/tree/integrate_float2 is already in the Jamulus Git repo. So there is no need for a Pull Request here. As soon as I continue working on that topic, I'll update the branch and simply merge the code into the Git master branch. I'll close this Pull Request therefore now.

So.... I'd say that the change to float never happened.

@pljones
Copy link
Collaborator

pljones commented Jun 27, 2021

So.... I'd say that the change to float never happened.

Thanks for checking (and no wonder I was confused by the sound of it!).

@ann0see
Copy link
Member

ann0see commented Nov 3, 2021

@j-santander @pljones What's missing here?

@pljones
Copy link
Collaborator

pljones commented Nov 3, 2021

Thanks for pinging me on this -- as it reminds me again that we're not yet float. At some point that work needs to be completed. But that's for a different time..!

In terms of review: it needs someone who knows the Android audio subsystem and how to do Android development to comment on it.

@ann0see
Copy link
Member

ann0see commented Jan 2, 2022

@sthenos - as you did the original Android work, is there a chance you could review this, please?

It would be really great if someone with android knowledge could move this forward.

@sthenos
Copy link
Contributor

sthenos commented Jan 2, 2022 via email

@softins
Copy link
Member

softins commented Jan 10, 2022

Thanks for pinging me on this -- as it reminds me again that we're not yet float. At some point that work needs to be completed. But that's for a different time..!

The float work that was done was specifically in the mixing (CServer::MixEncodeTransmitData()), in order to avoid potential 16-bit overflow when summing channels. Volker's original commit to do this was 9c5a779, where he starting using an intermediate buffer of double instead of summing directly into the int16 output buffer. Using double was probably overkill, and there was a subsequent accepted commit 9171caa from HPS changing it from double to float.

Once the final sum of the samples was calculated, it then was converted back to int16 when writing to the output buffer.

Of course, the protocol audio data is Opus encoded, so the remaining question would be whether it is possible/better/worse to get the uncompressed audio in and out of Opus in float or int16 format. But as said above, that is for another discussion, not this PR.

@softins softins self-assigned this Jan 12, 2022
@softins
Copy link
Member

softins commented Jan 13, 2022

I have squashed this into a single commit from the branch point, and included a necessary fix to Jamulus.pro, in my own repo at https://github.com/softins/jamulus/tree/android-update. I retained @j-santander as author of the commit.

I will get it rebased to the current master and submit it as a new PR from my branch, to replace this PR.

Marking this PR as draft in the meantime.

@softins softins marked this pull request as draft January 13, 2022 13:09
@softins softins mentioned this pull request Jan 13, 2022
5 tasks
softins added a commit that referenced this pull request Jan 13, 2022
@pljones pljones added this to the Release 3.8.2 milestone Feb 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants