From 45dfb5debd4a0d0bc79ad8b6691576e8462d1396 Mon Sep 17 00:00:00 2001 From: David Doukhan Date: Mon, 7 Feb 2011 13:09:27 +0000 Subject: cw_binaural~ code and examples! Makefile still missing svn path=/trunk/externals/ddoukhan/cw_binaural~/; revision=14855 --- matlab_src/README.txt | 3 ++ matlab_src/cipicdb2wav.m | 132 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 matlab_src/README.txt create mode 100755 matlab_src/cipicdb2wav.m (limited to 'matlab_src') diff --git a/matlab_src/README.txt b/matlab_src/README.txt new file mode 100644 index 0000000..a4a7832 --- /dev/null +++ b/matlab_src/README.txt @@ -0,0 +1,3 @@ +This directory contains matlab source code used in our project. +For now, the only available code consists in concerting CIPIC hrtf database, stored in matlab binary file, into wav files that could be used by our system. +The CIPIC hrtf database can be downloaded there: http://interface.idav.ucdavis.edu/data/CIPIC_hrtf_database.zip diff --git a/matlab_src/cipicdb2wav.m b/matlab_src/cipicdb2wav.m new file mode 100755 index 0000000..a5151b1 --- /dev/null +++ b/matlab_src/cipicdb2wav.m @@ -0,0 +1,132 @@ +function cipicdb2wav(src_path, output_path) +%CIPICDB2WAV Summary of this function goes here +% src_path correspond to the root of extracted archive containing +% the CIPIC hrtf database which can be downloaded there +% http://interface.idav.ucdavis.edu/data/CIPIC_hrtf_database.zip +% +% output_path is the directory where the converted database will +% be stored, if the directory does not exists, it will be created + + mkdir(output_path) + + % get a list corresponding the the sets of measures to process + pl = build_processing_list(src_path); + + % those value indexes are given in the cipic documentation, + % they correspond to the azimuths and elevations available in the db + azimuths = [-80 -65 -55 -45:5:45 55 65 80]; + elevations = -45 + 5.625*(0:49); + + % the external uses listen database formalism + % see http://recherche.ircam.fr/equipes/salles/listen/ + % in listen database, angle(90,0) correspond to a point directly to the + % left, and angle(-90,0) correspond to a point directely to the right + % in CIPIC, this is inversed, meaning (90,0) correspond to right + % and so on + % consequenly, we intersed the azimuth angle label to correspond to + % listen formalism + azimuths = -1 * azimuths + + for ihrtf = 1:length(pl) + 'processing' + fname = char(pl(ihrtf,1)) + outdir_name = [output_path '/' char(pl(ihrtf,2))] + mkdir(outdir_name) + data = load(fname) + + for azn=1:length(azimuths) + for eln=1:length(elevations) + + az = azimuths(azn) + el = elevations(eln) + + leftir = squeeze(data.hrir_l(azn, eln,:)); + rightir = squeeze(data.hrir_r(azn, eln,:)); + + stereo(:,1) = leftir; + stereo(:,2) = rightir; + wav_name = sprintf('%s/%s_azim_%.3f_elev_%.3f.wav', outdir_name, char(pl(ihrtf,2)), az, el) + wavwrite(stereo, 44100, 32, wav_name); + end + end + end + +% out_dir='C:\\Users\\david\\Desktop\\\CIPIC_hrtf_database\\rudk_cipic_new'; +% +% azimuths = [-80 -65 -55 -45:5:45 55 65 80]; +% elevations = -45 + 5.625*(0:49); +% +% for ifile = 1:nfiles +% cur_dir = char(dir_list(ifile, :)); +% if cur_dir(1:8) == 'subject_' +% disp(cur_dir) +% cur_dir = strtrim(cur_dir); +% cur_out = [out_dir '\\' cur_dir] +% mkdir(cur_out); +% load([cur_dir '\\\\hrir_final.mat']); +% +% % indexed by azimuth, elevation, and time +% for iazi = 1:length(azimuths) +% for ielev = 1:length(elevations) +% left_data = hrir_l(iazi, ielev, :); +% right_data = hrir_r(iazi, ielev, :); +% [az, el] = normalize_az_el(azimuths(iazi), elevations(ielev)); +% wav_name = sprintf('%s\\%s_az_%d_elev_%.2f.wav', cur_out, cur_dir, az, el) +% stereo_data(:,1) = left_data; +% stereo_data(:,2) = right_data; +% wavwrite(stereo_data, 44100, 32, wav_name); +% if abs(el - 90) < .01 +% wav_name = sprintf('%s\\%s_az_%d_elev_%.2f.wav', cur_out, cur_dir, mod(az+180, 360), el); +% wavwrite(stereo_data, 44100, 32, wav_name); +% end +% end +% end +% end +% end +% +% function [res_az, res_el] = normalize_az_el(az, el) +% % elevation should be between - 90 and + 90 +% if el > 226 %% HACK +% +% 'hack' +% +% el = -(el - 225); +% az = az + 180; +% +% end +% +% if el > 90 + .005 +% el = 180 -el; +% az = 180 + az; +% end +% +% +% az = mod(az, 360); +% if (az < 0) +% az = az + 360; +% end +% +% res_az = az; +% res_el = el; + function res = build_processing_list(path) + res = [] + c = {'tutu','tata','titi'} + d = [c; {'tutu2','tata2','titi2'}] + e = [d; {'tutu3','tata4','titi5'}] + path + l = dir([path '/standard_hrir_database/subject_*']) + for i=1:length(l) + fullname = [path '/standard_hrir_database/' l(i).name '/hrir_final.mat'] + res = [res; {fullname, char(l(i).name)}] + end +% those files do not contains the same fields +% p = [path '/special_kemar_hrir/kemar_frontal/large_pinna_frontal.mat'] +% res = [res; {p, 'kemar_frontal_large_pinna'}] +% p = [path '/special_kemar_hrir/kemar_frontal/small_pinna_frontal.mat'] +% res = [res; {p, 'kemar_frontal_small_pinna'}] +% p = [path '/special_kemar_hrir/kemar_horizontal/large_pinna_final.mat'] +% res = [res; {p, 'kemar_horizontal_large_pinna'}] +% p = [path '/special_kemar_hrir/kemar_horizontal/small_pinna_final.mat'] +% res = [res; {p, 'kemar_horizontal_small_pinna'}] + end +end \ No newline at end of file -- cgit v1.2.1