sdrangel/plugins/samplesource/fcd/fcdsource.cpp

70 wiersze
1.7 KiB
C++
Czysty Zwykły widok Historia

2014-11-30 21:59:06 +00:00
/* (C)2015 John Greb
2014-12-01 19:49:00 +00:00
*
* Funcube Dongle command line interface
* Copyright 2011 David Pello EA1IDZ
* Copyright 2011 Pieter-Tjerk de Boer PA3FWM
* Copyright 2012-2014 Alexandru Csete OZ9AEC
*
2014-11-30 21:59:06 +00:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public Licence version 3.
*/
#include "fcdthread.h"
2014-12-01 19:49:00 +00:00
#include "hid-libusb.h"
#include "qthid.h"
2014-11-30 21:59:06 +00:00
bool FCDThread::OpenSource(const char* cardname)
{
2014-12-01 16:56:27 +00:00
snd_pcm_hw_params_t* params;
2014-11-30 21:59:06 +00:00
//fcd_rate = FCDPP_RATE;
//fcd_channels =2;
//fcd_format = SND_PCM_SFMT_U16_LE;
2014-12-01 16:56:27 +00:00
snd_pcm_stream_t fcd_stream = SND_PCM_STREAM_CAPTURE;
2014-11-30 21:59:06 +00:00
if (fcd_handle)
return false;
2014-12-01 16:56:27 +00:00
if ( snd_pcm_open( &fcd_handle, cardname, fcd_stream, 0 ) < 0 )
2014-11-30 21:59:06 +00:00
return false;
2014-12-01 16:56:27 +00:00
snd_pcm_hw_params_alloca(&params);
if ( snd_pcm_hw_params_any(fcd_handle, params) < 0 )
qCritical("Funcube Dongle read settings failed");
else if ( snd_pcm_hw_params(fcd_handle, params) < 0 )
qCritical("Funcube Dongle write settings failed");
// TODO: check actual samplerate, may be crippled firmware
if ( snd_pcm_start(fcd_handle) < 0 )
qCritical("Funcube Dongle stream start failed");
else qDebug("Funcube stream started");
2014-11-30 21:59:06 +00:00
return true;
}
void FCDThread::CloseSource()
{
if (fcd_handle)
snd_pcm_close( fcd_handle );
fcd_handle = NULL;
}
void FCDThread::set_center_freq(double freq)
{
2014-12-01 19:49:00 +00:00
if (fcdAppSetFreq(freq) == FCD_MODE_NONE)
qCritical("No FCD HID found for frquency change");
2014-11-30 21:59:06 +00:00
}
2014-12-01 16:56:27 +00:00
int FCDThread::work(int n_items)
2014-11-30 21:59:06 +00:00
{
int l;
SampleVector::iterator it;
void *out;
it = m_convertBuffer.begin();
out = (void *)&it[0];
2014-12-01 16:56:27 +00:00
l = snd_pcm_mmap_readi(fcd_handle, out, (snd_pcm_uframes_t)n_items);
2014-11-30 21:59:06 +00:00
if (l > 0)
m_sampleFifo->write(it, it + l);
2014-12-01 16:56:27 +00:00
return l;
2014-11-30 21:59:06 +00:00
}