aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/xsample/source/inter.cpp
blob: f9d2fe1a0397f21a296c65de304d7000404839fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* 

xsample - extended sample objects for Max/MSP and pd (pure data)

Copyright (c) 2001-2003 Thomas Grill (xovo@gmx.net)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.  

*/

#include "main.h"
#include <math.h>

#ifdef _MSC_VER
#pragma warning (disable:4244)
#endif

#ifndef TMPLOPT
#include "inter.h"
#endif

void xinter::setup(t_classid c)
{
	FLEXT_CADDATTR_VAR_E(c,"interp",interp,m_interp);
}

xinter::xinter():
	doplay(false),outchns(1),
	interp(xsi_4p)
{
}

I xinter::m_set(I argc,const t_atom *argv) 
{
	I r = xsample::m_set(argc,argv);
	if(r) 
        // buffer parameters have changed, reset pos/min/max
        m_reset(); 
	return r;
}

V xinter::m_start() 
{ 
	m_refresh(); 
	doplay = true; 
	s_dsp(); 
}

V xinter::m_stop() 
{ 
	doplay = false; 
	s_dsp(); 
}

V xinter::s_dsp()
{
	switch(outchns) {
		case 1:	SETSIGFUN(zerofun,TMPLFUN(s_play0,-1,1)); break;
		case 2:	SETSIGFUN(zerofun,TMPLFUN(s_play0,-1,2)); break;
		case 4:	SETSIGFUN(zerofun,TMPLFUN(s_play0,-1,4)); break;
		default:	SETSIGFUN(zerofun,TMPLFUN(s_play0,-1,-1));
	}

	if(doplay) {
		if(interp == xsi_4p) 
			switch(buf->Channels()*1000+outchns) {
				case 1001:	SETSIGFUN(playfun,TMPLFUN(s_play4,1,1)); break;
				case 1002:	SETSIGFUN(playfun,TMPLFUN(s_play4,1,2)); break;
				case 2001:	SETSIGFUN(playfun,TMPLFUN(s_play4,2,1)); break;
				case 2002:	SETSIGFUN(playfun,TMPLFUN(s_play4,2,2)); break;
				case 4001:
				case 4002:
				case 4003:	SETSIGFUN(playfun,TMPLFUN(s_play4,4,-1)); break;
				case 4004:	SETSIGFUN(playfun,TMPLFUN(s_play4,4,4)); break;
				default:	SETSIGFUN(playfun,TMPLFUN(s_play4,-1,-1));
			}
		else if(interp == xsi_lin) 
			switch(buf->Channels()*1000+outchns) {
				case 1001:	SETSIGFUN(playfun,TMPLFUN(s_play2,1,1)); break;
				case 1002:	SETSIGFUN(playfun,TMPLFUN(s_play2,1,2)); break;
				case 2001:	SETSIGFUN(playfun,TMPLFUN(s_play2,2,1)); break;
				case 2002:	SETSIGFUN(playfun,TMPLFUN(s_play2,2,2)); break;
				case 4001:
				case 4002:
				case 4003:	SETSIGFUN(playfun,TMPLFUN(s_play2,4,-1)); break;
				case 4004:	SETSIGFUN(playfun,TMPLFUN(s_play2,4,4)); break;
				default:	SETSIGFUN(playfun,TMPLFUN(s_play2,-1,-1));
			}
		else 
			switch(buf->Channels()*1000+outchns) {
				case 1001:	SETSIGFUN(playfun,TMPLFUN(s_play1,1,1)); break;
				case 1002:	SETSIGFUN(playfun,TMPLFUN(s_play1,1,2)); break;
				case 2001:	SETSIGFUN(playfun,TMPLFUN(s_play1,2,1)); break;
				case 2002:	SETSIGFUN(playfun,TMPLFUN(s_play1,2,2)); break;
				case 4001:
				case 4002:
				case 4003:	SETSIGFUN(playfun,TMPLFUN(s_play1,4,-1)); break;
				case 4004:	SETSIGFUN(playfun,TMPLFUN(s_play1,4,4)); break;
				default:	SETSIGFUN(playfun,TMPLFUN(s_play1,-1,-1));
			}
	}
	else
		SETSIGFUN(playfun,TMPLFUN(s_play0,-1,-1));
}