2 * Copyright 2003-2010 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
12 #include "MixerSettings.h"
16 #include <TimeSource.h>
26 // The number of "enum media_multi_channels" types from MediaDefs.h
27 // XXX should be 18, but limited to 12 here
28 #define MAX_CHANNEL_TYPES 12
29 // XXX using a dedicated mono channel, this should be channel type 31
30 // but for now we redefine type 12
31 #define B_CHANNEL_MONO B_CHANNEL_TOP_CENTER
33 #define MIXER_PROCESS_EVENT BTimedEventQueue::B_USER_EVENT+10
34 #define MIXER_SCHEDULE_EVENT BTimedEventQueue::B_USER_EVENT+11
39 MixerCore(AudioMixer
* node
);
42 MixerSettings
* Settings();
43 void UpdateResamplingAlgorithm();
45 // To avoid calling Settings()->AttenuateOutput() for every outgoing
46 // buffer, this setting is cached in fOutputGain and must be set by
47 // the audio mixer node using SetOutputAttenuation()
48 void SetOutputAttenuation(float gain
);
49 MixerInput
* AddInput(const media_input
& input
);
50 MixerOutput
* AddOutput(const media_output
& output
);
52 bool RemoveInput(int32 inputID
);
54 int32
CreateInputID();
56 // index = 0 to count-1, NOT inputID
57 MixerInput
* Input(int index
);
58 MixerOutput
* Output();
61 bool LockWithTimeout(bigtime_t timeout
);
62 bool IsLocked() const;
66 bigtime_t
PickEvent();
68 void BufferReceived(BBuffer
* buffer
,
71 void InputFormatChanged(int32 inputID
,
72 const media_multi_audio_format
& format
);
73 void OutputFormatChanged(
74 const media_multi_audio_format
& format
);
76 void SetOutputBufferGroup(BBufferGroup
* group
);
77 void SetTimingInfo(BTimeSource
* timeSource
,
78 bigtime_t downstreamLatency
);
79 void EnableOutput(bool enabled
);
83 void StartMixThread();
85 uint32
OutputChannelCount();
88 void _UpdateResamplers(
89 const media_multi_audio_format
& format
);
90 void _ApplyOutputFormat();
91 static int32
_MixThreadEntry(void* arg
);
100 // true = the mix thread is running
103 // true = mix thread should be
104 // started of it is not running
107 // true = mix thread should be
108 // started of it is not running
110 Resampler
** fResampler
; // array
112 int32 fMixBufferFrameRate
;
113 int32 fMixBufferFrameCount
;
114 int32 fMixBufferChannelCount
;
115 int32
* fMixBufferChannelTypes
; //array
116 bool fDoubleRateMixing
;
117 bigtime_t fDownstreamLatency
;
118 MixerSettings
* fSettings
;
120 BBufferGroup
* fBufferGroup
;
121 BTimeSource
* fTimeSource
;
122 thread_id fMixThread
;
123 sem_id fMixThreadWaitSem
;
125 bigtime_t fEventTime
;
126 bigtime_t fEventLatency
;
129 friend class MixerInput
;
137 return fLocker
->Lock();
142 MixerCore::LockWithTimeout(bigtime_t timeout
)
144 return fLocker
->LockWithTimeout(timeout
) == B_OK
;
149 MixerCore::IsLocked() const
151 return fLocker
->IsLocked();
165 release_sem(fMixThreadWaitSem
);
170 MixerCore::PickEvent()
172 return fTimeSource
->RealTimeFor(fEventTime
, 0)
173 - fEventLatency
- fDownstreamLatency
;
177 #endif // _MIXER_CORE_H