Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2005

Tip: Looking for answers? Try searching our database.

bitwise problems&dpcm

Thread view: 
theo - 16 May 2005 01:33 GMT
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[i]=sndpcm1[i];
      }

     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[i]=snd[i]-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[i]=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[i]=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[i]=(byte)(snd[i-1]+diafores[i]);
     }
Wibble - 16 May 2005 02:36 GMT
Interesting, your code is as mixed up as your functional spec.

+
> Hello people,
> the problem is as follows :
[quoted text clipped - 77 lines]
>       snd[i]=(byte)(snd[i-1]+diafores[i]);
>      }
christopher@dailycrossword.com - 17 May 2005 03:09 GMT
I dream in code, too, but mine usually has a purpose, and I avoid
anything stronger than hops and alcohol . . .

"instead of music i hear only noise"

1)  Why do you think you should hear music?
2)  How do you know it is just noise?
3)  How is a "sample of sound" played on a PC anyway?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.