/[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 476 by matthewc, Sat Oct 4 00:03:24 2003 UTC revision 477 by matthewc, Sat Oct 4 12:24:56 2003 UTC
# Line 25  Line 25 
25  #include <fcntl.h>  #include <fcntl.h>
26  #include <errno.h>  #include <errno.h>
27  #include <sys/ioctl.h>  #include <sys/ioctl.h>
28  #include <sys/audio.h>  #include <sys/audioio.h>
29  #include <stropts.h>  #include <stropts.h>
30    
31  #define MAX_QUEUE       10  #define MAX_QUEUE       10
32    
33  int g_dsp_fd;  int g_dsp_fd;
34  BOOL g_dsp_busy;  BOOL g_dsp_busy;
35    static BOOL reopened;
36  static BOOL swapaudio;  static BOOL swapaudio;
37  static short samplewidth;  static short samplewidth;
38    
# Line 45  static unsigned int queue_hi, queue_lo; Line 46  static unsigned int queue_hi, queue_lo;
46  BOOL  BOOL
47  wave_out_open(void)  wave_out_open(void)
48  {  {
49          char *dsp_dev = "/dev/audio";          char *dsp_dev = getenv("AUDIODEV");
50    
51            if ( dsp_dev == NULL )
52            {
53                    dsp_dev="/dev/audio";
54            }
55    
56          if ((g_dsp_fd = open(dsp_dev, O_WRONLY|O_NONBLOCK)) == -1)          if ((g_dsp_fd = open(dsp_dev, O_WRONLY|O_NONBLOCK)) == -1)
57          {          {
# Line 53  wave_out_open(void) Line 59  wave_out_open(void)
59                  return False;                  return False;
60          }          }
61    
   
62          /* Non-blocking so that user interface is responsive */          /* Non-blocking so that user interface is responsive */
63          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);
64            
65          queue_lo = queue_hi = 0;          queue_lo = queue_hi = 0;
66            reopened = True;
67            
68          return True;          return True;
69  }  }
70    
71  void  void
72  wave_out_close(void)  wave_out_close(void)
73  {  {
74            /* Ack all remaining packets */
75            while ( queue_lo != queue_hi )
76            {
77                    rdpsnd_send_completion(packet_queue[queue_lo].tick, packet_queue[queue_lo].index);
78                    free(packet_queue[queue_lo].s.data);
79                    queue_lo = (queue_lo + 1) % MAX_QUEUE;
80            }
81    
82            /* Flush the audiobuffer */
83          ioctl(g_dsp_fd,I_FLUSH,FLUSHW);          ioctl(g_dsp_fd,I_FLUSH,FLUSHW);
84          close(g_dsp_fd);          close(g_dsp_fd);
85  }  }
# Line 94  wave_out_set_format(WAVEFORMATEX *pwfx) Line 111  wave_out_set_format(WAVEFORMATEX *pwfx)
111          if (pwfx->wBitsPerSample == 8)          if (pwfx->wBitsPerSample == 8)
112          {          {
113                  info.play.encoding = AUDIO_ENCODING_LINEAR8;                  info.play.encoding = AUDIO_ENCODING_LINEAR8;
114                  samplewidth=1;                  samplewidth = 1;
115          }          }
116          else if (pwfx->wBitsPerSample == 16)          else if (pwfx->wBitsPerSample == 16)
117          {          {
118                  info.play.encoding = AUDIO_ENCODING_LINEAR;                  info.play.encoding = AUDIO_ENCODING_LINEAR;
119                    samplewidth = 2;
120                    /* Do we need to swap the 16bit values? (Are we BigEndian) */
121                  swapaudio = !(*(uint8 *) (&test));                  swapaudio = !(*(uint8 *) (&test));
                 samplewidth=2;  
122          }          }
123    
124          if (pwfx->nChannels == 1 )          if (pwfx->nChannels == 1 )
# Line 110  wave_out_set_format(WAVEFORMATEX *pwfx) Line 128  wave_out_set_format(WAVEFORMATEX *pwfx)
128          else if (pwfx->nChannels == 2 )          else if (pwfx->nChannels == 2 )
129          {          {
130                  info.play.channels = AUDIO_CHANNELS_STEREO;                  info.play.channels = AUDIO_CHANNELS_STEREO;
131                  samplewidth*=2;                  samplewidth *= 2;
132          }          }
133    
134          info.play.sample_rate = pwfx->nSamplesPerSec;          info.play.sample_rate = pwfx->nSamplesPerSec;
# Line 165  wave_out_play(void) Line 183  wave_out_play(void)
183          STREAM out;          STREAM out;
184          static BOOL swapped = False;          static BOOL swapped = False;
185          static BOOL sentcompletion = True;          static BOOL sentcompletion = True;
186          static int samplecnt;          static uint32 samplecnt = 0;
187          static int numsamples;          static uint32 numsamples;
188    
189          while (1)          while (1)
190          {          {
191                    if ( reopened )
192                    {
193                            /* Device was just (re)openend */
194                            samplecnt = 0;
195                            swapped = False;
196                            sentcompletion = True;
197                            reopened = False;
198                    }
199    
200                  if (queue_lo == queue_hi)                  if (queue_lo == queue_hi)
201                  {                  {
202                          g_dsp_busy = 0;                          g_dsp_busy = 0;
# Line 179  wave_out_play(void) Line 206  wave_out_play(void)
206                  packet = &packet_queue[queue_lo];                  packet = &packet_queue[queue_lo];
207                  out = &packet->s;                  out = &packet->s;
208    
209                    /* Swap the current packet, but only once */
210                  if ( swapaudio && ! swapped )                  if ( swapaudio && ! swapped )
211                  {                  {
212                          for ( i = 0; i < out->end - out->p; i+=2 )                          for ( i = 0; i < out->end - out->p; i+=2 )
# Line 192  wave_out_play(void) Line 220  wave_out_play(void)
220    
221                  if ( sentcompletion )                  if ( sentcompletion )
222                  {                  {
                         if (ioctl(g_dsp_fd, AUDIO_GETINFO, &info) == -1)  
                         {  
                                 perror("AUDIO_GETINFO");  
                                 return;  
                         }  
                         samplecnt=info.play.samples;  
223                          sentcompletion = False;                          sentcompletion = False;
224                          numsamples = (out->end-out->p)/samplewidth;                          numsamples = (out->end - out->p)/samplewidth;
225                  }                  }
226    
227                  len=0;                  len=0;
228    
229                  if ( out->end - out->p != 0 )                  if ( out->end != out->p )
230                  {                  {
231                          len = write(g_dsp_fd, out->p, out->end - out->p);                          len = write(g_dsp_fd, out->p, out->end - out->p);
232                          if (len == -1)                          if (len == -1)
# Line 224  wave_out_play(void) Line 246  wave_out_play(void)
246                                  perror("AUDIO_GETINFO");                                  perror("AUDIO_GETINFO");
247                                  return;                                  return;
248                          }                          }
249                          if ( info.play.samples >= samplecnt+(numsamples)*0.9 )  
250                            /* Ack the packet, if we have played at least 70% */
251                            if ( info.play.samples >= samplecnt+((numsamples*7)/10) )
252                          {                          {
253                                    samplecnt += numsamples;
254                                  rdpsnd_send_completion(packet->tick, packet->index);                                  rdpsnd_send_completion(packet->tick, packet->index);
255                                  free(out->data);                                  free(out->data);
256                                  queue_lo = (queue_lo + 1) % MAX_QUEUE;                                  queue_lo = (queue_lo + 1) % MAX_QUEUE;

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

  ViewVC Help
Powered by ViewVC 1.1.26