File: rtSGI.c

package info (click to toggle)
csound 1%3A4.23f12-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,132 kB
  • ctags: 17,345
  • sloc: ansic: 101,063; cpp: 7,730; perl: 335; makefile: 318; tcl: 82
file content (146 lines) | stat: -rw-r--r-- 5,123 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*  
    rtSGI.c:

    Copyright (C) 1991 Barry Vercoe

    This file is part of Csound.

    The Csound Library is free software; you can redistribute it
    and/or modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    Csound is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with Csound; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA
*/

/*                                                  RTAUDIO.C for SGI  */

/*  This module is included when RTAUDIO is defined at compile time.
    It provides an interface between Csound realtime record/play calls
    and the device-driver code that controls the actual hardware.
 */

#include "cs.h"
#include "soundio.h"

#include <stdio.h>
#include <audio.h>
static  ALconfig iconfig, oconfig;
static  ALport   iport = NULL, oport = NULL;

static  int     ishift = 0, oshift = 0, oMaxLag;
extern  OPARMS  O;
#ifdef PIPES
#  define _pclose pclose
#endif

static int getshift(int dsize)  /* turn sample- or frame-size into shiftsize */
{
    switch(dsize) {
    case 1:  return(0);
    case 2:  return(1);
    case 4:  return(2);
    case 8:  return(3);
    default: die(Str(X_1169,"rtaudio: illegal dsize"));
      return(-1);               /* Not reached */
    }
}

void recopen_(int nchanls, int dsize, float sr, int scale)
                                /* open for audio input */
{
    oMaxLag = O.oMaxLag;        /* import DAC setting from command line   */
    if (oMaxLag <= 0)           /* if DAC sampframes ndef in command line */
      oMaxLag = IODACSAMPS;     /*    use the default value               */
    iconfig = ALnewconfig();
    ALsetchannels(iconfig, (long)nchanls);
    ALsetwidth(iconfig, (long)dsize);
    /*      ALsetsamplerate(iconfig, (long)sr);    */
    {
      long cmdBuf[2];
      cmdBuf[0] = AL_INPUT_RATE;
      cmdBuf[1] = (long)esr;
      ALsetparams(AL_DEFAULT_DEVICE,cmdBuf,2);
    }
    ALsetqueuesize(iconfig, (long)oMaxLag);
    iport = ALopenport("soundi", "r", iconfig);
    ishift = getshift(dsize);
}

void playopen_(int nchanls, int dsize, float sr, int scale)
                                /* open for audio output */
{
    int b = 0;

    oMaxLag = O.oMaxLag;        /* import DAC setting from command line   */
    if (oMaxLag <= 0)           /* if DAC sampframes ndef in command line */
      oMaxLag = IODACSAMPS;     /*    use the default value               */
    {
      int PMLqueuesize;
      oconfig = ALnewconfig();
      ALsetchannels(oconfig, (long)nchanls);
      ALsetwidth(oconfig, (long)dsize);
      /*      ALsetsamplerate(oconfig, (long)sr);    */
      {
        long cmdBuf[2];
        cmdBuf[0] = AL_OUTPUT_RATE;
        cmdBuf[1] = (long)sr;
        ALsetparams(AL_DEFAULT_DEVICE,cmdBuf,2);
      }
      ALsetqueuesize(oconfig, (long)oMaxLag);
      PMLqueuesize = ALgetqueuesize(oconfig);
      printf("\n PMLqueuesize = %d\n", PMLqueuesize);
      oport = ALopenport("soundo", "w", oconfig);
      oshift = getshift(dsize);
    }
}

int rtrecord_(char *inbuf, int nbytes) /* get samples from ADC */
{
    ALreadsamps(iport, inbuf, (long)nbytes >> ishift);
    return(nbytes);
}

void rtplay_(char *outbuf, int nbytes) /* put samples to DAC  */
    /* N.B. This routine serves as a THROTTLE in Csound Realtime Performance, */
    /* delaying the actual writes and return until the hardware output buffer */
    /* passes a sample-specific THRESHOLD.  If the I/O BLOCKING functionality */
    /* is implemented ACCURATELY by the vendor-supplied audio-library write,  */
    /* that is sufficient.  Otherwise, requires some kind of IOCTL from here. */
    /* This functionality is IMPORTANT when other realtime I/O is occurring,  */
    /* such as when external MIDI data is being collected from a serial port. */
    /* Since Csound polls for MIDI input at the software synthesis K-rate     */
    /* (the resolution of all software-synthesized events), the user can      */
    /* eliminate MIDI jitter by requesting that both be made synchronous with */
    /* the above audio I/O blocks, i.e. by setting -b to some 1 or 2 K-prds.  */
{
    long sampframes = nbytes >> oshift;
    ALwritesamps(oport, outbuf, sampframes);
    nrecs++;
}

void rtclose_(void)              /* close the I/O device entirely  */
{                                /* called only when both complete */
    if (iport != NULL)
      ALcloseport(iport);
    if (oport != NULL) {
      while (ALgetfilled(oport) > 0)
        sginap(1);
      ALcloseport(oport);
    }
    if (O.Linein) {
#ifdef PIPES
      if (O.Linename[0]=='|') _pclose(Linepipe);
      else
#endif
        if (strcmp(O.Linename, "stdin")!=0) close(Linefd);
    }
}