//
// MATLAB Compiler: 2.2
// Date: Sun Apr 18 15:57:57 2004
// Arguments: "-B" "macro_default" "-O" "all" "-O" "fold_scalar_mxarrays:on"
// "-O" "fold_non_scalar_mxarrays:on" "-O" "optimize_integer_for_loops:on" "-O"
// "array_indexing:on" "-O" "optimize_conditionals:on" "-p" "-W" "main" "-L"
// "Cpp" "-t" "-T" "link:exe" "-h" "libmmfile.mlib" "-B" "sglcpp" "-p" "-W"
// "main" "-L" "Cpp" "-t" "-T" "link:exe" "-h" "libmmfile.mlib" "-W" "mainhg"
// "libmwsglm.mlib" "hier_community.m" "Default.m" "Stop_Simulation.m"
// "Call_SaveLoad_Fig.m" "SaveLoad_Fig.m" "SaveLoad.m" "Load_Population_Data.m"
// "Save_Population_Data.m" "Start_hier_community.m" "MyInline.m" "Find_Var.m"
// "isnumber.m" "Change_Number_of_Populations.m" "Switch_Populations.m"
// "Store_Parameters.m" 
//
#include "audioplayer.hpp"
#include "audio_private_WinAudioPlayer_mex_interface.hpp"
#include "libmatlbm.hpp"
#include "libmmfile.hpp"

static mxChar _array1_[140] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ',
                                'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i',
                                'l', 'e', ':', ' ', 'a', 'u', 'd', 'i', 'o',
                                'p', 'l', 'a', 'y', 'e', 'r', ' ', 'L', 'i',
                                'n', 'e', ':', ' ', '1', ' ', 'C', 'o', 'l',
                                'u', 'm', 'n', ':', ' ', '1', ' ', 'T', 'h',
                                'e', ' ', 'f', 'u', 'n', 'c', 't', 'i', 'o',
                                'n', ' ', '"', 'a', 'u', 'd', 'i', 'o', 'p',
                                'l', 'a', 'y', 'e', 'r', '"', ' ', 'w', 'a',
                                's', ' ', 'c', 'a', 'l', 'l', 'e', 'd', ' ',
                                'w', 'i', 't', 'h', ' ', 'm', 'o', 'r', 'e',
                                ' ', 't', 'h', 'a', 'n', ' ', 't', 'h', 'e',
                                ' ', 'd', 'e', 'c', 'l', 'a', 'r', 'e', 'd',
                                ' ', 'n', 'u', 'm', 'b', 'e', 'r', ' ', 'o',
                                'f', ' ', 'o', 'u', 't', 'p', 'u', 't', 's',
                                ' ', '(', '1', ')', '.' };
static mwArray _mxarray0_ = mclInitializeString(140, _array1_);

static mxChar _array3_[139] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ',
                                'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i',
                                'l', 'e', ':', ' ', 'a', 'u', 'd', 'i', 'o',
                                'p', 'l', 'a', 'y', 'e', 'r', ' ', 'L', 'i',
                                'n', 'e', ':', ' ', '1', ' ', 'C', 'o', 'l',
                                'u', 'm', 'n', ':', ' ', '1', ' ', 'T', 'h',
                                'e', ' ', 'f', 'u', 'n', 'c', 't', 'i', 'o',
                                'n', ' ', '"', 'a', 'u', 'd', 'i', 'o', 'p',
                                'l', 'a', 'y', 'e', 'r', '"', ' ', 'w', 'a',
                                's', ' ', 'c', 'a', 'l', 'l', 'e', 'd', ' ',
                                'w', 'i', 't', 'h', ' ', 'm', 'o', 'r', 'e',
                                ' ', 't', 'h', 'a', 'n', ' ', 't', 'h', 'e',
                                ' ', 'd', 'e', 'c', 'l', 'a', 'r', 'e', 'd',
                                ' ', 'n', 'u', 'm', 'b', 'e', 'r', ' ', 'o',
                                'f', ' ', 'i', 'n', 'p', 'u', 't', 's', ' ',
                                '(', '3', ')', '.' };
