/[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 834 by stargo, Tue Mar 8 03:33:36 2005 UTC revision 835 by stargo, Tue Mar 8 04:25:12 2005 UTC
# Line 31  Line 31 
31  int g_dsp_fd;  int g_dsp_fd;
32  ao_device *o_device = NULL;  ao_device *o_device = NULL;
33  int default_driver;  int default_driver;
34    int g_samplerate;
35  BOOL g_dsp_busy = False;  BOOL g_dsp_busy = False;
36  static short g_samplewidth;  static short g_samplewidth;
37    
# Line 53  wave_out_open(void) Line 54  wave_out_open(void)
54          format.bits = 16;          format.bits = 16;
55          format.channels = 2;          format.channels = 2;
56          format.rate = 44100;          format.rate = 44100;
57            g_samplerate = 44100;
58          format.byte_format = AO_FMT_LITTLE;          format.byte_format = AO_FMT_LITTLE;
59    
60          o_device = ao_open_live(default_driver, &format, NULL);          o_device = ao_open_live(default_driver, &format, NULL);
# Line 93  wave_out_format_supported(WAVEFORMATEX * Line 95  wave_out_format_supported(WAVEFORMATEX *
95          if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16))          if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16))
96                  return False;                  return False;
97          /* The only common denominator between libao output drivers is a sample-rate of          /* The only common denominator between libao output drivers is a sample-rate of
98             44100, windows gives a max of 22050. we need to upsample that...             44100, we need to upsample 22050 to it */
99             TODO: support 11025, too */          if ((pwfx->nSamplesPerSec != 44100) && (pwfx->nSamplesPerSec != 22050))
         if (pwfx->nSamplesPerSec != 22050)  
100                  return False;                  return False;
101    
102          return True;          return True;
# Line 106  wave_out_set_format(WAVEFORMATEX * pwfx) Line 107  wave_out_set_format(WAVEFORMATEX * pwfx)
107  {  {
108          ao_sample_format format;          ao_sample_format format;
109    
         printf("%d\n",pwfx->wBitsPerSample);  
110          format.bits = pwfx->wBitsPerSample;          format.bits = pwfx->wBitsPerSample;
111          format.channels = pwfx->nChannels;          format.channels = pwfx->nChannels;
112          format.rate = 44100;          format.rate = 44100;
113            g_samplerate = pwfx->nSamplesPerSec;
114          format.byte_format = AO_FMT_LITTLE;          format.byte_format = AO_FMT_LITTLE;
115    
116          g_samplewidth = pwfx->wBitsPerSample / 8;          g_samplewidth = pwfx->wBitsPerSample / 8;
# Line 163  wave_out_play(void) Line 164  wave_out_play(void)
164  {  {
165          struct audio_packet *packet;          struct audio_packet *packet;
166          STREAM out;          STREAM out;
167          unsigned char expanded[8];          unsigned char expanded[16];
168            int offset,len,i;
169    
170          while (1)          if (queue_lo == queue_hi)
171          {          {
172                  if (queue_lo == queue_hi)                  g_dsp_busy = 0;
173                  {                  return;
174                          g_dsp_busy = 0;          }
                         return;  
                 }  
   
                 packet = &packet_queue[queue_lo];  
                 out = &packet->s;  
175    
176                  /* Resample 22050 -> 44100 */          packet = &packet_queue[queue_lo];
177                  /* TODO: Do this for 11025, too... */          out = &packet->s;
                 memcpy(&expanded[0],out->p,g_samplewidth);  
                 memcpy(&expanded[2*g_samplewidth],out->p,g_samplewidth);  
                 out->p += 2;  
                 memcpy(&expanded[1*g_samplewidth],out->p,g_samplewidth);  
                 memcpy(&expanded[3*g_samplewidth],out->p,g_samplewidth);  
                 out->p += 2;  
178    
179                  ao_play(o_device, expanded, g_samplewidth*4);          len = 0;
180    
181                  if (out->p == out->end)          if (g_samplerate == 22050 )
182            {
183                    /* Resample to 44100 */
184                    for(i=0; (i<(2*(3-g_samplewidth))) && (out->p < out->end); i++)
185                  {                  {
186                          rdpsnd_send_completion(packet->tick, packet->index);                          offset=i*4*g_samplewidth;
187                          free(out->data);                          memcpy(&expanded[0*g_samplewidth+offset],out->p,g_samplewidth);
188                          queue_lo = (queue_lo + 1) % MAX_QUEUE;                          memcpy(&expanded[2*g_samplewidth+offset],out->p,g_samplewidth);
189                  } else {                          out->p += 2;
190                          g_dsp_busy = 1;  
191                          return;                          memcpy(&expanded[1*g_samplewidth+offset],out->p,g_samplewidth);
192                            memcpy(&expanded[3*g_samplewidth+offset],out->p,g_samplewidth);
193                            out->p += 2;
194                            len += 4*g_samplewidth;
195                  }                  }
196          }          }
197            else
198            {
199                    len = (16 > (out->end - out->p)) ? (out->end - out->p) : 16;
200                    memcpy(expanded,out->p,len);
201                    out->p += len;
202            }
203    
204            ao_play(o_device, expanded, len);
205    
206            if (out->p == out->end)
207            {
208                    rdpsnd_send_completion(packet->tick, packet->index);
209                    free(out->data);
210                    queue_lo = (queue_lo + 1) % MAX_QUEUE;
211            }
212    
213            g_dsp_busy = 1;
214            return;
215  }  }

Legend:
Removed from v.834  
changed lines
  Added in v.835

  ViewVC Help
Powered by ViewVC 1.1.26