theori-io/nrsc5

Weird audio distortion on not-main channels

Closed this issue · 21 comments

MB6 commented

Hello,
I've compiled nrsc5 on windows, on multiple pcs now, and when I try to tune not-main ie (1-3) subchannels, I get a weird distortion, grainy quality. This does not occur with the sample file. Incompatible transmit mode? This happens on more than one subchannel in my area but not all of them.

Here is a sample. https://mega.nz/file/jp1CQYjB#mCDIBDRvp3UqZIyKop3Zt2fRGqIIBRHRpxhpBv6inTc

64 bit build. I know my way around computers, but programming is not my forte. I'll provide anything else someone might need.

I just noticed this now on a iHeart station subchannel here.

Is this a regression of #212 however it appears that this bug was fixed?

@argilo Any opinion?

It could also be a bug in faad2 or nrsc5's HDC patches. Unfortunately I know very little about the codec; @awesie might have more insight.

I'm also able to reproduce this. It sounds like it's dropping samples to me. Doesn't seem to affect HD-1, only HD-2 and beyond. I did some tests on my machine with the same IQ file. I built on both Windows and Ubuntu 20.02 to see if it was Windows related, but the output audio file matches byte-for-byte on the two platforms.

Here's an example IQ recording. To reproduce, download this file and unzip it. Begin listening to HD-2 by invoking with command nrsc5 -r example_trim 1 (NRSC5 starts subchannels at 0, their usual labels start at 1). After the ad and legal ID, you'll hear a song that has an especially garbled intro. Probably ~10 seconds into the song, press the 0 key to switch to HD-1 and compare it. The same ad will be playing on HD-1 and even that sounds clearer than the HD-2 channel. Once a song begins, it's a night and day difference.

https://drive.google.com/file/d/1DBqvxH8wEjrWa3nGDIFPF5TGWAvQRLhb/view?usp=sharing

Below, I've also uploaded the raw HE-AAC audio data for both HD-1 and HD-2. Note that these won't be playable without the patch in this repo.

KPFX-HD1.aac
KPFX-HD2.aac

I am also able to reproduce this, especially on iHeart subchannels! A station here got dropped to a subchannel. The only way for me to listen to it is on their site or HDRadio 2 subchannel! It sounds terrible listening to it on the hdradio 2 subchannel using this program!
I know nothing about HDC codec. I would've tried to find the issue if I knew about the codec.

Any chance someone with a "real" HD Radio with a digital output could record a station's HD-1 and HD-2 alongside an IQ recording for use with nrsc5? That way we could compare, byte-for-byte, the output of the patched codec to the known-good output of a real radio. Since it's all digital, the outputs from both should match exactly. Unfortunately, my Sony XDR-F1HD only has an analog output so I can't do it myself. Tomorrow I'll get in touch with an engineer friend of mine to see if I could borrow one of his sets with a digital output.

I don't believe that this would be related to the dongle. If this were an analog signal I could believe it, but with a digital signal like this we would be seeing very different problems. The program never loses sync, and all frames check out with their checksum, so we know everything was received correctly. This seems like it's simply a problem with decoding the valid digital information.

Thanks for the response. I understand that it's underlying modulation is analog, but that signal is demodulated into a digital stream. However, we know that step was performed correctly because all of the checksums used to detect errors pass. This guarantees that all of the digital data was successfully received.

Thanks @Roman-Port for the example IQ recording. I think it is likely a problem with the HDC decoding for your example. If you listen to the left and right channels separately, it sounded to me like only one of those channels is distorted. Do you agree?

I suspect this issue is related to your dongle(s) and their ppm rate(s).  I have 3 dongles, two cheap ones by Nooelec and one expensive stick from RTL-SDR.COM.  After measuring the PPM of these 3 sticks using SDR#, the dongle from RTL-SDR.COM had a ppm rate of -1 which is fine but the cheaper dongles from Nooelec had a ppm of -7 and -12 after running for about half an hour.  I recommend using SDR# to measure the ppm of your sticks after they get good and warmed up and then use the -p switch with the nrsc5 exe to see if your problem persists. It should go away as it did with my cheap sticks.

I am using an expensive stick from RTL-SDR.COM.

Thanks @Roman-Port for the example IQ recording. I think it is likely a problem with the HDC decoding for your example. If you listen to the left and right channels separately, it sounded to me like only one of those channels is distorted. Do you agree?

I would agree one of the channels is distorted. When I listen to a subchannel (2-3), it does sound like only one of those channels is distorted.
Though I do want to say that the frequencies I am getting this issue on, the first HD1 channel is 40kbps. I do get a higher bitrate on other stations? Then when I switch to HD2-3, the bitrate goes to 30kbps.

Thanks @Roman-Port for the example IQ recording. I think it is likely a problem with the HDC decoding for your example. If you listen to the left and right channels separately, it sounded to me like only one of those channels is distorted. Do you agree?

I would agree one of the channels is distorted. When I listen to a subchannel (2-3), it does sound like only one of those channels is distorted. Though I do want to say that the frequencies I am getting this issue on, the first HD1 channel is 40kbps. I do get a higher bitrate on other stations? Then when I switch to HD2-3, the bitrate goes to 30kbps.

Yeah, typically the HD2+ stations (referred to as SPS channels) are at a lower data rate than the HD1 channel. However, the same kind of distortion isn't present if I listen using a "real" HD radio like my Sony XDR-F1HD so we know it's a problem on our end.

PPM error in the receiver's oscillator is not a problem for nrsc5, because it compensates for error (within the range of approximately -125 to +125 PPM) and precisely tracks any frequency drift.

If BER values are at or near zero and no checksum errors appear, then the problem almost certainly lies in the HDC decoder.

MB6 commented

Hello! OP here

I'm an audio engineer, I know what AAC+ with SBC compression sounds like. That sound in my initial sample is not it. That does not rule out other people hearing the compression, but I do not that that was my initial problem. What is the problem is the almost clicky/grainy/frame droppy sound, not the bright, sibilant SBC compression artifacts.

#273 fixed this (by disabling the broken Parametric Stereo implementation for now), so I'll close this off.

Here were some observations I noticed in the libfaad2 implementation:

  • The HDC frame length is set at 1,024 samples, which means synthesis works on 2,048 audio samples at a time.
  • The HDC codec in libfaad2 utilized the DRM PS decoder, which works on 30 subsamples of QMF data with 64 QMF channels per subsample, for a total of 30*64 = 1,920 samples.
  • Synthesis produces 2,048 samples, but PS decoding seems to work only with 1,920 samples. This difference seems to be the main culprit of the distortion in the stream when the DRM PS decoder is used.

After decreasing the frame length to 960 so that synthesis works on 1,920 samples at a time, the overall audio quality was much better. However, there were a lot of underruns when streaming live, and the audio sounded sped up as well, probably by (2048/1920 - 1)*100% = 6.67%.

This seems to indicate two things. First, the frame length should be kept at 1,024. Second, a new PS decoder implementation for the HDC codec could be necessary, possibly with QMF constants computed for 2048/64 = 32 subsamples instead of 30. Just my two cents.