16 bit - MATLAB: playing 16-bit audio -



16 bit - MATLAB: playing 16-bit audio -

i have matrix (n,16) filled sound samples of 16 bits each.

so matrix like:

[0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1; 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1]

and on. how can play sound? sound() using double floating points (from -1 1 values). if convert values, guess work, im not sure. suggestions?

@anderbiguri pretty much nailed it. take array, convert signed double, normalize , play it.

as have n x 16 matrix, each row sample , each column bit number, first need convert matrix double format. can utilize bin2dec help that. however, bin2dec takes in string. such, can convert our matrix string array so. let's assume insound contains sound matrix specified before.

i assume bits in big-endian format, important bit left bit, next downwards right bit.

according comments, numbers signed 1's compliment. means should important bit 1, invert entire number. such, can figure out rows negative checking entire first column see if there 1 or 0. find rows 1 , take 1 , subtract every single element in array. such:

checksign = insound(:,1) == 1; insound(checksign,:) = 1 - insound(checksign,1);

therefore, when convert our number decimal, find rows 1 time again should negative , negate them. let's convert our numbers first.

insoundstring = char(insound + '0');

char converts each number in matrix or vector string representation, assuming input char ascii code. such, when add together 0, adding each number in insound numerical ascii code representative of 0 in ascii. our baseline start with. after that, insound add together either 0 or 1 numerical code when convert whole matrix string, string representation of numbers.

now convert binary strings actual numbers:

outsounddec = bin2dec(insoundstring);

this take each row , convert decimal equivalent. now, if bits in little-endian, can utilize swapbytes flip bits can transform bits big-endian before proceeding. have converted our numbers, need negate rows supposed negative.

as such:

outsounddec(checksign) = -outsounddec(checksign);

now need normalize range between -1 1. given have specified range between [-32768, 32767], split of our numbers 32768. therefore:

outsound = outsounddec / 32768;

the above code normalize signal goes -1 1. can utilize sound(outsound, fs); play sound fs sampling frequency signal obtained at.

good luck!

matlab 16-bit

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -