T
theo
Hello people,
the problem is as follows :
i am given an array of bytes called sndpcm1[] , in every nibble of each
byte there is a signed integer in the range -8 to +7 . From this array i
am supposed to make another array of bytes in which the real values are
stored.The real values are taken by adding the value of the previous
element with the value of the corresponding nibble(dpcm).So the new
array of bytes which i call snd[] will be double the length of
sndpcm1[].The values in snd[] are samples of sound which are then played
on my pc.The most significant nibble of every byte has priority over the
least significant nibble.i tried this dpcm->pcm conversion with the
following code and the question is whether this piece of code does the
conversion right,cause instead of music i hear only noise.
byte[] sndpcm2 = new byte[sndpcm1.length];
for (int i=0;i<=sndpcm2.length-1;i++)
{
sndpcm2=sndpcm1;
}
byte[] snd = new byte[2*sndpcm1.length]; //the values of the
//waveform
diafores = new byte[2*sndpcm1.length];//array that contains in
//every byte the difference among two bytes of snd[] :
//diafores=snd-snd[i-1]
for (int i=0,j=0 ; (i<=(diafores.length-2)) ; i+=2,j++ ) //get
//the most significant nibble out if a byte
{
sndpcm1[j]>>>=4;
sndpcm1[j]<<=4;
if (sndpcm1[j]<0)
{
sndpcm1[j]<<=1;
sndpcm1[j]>>>=5;
sndpcm1[j]=(byte)(sndpcm1[j]|0x80);
}
else
{
sndpcm1[j]>>>=4;
}
diafores=sndpcm1[j];
}
for (int
i=1,j=0;(i<=(2*sndpcm2.length-1))&&(j<=(sndpcm2.length-1));i+=2,j++)
//least significant nibble
{
sndpcm2[j]<<=4;
if (sndpcm2[j]<0)
{
sndpcm2[j]<<=1;
sndpcm2[j]>>>=5;
sndpcm2[j]=(byte)(sndpcm2[j]|0x80);
}
else
{
sndpcm2[j]>>>=4;
}
diafores=sndpcm2[j];
}
System.out.println("diafores size is : "+diafores.length );
System.out.println("sound size is : "+snd.length );
snd[0]=diafores[0];
for (int i=1;i<=snd.length-1;i++)
{
snd=(byte)(snd[i-1]+diafores);
}
the problem is as follows :
i am given an array of bytes called sndpcm1[] , in every nibble of each
byte there is a signed integer in the range -8 to +7 . From this array i
am supposed to make another array of bytes in which the real values are
stored.The real values are taken by adding the value of the previous
element with the value of the corresponding nibble(dpcm).So the new
array of bytes which i call snd[] will be double the length of
sndpcm1[].The values in snd[] are samples of sound which are then played
on my pc.The most significant nibble of every byte has priority over the
least significant nibble.i tried this dpcm->pcm conversion with the
following code and the question is whether this piece of code does the
conversion right,cause instead of music i hear only noise.
byte[] sndpcm2 = new byte[sndpcm1.length];
for (int i=0;i<=sndpcm2.length-1;i++)
{
sndpcm2=sndpcm1;
}
byte[] snd = new byte[2*sndpcm1.length]; //the values of the
//waveform
diafores = new byte[2*sndpcm1.length];//array that contains in
//every byte the difference among two bytes of snd[] :
//diafores=snd-snd[i-1]
for (int i=0,j=0 ; (i<=(diafores.length-2)) ; i+=2,j++ ) //get
//the most significant nibble out if a byte
{
sndpcm1[j]>>>=4;
sndpcm1[j]<<=4;
if (sndpcm1[j]<0)
{
sndpcm1[j]<<=1;
sndpcm1[j]>>>=5;
sndpcm1[j]=(byte)(sndpcm1[j]|0x80);
}
else
{
sndpcm1[j]>>>=4;
}
diafores=sndpcm1[j];
}
for (int
i=1,j=0;(i<=(2*sndpcm2.length-1))&&(j<=(sndpcm2.length-1));i+=2,j++)
//least significant nibble
{
sndpcm2[j]<<=4;
if (sndpcm2[j]<0)
{
sndpcm2[j]<<=1;
sndpcm2[j]>>>=5;
sndpcm2[j]=(byte)(sndpcm2[j]|0x80);
}
else
{
sndpcm2[j]>>>=4;
}
diafores=sndpcm2[j];
}
System.out.println("diafores size is : "+diafores.length );
System.out.println("sound size is : "+snd.length );
snd[0]=diafores[0];
for (int i=1;i<=snd.length-1;i++)
{
snd=(byte)(snd[i-1]+diafores);
}