aboutsummaryrefslogtreecommitdiff
path: root/include/main.h
blob: ea1093f30c4f6b3ab9ddfdcd5d2fb60ff95de360 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 * readanysf~  external for pd. 
 * 
 * Copyright (C) 2003 August Black
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * main.h
 */


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif


#include <flext.h>
#include <stdio.h>


extern "C" {
#include <samplerate.h>  //libsamplerate
}

#include "Readsf.h"
#include "ReadRaw.h"
#ifdef READ_VORBIS
#include "ReadVorbis.h"
#endif
#ifdef READ_MAD
#include "ReadMad.h"
#endif
#ifdef READ_MAD_URL
#include "ReadMadUrl.h"
#endif
#ifdef READ_FLAC
#include "ReadFlac.h"
#endif

#include "Fifo.h"
#include "generic.h"
#include "Input.h"
#include "InputFile.h"
#include "InputStream.h"

// check for appropriate flext version
#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 400)
#error You need at least flext version 0.4.0
#endif


class readanysf: public flext_dsp
{
  // obligatory flext header (class name,base class name)
  FLEXT_HEADER(readanysf, flext_dsp)

public:
  
  readanysf();
  ~readanysf();

  
protected:
  // here we declare the virtual DSP function
  virtual void m_signal(int n, float *const *in, float *const *out);

  void m_open(t_symbol *s);		// open file Input; set req = R_OPEN
  void m_reopen();		// re open a file Input; set req = R_OPEN
  void m_start();				// set state = S_PROCESS
  void m_pause();				// set state = S_IDLE
  void m_stop();				// set state = S_STATE; cond.signal();

  void m_child();
  void FillFifo();
  
  //void m_loop_s(t_symbol *s);
  void m_recover(float f);
  void m_loop_f(float f);
  void m_set_tick(int i);
  void m_pcm_seek(int i);
  void m_time_seek(float f);
  void m_src_factor(float f);

  void m_bang();

  int m_resample(int frames);

  int getState();
  int getRequest();
  void setState(int i);
  void setRequest(int i);
  void setSys(int state, int request);
private:
  FLEXT_CALLBACK_S(m_open)     
  FLEXT_CALLBACK(m_reopen)     


  FLEXT_CALLBACK_F(m_loop_f)     
  FLEXT_CALLBACK_F(m_recover)     
  FLEXT_CALLBACK_I(m_set_tick)     
  FLEXT_CALLBACK(m_start)     
  FLEXT_CALLBACK(m_pause)     
  FLEXT_CALLBACK(m_stop)     

  FLEXT_CALLBACK_I(m_pcm_seek)     
  FLEXT_CALLBACK_F(m_time_seek)

  FLEXT_CALLBACK_F(m_src_factor)     

  FLEXT_THREAD(m_child)
  FLEXT_CALLBACK(m_bang)


  Readsf *readsf;
  ThrCond cond;
  ThrMutex sysmut;
  ThrMutex varmutex;
  Fifo *fifo;
  Input *in;
  int format;
  int outtick, counttick;
  int fifosecondsize;

  volatile int state, request;
  volatile bool loop, eof, quit, sendout;
  volatile float floatmsg, cachemsg, lengthinseconds;
  
  char filename[1024];
  int num_channels;
  double samplerate;

  volatile long pcmseek;
  volatile double timeseek;

  float read_buffer[READBUFFER];
  float pd_buffer[1024*2*FLOATSIZE];

  ///Secret Rabbit Code stuff
  int src_channels;
  float *src_buffer;
  SRC_STATE * src_state;
  SRC_DATA  src_data;
  double src_factor;
  int src_error;
  int src_mode;
};