static mwArray _mxarray2_ = mclInitializeString(139, _array3_);

static mxChar _array5_[189] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ',
                                'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i',
                                'l', 'e', ':', ' ', 'a', 'u', 'd', 'i', 'o',
                                'p', 'l', 'a', 'y', 'e', 'r', '/', 'g', 'e',
                                't', 'n', 'u', 'm', 'b', 'i', 't', 's', 'f',
                                'o', 'r', 't', 'h', 'i', 's', 's', 'i', 'g',
                                'n', 'a', 'l', ' ', 'L', 'i', 'n', 'e', ':',
                                ' ', '8', '6', ' ', 'C', 'o', 'l', 'u', 'm',
                                'n', ':', ' ', '1', ' ', 'T', 'h', 'e', ' ',
                                'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', ' ',
                                '"', 'a', 'u', 'd', 'i', 'o', 'p', 'l', 'a',
                                'y', 'e', 'r', '/', 'g', 'e', 't', 'n', 'u',
                                'm', 'b', 'i', 't', 's', 'f', 'o', 'r', 't',
                                'h', 'i', 's', 's', 'i', 'g', 'n', 'a', 'l',
                                '"', ' ', 'w', 'a', 's', ' ', 'c', 'a', 'l',
                                'l', 'e', 'd', ' ', 'w', 'i', 't', 'h', ' ',
                                'm', 'o', 'r', 'e', ' ', 't', 'h', 'a', 'n',
                                ' ', 't', 'h', 'e', ' ', 'd', 'e', 'c', 'l',
                                'a', 'r', 'e', 'd', ' ', 'n', 'u', 'm', 'b',
                                'e', 'r', ' ', 'o', 'f', ' ', 'o', 'u', 't',
                                'p', 'u', 't', 's', ' ', '(', '1', ')', '.' };
static mwArray _mxarray4_ = mclInitializeString(189, _array5_);

static mxChar _array7_[188] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ',
                                'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i',
                                'l', 'e', ':', ' ', 'a', 'u', 'd', 'i', 'o',
                                'p', 'l', 'a', 'y', 'e', 'r', '/', 'g', 'e',
                                't', 'n', 'u', 'm', 'b', 'i', 't', 's', 'f',
                                'o', 'r', 't', 'h', 'i', 's', 's', 'i', 'g',
                                'n', 'a', 'l', ' ', 'L', 'i', 'n', 'e', ':',
                                ' ', '8', '6', ' ', 'C', 'o', 'l', 'u', 'm',
                                'n', ':', ' ', '1', ' ', 'T', 'h', 'e', ' ',
                                'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', ' ',
                                '"', 'a', 'u', 'd', 'i', 'o', 'p', 'l', 'a',
                                'y', 'e', 'r', '/', 'g', 'e', 't', 'n', 'u',
                                'm', 'b', 'i', 't', 's', 'f', 'o', 'r', 't',
                                'h', 'i', 's', 's', 'i', 'g', 'n', 'a', 'l',
                                '"', ' ', 'w', 'a', 's', ' ', 'c', 'a', 'l',
                                'l', 'e', 'd', ' ', 'w', 'i', 't', 'h', ' ',
                                'm', 'o', 'r', 'e', ' ', 't', 'h', 'a', 'n',
                                ' ', 't', 'h', 'e', ' ', 'd', 'e', 'c', 'l',
                                'a', 'r', 'e', 'd', ' ', 'n', 'u', 'm', 'b',
                                'e', 'r', ' ', 'o', 'f', ' ', 'i', 'n', 'p',
                                'u', 't', 's', ' ', '(', '1', ')', '.' };
static mwArray _mxarray6_ = mclInitializeString(188, _array7_);

static mxChar _array9_[41] = { 'W', 'r', 'o', 'n', 'g', ' ', 'n', 'u', 'm',
                               'b', 'e', 'r', ' ', 'o', 'f', ' ', 'a', 'r',
                               'g', 'u', 'm', 'e', 'n', 't', 's', ' ', 't',
                               'o', ' ', 'a', 'u', 'd', 'i', 'o', 'p', 'l',
                               'a', 'y', 'e', 'r', '.' };
