Menu

14-line fix for xHE-AAC decoding

KiwiSDR
2020-01-12
2021-03-22
1 2 > >> (Page 1 of 2)
  • KiwiSDR

    KiwiSDR - 2020-01-12

    Hi all.
    Here's a fix to get the xHE superframe interface working using the FDK xHE-AAC codec. I can't actually build Dream here due to Qt issues, but the fix is working with the KiwiSDR port of the Dream code. To test go to kiwisdr.com/public, bring up any Kiwi running v1.370 or later, click DRM mode, then click the "Test 2" button. A sample file recorded from Bengaluru, India will be looped (621 kHz AM MW, mode A, 9 kHz).

    I think these should be all the required changes if someone wants to try them with Dream:

    Index: src/MSC/xheaacsuperframe.cpp
    ===================================================================
    --- src/MSC/xheaacsuperframe.cpp    (revision 1338)
    +++ src/MSC/xheaacsuperframe.cpp    (working copy)
    @@ -109,8 +109,8 @@
                 break;
             default: // boundary in this superframe
                 borders[0] += start;
    -            if(borders[0]<2) return false;
    -            borders[0] -= 2; // header not in payload
    +            //if(borders[0]<2) return false;
    +            //borders[0] -= 2; // header not in payload
                 frameSize[0] = borders[0];
                 //cerr << "border 0 is " << borders[0] << " bytes from start of payload" << endl;
                 break;
    @@ -117,12 +117,17 @@
             }
             for(unsigned i=1; i<borders.size(); i++) {
                 borders[i] += start;
    -            borders[i] -= 2; // header not in payload
    +            //borders[i] -= 2; // header not in payload
                 unsigned bytes = borders[i]-borders[i-1];
                 frameSize[i] = bytes;
                 //cerr << "border " << i << " is " << borders[i] << " bytes from start of payload" << endl;
             }
    +    } else {
    +        // frameBorderCount == 0: spans entire ASF payload or bad data in header
    +        audioFrame.resize(0);
    +        return ok;
         }
    +    
         size_t bytesInFrames = 0; for(size_t i=0; i<frameSize.size(); i++) bytesInFrames+=frameSize[i];
         size_t next = payload.size()-bytesInFrames;
         //cerr << "payload is " << payload.size() << " bytes of which " << bytesInFrames << " are for this superframe and " << next << " are for the next superframe" << endl;
    Index: src/sourcedecoders/AudioSourceDecoder.cpp
    ===================================================================
    --- src/sourcedecoders/AudioSourceDecoder.cpp   (revision 1338)
    +++ src/sourcedecoders/AudioSourceDecoder.cpp   (working copy)
    @@ -356,6 +356,7 @@
             /* Since we do not do Mode E or correct for sample rate offsets here (yet), we do not
                have to consider larger buffers. An audio frame always corresponds to 400 ms */
             iMaxLenResamplerOutput = int(_REAL(outputSampleRate) * 0.4 /* 400ms */  * 2 /* for stereo */ );
    +        iMaxLenResamplerOutput *= 2;    // to prevent buffer overruns with xHE-AAC (as detected by clang asan)
    
             if(inputSampleRate != outputSampleRate) {
                 _REAL rRatio = _REAL(outputSampleRate) / _REAL(inputSampleRate);
    @@ -364,7 +365,11 @@
                 ResampleObjR.Init(iLenDecOutPerChan, rRatio);
             }
    
    -        int iResOutBlockSize = outputSampleRate * iLenDecOutPerChan / inputSampleRate;
    +        int iResOutBlockSize;
    +        if (inputSampleRate == 0)
    +            iResOutBlockSize = iLenDecOutPerChan;
    +        else
    +            iResOutBlockSize = outputSampleRate * iLenDecOutPerChan / inputSampleRate;
    
             //cerr << "output block size per channel " << iResOutBlockSize << " = samples " << iLenDecOutPerChan << " * " << Parameters.GetAudSampleRate() << " / " << iAudioSampleRate << endl;
    

    Regards,
    John, ZL/KF6VO
    KiwiSDR

     
  • zhongfanyang

    zhongfanyang - 2020-01-12

    Hi, John. Did you get the decoded audio produced properly?

    Months ago, when I attempted to use the FDK source on the test file, frame decoder always spitted out either "AAC_DEC_PARSE_ERROR" or "AAC_DECODE_UNKNOWN" error flag, even when frame CRC is OK.

    zhongfanyang

     
  • Chris Mackerell

    Chris Mackerell - 2020-01-12

    The KiwiSDR test decoding works fine on my own KiwiSDRs. I just wish the Dream developers had as much enthusiasm as the KiwiSDR team do at the moment!

     
    • zhongfanyang

      zhongfanyang - 2020-01-12

      Thanks for you speedy response. After I make the necessary patch to the source code as you provided, I DO succeed decoding xHE-AAC frames, FINALLY! Again really appreciated for your contribution to the Dream project.

       
  • Tarmo Tanilsoo

    Tarmo Tanilsoo - 2020-01-12

    Hello all.

    I can report success under Linux as well. In addition to patches above, I had to modify dream.pro (for fdk-aac to be discovered under Linux) src/sourcedecoders/fdk_aac_codec.cpp (to get rid of "no codec found" error for xHE-AAC codec).

    What is the very latest version of the code? Quite possible the additional tweaks I had to do are already in the newest code but if not, I am more than happy to contribute.

     

    Last edit: Tarmo Tanilsoo 2020-01-12
  • KiwiSDR

    KiwiSDR - 2020-01-12

    @Tarmo I just do a svn checkout http://svn.code.sf.net/p/drm/code/dream to get the latest sources (at svn-1338 currently I think). The latest Kiwi version is always at https://github.com/jks-prv/Beagle_SDR_GPS/tree/master/extensions/DRM/dream But it's difficult to diff that against Dream as I've been removing all the unrelated stuff (e.g. Qt) to simplify things.

     

    Last edit: KiwiSDR 2020-01-12
    • Tarmo Tanilsoo

      Tarmo Tanilsoo - 2020-01-12

      Thanks. Here are the additional changes that I had to do get the latest SVN code to work on my Kubuntu machine.

      Index: dream.pro
      ===================================================================
      --- dream.pro   (revision 1338)
      +++ dream.pro   (working copy)
      @@ -153,6 +153,9 @@
       }
       linux-* {
         LIBS += -ldl -lrt
      +  packagesExist(fdk-aac) {
      +     CONFIG += fdk-aac
      +  }
         contains(QT,multimedia) {
          CONFIG += sound
         }
      Index: src/sound/drm_pulseaudio.cpp
      ===================================================================
      --- src/sound/drm_pulseaudio.cpp    (revision 1338)
      +++ src/sound/drm_pulseaudio.cpp    (working copy)
      @@ -810,6 +810,7 @@
      
              /* Close the previous input */
              Close_HW();
      +        
      
              /* Open the new input */
              Init_HW();
      @@ -822,6 +823,9 @@
                  /* Save buffer size */
                  iBufferSize = iNewBufferSize;
      
      +            if(pa_s == nullptr) {
      +           Init_HW();
      +            }
                  /* Set buffer size */
                  SetBufferSize_HW();
              }
      Index: src/sourcedecoders/fdk_aac_codec.cpp
      ===================================================================
      --- src/sourcedecoders/fdk_aac_codec.cpp    (revision 1338)
      +++ src/sourcedecoders/fdk_aac_codec.cpp    (working copy)
      @@ -86,12 +86,10 @@
               }
               return true;
           }
      -#ifdef HAVE_USAC
           if(eAudioCoding == CAudioParam::AC_xHE_AAC) {
               if((linfo.flags & CAPF_AAC_USAC) != 0)
                   return true;
           }
      -#endif
           return false;
       }
      

      Your mileage may vary.

       
      • KiwiSDR

        KiwiSDR - 2020-01-12

        Thanks. I forgot about HAVE_USAC. Because it appears in two other places in that file, one of which is likely important, I would suggest adding the define to the project file. But I can't build Dream with Qt so I don't know if this actually works. But I think it should:

        Index: dream.pro
        ===================================================================
        --- dream.pro   (revision 1338)
        +++ dream.pro   (working copy)
        @@ -303,7 +303,7 @@
           }
         }
         fdk-aac {
        -     DEFINES += HAVE_LIBFDK_AAC
        +     DEFINES += HAVE_LIBFDK_AAC HAVE_USAC
              LIBS += -lfdk-aac
              HEADERS += src/sourcedecoders/fdk_aac_codec.h
              SOURCES += src/sourcedecoders/fdk_aac_codec.cpp
        
         
        • Tarmo Tanilsoo

          Tarmo Tanilsoo - 2020-01-12

          Just recompiled with restored #ifdef HAVE_USAC, and modified dream.pro. Looks to work indeed. Although I can't seem to hear any higher frequencies that one would expect from SBR. That at least on the New Delhi test file I've been using.

           
          • Tarmo Tanilsoo

            Tarmo Tanilsoo - 2020-01-13

            I have now identified why I was only hearing low frequencies despite SBR and the Decoded audio spectrum only went to 4 kHz. Dream.ini for some reason set the audio output sample rate to 8 kHz, and changing it from the Sound card settings menu had no effect. For now, the fix would be to change a line in Dream.ini from

            samplerateaud=8000
            

            to

            samplerateaud=48000
            
             

            Last edit: Tarmo Tanilsoo 2020-01-13
  • Peter Whisker

    Peter Whisker - 2020-02-05

    Thank you for these patches - I applied them to the latest git and managed to receive my first live transmission - from Voice of Nigeria on 13675 kHz on Sunday afternoon around 1615 UTC. This transmission was not on any of the lists I had. It was 9.1kbps AAC mono but quite strong here in the UK. I piped from gqrx via Pulse Audio. :-) My PC was running Debian Bullseye (testing) plus the multimedia distro which gives fdk-aac v2.

     

    Last edit: Peter Whisker 2020-02-05
  • Julian Cable

    Julian Cable - 2020-02-05

    Thats amazing!!! I'll try and find some time on Sunday to review and adopt this into the system. Thanks everyone!

     
  • Zygmunt Skrobanski

    Having problems compiling Revision 1339 using Ubuntu 18.04.4 LTS

    Trying to build and after running:

    qmake - result is OK

    make - the following problem apparently with src/resample/speexresampler.cpp

    In file included from src/resample/speexresampler.cpp:1:0:
    src/resample/speexresampler.h:4:10: fatal error: speex/speex_resampler.h: No such file or directory
    #include <speex speex_resampler.h="">
    ^~~~~~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    Makefile:5316: recipe for target 'obj/speexresampler.o' failed
    make: *** [obj/speexresampler.o] Error 1</speex>

    Can anybody help me out?

    Many thanks,

    -Zyg-

     

    Last edit: Zygmunt Skrobanski 2020-02-15
    • Chris Mackerell

      Chris Mackerell - 2020-02-15

      From one of Jayson's earlier emails:

      Also I had to add libspeex-dev and libspeexdsp-dev.

      Happy compiling!

      Cheers, Chris

      On 2020-02-15 15:39, Zygmunt Skrobanski wrote:

      Having problems compiling Revision 1339 using Ubuntu 18.04.4 LTS

      Trying to build and after running:

      qmake - result is OK

      make - the following problem apparently with
      src/resample/speexresampler.cpp

      In file included from src/resample/speexresampler.cpp:1:0:
      src/resample/speexresampler.h:4:10:fatal error:speex/speex_resampler.h:No such file or directory
      #include <speex speex_resampler.h="">
      ^~~~~~~~~~~~~~~~~~~~~~~~~
      compilation terminated.
      Makefile:5316:recipe for target 'obj/speexresampler.o' failed
      make:*** [obj/speexresampler.o]Error 1</speex>

      Can anybody help me out?

      Many thanks,

      -Zyg-


      14-line fix for xHE-AAC decoding
      https://sourceforge.net/p/drm/discussion/general/thread/01c6e64c3b/?limit=25#689c


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/drm/discussion/general/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

      --
      Chris Mackerell, Sandy Bay-Marahau Road, Marahau
      RD 2, Motueka 7197, New Zealand chris@owdjim.gen.nz

       
    • Rafael Diniz

      Rafael Diniz - 2020-02-15

      Read the error:
      speex/speex_resampler.h: No such file or directory

      So install the missing dependency. In a Debian based system, do:

      sudo apt-get install libspeex-dev libspeexdsp-dev

      Rafael

      On 2/15/20 12:39 AM, Zygmunt Skrobanski wrote:

      Having problems compiling Revision 1339 using Ubuntu 18.04.4 LTS

      Trying to build and after running:

      qmake - result is OK

      make - the following problem apparently with
      src/resample/speexresampler.cpp

      In file included from src/resample/speexresampler.cpp:1:0:
      src/resample/speexresampler.h:4:10: fatal error: speex/speex_resampler.h: No such file or directory
      #include <speex speex_resampler.h="">
      ^~~~~~~~~~~~~~~~~~~~~~~~~
      compilation terminated.
      Makefile:5316: recipe for target 'obj/speexresampler.o' failed
      make: *** [obj/speexresampler.o] Error 1</speex>

      Can anybody help me out?

      Many thanks,

      -Zyg-


      14-line fix for xHE-AAC decoding
      https://sourceforge.net/p/drm/discussion/general/thread/01c6e64c3b/?limit=25#689c


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/drm/discussion/general/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       
  • Zygmunt Skrobanski

    Hi Chris,

    Unfortunately I don't think adding those files will help in this case. There is an apparent error in not recognizing the file speexresampler.cpp. Particularly since I did not touch anything within that particular folder.

    -Zyg-

     
    • Tarmo Tanilsoo

      Tarmo Tanilsoo - 2020-02-15

      These are packages, not files. I am also using 18.04 LTS, and I was able to compile. Install these two packages with apt and then try again.

       
  • Jayson Bucknell

    Jayson Bucknell - 2020-02-15

    Hi, all. I put together a script that might simplify installing in Ubuntu. There's also basic instructions for installing WSL with sound when running in Windows 10. It shouldn't make too much of a mess hopefully. Enjoy! (Thanks Rafael)

    https://github.com/keyboarderror/DreamBuild

     
  • Zygmunt Skrobanski

    Tarmo, Rafael, and Chris:

    Thank you for the help it is very much appreciated!. My only excuse is that I'm a beginner with Linux.

    By adding sudo apt-get install libspeex-dev libspeexdsp-dev the error problem went away!

    Now I have to do some more work:

    zygmunt@OptiPlex-7010:~/dream$ sudo cp dream /usr/local/bin/dream
    zygmunt@OptiPlex-7010:~/dream$ dream
    Got FAAD2 library
    No usable FAAC aac encoder library found
    Got Opus library
    dummy: _init called

    This was followed by a whole lot of rig_register lines

    Thanks again,

    -Zyg-

     
  • Zygmunt Skrobanski

    Why is it that "No usable FAAC aac encoder library found" when it is meant to be decoding not encoding?

    I'm probably missing something that is obvious to everybody else.

     
  • Zygmunt Skrobanski

    Progress...

    Well I've got it working, sort of, the DRM Main screen shows up but the program slows down on the Ubuntu Terminal and doesn't come to an end.

    The Dream program does receive the VOA signal, at a 21 dB SNR, but shows that there is no codec. So the XHe-AAC decoding is not yet functional.

    A situation akin to the operation was a success but the patient died!

    Being an infrequent Linux user I'm still battling elementary stuff. I recently set up this computer to force myself to get better aquainted with this OS.

    Any help will continue to be greatly appreciated!

    -Zyg-

     
  • Zygmunt Skrobanski

    Hi Rafael,

    Did you installed fdk-aac 2?

    Apparently no - I thought it was part of the SVN package. I notice that that there are a number of packages located in "Helper Files" on the Dream Receiver page. Do I need to install it seperately?

    From which svn Dream branch you are compiling?

    The one from the main Source Forge Dream DRM receiver site.

    Thank you again for your help,

    -Zyg-

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.