3 * Copyright 2004,2006 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_s.h>
28 #include <gr_io_signature.h>
29 #include <usrp_standard.h>
30 #include <usrp_bytesex.h>
32 static const int NBASIC_SAMPLES_PER_ITEM = 1;
35 usrp_make_source_s (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 usrp_source_s_sptr (new usrp_source_s (which_board,
59 usrp_source_s::usrp_source_s (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_s",
70 gr_make_io_signature (1, 1, sizeof (short)),
71 which_board, decim_rate, nchan, mux, mode,
74 fpga_filename, firmware_filename)
78 usrp_source_s::~usrp_source_s ()
84 usrp_source_s::ninput_bytes_reqd_for_noutput_items (int noutput_items)
86 return noutput_items * NBASIC_SAMPLES_PER_ITEM * sizeof_basic_sample();
90 * Convert interleaved 8 or 16-bit I & Q from usrp buffer into a single
91 * short output stream.
94 usrp_source_s::copy_from_usrp_buffer (gr_vector_void_star &output_items,
96 int output_items_available,
97 int &output_items_produced,
98 const void *usrp_buffer,
99 int usrp_buffer_length,
102 short *out = &((short *) output_items[0])[output_index];
103 unsigned sbs = sizeof_basic_sample();
104 unsigned nusrp_bytes_per_item = NBASIC_SAMPLES_PER_ITEM * sbs;
106 int nitems = std::min (output_items_available,
107 (int)(usrp_buffer_length / nusrp_bytes_per_item));
109 signed char *s8 = (signed char *) usrp_buffer;
110 short *s16 = (short *) usrp_buffer;
114 for (int i = 0; i < nitems; i++){
120 for (int i = 0; i < nitems; i++){
121 out[i] = usrp_to_host_short(s16[i]);
129 output_items_produced = nitems;
130 bytes_read = nitems * nusrp_bytes_per_item;