[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fw: [Tinycc-devel] windows resources, playsound, xp theme (just rese

From: Jakob Eriksson
Subject: Re: Fw: [Tinycc-devel] windows resources, playsound, xp theme (just resending to the group)
Date: Tue, 03 Oct 2006 13:42:25 +0200
User-agent: Thunderbird (X11/20060909)

bj wrote:
ok, so if i do this:
1. open a .wav file using notepad
2. copy the contents of the .wav file from notepad
3. create a
    char *soundstring="";
in my c file;
4. paste the contents of the .wav file between the quotes in
    char *soundstring="";
like so
    char *soundstring="IOBD820Ṳ鷏..";//or something like that
5. escape the characters in *soundstring
6. and use fopen ("file.wav", "wb") to write the characters of *soundstring to file.wav
this will work?

This is getting off topic, but you cant do it exactly like that, because some numbers
in a .wav file have no printable characters who you can paste from notepad.

Instead you need to convert the wav file to a numbers description suitable for a C compiler.

Something like this:

#include <stdio.h>

int main ()
  FILE *fp;
  int c, first;

  fp = fopen ("nicesound.wav", "rb");

  printf ("unsigned char nicesound_buf[] = {\n");

  first = 1;
     c = fgetc (fp);
     if (!first && EOF != c)
        printf (", ");
     first = 0;

     if (EOF != c)
        printf ("%u\n", c);
  } (EOF != c);

  fclose (fp);

  printf ("}\n");

  return 0;

compile this program and run it with ./programname >  sound.c

then include sound.c into your program and in your program dump the buffer like this:

int dumpsound (void)
  FILE *fp;

  fp = fopen ("dump.wav", "wb");
  if (!fp)
     fprintf (stderr, "Can not open file.\n");

     return 1;

  fwrite (nicesound_buf, sizeof (nicesound_buf), 1, fp);

  fclose (fp);

  return 0;

After that you can play your sound in dump.wav

Of course, this is untested code, but hopefully the concept comes through. You also need to think about where you put your file and so on. Also there will be as many lines in sound.c as there are bytes in the wav, so for testing I suggest you start with as small a wav file as possible.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]