classdef lang1_sound

    properties (Constant)
        vowels =    ["a",   "e",    "i",    "o",    "u",    "NONE"];
        f1_erbs =   [13.0,  10.0,   7.0,    10.0,   7.0,    0.0];
        f2_erbs =   [19.0,  22.0,   25.0,   16.0,   13.0,   0.0]
        n_vowels = size(lang1_sound.vowels, 2) - 1
        n_auditory_nodes = vowel.n_auditory_nodes
    end

    properties (SetAccess = immutable)
        v_index uint32
    end

    methods
        function obj = lang1_sound(v_logical_vector)
            obj.v_index = find(v_logical_vector, 1, 'first');
            if isempty(obj.v_index)
                obj.v_index = lang1_sound.n_vowels + 1;
            end
        end
        
        function ret = f1_erb(obj)
            ret = obj.f1_erbs(obj.v_index);
        end

        function ret = f2_erb(obj)
            ret = obj.f2_erbs(obj.v_index);
        end

        function input_vector = sample_and_create_input_vector(obj)
            [f1, f2] = vowel.sample(obj.f1_erb , obj.f2_erb);
            input_vector = vowel.create_input_vector(f1, f2);
        end

        function input_vector = create_input_vector(obj)
            input_vector = vowel.create_input_vector(obj.f1_erb , obj.f2_erb);
        end
    end

    methods (Static)
        function sound = get_sound_by_index(v_index)
            s_cell_array = enumeration('lang1_sound');
            sound = s_cell_array(v_index);
        end
       
        function v_index = find_vowel_by_erbs(f1_erb, f2_erb)
            % if found, returns v_index 
            % else, returns lang1_sound.n_vowels + 2
            found = false;
            for i = 1:lang1_sound.n_vowels + 1
                if (f1_erb == lang1_sound.f1_erbs(i) && f2_erb == lang1_sound.f2_erbs(i))
                    found = true;
                    v_index = i;
                    break
                end
            end
            if ~found
                v_index = lang1_sound.n_vowels + 2;
            end
        end
        
        function draw_zero_input()
            draw.vowel(zeros(1, vowel.n_auditory_nodes), draw.lang1_vowel_input)
        end

        function draw_zero_output()
            draw.vowel(zeros(1, vowel.n_auditory_nodes), draw.lang1_vowel_output)
        end
       
        function draw_input(sound_input_vector)
            assert(lang1_sound.n_auditory_nodes == size(sound_input_vector, 2), ...
                "incorrect sound_input_vector size")
            draw.vowel(sound_input_vector, draw.lang1_vowel_input)
        end

        function draw_output(sound_output_vector)
            assert(lang1_sound.n_auditory_nodes == size(sound_output_vector, 2), ...
                "incorrect sound_output_vector size")
            draw.vowel(sound_output_vector, draw.lang1_vowel_output);
        end
    end 

    enumeration
        A       ([1 0 0 0 0])
        E       ([0 1 0 0 0])
        I       ([0 0 1 0 0])
        O       ([0 0 0 1 0])
        U       ([0 0 0 0 1])
        NONE    ([0 0 0 0 0])
    end
end

