cjcliffe / CubicSDR

Cross-Platform Software-Defined Radio Application
http://www.cubicsdr.com
GNU General Public License v2.0
2.07k stars 255 forks source link

SoapySDRPlay support #144

Closed ghost closed 9 years ago

ghost commented 9 years ago

I am trying to get the SDRplay to work on a mac using osmosdr and it just doesn't work. Also i don't expect too much Mac support from the SDRplay guys. They are mainly focussing on Windows. Given that the SDRplay API is public, how much effort would it be to add native support for SDRplay in CubicSDR? I think native support for the trio RTL-SDR (done), AirSpy and SDRplay would make CubicSDR the first SDR application for the "new generation" SDR devices.

In this issue you can find (will be copied to wiki eventually):

Build instructions (OSX): https://github.com/cjcliffe/CubicSDR/issues/144#issuecomment-140906180 Update instructions: https://github.com/cjcliffe/CubicSDR/issues/144#issuecomment-141237861

ghost commented 9 years ago

Log, see here: https://gist.github.com/cjcliffe/09226b6106e30b11bc98

cjcliffe commented 9 years ago

@Toontje it's this line:

[DEBUG] AGC: Gain reduction changed from 40 to -2147483648

That bothers me; that should have been fixed several commits ago.. Can you git pull and run a 'make clean' before your next 'make && sudo make install' to ensure that everything got rebuilt and installed fresh?

cjcliffe commented 9 years ago

@SDRplay excellent thanks; I'll check that out right away -- does 920Mhz that @Toontje is having problems with fall within one of the frequency gaps that weren't supported on Mac yet?

SDRplay commented 9 years ago

@cjcliffe no, the gap was between 250MHz and 420MHz, I've sent you the programming notes. There is also a tip about setting the DCMode after init in there as well.

cjcliffe commented 9 years ago

@SDRplay thanks, just wondered that quickly since it would make sense.. Just installing new bins; going to read up and try to implement that now.

SDRplay commented 9 years ago

@cjcliffe I can also see there is still far too much debug information. Do you have libusb debug turned on as well? I'll get a version of the API with a lot of the debug removed, just leave the static control stuff so you can still see freq and gain changes.

SDRplay commented 9 years ago

@cjcliffe v1.8 of the API released (right now it's just on Mac for testing - www.sdrplay.com/mac.html). Reduced debug messages considerably. Fixed Revision number displayed.

cjcliffe commented 9 years ago

@Toontje I found an uninitialized var that shouldn't have let the new AGC code work properly at all... If I switch off debug mode it behaves exactly as you report here -- I'm making some fixes and updating to 1.8 API lib /w frequency gap fixes -- will have an update in shortly.

cjcliffe commented 9 years ago

@Toontje @dc1rdb @SDRplay -- latest fixes have been pushed for AGC, DC and frequency gap using API 1.7-1.8 from http://sdrplay.com/platforms.html

Working much better here; and 1.8 API log noise is fairly minimal now.

dc1rdb commented 9 years ago

@cjcliffe looking at your latest changes in Streaming.cpp. In line 137

+        gainPrefs.push_back(SDRPlayGainPref(SDRPLAY_LO_120, 1000000000, 200000000, 40, 5, 85));

shouldn't it read 2GHz instead of 200MHz?

cjcliffe commented 9 years ago

@dc1rdb thanks, fixed :)

ghost commented 9 years ago

@cjcliffe When i build SoadySDRplay i use this script:

rm -rf SoapySDRplay
git clone https://user:password@github.com/pothosware/SoapySDRPlay.git
cd SoapySDRPlay
mkdir build
cd build
cmake ../ -DCMAKE_BUILD_TYPE=Release
Make
sudo make install

So i always clone the full source to be sure all is clean before building. When i run this script now i get the following errors:

