Fixed spelling error: s/writeable/writable/g
[debian/gnuradio] / gr-msdd6000 / src / lib / msdd_source_c.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
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)
10  * any later version.
11  * 
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.
16  * 
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.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 //#define MSDD_DEBUG2_TRUE
28
29 #ifdef MSDD_DEBUG2_TRUE
30 #include <iostream>
31 #define MSDD_DEBUG2(x) std::cout << x << std::endl;
32 #else
33 #define MSDD_DEBUG2(x)
34 #endif
35
36 #include <msdd_source_c.h>
37 #include <gr_io_signature.h>
38
39 namespace {
40   static const int NBASIC_SAMPLES_PER_ITEM = 2; // I & Q
41 };
42
43 msdd_source_c_sptr
44 msdd_make_source_c (int which_board, 
45                     int opp_mode,
46                     const char *src, 
47                     unsigned short port_src
48                     ) throw (std::runtime_error)
49 {
50   return msdd_source_c_sptr (new msdd_source_c (
51                                                 which_board,
52                                                 opp_mode,
53                                                 src,
54                                                 port_src
55                                                 ));
56 }
57
58 msdd_source_c::msdd_source_c (int which_board,
59                               int opp_mode,
60                               const char *src, 
61                               unsigned short port_src
62                               ) throw (std::runtime_error)
63   : msdd_source_base ("msdd_source_c",
64                       gr_make_io_signature (1, 1, 2 * sizeof (int)),
65                       which_board, opp_mode, src, port_src
66                       )
67 {
68
69   switch (sizeof_basic_sample()) {      
70   case 4:
71           d_buffer_copy_behavior.reset(
72            new msdd::BufferCopyBehaviorComplex <short> ());
73     break;
74   default:
75     assert(false);    
76   }                               
77   
78 }
79
80 msdd_source_c::~msdd_source_c ()
81 {
82 }
83
84 int
85 msdd_source_c::ninput_bytes_reqd_for_noutput_items (int noutput_items)
86 {
87   return noutput_items * NBASIC_SAMPLES_PER_ITEM * sizeof_basic_sample();
88 }
89
90 /*
91  * Copy 8 bit fft from mdss buffer into output buffer
92  */
93 void
94 msdd_source_c::copy_from_msdd_buffer (gr_vector_void_star &output_items,
95                                       int output_index,
96                                       int output_items_available,
97                                       int &output_items_produced,
98                                       const void *msdd_buffer,
99                                       int buffer_length,
100                                       int &bytes_read)
101 {
102   unsigned nmsdd_bytes_per_item = NBASIC_SAMPLES_PER_ITEM * sizeof_basic_sample();
103   
104   unsigned int nitems = std::min (output_items_available,
105                                   (int)(buffer_length / nmsdd_bytes_per_item));
106   
107   (*d_buffer_copy_behavior.get())(output_items, msdd_buffer, output_index, nitems);
108   
109   output_items_produced = nitems;
110   bytes_read = nitems * nmsdd_bytes_per_item;
111 }