Better initial sample rate setup, remove hard-coded default rate and use device info matching /w fallback

This commit is contained in:
Charles J. Cliffe 2015-03-22 20:47:07 -04:00
parent 4147582d2a
commit d5d44b0b30
8 changed files with 86 additions and 12 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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<unsigned int>::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;

View File

@ -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",

View File

@ -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

View File

@ -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()) {

View File

@ -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) {
}

View File

@ -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);