Blame examples/ex1.c

Packit c948fe
/*
Packit c948fe
 *  Copyright (C) 2004 Steve Harris
Packit c948fe
 *
Packit c948fe
 *  This program is free software; you can redistribute it and/or modify
Packit c948fe
 *  it under the terms of the GNU General Public License as published by
Packit c948fe
 *  the Free Software Foundation; either version 2 of the License, or
Packit c948fe
 *  (at your option) any later version.
Packit c948fe
 *
Packit c948fe
 *  This program is distributed in the hope that it will be useful,
Packit c948fe
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit c948fe
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit c948fe
 *  GNU General Public License for more details.
Packit c948fe
 *
Packit c948fe
 *  $Id: ex1.c $
Packit c948fe
 */
Packit c948fe
Packit c948fe
#include <stdio.h>
Packit c948fe
#include <stdint.h>
Packit c948fe
#include <math.h>
Packit c948fe
Packit c948fe
#define SIZE 256
Packit c948fe
Packit c948fe
#include "gdither.h"
Packit c948fe
Packit c948fe
int main(int argc, char *argv[])
Packit c948fe
{
Packit c948fe
    GDither ds;
Packit c948fe
    float in[SIZE];	    /* test input data */
Packit c948fe
    double ind[SIZE];	    /* test input data */
Packit c948fe
    int32_t out32[SIZE];    /* test output data: 1 chan 32bit */
Packit c948fe
    int16_t out16[SIZE][4]; /* test output data: 4 chan 16bit */
Packit c948fe
    float outf[SIZE];	    /* test output data: 1 chan float */
Packit c948fe
    int i;
Packit c948fe
Packit c948fe
    /* --- Example 1a --- */
Packit c948fe
Packit c948fe
    /* create an arbitrary sinewave for testing */
Packit c948fe
    for (i=0; i
Packit c948fe
	ind[i] = sin(i);
Packit c948fe
	in[i] = ind[i];
Packit c948fe
    }
Packit c948fe
Packit c948fe
    /* create a dither object that produces 32bit ints, triangular dithered to
Packit c948fe
     * 24 bits */
Packit c948fe
    ds = gdither_new(GDitherTri, 1, GDither32bit, 24);
Packit c948fe
Packit c948fe
    /* run the dother algorithm over the input data */
Packit c948fe
    gdither_runf(ds, 0, SIZE, in, out32);
Packit c948fe
Packit c948fe
    /* free the dither object */
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    /* --- Example 1b --- */
Packit c948fe
Packit c948fe
    /* create a dither object to produce rounded (undithered) 4 channel
Packit c948fe
     * interleaved 16bit output */
Packit c948fe
    ds = gdither_new(GDitherNone, 4, GDither16bit, 16);
Packit c948fe
    gdither_runf(ds, 0, SIZE, in, out16);
Packit c948fe
    gdither_runf(ds, 1, SIZE, in, out16);
Packit c948fe
    gdither_runf(ds, 2, SIZE, in, out16);
Packit c948fe
    gdither_runf(ds, 3, SIZE, in, out16);
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    /* --- Example 1c --- */
Packit c948fe
Packit c948fe
    /* create a dither object to produce float output rectangular dithered to
Packit c948fe
     * 24 bits from double data */
Packit c948fe
    ds = gdither_new(GDitherRect, 4, GDitherFloat, 24);
Packit c948fe
    gdither_run(ds, 0, SIZE, ind, outf);
Packit c948fe
    gdither_free(ds);
Packit c948fe
Packit c948fe
    return 0;
Packit c948fe
}
Packit c948fe
Packit c948fe
/* vi:set ts=8 sts=4 sw=4: */