[ 75%] Building CXX object CMakeFiles/sdrPlaySupport.dir/Streaming.cpp.o
/Users/Ton/SoapySDRPlay/Streaming.cpp:163:5: error: use of undeclared identifier 'mir_sdr_SetParam'; did you mean
      'mir_sdr_SetGrParams'?
    mir_sdr_SetParam(101, activeGainPref->loFreq);
    ^~~~~~~~~~~~~~~~
    mir_sdr_SetGrParams
/opt/local/include/mir_sdr.h:98:36: note: 'mir_sdr_SetGrParams' declared here
   _MIR_SDR_QUALIFIER mir_sdr_ErrT mir_sdr_SetGrParams(int minimumGr, int lnaGrThreshold);
                                   ^
/Users/Ton/SoapySDRPlay/Streaming.cpp:274:9: error: use of undeclared identifier 'mir_sdr_SetParam'; did you mean
      'mir_sdr_SetGrParams'?
        mir_sdr_SetParam(101, activeGainPref->loFreq);
        ^~~~~~~~~~~~~~~~
        mir_sdr_SetGrParams
/opt/local/include/mir_sdr.h:98:36: note: 'mir_sdr_SetGrParams' declared here
   _MIR_SDR_QUALIFIER mir_sdr_ErrT mir_sdr_SetGrParams(int minimumGr, int lnaGrThreshold);
                                   ^
2 errors generated.
make[2]: *** [CMakeFiles/sdrPlaySupport.dir/Streaming.cpp.o] Error 1
make[1]: *** [CMakeFiles/sdrPlaySupport.dir/all] Error 2
make: *** [all] Error 2
[ 25%] Building CXX object CMakeFiles/sdrPlaySupport.dir/Streaming.cpp.o
/Users/Ton/SoapySDRPlay/Streaming.cpp:163:5: error: use of undeclared identifier 'mir_sdr_SetParam'; did you mean
      'mir_sdr_SetGrParams'?
    mir_sdr_SetParam(101, activeGainPref->loFreq);
    ^~~~~~~~~~~~~~~~
    mir_sdr_SetGrParams
/opt/local/include/mir_sdr.h:98:36: note: 'mir_sdr_SetGrParams' declared here
   _MIR_SDR_QUALIFIER mir_sdr_ErrT mir_sdr_SetGrParams(int minimumGr, int lnaGrThreshold);
                                   ^
/Users/Ton/SoapySDRPlay/Streaming.cpp:274:9: error: use of undeclared identifier 'mir_sdr_SetParam'; did you mean
      'mir_sdr_SetGrParams'?
        mir_sdr_SetParam(101, activeGainPref->loFreq);
        ^~~~~~~~~~~~~~~~
        mir_sdr_SetGrParams
/opt/local/include/mir_sdr.h:98:36: note: 'mir_sdr_SetGrParams' declared here
   _MIR_SDR_QUALIFIER mir_sdr_ErrT mir_sdr_SetGrParams(int minimumGr, int lnaGrThreshold);
                                   ^
2 errors generated.
make[2]: *** [CMakeFiles/sdrPlaySupport.dir/Streaming.cpp.o] Error 1
make[1]: *** [CMakeFiles/sdrPlaySupport.dir/all] Error 2
make: *** [all] Error 2
SDRplay commented 9 years ago

mir_sdr_SetParam is an API 1.7+ only function - do you have the right API version?

ghost commented 9 years ago

I just downloaded it, yes. Downloaded file is called mir_sdr_api_MacOSX_1.8.tar.gz I copied the libmir_sdr.so into /usr/lib and mir_sdr.h into /usr/include, then run the build script again. Do i need to do more? Probably create some symlinks somwhere?

SDRplay commented 9 years ago

The Mac API (v1.8) has now been put into an installer just as the Linux installer so they are now called the same and put into the same place (/usr/local/lib and /usr/local/include) - any problems let me know - download it from www.sdrplay.com/mac.html

ghost commented 9 years ago

I downloaded the new installer and i see it installed the .o and .h file in /usr/local/lib and /usr/local/include instead of where i had my files. Also the filenames are different. I still have the errors above. Does that make sense?

