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

resampling #373

Closed
nilsbecker opened this issue Sep 24, 2016 · 13 comments
Closed

resampling #373

nilsbecker opened this issue Sep 24, 2016 · 13 comments

Comments

@nilsbecker
Copy link

I am using a RPi 3 with an i2s sound card to output coax SPDIF to an audio interface which only accepts a fixed sample rate, e.g. 96000. It would be great if shairport-sync could be configured to resample everything to that rate directly using soxr. (instead of going through alsa resampling which is of inferior quality).

@mikebrady
Copy link
Owner

Thanks for the suggestion -- it's a nice idea alright. We will soon have a version that will output exact multiples of 44100 in 8, 16, 24 or 32 bit. It'll take a good deal of work to get a good "true" transcoding system working well though. Also, to get an RPi 3 to be able to do it would require careful programming.

@nilsbecker
Copy link
Author

cool! for me personally, 88.2 would be good enough. i don't know about the synchronization part but at least the pure resampling with soxr from whatever to 88.2 is no problem for the RPi 3; i do that currently for audio coming from mpd.

btw: this is on runeaudio which uses the original shairport afaik. is it possible to use shairport-sync as a drop-in replacement for that?

@mikebrady
Copy link
Owner

mikebrady commented Sep 24, 2016

I'm not sure what the status of it is – it's on their roadmap. If you search for runeaudio and shairport sync you'll get a link to a how-to that a year or so old.

@mikebrady
Copy link
Owner

I've just pushed an updated version of Shairport Sync to the development branch. It has optional 88,200 frames per second output – basically sample replication. It's a bit buggy, but you might like to try it out...

@nilsbecker
Copy link
Author

i'll do when i get to it, thanks! so is sample replication the thing to do here? would some interpolation not be better? (i guess anything you do is in the frequency band above 22.05 kHz but i'm just wondering if replication might be somewhat pathological and could in principle cause nonlinear distortion in the audio band? disclaimer: scientist but not in dsp.)

@mikebrady
Copy link
Owner

mikebrady commented Sep 28, 2016

Cool. I can't see how replication (aka "upsampling") would be pathological, TBH. Pragmatically, many devices will not have the horsepower for interpolation. So, overall, I think replication is the right choice. Of course, I could be wrong!

@nilsbecker
Copy link
Author

yeah, i was just speculating. it seems that replication adds a peak at the new highest (nyquist) frequency, ie. it's concentrated, but far away from the audio band.

@mikebrady
Copy link
Owner

That's interesting. Would you have any references for that – I'd like to follow it up...

@nilsbecker
Copy link
Author

not really - i looked on the internet but did not find much. the wikipedia article about noise shaping has something loosely related. just now i just made some toy signals and looked at the fft of the signal and of it's sample-duplicated version. one way to think about it is this: take the original sampled digital signal and make a corresponding continous analog signal by fourier synthesis. this will contain sine and cosines up to 22.05 kHz that go more or less smoothly through the sampled points. now insert the replicated samples in between. this means every other new sample lags behind the old analog signal. to make a new analog signal that goes also through the new samples, you need higher-frequency sines and cosines. in fact, the waveform you need in addition to the old analog signal should have a period of roughly one old sampling interval. (if you draw it that's roughly what you should see). this is my interpretation for the observation that the fft showed just the new nyquist frequency as extra peak.

@nilsbecker
Copy link
Author

also, i may be wrong! this was just a quick test.

@mikebrady
Copy link
Owner

Many thanks. I'll have a think about it.

@nilsbecker
Copy link
Author

nilsbecker commented Nov 27, 2016

ok, so i have not tried your latest addition -- i did not want to venture into compiling shairport-sync on my runeaudio RPi. but i found another way of dealing with the problem: i finally managed to get an alsa configuration with sample rate conversion working. that uses the speex rate conversion at 'best' settings, which is apparently not bad either and a bit cheaper than libsamplerate. i then point shairport-sync to that alsa device, and that works great now! actually i can use the 'soxr' stuffing method together with that on my RPi 3.

what's a little ugly is that i now have to resamplers chained together... actually, i don't know anything about the internals of shairport-sync; but would it not be possible to just set the output rate of the soxr stuffer to the desired rate?

cheers!

@mikebrady
Copy link
Owner

Thanks for this information. Closing the issue. Please open a new one if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants