function OpenSound(f_sensorport, f_mode)
% Sets the parameter mode of the NXT sound sensor
%
% Syntax
%   |OpenSound(port, mode)|
%
% Description
%   |OpenSound(port, mode)| initializes the input mode of NXT sound sensor specified by the sensor
%   |port| and the sound |mode|. The value |port| can be addressed by the symbolic constants
%   |SENSOR_1| , |SENSOR_2|, |SENSOR_3| and |SENSOR_4| analog to the labeling on the NXT Brick. The
%   |mode| represents one of two modes |'DB'| (dB measurement) and |'DBA'| (dBA measurement)
%
%   For more complex settings the function |NXT_SetInputMode| can be used.
%
% Examples
%+   OpenSound(SENSOR_1, 'DB');
%+   sound = GetSound(SENSOR_1);
%+   CloseSensor(SENSOR_1);
%
% See also: NXT_SetInputMode, GetSound, CloseSensor, SENSOR_1, SENSOR_2, SENSOR_3, SENSOR_4
%
% Signature
%   Author: Linus Atorf, Alexander Behrens (see AUTHORS)
%   Date: 2007/10/15
%   Copyright: 2007-2008, RWTH Aachen University
%
;
%
% ***********************************************************************************************
% *  This file is part of the RWTH - Mindstorms NXT Toolbox.                                    *
% *                                                                                             *
% *  The RWTH - Mindstorms NXT Toolbox 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.        *
% *                                                                                             *
% *  The RWTH - Mindstorms NXT Toolbox 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 the           *
% *  RWTH - Mindstorms NXT Toolbox. If not, see <http://www.gnu.org/licenses/>.                 *
% ***********************************************************************************************

%% Check Parameter
    if ~strcmpi(f_mode, 'DB') && ~strcmpi(f_mode, 'DBA')
        error('MATLAB:RWTHMindstormsNXT:Sensor:invalidMode', 'Sound sensor mode has to be ''DB'' or ''DBA''');
    end

    % also accept strings as input
    if ischar(f_sensorport)
        f_sensorport = str2double(f_sensorport);
    end%if
    
	% invalid sensorport will be catched by NXT_ function
    
%% Set correct variables
    f_mode = upper(f_mode);
    sensortype = ['SOUND_' f_mode]; % switch sensor
    sensormode = 'RAWMODE'; % raw Mode
    
%% Call NXT_SetInputMode function    
    NXT_SetInputMode(f_sensorport, sensortype, sensormode, 'dontreply'); 

end%function  
