Code covered by the BSD License  

Highlights from
Simple Audio Editor

image thumbnail

Simple Audio Editor

by

 

09 May 2008 (Updated )

This is a simple audio editor GUI to read, write, cut, copy, paste, filter and analyze audio data.

filters.Downsample
classdef Downsample < handle
%Downsample Downsample data by integer quantity

%   Copyright 2008 The MathWorks, Inc.
%   Author: Navan Ruthramoorthy

  methods
    function this = Downsample()
    end
    
    function y = filter(this, data, Fs) %#ok<INUSD,INUSL>
      y = [];
      FigureHandle = figure( ...
                    'Visible','off', ...
                    'Menubar','none', ...
                    'Toolbar','none', ...
                    'Position', [360,500,400,50], ...
                    'IntegerHandle', 'off', ...
                    'Color',    get(0, 'defaultuicontrolbackgroundcolor'), ...
                    'NumberTitle', 'off', ...
                    'Name', 'Audio Editor: Downsample');
      movegui(FigureHandle, 'center');
      uicontrol('Parent', FigureHandle, 'Style', 'Text', ...
                'String', 'Downsampling factor:', ...
                'Units', 'Normalized', 'Position', [0 0.3 0.4 0.5], ...
                'FontSize', 12);
      hExpr = uicontrol('Parent', FigureHandle, 'Style', 'edit', ...
              'String', '2', ...
              'Units', 'Normalized', 'Position', [0.4 0.3 0.15 0.5], ...
              'FontSize', 12, 'BackgroundColor', 'white', ...
              'HorizontalAlignment', 'left');
      uicontrol('Parent', FigureHandle, 'Style', 'pushbutton', ...
                'String', 'Apply', 'Units', 'Normalized', ...
                'Position', [0.55 0.3 0.225 0.5], 'FontSize', 12, ...
                'Callback', @(hobj, evd) applyCallback());
      uicontrol('Parent', FigureHandle, 'Style', 'pushbutton', ...
                'String', 'Cancel', 'Units', 'Normalized', ...
                'Position', [0.775 0.3 0.225 0.5], 'FontSize', 12, ...
                'Callback', @(hobj, evd) cancelCallback());
      set(FigureHandle,'Visible','on', 'CloseRequestFcn', ...
                @(hobj, evd) cancelCallback);
      uiwait(FigureHandle);

        function applyCallback()
          d = evalin('base', get(hExpr, 'String'));
          if ~isfloat(d) || ~isscalar(d) || round(d) ~= d || d <= 0
            errordlg('Downsampling factor must be an integer valued scalar > 0', ...
                     'AudioEditor:Downsample');
            return;
          end
          y = data(1:d:end, :);
          delete(FigureHandle);
        end

        function cancelCallback()
          y = data;
          delete(FigureHandle);
        end
    end
  end
  
  methods (Static)
    function name = getName()
      name = 'Downsample';
    end
  end
end % classdef

Contact us