~ubuntu-branches/ubuntu/karmic/mhwaveedit/karmic

« back to all changes in this revision

Viewing changes to src/dataformat.c

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2008-01-08 22:20:37 UTC
  • mfrom: (2.1.6 hardy)
  • Revision ID: james.westby@ubuntu.com-20080108222037-tsazhckl5vmc8yih
Tags: 1.4.14-2
Added desktop file (Closes: #457849), thanks to Marco Rodrigues

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2002 2003 2004 2005, Magnus Hjorth
 
2
 * Copyright (C) 2002 2003 2004 2005 2006, Magnus Hjorth
3
3
 *
4
4
 * This file is part of mhWaveEdit.
5
5
 *
20
20
 
21
21
#include <config.h>
22
22
 
 
23
#ifndef _GNU_SOURCE
23
24
#define _GNU_SOURCE
 
25
#endif
24
26
 
25
27
#include <string.h>
26
28
#include <stdlib.h>
327
329
static void dither_convert_double(double *indata, char *outdata, int count,
328
330
                                  convert_function fn, int outdata_ssize)
329
331
{
330
 
     float amp_factor;
331
 
     float databuf[4096];
 
332
     double amp_factor;
 
333
     double databuf[4096];
332
334
     int i,j;
333
335
     amp_factor = pow(2.0,(double)(1-outdata_ssize*8));
334
336
     while (count > 0) {
335
337
          i = MIN(count,ARRAY_LENGTH(databuf));
336
 
          memcpy(databuf,indata,count*sizeof(double));
 
338
          memcpy(databuf,indata,i*sizeof(double));
337
339
          for (j=0; j<i; j++)
338
340
               databuf[j] += (((double)(rand()/2 + rand()/2))/
339
341
                              ((double)RAND_MAX)) * amp_factor;
340
 
          fn(databuf,outdata,count);
 
342
          fn(databuf,outdata,i);
341
343
          indata += i;
342
344
          outdata += outdata_ssize * i;
343
345
          count -= i;
349
351
                   guint count, int dither_mode)
350
352
{     
351
353
     int i;
 
354
     char *c;
352
355
     if (dataformat_samples_equal(indata_format,outdata_format)) {
353
356
          memcpy(outdata,indata,count*indata_format->samplesize);
354
357
     } else if (indata_format->type == DATAFORMAT_PCM) {
356
359
               /* PCM -> PCM conversion */
357
360
               if (outdata_format->samplesize > indata_format->samplesize)
358
361
                    dither_mode = DITHER_NONE;
359
 
               char *c;
360
362
               c = g_malloc(count * sizeof(sample_t));         
361
363
               convert_array(indata,indata_format,c,&dataformat_sample_t,
362
364
                             count,dither_mode);
380
382
               (outdata_format->bigendian?2:0) + 
381
383
               (indata_format->samplesize/sizeof(double));
382
384
          g_assert(i < ARRAY_LENGTH(fp_pcm_functions));
 
385
          g_assert(dither_mode != DITHER_UNSPEC);
383
386
          if (dither_mode != DITHER_NONE) {
384
387
               if (indata_format->samplesize == sizeof(float))
385
388
                    dither_convert_float(indata,outdata,count,
407
410
     }
408
411
}
409
412
 
 
413
gint unnormalized_count(sample_t *buf, gint count)
 
414
{
 
415
     gint i,c=0;
 
416
     for (i=0; i<count; i++)
 
417
          if (buf[i] > 1.0 || buf[i] < -1.0)
 
418
               c++;
 
419
     return c;
 
420
}
 
421
 
410
422
static void print_format(Dataformat *fmt)
411
423
{
412
424
     if (fmt->type == DATAFORMAT_FLOAT) {