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

Reuse iter approch #47

Merged
merged 9 commits into from
Jan 10, 2025
Merged

Conversation

wiiznokes
Copy link
Contributor

Hi and Happy new year,

This pr reuse the previous Streamer trait approach with an "iter".

I tested

  • Adb
  • Tcp via Adb
  • Udp via Adb doesn't works, but it may be expected. I can't test it rn but it should work.
  • Usb: works but still not very user friendly

For the USB part, i had to debug multiple things. I added some info in the readme that i think is the same problem of #45.

  • It worked perfectly for some time, then i try to disable aoa on the phone, and impossible to repass the phone in aoa latter. I had to enable/disable ADB for this to reworks.
  • we should find a solution to detect all phones
  • There was also a bug Android side related to automatically starting the app when aoa is connected

Except that, the AsyncReader approach for usb looks very clean. The audio wave looks nice, and more optimized than mine (Android mic is at 0% on my pc). I wonder how this is possible. The scale is perhaps a little too small, at least on my setup, but it's a detail.

@teamclouday
Copy link
Owner

Hi thanks for the PR!

Yes I agree iter is better. The pattern of using mutex with arc was messy and it has no good impact on the performance. I initially switched to it from iter because I was using rusb which requires maintaining a global context for the connection. But later I changed to nusb and the requirement no longer exists. Thanks for changing it back.

Udp via Adb doesn't works, but it may be expected. I can't test it rn but it should work.

For tcp and udp, I think both of them were designed to connect through the local internet, so if the phone and laptop are under the same wifi environment, they should be able to find each other. So they don't have to go through adb. Also adb reverse proxy only supports tcp as far as I know.

we should find a solution to detect all phones

It's a little tricky because the device connection doesn't have a category for the device, and phones are usually identified by unique IDs set by the manufacturers. However, I've seen a code pattern that they send the "start accessory" command to all USB devices, and only the android devices will respond. In that case there's no need to identify phones by vendor names ourselves.

It worked perfectly for some time, then i try to disable aoa on the phone, and impossible to repass the phone in aoa latter. I had to enable/disable ADB for this to reworks.

Right this is a little annoying. What I've learned is that USB communication is one channel, and it's a little different based on OS. Windows only allows one program to take over the USB, so if adb is using it, aoa won't work with the phone. On mac or linux it's different so the adb can keep running. What I have been doing is to set phone to charging only mode, shutdown adb server, close the mobile app, and then start aoa which will reopen the app after confirmation. But I agree it's not user friendly.

Except that, the AsyncReader approach for usb looks very clean. The audio wave looks nice, and more optimized than mine (Android mic is at 0% on my pc). I wonder how this is possible. The scale is perhaps a little too small, at least on my setup, but it's a detail.

Thanks! Yep I learned how to use canvas from this clock example. Apparently there are games written with canvas so it can run super fast.
For the scale, maybe consider changing the window size here:

let window_size = 50;

It's probably better to dynamically compute this value based on sample rate and sample size. For example, 48k 24bit will carry more data than 44.1k 8bit in each frame, so the window size should be larger in that case.

@wiiznokes wiiznokes mentioned this pull request Jan 10, 2025
@teamclouday teamclouday merged commit ead15ce into teamclouday:main Jan 10, 2025
@wiiznokes wiiznokes deleted the reuse-iter-approch branch January 10, 2025 14:25
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.

2 participants