src/audio/SDL_audiocvt.c
changeset 11631 150b925ddfbb
parent 11611 4ad5d0fccc9f
child 11632 385312bd6594
equal deleted inserted replaced
11630:ad4b5d85edee 11631:150b925ddfbb
  1075 
  1075 
  1076 typedef int (*SDL_ResampleAudioStreamFunc)(SDL_AudioStream *stream, const void *inbuf, const int inbuflen, void *outbuf, const int outbuflen);
  1076 typedef int (*SDL_ResampleAudioStreamFunc)(SDL_AudioStream *stream, const void *inbuf, const int inbuflen, void *outbuf, const int outbuflen);
  1077 typedef void (*SDL_ResetAudioStreamResamplerFunc)(SDL_AudioStream *stream);
  1077 typedef void (*SDL_ResetAudioStreamResamplerFunc)(SDL_AudioStream *stream);
  1078 typedef void (*SDL_CleanupAudioStreamResamplerFunc)(SDL_AudioStream *stream);
  1078 typedef void (*SDL_CleanupAudioStreamResamplerFunc)(SDL_AudioStream *stream);
  1079 
  1079 
  1080 struct SDL_AudioStream
  1080 struct _SDL_AudioStream
  1081 {
  1081 {
  1082     SDL_AudioCVT cvt_before_resampling;
  1082     SDL_AudioCVT cvt_before_resampling;
  1083     SDL_AudioCVT cvt_after_resampling;
  1083     SDL_AudioCVT cvt_after_resampling;
  1084     SDL_DataQueue *queue;
  1084     SDL_DataQueue *queue;
  1085     SDL_bool first_run;
  1085     SDL_bool first_run;
  1347 
  1347 
  1348     return retval;
  1348     return retval;
  1349 }
  1349 }
  1350 
  1350 
  1351 int
  1351 int
  1352 SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, const Uint32 _buflen)
  1352 SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len)
  1353 {
  1353 {
  1354     int buflen = (int) _buflen;
  1354     int buflen = len;
  1355     int workbuflen;
  1355     int workbuflen;
  1356     Uint8 *workbuf;
  1356     Uint8 *workbuf;
  1357     Uint8 *resamplebuf = NULL;
  1357     Uint8 *resamplebuf = NULL;
  1358     int resamplebuflen = 0;
  1358     int resamplebuflen = 0;
  1359     int neededpaddingbytes;
  1359     int neededpaddingbytes;
  1493 
  1493 
  1494     /* resamplebuf holds the final output, even if we didn't resample. */
  1494     /* resamplebuf holds the final output, even if we didn't resample. */
  1495     return buflen ? SDL_WriteToDataQueue(stream->queue, resamplebuf, buflen) : 0;
  1495     return buflen ? SDL_WriteToDataQueue(stream->queue, resamplebuf, buflen) : 0;
  1496 }
  1496 }
  1497 
  1497 
       
  1498 /* get converted/resampled data from the stream */
       
  1499 int
       
  1500 SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len)
       
  1501 {
       
  1502     #if DEBUG_AUDIOSTREAM
       
  1503     printf("AUDIOSTREAM: want to get %d converted bytes\n", len);
       
  1504     #endif
       
  1505 
       
  1506     if (!stream) {
       
  1507         return SDL_InvalidParamError("stream");
       
  1508     } else if (!buf) {
       
  1509         return SDL_InvalidParamError("buf");
       
  1510     } else if (len <= 0) {
       
  1511         return 0;  /* nothing to do. */
       
  1512     } else if ((len % stream->dst_sample_frame_size) != 0) {
       
  1513         return SDL_SetError("Can't request partial sample frames");
       
  1514     }
       
  1515 
       
  1516     return (int) SDL_ReadFromDataQueue(stream->queue, buf, len);
       
  1517 }
       
  1518 
       
  1519 /* number of converted/resampled bytes available */
       
  1520 int
       
  1521 SDL_AudioStreamAvailable(SDL_AudioStream *stream)
       
  1522 {
       
  1523     return stream ? (int) SDL_CountDataQueue(stream->queue) : 0;
       
  1524 }
       
  1525 
  1498 void
  1526 void
  1499 SDL_AudioStreamClear(SDL_AudioStream *stream)
  1527 SDL_AudioStreamClear(SDL_AudioStream *stream)
  1500 {
  1528 {
  1501     if (!stream) {
  1529     if (!stream) {
  1502         SDL_InvalidParamError("stream");
  1530         SDL_InvalidParamError("stream");
  1507         }
  1535         }
  1508         stream->first_run = SDL_TRUE;
  1536         stream->first_run = SDL_TRUE;
  1509     }
  1537     }
  1510 }
  1538 }
  1511 
  1539 
  1512 
       
  1513 /* get converted/resampled data from the stream */
       
  1514 int
       
  1515 SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, const Uint32 len)
       
  1516 {
       
  1517     #if DEBUG_AUDIOSTREAM
       
  1518     printf("AUDIOSTREAM: want to get %u converted bytes\n", (unsigned int) len);
       
  1519     #endif
       
  1520 
       
  1521     if (!stream) {
       
  1522         return SDL_InvalidParamError("stream");
       
  1523     } else if (!buf) {
       
  1524         return SDL_InvalidParamError("buf");
       
  1525     } else if (len == 0) {
       
  1526         return 0;  /* nothing to do. */
       
  1527     } else if ((len % stream->dst_sample_frame_size) != 0) {
       
  1528         return SDL_SetError("Can't request partial sample frames");
       
  1529     }
       
  1530 
       
  1531     return (int) SDL_ReadFromDataQueue(stream->queue, buf, len);
       
  1532 }
       
  1533 
       
  1534 /* number of converted/resampled bytes available */
       
  1535 int
       
  1536 SDL_AudioStreamAvailable(SDL_AudioStream *stream)
       
  1537 {
       
  1538     return stream ? (int) SDL_CountDataQueue(stream->queue) : 0;
       
  1539 }
       
  1540 
       
  1541 /* dispose of a stream */
  1540 /* dispose of a stream */
  1542 void
  1541 void
  1543 SDL_FreeAudioStream(SDL_AudioStream *stream)
  1542 SDL_FreeAudioStream(SDL_AudioStream *stream)
  1544 {
  1543 {
  1545     if (stream) {
  1544     if (stream) {