aboutsummaryrefslogtreecommitdiff
path: root/modules++/loopsampler.cc
blob: 01d2d26e896ca71eed0c09af8a568aee6ea62989 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
 *   loopsampler.cc  -  a sampler object for looping
 *   Copyright (c) 2000-2003 by Tom Schouten
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */


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


/* "soundfiler" object */

#define QUEUE_LENGTH 64;
typedef struct
{
} t_audiobuffer;



typedef struct
{
    t_soundfiler_queue q[QUEUE_LENGTH];

} t_soundfiler;





/* sample player class */


typedef struct loopsampler_struct
{
    t_object x_obj;
    t_float x_f;

    t_symbol *x_soundfile;
    t_int x_channels;
    t_int x_frames;
    t_float *x_buffer;

} t_loopsampler;

void loopsampler_bang(t_loopsampler *x)
{

}


static t_int *loopsampler_perform(t_int *w)
{


  t_loopsampler *x = (t_loopsampler *)(w[1]);
  t_int n          = (t_int)(w[2]);
  t_float *inL      = (float *)(w[3]);
  t_float *inR      = (float *)(w[4]);
  t_float *outL    = (float *)(w[5]);
  t_float *outR    = (float *)(w[6]);
  t_int i;
  t_float x;

  if (!x->x_buffer) goto nofile;




 nofile:
  while (n--){
      *outL++ = 0.0f;
      *outR++ = 0.0f;
  }

  return (w+7);
}

static void loopsampler_dsp(t_loopsampler *x, t_signal **sp)
{
    dsp_add(loopsampler_perform, 6, x->loopsampler, sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec);

}                                  
void loopsampler_free(void)
{

}

t_class *loopsampler_class;

void *loopsampler_new(t_floatarg fsections)
{
    t_loopsampler *x = (t_loopsampler *)pd_new(loopsampler_class);


    inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("signal"), gensym("signal"));  
    outlet_new(&x->x_obj, gensym("signal")); 
    outlet_new(&x->x_obj, gensym("signal")); 

    x->x_buffer = 0;
    x->x_soundfile = 0;
    x->x_channels = 0;
    x->x_frames = 0;

    return (void *)x;
}


extern "C" {

void loopsampler_tilde_setup(void)
{
    //post("loopsampler~ v0.1");

    loopsampler_class = class_new(gensym("loopsampler~"), (t_newmethod)loopsampler_new,
    	(t_method)loopsampler_free, sizeof(t_loopsampler), 0, A_DEFFLOAT, 0);

    CLASS_MAINSIGNALIN(loopsampler_class, t_loopsampler, x_f); 
    class_addmethod(loopsampler_class, (t_method)loopsampler_bang, gensym("bang"), (t_atomtype)0);
    class_addmethod(loopsampler_class, (t_method)loopsampler_dsp, gensym("dsp"), (t_atomtype)0); 


}

}