static mwArray _mxarray8_ = mclInitializeString(41, _array9_);
static mwArray _mxarray10_ = mclInitializeDouble(0.0);

static mxChar _array12_[29] = { 'S', 'a', 'm', 'p', 'l', 'e', ' ', 'r',
                                'a', 't', 'e', ' ', 'm', 'u', 's', 't',
                                ' ', 'b', 'e', ' ', 'p', 'o', 's', 'i',
                                't', 'i', 'v', 'e', '.' };
static mwArray _mxarray11_ = mclInitializeString(29, _array12_);
static mwArray _mxarray13_ = mclInitializeDouble(16.0);

static mxChar _array15_[47] = { 'C', 'u', 'r', 'r', 'e', 'n', 't', 'l',
                                'y', ' ', 'o', 'n', 'l', 'y', ' ', '8',
                                ' ', 'a', 'n', 'd', ' ', '1', '6', ' ',
                                'b', 'i', 't', ' ', 'a', 'u', 'd', 'i',
                                'o', ' ', 'i', 's', ' ', 's', 'u', 'p',
                                'p', 'o', 'r', 't', 'e', 'd', '.' };
static mwArray _mxarray14_ = mclInitializeString(47, _array15_);
static mwArray _mxarray16_ = mclInitializeDouble(8.0);

static mxChar _array18_[59] = { 'T', 'h', 'i', 's', ' ', 'f', 'u', 'n', 'c',
                                't', 'i', 'o', 'n', ' ', 'i', 's', ' ', 'o',
                                'n', 'l', 'y', ' ', 'f', 'o', 'r', ' ', 'u',
                                's', 'e', ' ', 'w', 'i', 't', 'h', ' ', '3',
                                '2', ' ', 'b', 'i', 't', ' ', 'W', 'i', 'n',
                                'd', 'o', 'w', 's', ' ', 'm', 'a', 'c', 'h',
                                'i', 'n', 'e', 's', '.' };
static mwArray _mxarray17_ = mclInitializeString(59, _array18_);

static mxChar _array20_[6] = { 'd', 'o', 'u', 'b', 'l', 'e' };
static mwArray _mxarray19_ = mclInitializeString(6, _array20_);

static mxChar _array22_[6] = { 's', 'i', 'n', 'g', 'l', 'e' };
static mwArray _mxarray21_ = mclInitializeString(6, _array22_);

static mxChar _array24_[5] = { 'i', 'n', 't', '1', '6' };
static mwArray _mxarray23_ = mclInitializeString(5, _array24_);

static mxChar _array26_[4] = { 'i', 'n', 't', '8' };
static mwArray _mxarray25_ = mclInitializeString(4, _array26_);

static mxChar _array28_[5] = { 'u', 'i', 'n', 't', '8' };
static mwArray _mxarray27_ = mclInitializeString(5, _array28_);

static mxChar _array30_[22] = { 'U', 'n', 's', 'u', 'p', 'p', 'o', 'r',
                                't', 'e', 'd', ' ', 'd', 'a', 't', 'a',
                                ' ', 't', 'y', 'p', 'e', '.' };
static mwArray _mxarray29_ = mclInitializeString(22, _array30_);

void InitializeModule_audioplayer() {
}

void TerminateModule_audioplayer() {
}

static mwArray audioplayer_getnumbitsforthissignal(mwArray thesignal
                                                   = mwArray::DIN);
#ifdef __cplusplus
extern "C"
#endif
void mlxAudioplayer_getnumbitsforthissignal(int nlhs,
                                            mxArray * plhs[],
                                            int nrhs,
                                            mxArray * prhs[]);
static mwArray Maudioplayer(int nargout_,
                            mwArray signal,
                            mwArray sampleRate,
                            mwArray numBits);
