correct discrepancy between number of samples and number of bytes in blocks of samples

related to #346
This commit is contained in:
Michael Ossmann
2017-02-16 12:46:17 -07:00
parent 6aacfa2cc9
commit 79f95abdb3
4 changed files with 21 additions and 20 deletions

View File

@ -47,11 +47,11 @@ static enum sweep_style style = LINEAR;
usb_request_status_t usb_vendor_request_init_sweep( usb_request_status_t usb_vendor_request_init_sweep(
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
{ {
uint32_t num_samples; uint32_t num_bytes;
int i; int i;
if (stage == USB_TRANSFER_STAGE_SETUP) { if (stage == USB_TRANSFER_STAGE_SETUP) {
num_samples = (endpoint->setup.index << 16) | endpoint->setup.value; num_bytes = (endpoint->setup.index << 16) | endpoint->setup.value;
dwell_blocks = num_samples / 0x4000; dwell_blocks = num_bytes / 0x4000;
if(1 > dwell_blocks) { if(1 > dwell_blocks) {
return USB_REQUEST_STATUS_STALL; return USB_REQUEST_STATUS_STALL;
} }

View File

@ -98,7 +98,7 @@ int gettimeofday(struct timeval *tv, void* ignored) {
#define TUNE_STEP (DEFAULT_SAMPLE_RATE_HZ / FREQ_ONE_MHZ) #define TUNE_STEP (DEFAULT_SAMPLE_RATE_HZ / FREQ_ONE_MHZ)
#define OFFSET 7500000 #define OFFSET 7500000
#define DEFAULT_SAMPLE_COUNT 0x4000 #define DEFAULT_SAMPLE_COUNT 0x2000
#define BLOCKS_PER_TRANSFER 16 #define BLOCKS_PER_TRANSFER 16
#if defined _WIN32 #if defined _WIN32
@ -219,23 +219,23 @@ int rx_callback(hackrf_transfer* transfer) {
| ((uint64_t)(ubuf[6]) << 32) | ((uint64_t)(ubuf[5]) << 24) | ((uint64_t)(ubuf[4]) << 16) | ((uint64_t)(ubuf[6]) << 32) | ((uint64_t)(ubuf[5]) << 24) | ((uint64_t)(ubuf[4]) << 16)
| ((uint64_t)(ubuf[3]) << 8) | ubuf[2]; | ((uint64_t)(ubuf[3]) << 8) | ubuf[2];
} else { } else {
buf += SAMPLES_PER_BLOCK; buf += BYTES_PER_BLOCK;
continue; continue;
} }
if(!sweep_started) { if(!sweep_started) {
if (frequency == (uint64_t)(FREQ_ONE_MHZ*frequencies[0])) { if (frequency == (uint64_t)(FREQ_ONE_MHZ*frequencies[0])) {
sweep_started = true; sweep_started = true;
} else { } else {
buf += SAMPLES_PER_BLOCK; buf += BYTES_PER_BLOCK;
continue; continue;
} }
} }
if((FREQ_MAX_MHZ * FREQ_ONE_MHZ) < frequency) { if((FREQ_MAX_MHZ * FREQ_ONE_MHZ) < frequency) {
buf += SAMPLES_PER_BLOCK; buf += BYTES_PER_BLOCK;
continue; continue;
} }
/* copy to fftwIn as floats */ /* copy to fftwIn as floats */
buf += SAMPLES_PER_BLOCK - (fftSize * 2); buf += BYTES_PER_BLOCK - (fftSize * 2);
for(i=0; i < fftSize; i++) { for(i=0; i < fftSize; i++) {
fftwIn[i][0] = buf[i*2] * window[i] * 1.0f / 128.0f; fftwIn[i][0] = buf[i*2] * window[i] * 1.0f / 128.0f;
fftwIn[i][1] = buf[i*2+1] * window[i] * 1.0f / 128.0f; fftwIn[i][1] = buf[i*2+1] * window[i] * 1.0f / 128.0f;
@ -304,7 +304,7 @@ static void usage() {
fprintf(stderr, "\t[-p antenna_enable] # Antenna port power, 1=Enable, 0=Disable\n"); fprintf(stderr, "\t[-p antenna_enable] # Antenna port power, 1=Enable, 0=Disable\n");
fprintf(stderr, "\t[-l gain_db] # RX LNA (IF) gain, 0-40dB, 8dB steps\n"); fprintf(stderr, "\t[-l gain_db] # RX LNA (IF) gain, 0-40dB, 8dB steps\n");
fprintf(stderr, "\t[-g gain_db] # RX VGA (baseband) gain, 0-62dB, 2dB steps\n"); fprintf(stderr, "\t[-g gain_db] # RX VGA (baseband) gain, 0-62dB, 2dB steps\n");
fprintf(stderr, "\t[-n num_samples] # Number of samples per frequency, 16384-4294967296\n"); fprintf(stderr, "\t[-n num_samples] # Number of samples per frequency, 8192-4294967296\n");
fprintf(stderr, "\t[-w bin_width] # FFT bin width (frequency resolution) in Hz\n"); fprintf(stderr, "\t[-w bin_width] # FFT bin width (frequency resolution) in Hz\n");
fprintf(stderr, "\t[-1] # one shot mode\n"); fprintf(stderr, "\t[-1] # one shot mode\n");
fprintf(stderr, "\t[-B] # binary output\n"); fprintf(stderr, "\t[-B] # binary output\n");
@ -447,12 +447,12 @@ int main(int argc, char** argv) {
fprintf(stderr, "warning: vga_gain (-g) must be a multiple of 2\n"); fprintf(stderr, "warning: vga_gain (-g) must be a multiple of 2\n");
if (num_samples % SAMPLES_PER_BLOCK) { if (num_samples % SAMPLES_PER_BLOCK) {
fprintf(stderr, "warning: num_samples (-n) must be a multiple of 16384\n"); fprintf(stderr, "warning: num_samples (-n) must be a multiple of 8192\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (num_samples < SAMPLES_PER_BLOCK) { if (num_samples < SAMPLES_PER_BLOCK) {
fprintf(stderr, "warning: num_samples (-n) must be at least 16384\n"); fprintf(stderr, "warning: num_samples (-n) must be at least 8192\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -592,7 +592,7 @@ int main(int argc, char** argv) {
frequencies[2*i], frequencies[2*i+1]); frequencies[2*i], frequencies[2*i+1]);
} }
result = hackrf_init_sweep(device, frequencies, num_ranges, num_samples, result = hackrf_init_sweep(device, frequencies, num_ranges, num_samples * 2,
TUNE_STEP * FREQ_ONE_MHZ, OFFSET, INTERLEAVED); TUNE_STEP * FREQ_ONE_MHZ, OFFSET, INTERLEAVED);
if( result != HACKRF_SUCCESS ) { if( result != HACKRF_SUCCESS ) {
fprintf(stderr, "hackrf_init_sweep() failed: %s (%d)\n", fprintf(stderr, "hackrf_init_sweep() failed: %s (%d)\n",

View File

@ -1811,7 +1811,7 @@ int ADDCALL hackrf_set_hw_sync_mode(hackrf_device* device, const uint8_t value)
* Initialize sweep mode: * Initialize sweep mode:
* frequency_list is a list of start/stop pairs of frequencies in MHz. * frequency_list is a list of start/stop pairs of frequencies in MHz.
* num_ranges is the number of pairs in frequency_list (1 to 10) * num_ranges is the number of pairs in frequency_list (1 to 10)
* num_samples is the number of samples to capture after each tuning. * num_bytes is the number of sample bytes to capture after each tuning.
* step_width is the width in Hz of the tuning step. * step_width is the width in Hz of the tuning step.
* offset is a number of Hz added to every tuning frequency. * offset is a number of Hz added to every tuning frequency.
* Use to select center frequency based on the expected usable bandwidth. * Use to select center frequency based on the expected usable bandwidth.
@ -1823,7 +1823,7 @@ int ADDCALL hackrf_set_hw_sync_mode(hackrf_device* device, const uint8_t value)
*/ */
int ADDCALL hackrf_init_sweep(hackrf_device* device, int ADDCALL hackrf_init_sweep(hackrf_device* device,
const uint16_t* frequency_list, const int num_ranges, const uint16_t* frequency_list, const int num_ranges,
const uint32_t num_samples, const uint32_t step_width, const uint32_t num_bytes, const uint32_t step_width,
const uint32_t offset, const enum sweep_style style) { const uint32_t offset, const enum sweep_style style) {
USB_API_REQUIRED(device, 0x0102) USB_API_REQUIRED(device, 0x0102)
int result, i; int result, i;
@ -1834,11 +1834,11 @@ int ADDCALL hackrf_init_sweep(hackrf_device* device,
return HACKRF_ERROR_INVALID_PARAM; return HACKRF_ERROR_INVALID_PARAM;
} }
if(num_samples % SAMPLES_PER_BLOCK) { if(num_bytes % BYTES_PER_BLOCK) {
return HACKRF_ERROR_INVALID_PARAM; return HACKRF_ERROR_INVALID_PARAM;
} }
if(SAMPLES_PER_BLOCK > num_samples) { if(BYTES_PER_BLOCK > num_bytes) {
return HACKRF_ERROR_INVALID_PARAM; return HACKRF_ERROR_INVALID_PARAM;
} }
@ -1868,8 +1868,8 @@ int ADDCALL hackrf_init_sweep(hackrf_device* device,
device->usb_device, device->usb_device,
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
HACKRF_VENDOR_REQUEST_INIT_SWEEP, HACKRF_VENDOR_REQUEST_INIT_SWEEP,
num_samples & 0xffff, num_bytes & 0xffff,
(num_samples >> 16) & 0xffff, (num_bytes >> 16) & 0xffff,
data, data,
size, size,
0 0

View File

@ -47,7 +47,8 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
#endif #endif
#define SAMPLES_PER_BLOCK 16384 #define SAMPLES_PER_BLOCK 8192
#define BYTES_PER_BLOCK 16384
#define MAX_SWEEP_RANGES 10 #define MAX_SWEEP_RANGES 10
enum hackrf_error { enum hackrf_error {
@ -229,7 +230,7 @@ extern ADDAPI int ADDCALL hackrf_set_hw_sync_mode(hackrf_device* device, const u
/* Start sweep mode */ /* Start sweep mode */
extern ADDAPI int ADDCALL hackrf_init_sweep(hackrf_device* device, extern ADDAPI int ADDCALL hackrf_init_sweep(hackrf_device* device,
const uint16_t* frequency_list, const int num_ranges, const uint16_t* frequency_list, const int num_ranges,
const uint32_t num_samples, const uint32_t step_width, const uint32_t num_bytes, const uint32_t step_width,
const uint32_t offset, const enum sweep_style style); const uint32_t offset, const enum sweep_style style);
/* Operacake functions */ /* Operacake functions */