src/audio/arts/SDL_artsaudio.c
changeset 10236 c2730130a448
parent 10231 0bd26418c5e4
child 10237 9530fc07da6c
equal deleted inserted replaced
10235:0e83beda6d8b 10236:c2730130a448
    52 static int (*SDL_NAME(arts_init)) (void);
    52 static int (*SDL_NAME(arts_init)) (void);
    53 static void (*SDL_NAME(arts_free)) (void);
    53 static void (*SDL_NAME(arts_free)) (void);
    54 static arts_stream_t(*SDL_NAME(arts_play_stream)) (int rate, int bits,
    54 static arts_stream_t(*SDL_NAME(arts_play_stream)) (int rate, int bits,
    55                                                    int channels,
    55                                                    int channels,
    56                                                    const char *name);
    56                                                    const char *name);
    57 static arts_stream_t(*SDL_NAME(arts_record_stream)) (int rate, int bits,
       
    58                                                    int channels,
       
    59                                                    const char *name);
       
    60 static int (*SDL_NAME(arts_stream_set)) (arts_stream_t s,
    57 static int (*SDL_NAME(arts_stream_set)) (arts_stream_t s,
    61                                          arts_parameter_t param, int value);
    58                                          arts_parameter_t param, int value);
    62 static int (*SDL_NAME(arts_stream_get)) (arts_stream_t s,
    59 static int (*SDL_NAME(arts_stream_get)) (arts_stream_t s,
    63                                          arts_parameter_t param);
    60                                          arts_parameter_t param);
    64 static int (*SDL_NAME(arts_write)) (arts_stream_t s, const void *buffer,
    61 static int (*SDL_NAME(arts_write)) (arts_stream_t s, const void *buffer,
    65                                     int count);
    62                                     int count);
    66 static int (*SDL_NAME(arts_read)) (arts_stream_t s, void *buffer, int count);
       
    67 static void (*SDL_NAME(arts_close_stream)) (arts_stream_t s);
    63 static void (*SDL_NAME(arts_close_stream)) (arts_stream_t s);
    68 static int (*SDL_NAME(arts_suspend))(void);
    64 static int (*SDL_NAME(arts_suspend))(void);
    69 static int (*SDL_NAME(arts_suspended)) (void);
    65 static int (*SDL_NAME(arts_suspended)) (void);
    70 static const char *(*SDL_NAME(arts_error_text)) (int errorcode);
    66 static const char *(*SDL_NAME(arts_error_text)) (int errorcode);
    71 
    67 
    77 } arts_functions[] = {
    73 } arts_functions[] = {
    78 /* *INDENT-OFF* */
    74 /* *INDENT-OFF* */
    79     SDL_ARTS_SYM(arts_init),
    75     SDL_ARTS_SYM(arts_init),
    80     SDL_ARTS_SYM(arts_free),
    76     SDL_ARTS_SYM(arts_free),
    81     SDL_ARTS_SYM(arts_play_stream),
    77     SDL_ARTS_SYM(arts_play_stream),
    82     SDL_ARTS_SYM(arts_record_stream),
       
    83     SDL_ARTS_SYM(arts_stream_set),
    78     SDL_ARTS_SYM(arts_stream_set),
    84     SDL_ARTS_SYM(arts_stream_get),
    79     SDL_ARTS_SYM(arts_stream_get),
    85     SDL_ARTS_SYM(arts_write),
    80     SDL_ARTS_SYM(arts_write),
    86     SDL_ARTS_SYM(arts_read),
       
    87     SDL_ARTS_SYM(arts_close_stream),
    81     SDL_ARTS_SYM(arts_close_stream),
    88     SDL_ARTS_SYM(arts_suspend),
    82     SDL_ARTS_SYM(arts_suspend),
    89     SDL_ARTS_SYM(arts_suspended),
    83     SDL_ARTS_SYM(arts_suspended),
    90     SDL_ARTS_SYM(arts_error_text),
    84     SDL_ARTS_SYM(arts_error_text),
    91 /* *INDENT-ON* */
    85 /* *INDENT-ON* */
   203 ARTS_GetDeviceBuf(_THIS)
   197 ARTS_GetDeviceBuf(_THIS)
   204 {
   198 {
   205     return (this->hidden->mixbuf);
   199     return (this->hidden->mixbuf);
   206 }
   200 }
   207 
   201 
   208 static int
       
   209 ARTS_CaptureFromDevice(_THIS, void *buffer, int buflen)
       
   210 {
       
   211     return SDL_NAME(arts_read) (this->hidden->stream, buffer, buflen);
       
   212 }
       
   213 
       
   214 static void
       
   215 ARTS_FlushCapture(_THIS)
       
   216 {
       
   217     arts_stream_t stream = this->hidden->stream;
       
   218     int remain = SDL_NAME(arts_stream_get)(stream, ARTS_P_BUFFER_SPACE);
       
   219     Uint8 buf[512];
       
   220     while (remain > 0) {
       
   221         const int len = SDL_min(sizeof (buf), remain);
       
   222         const int br = SDL_NAME(arts_read)(stream, buf, len);
       
   223         if (br <= 0) {
       
   224             return;  /* oh well. */
       
   225         }
       
   226         remain -= br;
       
   227     }
       
   228 }
       
   229 
   202 
   230 static void
   203 static void
   231 ARTS_CloseDevice(_THIS)
   204 ARTS_CloseDevice(_THIS)
   232 {
   205 {
   233     if (this->hidden != NULL) {
   206     if (this->hidden != NULL) {
   303         ARTS_CloseDevice(this);
   276         ARTS_CloseDevice(this);
   304         return SDL_SetError("Unable to initialize ARTS: %s",
   277         return SDL_SetError("Unable to initialize ARTS: %s",
   305                             SDL_NAME(arts_error_text) (rc));
   278                             SDL_NAME(arts_error_text) (rc));
   306     }
   279     }
   307 
   280 
   308     if (iscapture) {
   281     if (!ARTS_Suspend()) {
   309         this->hidden->stream = SDL_NAME(arts_record_stream) (this->spec.freq,
   282         ARTS_CloseDevice(this);
   310                                                              bits,
   283         return SDL_SetError("ARTS can not open audio device");
   311                                                              this->spec.channels,
   284     }
   312                                                              "SDL");
   285 
   313     } else {
   286     this->hidden->stream = SDL_NAME(arts_play_stream) (this->spec.freq,
   314         this->hidden->stream = SDL_NAME(arts_play_stream) (this->spec.freq,
   287                                                        bits,
   315                                                            bits,
   288                                                        this->spec.channels,
   316                                                            this->spec.channels,
   289                                                        "SDL");
   317                                                            "SDL");
   290 
   318         /* Play nothing so we have at least one write (server bug workaround). */
   291     /* Play nothing so we have at least one write (server bug workaround). */
   319         SDL_NAME(arts_write) (this->hidden->stream, "", 0);
   292     SDL_NAME(arts_write) (this->hidden->stream, "", 0);
   320     }
       
   321 
   293 
   322     /* Calculate the final parameters for this audio specification */
   294     /* Calculate the final parameters for this audio specification */
   323     SDL_CalculateAudioSpec(&this->spec);
   295     SDL_CalculateAudioSpec(&this->spec);
   324 
   296 
   325     /* Determine the power of two of the fragment size */
   297     /* Determine the power of two of the fragment size */
   395     impl->WaitDevice = ARTS_WaitDevice;
   367     impl->WaitDevice = ARTS_WaitDevice;
   396     impl->GetDeviceBuf = ARTS_GetDeviceBuf;
   368     impl->GetDeviceBuf = ARTS_GetDeviceBuf;
   397     impl->CloseDevice = ARTS_CloseDevice;
   369     impl->CloseDevice = ARTS_CloseDevice;
   398     impl->WaitDone = ARTS_WaitDone;
   370     impl->WaitDone = ARTS_WaitDone;
   399     impl->Deinitialize = ARTS_Deinitialize;
   371     impl->Deinitialize = ARTS_Deinitialize;
   400     impl->CaptureFromDevice = ARTS_CaptureFromDevice;
       
   401     impl->FlushCapture = ARTS_FlushCapture;
       
   402 
       
   403     impl->OnlyHasDefaultOutputDevice = 1;
   372     impl->OnlyHasDefaultOutputDevice = 1;
   404     impl->OnlyHasDefaultInputDevice = 1;
       
   405     impl->HasCaptureSupport = 1;
       
   406 
   373 
   407     return 1;   /* this audio target is available. */
   374     return 1;   /* this audio target is available. */
   408 }
   375 }
   409 
   376 
   410 
   377