Resampling question

I'm using moc from svn and my audio setup is:

moc -> jack @ 96k sample rate -> alsa softvol -> Xonar D2X spdif/coax -> DAC -> hi-fi

I notice that when playing a 44k flac with mplayer the CPU usage is <1% and it doesn't say that it's doing any resampling:

==========================================================================
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
libavcodec version 58.13.102 (internal)
AUDIO: 44100 Hz, 2 ch, s16le, 0.0 kbit/0.00% (ratio: 0->176400)
Selected audio codec: [ffflac] afm: ffmpeg (FFmpeg FLAC audio)
==========================================================================
AO: [jack] 96000Hz 2ch floatle (4 bytes per sample)
[Mixer] No hardware mixing, inserting volume filter.

However it seems that moc will always want to resample and the CPU usage shows
that it's doing that. I don't mind using CPU, but is there a way of not
resampling the audio and playing the file directly to jack as mplayer seems to? I'd
rather not compromise on audio quality by resampling if possible.

Maybe I've got it wrong how mplayer is playing files?

I should add that I've tried ForceSampleRate = 0, 44100, 9600 and just commenting it out.

Recompiling --without-samplerate refuses to play anything (at least with jack set at 96k).

If the audio is at 44kHz and the output is at 96kHz, somewhere along the way some resampling is going to have to be done.

I don't use JACK and haven't paid much attention to its MOC sound driver, but in a quick look it appears to just accept JACK's sample rate and must therefore resample the audio to JACK's requirements. That agrees with what you're seeing from MOC.

I'll have a look at mplayer to see what I can see.

If JACK is set to accept only 96k audio, then there needs to be some resampling done and mplayer (or JACK, I don't know) is probably doing that under the hood. MOC learns from JACK driver that it wants to accept only 96k audio and does the resampling. Regretfully, official MOC version doesn't report detected sample rate in debug output (mocp -D).

Anyway, if MOC is compiled without libsamplerate, it is unable to do the resampling and fails to play the file. As I understand that is expected behaviour. I'm really not sure what your problem with MOC is :) Seems you just shouldn't set your JACK to 96k if you don't want to use that frequency. I suspect that one almost never needs it as it doesn't increase sound quality in any way.

CPU usage depends obviously on the algorithm used for resampling (by default MOC uses quite fast low quality algorithm for resampling). At some point I created a way to use alternative resampling methods in MOC (speex and soxr). If you're feeling adventurous you might try it (https://gitlab.com/tomaszg/mocp/tree/speex) but I didn't test it with JACK.

96k is jackd's output rate. It usually accepts whatever input you give it.

I'll have to look at the moc and mplayer source to see what they do differently I guess.

If jack is resampling it doesn't show any more CPU than mplayer.

Ok, so that definitely means that MOC JACK plugin is buggy (or to be precise - interprets data returned by JACK incorrectly). However, unless you have a reason to believe JACK uses extraordinarily good resampling method, from your point of view it is quite irrelevant who does the resampling. In any case, if playback fidelity is your goal, you should consider setting JACK output to match the audio you want to play.

You can try setting in .moc/config:
ResampleMethod = ZeroOrderHold
and check MOC CPU usage. If mplayer and JACK show really low CPU usage it is a bad sign - means they use very simple resampling method.

I don't know how JACK works, but I found something like this :

https://github.com/jackaudio/jackaudio.github.com/issues/20
http://jack-audio.10948.n7.nabble.com/Resampling-amp-jack-td6164.html

Thanks for those links. So jackd does no resampling. That makes me wonder what mplayer, and the ffflac decoder is doing.

Personally I avoid using the ffmpeg decoder now if I can - using it in moc to play flacs it outputs a constant bitrate, but the flac decoder is variable.

In a comparison of a 44k flac of David Bowie's Life on Mars, ffmpeg sticks at around 815kbps, while flac goes above this, over 1000kbps in places.

I wouldn't worry about reported bitrate. The file has a bitrate regardless of a decoder used. Both decoders in MOC just calculate in other way and some averaging may happen. The decoded stream should be exactly the same. You can try scripts in tools directory which can verify that.

Oh right. I'll check those out. Thanks.

Yeah, I have been setting it at either 44k or 48k to match the source media, but wanted to experiment a bit with seeing how upsampling affects the audio quality.

Lots of discussion on hifi forums about whether it sounds better or worse. Personally, I've always been of the opinion that resampling would be detrimental, and it is better to keep the rate the same as the source media, but some say otherwise.

Whether it sounds better or worse is a subjective thing. It obviously depends on the algorithm and for a good one and good sound system it should sound exactly the same. It can sound better for the same reason why some people claim vinyl sounds better - they like the distortions it introduces :)

Hifi guys usually blatantly ignore biology and math thus displaying a great example of various psychological biases. If you're interested, I recommend this text https://people.xiph.org/~xiphmont/demo/neil-young.html There are even some 96k audio files there to test your system with.

Right, I've seen that page in the past.

I also play vinyls, although I mostly stick to classical music. There is a wamer presence to vinyl in my view, but it depends largely on your setup. I'm not quite devoted enought to spend £1000 on a stylus though :)

Yeah, I have a bunch of vinyls as well and I also use rather moderately priced stuff to play them (I have a Sumiko Pearl cartridge and Monacor pre-amp).

That looks like a nice cartridge. A read a review that it's better for rock/pop than classical though. How do you find it?

I'm thinking of upgrading my shure m97xe. It's OK, but I'm sure there is better out there for classical music. And now Shure have discontinued their phono line I'm finding that stylus prices for those are hiked up a bit.

I like it in the sense that it meets my expectations which are not that high :) I suppose my system is too good for me to be able to really hear the difference. At least I'm not tempted all the time to change something ;) Anyway, any serious hifi guy would get a heart attack if he had seen the cables I used to connect my speakers - just some old pieces of wire from old lamps and irons ;) (because I also believe this guy over the marketing people: http://www.roger-russell.com/wire/wire.htm )

In principle I really don't like those classifications saying that one piece is better for rock, the other for classical - it just mean that they're not working well and are distorting the sound in some way. However I don't hear any problems with my Sumiko even though it is mounted into an old and basic player.

I know what you mean about hype. I have fairly normal speaker wire at the moment, although it is rather thick. If I had to choose speaker wire again I'd probably go for any 2 core mains wire like lamp wire.

I will say though that I once had some crappy phono leads and after I changed them the sound difference was very obvious. The old ones were just plain tinny with no tone at all. Now I tend to use whatever I can get that's fairly thick and wire them myself.