1678c2017Sbeveloper #ifndef _MIXER_INPUT_H 2678c2017Sbeveloper #define _MIXER_INPUT_H 3678c2017Sbeveloper 4*fae6ce82Sbeveloper #include "debug.h" 5*fae6ce82Sbeveloper 6678c2017Sbeveloper class MixerCore; 788777023Sbeveloper class ByteSwap; 87b0daf5cSbeveloper class Resampler; 9678c2017Sbeveloper 10678c2017Sbeveloper class MixerInput 11678c2017Sbeveloper { 12678c2017Sbeveloper public: 138d28117fSbeveloper MixerInput(MixerCore *core, const media_input &input, float mixFrameRate, int32 mixFrameCount); 14678c2017Sbeveloper ~MixerInput(); 15678c2017Sbeveloper 16e6c7c99fSbeveloper int32 ID(); 17e6c7c99fSbeveloper 18678c2017Sbeveloper void BufferReceived(BBuffer *buffer); 19678c2017Sbeveloper 20be2a2489Sbeveloper media_input & MediaInput(); 21be2a2489Sbeveloper 222e9d6607Sbeveloper uint32 GetMixerChannelCount(); 232e9d6607Sbeveloper void SetMixerChannelGain(int channel, float gain); 242e9d6607Sbeveloper float GetMixerChannelGain(int channel); 252e9d6607Sbeveloper 26*fae6ce82Sbeveloper uint32 GetInputChannelCount(); 272e9d6607Sbeveloper void AddInputChannelDesignation(int channel, uint32 des); 282e9d6607Sbeveloper void RemoveInputChannelDesignation(int channel, uint32 des); 292e9d6607Sbeveloper uint32 GetInputChannelDesignations(int channel); 302e9d6607Sbeveloper uint32 GetInputChannelType(int channel); 312e9d6607Sbeveloper void SetInputChannelGain(int channel, float gain); 322e9d6607Sbeveloper float GetInputChannelGain(int channel); 332e9d6607Sbeveloper 34*fae6ce82Sbeveloper // only for use by MixerCore 35*fae6ce82Sbeveloper void GetMixerChannelInfo(int channel, int64 framepos, const float **buffer, uint32 *sample_offset, int *type, float *gain); 36*fae6ce82Sbeveloper int GetMixerChannelType(int channel); 37*fae6ce82Sbeveloper 382e9d6607Sbeveloper protected: 392e9d6607Sbeveloper friend class MixerCore; 408d28117fSbeveloper void SetMixBufferFormat(int32 framerate, int32 frames); 412e9d6607Sbeveloper 422e9d6607Sbeveloper private: 432e9d6607Sbeveloper void UpdateChannelDesignations(); 442e9d6607Sbeveloper void UpdateMixerChannels(); 452e9d6607Sbeveloper 462e9d6607Sbeveloper private: 472e9d6607Sbeveloper struct input_chan_info { 482e9d6607Sbeveloper float *buffer_base; 492e9d6607Sbeveloper uint32 designations; // multiple or no bits sets 502e9d6607Sbeveloper float gain; 512e9d6607Sbeveloper }; 522e9d6607Sbeveloper struct mixer_chan_info { 532e9d6607Sbeveloper float *buffer_base; 54a4b8db85Sbeveloper int type; 552e9d6607Sbeveloper float gain; 562e9d6607Sbeveloper }; 572e9d6607Sbeveloper 58678c2017Sbeveloper private: 59678c2017Sbeveloper MixerCore *fCore; 607ee2c804Sbeveloper media_input fInput; 6188777023Sbeveloper ByteSwap *fInputByteSwap; 622e9d6607Sbeveloper 632e9d6607Sbeveloper input_chan_info *fInputChannelInfo; // array 642e9d6607Sbeveloper uint32 fInputChannelCount; 652e9d6607Sbeveloper uint32 fInputChannelMask; 662e9d6607Sbeveloper 672e9d6607Sbeveloper mixer_chan_info *fMixerChannelInfo; // array 682e9d6607Sbeveloper uint32 fMixerChannelCount; 692e9d6607Sbeveloper 702e9d6607Sbeveloper float *fMixBuffer; 712e9d6607Sbeveloper 727619f562Sbeveloper int32 fMixBufferFrameRate; 737b0daf5cSbeveloper uint32 fMixBufferFrameCount; 742e9d6607Sbeveloper 757b0daf5cSbeveloper Resampler **fResampler; // array 76356855c3Sbeveloper rtm_pool *fRtmPool; 777b0daf5cSbeveloper 782e9d6607Sbeveloper bool fUserOverridesChannelDesignations; 798df36cddSbeveloper 808df36cddSbeveloper int32 debugMixBufferFrames; 81678c2017Sbeveloper }; 82678c2017Sbeveloper 83*fae6ce82Sbeveloper inline void 84*fae6ce82Sbeveloper MixerInput::GetMixerChannelInfo(int channel, int64 framepos, const float **buffer, uint32 *sample_offset, int *type, float *gain) 85*fae6ce82Sbeveloper { 86*fae6ce82Sbeveloper ASSERT(fMixBuffer); // this function should not be called if we don't have a mix buffer! 87*fae6ce82Sbeveloper ASSERT(channel >= 0 && channel < fMixerChannelCount); 88*fae6ce82Sbeveloper int32 offset = framepos % fMixBufferFrameCount; 89*fae6ce82Sbeveloper if (channel == 0) PRINT(3, "GetMixerChannelInfo: frames %ld to %ld\n", offset, offset + debugMixBufferFrames - 1); 90*fae6ce82Sbeveloper *buffer = reinterpret_cast<float *>(reinterpret_cast<char *>(fMixerChannelInfo[channel].buffer_base) + (offset * sizeof(float) * fInputChannelCount)); 91*fae6ce82Sbeveloper *sample_offset = sizeof(float) * fInputChannelCount; 92*fae6ce82Sbeveloper *type = fMixerChannelInfo[channel].type; 93*fae6ce82Sbeveloper *gain = fMixerChannelInfo[channel].gain; 94*fae6ce82Sbeveloper } 95*fae6ce82Sbeveloper 96*fae6ce82Sbeveloper inline int 97*fae6ce82Sbeveloper MixerInput::GetMixerChannelType(int channel) 98*fae6ce82Sbeveloper { 99*fae6ce82Sbeveloper ASSERT(fMixBuffer); // this function should not be called if we don't have a mix buffer! 100*fae6ce82Sbeveloper ASSERT(channel >= 0 && channel < fMixerChannelCount); 101*fae6ce82Sbeveloper return fMixerChannelInfo[channel].type; 102*fae6ce82Sbeveloper } 103*fae6ce82Sbeveloper 104678c2017Sbeveloper #endif 105