src/audio/SDL_audiocvt.c
changeset 10777 2883d23b5a28
parent 10776 7e935b2c430f
child 10789 e3eb7a266ec2
equal deleted inserted replaced
10776:7e935b2c430f 10777:2883d23b5a28
    27 
    27 
    28 #include "SDL_loadso.h"
    28 #include "SDL_loadso.h"
    29 #include "SDL_assert.h"
    29 #include "SDL_assert.h"
    30 #include "../SDL_dataqueue.h"
    30 #include "../SDL_dataqueue.h"
    31 
    31 
    32 #ifdef HAVE_LIBSAMPLERATE
    32 #if HAVE_LIBSAMPLERATE_H
    33 #include "samplerate.h"
    33 #include "samplerate.h"
    34 #endif
    34 #endif
    35 
    35 
    36 
    36 
    37 /* Effectively mix right and left channels into a single channel */
    37 /* Effectively mix right and left channels into a single channel */
   631     SDL_ResampleAudioStreamFunc resampler_func;
   631     SDL_ResampleAudioStreamFunc resampler_func;
   632     SDL_ResetAudioStreamResamplerFunc reset_resampler_func;
   632     SDL_ResetAudioStreamResamplerFunc reset_resampler_func;
   633     SDL_CleanupAudioStreamResamplerFunc cleanup_resampler_func;
   633     SDL_CleanupAudioStreamResamplerFunc cleanup_resampler_func;
   634 };
   634 };
   635 
   635 
   636 #ifdef HAVE_LIBSAMPLERATE
   636 #ifdef HAVE_LIBSAMPLERATE_H
   637 
   637 
   638 typedef struct
   638 typedef struct
   639 {
   639 {
   640     void *SRC_lib;
   640     void *SRC_lib;
   641 
   641 
   649 } SDL_AudioStreamResamplerState_SRC;
   649 } SDL_AudioStreamResamplerState_SRC;
   650 
   650 
   651 static SDL_bool
   651 static SDL_bool
   652 LoadLibSampleRate(SDL_AudioStreamResamplerState_SRC *state)
   652 LoadLibSampleRate(SDL_AudioStreamResamplerState_SRC *state)
   653 {
   653 {
   654 #ifdef LIBSAMPLERATE_DYNAMIC
   654 #ifdef SDL_LIBSAMPLERATE_DYNAMIC
   655     state->SRC_lib = SDL_LoadObject(LIBSAMPLERATE_DYNAMIC);
   655     state->SRC_lib = SDL_LoadObject(SDL_LIBSAMPLERATE_DYNAMIC);
   656     if (!state->SRC_lib) {
   656     if (!state->SRC_lib) {
   657         return SDL_FALSE;
   657         return SDL_FALSE;
   658     }
   658     }
   659 #endif
   659 #endif
   660 
   660 
   674 {
   674 {
   675     SDL_AudioStreamResamplerState_SRC *state = (SDL_AudioStreamResamplerState_SRC*)stream->resampler_state;
   675     SDL_AudioStreamResamplerState_SRC *state = (SDL_AudioStreamResamplerState_SRC*)stream->resampler_state;
   676     SRC_DATA data;
   676     SRC_DATA data;
   677     int result;
   677     int result;
   678 
   678 
   679     data.data_in = inbuf;
   679     data.data_in = (float *)inbuf; /* Older versions of libsamplerate had a non-const pointer, but didn't write to it */
   680     data.input_frames = inbuflen / ( sizeof(float) * stream->pre_resample_channels );
   680     data.input_frames = inbuflen / ( sizeof(float) * stream->pre_resample_channels );
   681     data.input_frames_used = 0;
   681     data.input_frames_used = 0;
   682 
   682 
   683     data.data_out = outbuf;
   683     data.data_out = outbuf;
   684     data.output_frames = outbuflen / (sizeof(float) * stream->pre_resample_channels);
   684     data.output_frames = outbuflen / (sizeof(float) * stream->pre_resample_channels);
   750         return SDL_FALSE;
   750         return SDL_FALSE;
   751     }
   751     }
   752     return SDL_TRUE;
   752     return SDL_TRUE;
   753 }
   753 }
   754 
   754 
   755 #endif /* HAVE_LIBSAMPLERATE */
   755 #endif /* HAVE_LIBSAMPLERATE_H */
   756 
   756 
   757 typedef struct
   757 typedef struct
   758 {
   758 {
   759     SDL_bool resampler_seeded;
   759     SDL_bool resampler_seeded;
   760     float resampler_state[8];
   760     float resampler_state[8];
   871         if (SDL_BuildAudioCVT(&retval->cvt_before_resampling, src_format, src_channels, src_rate, AUDIO_F32SYS, pre_resample_channels, src_rate) < 0) {
   871         if (SDL_BuildAudioCVT(&retval->cvt_before_resampling, src_format, src_channels, src_rate, AUDIO_F32SYS, pre_resample_channels, src_rate) < 0) {
   872             SDL_FreeAudioStream(retval);
   872             SDL_FreeAudioStream(retval);
   873             return NULL;  /* SDL_BuildAudioCVT should have called SDL_SetError. */
   873             return NULL;  /* SDL_BuildAudioCVT should have called SDL_SetError. */
   874         }
   874         }
   875 
   875 
   876 #ifdef HAVE_LIBSAMPLERATE
   876 #ifdef HAVE_LIBSAMPLERATE_H
   877         SetupLibSampleRateResampling(retval);
   877         SetupLibSampleRateResampling(retval);
   878 #endif
   878 #endif
   879 
   879 
   880         if (!retval->resampler_func) {
   880         if (!retval->resampler_func) {
   881             retval->resampler_state = SDL_calloc(1, sizeof(SDL_AudioStreamResamplerState));
   881             retval->resampler_state = SDL_calloc(1, sizeof(SDL_AudioStreamResamplerState));