📄 readdata.m
字号:
function QC = ReadData (FNameI, FNameErr)% Read data for the G.723.1 decoder% Input data is either from a bitstream file or a Matlab file.% For the case of a bitstream file, an optional frame error% file can be specified (contains an error flag for each frame)% $Id: ReadData.m 1.4 2004/08/06 G.723.1-v2r1a $% Read data for either a bitstream file or a Matlab fileQC = ReadInputFile (FNameI);% Declare errors as set by the frame error fileif (~ isempty (FNameErr)) QC = ReadErrFile (FNameErr, QC);end% Check for "forbidden codes"if (isfield (QC, 'FType')) NFrame = length (QC); for (i = 1:NFrame) if (CheckQCErr (QC(i))) QC(i) = NullStruct (QC(i)); QC(i).FType = 4; end endendreturn% ----------function [VC, BitStream] = ReadInputFile (FName)% Open the file for a peek at the first 6 charactersfid = fopen (FName, 'r');if (fid == -1) error ('G7231Decoder: Cannot open input file');endid = char (fread (fid, 6, 'uchar')');fclose (fid);BitStream = (~ strcmp (id, 'MATLAB'));% Read the fileif (BitStream) VC = ReadG7231Stream (FName);else load (FName, '-mat'); % Loads VC fprintf ('G723.1 data file: %s\n', FullName (FName));endreturn% ----------function QC = ReadErrFile (FName, QC)% Read the frame error file; set the frame type in QC% for error framesNFrame = length (QC);fid = fopen (FName, 'r', 'l'); % Little-endianif (fid == -1) error ('G7231Decoder: Cannot open input frame error file');endFErr = (fread (fid, Inf, 'uint16') ~= 0);fclose (fid);fprintf ('G.723.1 Frame error file: %s\n', FullName (FName));if (length (FErr) ~= NFrame) error ('G7231Decoder: Invalid frame error file length');end % Set FType for marked frames from the frame error filefor (i = 1:NFrame) if (FErr(i) ~= 0) QC(i) = NullStruct (QC(i)); QC(i).FType = 4; endendreturn% ----------function Err = CheckQCErr (QC)% Check whether the data has "forbidden" values% - The last 4 pitch lag values are forbidden% - The pitch coefficient values must be in boundsACBLCMax = 123; % PMax = ACBLCMax + 18ACBLCThr = 40; % LThr = ACBLCThr + 18, threshold for 85 codebook (MP only)GModV = {[1 24 2048]; [1 24]};Nb = [85; 170];Err = 0;if (QC.FType == 0 | QC.FType == 1) Err = (QC.ACBLC(1) > ACBLCMax | QC.ACBLC(3) > ACBLCMax); CBookI(1:4) = 2; if (QC.FType == 0) if (QC.ACBLC(1) < ACBLCThr) CBookI(1:2) = 1; end if (QC.ACBLC(3) < ACBLCThr) CBookI(3:4) = 1; end end for (i = 1:4) [gC, ACBbC] = ExtractVals (QC.CGC(i), GModV{CBookI(i)}); if (ACBbC >= Nb) Err = 1; end endendreturn% ----------function SN = NullStruct (S)% Create a structure element with null fields with the% same fields as an input structureSt = S(1); % Sample element from the stuctureFN = fieldnames (St);% St(2).(FN{1}) = []; % Only for Matlab 6.5 and latereval (['St(2).' FN{1} ' = [];']); % Create a null elementSN = St(2);return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -