readViaLen.m
资源名称:10_11.rar [点击查看]
上传用户:abcwxk
上传日期:2016-05-20
资源大小:434k
文件大小:1k
源码类别:
midi
开发平台:
Visual C++
- % ------------------------------------------------------------------------------------------------
- function [value, len] = readViaLen(via)
- % description
- % 输入变长量开始的4字节数据,求出真实值value和变长量的长度len
- % 变长量,前n-1个元素最高位都为1,最后一个元素最高位为0,找到len
- % 剪去每个元素的最高位,乘以各自权值,输出value
- % 参考Borg.com+Midi+Specification.pdf
- % Page154 - 157: viariable length quantities
- % c routines
- % unsigned long ReadVarLen()
- % { register unsigned long value; register unsigned char c;
- % if ( (value = getc(infile)) & 0x80 )
- % { value &= 0x7F;
- % do { value = (value << 7) + ((c = getc(infile)) & 0x7F); }
- % while (c & 0x80);
- % }
- % return(value);}
- % 2008.9.22 17:06
- len = 1;
- value = 0;
- for i=1:4
- temp = bitand(via(i), 128) % 1000 0000b 128oct
- if temp
- % 最高位为1
- value = (double(value) + double(bitand(via(i), 127)) ) * 2^7; % 0111 1111b 127oct
- len = len + 1;
- else
- value = double(value) + double(via(i));
- break
- end
- end
- return;