summaryrefslogtreecommitdiff
path: root/muse2/muse/audioconvert.h
blob: f17d74b23535cd15aecb29b9a81c222b0198693f (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
//=========================================================
//  MusE
//  Linux Music Editor
//  $Id: audioconvert.h,v 1.1.1.1 2009/12/28 16:07:33 terminator356 Exp $
//
//  (C) Copyright 1999-2009 Werner Schweer (ws@seh.de)
//
//  Audio converter module created by Tim 
//  (C) Copyright 2009-2011 Tim E. Real (terminator356 A T sourceforge D O T net)
//
//  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; 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//
//=========================================================

#ifndef __AUDIOCONVERT_H__
#define __AUDIOCONVERT_H__

#include <map>

#ifdef RUBBERBAND_SUPPORT
#include <RubberBandStretcher.h>
#endif

#include <samplerate.h>
#include <sys/types.h>


namespace MusECore {
class EventBase;
class EventList;
class SndFileR;


//---------------------------------------------------------
//   AudioConverter
//---------------------------------------------------------

class AudioConverter
{
   protected:   
      int _refCount;
      off_t _sfCurFrame;
      
   public:   
      AudioConverter();
      virtual ~AudioConverter();
      
      AudioConverter* reference();
      static AudioConverter* release(AudioConverter* cv);
      
      off_t readAudio(MusECore::SndFileR& sf, unsigned offset, float** buffer, 
                      int channels, int frames, bool doSeek, bool overwrite);
      
      virtual bool isValid() = 0;
      virtual void reset() = 0;
      virtual void setChannels(int ch) = 0;
      virtual off_t process(MusECore::SndFileR& sf, float** buffer, 
                            int channels, int frames, bool overwrite) = 0; // Interleaved buffer if stereo.
};

//---------------------------------------------------------
//   SRCAudioConverter
//---------------------------------------------------------

class SRCAudioConverter : public AudioConverter
{
      int _type;
      int _channels;
      SRC_STATE* _src_state;
   
   public:   
      SRCAudioConverter(int channels, int type);
      ~SRCAudioConverter();
      
      virtual bool isValid() { return _src_state != 0; }
      virtual void reset();
      virtual void setChannels(int ch);
      virtual off_t process(MusECore::SndFileR& sf, float** buffer, 
                            int channels, int frames, bool overwrite); // Interleaved buffer if stereo.
};

#ifdef RUBBERBAND_SUPPORT

//---------------------------------------------------------
//   RubberBandAudioConverter
//---------------------------------------------------------

class RubberBandAudioConverter : public AudioConverter
{
      int _options;
      int _channels;
      RubberBandStretcher* _rbs;
   
   public:   
      RubberBandAudioConverter(int channels, int options);
      ~RubberBandAudioConverter();
      
      virtual bool isValid() { return _rbs != 0; }
      virtual void reset();
      virtual void setChannels(int ch);
      virtual off_t process(MusECore::SndFileR& sf, float** buffer, 
                            int channels, int frames, bool overwrite); // Interleaved buffer if stereo.
};

#endif // RUBBERBAND_SUPPORT

//---------------------------------------------------------
//   AudioConvertMap
//---------------------------------------------------------

typedef std::map<EventBase*, AudioConverter*, std::less<EventBase*> >::iterator iAudioConvertMap;
typedef std::map<EventBase*, AudioConverter*, std::less<EventBase*> >::const_iterator ciAudioConvertMap;

class AudioConvertMap : public std::map<EventBase*, AudioConverter*, std::less<EventBase*> > 
{
   public:
      void remapEvents(const EventList*);  
      iAudioConvertMap addEvent(EventBase*);
      void removeEvent(EventBase*);
      iAudioConvertMap getConverter(EventBase*);
};

} // namespace MusECore

#endif