Updated get_sample_count_of_file to use new function for num of bytes/sample

main
David Protzman 2022-04-26 21:28:59 -04:00
rodzic 3213764d68
commit 94ee1b3602
1 zmienionych plików z 13 dodań i 4 usunięć

Wyświetl plik

@ -1,16 +1,25 @@
% Get the number of complex 32-bit floating point values in the specified file
% Get the number of complex values in the specified file using the provided sample type
%
% @param file_path Path to the file that contains complex 32-bit floating point samples
% @param sample_type MATLAB numeric class type for each I and Q value in the file. Ex: 'single', 'int16', 'int8', etc
% @return sample_count Number of complex 32-bit floating point samples in the provided input file
function [sample_count] = get_sample_count_of_file(file_path)
function [sample_count] = get_sample_count_of_file(file_path, sample_type)
handle = fopen(file_path, "r");
if (handle == 0)
error("Could not open input file '%s'"', file_path);
end
% Get how many bytes are required to make a single I or Q value
bytes_per_sample = get_bytes_per_sample(sample_type);
% Move to the end of the file
fseek(handle, 0, 'eof');
% Ask how many bytes into the file the pointer is currently
byte_count = ftell(handle);
fclose(handle);
sample_count = floor(byte_count / 4 / 2);
% Get the number of complex samples in the file. Flooring to ensure that if there are bytes missing those are not
% counted towards the total number of samples
sample_count = floor(byte_count / bytes_per_sample / 2);
end