summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Schleef <ds@schleef.org>2010-08-20 12:15:14 -0700
committerDavid Schleef <ds@schleef.org>2010-08-20 12:15:14 -0700
commit02ec311f66e21d23541830424bdb735a4d2df484 (patch)
tree022db8ec4ac72884074c4281dd478343f71af1c6 /examples
parent241a7ad309ee2969672500792933f6c0afe330ee (diff)
downloadorc-02ec311f66e21d23541830424bdb735a4d2df484.tar.gz
Update documentation, add tutorial
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am16
-rw-r--r--examples/example1.c58
-rw-r--r--examples/example1orc.orc8
-rw-r--r--examples/example2.c34
-rw-r--r--examples/example2orc.orc16
-rw-r--r--examples/example3.c24
-rw-r--r--examples/example3orc.orc23
7 files changed, 127 insertions, 52 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 921c980..012e7a9 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,5 +1,5 @@
-orcbin_PROGRAMS = example1 mt19937ar
+orcbin_PROGRAMS = example1 example2 example3 mt19937ar
if ENABLE_BACKEND_MMX
orcbin_PROGRAMS += volscale
@@ -8,3 +8,17 @@ endif
AM_LDFLAGS = $(ORC_LIBS)
AM_CFLAGS = $(ORC_CFLAGS)
+
+example1_SOURCES = example1.c example1orc.c example1orc.h
+example2_SOURCES = example2.c example2orc.c example2orc.h
+example3_SOURCES = example3.c example3orc.c example3orc.h
+
+update:
+ $(top_builddir)/tools/orcc$(EXEEXT) --implementation -o example1orc.c example1orc.orc
+ $(top_builddir)/tools/orcc$(EXEEXT) --header -o example1orc.h example1orc.orc
+ $(top_builddir)/tools/orcc$(EXEEXT) --implementation -o example2orc.c example2orc.orc
+ $(top_builddir)/tools/orcc$(EXEEXT) --header -o example2orc.h example2orc.orc
+ $(top_builddir)/tools/orcc$(EXEEXT) --implementation -o example3orc.c example3orc.orc
+ $(top_builddir)/tools/orcc$(EXEEXT) --header -o example3orc.h example3orc.orc
+
+
diff --git a/examples/example1.c b/examples/example1.c
index ad1630d..ee11c1f 100644
--- a/examples/example1.c
+++ b/examples/example1.c
@@ -1,34 +1,25 @@
-
-
#include <stdio.h>
-
-#include <orc/orcprogram.h>
+#include "example1orc.h"
#define N 10
-orc_int16 a[N];
-orc_int16 b[N];
-orc_int16 c[N];
-
-void add_s16(orc_int16 *dest, orc_int16 *src1, orc_int16 *src2, int n);
-
+short a[N];
+short b[N];
+short c[N];
int
main (int argc, char *argv[])
{
int i;
- /* orc_init() must be called before any other Orc function */
- orc_init ();
-
/* Create some data in the source arrays */
for(i=0;i<N;i++){
- a[i] = i;
- b[i] = 100;
+ a[i] = 100*i;
+ b[i] = 32000;
}
/* Call a function that uses Orc */
- add_s16 (c, a, b, N);
+ audio_add_s16 (c, a, b, N);
/* Print the results */
for(i=0;i<N;i++){
@@ -38,38 +29,3 @@ main (int argc, char *argv[])
return 0;
}
-void
-add_s16(orc_int16 *dest, orc_int16 *src1, orc_int16 *src2, int n)
-{
- static OrcProgram *p = NULL;
- OrcExecutor _ex;
- OrcExecutor *ex = &_ex;
-
- if (p == NULL) {
- /* First time through, create the program */
-
- /* Create a new program with two sources and one destination.
- * Size of the members of each array is 2. */
- p = orc_program_new_dss (2, 2, 2);
-
- /* Append an instruction to add the 2-byte values s1 and s2 (which
- * are the source arrays created above), and place the result in
- * the destination array d1, which was also create above. */
- orc_program_append_str (p, "addw", "d1", "s1", "s2");
-
- /* Compile the program. Ignore the very important result. */
- orc_program_compile (p);
- }
-
- /* Set the values on the executor structure */
- orc_executor_set_program (ex, p);
- orc_executor_set_n (ex, n);
- orc_executor_set_array_str (ex, "s1", src1);
- orc_executor_set_array_str (ex, "s2", src2);
- orc_executor_set_array_str (ex, "d1", dest);
-
- /* Run the program. This calls the code that was generated above,
- * or, if the compilation failed, will emulate the program. */
- orc_executor_run (ex);
-}
-
diff --git a/examples/example1orc.orc b/examples/example1orc.orc
new file mode 100644
index 0000000..6430f70
--- /dev/null
+++ b/examples/example1orc.orc
@@ -0,0 +1,8 @@
+
+.function audio_add_s16
+.dest 2 d1 short
+.source 2 s1 short
+.source 2 s2 short
+
+addssw d1, s1, s2
+
diff --git a/examples/example2.c b/examples/example2.c
new file mode 100644
index 0000000..c2d03e4
--- /dev/null
+++ b/examples/example2.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include "example2orc.h"
+
+#define N 10
+
+short a[N*2];
+short b[N];
+short c[N*2];
+
+int
+main (int argc, char *argv[])
+{
+ int i;
+ double volume = 0.5;
+
+ /* Create some data in the source arrays */
+ for(i=0;i<N;i++){
+ a[2*i] = 10*i;
+ a[2*i+1] = 100*i;
+ b[i] = (i&1) ? 10000 : -10000;
+ }
+
+ /* Call a function that uses Orc */
+ audio_add_mono_to_stereo_scaled_s16 (c, a, b, volume*4096, N);
+
+ /* Print the results */
+ for(i=0;i<N;i++){
+ printf("%d: %d,%d %d -> %d,%d\n", i, a[2*i], a[2*i+1], b[i],
+ c[2*i], c[2*i+1]);
+ }
+
+ return 0;
+}
+
diff --git a/examples/example2orc.orc b/examples/example2orc.orc
new file mode 100644
index 0000000..06a4de8
--- /dev/null
+++ b/examples/example2orc.orc
@@ -0,0 +1,16 @@
+
+.function audio_add_mono_to_stereo_scaled_s16
+.dest 4 d1 short
+.source 4 s1 short
+.source 2 s2 short
+.param 2 volume
+.temp 4 s2_scaled
+.temp 2 t
+.temp 4 s2_stereo
+
+mulswl s2_scaled, s2, volume
+shrsl s2_scaled, s2_scaled, 12
+convssslw t, s2_scaled
+mergewl s2_stereo, t, t
+x2 addssw d1, s1, s2_stereo
+
diff --git a/examples/example3.c b/examples/example3.c
new file mode 100644
index 0000000..5b04b3f
--- /dev/null
+++ b/examples/example3.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include "example3orc.h"
+
+#define N 10
+
+unsigned char input_y[640*480];
+unsigned char input_u[320*240];
+unsigned char input_v[320*240];
+
+unsigned int output[640*480];
+
+int
+main (int argc, char *argv[])
+{
+
+ /* Call a function that uses Orc */
+ convert_I420_AYUV (output, 1280*4, output + 640, 1280 * 4,
+ input_y, 1280, input_y + 640, 1280,
+ input_u, 320, input_v, 320,
+ 320, 240);
+
+ return 0;
+}
+
diff --git a/examples/example3orc.orc b/examples/example3orc.orc
new file mode 100644
index 0000000..2e06a50
--- /dev/null
+++ b/examples/example3orc.orc
@@ -0,0 +1,23 @@
+
+.function convert_I420_AYUV
+.flags 2d
+.dest 4 d1
+.dest 4 d2
+.source 1 y1
+.source 1 y2
+.source 1 u
+.source 1 v
+.const 1 c255 255
+.temp 2 uv
+.temp 2 ay
+.temp 1 tu
+.temp 1 tv
+
+loadupdb tu, u
+loadupdb tv, v
+mergebw uv, tu, tv
+mergebw ay, c255, y1
+mergewl d1, ay, uv
+mergebw ay, c255, y2
+mergewl d2, ay, uv
+