/[rdesktop]/sourceforge.net/trunk/rdesktop/rdpsnd_sun.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/rdpsnd_sun.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 477 by matthewc, Sat Oct 4 12:24:56 2003 UTC revision 561 by stargo, Thu Dec 11 15:07:04 2003 UTC
# Line 26  Line 26 
26  #include <errno.h>  #include <errno.h>
27  #include <sys/ioctl.h>  #include <sys/ioctl.h>
28  #include <sys/audioio.h>  #include <sys/audioio.h>
29    
30    #if (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
31  #include <stropts.h>  #include <stropts.h>
32    #endif
33    
34  #define MAX_QUEUE       10  #define MAX_QUEUE       10
35    
36  int g_dsp_fd;  int g_dsp_fd;
37  BOOL g_dsp_busy;  BOOL g_dsp_busy = False;
38  static BOOL reopened;  static BOOL g_reopened;
39  static BOOL swapaudio;  static BOOL g_swapaudio;
40  static short samplewidth;  static short g_samplewidth;
41    
42  static struct audio_packet {  static struct audio_packet
43    {
44          struct stream s;          struct stream s;
45          uint16 tick;          uint16 tick;
46          uint8 index;          uint8 index;
# Line 48  wave_out_open(void) Line 52  wave_out_open(void)
52  {  {
53          char *dsp_dev = getenv("AUDIODEV");          char *dsp_dev = getenv("AUDIODEV");
54    
55          if ( dsp_dev == NULL )          if (dsp_dev == NULL)
56          {          {
57                  dsp_dev="/dev/audio";                  dsp_dev = "/dev/audio";
58          }          }
59    
60          if ((g_dsp_fd = open(dsp_dev, O_WRONLY|O_NONBLOCK)) == -1)          if ((g_dsp_fd = open(dsp_dev, O_WRONLY | O_NONBLOCK)) == -1)
61          {          {
62                  perror(dsp_dev);                  perror(dsp_dev);
63                  return False;                  return False;
64          }          }
65    
66          /* Non-blocking so that user interface is responsive */          /* Non-blocking so that user interface is responsive */
67          fcntl(g_dsp_fd, F_SETFL, fcntl(g_dsp_fd, F_GETFL)|O_NONBLOCK);          fcntl(g_dsp_fd, F_SETFL, fcntl(g_dsp_fd, F_GETFL) | O_NONBLOCK);
68            
69          queue_lo = queue_hi = 0;          queue_lo = queue_hi = 0;
70          reopened = True;          g_reopened = True;
71            
72          return True;          return True;
73  }  }
74    
# Line 72  void Line 76  void
76  wave_out_close(void)  wave_out_close(void)
77  {  {
78          /* Ack all remaining packets */          /* Ack all remaining packets */
79          while ( queue_lo != queue_hi )          while (queue_lo != queue_hi)
80          {          {
81                  rdpsnd_send_completion(packet_queue[queue_lo].tick, packet_queue[queue_lo].index);                  rdpsnd_send_completion(packet_queue[queue_lo].tick, packet_queue[queue_lo].index);
82                  free(packet_queue[queue_lo].s.data);                  free(packet_queue[queue_lo].s.data);
83                  queue_lo = (queue_lo + 1) % MAX_QUEUE;                  queue_lo = (queue_lo + 1) % MAX_QUEUE;
84          }          }
85    
86    #if defined I_FLUSH && defined FLUSHW
87          /* Flush the audiobuffer */          /* Flush the audiobuffer */
88          ioctl(g_dsp_fd,I_FLUSH,FLUSHW);          ioctl(g_dsp_fd, I_FLUSH, FLUSHW);
89    #endif
90    #if defined AUDIO_FLUSH
91            ioctl(g_dsp_fd, AUDIO_FLUSH, NULL);
92    #endif
93          close(g_dsp_fd);          close(g_dsp_fd);
94  }  }
95    
96  BOOL  BOOL
97  wave_out_format_supported(WAVEFORMATEX *pwfx)  wave_out_format_supported(WAVEFORMATEX * pwfx)
98  {  {
99          if (pwfx->wFormatTag != WAVE_FORMAT_PCM)          if (pwfx->wFormatTag != WAVE_FORMAT_PCM)
100                  return False;                  return False;
# Line 98  wave_out_format_supported(WAVEFORMATEX * Line 107  wave_out_format_supported(WAVEFORMATEX *
107  }  }
108    
109  BOOL  BOOL
110  wave_out_set_format(WAVEFORMATEX *pwfx)  wave_out_set_format(WAVEFORMATEX * pwfx)
111  {  {
112          audio_info_t info;          audio_info_t info;
113          int test = 1;          int test = 1;
114    
115          ioctl(g_dsp_fd, AUDIO_DRAIN, 0);          ioctl(g_dsp_fd, AUDIO_DRAIN, 0);
116          swapaudio = False;          g_swapaudio = False;
117          AUDIO_INITINFO(&info);          AUDIO_INITINFO(&info);
118    
119    
120          if (pwfx->wBitsPerSample == 8)          if (pwfx->wBitsPerSample == 8)
121          {          {
122                  info.play.encoding = AUDIO_ENCODING_LINEAR8;                  info.play.encoding = AUDIO_ENCODING_LINEAR8;
                 samplewidth = 1;  
123          }          }
124          else if (pwfx->wBitsPerSample == 16)          else if (pwfx->wBitsPerSample == 16)
125          {          {
126                  info.play.encoding = AUDIO_ENCODING_LINEAR;                  info.play.encoding = AUDIO_ENCODING_LINEAR;
                 samplewidth = 2;  
127                  /* Do we need to swap the 16bit values? (Are we BigEndian) */                  /* Do we need to swap the 16bit values? (Are we BigEndian) */
128                  swapaudio = !(*(uint8 *) (&test));                  g_swapaudio = !(*(uint8 *) (&test));
129          }          }
130    
131          if (pwfx->nChannels == 1 )          g_samplewidth = pwfx->wBitsPerSample / 8;
132          {        
133                  info.play.channels = AUDIO_CHANNELS_MONO;          if (pwfx->nChannels == 1)
134            {
135                    info.play.channels = 1;
136          }          }
137          else if (pwfx->nChannels == 2 )          else if (pwfx->nChannels == 2)
138          {          {
139                  info.play.channels = AUDIO_CHANNELS_STEREO;                  info.play.channels = 2;
140                  samplewidth *= 2;                  g_samplewidth *= 2;
141          }          }
142    
143          info.play.sample_rate = pwfx->nSamplesPerSec;          info.play.sample_rate = pwfx->nSamplesPerSec;
# Line 136  wave_out_set_format(WAVEFORMATEX *pwfx) Line 145  wave_out_set_format(WAVEFORMATEX *pwfx)
145          info.play.samples = 0;          info.play.samples = 0;
146          info.play.eof = 0;          info.play.eof = 0;
147          info.play.error = 0;          info.play.error = 0;
148            g_reopened = True;
149    
150          if (ioctl(g_dsp_fd, AUDIO_SETINFO, &info) == -1)          if (ioctl(g_dsp_fd, AUDIO_SETINFO, &info) == -1)
151          {          {
# Line 148  wave_out_set_format(WAVEFORMATEX *pwfx) Line 158  wave_out_set_format(WAVEFORMATEX *pwfx)
158  }  }
159    
160  void  void
161    wave_out_volume(uint16 left, uint16 right)
162    {
163            audio_info_t info;
164            uint balance;
165            uint volume;
166    
167            if (ioctl(g_dsp_fd, AUDIO_GETINFO, &info) == -1)
168            {
169                    perror("AUDIO_GETINFO");
170                    return;
171            }
172    
173            volume = (left > right) ? left : right;
174    
175            if (volume / AUDIO_MID_BALANCE != 0)
176            {
177                    balance =
178                            AUDIO_MID_BALANCE - (left / (volume / AUDIO_MID_BALANCE)) +
179                            (right / (volume / AUDIO_MID_BALANCE));
180            }
181            else
182            {
183                    balance = AUDIO_MID_BALANCE;
184            }
185    
186            info.play.gain = volume / (65536 / AUDIO_MAX_GAIN);
187            info.play.balance = balance;
188    
189            if (ioctl(g_dsp_fd, AUDIO_SETINFO, &info) == -1)
190            {
191                    perror("AUDIO_SETINFO");
192                    return;
193            }
194    }
195    
196    void
197  wave_out_write(STREAM s, uint16 tick, uint8 index)  wave_out_write(STREAM s, uint16 tick, uint8 index)
198  {  {
199          struct audio_packet *packet = &packet_queue[queue_hi];          struct audio_packet *packet = &packet_queue[queue_hi];
# Line 158  wave_out_write(STREAM s, uint16 tick, ui Line 204  wave_out_write(STREAM s, uint16 tick, ui
204                  error("No space to queue audio packet\n");                  error("No space to queue audio packet\n");
205                  return;                  return;
206          }          }
207            
208          queue_hi = next_hi;          queue_hi = next_hi;
209    
210          packet->s = *s;          packet->s = *s;
211          packet->tick = tick;          packet->tick = tick;
212          packet->index = index;          packet->index = index;
213            packet->s.p += 4;
214    
215          /* we steal the data buffer from s, give it a new one */          /* we steal the data buffer from s, give it a new one */
216          s->data = malloc(s->size);          s->data = malloc(s->size);
# Line 188  wave_out_play(void) Line 235  wave_out_play(void)
235    
236          while (1)          while (1)
237          {          {
238                  if ( reopened )                  if (g_reopened)
239                  {                  {
240                          /* Device was just (re)openend */                          /* Device was just (re)openend */
241                          samplecnt = 0;                          samplecnt = 0;
242                          swapped = False;                          swapped = False;
243                          sentcompletion = True;                          sentcompletion = True;
244                          reopened = False;                          g_reopened = False;
245                  }                  }
246    
247                  if (queue_lo == queue_hi)                  if (queue_lo == queue_hi)
# Line 207  wave_out_play(void) Line 254  wave_out_play(void)
254                  out = &packet->s;                  out = &packet->s;
255    
256                  /* Swap the current packet, but only once */                  /* Swap the current packet, but only once */
257                  if ( swapaudio && ! swapped )                  if (g_swapaudio && !swapped)
258                  {                  {
259                          for ( i = 0; i < out->end - out->p; i+=2 )                          for (i = 0; i < out->end - out->p; i += 2)
260                          {                          {
261                                  swap = *(out->p + i);                                  swap = *(out->p + i);
262                                  *(out->p + i ) = *(out->p + i + 1);                                  *(out->p + i) = *(out->p + i + 1);
263                                  *(out->p + i + 1) = swap;                                  *(out->p + i + 1) = swap;
                                 swapped = True;  
264                          }                          }
265                            swapped = True;
266                  }                  }
267    
268                  if ( sentcompletion )                  if (sentcompletion)
269                  {                  {
270                          sentcompletion = False;                          sentcompletion = False;
271                          numsamples = (out->end - out->p)/samplewidth;                          numsamples = (out->end - out->p) / g_samplewidth;
272                  }                  }
273    
274                  len=0;                  len = 0;
275    
276                  if ( out->end != out->p )                  if (out->end != out->p)
277                  {                  {
278                          len = write(g_dsp_fd, out->p, out->end - out->p);                          len = write(g_dsp_fd, out->p, out->end - out->p);
279                          if (len == -1)                          if (len == -1)
# Line 248  wave_out_play(void) Line 295  wave_out_play(void)
295                          }                          }
296    
297                          /* Ack the packet, if we have played at least 70% */                          /* Ack the packet, if we have played at least 70% */
298                          if ( info.play.samples >= samplecnt+((numsamples*7)/10) )                          if (info.play.samples >= samplecnt + ((numsamples * 7) / 10))
299                          {                          {
300                                  samplecnt += numsamples;                                  samplecnt += numsamples;
301                                  rdpsnd_send_completion(packet->tick, packet->index);                                  rdpsnd_send_completion(packet->tick, packet->index);

Legend:
Removed from v.477  
changed lines
  Added in v.561

  ViewVC Help
Powered by ViewVC 1.1.26