SoDaRadio-5.0.3-master:8901fb5
ReSamplers625x48.cxx
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012, Matthew H. Reilly (kb1vc)
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are
7  met:
8 
9  Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the
14  distribution.
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 #include "ReSampler.hxx"
29 #include "ReSamplers625x48.hxx"
30 #include "SoDaBase.hxx"
31 #include <iostream>
32 #include <stdlib.h>
33 #include <string.h>
34 
35 
36 // Implement an overlap-and-save interpolator with zero stuffing.
37 SoDa::ReSample48to625::ReSample48to625(unsigned int inbufsize, float _gain) : SoDaBase("ReSamp 48 to 625")
38 {
39  // create the input and output buffers.
40  // set N and MN;
41 
42  // N is the length of the input buffer.
43  N = inbufsize;
44 
45  // N must be a multiple of 48, otherwise this doesn't work.
46  if ((N % 48) != 0) {
47  throw(new SoDa::SoDaException("48 to 625 resampler got an input buffer size that is not a multiple of 48", this));
48  }
49 
50  // MN is the size of the output buffer.
51  MN = N * 625 / 48;
52 
53  // allocate the intermediate buffers
54  inter1 = new std::complex<float>[MN];
55  inter2 = new std::complex<float>[MN];
56  finter1 = new float[MN];
57  finter2 = new float[MN];
58 
59  // create the resamplers.
60  int s1, s2, s3, s4;
61  s1 = N;
62  s2 = (s1 * 5) / 4;
63  s3 = (s2 * 5) / 4;
64  s4 = (s3 * 5) / 3;
65  rs54a = new SoDa::ReSampler(5, 4, s1, 255);
66  rs54b = new SoDa::ReSampler(5, 4, s2, 255);
67  rs53 = new SoDa::ReSampler(5, 3, s3, 255);
68  rs51 = new SoDa::ReSampler(5, 1, s4, 255);
69 
70  gain = _gain;
71 }
72 
74 {
75  delete rs54a;
76  delete rs54b;
77  delete rs53;
78  delete rs51;
79 }
80 
81 // inlen and outlen are in "samples" -- that is pairs of doubles...
82 void SoDa::ReSample48to625::apply(std::complex<float> * in, std::complex<float> * out)
83 {
84  rs54a->apply(in, inter1);
86  rs53->apply(inter2, inter1);
87  rs51->apply(inter1 ,out, gain);
88 }
89 
90 void SoDa::ReSample48to625::apply(float * in, float * out)
91 {
92  rs54a->apply(in, finter1);
95  rs51->apply(finter1, out, gain);
96 }
97 
98 
99 
100 
101 SoDa::ReSample625to48::ReSample625to48(unsigned int inbufsize, float _gain) : SoDaBase("ReSamp 48 to 625")
102 {
103  // create the input and output buffers.
104  // set N and MN;
105 
106  // N is the length of the input buffer.
107  N = inbufsize;
108 
109  // N must be a multiple of 625, otherwise this doesn't work.
110  if ((N % 625) != 0) {
111  throw(new SoDa::SoDaException("625 to 48 resampler got an input buffer size that is not a multiple of 48", this));
112  }
113 
114  // MN is the size of the output buffer.
115  MN = N * 48 / 625;
116 
117  // allocate the intermediate buffers
118  inter1 = new std::complex<float>[N];
119  inter2 = new std::complex<float>[N];
120  finter1 = new float[N];
121  finter2 = new float[N];
122 
123  // create the resamplers.
124  int s1, s2, s3, s4;
125  s1 = N;
126  s2 = (s1 * 1) / 5;
127  s3 = (s2 * 3) / 5;
128  s4 = (s3 * 4) / 5;
129  rs15 = new SoDa::ReSampler(1, 5, s1, 255);
130  rs35 = new SoDa::ReSampler(3, 5, s2, 255);
131  rs45a = new SoDa::ReSampler(4, 5, s3, 255);
132  rs45b = new SoDa::ReSampler(4, 5, s4, 255);
133 
134  gain = _gain;
135 }
136 
138 {
139  delete rs45a;
140  delete rs45b;
141  delete rs35;
142  delete rs15;
143 }
144 
145 // inlen and outlen are in "samples" -- that is pairs of doubles...
146 void SoDa::ReSample625to48::apply(std::complex<float> * in, std::complex<float> * out)
147 {
148  rs15->apply(in, inter1);
149  rs35->apply(inter1, inter2);
150  rs45a->apply(inter2, inter1);
151  rs45b->apply(inter1 ,out, gain);
152 }
153 
154 void SoDa::ReSample625to48::apply(float * in, float * out)
155 {
156  rs15->apply(in, finter1);
159  rs45b->apply(finter1, out, gain);
160 }
The Baseclass for all SoDa objects, and useful commonly used classes.
Rational Resampler.
Definition: ReSampler.hxx:41
std::complex< float > * inter1
SoDa::ReSampler * rs45a
The SoDa Exception class.
Definition: SoDaBase.hxx:217
float gain
the gain to be applied to the final transform result.
SoDa::ReSampler * rs15
SoDa::ReSampler * rs54b
void apply(std::complex< float > *in, std::complex< float > *out)
Perform the resampling on a complex float buffer.
SoDa::ReSampler * rs45b
std::complex< float > * inter2
float gain
the gain to be applied to the final transform result.
void apply(std::complex< float > *in, std::complex< float > *out)
Perform the resampling on a complex float buffer.
std::complex< float > * inter2
SoDa::ReSampler * rs35
std::complex< float > * inter1
ReSample48to625(unsigned int inbufsize, float gain=1.0)
Constructor.
SoDa::ReSampler * rs53
ReSample625to48(unsigned int inbufsize, float _gain=1.0)
Constructor.
The SoDa Base class.
Definition: SoDaBase.hxx:167
SoDa::ReSampler * rs51
SoDa::ReSampler * rs54a
unsigned int apply(std::complex< float > *in, std::complex< float > *out, float gain=1.0)
apply the resampler to a buffer of IQ samples.
Definition: ReSampler.cxx:272