title: Playing sound from a memory buffer in pure WinAPI
body: <p>I have tried several ways to play sound using either MediaFoundation or the simple PlaySound method. Both of these seem to expect a .WAV file. I can't play sound from a WAVE file since I'm getting the data from internet and discarding it right once it is played. I need it to be efficient and fast and done directly from a memory buffer. MediaFoundations code to playback audio is very long and requires several steps. While PlaySound is simple but it doesn't play my sound from memory buffer. I've also tried SDL_mixer but I can't seem to set the sound buffer directly instead of relying on SDL_LoadWav. Here's my PlaySound code taken from here <a href="https://stackoverflow.com/questions/32320825/load-wavs-into-memory-then-play-sounds-asynchronously-using-win32-api">Load wavs into memory then play sounds asynchronously using Win32 API</a>:</p>
  <pre><code>unsigned char* sounddata;
  hr = pSoundBuffer-&gt;Lock(&amp;sounddata, NULL, &amp;soundlength);
  PlaySound((LPCWSTR) sounddata, GetModuleHandle(NULL), SND_MEMORY);
  </code></pre>
  <p>Here's my SDL_mixer code:</p>
  <pre><code>SDL_Init(SDL_INIT_AUDIO);
  Mix_OpenAudio(22050, AUDIO_S16, 2, NULL);
  Mix_Chunk* sound = new Mix_Chunk();
  sound-&gt;allocated = 1;
  sound-&gt;abuf = sounddata;
  sound-&gt;alen = soundlength;
  sound-&gt;volume = 128;
  Mix_PlayChannel(-1, sound, 0);
  </code></pre>
  <p>With SDL_mixer I'm just getting random noise. So my question is how to play sound simply from memory buffer either by using SDL_mixer or the PlaySound function. Are there any other alternatives (other then MediaFoundation)?</p>