Index: roard/codecfilter_roardmx.c
===================================================================
--- roard/codecfilter_roardmx.c	(revision 5977)
+++ roard/codecfilter_roardmx.c	(revision 5980)
@@ -156,5 +156,5 @@
 
  for (i = 0; i < g_light_state.channels; i++) {
-  if ( g_light_state.changes[i] ) {
+  if ( g_light_state.outputchanges[i] ) {
    if ( !have_message )
     if ( roar_roardmx_message_new_sset(&mes) == -1 )
@@ -163,5 +163,5 @@
    have_message = 2;
 
-   if ( roar_roardmx_message_add_chanval(&mes, i, g_light_state.state[i]) == -1 ) {
+   if ( roar_roardmx_message_add_chanval(&mes, i, g_light_state.output[i]) == -1 ) {
     if ( roar_roardmx_message_send(&mes, &(ss->vio)) == -1 )
      return -1;
Index: roard/include/light.h
===================================================================
--- roard/include/light.h	(revision 5961)
+++ roard/include/light.h	(revision 5980)
@@ -40,4 +40,6 @@
  uint8_t * state;
  uint8_t * changes;
+ uint8_t * output;
+ uint8_t * outputchanges;
 } g_light_state;
 
Index: roard/light.c
===================================================================
--- roard/light.c	(revision 5961)
+++ roard/light.c	(revision 5980)
@@ -53,4 +53,17 @@
  if ( (g_light_state.changes = roar_mm_malloc(channels)) == NULL ) {
   roar_mm_free(g_light_state.state);
+  return -1;
+ }
+
+ if ( (g_light_state.output = roar_mm_malloc(channels)) == NULL ) {
+  roar_mm_free(g_light_state.state);
+  roar_mm_free(g_light_state.changes);
+  return -1;
+ }
+
+ if ( (g_light_state.outputchanges = roar_mm_malloc(channels)) == NULL ) {
+  roar_mm_free(g_light_state.state);
+  roar_mm_free(g_light_state.changes);
+  roar_mm_free(g_light_state.output);
   return -1;
  }
@@ -87,4 +100,12 @@
  }
 
+ if ( g_light_state.output != NULL ) {
+  roar_mm_free(g_light_state.changes);
+ }
+
+ if ( g_light_state.outputchanges != NULL ) {
+  roar_mm_free(g_light_state.changes);
+ }
+
  g_light_state.channels = 0;
 
@@ -102,5 +123,20 @@
   return -1;
 
- memset(g_light_state.state,   0, g_light_state.channels);
+ memset(g_light_state.state,         0, g_light_state.channels);
+ memset(g_light_state.changes,       0, g_light_state.channels);
+ memset(g_light_state.output,        0, g_light_state.channels);
+ memset(g_light_state.outputchanges, 0, g_light_state.channels);
+ memset(g_light_state.events,        0, sizeof(g_light_state.events));
+
+ g_light_state.eventsqueuelen = 0;
+
+ return 0;
+}
+
+// called at end of mainloop.
+int light_reinit(void) {
+ if ( g_light_state.changes == NULL )
+  return -1;
+
  memset(g_light_state.changes, 0, g_light_state.channels);
  memset(g_light_state.events,  0, sizeof(g_light_state.events));
@@ -111,17 +147,25 @@
 }
 
-int light_reinit(void) {
- if ( g_light_state.changes == NULL )
-  return -1;
-
- memset(g_light_state.changes, 0, g_light_state.channels);
- memset(g_light_state.events,  0, sizeof(g_light_state.events));
-
- g_light_state.eventsqueuelen = 0;
-
- return 0;
-}
-
+// called at mid of mainloop.
 int light_update(void) {
+ uint8_t * tmp;
+ unsigned int c;
+
+ // swap buffers:
+ // after that step we have the old values in outputchanges and output is a fresh buffer.
+ tmp = g_light_state.outputchanges;
+ g_light_state.outputchanges = g_light_state.output;
+ g_light_state.output = tmp;
+
+ // copy data for filters:
+ memcpy(g_light_state.output, g_light_state.state, g_light_state.channels);
+
+ // TODO: next run filters
+
+ // calculate diffrence:
+ // after this step we have only teh changes in the outputchanges array.
+ for (c = 0; c < g_light_state.channels; c++)
+  g_light_state.outputchanges[c] ^= g_light_state.output[c];
+
  return 0;
 }
@@ -180,8 +224,8 @@
 
  if ( chans == 512 ) {
-  bufptr = g_light_state.state;
+  bufptr = g_light_state.output;
  } else {
   memset(buf, 0, 512);
-  memcpy(buf, g_light_state.state, chans);
+  memcpy(buf, g_light_state.output, chans);
   bufptr = buf;
  }
Index: roard/loop.c
===================================================================
--- roard/loop.c	(revision 5979)
+++ roard/loop.c	(revision 5980)
@@ -93,4 +93,7 @@
   midi_update();
 #endif
+#ifndef ROAR_WITHOUT_DCOMP_LIGHT
+  light_update();
+#endif
 
   if ( waveform_update_inputs() == -1 )
