[SDL] compiling sounds into binaries

Mattias Karlsson betasoft at acc.umu.se
Sat Jun 24 06:44:53 PDT 2006


On Sat, 24 Jun 2006, Neil White wrote:

> does anone have any <i>simple</i> methods of compiling sound files into binary
> files similar to compiling xpm's into the binarys?
>
> remember i am stupid and lazy.

I would write myself a bin->c converter similar to (untested):

   #include <stdio.h>
   int main(int argc, char *argv[])
   {
     FILE *in,*out;
     int value;

     in=fopen(argv[1],"rb");
     out=fopen(argv[2],"w");
     fprintf(out, "static unsigned char NAME_HERE[] = {\n");
     while(EOF != (value = fgetc(in))
       fprintf(out, "   %d,\n", value);
     fprintf(out, "};\n");
   }


Run it like: "bin2c file.wav file.c"

Edit file.c and give the array a better name, and include it in your 
project.

Finaly, use SDL_RWFromMem() instead of SDL_RWFromFile()




More information about the SDL mailing list