Verifying archive integrity... All good.
Uncompressing SDRplay Mirics API Install Package for Mac OSX V1.8  100%  
Installing SDRplay RSP Mirics API library...

Please enter your sudo password if prompted for one.

Architecture: i386
/usr/local/lib/libmirsdrapi-rsp.so
Password:
/usr/local/include/mirsdrapi-rsp.h
Cloning into 'SoapySDRPlay'...
remote: Counting objects: 140, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 140 (delta 2), reused 0 (delta 0), pack-reused 132
Receiving objects: 100% (140/140), 40.57 KiB | 0 bytes/s, done.
Resolving deltas: 100% (91/91), done.
Checking connectivity... done.
-- The CXX compiler identification is AppleClang 7.0.0.7000072
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found libsdrplay: /opt/local/include, /opt/local/lib/libmir_sdr.so
-- LIBSDRPLAY_INCLUDE_DIRS - /opt/local/include
-- LIBSDRPLAY_LIBRARIES - /opt/local/lib/libmir_sdr.so
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Ton/SoapySDRPlay/build
Scanning dependencies of target sdrPlaySupport
[ 25%] Building CXX object CMakeFiles/sdrPlaySupport.dir/Registation.cpp.o
[ 50%] Building CXX object CMakeFiles/sdrPlaySupport.dir/Settings.cpp.o
[ 75%] Building CXX object CMakeFiles/sdrPlaySupport.dir/Streaming.cpp.o
/Users/Ton/SoapySDRPlay/Streaming.cpp:163:5: error: use of undeclared identifier 'mir_sdr_SetParam'; did you mean
      'mir_sdr_SetGrParams'?
    mir_sdr_SetParam(101, activeGainPref->loFreq);
    ^~~~~~~~~~~~~~~~
    mir_sdr_SetGrParams
/opt/local/include/mir_sdr.h:98:36: note: 'mir_sdr_SetGrParams' declared here
   _MIR_SDR_QUALIFIER mir_sdr_ErrT mir_sdr_SetGrParams(int minimumGr, int lnaGrThreshold);
                                   ^
/Users/Ton/SoapySDRPlay/Streaming.cpp:274:9: error: use of undeclared identifier 'mir_sdr_SetParam'; did you mean
      'mir_sdr_SetGrParams'?
        mir_sdr_SetParam(101, activeGainPref->loFreq);
        ^~~~~~~~~~~~~~~~
        mir_sdr_SetGrParams
/opt/local/include/mir_sdr.h:98:36: note: 'mir_sdr_SetGrParams' declared here
   _MIR_SDR_QUALIFIER mir_sdr_ErrT mir_sdr_SetGrParams(int minimumGr, int lnaGrThreshold);
                                   ^
2 errors generated.
make[2]: *** [CMakeFiles/sdrPlaySupport.dir/Streaming.cpp.o] Error 1
make[1]: *** [CMakeFiles/sdrPlaySupport.dir/all] Error 2
make: *** [all] Error 2
[ 25%] Building CXX object CMakeFiles/sdrPlaySupport.dir/Streaming.cpp.o
/Users/Ton/SoapySDRPlay/Streaming.cpp:163:5: error: use of undeclared identifier 'mir_sdr_SetParam'; did you mean
      'mir_sdr_SetGrParams'?
    mir_sdr_SetParam(101, activeGainPref->loFreq);
    ^~~~~~~~~~~~~~~~
    mir_sdr_SetGrParams
/opt/local/include/mir_sdr.h:98:36: note: 'mir_sdr_SetGrParams' declared here
   _MIR_SDR_QUALIFIER mir_sdr_ErrT mir_sdr_SetGrParams(int minimumGr, int lnaGrThreshold);
                                   ^
/Users/Ton/SoapySDRPlay/Streaming.cpp:274:9: error: use of undeclared identifier 'mir_sdr_SetParam'; did you mean
      'mir_sdr_SetGrParams'?
        mir_sdr_SetParam(101, activeGainPref->loFreq);
        ^~~~~~~~~~~~~~~~
        mir_sdr_SetGrParams
