~ubuntu-branches/ubuntu/dapper/lmms/dapper

« back to all changes in this revision

Viewing changes to include/mixer.h

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ragwitz
  • Date: 2005-12-22 16:22:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20051222162250-key3p7x0212jy6dn
Tags: 0.1.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * mixer.h - audio-device-independent mixer for LMMS
3
3
 *
4
 
 * Linux MultiMedia Studio
5
 
 * Copyright (c) 2004-2005 Tobias Doerffel <tobydox@users.sourceforge.net>
 
4
 * Copyright (c) 2004-2005 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 
5
 * 
 
6
 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
6
7
 *
7
8
 * This program is free software; you can redistribute it and/or
8
9
 * modify it under the terms of the GNU General Public
33
34
 
34
35
#ifdef QT4
35
36
 
36
 
#include <QThread>
37
37
#include <QMutex>
38
38
#include <QVector>
39
39
 
40
40
#else
41
41
 
42
42
#include <qobject.h>
43
 
#include <qthread.h>
44
43
#include <qmutex.h>
45
44
#include <qvaluevector.h>
46
45
 
52
51
#include "panning.h"
53
52
#include "note.h"
54
53
#include "play_handle.h"
 
54
#include "effect_board.h"
55
55
 
56
56
 
57
57
class audioDevice;
58
 
class midiDevice;
 
58
class midiClient;
59
59
class lmmsMainWin;
 
60
class plugin;
 
61
class audioPort;
60
62
 
61
63
 
62
64
const int DEFAULT_BUFFER_SIZE = 512;
63
65
 
64
 
const Uint16 MAX_SAMPLE_PACKETS = 256;  // how many parallel audio-samples-
65
 
                                        // buffers shall be maximal exist and
66
 
                                        // mixed together?
67
 
 
68
66
const Uint8  DEFAULT_CHANNELS = 2;
69
67
 
70
68
const Uint8  SURROUND_CHANNELS =
78
76
const Uint32 DEFAULT_QUALITY_LEVEL = 0;
79
77
const Uint32 HIGH_QUALITY_LEVEL = DEFAULT_QUALITY_LEVEL+1;
80
78
extern Uint32 SAMPLE_RATES[QUALITY_LEVELS];
81
 
const Uint32 DEFAULT_SAMPLE_RATE = 44100;//SAMPLE_RATES[DEFAULT_QUALITY_LEVEL];
 
79
const Uint32 DEFAULT_SAMPLE_RATE = 44100;
82
80
 
83
81
 
84
82
typedef sampleType sampleFrame[DEFAULT_CHANNELS];
104
102
 
105
103
 
106
104
 
107
 
class mixer : 
108
 
#ifndef QT4
109
 
                public QObject,
110
 
#endif
111
 
                public QThread
 
105
class mixer : public QObject
112
106
{
113
107
        Q_OBJECT
114
108
public:
122
116
        }
123
117
 
124
118
 
125
 
        void FASTCALL addBuffer( sampleFrame * _buf, Uint32 _frames,
 
119
        void FASTCALL bufferToPort( sampleFrame * _buf, Uint32 _frames,
126
120
                                                Uint32 _framesAhead,
127
 
                                                volumeVector & _volumeVector );
 
121
                                                volumeVector & _volumeVector,
 
122
                                                audioPort * _port );
128
123
        inline Uint32 framesPerAudioBuffer( void ) const
129
124
        {
130
125
                return( m_framesPerAudioBuffer );
131
126
        }
132
127
 
 
128
        inline Uint8 cpuLoad( void ) const
 
129
        {
 
130
                return( m_cpuLoad );
 
131
        }
133
132
 
134
133
        inline bool highQuality( void ) const
135
134
        {
150
149
 
151
150
        void FASTCALL setAudioDevice( audioDevice * _dev, bool _hq );
152
151
        void restoreAudioDevice( void );
153
 
 
154
 
 
155
 
        // MIDI-device-stuff
156
 
        inline const QString & midiDevName( void ) const
157
 
        {
158
 
                return( m_midiDevName );
159
 
        }
160
 
 
161
 
        inline midiDevice * getMIDIDevice( void )
162
 
        {
163
 
                return( m_midiDev );
 
152
        inline audioDevice * audioDev( void )
 
153
        {
 
154
                return( m_audioDev );
 
155
        }
 
156
 
 
157
 
 
158
        // audio-port-stuff
 
159
        inline void addAudioPort( audioPort * _port )
 
160
        {
 
161
                pause();
 
162
                m_audioPorts.push_back( _port );
 
163
                play();
 
164
        }
 
165
 
 
166
        inline void removeAudioPort( audioPort * _port )
 
167
        {
 
168
                vvector<audioPort *>::iterator it = qFind( m_audioPorts.begin(),
 
169
                                                        m_audioPorts.end(),
 
170
                                                        _port );
 
171
                if( it != m_audioPorts.end() )
 
172
                {
 
173
                        m_audioPorts.erase( it );
 
174
                }
 
175
        }
 
176
 
 
177
        // MIDI-client-stuff
 
178
        inline const QString & midiClientName( void ) const
 
179
        {
 
180
                return( m_midiClientName );
 
181
        }
 
182
 
 
183
        inline midiClient * getMIDIClient( void )
 
184
        {
 
185
                return( m_midiClient );
164
186
        }
165
187
 
166
188
 
174
196
                m_playHandlesToRemove.push_back( _ph );
175
197
        }
176
198
 
177
 
        void FASTCALL checkValidityOfPlayHandles( void );
178
 
 
179
 
 
180
 
        inline int sampleRate( void )
 
199
        void checkValidityOfPlayHandles( void );
 
200
 
 
201
 
 
202
 
 
203
        inline Uint32 sampleRate( void )
181
204
        {
182
205
                return( SAMPLE_RATES[m_qualityLevel] );
183
206
        }
184
207
 
185
208
 
186
 
        inline float masterOutput( void ) const
 
209
        inline float masterGain( void ) const
187
210
        {
188
 
                return( m_masterOutput );
 
211
                return( m_masterGain );
189
212
        }
190
213
 
191
 
        inline void setMasterOutput( float _mo )
 
214
        inline void setMasterGain( float _mo )
192
215
        {
193
 
                m_masterOutput = _mo;
 
216
                m_masterGain = _mo;
194
217
        }
195
218
 
196
219
 
208
231
        }
