2 * Copyright 2007 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 #ifndef _MIXER_OUTPUT_H
6 #define _MIXER_OUTPUT_H
9 #include "MixerDebug.h"
11 #include "MixerCore.h"
13 /* The data storage for channel sources is optimized
14 * for fast data retrieval by the MixerCore, which
15 * will call GetOutputChannelSourceInfoAt() and
16 * iterate through the first source_count array entries
17 * for source_gain[] and source_type[] arrays, they are
18 * index by 0 to GetOutputChannelSourceCount() - 1.
19 * To allow gain change for not active sources,
20 * we use the source_gain_cache[] array that is indexed
27 MixerOutput(MixerCore
*core
,
28 const media_output
&output
);
31 media_output
& MediaOutput();
33 const media_multi_audio_format
&format
);
35 // The physical output channels
36 int GetOutputChannelCount();
37 int GetOutputChannelType(int channel
);
38 void SetOutputChannelGain(int channel
,
40 float GetOutputChannelGain(int channel
);
42 // The sources for each channel
43 void AddOutputChannelSource(int channel
,
45 void RemoveOutputChannelSource(int channel
,
47 void SetOutputChannelSourceGain(int channel
,
50 float GetOutputChannelSourceGain(int channel
,
52 bool HasOutputChannelSource(int channel
,
55 // The output can be muted
56 void SetMuted(bool yesno
);
59 // Only for use by MixerCore:
60 // For iteration of a channel's sources
61 int GetOutputChannelSourceCount(int channel
);
62 void GetOutputChannelSourceInfoAt(int channel
,
67 // To swap byteorder in a buffer is that is needed
68 void AdjustByteOrder(BBuffer
*buffer
);
71 void UpdateByteOrderSwap();
72 void UpdateOutputChannels();
73 void AssignDefaultSources();
77 // An entry in the source array is not the same as the
78 // channel type, but the count should be the same
80 MAX_SOURCE_ENTRIES
= MAX_CHANNEL_TYPES
83 struct output_chan_info
{
87 float source_gain
[MAX_SOURCE_ENTRIES
];
88 int source_type
[MAX_SOURCE_ENTRIES
];
89 float source_gain_cache
[MAX_CHANNEL_TYPES
];
94 int fOutputChannelCount
;
95 output_chan_info
*fOutputChannelInfo
; //array
96 ByteSwap
*fOutputByteSwap
;
102 MixerOutput::GetOutputChannelCount()
104 return fOutputChannelCount
;
109 MixerOutput::GetOutputChannelGain(int channel
)
111 if (channel
< 0 || channel
>= fOutputChannelCount
)
113 return fOutputChannelInfo
[channel
].channel_gain
;
118 MixerOutput::GetOutputChannelSourceCount(int channel
)
120 ASSERT(channel
>= 0 && channel
< fOutputChannelCount
);
121 return fOutputChannelInfo
[channel
].source_count
;
125 inline void MixerOutput::GetOutputChannelSourceInfoAt(int channel
,
130 ASSERT(channel
>= 0 && channel
< fOutputChannelCount
);
131 ASSERT(source_index
>= 0 && source_index
< fOutputChannelInfo
[channel
].source_count
);
132 *source_type
= fOutputChannelInfo
[channel
].source_type
[source_index
];
133 *source_gain
= fOutputChannelInfo
[channel
].source_gain
[source_index
];
138 MixerOutput::AdjustByteOrder(BBuffer
*buffer
)
141 fOutputByteSwap
->Swap(buffer
->Data(), buffer
->SizeUsed());
145 MixerOutput::IsMuted()