badaix / snapdroid

Snapcast client for Android
GNU General Public License v3.0
135 stars 26 forks source link

snapclient.so not connecting with correct format #68

Open whatamesss opened 3 months ago

whatamesss commented 3 months ago

hello! love snapcast! my mpd server and snapserver are both running on linux with format 9600:24:2 (tried 32-bit as well) the problem is, on android, the snapclient is not playing with the right format. where is the the config for the client?

from my process list: libsnapclient.so -h io -p 1704 --hostID 0e2bcfe3-5d26-477d-a516-a3f035b0cb88 --player oboe --sampleformat 96000:16: --logfilter :info,Stats:debug

in the pursuit of bit-perfect audio, i've tried several android devices and some do have crippled audio engines (typcally 24/48) but not the one i'm using in this case. i read that snapclient uses oboe and open sl/es as a backend but using poweramp i was able to see that it had acutally selected the audiotrack backend. i have changed this (using poweramp) to open sl/es with float capability and the audio chain seems to respect 24/96 all the way through now...however the snapcast client still doesnt respect 24-bit or 32-bit float audio.

this is a bug! please help!

as a feature request i'd also love to see snapserver respect whatever source format is preseneted by mpd. mpd as the ability to set the format as ::* which would completely disable resampling (exactaly what i'm looking for) but unfortunately snapserver does not accept this as a format setting...

