Skip to content

Instantly share code, notes, and snippets.

@Buggem
Created September 30, 2026 18:14
Show Gist options
  • Select an option

  • Save Buggem/a75ee54ba7a13e53f42c412a520bda20 to your computer and use it in GitHub Desktop.

Select an option

Save Buggem/a75ee54ba7a13e53f42c412a520bda20 to your computer and use it in GitHub Desktop.
Quick and dirty C gadget to convert sndfile formats to PortAudio formats
#include <portaudio.h>
#include <sndfile.h>
static inline PaSampleFormat sndFileToPa(int format)
{
switch(format & SF_FORMAT_SUBMASK)
{
case SF_FORMAT_PCM_S8:
return paInt8;
case SF_FORMAT_PCM_16:
return paInt16;
case SF_FORMAT_PCM_24:
return paInt24;
case SF_FORMAT_PCM_32:
return paInt32;
case SF_FORMAT_PCM_U8:
return paUInt8;
case SF_FORMAT_FLOAT:
return paFloat32;
}
return (PaSampleFormat)-1; // error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment