DAFF.m 4.75 KB
Newer Older
1
classdef DAFF < handle
2 3 4 5 6 7 8 9 10 11 12 13 14 15
    
    % DAFF is a direction audio file format for virtual acoustics
    % A daff file instance can be used to load a file in DAFF format and 
    % receiver metadata, proerties and directional audio content.
    %
    % The most important functions are
    %
    %   load                        Open a DAFF file
    %   close                       Closes a DAFF file
    %   nearest_neighbour_record    Receive content for a certain direction in spherical coordinates
    %   metadata                    Get DAFF metadata as struct
    %   properties                  Get DAFF properties as struct
    %
    
16
   properties (Access = protected)
17 18 19 20
       
      daffhandle % The internal DAFF file handle
      view = 'object' % The DAFF viewpoint (user/object or developer/data)
      
21
   end
22
   
23
   methods
24
       
25
        function obj = DAFF( filepath )
26 27
            % Creates a DAFF instance and loads content from file
            %   filepath    Path to DAFF file
28
            if( nargin > 0 )
29
                obj.open( filepath )
30 31
            end
        end
32
        
33
        function open( obj, filepath )
34
			% Opens a DAFF file
35 36
             obj.daffhandle = DAFFv17( 'open', filepath );
        end
37
        
38
        function close( obj )
39
			% Closes the DAFF file
40 41
			DAFFv17( 'close', obj.daffhandle )
        end
42
        
43
        function set_data_view( obj )
44
			% Switches to data view (alpha, beta)
45 46 47
             obj.view = 'data';
        end
        function set_object_view( obj )
48
			% Switches to object / user view (elevation, azimuth) [default]
49
             obj.view = 'object';
50
        end        
51 52 53
        function metadata = metadata(obj)
            % Returns the metadata of an opened DAFF file
            metadata = DAFFv17( 'getMetadata', obj.daffhandle );
54
        end
55 56 57
        function metadata = record_metadata( obj, index )
            % Returns the record metadata of an opened DAFF file
            metadata = DAFFv17( 'getRecordMetadata', obj.daffhandle, index );
58
        end
59 60
        function props = properties( obj )
            % Returns the properties of an opened DAFF file
61
            props = DAFFv17( 'getProperties', obj.daffhandle );
62
        end
63 64
        function coords = record_coords( obj, index )
            % Returns the coordinates of a grid point
65 66
            coords = DAFFv17( 'getRecordCoords', obj.daffhandle, obj.view, index );
        end
67 68 69 70 71 72 73
        function idx = nearest_neighbour_index( obj, azi_deg, ele_deg )
            % Returns the data at the nearest neighbour grid point to the given direction
            % Uses spherical coordinates azimuth and elevation in degree.
            %
            %   azi_deg     Azimuthal angle in degree
            %   ele_deg     Elevation angle in degree
            %
74 75
            idx = DAFFv17( 'getNearestNeighbourIndex', obj.daffhandle, obj.view, azi_deg, ele_deg );
        end
76 77 78 79 80 81 82
        function data = nearest_neighbour_record( obj, azi_deg, ele_deg )
            % Returns the data at the nearest neighbour grid point to the given direction
            % Uses spherical coordinates azimuth and elevation in degree.
            %
            %   azi_deg     Azimuthal angle in degree
            %   ele_deg     Elevation angle in degree
            %
83 84
            data = DAFFv17( 'getNearestNeighbourRecord', obj.daffhandle, obj.view, azi_deg, ele_deg );
        end
85 86
        function rec = record_by_index( obj, idx )
            % Returns the data at a grid of the given index
87 88
            rec = DAFFv17( 'getRecordByIndex', obj.daffhandle, idx );
        end
89 90 91 92 93 94 95
        function data = cell_records( obj, azi_deg, ele_deg )
            % Returns the data of all four records of the surrounding cell to the given direction
            % Uses spherical coordinates azimuth and elevation in degree.
            %
            %   azi_deg     Azimuthal angle in degree
            %   ele_deg     Elevation angle in degree
            %
96 97
            data = DAFFv17('getCellRecords', obj.daffhandle, obj.view, azi_deg, ele_deg );
        end
98 99 100 101 102 103 104
        function idx = cell( obj, azi_deg, ele_deg )
            % Returns the data at the nearest neighbour grid point to the given direction
            % Uses spherical coordinates azimuth and elevation in degree.
            %
            %   azi_deg     Azimuthal angle in degree
            %   ele_deg     Elevation angle in degree
            %
105 106
            idx = DAFFv17( 'getCell', obj.daffhandle, obj.view, azi_deg, ele_deg );
        end
107
        
108
   end
109
   
110
    methods (Static)
111 112 113 114
        
        function mex_help()
            % Prints the help output of OpenDAFF extension (mex)
            DAFFv17( 'help' )
115
        end
116 117 118 119
        
        function v = mex_version()
            % Returns the OpenDAFF extension (mex) version
            v = DAFFv17( 'getVersion' );
120
        end
121 122 123
        
    end
   
124
end