static mwArray Maudioplayer_getnumbitsforthissignal(int nargout_,
                                                    mwArray thesignal);

static mexFunctionTableEntry local_function_table_[1]
  = { { "getnumbitsforthissignal",
        mlxAudioplayer_getnumbitsforthissignal, 1, 1, NULL } };

_mexLocalFunctionTable _local_function_table_audioplayer
  = { 1, local_function_table_ };

//
// The function "audioplayer" contains the normal interface for the
// "audioplayer" M-function from file
// "C:\MATLAB6p1\toolbox\matlab\audio\audioplayer.m" (lines 1-86). This
// function processes any input arguments and passes them to the implementation
// version of the function, appearing above.
//
mwArray audioplayer(mwArray signal, mwArray sampleRate, mwArray numBits) {
    int nargout(1);
    mwArray player(mclGetUninitializedArray());
    player = Maudioplayer(nargout, signal, sampleRate, numBits);
    return player;
}

//
// The function "mlxAudioplayer" contains the feval interface for the
// "audioplayer" M-function from file
// "C:\MATLAB6p1\toolbox\matlab\audio\audioplayer.m" (lines 1-86). The feval
// function calls the implementation version of audioplayer through this
// function. This function processes any input arguments and passes them to the
// implementation version of the function, appearing above.
//
void mlxAudioplayer(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
    MW_BEGIN_MLX();
    {
        mwArray mprhs[3];
        mwArray mplhs[1];
        int i;
        mclCppUninitializeArrays(1, mplhs);
        if (nlhs > 1) {
            error(_mxarray0_);
        }
        if (nrhs > 3) {
            error(_mxarray2_);
        }
        for (i = 0; i < 3 && i < nrhs; ++i) {
            mprhs[i] = mwArray(prhs[i], 0);
        }
        for (; i < 3; ++i) {
            mprhs[i].MakeDIN();
        }
        mplhs[0] = Maudioplayer(nlhs, mprhs[0], mprhs[1], mprhs[2]);
        plhs[0] = mplhs[0].FreezeData();
    }
    MW_END_MLX();
}

//
// The function "audioplayer_getnumbitsforthissignal" contains the normal
// interface for the "audioplayer/getnumbitsforthissignal" M-function from file
// "C:\MATLAB6p1\toolbox\matlab\audio\audioplayer.m" (lines 86-101). This
// function processes any input arguments and passes them to the implementation
// version of the function, appearing above.
//
static mwArray audioplayer_getnumbitsforthissignal(mwArray thesignal) {
    int nargout(1);
    mwArray bits(mclGetUninitializedArray());
    bits = Maudioplayer_getnumbitsforthissignal(nargout, thesignal);
    return bits;
}

//
// The function "mlxAudioplayer_getnumbitsforthissignal" contains the feval
// interface for the "audioplayer/getnumbitsforthissignal" M-function from file
// "C:\MATLAB6p1\toolbox\matlab\audio\audioplayer.m" (lines 86-101). The feval
// function calls the implementation version of
// audioplayer/getnumbitsforthissignal through this function. This function
// processes any input arguments and passes them to the implementation version
// of the function, appearing above.
//
void mlxAudioplayer_getnumbitsforthissignal(int nlhs,
                                            mxArray * plhs[],
                                            int nrhs,
                                            mxArray * prhs[]) {
    MW_BEGIN_MLX();
    {
        mwArray mprhs[1];
        mwArray mplhs[1];
        int i;
        mclCppUninitializeArrays(1, mplhs);
        if (nlhs > 1) {
            error(_mxarray4_);
        }
        if (nrhs > 1) {
            error(_mxarray6_);
        }
        for (i = 0; i < 1 && i < nrhs; ++i) {
            mprhs[i] = mwArray(prhs[i], 0);
        }
        for (; i < 1; ++i) {
            mprhs[i].MakeDIN();
        }
        mplhs[0] = Maudioplayer_getnumbitsforthissignal(nlhs, mprhs[0]);
        plhs[0] = mplhs[0].FreezeData();
    }
    MW_END_MLX();
}

//
// The function "Maudioplayer" is the implementation version of the
// "audioplayer" M-function from file
// "C:\MATLAB6p1\toolbox\matlab\audio\audioplayer.m" (lines 1-86). It contains
// the actual compiled code for that M-function. It is a static function and
// must only be called from one of the interface functions, appearing below.
//
//
// function player = audioplayer(signal,sampleRate,numBits)
//
static mwArray Maudioplayer(int nargout_,
                            mwArray signal,
                            mwArray sampleRate,
                            mwArray numBits) {
    mwLocalFunctionTable save_local_function_table_
      (&_local_function_table_audioplayer);
    int nargin_(nargin(3, mwVarargin(signal, sampleRate, numBits)));
    mwArray player(mclGetUninitializedArray());
    mwArray audioplayers(mwArray::UNDEFINED);
    mwArray ans(mclGetUninitializedArray());
    //
    // %AUDIOPLAYER Windows audio player object.
    // %   AUDIOPLAYER(Y, Fs) creates an AUDIOPLAYER object for signal Y, using 
    // %   sample rate Fs.  A handle to the object is returned.
    // %   
    // %   AUDIOPLAYER(Y, Fs, NBITS) creates an AUDIOPLAYER object and uses NBITS 
    // %   bits per sample for floating point signal Y.  Valid values for NBITS are 
    // %   8 and 16.  The default number of bits per sample for floating point 
    // %   signals is 16.
    // %
    // %   METHODS:
    // %
    // %   PLAY                       - play from beginning
    // %   PLAY(start)                - play from start sample
    // %   PLAY([start stop])         - play from start sample until stop sample
    // %   PLAYBLOCKING               - play from beginning; does not return until 
    // %                                playback completes
    // %   PLAYBLOCKING(start)        - play from start sample; does not return until
    // %                                playback completes
    // %   PLAYBLOCKING([start stop]) - play from start sample until stop sample; 
    // %                                does not return until playback completes
    // %   STOP                       - stop playback in progress
    // %   PAUSE                      - pause playback in progress
    // %   RESUME                     - continue playback from paused location
    // %   ISPLAYING                  - returns 1 or 0, indicating playback is or 
    // %                                is not in progress
    // %
    // %   PROPERTIES:
    // %
    // %   Type             - string containing object's class name (read-only)
    // %   SampleRate       - the current sample rate (samples per second)
    // %   BitsPerSample    - the number of bits per sample (read-only)
    // %   NumberOfChannels - the number of channels (read-only)
    // %   TotalSamples     - the length of the loaded audio signal, in samples
    // %                      (read-only)
    // %   Running          - string indicating playback status as 'on' or 'off'
    // %                      (read-only)
    // %   CurrentSample    - current sample being played by audio output device - 
    // %                      if playback is not in progress, CurrentSample is 
    // %                      the next sample to be played (read-only)
    // %   UserData         - user-defined data location
    // %   Tag              - user-defined string
    // %
    // %   This functionality is only available on 32-bit Windows machines.
    // %
    // %   Example:  Load snippet of Handel's Halleluiah Chorus and play back 
    // %             only the first three seconds.
    // %
    // %      load handel;
    // %      p = audioplayer(y, Fs); 
    // %      p.play([1 (p.SampleRate * 3)]);
    // %
    // %   See also AUDIORECORDER, METHODS, GET, SET. 
    // 
    // 
    // %    Author(s): Brian Wherry 
    // %    Copyright 1984-2001 The MathWorks, Inc. 
    // %    $Revision: 1.3 $  $Date: 2001/04/06 20:16:29 $ 
    // 
    // if nargin < 2 | nargin > 3,
    //
    if (nargin_ < 2 || nargin_ > 3) {
        //
        // error('Wrong number of arguments to audioplayer.');
        //
        error(_mxarray8_);
    //
    // end
    //
    }
    //
    // 
    // if sampleRate <= 0,
    //
    if (mclLeBool(mwVa(sampleRate, "sampleRate"), _mxarray10_)) {
        //
        // error('Sample rate must be positive.');
        //
        error(_mxarray11_);
    //
    // end
    //
    }
    //
    // 
    // if nargin < 3,
    //
    if (nargin_ < 3) {
        //
        // numBits = getnumbitsforthissignal(signal);
        //
        numBits = audioplayer_getnumbitsforthissignal(mwVa(signal, "signal"));
    //
    // else
    //
    } else {
        //
        // getnumbitsforthissignal(signal);
        //
        ans.EqAns(audioplayer_getnumbitsforthissignal(mwVa(signal, "signal")));
    //
    // end
    //
    }
    //
    // 
    // if numBits ~= 8 & numBits ~= 16,
    //
    {
        mwArray a_(mwVa(numBits, "numBits") != _mxarray16_);
        if (tobool(a_)
            && tobool(a_ & mwVa(numBits, "numBits") != _mxarray13_)) {
            //
            // error('Currently only 8 and 16 bit audio is supported.');
            //
            error(_mxarray14_);
        } else {
        }
    //
    // end
    //
    }
    //
    // 
    // if ispc,
    //
    if (tobool(mwVe(ispc()))) {
        //
        // winaudioplayer;
        //
        ans.EqAns(
          Naudio_private_WinAudioPlayer(0, mwAnsVarargout(), mwVarargin()));
        //
        // player = audioplayers.winaudioplayer(signal, sampleRate, numBits);
        //
        player
          = mwVsv(audioplayers, "audioplayers").field("winaudioplayer")(
              mwVsa(signal, "signal"),
              mwVsa(sampleRate, "sampleRate"),
              mwVsa(numBits, "numBits"));
    //
    // else
    //
    } else {
        //
        // error('This function is only for use with 32 bit Windows machines.');
        //
        error(_mxarray17_);
    //
    // end
    //
    }
    mwValidateOutput(player, 1, nargout_, "player", "audioplayer");
    return player;
    //
    // 
    // 
    //
}

//
// The function "Maudioplayer_getnumbitsforthissignal" is the implementation
// version of the "audioplayer/getnumbitsforthissignal" M-function from file
// "C:\MATLAB6p1\toolbox\matlab\audio\audioplayer.m" (lines 86-101). It
// contains the actual compiled code for that M-function. It is a static
// function and must only be called from one of the interface functions,
// appearing below.
//
//
// function bits = getnumbitsforthissignal(thesignal)
//
static mwArray Maudioplayer_getnumbitsforthissignal(int nargout_,
                                                    mwArray thesignal) {
    mwLocalFunctionTable save_local_function_table_
      (&_local_function_table_audioplayer);
    mwArray bits(mclGetUninitializedArray());
    mwArray ans(mclGetUninitializedArray());
    //
    // 
    // switch class(thesignal)
    //
    mwArray v_(mwVe(classname(mwVa(thesignal, "thesignal"))));
    if (switchcompare(v_, _mxarray19_)) {
        //
        // case 'double',
        // bits = 16;
        //
        bits = _mxarray13_;
    //
    // case 'single',
    //
    } else if (switchcompare(v_, _mxarray21_)) {
        //
        // bits = 16;
        //
        bits = _mxarray13_;
    //
    // case 'int16',
    //
    } else if (switchcompare(v_, _mxarray23_)) {
        //
        // bits = 16;
        //
        bits = _mxarray13_;
    //
    // case 'int8',
    //
    } else if (switchcompare(v_, _mxarray25_)) {
        //
        // bits = 8;
        //
        bits = _mxarray16_;
    //
    // case 'uint8',
    //
    } else if (switchcompare(v_, _mxarray27_)) {
        //
        // bits = 8;
        //
        bits = _mxarray16_;
    //
    // otherwise
    //
    } else {
        //
        // error('Unsupported data type.');
        //
        error(_mxarray29_);
    //
    // end
    //
    }
    mwValidateOutput(
      bits, 1, nargout_, "bits", "audioplayer/getnumbitsforthissignal");
    return bits;
}
