~ubuntu-branches/ubuntu/trusty/gnuradio/trusty

« back to all changes in this revision

Viewing changes to gnuradio-core/src/lib/general/gr_sig_source_f.cc

  • Committer: Bazaar Package Importer
  • Author(s): Kamal Mostafa
  • Date: 2010-03-13 07:46:01 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100313074601-zjsa893a87bozyh7
Tags: 3.2.2.dfsg-1ubuntu1
* Fix build for Ubuntu lucid (LP: #260406)
  - add binary package dep for libusrp0, libusrp2-0: adduser
  - debian/rules clean: remove pre-built Qt moc files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- c++ -*- */
2
 
/*
3
 
 * Copyright 2004 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
 
// WARNING: this file is machine generated.  Edits will be over written
24
 
 
25
 
#ifdef HAVE_CONFIG_H
26
 
#include <config.h>
27
 
#endif
28
 
#include <gr_sig_source_f.h>
29
 
#include <algorithm>
30
 
#include <gr_io_signature.h>
31
 
#include <stdexcept>
32
 
#include <gr_complex.h>
33
 
 
34
 
 
35
 
gr_sig_source_f::gr_sig_source_f (double sampling_freq, gr_waveform_t waveform,
36
 
                double frequency, double ampl, float offset)
37
 
  : gr_sync_block ("sig_source_f",
38
 
                   gr_make_io_signature (0, 0, 0),
39
 
                   gr_make_io_signature (1, 1, sizeof (float))),
40
 
    d_sampling_freq (sampling_freq), d_waveform (waveform), d_frequency (frequency),
41
 
    d_ampl (ampl), d_offset (offset)
42
 
{
43
 
  d_nco.set_freq (2 * M_PI * d_frequency / d_sampling_freq);
44
 
}
45
 
 
46
 
gr_sig_source_f_sptr
47
 
gr_make_sig_source_f (double sampling_freq, gr_waveform_t waveform,
48
 
                     double frequency, double ampl, float offset)
49
 
{
50
 
  return gr_sig_source_f_sptr (new gr_sig_source_f (sampling_freq, waveform, frequency, ampl, offset));
51
 
}
52
 
 
53
 
int
54
 
gr_sig_source_f::work (int noutput_items,
55
 
                    gr_vector_const_void_star &input_items,
56
 
                    gr_vector_void_star &output_items)
57
 
{
58
 
  float *optr = (float *) output_items[0];
59
 
  float t;
60
 
 
61
 
  switch (d_waveform){
62
 
 
63
 
#if 0   // complex?
64
 
 
65
 
  case GR_CONST_WAVE:
66
 
    t = (gr_complex) d_ampl + d_offset;
67
 
    for (int i = 0; i < noutput_items; i++)     // FIXME unroll
68
 
      optr[i] = t;
69
 
    break;
70
 
    
71
 
  case GR_SIN_WAVE:
72
 
  case GR_COS_WAVE:
73
 
    d_nco.sincos (optr, noutput_items, d_ampl);
74
 
    if (d_offset == gr_complex(0,0))
75
 
      break;
76
 
 
77
 
    for (int i = 0; i < noutput_items; i++){
78
 
      optr[i] += d_offset;
79
 
    }
80
 
    break;
81
 
 
82
 
#else                   // nope...
83
 
 
84
 
  case GR_CONST_WAVE:
85
 
    t = (float) d_ampl + d_offset;
86
 
    for (int i = 0; i < noutput_items; i++)     // FIXME unroll
87
 
      optr[i] = t;
88
 
    break;
89
 
    
90
 
  case GR_SIN_WAVE:
91
 
    d_nco.sin (optr, noutput_items, d_ampl);
92
 
    if (d_offset == 0)
93
 
      break;
94
 
 
95
 
    for (int i = 0; i < noutput_items; i++){
96
 
      optr[i] += d_offset;
97
 
    }
98
 
    break;
99
 
 
100
 
  case GR_COS_WAVE:
101
 
    d_nco.cos (optr, noutput_items, d_ampl);
102
 
    if (d_offset == 0)
103
 
      break;
104
 
 
105
 
    for (int i = 0; i < noutput_items; i++){
106
 
      optr[i] += d_offset;
107
 
    }
108
 
    break;
109
 
#endif
110
 
 
111
 
  default:
112
 
    throw std::runtime_error ("gr_sig_source: invalid waveform");
113
 
  }
114
 
 
115
 
  return noutput_items;
116
 
}
117
 
 
118
 
void
119
 
gr_sig_source_f::set_sampling_freq (double sampling_freq)
120
 
{
121
 
  d_sampling_freq = sampling_freq;
122
 
  d_nco.set_freq (2 * M_PI * d_frequency / d_sampling_freq);
123
 
}
124
 
 
125
 
void
126
 
gr_sig_source_f::set_waveform (gr_waveform_t waveform)
127
 
{
128
 
  d_waveform = waveform;
129
 
}
130
 
 
131
 
void
132
 
gr_sig_source_f::set_frequency (double frequency)
133
 
{
134
 
  d_frequency = frequency;
135
 
  d_nco.set_freq (2 * M_PI * d_frequency / d_sampling_freq);
136
 
}
137
 
 
138
 
void
139
 
gr_sig_source_f::set_amplitude (double ampl)
140
 
{
141
 
  d_ampl = ampl;
142
 
}
143
 
 
144
 
void
145
 
gr_sig_source_f::set_offset (float offset)
146
 
{
147
 
  d_offset = offset;
148
 
}
149