(edit to mention that i'm using an external dac via usb) best j

whatamesss commented 3 months ago

more info....i was able to find libsnapclient.so in my android device...and run it manually with the format 96000/24/* it only outputs noise.

and i can confirm that snapclient on linux connects to my snapserver and recognizes/correctly plays the format 96000/24/2

it seems there's a problem with the android client

here is the shell output from running it manually on android 12. again, the audio output is just noise.

/libsnapclient.so -h io -p 1704 --hostID 0e2bcfe3-5d26-477d-a516-a3f035b0cb88 --player oboe --sampleformat 96000:24: --logfilter :info,Stats:debug < 2024-06-25 09-41-39.896 [Info] (Snapclient) Version 0.28.0 2024-06-25 09-41-39.897 [Info] (Connection) Resolving host IP for: io 2024-06-25 09-41-39.905 [Info] (Connection) Connecting to 10.10.10.10:1704 2024-06-25 09-41-39.917 [Notice] (Connection) Connected to 10.10.10.10 2024-06-25 09-41-39.918 [Info] (Connection) My MAC: "c4:4e:ac:e6:95:e4", socket: 7 2024-06-25 09-41-39.927 [Info] (Controller) ServerSettings - buffer: 750, latency: 0, volume: 100, muted: 0 2024-06-25 09-41-39.932 [Info] (Controller) Codec: flac, sampleformat: 96000:24:2 2024-06-25 09-41-39.933 [Info] (Player) Player name: oboe, device: default, description: , idx: -1, sharing mode: shared, parameters: 2024-06-25 09-41-39.933 [Info] (Player) Mixer mode: software, parameters: 2024-06-25 09-41-39.933 [Info] (Player) Sampleformat: 96000:24:0, stream: 96000:24:2 2024-06-25 09-41-39.933 [Info] (OboePlayer) Init start 2024-06-25 09-41-39.933 [Info] (OboePlayer) DefaultStreamValues::SampleRate: 48000, DefaultStreamValues::FramesPerBurst: 192 2024-06-25 09-41-39.951 [Info] (OboePlayer) AudioApi: AAudio 2024-06-25 09-41-39.952 [Info] (OboePlayer) BufferSizeInFrames: 5766, FramesPerBurst: 1922 2024-06-25 09-41-39.952 [Info] (OboePlayer) Init done 2024-06-25 09-41-39.952 [Info] (OboePlayer) Start 2024-06-25 09-41-39.958 [Info] (Stream) No chunks available 2024-06-25 09-41-40.309 [Info] (Controller) diff to server [ms]: 7.35386e+07 2024-06-25 09-41-40.539 [Debug] (Stats) Chunk: 0 0 0 0 1 118 0 2024-06-25 09-41-41.018 [Debug] (Stats) Chunk: 0 0 0 0 40 99 0 2024-06-25 09-41-42.018 [Debug] (Stats) Chunk: 0 0 0 0 127 99 0 2024-06-25 09-41-43.018 [Debug] (Stats) Chunk: 0 0 0 0 213 99 0 2024-06-25 09-41-44.018 [Debug] (Stats) Chunk: 1 0 0 0 300 99 0 ^C2024-06-25 09-41-44.905 [Info] (Snapclient) Received signal 2: Interrupt 2024-06-25 09-41-44.906 [Info] (OboePlayer) Stop

whatamesss commented 3 months ago

found more options to the client...but they dont seem to be working

(set mixer none and sharing mode exclusive) result=noise "OboePlayer) DefaultStreamValues::SampleRate: 48000"=wrong

bcfe3-5d26-477d-a516-a3f035b0cb88 --player oboe --mixer none --sharingmode exclusive --sampleformat 96000:24: --logfilter :info,Stats:debug < 2024-06-25 09-55-00.004 [Info] (Snapclient) Version 0.28.0 2024-06-25 09-55-00.005 [Info] (Connection) Resolving host IP for: io 2024-06-25 09-55-00.017 [Info] (Connection) Connecting to 10.10.10.10:1704 2024-06-25 09-55-00.025 [Notice] (Connection) Connected to 10.10.10.10 2024-06-25 09-55-00.025 [Info] (Connection) My MAC: "c4:4e:ac:e6:95:e4", socket: 7 2024-06-25 09-55-00.036 [Info] (Controller) ServerSettings - buffer: 750, latency: 0, volume: 100, muted: 0 2024-06-25 09-55-00.041 [Info] (Controller) Codec: flac, sampleformat: 96000:24:2 2024-06-25 09-55-00.041 [Info] (Player) Player name: oboe, device: default, description: , idx: -1, sharing mode: exclusive, parameters: 2024-06-25 09-55-00.041 [Info] (Player) Mixer mode: none, parameters: 2024-06-25 09-55-00.042 [Info] (Player) Sampleformat: 96000:24:0, stream: 96000:24:2 2024-06-25 09-55-00.042 [Info] (OboePlayer) Init start 2024-06-25 09-55-00.042 [Info] (OboePlayer) DefaultStreamValues::SampleRate: 48000, DefaultStreamValues::FramesPerBurst: 192 2024-06-25 09-55-00.056 [Info] (OboePlayer) AudioApi: AAudio 2024-06-25 09-55-00.057 [Info] (OboePlayer) BufferSizeInFrames: 5766, FramesPerBurst: 1922 2024-06-25 09-55-00.057 [Info] (OboePlayer) Init done 2024-06-25 09-55-00.057 [Info] (OboePlayer) Start 2024-06-25 09-55-00.058 [Info] (Stream) No chunks available 2024-06-25 09-55-00.293 [Info] (Controller) diff to server [ms]: 7.35386e+07 2024-06-25 09-55-01.002 [Debug] (Stats) Chunk: 0 0 0 0 29 98 0 2024-06-25 09-55-02.002 [Debug] (Stats) Chunk: 0 0 0 0 115 98 0 2024-06-25 09-55-03.002 [Debug] (Stats) Chunk: 0 0 0 0 202 98 0 ^C2024-06-25 09-55-03.104 [Info] (Snapclient) Received signal 2: Interrupt 2024-06-25 09-55-03.105 [Info] (OboePlayer) Stop 2024-06-25 09-55-03.131 [Notice] (Snapclient) Snapclient terminated.

using --player opensl (much prefered!) result=snapclient fails

bcfe3-5d26-477d-a516-a3f035b0cb88 --player opensl --mixer none --sharingmode exclusive --sampleformat 96000:24: --logfilter :info,Stats:debug < 2024-06-25 09-55-17.005 [Info] (Snapclient) Version 0.28.0 2024-06-25 09-55-17.006 [Info] (Connection) Resolving host IP for: io 2024-06-25 09-55-17.020 [Info] (Connection) Connecting to 10.10.10.10:1704 2024-06-25 09-55-17.025 [Notice] (Connection) Connected to 10.10.10.10 2024-06-25 09-55-17.026 [Info] (Connection) My MAC: "c4:4e:ac:e6:95:e4", socket: 7 2024-06-25 09-55-17.029 [Info] (Controller) ServerSettings - buffer: 750, latency: 0, volume: 100, muted: 0 2024-06-25 09-55-17.029 [Info] (Controller) Codec: flac, sampleformat: 96000:24:2 2024-06-25 09-55-17.030 [Info] (Player) Player name: opensl, device: default, description: , idx: -1, sharing mode: exclusive, parameters: 2024-06-25 09-55-17.030 [Info] (Player) Mixer mode: none, parameters: 2024-06-25 09-55-17.030 [Info] (Player) Sampleformat: 96000:24:0, stream: 96000:24:2 2024-06-25 09-55-17.030 [Info] (OpenSlPlayer) Init start 2024-06-25 09-55-17.030 [Info] (OpenSlPlayer) frames: 4800, channels: 2, rate: 96000, buff: 38400 2024-06-25 09-55-17.032 [Fatal] (Snapclient) Exception: Init failed, operation: Engine::CreateAudioPlayer, result: SL_RESULT_CONTENT_UNSUPPORTED(9) 2024-06-25 09-55-17.032 [Notice] (Snapclient) Snapclient terminated.

badaix commented 3 months ago

This code snipped looks suspicious (client/player/oboe_player.cpp):

    auto result = builder.setSharingMode(sharing_mode)
                      ->setPerformanceMode(oboe::PerformanceMode::None)
                      ->setChannelCount(stream_->getFormat().channels())
                      ->setSampleRate(stream_->getFormat().rate())
                      ->setFormat(oboe::AudioFormat::I16)
                      ->setDataCallback(this)
                      ->setErrorCallback(this)
                      ->setDirection(oboe::Direction::Output)
                      //->setFramesPerCallback((8 * stream->getFormat().rate) / 1000)
                      //->setFramesPerCallback(2 * oboe::DefaultStreamValues::FramesPerBurst)
                      //->setFramesPerCallback(960) // 2*192)
                      ->openStream(out_stream_);

It seems to set the bit depth to 16 bit: setFormat(oboe::AudioFormat::I16)

whatamesss commented 3 months ago

i do believe you've identified the 16-bit issue....i'd love to submit a PR but unfortunately i'm not a coder....is it something you can fix?

whatamesss commented 2 months ago

Hello again Johannes, i see you may have a fix in your development branch ...any chance of a release soon? i'm forced to use http streaming for the meantime with poweramp...(because i am testing some hi-res dacs)

cheers

badaix commented 2 months ago

I don't know yet when I will do the next release, but you can install the build artifact: https://github.com/badaix/snapdroid/actions/runs/9731928937

Snapdroid and Snapcast will now support 16, 24 and 32 bit audio, but will use the sample rate, given by AudioManager::PROPERTY_OUTPUT_SAMPLE_RATE, as documented here: https://developer.android.com/reference/android/media/AudioManager.html#PROPERTY_OUTPUT_SAMPLE_RATE and here: https://google.github.io/oboe/classoboe_1_1_default_stream_values.html

I've also tested to query the "native" sample rate of the device with getHardwareSampleRate, which returns the same sample rate as the audio manager. There is also a setting in Oboe, which sample rate quality to apply for internal resampling. Since this internal resampling will have impact on the latency estimation, Snapcast will continue doing the resampling into the native hardware rate, so that Oboe must not apply further resampling.

whatamesss commented 2 months ago

i'm unable to run the server now (linux) which i build from your master..it gives a floating point exception

badaix commented 2 months ago

Master is 1.5 years old, try develop, which is the default branch