if(save)
{
    PACKFILE *pfp;
    int bps = speak->bits/8 * ((speak->stereo) ? 2 : 1);
    int i, s;
    pfp = pack_fopen("out.wav", F_WRITE);
    pack_fputs("RIFF", pfp);                                /* RIFF header */
    pack_iputl(36+length2, pfp);                            /* size of RIFF chunk */
    pack_fputs("WAVE", pfp);                                /* WAV definition */
    pack_fputs("fmt ", pfp);                                /* format chunk */
    pack_iputl(16, pfp);                                        /* size of format chunk */
    pack_iputw(1, pfp);                                        /* PCM data */
    pack_iputw((speak->stereo) ? 2 : 1, pfp);            /* mono/stereo data */
    pack_iputl(speak->freq, pfp);                            /* sample frequency */
    pack_iputl(speak->freq*bps, pfp);                    /* avg. bytes per sec */
    pack_iputw(bps, pfp);                                    /* block alignment */
    pack_iputw(speak->bits, pfp);                            /* bits per sample */
    pack_fputs("data", pfp);                                /* data chunk */
    pack_iputl(length2, pfp);                                /* actual data length */
    if (speak->bits == 8) {
        pack_fwrite(speak->data, length2, pfp);        /* write the data */
    }
    else {
        for (i=0; i < (int)speak->len * ((speak->stereo) ? 2 : 1); i++) {
            s = ((signed short *)speak->data)[i];
            pack_iputw(s^0x8000, pfp);
        }
    }
    pack_fclose(pfp);    
    save=FALSE;
}
