Advertisement
Kitomas

using kit_w32_audio's waveOut functionality

Jun 29th, 2023
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | Source Code | 0 0
  1. #include <combaseapi.h>
  2. #include <stdint.h>
  3. #include <math.h>
  4.  
  5. #define KIT_AUDIO_USE_WINMM
  6. #include <kit_w32.h>
  7.  
  8. extern int printf(const char* __format, ...);
  9.  
  10. float getSinSample(){
  11.   static int sample=0;
  12.   float value=sinf(PI*2*440*((float)sample/11025));
  13.   ++sample;
  14.   return value;
  15. }
  16.  
  17. void callback(void* userdata, void* stream, unsigned int len){
  18.   float* stream_flt=stream;
  19.   for(unsigned int i=0; i<len; ++i) stream_flt[i]=getSinSample();
  20. }
  21.  
  22. int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int nCmdShow){
  23.   kit_audioSpec spec;
  24.   spec.callback=callback;
  25.   spec.buffer_len=4096;
  26.   spec.frequency=11025;
  27.   spec.channels=1;
  28.   spec.format=KIT_AUDIO_FMT_F32;
  29.  
  30.   int returnStatus;
  31.   kit_audioDevice* device=kit_audioWaveOutOpen(&spec,-1,&returnStatus);
  32.   if(!device){ printf("returnStatus=%i\n",returnStatus); return 0; }
  33.  
  34.   kit_audioWaveOutPlay(device,1);
  35.   Sleep(1000);
  36.  
  37.   //you'd then close the device (if only waveOutReset worked...)
  38.  
  39.   return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement