libnxter  0.1
Sampler.nxc
Go to the documentation of this file.
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3  Sampler.nxc
4  Copyright (C) 2008 Naba Kumar <naba@gnome.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
25 #ifndef __SAMPLER_H_
26 #define __SAMPLER_H_
27 
32 {
33  int lastPosition;
34  int samplingPeriod;
35  int lastOutput;
36  int lastInput;
37  bool hasMore;
38 };
39 
43 void
44 SamplerInit (SamplerContext &context, int currentPosition, int samplingPeriod)
45 {
46  context.lastPosition = currentPosition;
47  context.samplingPeriod = samplingPeriod;
48  context.lastOutput = -1;
49  context.lastInput = -1;
50  context.hasMore = false;
51 }
52 
55 int
56 SamplerGet (SamplerContext &context, int currentPosition, int sampleInput)
57 {
58  /* If current sampling period hasn't arrived, return no sample */
59  if (currentPosition < context.lastPosition + context.samplingPeriod)
60  return -1;
61 
62  context.lastPosition += context.samplingPeriod;
63  context.lastOutput = sampleInput;
64  context.lastInput = sampleInput;
65 
66  if (currentPosition < context.lastPosition + context.samplingPeriod)
67  context.hasMore = true;
68  else
69  context.hasMore = false;
70  return sampleInput;
71 }
72 
73 #endif
74 
void SamplerInit(SamplerContext &context, int currentPosition, int samplingPeriod)
Initializes the sampler with given sampling period and initial position.
Definition: Sampler.nxc:44
int SamplerGet(SamplerContext &context, int currentPosition, int sampleInput)
Returns sampleInput at the sampling periods and -1 for all others.
Definition: Sampler.nxc:56
The class to hold sampler context.
Definition: Sampler.nxc:31