diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ac988e..eb3c5b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,10 +175,12 @@ IF(USE_AUDIO_PULSE) ENDIF(USE_AUDIO_PULSE) IF(USE_AUDIO_JACK) - SET (OTHER_LIBRARIES ${OTHER_LIBRARIES} jack) + find_package(Jack) + SET (OTHER_LIBRARIES ${OTHER_LIBRARIES} ${JACK_LIBRARIES}) ADD_DEFINITIONS( -D__UNIX_JACK__ ) + include_directories(${JACK_INCLUDE_DIRS}) ENDIF(USE_AUDIO_JACK) IF(USE_AUDIO_ALSA) diff --git a/cmake/Modules/FindJack.cmake b/cmake/Modules/FindJack.cmake new file mode 100644 index 0000000..6d93087 --- /dev/null +++ b/cmake/Modules/FindJack.cmake @@ -0,0 +1,50 @@ +# Try to find JACK +# This will define the following variables: +# +# JACK_FOUND - Whether Jack was found. +# JACK_INCLUDE_DIRS - Jack include directories. +# JACK_LIBRARIES - Jack libraries. + +include(FindPackageHandleStandardArgs) + +if(JACK_LIBRARIES AND JACK_INCLUDE_DIRS) + + # in cache already + set(JACK_FOUND TRUE) + +else() + + find_package(PkgConfig) + if(PKG_CONFIG_FOUND) + pkg_check_modules(_JACK jack) + endif(PKG_CONFIG_FOUND) + + find_path(JACK_INCLUDE_DIR + NAMES + jack/jack.h + PATHS + ${_JACK_INCLUDEDIR} + ) + + find_library(JACK_LIBRARY + NAMES + jack + PATHS + ${_JACK_LIBDIR} + ) + + set(JACK_INCLUDE_DIRS + ${JACK_INCLUDE_DIR} + ) + + set(JACK_LIBRARIES + ${JACK_LIBRARY} + ) + + find_package_handle_standard_args(Jack DEFAULT_MSG JACK_LIBRARIES JACK_INCLUDE_DIRS) + + # show the JACK_INCLUDE_DIRS and JACK_LIBRARIES variables only in the advanced view + mark_as_advanced(JACK_INCLUDE_DIR JACK_LIBRARY JACK_INCLUDE_DIRS JACK_LIBRARIES) + +endif() + diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 0a6d243..d9c4f20 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -164,7 +164,6 @@ wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL) { i++; } - i = 0; for (mdevices_i = outputDevices.begin(); mdevices_i != outputDevices.end(); mdevices_i++) { wxMenuItem *itm = menu->AppendRadioItem(wxID_RT_AUDIO_DEVICE + mdevices_i->first, mdevices_i->second.name, wxT("Description?")); @@ -236,7 +235,30 @@ wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL) { menu = new wxMenu; - i = 0; + + #define NUM_RATES_DEFAULT 4 + int desired_rates[NUM_RATES_DEFAULT] = { 48000, 44100, 96000, 192000 }; + + for (mdevices_i = outputDevices.begin(); mdevices_i != outputDevices.end(); mdevices_i++) { + int desired_rate = 0; + int desired_rank = NUM_RATES_DEFAULT+1; + + for (std::vector::iterator srate = mdevices_i->second.sampleRates.begin(); srate != mdevices_i->second.sampleRates.end(); srate++) { + for (i = 0; i < NUM_RATES_DEFAULT; i++) { + if (desired_rates[i] == (*srate)) { + if (desired_rank > i) { + desired_rank = i; + desired_rate = (*srate); + } + } + } + } + + if (desired_rank > NUM_RATES_DEFAULT) { + desired_rate = mdevices_i->second.sampleRates.back(); + } + AudioThread::deviceSampleRate[mdevices_i->first] = desired_rate; + } for (mdevices_i = outputDevices.begin(); mdevices_i != outputDevices.end(); mdevices_i++) { new wxMenu; @@ -250,8 +272,7 @@ wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL) { srateName << ((float)(*srate)/1000.0f) << "kHz"; wxMenuItem *itm = subMenu->AppendRadioItem(menu_id+j, srateName.str(), wxT("Description?")); - if ((*srate) == DEFAULT_AUDIO_SAMPLE_RATE) { - AudioThread::deviceSampleRate[mdevices_i->first] = DEFAULT_AUDIO_SAMPLE_RATE; + if ((*srate) == AudioThread::deviceSampleRate[mdevices_i->first]) { itm->Check(true); } audioSampleRateMenuItems[menu_id+j] = itm; diff --git a/src/CubicSDR.xpm b/src/CubicSDR.xpm index 3b6f061..a283fb5 100644 --- a/src/CubicSDR.xpm +++ b/src/CubicSDR.xpm @@ -1,5 +1,5 @@ /* XPM */ -static char *cubicsdr_xpm[] = { +static char const *cubicsdr_xpm[] = { /* columns rows colors chars-per-pixel */ "256 256 256 2 ", " c #010101", diff --git a/src/CubicSDRDefs.h b/src/CubicSDRDefs.h index 3614fba..de171dc 100644 --- a/src/CubicSDRDefs.h +++ b/src/CubicSDRDefs.h @@ -42,7 +42,6 @@ const char filePathSeparator = #define DEFAULT_FFT_SIZE 2048 #define DEFAULT_FREQ 100000000 -#define DEFAULT_AUDIO_SAMPLE_RATE 44100 #define DEFAULT_DEMOD_TYPE 1 #define DEFAULT_DEMOD_BW 200000 diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index 654af30..b173123 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -303,8 +303,10 @@ void AudioThread::setupDevice(int deviceId) { if (deviceSampleRate.find(parameters.deviceId) != deviceSampleRate.end()) { sampleRate = deviceSampleRate[parameters.deviceId]; } else { - sampleRate = DEFAULT_AUDIO_SAMPLE_RATE; - deviceSampleRate[parameters.deviceId] = sampleRate; + std::cout << "Error, device sample rate wasn't initialized?" << std::endl; + return; +// sampleRate = AudioThread::getDefaultAudioSampleRate(); +// deviceSampleRate[parameters.deviceId] = sampleRate; } if (deviceController.find(parameters.deviceId) == deviceController.end()) { diff --git a/src/demod/DemodDefs.h b/src/demod/DemodDefs.h index fa1adc0..6282ac0 100644 --- a/src/demod/DemodDefs.h +++ b/src/demod/DemodDefs.h @@ -132,8 +132,8 @@ public: int demodType; DemodulatorThreadParameters() : - frequency(0), sampleRate(DEFAULT_SAMPLE_RATE), bandwidth(200000), audioSampleRate( - DEFAULT_AUDIO_SAMPLE_RATE), demodType(DEMOD_TYPE_FM) { + frequency(0), sampleRate(DEFAULT_SAMPLE_RATE), bandwidth(200000), audioSampleRate(0), + demodType(DEMOD_TYPE_FM) { } diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 1aa70a4..a14f8e2 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -222,7 +222,7 @@ void DemodulatorThread::threadMain() { demodStereoData.resize(bufSize); } - double freq = (2.0 * M_PI) * (((double) abs(38000)) / ((double) inp->sampleRate)); + double freq = (2.0 * M_PI) * ((double) 38000) / ((double) inp->sampleRate); if (stereoShiftFrequency != freq) { nco_crcf_set_frequency(stereoShifter, freq);