/*
  Copyright (C) 2010-2011  Charles Pence <charles@charlespence.net>
  Copyright (C) 1996-1997  Id Software, Inc.

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOUND_MIXER_H__
#define SOUND_MIXER_H__

#include "channel.h"

#define MAX_DYNAMIC_CHANNELS 16


namespace sound
{

class Music;

class Mixer
{
public:
    Mixer();
    virtual ~Mixer();
    
    Channel *GetNewChannel(int entity_num, int entity_channel);
    Channel *GetStaticChannel();
        
    void Stop(int entnum, int entchannel);
    void StopAll();    
    
    void SetListenerParams(const refdef_t &refdef);
    void Update();
    
    float *listener_origin();
    float *listener_right();
        
private:
    void UpdateChannel(Channel &channel);
    void UpdateAmbients();
    
    vec3_t listener_origin_, listener_right_;
    
    unsigned ambient_indexes_[NUM_AMBIENTS];
    
    Channel dynamic_channels_[MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS];
    std::list<Channel> static_channels_;
    
    boost::mutex channel_lock_;
};

}

#endif /* SOUND_MIXER_H__ */
