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