/opt/local/include/mir_sdr.h:98:36: note: 'mir_sdr_SetGrParams' declared here
   _MIR_SDR_QUALIFIER mir_sdr_ErrT mir_sdr_SetGrParams(int minimumGr, int lnaGrThreshold);
                                   ^
2 errors generated.
make[2]: *** [CMakeFiles/sdrPlaySupport.dir/Streaming.cpp.o] Error 1
make[1]: *** [CMakeFiles/sdrPlaySupport.dir/all] Error 2
make: *** [all] Error 2
SDRplay commented 9 years ago

@Toontje Yes, sorry about that - it's now consistent with the Linux installer so SoapySDRPlay will need updating to reflect the new installation path and filenames.

ghost commented 9 years ago

Do they know that?

SDRplay commented 9 years ago

Yes, I mentioned that it needed to happen a while ago - the post above from me explains what I've done. @cjcliffe just needs to remove the IF Apple statement... in theory ;-)

ghost commented 9 years ago

I changed every reference to the old files to the new namings and still get a message that the developer files cannot be found. I will wait for the team to fix the files and then try again.

cjcliffe commented 9 years ago

Ah, I built it last night using just the tarball version -- I'll try the installer once I get home and see what needs to change for that.

SDRplay commented 9 years ago

I have it building ok now for Mac - had to make some changes to FindLibSDRplay.cmake and SoapySDRPlay.hpp @cjcliffe I can fork and make those changes if ok with you? However, when I build on Ubuntu lots of warnings and an error (to_string is not a member of std in Settings.cpp:82)

cjcliffe commented 9 years ago

@Toontje @SDRplay @dc1rdb I've made the adjustments for the library file name changes; I've just pushed to SoapySDRPlay now -- I had to clear my cmake cache here to find the new lib at least; @Toontje 's script looks good for making a fresh build though.

@SDRplay I'm wondering if it's possible for you to get it in a more common OSX GUI-friendly installer format such as .pkg? Optionally you can just use Disk Utility to create a small read/write .DMG disk image, copy the script (and perhaps a readme) onto it, set it as executable and set default application to 'Terminal.app' in the file properties. Then run it through Disk Utility again to generate a read-only compressed DMG version from it -- after mounting the DMG and double-clicking the script it'll simply run it in a new Terminal window.

Thanks!

cjcliffe commented 9 years ago

@SDRplay having issues here after removing the 1.7 library files and re-installing the .run file; the libmirsdrapi-rsp-i386-1.8.so still seems to be linked to libmir_sdr.so? This is with latest commit and .run file installed:

######################################################
## Soapy SDR -- the SDR abstraction library
######################################################

Probe device 
SoapySDR::loadModules() dlopen(/usr/local/lib/SoapySDR/modules/libsdrPlaySupport.so) failed: dlopen(/usr/local/lib/SoapySDR/modules/libsdrPlaySupport.so, 1): Library not loaded: libmir_sdr.so
  Referenced from: /usr/local/lib/SoapySDR/modules/libsdrPlaySupport.so
  Reason: image not found
[DEBUG] RTL-SDR Devices: 0
Error probing device: Failed to open AirSpy device (-5) AIRSPY_ERROR_NOT_FOUND

otool reveals:

cjmacbook:lib ccliffe$ otool -L libmirsdrapi-rsp.so 
libmirsdrapi-rsp.so:
    libmir_sdr.so (compatibility version 0.0.0, current version 0.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1225.1.1)
    /usr/local/lib/libusb-1.0.0.dylib (compatibility version 2.0.0, current version 2.0.0)

Looks like it still needs the libmir_sdr.so and apparently that wasn't installed with the .run file? Copying libmir_sdr.so from the 1.7 tarball to /usr/local/lib/ seems to fix it.

SDRplay commented 9 years ago

Sorry my fault, have fixed it and new .run file is on the server

cjcliffe commented 9 years ago

