2 * Copyright 2003-2010 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
12 #include <MediaNode.h>
13 #include <RealtimeAlloc.h>
15 #include "MixerCore.h"
16 #include "MixerDebug.h"
17 #include "MixerUtils.h"
26 MixerInput(MixerCore
* core
,
27 const media_input
& input
,
28 float mixFrameRate
, int32 mixFrameCount
);
32 media_input
& MediaInput();
34 void BufferReceived(BBuffer
* buffer
);
36 void UpdateResamplingAlgorithm();
38 // The physical input channels
39 int GetInputChannelCount();
40 int GetInputChannelType(int channel
);
41 void SetInputChannelGain(int channel
, float gain
);
42 float GetInputChannelGain(int channel
);
44 // The destinations for each channel
45 void AddInputChannelDestination(int channel
,
47 void RemoveInputChannelDestination(int channel
,
49 bool HasInputChannelDestination(int channel
,
51 int GetInputChannelForDestination(
53 // returns -1 if not found
55 // The virtual mixer channels that are generated from destinations
56 int GetMixerChannelCount();
57 void SetMixerChannelGain(int mixerChannel
,
59 float GetMixerChannelGain(int mixerChannel
);
60 int GetMixerChannelType(int mixerChannel
);
62 void SetEnabled(bool enabled
);
65 // only for use by MixerCore
66 bool GetMixerChannelInfo(int mixerChannel
,
67 int64 framepos
, bigtime_t time
,
68 const float** _buffer
,
69 uint32
* _sampleOffset
, int* _type
,
73 friend class MixerCore
;
75 void SetMixBufferFormat(int32 framerate
,
79 void _UpdateInputChannelDestinationMask();
80 void _UpdateInputChannelDestinations();
82 struct input_chan_info
{
84 uint32 destination_mask
; // multiple or no bits sets
88 struct mixer_chan_info
{
91 float destination_gain
;
97 ByteSwap
* fInputByteSwap
;
98 float fChannelTypeGain
[MAX_CHANNEL_TYPES
];
100 input_chan_info
* fInputChannelInfo
; // array
101 int fInputChannelCount
;
102 uint32 fInputChannelMask
;
103 mixer_chan_info
* fMixerChannelInfo
; // array
104 int fMixerChannelCount
;
106 int32 fMixBufferFrameRate
;
107 int fMixBufferFrameCount
;
108 int32 fLastDataFrameWritten
;
109 bigtime_t fLastDataAvailableTime
;
110 double fFractionalFrames
;
111 Resampler
** fResampler
; // array
113 bool fUserOverridesChannelDestinations
;
114 int32 fDebugMixBufferFrames
;
119 MixerInput::GetMixerChannelCount()
121 return fMixerChannelCount
;
126 MixerInput::GetMixerChannelInfo(int mixerChannel
, int64 framepos
,
127 bigtime_t time
, const float** buffer
, uint32
* sampleOffset
, int* type
,
130 // this function should not be called if we don't have a mix buffer!
131 ASSERT(fMixBuffer
!= NULL
);
132 ASSERT(mixerChannel
>= 0 && mixerChannel
< fMixerChannelCount
);
137 if (time
< (fLastDataAvailableTime
- duration_for_frames(
138 fMixBufferFrameRate
, fMixBufferFrameCount
))
139 || (time
+ duration_for_frames(fMixBufferFrameRate
,
140 fDebugMixBufferFrames
)) >= fLastDataAvailableTime
) {
141 // Print this error for the first channel only.
142 if (mixerChannel
== 0) {
143 ERROR("MixerInput::GetMixerChannelInfo: reading wrong data, have %Ld "
144 "to %Ld, reading from %Ld to %Ld\n",
145 fLastDataAvailableTime
- duration_for_frames(fMixBufferFrameRate
,
146 fMixBufferFrameCount
), fLastDataAvailableTime
, time
,
147 time
+ duration_for_frames(fMixBufferFrameRate
,
148 fDebugMixBufferFrames
));
153 if (time
> fLastDataAvailableTime
)
156 int32 offset
= framepos
% fMixBufferFrameCount
;
157 if (mixerChannel
== 0) {
158 PRINT(3, "GetMixerChannelInfo: frames %ld to %ld\n", offset
,
159 offset
+ fDebugMixBufferFrames
- 1);
161 *buffer
= reinterpret_cast<float*>(reinterpret_cast<char*>(
162 fMixerChannelInfo
[mixerChannel
].buffer_base
)
163 + (offset
* sizeof(float) * fInputChannelCount
));
164 *sampleOffset
= sizeof(float) * fInputChannelCount
;
165 *type
= fMixerChannelInfo
[mixerChannel
].destination_type
;
166 *gain
= fMixerChannelInfo
[mixerChannel
].destination_gain
;
170 #endif // _MIXER_INPUT_H