[llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/Makefile README adpcm.c adpcm.h libst.h rawdaudio.c
Dinakar Dhurjati
dhurjati at cs.uiuc.edu
Tue Jan 11 10:05:47 PST 2005
Changes in directory llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio:
Makefile added (r1.1)
README added (r1.1)
adpcm.c added (r1.1)
adpcm.h added (r1.1)
libst.h added (r1.1)
rawdaudio.c added (r1.1)
---
Log message:
Added media bench to llvm-test
---
Diffs of the changes: (+468 -0)
Index: llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/Makefile
diff -c /dev/null llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/Makefile:1.1
*** /dev/null Tue Jan 11 12:05:46 2005
--- llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/Makefile Tue Jan 11 12:04:35 2005
***************
*** 0 ****
--- 1,11 ----
+ LEVEL = ../../../../..
+ STDIN_FILENAME = $(SourceDir)/../data/clinton.adpcm
+ PROG = rawdaudio
+
+ Source = rawdaudio.c adpcm.c
+
+ all::
+
+ include $(LEVEL)/MultiSource/Makefile.multisrc
+
+
Index: llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/README
diff -c /dev/null llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/README:1.1
*** /dev/null Tue Jan 11 12:05:47 2005
--- llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/README Tue Jan 11 12:04:35 2005
***************
*** 0 ****
--- 1,92 ----
+ This directory contains version 1.2 of a simple 16 bit PCM <-> 4 bit
+ ADPCM coder and decoder. See the source and the manpage for comments
+ on the algorithm.
+
+ If you have previously used version 1.0: there was a bug in it. This
+ version fixes the bug. (1.1 fixed that, but had another slight bug
+ that caused loss of quality on SGI machines).
+
+ The routines have been tested on an SGI Indigo running Irix 4 and
+ 5 and on a Sun Sparc SLC running SunOS 4.1.1. There are no real
+ machine dependencies, though, so there should be no problems on other
+ architectures.
+
+ There is a timing program to test how fast the stuff runs on your
+ machine. Here are some sample numbers:
+
+ R4000 Indigo: compress: 1.1Msample/sec, decompress: 1.7Msample/sec
+ R3000 Indigo: compress: 410Ksample/sec, decompress: 850Ksample/sec
+ Sun SLC: compress: 250Ksample/sec, decompress: 420Ksample/sec
+ Mac-IIsi compress 21Ksample/sec, decompress: 35Ksample/sec
+ 486/DX2-33 SCO: compress 550Ksample/sec, decompress: 865Ksample/sec
+ 486/33 linux: compress 278Ksample/sec, decompress: 464Ksample/sec
+ 386/33 gcc: compress 117Ksample/sec, decompress: 168Ksample/sec
+ (the Borland and MS compilers are a little slower)
+
+ Also included are some simple test programs that convert audio files
+ to/from 4bit ADPCM samples. Rawcaudio/rawdaudio convert to/from raw
+ 16bit PCM files; sgicaudio/sgidaudio convert to/from SGI AIFF files
+ and suncaudio/sundaudio convert to/from SUN/NeXT format audio files.
+ The Sun program was donated by Hughes Doug, hughes at sde.mdso.vf.ge.com
+ (it is actually only one program and looks at the program name to
+ decide whether to compress or decompress). Oh yeah, the sun and sgi
+ compressors will probably only compile on those machines. Also, for
+ the sgi compressor you need the Digital Media Developers Option.
+
+ Note: I have had to make a few changes to the sun audio converter, but
+ unfortunately I have no way of testing the result (since it needs
+ Solaris 1.somethingorother which I don't have). If the program does
+ not work and someone fixes it I would like to get a copy.
+
+ Finally, there is a uuencoded adpcm sound file of me saying "hello
+ world" (with a cold) that you can use to test that everything works
+ correctly.
+
+ If you use this package I would like to hear from you.
+ I am especially interested in people who can test interoperability
+ with proven Intel/DVI ADPCM coders. I have tried to get the algorithm
+ correct, but you never know....
+
+ Answers to often-asked questions:
+ - No, this is *not* a G.721 coder/decoder. The algorithm used by G.721
+ is very complicated, requiring oodles of floating-point ops per
+ sample (resulting in very poor performance). I have not done any
+ tests myself but various people have assured my that 721 quality is
+ actually lower than DVI quality.
+
+ - No, it probably isn't a RIFF ADPCM decoder either. Trying to decode
+ RIFF ADPCM with these routines seems to result in something
+ recognizable but very distorted.
+
+ - No, it is not a CDROM-XA coder either, as far as I know. I haven't
+ come across a good description of XA yet.
+
+ - No, testc and testd are not full-blown audio-file converters, only
+ simple test programs. If you write a file-converter (like caudio.c,
+ which compresses Sun audio files) and you're willing to donate it
+ I'd be very happy to include it in the distribution.
+
+ - No, I know of no standard audio file format that supports idvi
+ adpcm. If you find one, please let me know.
+
+ - Also, I know next-to-nothing about who IMA are. Their address, though,
+ from their May 1992 proceedings (where I got the algorithm from):
+ IMA Compatability Project Headquarters
+ 9 Randall Court
+ Annapolis MD 21401
+ USA
+
+ Phone: (410) 626-1380
+ Fax: (410) 263-0590
+
+ They might be able to send back issues of their proceedings, I don't
+ know.
+
+ Jack Jansen
+ Centre for Mathematics and Computer Science
+ Kruislaan 413
+ Amsterdam
+ the Netherlands
+
+ +31 20 592 4098
+ Jack.Jansen at cwi.nl
Index: llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/adpcm.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/adpcm.c:1.1
*** /dev/null Tue Jan 11 12:05:47 2005
--- llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/adpcm.c Tue Jan 11 12:04:35 2005
***************
*** 0 ****
--- 1,252 ----
+ /***********************************************************
+ Copyright 1992 by Stichting Mathematisch Centrum, Amsterdam, The
+ Netherlands.
+
+ All Rights Reserved
+
+ Permission to use, copy, modify, and distribute this software and its
+ documentation for any purpose and without fee is hereby granted,
+ provided that the above copyright notice appear in all copies and that
+ both that copyright notice and this permission notice appear in
+ supporting documentation, and that the names of Stichting Mathematisch
+ Centrum or CWI not be used in advertising or publicity pertaining to
+ distribution of the software without specific, written prior permission.
+
+ STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
+ THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
+ FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ ******************************************************************/
+
+ /*
+ ** Intel/DVI ADPCM coder/decoder.
+ **
+ ** The algorithm for this coder was taken from the IMA Compatability Project
+ ** proceedings, Vol 2, Number 2; May 1992.
+ **
+ ** Version 1.2, 18-Dec-92.
+ **
+ ** Change log:
+ ** - Fixed a stupid bug, where the delta was computed as
+ ** stepsize*code/4 in stead of stepsize*(code+0.5)/4.
+ ** - There was an off-by-one error causing it to pick
+ ** an incorrect delta once in a blue moon.
+ ** - The NODIVMUL define has been removed. Computations are now always done
+ ** using shifts, adds and subtracts. It turned out that, because the standard
+ ** is defined using shift/add/subtract, you needed bits of fixup code
+ ** (because the div/mul simulation using shift/add/sub made some rounding
+ ** errors that real div/mul don't make) and all together the resultant code
+ ** ran slower than just using the shifts all the time.
+ ** - Changed some of the variable names to be more meaningful.
+ */
+
+ #include "adpcm.h"
+ #include <stdio.h> /*DBG*/
+
+ #ifndef __STDC__
+ #define signed
+ #endif
+
+ /* Intel ADPCM step variation table */
+ static int indexTable[16] = {
+ -1, -1, -1, -1, 2, 4, 6, 8,
+ -1, -1, -1, -1, 2, 4, 6, 8,
+ };
+
+ static int stepsizeTable[89] = {
+ 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
+ 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
+ 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
+ 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
+ 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
+ 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
+ 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
+ 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
+ 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
+ };
+
+ void
+ adpcm_coder(indata, outdata, len, state)
+ short indata[];
+ char outdata[];
+ int len;
+ struct adpcm_state *state;
+ {
+ short *inp; /* Input buffer pointer */
+ signed char *outp; /* output buffer pointer */
+ int val; /* Current input sample value */
+ int sign; /* Current adpcm sign bit */
+ int delta; /* Current adpcm output value */
+ int diff; /* Difference between val and valprev */
+ int step; /* Stepsize */
+ int valpred; /* Predicted output value */
+ int vpdiff; /* Current change to valpred */
+ int index; /* Current step change index */
+ int outputbuffer; /* place to keep previous 4-bit value */
+ int bufferstep; /* toggle between outputbuffer/output */
+
+ outp = (signed char *)outdata;
+ inp = indata;
+
+ valpred = state->valprev;
+ index = state->index;
+ step = stepsizeTable[index];
+
+ bufferstep = 1;
+
+ for ( ; len > 0 ; len-- ) {
+ val = *inp++;
+
+ /* Step 1 - compute difference with previous value */
+ diff = val - valpred;
+ sign = (diff < 0) ? 8 : 0;
+ if ( sign ) diff = (-diff);
+
+ /* Step 2 - Divide and clamp */
+ /* Note:
+ ** This code *approximately* computes:
+ ** delta = diff*4/step;
+ ** vpdiff = (delta+0.5)*step/4;
+ ** but in shift step bits are dropped. The net result of this is
+ ** that even if you have fast mul/div hardware you cannot put it to
+ ** good use since the fixup would be too expensive.
+ */
+ delta = 0;
+ vpdiff = (step >> 3);
+
+ if ( diff >= step ) {
+ delta = 4;
+ diff -= step;
+ vpdiff += step;
+ }
+ step >>= 1;
+ if ( diff >= step ) {
+ delta |= 2;
+ diff -= step;
+ vpdiff += step;
+ }
+ step >>= 1;
+ if ( diff >= step ) {
+ delta |= 1;
+ vpdiff += step;
+ }
+
+ /* Step 3 - Update previous value */
+ if ( sign )
+ valpred -= vpdiff;
+ else
+ valpred += vpdiff;
+
+ /* Step 4 - Clamp previous value to 16 bits */
+ if ( valpred > 32767 )
+ valpred = 32767;
+ else if ( valpred < -32768 )
+ valpred = -32768;
+
+ /* Step 5 - Assemble value, update index and step values */
+ delta |= sign;
+
+ index += indexTable[delta];
+ if ( index < 0 ) index = 0;
+ if ( index > 88 ) index = 88;
+ step = stepsizeTable[index];
+
+ /* Step 6 - Output value */
+ if ( bufferstep ) {
+ outputbuffer = (delta << 4) & 0xf0;
+ } else {
+ *outp++ = (delta & 0x0f) | outputbuffer;
+ }
+ bufferstep = !bufferstep;
+ }
+
+ /* Output last step, if needed */
+ if ( !bufferstep )
+ *outp++ = outputbuffer;
+
+ state->valprev = valpred;
+ state->index = index;
+ }
+
+ void
+ adpcm_decoder(indata, outdata, len, state)
+ char indata[];
+ short outdata[];
+ int len;
+ struct adpcm_state *state;
+ {
+ signed char *inp; /* Input buffer pointer */
+ short *outp; /* output buffer pointer */
+ int sign; /* Current adpcm sign bit */
+ int delta; /* Current adpcm output value */
+ int step; /* Stepsize */
+ int valpred; /* Predicted value */
+ int vpdiff; /* Current change to valpred */
+ int index; /* Current step change index */
+ int inputbuffer; /* place to keep next 4-bit value */
+ int bufferstep; /* toggle between inputbuffer/input */
+
+ outp = outdata;
+ inp = (signed char *)indata;
+
+ valpred = state->valprev;
+ index = state->index;
+ step = stepsizeTable[index];
+
+ bufferstep = 0;
+
+ for ( ; len > 0 ; len-- ) {
+
+ /* Step 1 - get the delta value */
+ if ( bufferstep ) {
+ delta = inputbuffer & 0xf;
+ } else {
+ inputbuffer = *inp++;
+ delta = (inputbuffer >> 4) & 0xf;
+ }
+ bufferstep = !bufferstep;
+
+ /* Step 2 - Find new index value (for later) */
+ index += indexTable[delta];
+ if ( index < 0 ) index = 0;
+ if ( index > 88 ) index = 88;
+
+ /* Step 3 - Separate sign and magnitude */
+ sign = delta & 8;
+ delta = delta & 7;
+
+ /* Step 4 - Compute difference and new predicted value */
+ /*
+ ** Computes 'vpdiff = (delta+0.5)*step/4', but see comment
+ ** in adpcm_coder.
+ */
+ vpdiff = step >> 3;
+ if ( delta & 4 ) vpdiff += step;
+ if ( delta & 2 ) vpdiff += step>>1;
+ if ( delta & 1 ) vpdiff += step>>2;
+
+ if ( sign )
+ valpred -= vpdiff;
+ else
+ valpred += vpdiff;
+
+ /* Step 5 - clamp output value */
+ if ( valpred > 32767 )
+ valpred = 32767;
+ else if ( valpred < -32768 )
+ valpred = -32768;
+
+ /* Step 6 - Update step value */
+ step = stepsizeTable[index];
+
+ /* Step 7 - Output value */
+ *outp++ = valpred;
+ }
+
+ state->valprev = valpred;
+ state->index = index;
+ }
Index: llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/adpcm.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/adpcm.h:1.1
*** /dev/null Tue Jan 11 12:05:47 2005
--- llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/adpcm.h Tue Jan 11 12:04:35 2005
***************
*** 0 ****
--- 1,19 ----
+ /*
+ ** adpcm.h - include file for adpcm coder.
+ **
+ ** Version 1.0, 7-Jul-92.
+ */
+
+ struct adpcm_state {
+ short valprev; /* Previous output value */
+ char index; /* Index into stepsize table */
+ };
+
+ #ifdef __STDC__
+ #define ARGS(x) x
+ #else
+ #define ARGS(x) ()
+ #endif
+
+ void adpcm_coder ARGS((short [], char [], int, struct adpcm_state *));
+ void adpcm_decoder ARGS((char [], short [], int, struct adpcm_state *));
Index: llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/libst.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/libst.h:1.1
*** /dev/null Tue Jan 11 12:05:47 2005
--- llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/libst.h Tue Jan 11 12:04:35 2005
***************
*** 0 ****
--- 1,65 ----
+ /* libst.h - include file for portable sound tools library
+ **
+ ** Copyright (C) 1989 by Jef Poskanzer.
+ **
+ ** Permission to use, copy, modify, and distribute this software and its
+ ** documentation for any purpose and without fee is hereby granted, provided
+ ** that the above copyright notice appear in all copies and that both that
+ ** copyright notice and this permission notice appear in supporting
+ ** documentation. This software is provided "as is" without express or
+ ** implied warranty.
+ */
+
+ #define SAMPLES_PER_SECOND 8192
+
+ #define MINLIN -32768
+ #define MAXLIN 32767
+ #define LINCLIP(x) do { if ( x < MINLIN ) x = MINLIN ; else if ( x > MAXLIN ) x = MAXLIN; } while ( 0 )
+
+ unsigned char st_linear_to_ulaw( /* int sample */ );
+ int st_ulaw_to_linear_slow( /* unsigned char ulawbyte */ );
+
+ /*
+ ** This macro converts from ulaw to 16 bit linear, faster.
+ **
+ ** Jef Poskanzer
+ ** 23 October 1989
+ **
+ ** Input: 8 bit ulaw sample
+ ** Output: signed 16 bit linear sample
+ */
+ #define st_ulaw_to_linear(ulawbyte) ulaw_table[ulawbyte]
+
+ static int ulaw_table[256] = {
+ -32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956,
+ -23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764,
+ -15996, -15484, -14972, -14460, -13948, -13436, -12924, -12412,
+ -11900, -11388, -10876, -10364, -9852, -9340, -8828, -8316,
+ -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140,
+ -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092,
+ -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004,
+ -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980,
+ -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436,
+ -1372, -1308, -1244, -1180, -1116, -1052, -988, -924,
+ -876, -844, -812, -780, -748, -716, -684, -652,
+ -620, -588, -556, -524, -492, -460, -428, -396,
+ -372, -356, -340, -324, -308, -292, -276, -260,
+ -244, -228, -212, -196, -180, -164, -148, -132,
+ -120, -112, -104, -96, -88, -80, -72, -64,
+ -56, -48, -40, -32, -24, -16, -8, 0,
+ 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956,
+ 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764,
+ 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412,
+ 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316,
+ 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140,
+ 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092,
+ 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004,
+ 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980,
+ 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436,
+ 1372, 1308, 1244, 1180, 1116, 1052, 988, 924,
+ 876, 844, 812, 780, 748, 716, 684, 652,
+ 620, 588, 556, 524, 492, 460, 428, 396,
+ 372, 356, 340, 324, 308, 292, 276, 260,
+ 244, 228, 212, 196, 180, 164, 148, 132,
+ 120, 112, 104, 96, 88, 80, 72, 64,
+ 56, 48, 40, 32, 24, 16, 8, 0 };
Index: llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/rawdaudio.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/rawdaudio.c:1.1
*** /dev/null Tue Jan 11 12:05:47 2005
--- llvm-test/MultiSource/Benchmarks/mediabench/adpcm/rawdaudio/rawdaudio.c Tue Jan 11 12:04:35 2005
***************
*** 0 ****
--- 1,29 ----
+ /* testd - Test adpcm decoder */
+
+ #include "adpcm.h"
+ #include <stdio.h>
+
+ struct adpcm_state state;
+
+ #define NSAMPLES 1000
+
+ char abuf[NSAMPLES/2];
+ short sbuf[NSAMPLES];
+
+ main() {
+ int n;
+
+ while(1) {
+ n = read(0, abuf, NSAMPLES/2);
+ if ( n < 0 ) {
+ perror("input file");
+ exit(1);
+ }
+ if ( n == 0 ) break;
+ adpcm_decoder(abuf, sbuf, n*2, &state);
+ write(1, sbuf, n*4);
+ }
+ fprintf(stderr, "Final valprev=%d, index=%d\n",
+ state.valprev, state.index);
+ exit(0);
+ }
More information about the llvm-commits
mailing list