Home > voicebox > midi2frq.m

midi2frq

PURPOSE ^

MIDI2FRQ Convert musical note numbers to frequencies F=(N,S)

SYNOPSIS ^

function f=midi2frq(n,s)

DESCRIPTION ^

MIDI2FRQ    Convert musical note numbers to frequencies F=(N,S)
        s is:    'e' equal tempered (default)
            'p' pythagorean scale
            'j' just intonation

 notes are numbered in semitones with middle C being 60
 On the equal tempered scale, note 69 (the A above middle C)
 has a frequency of 440 Hz.

 see FRQ2NOTE for the inverse transform

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function f=midi2frq(n,s)
0002 %MIDI2FRQ    Convert musical note numbers to frequencies F=(N,S)
0003 %        s is:    'e' equal tempered (default)
0004 %            'p' pythagorean scale
0005 %            'j' just intonation
0006 %
0007 % notes are numbered in semitones with middle C being 60
0008 % On the equal tempered scale, note 69 (the A above middle C)
0009 % has a frequency of 440 Hz.
0010 %
0011 % see FRQ2NOTE for the inverse transform
0012 
0013 % Pythagorean
0014 %     sharps 1 2187/2048 9/8 19683/16384 81/64 4/3 729/512  3/2 6561/4096 27/16 59049/32768 243/128 2
0015 %     flats  1 256/243   9/8 32/27       81/64 4/3 1024/729 3/2 128/81    27/16 16/9        243/128 2
0016 %
0017 % Just Intonation
0018 %     sharps 1 25/24 9/8 75/64 5/4 4/3 45/32  3/2 25/16 5/3 225/128 15/8 2
0019 %     flats  1 16/15 9/8 6/5   5/4 4/3 108/75 3/2 8/5   5/3 18/10   15/8 2
0020 
0021 
0022 %      Copyright (C) Mike Brookes 1997
0023 %      Version: $Id: midi2frq.m 713 2011-10-16 14:45:43Z dmb $
0024 %
0025 %   VOICEBOX is a MATLAB toolbox for speech processing.
0026 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
0027 %
0028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0029 %   This program is free software; you can redistribute it and/or modify
0030 %   it under the terms of the GNU General Public License as published by
0031 %   the Free Software Foundation; either version 2 of the License, or
0032 %   (at your option) any later version.
0033 %
0034 %   This program is distributed in the hope that it will be useful,
0035 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0036 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0037 %   GNU General Public License for more details.
0038 %
0039 %   You can obtain a copy of the GNU General Public License from
0040 %   http://www.gnu.org/copyleft/gpl.html or by writing to
0041 %   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
0042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0043 
0044 if nargin > 1
0045   if s(1)=='p'
0046     r=[256/243 9/8 32/27 81/64 4/3 729/512 3/2 128/81 27/16 16/9 243/128];
0047   elseif s(1)=='j'
0048     r=[16/15 9/8 6/5 5/4 4/3 36/25 3/2 8/5 5/3 9/5 15/8];
0049   else
0050     r=0;
0051   end
0052   if r(1)
0053     c=[0 0 12*log(r)/log(2)-(1:11) 0];
0054     nm=mod(n,12);
0055     na=floor(nm);
0056     nb=nm-na;
0057     f=440*exp((n+c(na+2).*(1-nb)+c(na+3).*nb-69)*log(2)/12);
0058   else
0059     f=440*exp((n-69)*log(2)/12);
0060   end
0061 else
0062   f=440*exp((n-69)*log(2)/12);
0063 end
0064

Generated on Tue 19-Sep-2017 12:07:31 by m2html © 2003