Esempio n. 1
0
void
swap_phontab (const char *infile, const char *outfile)
{
    FILE *in, *out;
    char buf_4[4];
    int i, n_phoneme_tables;

    in = fopen (infile, "rb");
    if (in == NULL) {
        fprintf (stderr, "Unable to read from file %s\n", infile);
        exit (1);
    }

    out = fopen (outfile, "wb");
    if (out == NULL) {
        fprintf (stderr, "Unable to open file %s for writing\n", outfile);
        exit (1);
    }

    fread (buf_4, 4, 1, in);
    fwrite (buf_4, 4, 1, out);
    n_phoneme_tables = buf_4[0];

    for (i = 0; i < n_phoneme_tables; i++) {
        int n_phonemes, j;
        char tab_name[N_PHONEME_TAB_NAME];

        fread (buf_4, 4, 1, in);
        fwrite (buf_4, 4, 1, out);

        n_phonemes = buf_4[0];

        fread (tab_name, N_PHONEME_TAB_NAME, 1, in);
        fwrite (tab_name, N_PHONEME_TAB_NAME, 1, out);

        for (j = 0; j < n_phonemes; j++) {
            PHONEME_TAB table;

            fread (&table, sizeof (PHONEME_TAB), 1, in);

            table.mnemonic = SWAP_UINT (table.mnemonic);
            table.phflags = SWAP_UINT (table.phflags);

            table.std_length = SWAP_USHORT (table.std_length);
            table.spect = SWAP_USHORT (table.spect);
            table.before = SWAP_USHORT (table.before);
            table.after = SWAP_USHORT (table.after);

            fwrite (&table, sizeof (PHONEME_TAB), 1, out);
        }
    }

    fclose (in);
    fclose (out);
}
Esempio n. 2
0
void swap_phonindex (const char *infile, const char *outfile)
{   //==========================================================
    FILE *in, *out;
    char buf_4[4];
    unsigned short val;

    in = fopen (infile, "rb");
    if (in == NULL) {
        fprintf (stderr, "Unable to read from file %s\n", infile);
        exit (1);
    }

    out = fopen (outfile, "wb");
    if (out == NULL) {
        fprintf (stderr, "Unable to open file %s for writing\n", outfile);
        exit (1);
    }

    xread = fread (buf_4, 4, 1, in);  // skip first 4 bytes
    fwrite(buf_4, 4, 1, out);

    while (! feof (in)) {
        size_t n;

        n = fread (&val, 2, 1, in);
        if (n != 1)
            break;

        val = SWAP_USHORT (val);
        fwrite (&val, 2, 1, out);
    }

    fclose (in);
    fclose (out);
}  // end of swap_phonindex
Esempio n. 3
0
void swap_phontab (const char *infile, const char *outfile)
{   //========================================================
    FILE *in, *out;
    char buf_8[8];
    int i, n_phoneme_tables;

    in = fopen (infile, "rb");
    if (in == NULL) {
        fprintf (stderr, "Unable to read from file %s\n", infile);
        exit (1);
    }

    out = fopen (outfile, "wb");
    if (out == NULL) {
        fprintf (stderr, "Unable to open file %s for writing\n", outfile);
        exit (1);
    }

    xread = fread (buf_8, 4, 1, in);
    fwrite (buf_8, 4, 1, out);
    n_phoneme_tables = buf_8[0];

    for (i = 0; i < n_phoneme_tables; i++) {
        int n_phonemes, j;
        char tab_name[N_PHONEME_TAB_NAME];

        xread = fread (buf_8, 8, 1, in);
        fwrite (buf_8, 8, 1, out);

        n_phonemes = buf_8[0];

        xread = fread (tab_name, N_PHONEME_TAB_NAME, 1, in);
        fwrite (tab_name, N_PHONEME_TAB_NAME, 1, out);

        for (j = 0; j < n_phonemes; j++) {
            PHONEME_TAB table;

            xread = fread (&table, sizeof (PHONEME_TAB), 1, in);

            table.mnemonic = SWAP_UINT (table.mnemonic);
            table.phflags = SWAP_UINT (table.phflags);
            table.program = SWAP_USHORT (table.program);

            fwrite (&table, sizeof (PHONEME_TAB), 1, out);
        }
    }

    fclose (in);
    fclose (out);
}  // end of swap_phontab
Esempio n. 4
0
void swap_phondata  (const char *infile, const char *outfile,
                     const char *manifest)
{   //==========================================================
    FILE *in, *mfest, *out;
    int displ;
    int displ_out;
    int errorflag_displ = 0;  // only report the first displ mismatch error
    char line[1024];
    unsigned char buf_4[4];

    in = fopen (infile, "rb");
    if (in == NULL) {
        fprintf (stderr, "Unable to read from file %s\n", infile);
        exit (1);
    }

    mfest = fopen (manifest, "rb");
    if (mfest == NULL) {
        fprintf (stderr, "Unable to read from file %s\n", manifest);
        exit (1);
    }

    out = fopen (outfile, "wb");
    if (out == NULL) {
        fprintf (stderr, "Unable to open file %s for writing\n", outfile);
        exit (1);
    }

    xread = fread(buf_4, 4, 1, in);   // version number
    fwrite(buf_4, 4, 1, out);
    xread = fread(buf_4, 4, 1, in);   // sample rate
    fwrite(buf_4, 4, 1, out);

    while (fgets (line, sizeof(line), mfest))
    {
        if(!isupper(line[0])) continue;

        sscanf(&line[2],"%x",&displ);
        fseek(in, displ, SEEK_SET);
        fflush(out);
        displ_out = ftell(out);
        if((errorflag_displ==0) && (displ != displ_out))
        {
            fprintf(stderr, "Length error at the line before:   %s", line);
            errorflag_displ = 1;
        }

        if (line[0] == 'S') {
            SPECT_SEQ buf_spect;
            size_t frame_start;
            int n;

            xread = fread(&buf_spect, 4, 1, in);
            buf_spect.length = (short) SWAP_USHORT (buf_spect.length);
            fwrite(&buf_spect, 4, 1, out);

            for (n = 0; n < buf_spect.n_frames; n++) {
                int k;

                frame_start = ftell(in);
                xread = fread(&buf_spect.frame[0], sizeof(frame_t), 1, in);

                buf_spect.frame[0].frflags = (short)
                                             SWAP_USHORT (buf_spect.frame[0].frflags);

// Changed for eSpeak 1.41
                for (k = 0; k < 7; k++) {
                    buf_spect.frame[0].ffreq[k] = (short)
                                                  SWAP_USHORT (buf_spect.frame[0].ffreq[k]);
                }

                // is this a long or a short frame?
                if(buf_spect.frame[0].frflags & FRFLAG_KLATT)
                {
                    fwrite(&buf_spect.frame[0], sizeof(frame_t), 1, out);
                    fseek(in, frame_start + sizeof(frame_t), SEEK_SET);
                }
                else
                {
                    fwrite(&buf_spect.frame[0], sizeof(frame_t2), 1, out);
                    fseek(in, frame_start + sizeof(frame_t2), SEEK_SET);
                }
            }
        }
        else if (line[0] == 'W') {
            long pos;
            int length;
            char *wave_data;

            xread = fread (buf_4, 4, 1, in);
            fwrite (buf_4, 4, 1, out);

            length = buf_4[1] * 256 + buf_4[0];

            wave_data = (char *) malloc (length);
            if (wave_data == NULL) {
                fprintf (stderr, "Memory allocation error\n");
                exit (1);
            }

            xread = fread (wave_data, 1, length, in);
            fwrite (wave_data, 1, length, out);

            pos = ftell (in);
            while((pos & 3) != 0) {
                fgetc (in);
                pos++;
            }

            pos = ftell (out);
            while((pos & 3) != 0) {
                fputc (0, out);
                pos++;
            }

            free (wave_data);
        }
        else if (line[0] == 'E') {
            char env_buf[128];

            xread = fread (env_buf, 1, 128, in);
            fwrite (env_buf, 1, 128, out);
        }
        else if (line[0] == 'Q') {
            unsigned char pb[4];
            unsigned length;
            char *buf;

            xread = fread (pb, 1, 4, in);
            fwrite (pb, 1, 4, out);

            length = (pb[2] << 8) + pb[3]; // size in words
            length *= 4;

            buf = (char *) malloc (length);

            xread = fread (buf, length, 1, in);
            fwrite (buf, length, 1, out);

            free (buf);
        }
    }

    fclose (in);
    fclose (out);
    fclose (mfest);
}  // end of swap_phondata
Esempio n. 5
0
U8 * CSimAppToolkit::SATCovertStringForSIM(U8 *data, U16 len, U8 format, U16 *outLen)
{
	U8 *convertedData;

	if (len > 0)
    {
		switch (format)
		{
		#if 0
/* under construction !*/
			#ifdef __ASCII
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
			#endif
/* under construction !*/
			#ifdef __UCS2_ENCODING
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
			#endif
/* under construction !*/
/* under construction !*/
		#endif	

			case SAT_8BIT_DCS:
			#ifdef __ASCII
				convertedData = (U8 *)malloc((len)+1);
				memcpy(convertedData,data,len);
				memset((void *)&convertedData[len*ENCODING_LENGTH],0,1);
				if(outLen!=NULL) *outLen=len+1;
			#endif
			#ifdef __UCS2_ENCODING
				convertedData = malloc((len/ENCODING_LENGTH)+1);
				UnicodeNToAnsii((PS8)convertedData,(PS8)data,len);
				memset((void *)&convertedData[len/ENCODING_LENGTH],0,1);
				if(outLen!=NULL) *outLen=len/ENCODING_LENGTH+1;
			#endif
			break;

			case SAT_UCS2_DCS:
			#ifdef __ASCII
					convertedData = (U8 *)malloc((len*2)+2);
					AnsiiNToUnicodeString((PS8)convertedData,(PS8)data,len);
					memset((void *)&convertedData[len*2],0,2);
					if(outLen!=NULL) *outLen=len*2+2;
			#endif
			#ifdef __UCS2_ENCODING
					convertedData = malloc((len)+ENCODING_LENGTH);
					memcpy(convertedData,data,len);
					memset((void *)&convertedData[len],0,ENCODING_LENGTH);
					if(outLen!=NULL) *outLen=len+ENCODING_LENGTH;
			#endif
			#ifdef MMI_ON_HARDWARE_P
			{
				U16 *tempData;
				int i;
				tempData=(U16 *)convertedData;
				for(i=0;i<len*2/ENCODING_LENGTH;i+=2)
				{
					SWAP_USHORT(tempData);
					tempData++;
				}
			}
			#endif
			break;
		}

		return convertedData;
	}
	else
	{
		U8 noOfNulls;
		if(format==SAT_UCS2_DCS) noOfNulls=2;
		else noOfNulls=1;
		convertedData = (U8 *)malloc(noOfNulls);
		memset((void *)convertedData,0,noOfNulls);
		if(outLen!=NULL) *outLen=noOfNulls;
	 	return convertedData;
	}
}
Esempio n. 6
0
static HRESULT load_IFD_entry(IStream *input, const struct IFD_entry *entry,
                              MetadataItem *item, BOOL native_byte_order)
{
    ULONG count, value, i, bytesread;
    SHORT type;
    LARGE_INTEGER pos;
    HRESULT hr;

    item->schema.vt = VT_EMPTY;
    item->id.vt = VT_UI2;
    item->id.u.uiVal = entry->id;
    SWAP_USHORT(item->id.u.uiVal);

    count = entry->count;
    SWAP_ULONG(count);
    type = entry->type;
    SWAP_USHORT(type);
    item->value.vt = tag_to_vt(type);
    value = entry->value;
    SWAP_ULONG(value);

    switch (type)
    {
     case IFD_BYTE:
     case IFD_SBYTE:
        if (!count) count = 1;

        if (count <= 4)
        {
            const BYTE *data = (const BYTE *)&entry->value;

            if (count == 1)
                item->value.u.bVal = data[0];
            else
            {
                item->value.vt |= VT_VECTOR;
                item->value.u.caub.cElems = count;
                item->value.u.caub.pElems = HeapAlloc(GetProcessHeap(), 0, count);
                memcpy(item->value.u.caub.pElems, data, count);
            }
            break;
        }

        item->value.vt |= VT_VECTOR;
        item->value.u.caub.cElems = count;
        item->value.u.caub.pElems = HeapAlloc(GetProcessHeap(), 0, count);
        if (!item->value.u.caub.pElems) return E_OUTOFMEMORY;

        pos.QuadPart = value;
        hr = IStream_Seek(input, pos, SEEK_SET, NULL);
        if (FAILED(hr))
        {
            HeapFree(GetProcessHeap(), 0, item->value.u.caub.pElems);
            return hr;
        }
        hr = IStream_Read(input, item->value.u.caub.pElems, count, &bytesread);
        if (bytesread != count) hr = E_FAIL;
        if (hr != S_OK)
        {
            HeapFree(GetProcessHeap(), 0, item->value.u.caub.pElems);
            return hr;
        }
        break;
    case IFD_SHORT:
    case IFD_SSHORT:
        if (!count) count = 1;

        if (count <= 2)
        {
            const SHORT *data = (const SHORT *)&entry->value;

            if (count == 1)
            {
                item->value.u.uiVal = data[0];
                SWAP_USHORT(item->value.u.uiVal);
            }
            else
            {
                item->value.vt |= VT_VECTOR;
                item->value.u.caui.cElems = count;
                item->value.u.caui.pElems = HeapAlloc(GetProcessHeap(), 0, count * 2);
                memcpy(item->value.u.caui.pElems, data, count * 2);
                for (i = 0; i < count; i++)
                    SWAP_USHORT(item->value.u.caui.pElems[i]);
            }
            break;
        }

        item->value.vt |= VT_VECTOR;
        item->value.u.caui.cElems = count;
        item->value.u.caui.pElems = HeapAlloc(GetProcessHeap(), 0, count * 2);
        if (!item->value.u.caui.pElems) return E_OUTOFMEMORY;

        pos.QuadPart = value;
        hr = IStream_Seek(input, pos, SEEK_SET, NULL);
        if (FAILED(hr))
        {
            HeapFree(GetProcessHeap(), 0, item->value.u.caui.pElems);
            return hr;
        }
        hr = IStream_Read(input, item->value.u.caui.pElems, count * 2, &bytesread);
        if (bytesread != count * 2) hr = E_FAIL;
        if (hr != S_OK)
        {
            HeapFree(GetProcessHeap(), 0, item->value.u.caui.pElems);
            return hr;
        }
        for (i = 0; i < count; i++)
            SWAP_USHORT(item->value.u.caui.pElems[i]);
        break;
    case IFD_LONG:
    case IFD_SLONG:
    case IFD_FLOAT:
        if (!count) count = 1;

        if (count == 1)
        {
            item->value.u.ulVal = value;
            break;
        }

        item->value.vt |= VT_VECTOR;
        item->value.u.caul.cElems = count;
        item->value.u.caul.pElems = HeapAlloc(GetProcessHeap(), 0, count * 4);
        if (!item->value.u.caul.pElems) return E_OUTOFMEMORY;

        pos.QuadPart = value;
        hr = IStream_Seek(input, pos, SEEK_SET, NULL);
        if (FAILED(hr))
        {
            HeapFree(GetProcessHeap(), 0, item->value.u.caul.pElems);
            return hr;
        }
        hr = IStream_Read(input, item->value.u.caul.pElems, count * 4, &bytesread);
        if (bytesread != count * 4) hr = E_FAIL;
        if (hr != S_OK)
        {
            HeapFree(GetProcessHeap(), 0, item->value.u.caul.pElems);
            return hr;
        }
        for (i = 0; i < count; i++)
            SWAP_ULONG(item->value.u.caul.pElems[i]);
        break;
    case IFD_RATIONAL:
    case IFD_SRATIONAL:
    case IFD_DOUBLE:
        if (!count)
        {
            FIXME("IFD field type %d, count 0\n", type);
            item->value.vt = VT_EMPTY;
            break;
        }

        if (count == 1)
        {
            ULONGLONG ull;

            pos.QuadPart = value;
            hr = IStream_Seek(input, pos, SEEK_SET, NULL);
            if (FAILED(hr)) return hr;

            hr = IStream_Read(input, &ull, sizeof(ull), &bytesread);
            if (bytesread != sizeof(ull)) hr = E_FAIL;
            if (hr != S_OK) return hr;

            item->value.u.uhVal.QuadPart = ull;

            if (type == IFD_DOUBLE)
                SWAP_ULONGLONG(item->value.u.uhVal.QuadPart);
            else
            {
                SWAP_ULONG(item->value.u.uhVal.u.LowPart);
                SWAP_ULONG(item->value.u.uhVal.u.HighPart);
            }
            break;
        }
        else
        {
            item->value.vt |= VT_VECTOR;
            item->value.u.cauh.cElems = count;
            item->value.u.cauh.pElems = HeapAlloc(GetProcessHeap(), 0, count * 8);
            if (!item->value.u.cauh.pElems) return E_OUTOFMEMORY;

            pos.QuadPart = value;
            hr = IStream_Seek(input, pos, SEEK_SET, NULL);
            if (FAILED(hr))
            {
                HeapFree(GetProcessHeap(), 0, item->value.u.cauh.pElems);
                return hr;
            }
            hr = IStream_Read(input, item->value.u.cauh.pElems, count * 8, &bytesread);
            if (bytesread != count * 8) hr = E_FAIL;
            if (hr != S_OK)
            {
                HeapFree(GetProcessHeap(), 0, item->value.u.cauh.pElems);
                return hr;
            }
            for (i = 0; i < count; i++)
            {
                if (type == IFD_DOUBLE)
                    SWAP_ULONGLONG(item->value.u.cauh.pElems[i].QuadPart);
                else
                {
                    SWAP_ULONG(item->value.u.cauh.pElems[i].u.LowPart);
                    SWAP_ULONG(item->value.u.cauh.pElems[i].u.HighPart);
                }
            }
        }
        break;
    case IFD_ASCII:
        item->value.u.pszVal = HeapAlloc(GetProcessHeap(), 0, count + 1);
        if (!item->value.u.pszVal) return E_OUTOFMEMORY;

        if (count <= 4)
        {
            const char *data = (const char *)&entry->value;
            memcpy(item->value.u.pszVal, data, count);
            item->value.u.pszVal[count] = 0;
            break;
        }

        pos.QuadPart = value;
        hr = IStream_Seek(input, pos, SEEK_SET, NULL);
        if (FAILED(hr))
        {
            HeapFree(GetProcessHeap(), 0, item->value.u.pszVal);
            return hr;
        }
        hr = IStream_Read(input, item->value.u.pszVal, count, &bytesread);
        if (bytesread != count) hr = E_FAIL;
        if (hr != S_OK)
        {
            HeapFree(GetProcessHeap(), 0, item->value.u.pszVal);
            return hr;
        }
        item->value.u.pszVal[count] = 0;
        break;
    case IFD_UNDEFINED:
        if (!count)
        {
            FIXME("IFD field type %d, count 0\n", type);
            item->value.vt = VT_EMPTY;
            break;
        }

        item->value.u.blob.pBlobData = HeapAlloc(GetProcessHeap(), 0, count);
        if (!item->value.u.blob.pBlobData) return E_OUTOFMEMORY;

        item->value.u.blob.cbSize = count;

        if (count <= 4)
        {
            const char *data = (const char *)&entry->value;
            memcpy(item->value.u.blob.pBlobData, data, count);
            break;
        }

        pos.QuadPart = value;
        hr = IStream_Seek(input, pos, SEEK_SET, NULL);
        if (FAILED(hr))
        {
            HeapFree(GetProcessHeap(), 0, item->value.u.blob.pBlobData);
            return hr;
        }
        hr = IStream_Read(input, item->value.u.blob.pBlobData, count, &bytesread);
        if (bytesread != count) hr = E_FAIL;
        if (hr != S_OK)
        {
            HeapFree(GetProcessHeap(), 0, item->value.u.blob.pBlobData);
            return hr;
        }
        break;
    default:
        FIXME("loading field of type %d, count %u is not implemented\n", type, count);
        break;
    }
    return S_OK;
}
Esempio n. 7
0
static HRESULT LoadIfdMetadata(IStream *input, const GUID *preferred_vendor,
    DWORD persist_options, MetadataItem **items, DWORD *item_count)
{
    HRESULT hr;
    MetadataItem *result;
    USHORT count, i;
    struct IFD_entry *entry;
    BOOL native_byte_order = TRUE;
    ULONG bytesread;

    TRACE("\n");

#ifdef WORDS_BIGENDIAN
    if (persist_options & WICPersistOptionsLittleEndian)
#else
    if (persist_options & WICPersistOptionsBigEndian)
#endif
        native_byte_order = FALSE;

    hr = IStream_Read(input, &count, sizeof(count), &bytesread);
    if (bytesread != sizeof(count)) hr = E_FAIL;
    if (hr != S_OK) return hr;

    SWAP_USHORT(count);

    entry = HeapAlloc(GetProcessHeap(), 0, count * sizeof(*entry));
    if (!entry) return E_OUTOFMEMORY;

    hr = IStream_Read(input, entry, count * sizeof(*entry), &bytesread);
    if (bytesread != count * sizeof(*entry)) hr = E_FAIL;
    if (hr != S_OK)
    {
        HeapFree(GetProcessHeap(), 0, entry);
        return hr;
    }

    /* limit number of IFDs to 4096 to avoid infinite loop */
    for (i = 0; i < 4096; i++)
    {
        ULONG next_ifd_offset;
        LARGE_INTEGER pos;
        USHORT next_ifd_count;

        hr = IStream_Read(input, &next_ifd_offset, sizeof(next_ifd_offset), &bytesread);
        if (bytesread != sizeof(next_ifd_offset)) hr = E_FAIL;
        if (hr != S_OK) break;

        SWAP_ULONG(next_ifd_offset);
        if (!next_ifd_offset) break;

        pos.QuadPart = next_ifd_offset;
        hr = IStream_Seek(input, pos, SEEK_SET, NULL);
        if (FAILED(hr)) break;

        hr = IStream_Read(input, &next_ifd_count, sizeof(next_ifd_count), &bytesread);
        if (bytesread != sizeof(next_ifd_count)) hr = E_FAIL;
        if (hr != S_OK) break;

        SWAP_USHORT(next_ifd_count);

        pos.QuadPart = next_ifd_count * sizeof(*entry);
        hr = IStream_Seek(input, pos, SEEK_CUR, NULL);
        if (FAILED(hr)) break;
    }

    if (hr != S_OK || i == 4096)
    {
        HeapFree(GetProcessHeap(), 0, entry);
        return WINCODEC_ERR_BADMETADATAHEADER;
    }

    result = HeapAlloc(GetProcessHeap(), 0, count * sizeof(*result));
    if (!result)
    {
        HeapFree(GetProcessHeap(), 0, entry);
        return E_OUTOFMEMORY;
    }

    for (i = 0; i < count; i++)
    {
        hr = load_IFD_entry(input, &entry[i], &result[i], native_byte_order);
        if (FAILED(hr))
        {
            HeapFree(GetProcessHeap(), 0, entry);
            HeapFree(GetProcessHeap(), 0, result);
            return hr;
        }
    }

    HeapFree(GetProcessHeap(), 0, entry);

    *items = result;
    *item_count = count;

    return S_OK;
}
Esempio n. 8
0
void
swap_phondata  (const char *infile, const char *outfile,
                const char *manifest)
{
    FILE *in, *mfest, *out;
    char line[1024];
    unsigned char buf_4[4];

    in = fopen (infile, "rb");
    if (in == NULL) {
        fprintf (stderr, "Unable to read from file %s\n", infile);
        exit (1);
    }

    mfest = fopen (manifest, "rb");
    if (mfest == NULL) {
        fprintf (stderr, "Unable to read from file %s\n", manifest);
        exit (1);
    }

    out = fopen (outfile, "wb");
    if (out == NULL) {
        fprintf (stderr, "Unable to open file %s for writing\n", outfile);
        exit (1);
    }

    fread (buf_4, 4, 1, in);
    fwrite (buf_4, 4, 1, out);

    while (fgets (line, 1024, mfest)) {
        if (line[0] == 'S') {
            SPECT_SEQ buf_spect;
            size_t ix;
            int n;

            fread (&buf_spect.length, 2, 1, in);
            fread (&buf_spect.n_frames, 1, 1, in);
            fseek (in, -3, SEEK_CUR);

            ix = (char *)(&buf_spect.frame[buf_spect.n_frames]) -
                (char *)(&buf_spect);
            ix = (ix+3) & 0xfffc;

            fread (&buf_spect, ix, 1, in);

            buf_spect.length = (short) SWAP_USHORT (buf_spect.length);
            for (n = 0; n < buf_spect.n_frames; n++) {
                int k;

                buf_spect.frame[n].frflags = (short)
                    SWAP_USHORT (buf_spect.frame[n].frflags);

                for (k = 0; k < 9; k++) {
                    buf_spect.frame[n].ffreq[k] = (short)
                        SWAP_USHORT (buf_spect.frame[n].ffreq[k]);
                }
            }

            fwrite (&buf_spect, ix, 1, out);
        }
        else if (line[0] == 'W') {
            long pos;
            int length;
            char *wave_data;

            fread (buf_4, 4, 1, in);
            fwrite (buf_4, 4, 1, out);

            length = buf_4[1] * 256 + buf_4[0];

            wave_data = (char *) malloc (length);
            if (wave_data == NULL) {
                fprintf (stderr, "Memory allocation error\n");
                exit (1);
            }

            fread (wave_data, 1, length, in);
            fwrite (wave_data, 1, length, out);

            pos = ftell (in);
            while((pos & 3) != 0) {
                fgetc (in);
                pos++;
            }

            pos = ftell (out);
            while((pos & 3) != 0) {
                fputc (0, out);
                pos++;
            }

            free (wave_data);
        }
        else if (line[0] == 'E') {
            char env_buf[128];

            fread (env_buf, 1, 128, in);
            fwrite (env_buf, 1, 128, out);
        }
    }

    fclose (in);
    fclose (out);
    fclose (mfest);
}