/[rdesktop]/sourceforge.net/trunk/rdesktop/rdpsnd_libao.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_libao.c

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

revision 1253 by stargo, Sun Jul 9 23:41:07 2006 UTC revision 1254 by stargo, Sun Sep 17 10:32:18 2006 UTC
# Line 3  Line 3 
3     Sound Channel Process Functions - libao-driver     Sound Channel Process Functions - libao-driver
4     Copyright (C) Matthew Chapman 2003     Copyright (C) Matthew Chapman 2003
5     Copyright (C) GuoJunBo guojunbo@ict.ac.cn 2003     Copyright (C) GuoJunBo guojunbo@ict.ac.cn 2003
6     Copyright (C) Michael Gernoth mike@zerfleddert.de 2005     Copyright (C) Michael Gernoth mike@zerfleddert.de 2005-2006
7    
8     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# Line 21  Line 21 
21  */  */
22    
23  #include "rdesktop.h"  #include "rdesktop.h"
24    #include "rdpsnd.h"
25  #include <unistd.h>  #include <unistd.h>
26  #include <fcntl.h>  #include <fcntl.h>
27  #include <errno.h>  #include <errno.h>
28  #include <ao/ao.h>  #include <ao/ao.h>
29  #include <sys/time.h>  #include <sys/time.h>
30    
 #define MAX_QUEUE       10  
31  #define WAVEOUTBUF      16  #define WAVEOUTBUF      16
32    
 int g_dsp_fd;  
 BOOL g_dsp_busy = False;  
33  static ao_device *o_device = NULL;  static ao_device *o_device = NULL;
34  static int default_driver;  static int default_driver;
35  static int samplerate;  static int samplerate;
# Line 39  static int audiochannels; Line 37  static int audiochannels;
37  static BOOL reopened;  static BOOL reopened;
38  static short samplewidth;  static short samplewidth;
39    
 static struct audio_packet  
 {  
         struct stream s;  
         uint16 tick;  
         uint8 index;  
 } packet_queue[MAX_QUEUE];  
 static unsigned int queue_hi, queue_lo;  
   
40  BOOL  BOOL
41  wave_out_open(void)  wave_out_open(void)
42  {  {
# Line 69  wave_out_open(void) Line 59  wave_out_open(void)
59          }          }
60    
61          g_dsp_fd = 0;          g_dsp_fd = 0;
62          queue_lo = queue_hi = 0;          rdpsnd_queue_init();
63    
64          reopened = True;          reopened = True;
65    
# Line 80  void Line 70  void
70  wave_out_close(void)  wave_out_close(void)
71  {  {
72          /* Ack all remaining packets */          /* Ack all remaining packets */
73          while (queue_lo != queue_hi)          while (!rdpsnd_queue_empty())
74          {          {
75                  rdpsnd_send_completion(packet_queue[queue_lo].tick, packet_queue[queue_lo].index);                  rdpsnd_send_completion(rdpsnd_queue_current_packet()->tick,
76                  free(packet_queue[queue_lo].s.data);                                         rdpsnd_queue_current_packet()->index);
77                  queue_lo = (queue_lo + 1) % MAX_QUEUE;                  rdpsnd_queue_next();
78          }          }
79    
80          if (o_device != NULL)          if (o_device != NULL)
# Line 145  wave_out_volume(uint16 left, uint16 righ Line 135  wave_out_volume(uint16 left, uint16 righ
135  }  }
136    
137  void  void
 wave_out_write(STREAM s, uint16 tick, uint8 index)  
 {  
         struct audio_packet *packet = &packet_queue[queue_hi];  
         unsigned int next_hi = (queue_hi + 1) % MAX_QUEUE;  
   
         if (next_hi == queue_lo)  
         {  
                 error("No space to queue audio packet\n");  
                 return;  
         }  
   
         queue_hi = next_hi;  
   
         packet->s = *s;  
         packet->tick = tick;  
         packet->index = index;  
         packet->s.p += 4;  
   
         /* we steal the data buffer from s, give it a new one */  
         s->data = malloc(s->size);  
   
         if (!g_dsp_busy)  
                 wave_out_play();  
 }  
   
 void  
138  wave_out_play(void)  wave_out_play(void)
139  {  {
140          struct audio_packet *packet;          struct audio_packet *packet;
# Line 190  wave_out_play(void) Line 154  wave_out_play(void)
154                  prev_us = tv.tv_usec;                  prev_us = tv.tv_usec;
155          }          }
156    
157          if (queue_lo == queue_hi)          if (rdpsnd_queue_empty())
158          {          {
159                  g_dsp_busy = 0;                  g_dsp_busy = 0;
160                  return;                  return;
161          }          }
162    
163          packet = &packet_queue[queue_lo];          packet = rdpsnd_queue_current_packet();
164          out = &packet->s;          out = &packet->s;
165    
166          if (((queue_lo + 1) % MAX_QUEUE) != queue_hi)          next_tick = rdpsnd_queue_next_tick();
         {  
                 next_tick = packet_queue[(queue_lo + 1) % MAX_QUEUE].tick;  
         }  
         else  
         {  
                 next_tick = (packet->tick + 65535) % 65536;  
         }  
167    
168          len = 0;          len = 0;
169    
# Line 261  wave_out_play(void) Line 218  wave_out_play(void)
218                                 (packet->tick + duration) % 65536, next_tick % 65536));                                 (packet->tick + duration) % 65536, next_tick % 65536));
219                  }                  }
220    
221                  /* Until all drivers are using the windows sound-ticks, we need to                  rdpsnd_send_completion(((packet->tick + duration) % 65536), packet->index);
222                     substract the 50 ticks added later by rdpsnd.c */                  rdpsnd_queue_next();
                 rdpsnd_send_completion(((packet->tick + duration) % 65536) - 50, packet->index);  
                 free(out->data);  
                 queue_lo = (queue_lo + 1) % MAX_QUEUE;  
223          }          }
224    
225          g_dsp_busy = 1;          g_dsp_busy = 1;

Legend:
Removed from v.1253  
changed lines
  Added in v.1254

  ViewVC Help
Powered by ViewVC 1.1.26