3 * Copyright 2004,2006,2009,2010 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
27 #include <usrp_source_c.h>
28 #include <gr_io_signature.h>
29 #include <usrp/usrp_standard.h>
30 #include <usrp/usrp_bytesex.h>
32 static const int NBASIC_SAMPLES_PER_ITEM = 2; // I & Q
35 usrp_make_source_c (int which_board,
36 unsigned int decim_rate,
42 const std::string fpga_filename,
43 const std::string firmware_filename
44 ) throw (std::runtime_error)
46 return gnuradio::get_initial_sptr(new usrp_source_c (which_board,
59 usrp_source_c::usrp_source_c (int which_board,
60 unsigned int decim_rate,
66 const std::string fpga_filename,
67 const std::string firmware_filename
68 ) throw (std::runtime_error)
69 : usrp_source_base ("usrp_source_c",
70 gr_make_io_signature (1, 1, sizeof (gr_complex)),
71 which_board, decim_rate, nchan, mux, mode,
72 fusb_block_size, fusb_nblocks,
73 fpga_filename, firmware_filename)
77 usrp_source_c::~usrp_source_c ()
83 usrp_source_c::ninput_bytes_reqd_for_noutput_items (int noutput_items)
85 return noutput_items * NBASIC_SAMPLES_PER_ITEM * sizeof_basic_sample();
89 * Convert interleaved 8 or 16-bit I & Q from usrp buffer into a single
90 * complex output stream.
93 usrp_source_c::copy_from_usrp_buffer (gr_vector_void_star &output_items,
95 int output_items_available,
96 int &output_items_produced,
97 const void *usrp_buffer,
98 int usrp_buffer_length,
101 gr_complex *out = &((gr_complex *) output_items[0])[output_index];
102 unsigned sbs = sizeof_basic_sample();
103 unsigned nusrp_bytes_per_item = NBASIC_SAMPLES_PER_ITEM * sbs;
105 int nitems = std::min (output_items_available,
106 (int)(usrp_buffer_length / nusrp_bytes_per_item));
108 signed char *s8 = (signed char *) usrp_buffer;
109 short *s16 = (short *) usrp_buffer;
113 for (int i = 0; i < nitems; i++){
114 out[i] = gr_complex ((float)(s8[2*i+0] << 8), (float)(s8[2*i+1] << 8));
119 for (int i = 0; i < nitems; i++){
120 out[i] = gr_complex ((float) usrp_to_host_short(s16[2*i+0]),
121 (float) usrp_to_host_short(s16[2*i+1]));
129 output_items_produced = nitems;
130 bytes_read = nitems * nusrp_bytes_per_item;