/[rdesktop]/jpeg/rdesktop/trunk/rdpsnd_dsp.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /jpeg/rdesktop/trunk/rdpsnd_dsp.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1285 by stargo, Sun Oct 1 18:22:05 2006 UTC revision 1291 by stargo, Sun Oct 1 23:42:14 2006 UTC
# Line 183  rdpsnd_dsp_resample(unsigned char **out, Line 183  rdpsnd_dsp_resample(unsigned char **out,
183          int ratio1k = (resample_to_srate * 1000) / format->nSamplesPerSec;          int ratio1k = (resample_to_srate * 1000) / format->nSamplesPerSec;
184  #endif  #endif
185          int innum, outnum;          int innum, outnum;
186          static BOOL warned = False;          unsigned char *tmpdata = NULL, *tmp = NULL;
         unsigned char *tmpdata = NULL;  
187          int samplewidth = format->wBitsPerSample / 8;          int samplewidth = format->wBitsPerSample / 8;
188          int outsize = 0;          int outsize = 0;
189          int i;          int i;
# Line 199  rdpsnd_dsp_resample(unsigned char **out, Line 198  rdpsnd_dsp_resample(unsigned char **out,
198                  rdpsnd_dsp_swapbytes(in, size, format);                  rdpsnd_dsp_swapbytes(in, size, format);
199  #endif  #endif
200    
201            if (resample_to_channels != format->nChannels)
202            {
203                    int newsize = (size / format->nChannels) * resample_to_channels;
204                    tmpdata = xmalloc(newsize);
205    
206                    for (i = 0; i < newsize / samplewidth; i++)
207                    {
208                            if (format->nChannels > resample_to_channels)
209                                    memcpy(tmpdata + (i * samplewidth),
210                                           in +
211                                           (((i * format->nChannels) / resample_to_channels) *
212                                            samplewidth), samplewidth);
213                            else
214                                    memcpy(tmpdata + (i * samplewidth),
215                                           in +
216                                           (((i / resample_to_channels) * format->nChannels +
217                                             (i % format->nChannels)) * samplewidth), samplewidth);
218    
219                    }
220    
221                    in = tmpdata;
222                    size = newsize;
223            }
224    
225    
226          /* Expand 8bit input-samples to 16bit */          /* Expand 8bit input-samples to 16bit */
227  #ifndef HAVE_LIBSAMPLERATE      /* libsamplerate needs 16bit samples */  #ifndef HAVE_LIBSAMPLERATE      /* libsamplerate needs 16bit samples */
228          if (format->wBitsPerSample != resample_to_bitspersample)          if (format->wBitsPerSample != resample_to_bitspersample)
# Line 207  rdpsnd_dsp_resample(unsigned char **out, Line 231  rdpsnd_dsp_resample(unsigned char **out,
231                  /* source: 8 bit, dest: 16bit */                  /* source: 8 bit, dest: 16bit */
232                  if (format->wBitsPerSample == 8)                  if (format->wBitsPerSample == 8)
233                  {                  {
234                            tmp = tmpdata;
235                          tmpdata = xmalloc(size * 2);                          tmpdata = xmalloc(size * 2);
236                          for (i = 0; i < size; i++)                          for (i = 0; i < size; i++)
237                          {                          {
# Line 216  rdpsnd_dsp_resample(unsigned char **out, Line 241  rdpsnd_dsp_resample(unsigned char **out,
241                          in = tmpdata;                          in = tmpdata;
242                          samplewidth = 16 / 2;                          samplewidth = 16 / 2;
243                          size *= 2;                          size *= 2;
                 }  
         }  
244    
245          if (resample_to_channels != format->nChannels)                          if (tmp != NULL)
246          {                                  xfree(tmp);
247                  warning("unsupported resample-settings (%u -> %u/%u -> %u/%u -> %u), not resampling!\n", format->nSamplesPerSec, resample_to_srate, format->wBitsPerSample, resample_to_bitspersample, format->nChannels, resample_to_channels);                  }
                 warned = True;  
248          }          }
249    
250          innum = size / samplewidth;          innum = size / samplewidth;
# Line 277  rdpsnd_dsp_resample(unsigned char **out, Line 299  rdpsnd_dsp_resample(unsigned char **out,
299    
300          for (i = 0; i < outsize / (resample_to_channels * samplewidth); i++)          for (i = 0; i < outsize / (resample_to_channels * samplewidth); i++)
301          {          {
302                  int source = ((i * 1000) + ratio1k - 1000) / (ratio1k + 1);                  int source = (i * 1000) / ratio1k;
303                    int j;
304    
305                  if (source * resample_to_channels + samplewidth > size)                  if (source * resample_to_channels + samplewidth > size)
306                          break;                          break;
307    
308                  if (resample_to_channels == 2)                  for (j = 0; j < resample_to_channels; j++)
                 {  
                         memcpy(*out + (i * resample_to_channels * samplewidth),  
                                in + (source * resample_to_channels * samplewidth), samplewidth);  
                         memcpy(*out + (i * resample_to_channels * samplewidth) + samplewidth,  
                                in + (source * resample_to_channels * samplewidth) + samplewidth,  
                                samplewidth);  
                 }  
                 else  
309                  {                  {
310                          memcpy(*out + (i * samplewidth), in + (source * samplewidth), samplewidth);                          memcpy(*out + (i * resample_to_channels * samplewidth) + (samplewidth * j),
311                                   in + (source * resample_to_channels * samplewidth) +
312                                   (samplewidth * j), samplewidth);
313                  }                  }
314          }          }
315          outsize = i * resample_to_channels * samplewidth;          outsize = i * resample_to_channels * samplewidth;

Legend:
Removed from v.1285  
changed lines
  Added in v.1291

  ViewVC Help
Powered by ViewVC 1.1.26