/[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 491 by stargo, Mon Oct 13 16:09:45 2003 UTC revision 499 by astrand, Wed Oct 15 14:01:32 2003 UTC
# Line 36  static BOOL reopened; Line 36  static BOOL reopened;
36  static BOOL swapaudio;  static BOOL swapaudio;
37  static short samplewidth;  static short samplewidth;
38    
39  static struct audio_packet {  static struct audio_packet
40    {
41          struct stream s;          struct stream s;
42          uint16 tick;          uint16 tick;
43          uint8 index;          uint8 index;
# Line 48  wave_out_open(void) Line 49  wave_out_open(void)
49  {  {
50          char *dsp_dev = getenv("AUDIODEV");          char *dsp_dev = getenv("AUDIODEV");
51    
52          if ( dsp_dev == NULL )          if (dsp_dev == NULL)
53          {          {
54                  dsp_dev="/dev/audio";                  dsp_dev = "/dev/audio";
55          }          }
56    
57          if ((g_dsp_fd = open(dsp_dev, O_WRONLY|O_NONBLOCK)) == -1)          if ((g_dsp_fd = open(dsp_dev, O_WRONLY | O_NONBLOCK)) == -1)
58          {          {
59                  perror(dsp_dev);                  perror(dsp_dev);
60                  return False;                  return False;
61          }          }
62    
63          /* Non-blocking so that user interface is responsive */          /* Non-blocking so that user interface is responsive */
64          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);
65            
66          queue_lo = queue_hi = 0;          queue_lo = queue_hi = 0;
67          reopened = True;          reopened = True;
68            
69          return True;          return True;
70  }  }
71    
# Line 72  void Line 73  void
73  wave_out_close(void)  wave_out_close(void)
74  {  {
75          /* Ack all remaining packets */          /* Ack all remaining packets */
76          while ( queue_lo != queue_hi )          while (queue_lo != queue_hi)
77          {          {
78                  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);
79                  free(packet_queue[queue_lo].s.data);                  free(packet_queue[queue_lo].s.data);
# Line 80  wave_out_close(void) Line 81  wave_out_close(void)
81          }          }
82    
83          /* Flush the audiobuffer */          /* Flush the audiobuffer */
84          ioctl(g_dsp_fd,I_FLUSH,FLUSHW);          ioctl(g_dsp_fd, I_FLUSH, FLUSHW);
85          close(g_dsp_fd);          close(g_dsp_fd);
86  }  }
87    
88  BOOL  BOOL
89  wave_out_format_supported(WAVEFORMATEX *pwfx)  wave_out_format_supported(WAVEFORMATEX * pwfx)
90  {  {
91          if (pwfx->wFormatTag != WAVE_FORMAT_PCM)          if (pwfx->wFormatTag != WAVE_FORMAT_PCM)
92                  return False;                  return False;
# Line 98  wave_out_format_supported(WAVEFORMATEX * Line 99  wave_out_format_supported(WAVEFORMATEX *
99  }  }
100    
101  BOOL  BOOL
102  wave_out_set_format(WAVEFORMATEX *pwfx)  wave_out_set_format(WAVEFORMATEX * pwfx)
103  {  {
104          audio_info_t info;          audio_info_t info;
105          int test = 1;          int test = 1;
# Line 119  wave_out_set_format(WAVEFORMATEX *pwfx) Line 120  wave_out_set_format(WAVEFORMATEX *pwfx)
120                  swapaudio = !(*(uint8 *) (&test));                  swapaudio = !(*(uint8 *) (&test));
121          }          }
122    
123          samplewidth = pwfx->wBitsPerSample/8;          samplewidth = pwfx->wBitsPerSample / 8;
124    
125          if (pwfx->nChannels == 1 )          if (pwfx->nChannels == 1)
126          {                {
127                  info.play.channels = AUDIO_CHANNELS_MONO;                  info.play.channels = AUDIO_CHANNELS_MONO;
128          }          }
129          else if (pwfx->nChannels == 2 )          else if (pwfx->nChannels == 2)
130          {          {
131                  info.play.channels = AUDIO_CHANNELS_STEREO;                  info.play.channels = AUDIO_CHANNELS_STEREO;
132                  samplewidth *= 2;                  samplewidth *= 2;
# Line 163  wave_out_volume(uint16 left, uint16 righ Line 164  wave_out_volume(uint16 left, uint16 righ
164    
165          volume = (left > right) ? left : right;          volume = (left > right) ? left : right;
166    
167          if ( volume/AUDIO_MID_BALANCE != 0 )          if (volume / AUDIO_MID_BALANCE != 0)
168          {          {
169                  balance = AUDIO_MID_BALANCE - (left/(volume/AUDIO_MID_BALANCE)) + (right/(volume/AUDIO_MID_BALANCE));                  balance =
170                            AUDIO_MID_BALANCE - (left / (volume / AUDIO_MID_BALANCE)) +
171                            (right / (volume / AUDIO_MID_BALANCE));
172          }          }
173          else          else
174          {          {
175                  balance = AUDIO_MID_BALANCE;                  balance = AUDIO_MID_BALANCE;
176          }          }
177    
178          info.play.gain = volume/(65536/AUDIO_MAX_GAIN);          info.play.gain = volume / (65536 / AUDIO_MAX_GAIN);
179          info.play.balance = balance;          info.play.balance = balance;
180    
181          if (ioctl(g_dsp_fd, AUDIO_SETINFO, &info) == -1)          if (ioctl(g_dsp_fd, AUDIO_SETINFO, &info) == -1)
# Line 193  wave_out_write(STREAM s, uint16 tick, ui Line 196  wave_out_write(STREAM s, uint16 tick, ui
196                  error("No space to queue audio packet\n");                  error("No space to queue audio packet\n");
197                  return;                  return;
198          }          }
199            
200          queue_hi = next_hi;          queue_hi = next_hi;
201    
202          packet->s = *s;          packet->s = *s;
# Line 224  wave_out_play(void) Line 227  wave_out_play(void)
227    
228          while (1)          while (1)
229          {          {
230                  if ( reopened )                  if (reopened)
231                  {                  {
232                          /* Device was just (re)openend */                          /* Device was just (re)openend */
233                          samplecnt = 0;                          samplecnt = 0;
# Line 243  wave_out_play(void) Line 246  wave_out_play(void)
246                  out = &packet->s;                  out = &packet->s;
247    
248                  /* Swap the current packet, but only once */                  /* Swap the current packet, but only once */
249                  if ( swapaudio && ! swapped )                  if (swapaudio && !swapped)
250                  {                  {
251                          for ( i = 0; i < out->end - out->p; i += 2 )                          for (i = 0; i < out->end - out->p; i += 2)
252                          {                          {
253                                  swap = *(out->p + i);                                  swap = *(out->p + i);
254                                  *(out->p + i) = *(out->p + i + 1);                                  *(out->p + i) = *(out->p + i + 1);
# Line 254  wave_out_play(void) Line 257  wave_out_play(void)
257                          swapped = True;                          swapped = True;
258                  }                  }
259    
260                  if ( sentcompletion )                  if (sentcompletion)
261                  {                  {
262                          sentcompletion = False;                          sentcompletion = False;
263                          numsamples = (out->end - out->p)/samplewidth;                          numsamples = (out->end - out->p) / samplewidth;
264                  }                  }
265    
266                  len=0;                  len = 0;
267    
268                  if ( out->end != out->p )                  if (out->end != out->p)
269                  {                  {
270                          len = write(g_dsp_fd, out->p, out->end - out->p);                          len = write(g_dsp_fd, out->p, out->end - out->p);
271                          if (len == -1)                          if (len == -1)
# Line 284  wave_out_play(void) Line 287  wave_out_play(void)
287                          }                          }
288    
289                          /* Ack the packet, if we have played at least 70% */                          /* Ack the packet, if we have played at least 70% */
290                          if ( info.play.samples >= samplecnt+((numsamples*7)/10) )                          if (info.play.samples >= samplecnt + ((numsamples * 7) / 10))
291                          {                          {
292                                  samplecnt += numsamples;                                  samplecnt += numsamples;
293                                  rdpsnd_send_completion(packet->tick, packet->index);                                  rdpsnd_send_completion(packet->tick, packet->index);

Legend:
Removed from v.491  
changed lines
  Added in v.499

  ViewVC Help
Powered by ViewVC 1.1.26