HydrogenAudio

Misc. => Off-Topic => Topic started by: S_O on 2002-10-04 22:27:56

Title: Need Help
Post by: S_O on 2002-10-04 22:27:56
I´m trying to build a little vorbis-encoder based on nic´s oggencgui RC3.
The problem is that his wav-reading algorithm works only for 16Bit mono or Stereo:
Code: [Select]
float **buffer=vorbis_analysis_buffer(&vd,READ);
   
   // uninterleave samples
   for(i=0;i<bytes/(2*channels);i++)
   {
     buffer[0][i]=((readbuffer[(i*2*channels)+1]<<8)|
      (0x00ff&(int)readbuffer[i*2*channels]))/32768.f;
     if ( channels == 2 )
     buffer[1][i]=((readbuffer[i*4+3]<<8)|
      (0x00ff&(int)readbuffer[i*4+2]))/32768.f;
   }

I was able to modfie the code that it reads mono, stereo and 4ch in 16bit.(it was ment to be read all channles, but that didn´t worked).
Then I looked into the sources (audio.c) of oggenc and that came out:
Code: [Select]
float **buffer=vorbis_analysis_buffer(&vd,READ);
   
   // uninterleave samples
       if (wavformat == 1)
   {
(readbuffer,1,4*4*channels, in);
   bytesread += bytes;
   SetProgressBar(IDC_PROGRESS1,(int)(((float)((float)bytesread/(float)filelen))*100));
 long realsamples = bytes/((bitps/8) * channels);
 if(bitps==8) //
 {
     unsigned char *bufu = (unsigned char *)readbuffer;
     for(i = 0; i < realsamples; i++)
     {
   for(j=0; j < channels; j++)
   {
       buffer[j][i]=((int)(bufu[i*channels + j])-128)/128.0f;
   }
     }
 }
 if(bitps==12)
 {
     unsigned char *bufu = (unsigned char *)readbuffer;
     for(i = 0; i < realsamples; i++)
     {
   for(j=0; j < channels; j++)
   {
       buffer[j][i]=((int)(bufu[i*channels + j])-2048)/2048.0f;
   }
     }
 }
 if(bitps==16)
 {
     for(i = 0; i < realsamples; i++)
     {
   for(j=0; j < channels; j++)
   {
       buffer[j][i] = ((readbuffer[i*2*channels + 2*j + 1]<<8) |
              (readbuffer[i*2*channels + 2*j + 0] & 0xff))/32768.0f;
   }
     }
 }
 if(bitps==24)
 {
     for(i = 0; i < realsamples; i++)
     {
   for(j=0; j < channels; j++)
   {
       buffer[j][i] = ((readbuffer[i*2*channels + 2*j + 1]<<8) |
              (readbuffer[i*2*channels + 2*j + 0] & 0xff))/8388608.0f;
   }
     }
 }
   }
   if (wavformat == 3)
   {

     bytesread += bytes;
     SetProgressBar(IDC_PROGRESS1,(int)(((float)((float)bytesread/(float)filelen))*100));
     for(i=0; i < bytes/(samplesize*channels); i++)
     {
   for(j=0; j < channels; j++)
   {
       buffer[j][i] = readbuffer[i*channels + j];
   }
     }
   }

Notes: READ = 1024; bitps = Bits per sample; samplesize = bitps/8, if wavformat == 3 samplesize = 4.
This code is much longer, but doesn´t work much better. 8Bit and 16Bit int-pcm is working with mono, stereo and 4ch. 3ch or 6ch is not working, it encodes, but it´s just noise. 24Bit-int and 32bit-float also completly doesn´t work, just noise, too. I don´t know with 12bit, because I didn´t found a programm creating 12bit-wav.
anybody here how could help me? my programming knowledge is very limited so I´m not able to find a solution.