QMediaPlayer wav file playback speed is incorrect (Linux)
-
I'm running Ubuntu server 18.04.0 on a x86 tablet computer.
The manufacturer doesn't support Linux, but I was able to get audio working using the UCM stuff from here and jumping through a few hoops: https://github.com/plbossart/UCMI am running jackd and alsa on the tablet. The jackd seems to be fine, and here is its startup information:
jackd[2149]: creating alsa driver ... hw:chtbswrt5672|-|1024|2|44100|0|0|nomon|swmeter|-|32bit jackd[2149]: configuring for 44100Hz, period = 1024 frames (23.2 ms), buffer = 2 periods jackd[2149]: ALSA: final selected sample format for playback: 24bit little-endian jackd[2149]: ALSA: use 2 periods for playback
And audio seems to work fine via the command line with the aplay command:
aplay /var/ftp/pub/beep.wav Playing WAVE '/var/ftp/pub/beep.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Mono
But, when I play the same wave file using an application that uses QMediaPlayer with this code:
playlist = new QMediaPlaylist(this); playlist->addMedia(QUrl::fromLocalFile("/var/ftp/pub/beep.wav")); playlist->setPlaybackMode(QMediaPlaylist::CurrentItemOnce); player = new QMediaPlayer(this); player->setPlaylist(playlist); playlist->setCurrentIndex(0); player->play();
the sound plays back at the incorrect rate, as I hear a sound which is very high pitched and of a shorter duration.
I'm guessing that the playback rate of the file (44100Hz) isn't being observed, and it's maybe being played back at 48000Hz?If I run this same test program on my laptop, it plays the wav file back with the correct pitch and speed, so it's something that I'm doing on this tablet....
Does QMediaPlayer use the gstreamer stuff on Linux? Here is the package installation status for the gst* packages:
dpkg -l gst* Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-========================-=================-=================-===================================================== un gstreamer1.0-alsa <none> <none> (no description available) un gstreamer1.0-audiosink <none> <none> (no description available) un gstreamer1.0-audiosource <none> <none> (no description available) ii gstreamer1.0-gl:amd64 1.14.5-0ubuntu1~1 amd64 GStreamer plugins for GL un gstreamer1.0-plugins-bad <none> <none> (no description available) ii gstreamer1.0-plugins-bas 1.14.5-0ubuntu1~1 amd64 GStreamer plugins from the "base" set ii gstreamer1.0-plugins-goo 1.14.5-0ubuntu1~1 amd64 GStreamer plugins from the "good" set un gstreamer1.0-plugins-ugl <none> <none> (no description available) ii gstreamer1.0-pulseaudio: 1.14.5-0ubuntu1~1 amd64 GStreamer plugin for PulseAudio un gstreamer1.0-tools <none> <none> (no description available) un gstreamer1.0-videosink <none> <none> (no description available) un gstreamer1.0-videosource <none> <none> (no description available) un gstreamer1.0-visualizati <none> <none> (no description available) ii gstreamer1.0-x:amd64 1.14.5-0ubuntu1~1 amd64 GStreamer plugins for X11 and Pango
Anyone know where my problem is, and if there's a way to get the QMediaPlayer to play the wav file correctly?
Thanks!
-
And to add to my misery....
I converted the wav files in question from 44100Hz to 48000Hz and they still play fast via Qt, but normal from aplay.
-
I have figured out a solution that works for me.
I modified my call to jackd to pass the -S option to the ALSA driver in the jackd line./usr/bin/jackd -d alsa -P hw:chtbswrt5672 -S
Once I did that, the playback speed/pitch is now correct.
Here is what the man page says for the -S option:
-S, --shorts Try to configure card for 16-bit samples first, only trying 32-bits if unsuccessful. Default is to prefer 32-bit samples.