superpoweredSDK / Low-Latency-Android-iOS-Linux-Windows-tvOS-macOS-Interactive-Audio-Platform

🇸Superpowered Audio, Networking and Cryptographics SDKs. High performance and cross platform on Android, iOS, macOS, tvOS, Linux, Windows and modern web browsers.
https://superpowered.com
1.34k stars 285 forks source link

sound crackling throught USB #388

Closed MolchanovDmitry closed 6 years ago

MolchanovDmitry commented 6 years ago

Good day. I have some problem with sound quality. Songs sound like from gramophone with specific crackling.

I play sound with code below: SuperpoweredUSBAudio::getBestIO (devID, &inputIOindex, &outputIOindex, 44100, 16, 2, 2, true); SuperpoweredUSBAudio::startIO(devID, inputIOindex, outputIOindex, SuperpoweredUSBLatency_High, this, audioProcessingUsb);

Also tried with: SuperpoweredUSBAudio::easyIO(deviceID, 44100, 16, 0, 256, SuperpoweredUSBLatency_Low, this, audioProcessing)

There is no reason for crackling: processUsb(float *output, unsigned int numberOfSamples) {
audioRecorder->process(output, NULL, numberOfSamples);
bool silence = audioPlayer->process(output, false, numberOfSamples);
return silence;}

By the way I route sound throught USB and standard android music players play songs clearly. Also tried to play with arguments, but without result.

Can I get some advice? Thanks you!

superpoweredSDK commented 6 years ago

Does this happen with a specific USB audio device only?

MolchanovDmitry commented 6 years ago

Now I have checked with other device. The same result.

superpoweredSDK commented 6 years ago

Please let me know your phone model, Android version and the USB audio device models.

MolchanovDmitry commented 6 years ago

Mag410(SmartTV), Android 6.0.1. USB audio device - UGM96.

MolchanovDmitry commented 6 years ago

Is USB IO buffer size limited by 512 ? Can I put 1024, for example?

DanNi0130 commented 6 years ago

I am having this issue as well. On an LG G4 device, I get crackling when the app goes into the background. Increasing the buffer size did not help.

superpoweredSDK commented 6 years ago

you need to enable sustained performance mode with the SuperpoweredCPU class

MolchanovDmitry commented 6 years ago

We use it already: void SuperpoweredRenderer::onPlayPause(bool play, bool record) { if (!play) { audioPlayer->pause(); } else { audioPlayer->play(false); }; SuperpoweredCPU::setSustainedPerformanceMode(play); // <-- Important to prevent audio dropouts. }

DanNi0130 commented 6 years ago

@MolchanovDmitry I fixed this by setting the samplerate and buffersize dynamically, from the HLSExample:

if (Build.VERSION.SDK_INT >= 17) { AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE); samplerateString = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE); buffersizeString = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER); } if (samplerateString == null) samplerateString = "44100"; if (buffersizeString == null) buffersizeString = "512";

See if that works for you.

MolchanovDmitry commented 6 years ago

@DanNi0130 Thanks you. But your code applied with SuperpoweredAndroidAudioIO. But I have crackling with USB IO only.

DanNi0130 commented 6 years ago

Oh sorry, good luck with your problem!

superpoweredSDK commented 6 years ago

Can you test with another Android device, not the smart tv?