/[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 1254 by stargo, Sun Sep 17 10:32:18 2006 UTC revision 1279 by stargo, Sun Oct 1 14:03:43 2006 UTC
# Line 35  Line 35 
35  #define DEFAULTDEVICE   "/dev/audio"  #define DEFAULTDEVICE   "/dev/audio"
36    
37  static BOOL g_reopened;  static BOOL g_reopened;
 static BOOL g_swapaudio;  
38  static short g_samplewidth;  static short g_samplewidth;
39    static char *dsp_dev;
40    
41  BOOL  BOOL
42  wave_out_open(void)  sun_open(void)
43  {  {
         char *dsp_dev = getenv("AUDIODEV");  
   
         if (dsp_dev == NULL)  
         {  
                 dsp_dev = xstrdup(DEFAULTDEVICE);  
         }  
   
44          if ((g_dsp_fd = open(dsp_dev, O_WRONLY | O_NONBLOCK)) == -1)          if ((g_dsp_fd = open(dsp_dev, O_WRONLY | O_NONBLOCK)) == -1)
45          {          {
46                  perror(dsp_dev);                  perror(dsp_dev);
# Line 64  wave_out_open(void) Line 57  wave_out_open(void)
57  }  }
58    
59  void  void
60  wave_out_close(void)  sun_close(void)
61  {  {
62          /* Ack all remaining packets */          /* Ack all remaining packets */
63          while (!rdpsnd_queue_empty())          while (!rdpsnd_queue_empty())
# Line 85  wave_out_close(void) Line 78  wave_out_close(void)
78  }  }
79    
80  BOOL  BOOL
81  wave_out_format_supported(WAVEFORMATEX * pwfx)  sun_format_supported(WAVEFORMATEX * pwfx)
82  {  {
83          if (pwfx->wFormatTag != WAVE_FORMAT_PCM)          if (pwfx->wFormatTag != WAVE_FORMAT_PCM)
84                  return False;                  return False;
# Line 98  wave_out_format_supported(WAVEFORMATEX * Line 91  wave_out_format_supported(WAVEFORMATEX *
91  }  }
92    
93  BOOL  BOOL
94  wave_out_set_format(WAVEFORMATEX * pwfx)  sun_set_format(WAVEFORMATEX * pwfx)
95  {  {
96          audio_info_t info;          audio_info_t info;
97    
98          ioctl(g_dsp_fd, AUDIO_DRAIN, 0);          ioctl(g_dsp_fd, AUDIO_DRAIN, 0);
         g_swapaudio = False;  
99          AUDIO_INITINFO(&info);          AUDIO_INITINFO(&info);
100    
101    
# Line 114  wave_out_set_format(WAVEFORMATEX * pwfx) Line 106  wave_out_set_format(WAVEFORMATEX * pwfx)
106          else if (pwfx->wBitsPerSample == 16)          else if (pwfx->wBitsPerSample == 16)
107          {          {
108                  info.play.encoding = AUDIO_ENCODING_LINEAR;                  info.play.encoding = AUDIO_ENCODING_LINEAR;
                 /* Do we need to swap the 16bit values? (Are we BigEndian) */  
 #ifdef B_ENDIAN  
                 g_swapaudio = 1;  
 #else  
                 g_swapaudio = 0;  
 #endif  
109          }          }
110    
111          g_samplewidth = pwfx->wBitsPerSample / 8;          g_samplewidth = pwfx->wBitsPerSample / 8;
# Line 152  wave_out_set_format(WAVEFORMATEX * pwfx) Line 138  wave_out_set_format(WAVEFORMATEX * pwfx)
138  }  }
139    
140  void  void
141  wave_out_volume(uint16 left, uint16 right)  sun_volume(uint16 left, uint16 right)
142  {  {
143          audio_info_t info;          audio_info_t info;
144          uint balance;          uint balance;
# Line 184  wave_out_volume(uint16 left, uint16 righ Line 170  wave_out_volume(uint16 left, uint16 righ
170  }  }
171    
172  void  void
173  wave_out_play(void)  sun_play(void)
174  {  {
175          struct audio_packet *packet;          struct audio_packet *packet;
176          audio_info_t info;          audio_info_t info;
177          ssize_t len;          ssize_t len;
178          unsigned int i;          unsigned int i;
         uint8 swap;  
179          STREAM out;          STREAM out;
         static BOOL swapped = False;  
180          static BOOL sentcompletion = True;          static BOOL sentcompletion = True;
181          static uint32 samplecnt = 0;          static uint32 samplecnt = 0;
182          static uint32 numsamples;          static uint32 numsamples;
# Line 203  wave_out_play(void) Line 187  wave_out_play(void)
187                  {                  {
188                          /* Device was just (re)openend */                          /* Device was just (re)openend */
189                          samplecnt = 0;                          samplecnt = 0;
                         swapped = False;  
190                          sentcompletion = True;                          sentcompletion = True;
191                          g_reopened = False;                          g_reopened = False;
192                  }                  }
# Line 217  wave_out_play(void) Line 200  wave_out_play(void)
200                  packet = rdpsnd_queue_current_packet();                  packet = rdpsnd_queue_current_packet();
201                  out = &packet->s;                  out = &packet->s;
202    
                 /* Swap the current packet, but only once */  
                 if (g_swapaudio && !swapped)  
                 {  
                         for (i = 0; i < out->end - out->p; i += 2)  
                         {  
                                 swap = *(out->p + i);  
                                 *(out->p + i) = *(out->p + i + 1);  
                                 *(out->p + i + 1) = swap;  
                         }  
                         swapped = True;  
                 }  
   
203                  if (sentcompletion)                  if (sentcompletion)
204                  {                  {
205                          sentcompletion = False;                          sentcompletion = False;
# Line 266  wave_out_play(void) Line 237  wave_out_play(void)
237                                   * playing this packet */                                   * playing this packet */
238                                  rdpsnd_send_completion(packet->tick + 50, packet->index);                                  rdpsnd_send_completion(packet->tick + 50, packet->index);
239                                  rdpsnd_queue_next();                                  rdpsnd_queue_next();
                                 swapped = False;  
240                                  sentcompletion = True;                                  sentcompletion = True;
241                          }                          }
242                          else                          else
# Line 277  wave_out_play(void) Line 247  wave_out_play(void)
247                  }                  }
248          }          }
249  }  }
250    
251    struct audio_driver *
252    sun_register(char *options)
253    {
254            static struct audio_driver sun_driver;
255    
256            sun_driver.wave_out_write = rdpsnd_queue_write;
257            sun_driver.wave_out_open = sun_open;
258            sun_driver.wave_out_close = sun_close;
259            sun_driver.wave_out_format_supported = sun_format_supported;
260            sun_driver.wave_out_set_format = sun_set_format;
261            sun_driver.wave_out_volume = sun_volume;
262            sun_driver.wave_out_play = sun_play;
263            sun_driver.name = xstrdup("sun");
264            sun_driver.description =
265                    xstrdup("SUN/BSD output driver, default device: " DEFAULTDEVICE " or $AUDIODEV");
266            sun_driver.need_byteswap_on_be = 1;
267            sun_driver.need_resampling = 0;
268            sun_driver.next = NULL;
269    
270            if (options)
271            {
272                    dsp_dev = xstrdup(options);
273            }
274            else
275            {
276                    dsp_dev = getenv("AUDIODEV");
277    
278                    if (dsp_dev == NULL)
279                    {
280                            dsp_dev = xstrdup(DEFAULTDEVICE);
281                    }
282            }
283    
284            return &sun_driver;
285    }

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

  ViewVC Help
Powered by ViewVC 1.1.26