209
232
 
210
233
 
211
 
        inline void pause( void )
 
234
        void pause( void )
212
235
        {
213
 
                m_safetySyncMutex.lock();
 
236
                m_mixMutex.lock();
214
237
        }
215
238
 
216
 
        inline void play( void )
 
239
        void play( void )
217
240
        {
218
 
                m_safetySyncMutex.unlock();
 
241
                m_mixMutex.unlock();
219
242
        }
220
243
 
221
244
 
234
257
        }
235
258
 
236
259
 
 
260
        const surroundSampleFrame * renderNextBuffer( void );
 
261
 
237
262
public slots:
238
263
        void setHighQuality( bool _hq_on = FALSE );
239
264
 
244
269
 
245
270
 
246
271
private:
247
 
        struct samplePacket
248
 
        {
249
 
                surroundSampleFrame * m_buffer; // actual buffer for
250
 
                                                // wave-data
251
 
                Uint32 m_frames;
252
 
                Uint32 m_framesDone;
253
 
                Uint32 m_framesAhead;           // number of frames, the buffer 
254
 
                                                // should be mixed ahead
255
 
                volume m_vol;
256
 
                panning m_pan;
257
 
                enum samplePacketStates
258
 
                {
259
 
                        READY, FILLING, UNUSED
260
 
                } m_state;
261
 
        } ;
262
 
 
263
272
 
264
273
        static mixer * s_instanceOfMe;
265
274
 
266
275
        mixer();
267
276
        ~mixer();
268
277
 
269
 
        void quitThread( void );
 
278
        void stopProcessing( void );
270
279
 
271
280
 
272
281
        // we don't allow to create mixer by using copy-ctor
273
 
        mixer( const mixer & ) :
274
 
#ifndef QT4
275
 
                QObject(),
276
 
#endif
277
 
                QThread(),
278
 
                m_curBuf( m_buffer1 ),
279
 
                m_nextBuf( m_buffer2 )
 
282
        mixer( const mixer & )
280
283
        {
281
284
        }
282
285
 
283
 
        virtual void run( void );
284
 
 
285
 
 
286
 
        void FASTCALL mixSamplePacket( samplePacket * _sp );
287
286
 
288
287
 
289
288
        audioDevice * tryAudioDevices( void );
290
 
        midiDevice * tryMIDIDevices( void );
291
 
 
292
 
 
293
 
 
294
 
        sampleFrame * m_silence;
295
 
#ifndef DISABLE_SURROUND
296
 
        surroundSampleFrame * m_surroundSilence;// cool, silence in surround ;-)
297
 
#endif
298
 
 
299
 
 
300
 
        samplePacket m_samplePackets[MAX_SAMPLE_PACKETS];
 
289
        midiClient * tryMIDIClients( void );
 
290
 
 
291
        void processBuffer( surroundSampleFrame * _buf, fxChnl _fx_chnl );
 
292
 
 
293
 
 
294
 
 
295
        vvector<audioPort *> m_audioPorts;
301
296
 
302
297
        Uint32 m_framesPerAudioBuffer;
303
298
 
304
 
        surroundSampleFrame * m_buffer1;
305
 
        surroundSampleFrame * m_buffer2;
306
 
 
307
299
        surroundSampleFrame * m_curBuf;
308
300
        surroundSampleFrame * m_nextBuf;
309
301
 
310
 
        bool m_discardCurBuf;
311
 
 
 
302
        Uint8 m_cpuLoad;
312
303
 
313
304
        playHandleVector m_playHandles;
314
305
        playHandleVector m_playHandlesToRemove;
315
306
 
316
307
        Uint8 m_qualityLevel;
317
 
        volatile float m_masterOutput;
318
 
 
319
 
        volatile bool m_quit;
320
 
 
 
308
        float m_masterGain;
321
309
 
322
310
 
323
311
        audioDevice * m_audioDev;
325
313
        QString m_audioDevName;
326
314
 
327
315
 
328
 
        midiDevice * m_midiDev;
329
 
        QString m_midiDevName;
330
 
 
331
 
 
332
 
        QMutex m_safetySyncMutex;
333
 
        QMutex m_devMutex;
 
316
        midiClient * m_midiClient;
 
317
        QString m_midiClientName;
 
318
 
 
319
 
 
320
        QMutex m_mixMutex;
334
321
 
335
322
 
336
323
        friend class lmmsMainWin;