Advertisement
Kitomas

f32 stereo voice callback example

Sep 29th, 2023
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. unsigned currentSample=0;
  2. void user_callback(void* userdata, void* _stream, int size, SDL_bool hasInput){
  3.   if(userdata == NULL){ exit_early: memset(_stream,0,size); return; }
  4.  
  5.   kit_acodecPCM* pcm = userdata;
  6.   Uint64 numSamples = pcm->numSamples;
  7.   kit_acodecPCM_F32S* src = pcm->f32s;
  8.  
  9.   if(pcm->format != AUDIO_F32) goto exit_early;
  10.   if(pcm->channels != 2) goto exit_early;
  11.   if(currentSample >= numSamples) goto exit_early;
  12.  
  13.   memset(_stream,0,size);
  14.   kit_acodecPCM_F32S* dst=_stream; int len=size/(2*4);
  15.   for(int i=0; i<len; ++i){
  16.     dst[i] = src[currentSample];
  17.     dst[i].l *= 0.7;
  18.     dst[i].r *= 0.7;
  19.     if((++currentSample)>=numSamples){ currentSample=-1; break; }
  20.   }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement