prefect
Home Engineering Publications
DACS: Mixer Mid-Level Driver Code, mixer.c
 
  next up previous contents
Next: CDROM Service Provider Communications Up: MIDI Controller Previous: Mixer Mid-Level Driver Header,   Contents

Mixer Mid-Level Driver Code, mixer.c

This code handles DACS mixer mid-level functionality. This code is mostly responsible for handling single MIDI controller to multiple mixer register translations (e.g. pan knobs, etc.).
/*****************************************************************************
 * DACS : Distributed Audio Control System
 *============================================================================
 *         File: mixer.c
 *       Author: Stephen S. Richardson
 * Date Created: 04.21.97
 *  Environment: GNU C Compiler (GCC) v2.7.1, Linux i486 v2.0.28
 *        Build: make
 *============================================================================
 * The code, executables, documentation, firmware images, and all related
 * material of DACS are  
 * Copyright (C) 1997 Stephen S. Richardson - ALL RIGHTS RESERVED
 *****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/types.h>
#include <time.h>
#include <sys/time.h>
#include "mixer.h"
#include "midi.h"

/*****************************************************************************
 * controller_translate
 *
 * translate MIDI controllers to DACS 411 mixer register data.
 * kind of kludgy, but functional.
 *****************************************************************************/
void controller_translate (struct mix_control *mc, int fd)
{
  float lev;
  unsigned char pan, luleft[128], luright[128], newl, newr, obuf[10];
  unsigned char fl1,fl2;
  int i,r;

  for (i=0;i<64;i++) {
    luleft[i]=127;
    luright[i]=(i*2)+1;
  }
  for (i=64;i<128;i++) {
    luleft[i]=127-((i-64)*2);
    luright[i]=127;
  }

  fl1=0;
  fl2=0;

  for (i=0;i<32;i++) {
    
    lev=(float) mc->midictrl[i] / 127.0;
    pan=mc->midictrl[i+64];
    
    newl = (unsigned char) luleft[pan] * lev;
    if (newl != mc->chipreg[i]) {
      mc->chipreg[i] = newl;
      
      if (fl1) usleep(150);

      obuf[0]=MIDICMD_CONTROL;
      obuf[1]=i;
      obuf[2]=newl;
      
      r=0;
      do {
	r+=write (fd, obuf, 3);
      } while (r<3);

      fl2=1;

    }

    newr = (unsigned char) luright[pan] * lev;
    if (newr != mc->chipreg[i+32]) {
      mc->chipreg[i+32] = newr;

      if (fl2) usleep (150);

      obuf[0]=MIDICMD_CONTROL;
      obuf[1]=i+32;
      obuf[2]=newr;
      
      r=0;
      do {
	r+=write (fd, obuf, 3);
      } while (r<3);

      fl1=1;

    }
    
  }
}


/*****************************************************************************
 * mixer_reset
 *
 * resets the DACS mixer.
 *****************************************************************************/
void mixer_reset (struct midi_stream *ms)
{
  int r;
  char resbyte=0xFF;

  r=0;
  do {
    r=write (ms->fd, &resbyte, 1);
  } while (r<1);
}


Steve Richardson 2000-07-06
Table of Contents

[PDF] [Whole document in PDF 1.9MB]

[more photos and information]

 
Page last modified:
Copyright © 1993-2000 prefect - All Rights Reserved.