xref: /haiku/src/add-ons/media/media-add-ons/mixer/MixerOutput.h (revision b326a30e21605eb8b3bb4a2b7598bb30bfcd8957)
1 #ifndef _MIXER_OUTPUT_H
2 #define _MIXER_OUTPUT_H
3 
4 #include "debug.h"
5 #include "ByteSwap.h"
6 #include <Buffer.h>
7 
8 #define MAX_SOURCES 20
9 
10 class MixerCore;
11 
12 class MixerOutput
13 {
14 public:
15 	MixerOutput(MixerCore *core, const media_output &output);
16 	~MixerOutput();
17 
18 	media_output & MediaOutput();
19 
20 	void ChangeFormat(const media_multi_audio_format &format);
21 
22 	uint32 GetOutputChannelCount();
23 	uint32 GetOutputChannelDesignation(int channel);
24 	void SetOutputChannelGain(int channel, float gain);
25 	float GetOutputChannelGain(int channel);
26 
27 	uint32 GetOutputChannelSourceCount(int channel);
28 	void AddOutputChannelSource(int channel, uint32 source_designation, float source_gain);
29 	void RemoveOutputChannelSource(int channel, uint32 source_designation);
30 	void SetOutputChannelSourceGain(int channel, uint32 source_designation, float source_gain);
31 	float GetOutputChannelSourceGain(int channel, uint32 source_designation);
32 	void GetOutputChannelSourceAt(int channel, int index, uint32 *source_designation, float *source_gain);
33 
34 	void SetMuted(bool yesno);
35 	bool IsMuted();
36 
37 	// only for use by MixerCore
38 	void GetMixerChannelInfo(int channel, int index, int *type, float *gain);
39 	void AdjustByteOrder(BBuffer *buffer);
40 
41 private:
42 	void UpdateByteOrderSwap();
43 	void UpdateOutputChannels();
44 	void AssignDefaultSources();
45 
46 private:
47 	struct output_chan_info {
48 		uint32 designation;	// only one bit set
49 		float gain;
50 		int source_count;
51 		float source_gain[MAX_SOURCES];
52 		int source_type[MAX_SOURCES];
53 	};
54 
55 	MixerCore 			*fCore;
56 	media_output 		fOutput;
57 
58 	uint32				fOutputChannelCount;
59 	output_chan_info 	*fOutputChannelInfo; //array
60 	ByteSwap			*fOutputByteSwap;
61 
62 	bool				fMuted;
63 };
64 
65 inline uint32 MixerOutput::GetOutputChannelCount()
66 {
67 	return fOutputChannelCount;
68 }
69 
70 inline float MixerOutput::GetOutputChannelGain(int channel)
71 {
72 	if (channel < 0 || channel >= fOutputChannelCount)
73 		return 1.0;
74 	return fOutputChannelInfo[channel].gain;
75 }
76 
77 inline uint32 MixerOutput::GetOutputChannelSourceCount(int channel)
78 {
79 	if (channel < 0 || channel >= fOutputChannelCount)
80 		return 0;
81 	return fOutputChannelInfo[channel].source_count;
82 }
83 
84 inline void MixerOutput::GetMixerChannelInfo(int channel, int index, int *type, float *gain)
85 {
86 	ASSERT(channel >= 0 && channel < fOutputChannelCount);
87 	ASSERT(index >= 0 && index < fOutputChannelInfo[channel].source_count);
88 	*type = fOutputChannelInfo[channel].source_type[index];
89 	*gain = fOutputChannelInfo[channel].source_gain[index];
90 }
91 
92 inline void MixerOutput::AdjustByteOrder(BBuffer *buffer)
93 {
94 	if (fOutputByteSwap)
95 		fOutputByteSwap->Swap(buffer->Data(), buffer->SizeUsed());
96 }
97 
98 inline bool MixerOutput::IsMuted()
99 {
100 	return fMuted;
101 }
102 
103 #endif
104