Digital Audio programming the standard audio format and audio - TopicsExpress



          

Digital Audio programming the standard audio format and audio theory and math by Damian Recoskie sound is vibration so the binary numbers normally move up and down faster or slower in the numbers that you give to the audio PCM device in audio you are using trigonometry such as sine(X) to produce perfect curves of vibration the rate that you send that numbers at in one second is called the sample rate nowadays there are fancy names but I still like sample rate if you make the numbers in your data that is sent in one second move up and down once using angles of sine you produce an 1 hertz frequency The sample rate is measured in how meany numbers you send to the PCM in one second how does sample rate and frequency connect for example: if you try to create an sine frequency that is 10 hertz and store the curve that moves up and down 10 times in one second and the sample in one second can only hold 3 numbers in one second how do you store each point that moves up and down in the one second in the 3 points? we would need at least an sample rate of 20 so at least send 20 numbers to the PCM in one second to store the points that go up and down in the one second of the 10 sine curves that go up and down 10x2=20 but this would make the magnet to move straight in and out with 20 numbers in an second this is not an sine curve it is similar to an square wave we want to be able to store nice curves of vibration so the sound sounds the most natural so if we use the number PI=3.1415926535 and multiply it by 10 we get 31 so we need at least an sample rate of 31.4x2=62.8 round 63 hertz today in recording audio we use samples that can store the highest frequency that are to the highest an human can hear our ears are only so sensitive when something vibrates two quickly we can no longer hear it because the hairs in our ears have to vibrate in resonates to the frequency vibration and this is to do with the length of the hairs in our ears and nervous system. The commonly stated range of human hearing is 20 Hz to 20 kHz have you ever noticed that when you click the rate of an song you have selections in the forum of 20 kHz except the highest frequency we can hear is different than storing each point of the perfect tone of frequency of it so we ask the question what can hold the the full sine curve at the highest frequency we can hear to loose as little quality as possible in recoding we calculate 20 kHz=20000 and multiply by PI 20000*3.1415926535=62831.85307 then round it 62832 convert it back to kilo in metric 62.832 kHz we also know that some times the smaller points and tangents do not record accurately some times so to get it perfect we double it 62.832 kHz so 62.832*2=125.664 we round it to 126 kHz so technically 126 kHz is the best audio quality possible but because it was easier to store it as 128 kHz in digital memory this is the minimal best quality In audio an audio track is just numbers most tracks are 128 kHz an second now for example if you want to calculate an 1 hertz frequency in 128 kHz we convert it from its metric value back to the unit of measurement called hertz so 128000 points in one second we calculate 128000 angles of sine in degrees it would look like this 0 to 360 but out of 360 we need 128000 points so 360 divided by 128000 is 0.0028125 if you multiply this by 0.0028125x128000=360 which is the last angle of sine so it look like this sine(0.0028125xPoint) the value of point adds by one till 128000 if you want this to continue for tow seconds you go 128000x2=256000 you have point add by one till 256000 this makes two samples with sine going up and down once in each second and stops at 256000. lastly is the size of the numbers you use for each sine point for example 8 bit mans eight binary digits long and have an max value of 0 to 255 do you see how this becomes an problem the sample rate can be perfect but if you have only an max possible of points of 255 up and down the magnet in the speaker cone makes bigger leaps from up one value or down one value in the cone for values 0 to 255 so in an way it is like an bunch of stepping tones though the curve we do not want this aether. 8 bit = 0-255 = 2^8-1 16 bit = 0-65535 = 2^16-1 32 bit = 0-4294967295 = 2^32-1 64 bit = 0-18446744073709551615 = 2^64-1 64 bit numbers and 32 bit numbers are the best 8 bit sucks it might sound ok on an very low volume but the louder it is the farther apart the spaces are when going up one value in the curve or down when I am talking about this aspect of audio I am taking about possible combinations the speaker magnet has to move in and out. sine(0.0028125xPoint)*18446744073709551615 in programming it looks like this sine((360/SampleRate)*Point)*64BitMaxValue the users selected Sample rate is divided into 360 and Point is added by one and is stored into an array the bit size to each binary number is 2^8-1=255 it work this way because binary is only two digits and decimal is ten digits so 10^1-1=9 and 10^2-1=99 and 10^3-1=999 is the same in our number system because we count to 10 before so every multiple of 10 is the next column value and minus one is max value but an 8 bit number in binary is 8 digits and we go 2^8-1=255 In programming / is divide and * is multiply and sine is called Math.sin() the input goes into the parentheses and Math.PI is the number PI=3.1415926535 and the sine function in the computer uses radians instead of degrees like on the calculator to calculate an point out of 360 in sine we use Math.sin(Math.PI/180*degrees) we divide PI=3.1415926535 into 180 so what we must calculate is half of 360 Math.sin(Math.PI/(360/2)*degrees) is 360/2=180 the computer uses the sine taylor series sine((360/SampleRate)*Point) this changes to Math.sin(Math.PI/(360/2)*degrees) changes to Math.sin(Math.PI/(SampleRate/2)*Point)*64BitMaxValue what if we want it to move up and down more than once in the sample rate to produce an frequency of sine in one second faster than one time in an second of the sample rate the easy way is to divide the sample rate by 2 then it will move up and down tow times before reaching the end of the sample in one second producing an two hertz frequency in one second so it now looks like this Math.sin(Math.PI/((SampleRate/Frequency)/2)*Point)*64BitMaxValue so if you want it to move up and down three times you pretend the sample is 3 times smaller by dividing sample rate by 3 so it moves up and down in an third of the sample and continues till the end of the sample in one second because the variable point is added by one till the end of the sample in one second so now we have the variable Frequency we even have to where we can adjust the sample rate quality but remember too small of an sample rate might clip parts of the curves of sine in programming we use arrays to store an set of numbers for example 64 bit numbers are called ULONGLONG if you are using C++ or C but for now lets keep it simple and show it in java int[] sample=new int[size]; the variable name is named sample for example if the int array size is 5 int[] sample=new int[5]; we can access each number in the int like this sample[0]=1 sample[1]=4 sample[2]=7 sample[3]=9 sample[4]=20 if we want an number from the array we go int value=sample[3] and it will set our variable value the number 9 because we set the third element 9 above the first element is always 0 the last element is always minus one to its size you gave it this will create an 32 bit sample because integers are 32 bit we made this integer array five in size and indeed we assigned 5 numbers to the array called sample because it starts at 0 and 0 is not worth anything and we count upwards there are still five elements just that it stops at 4 because 0 is the first element now the next step to this code is an loop so it can make all the points of sine into an sample array so we have an loop called an for loop what this does is you define what variable you will use for the for loop and start at 0 in this case so we write for(int point=0; the semicolon identified the end of the variables we are using in the for loop we now have to make an algebraic expression that is true till the end of the sample so we write for(int point=0;point
Posted on: Sun, 17 Aug 2014 22:06:44 +0000

Trending Topics



Recently Viewed Topics




© 2015