@SDRplay wow that was fast :+1: thanks!

cjcliffe commented 9 years ago

@SDRplay any additional hints on the built-in DC Offset correction? The best I've gotten so far is using mir_sdr_SetDcMode(1, 1); after each init -- but the spike never completely disappears like it does when I turn on the Liquid-DSP DC-blocking IIR filter in CubicSDR

SDRplay commented 9 years ago

@cjcliffe check the email I sent you - it says to use 2,0 after each init - does that work for you?

cjcliffe commented 9 years ago

@SDRplay yup that's where I got the idea -- 1,1 works better here though; the spike bounces a bit more but stays well below the signal level -- with 2,0 it often pushes above the other peaks.

Perhaps I'm introducing a DC offset in my int -> float conversion? I'm dividing the output by 32767.0 as previously discussed but perhaps I need a fraction or offset in there (i.e. add 0.5 to make up for -32768 range on the low side)

I'll try some experiments here to see.

ghost commented 9 years ago

Installed the latest .run from SDRplay.com and ran my build script which pulls down the latest from git and builds it.

Cloning into 'SoapySDRPlay'...
remote: Counting objects: 144, done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 144 (delta 4), reused 0 (delta 0), pack-reused 132
Receiving objects: 100% (144/144), 41.35 KiB | 0 bytes/s, done.
Resolving deltas: 100% (93/93), done.
Checking connectivity... done.
-- The CXX compiler identification is AppleClang 7.0.0.7000072
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found libsdrplay: /usr/local/include, /opt/local/lib/libmirsdrapi-rsp.so
-- LIBSDRPLAY_INCLUDE_DIRS - /usr/local/include
-- LIBSDRPLAY_LIBRARIES - /opt/local/lib/libmirsdrapi-rsp.so
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Ton/SoapySDRPlay/build
Scanning dependencies of target sdrPlaySupport
[ 25%] Building CXX object CMakeFiles/sdrPlaySupport.dir/Registation.cpp.o
[ 50%] Building CXX object CMakeFiles/sdrPlaySupport.dir/Settings.cpp.o
[ 75%] Building CXX object CMakeFiles/sdrPlaySupport.dir/Streaming.cpp.o
[100%] Linking CXX shared module libsdrPlaySupport.so
Undefined symbols for architecture x86_64:
  "_mir_sdr_SetParam", referenced from:
      SoapySDRPlay::activateStream(SoapySDR::Stream*, int, long long, unsigned long) in Streaming.cpp.o
      SoapySDRPlay::readStream(SoapySDR::Stream*, void* const*, unsigned long, int&, long long&, long) in Streaming.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libsdrPlaySupport.so] Error 1
make[1]: *** [CMakeFiles/sdrPlaySupport.dir/all] Error 2
make: *** [all] Error 2
[ 25%] Linking CXX shared module libsdrPlaySupport.so
Undefined symbols for architecture x86_64:
  "_mir_sdr_SetParam", referenced from:
      SoapySDRPlay::activateStream(SoapySDR::Stream*, int, long long, unsigned long) in Streaming.cpp.o
      SoapySDRPlay::readStream(SoapySDR::Stream*, void* const*, unsigned long, int&, long long&, long) in Streaming.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libsdrPlaySupport.so] Error 1
make[1]: *** [CMakeFiles/sdrPlaySupport.dir/all] Error 2
make: *** [all] Error 2
SDRplay commented 9 years ago

I've just done the same and it builds fine for me. For some reason your .so is coming from /opt/local/lib and the SDRplay installer puts it in /usr/local/lib - do you have multiple copies?

SDRplay commented 9 years ago

@cjcliffe adding "-std=c++0x" to CXX_FLAGS enables this to build in Ubuntu for me.

ghost commented 9 years ago

Apparently.

Ton@TM-MBP:/opt/local/lib>ls -al libmir*
-rwxr-xr-x@ 1 root  admin  71876 Sep 11 09:32 libmir_sdr.so
lrwxr-xr-x  1 root  admin     13 Sep 11 09:54 libmirsdrapi-rsp-x86_64-1.1.so -> libmir_sdr.so
lrwxr-xr-x  1 root  admin     13 Sep 11 09:55 libmirsdrapi-rsp.so -> libmir_sdr.so
dc1rdb commented 9 years ago

Latest commit 1b35453fb5 of SoapySDRPlay module together with API v1.8 working flawlessly here.

ghost commented 9 years ago

Same here now.

cjcliffe commented 9 years ago

@dc1rdb @Toontje excellent -- It's very stable here now as well; I've been hopping around between remote and local devices for hours without crashes -- haven't tried the SDRPlay remotely yet though; so that's still on the list :)

On another positive note I've been researching and experimenting with the Liquid FIR polyphase filter-bank channelizer; it's a bit tricky but I'll be able to implement it directly into the SDRPostThread and it should help reduce the amount of CPU used for decimating high-bandwidth inputs and make multiple demodulation streams consume far less CPU.

SDRplay commented 9 years ago

First cut of a Mac pkg for the API installer - please try and let me know what you think... http://www.sdrplay.com/software/SDRplay_RSP_API_Installer_1.8.pkg - could also incorporate SoapySDRPlay to reduce steps required. Let me know what you think

cjcliffe commented 9 years ago

@SDRplay That's exactly what I was looking for; if we can get it to install the SoapySDRPlay binaries and check for libusb too that would be perfect.

SDRplay commented 9 years ago

@cjcliffe ok, on it - did you see my fix for the Linux build?

cjcliffe commented 9 years ago

@SDRplay aye, just haven't had a chance to reboot my desktop back to Debian to test it yet. Will update that when I'm home this evening unless you want to send over a Pull Request before then.

SDRplay commented 9 years ago

@cjcliffe no problem. if I get a chance I'll do that - just wanted to make sure you spotted it :-)

cjcliffe commented 9 years ago

@SDRplay now have it working here on Ubuntu with the latest SoapySDRPlay commits -- thanks.

SDRplay commented 9 years ago

@cjcliffe great, will check it out. I'll add SoapySDRPlay in the next API installer release for testing. From your perspective, what's the best way to deliver biinaries on Linux, now that we have the pkg on Mac, is there an equivalent or is the self extracting script working out ok?

SDRplay commented 9 years ago

@cjcliffe I haven't had a chance to run it yet, but just looked at:

if(HAS_STD_CXX11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") else(HAS_STD_CXX11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")

Isn't that the same check for HAS_STD_CXX11 in IF and ELSE?

ghost commented 9 years ago

Checked out the .pkg Works as expected. Does it check for older version of the drivers and removes them? That was my issue a couple of posts ago. Would be great if the installer checks for that as well.

SDRplay commented 9 years ago

@toontje it removes unwanted SDRplay files from /usr/local but should it also check /opt/local ? Thoughts?

ghost commented 9 years ago

I think it should check against all paths supported by brew and port and the paths in this thread. People who have been following this thread, like myself, might have driver files all over the place.

SDRplay commented 9 years ago

Ok I'll investigate and implement on the next release within the next few days.

cjcliffe commented 9 years ago

@SDRplay CMake IF / ELSE is kinda weird like that, you actually specify the same name of the "logic group" for each part.. so ELSE(HAS_STD_CXX11) just means it's the else case for IF(HAS_STD_CXX11) -- you can actually just leave the subsequent brackets empty to make it less confusing too :)

I think that a .run file works fine for linux installations; though having a .deb version available would be handy but I'm guessing most linux users have opened a terminal at some point :)

cjcliffe commented 9 years ago

@Toontje @dc1rdb I'd be interested to know if https://github.com/cjcliffe/CubicSDR/releases/tag/0.1.8-soapytest performs any better for you than your local builds. I did a local compile of liquid-dsp with fftw-3 integration for this build and it seems to perform a little better here; most notably I can actually demodulate a 12Msps stream..