From e2ba3703bb37d4620e97df28d916da3350a9dbbe Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sun, 13 Dec 2015 16:37:57 +0000 Subject: [PATCH] espeakedit: remove wxWidgets from spect.cpp --- Makefile.am | 1 + src/libespeak-ng/ieee80.c | 83 +++++++++++++++++++++++++++++++++++++++ src/spect.cpp | 71 +++++++++++++++++---------------- src/spect.h | 8 ++-- 4 files changed, 122 insertions(+), 41 deletions(-) create mode 100644 src/libespeak-ng/ieee80.c diff --git a/Makefile.am b/Makefile.am index 9f9fe5d6..8e3ee40c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -61,6 +61,7 @@ common_SOURCE = \ src/libespeak-ng/compiledict.c \ src/libespeak-ng/compilembrola.c \ src/libespeak-ng/dictionary.c \ + src/libespeak-ng/ieee80.c \ src/libespeak-ng/intonation.c \ src/libespeak-ng/numbers.c \ src/libespeak-ng/readclause.c \ diff --git a/src/libespeak-ng/ieee80.c b/src/libespeak-ng/ieee80.c new file mode 100644 index 00000000..177b1144 --- /dev/null +++ b/src/libespeak-ng/ieee80.c @@ -0,0 +1,83 @@ +/* + * C O N V E R T F R O M I E E E E X T E N D E D + */ + +/* + * Copyright (C) 1988-1991 Apple Computer, Inc. + * All rights reserved. + * + * Machine-independent I/O routines for IEEE floating-point numbers. + * + * NaN's and infinities are converted to HUGE_VAL or HUGE, which + * happens to be infinity on IEEE machines. Unfortunately, it is + * impossible to preserve NaN's in a machine-independent way. + * Infinities are, however, preserved on IEEE machines. + * + * These routines have been tested on the following machines: + * Apple Macintosh, MPW 3.1 C compiler + * Apple Macintosh, THINK C compiler + * Silicon Graphics IRIS, MIPS compiler + * Cray X/MP and Y/MP + * Digital Equipment VAX + * + * + * Implemented by Malcolm Slaney and Ken Turkowski. + * + * Malcolm Slaney contributions during 1988-1990 include big- and little- + * endian file I/O, conversion to and from Motorola's extended 80-bit + * floating-point format, and conversions to and from IEEE single- + * precision floating-point format. + * + * In 1991, Ken Turkowski implemented the conversions to and from + * IEEE double-precision format, added more precision to the extended + * conversions, and accommodated conversions involving +/- infinity, + * NaN's, and denormalized numbers. + */ + +#include + +#ifndef HUGE_VAL +# define HUGE_VAL HUGE +#endif /*HUGE_VAL*/ + +# define UnsignedToFloat(u) (((double)((long)(u - 2147483647L - 1))) + 2147483648.0) + +/**************************************************************** + * Extended precision IEEE floating-point conversion routine. + ****************************************************************/ + +double ConvertFromIeeeExtended(unsigned char *bytes /* LCN */) +{ + double f; + int expon; + unsigned long hiMant, loMant; + + expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF); + hiMant = ((unsigned long)(bytes[2] & 0xFF) << 24) + | ((unsigned long)(bytes[3] & 0xFF) << 16) + | ((unsigned long)(bytes[4] & 0xFF) << 8) + | ((unsigned long)(bytes[5] & 0xFF)); + loMant = ((unsigned long)(bytes[6] & 0xFF) << 24) + | ((unsigned long)(bytes[7] & 0xFF) << 16) + | ((unsigned long)(bytes[8] & 0xFF) << 8) + | ((unsigned long)(bytes[9] & 0xFF)); + + if (expon == 0 && hiMant == 0 && loMant == 0) { + f = 0; + } + else { + if (expon == 0x7FFF) { /* Infinity or NaN */ + f = HUGE_VAL; + } + else { + expon -= 16383; + f = ldexp(UnsignedToFloat(hiMant), expon-=31); + f += ldexp(UnsignedToFloat(loMant), expon-=32); + } + } + + if (bytes[0] & 0x80) + return -f; + else + return f; +} diff --git a/src/spect.cpp b/src/spect.cpp index d95f346b..2fb551c4 100644 --- a/src/spect.cpp +++ b/src/spect.cpp @@ -18,22 +18,19 @@ * . * ***************************************************************************/ - -#include "wx/wx.h" - #include "speak_lib.h" #include "speech.h" #include "phoneme.h" #include "synthesize.h" #include "voice.h" #include "spect.h" -#include "wx/wfstream.h" -#include "wx/txtstrm.h" -#include "wx/datstrm.h" #include #include +#include +#include +extern "C" double ConvertFromIeeeExtended(unsigned char *bytes); extern "C" int PeaksToHarmspect(wavegen_peaks_t *peaks, int pitch, int *htab, int control); extern unsigned char pk_shape1[]; @@ -53,9 +50,11 @@ static int default_width[N_PEAKS] = static int default_klt_bw[N_PEAKS] = {89,90,140,260,260,260,500,500,500}; -static void fread(void *ptr, int size, int count, wxInputStream &stream) +static double read_double(FILE *stream) { - stream.Read(ptr, count*size); + unsigned char bytes[10]; + fread(bytes,sizeof(char),10,stream); + return ConvertFromIeeeExtended(bytes); } float polint(float xa[],float ya[],int n,float x) @@ -152,43 +151,42 @@ static void SpectFrameDestroy(SpectFrame *frame) -int LoadFrame(SpectFrame &frame, wxInputStream& stream, int file_format_type) +int LoadFrame(SpectFrame &frame, FILE *stream, int file_format_type) {//============================================================== - int ix; - int x; + short ix; + short x; unsigned short *spect_data; - wxDataInputStream s(stream); - - frame.time = s.ReadDouble(); - frame.pitch = s.ReadDouble(); - frame.length = s.ReadDouble(); - frame.dx = s.ReadDouble(); - frame.nx = s.Read16(); - frame.markers = s.Read16(); - frame.amp_adjust = s.Read16(); + frame.time = read_double(stream); + frame.pitch = read_double(stream); + frame.length = read_double(stream); + frame.dx = read_double(stream); + fread(&frame.nx,sizeof(short),1,stream); + fread(&frame.markers,sizeof(short),1,stream); + fread(&frame.amp_adjust,sizeof(short),1,stream); if(file_format_type == 2) { - ix = s.Read16(); // spare - ix = s.Read16(); // spare + fread(&ix,sizeof(short),1,stream); // spare + fread(&ix,sizeof(short),1,stream); // spare } for(ix=0; ix 0) + fread(&frame.formants[ix].freq,sizeof(short),1,stream); + fread(&frame.formants[ix].bandw,sizeof(short),1,stream); + fread(&frame.peaks[ix].pkfreq,sizeof(short),1,stream); + fread(&frame.peaks[ix].pkheight,sizeof(short),1,stream); + fread(&frame.peaks[ix].pkwidth,sizeof(short),1,stream); + fread(&frame.peaks[ix].pkright,sizeof(short),1,stream); + if(frame.peaks[ix].pkheight > 0) frame.keyframe = 1; - frame.peaks[ix].pkwidth = s.Read16(); - frame.peaks[ix].pkright = s.Read16(); if(file_format_type == 2) { - frame.peaks[ix].klt_bw = s.Read16(); - frame.peaks[ix].klt_ap = s.Read16(); - frame.peaks[ix].klt_bp = s.Read16(); + fread(&frame.peaks[ix].klt_bw,sizeof(short),1,stream); + fread(&frame.peaks[ix].klt_ap,sizeof(short),1,stream); + fread(&frame.peaks[ix].klt_bp,sizeof(short),1,stream); } } @@ -196,7 +194,7 @@ int LoadFrame(SpectFrame &frame, wxInputStream& stream, int file_format_type) { for(ix=0; ix frame.max_y) frame.max_y = x; } frame.spect = spect_data; @@ -314,8 +313,8 @@ int LoadSpectSeq(SpectSeq *spect, const char *filename) int set_max_y=0; float time_offset; - wxFileInputStream stream(filename); - if(stream.Ok() == FALSE) + FILE *stream = fopen(filename, "rb"); + if(stream == NULL) { fprintf(stderr, "Failed to open: '%s'", filename); return(0); diff --git a/src/spect.h b/src/spect.h index 537ba6fb..4ea916df 100644 --- a/src/spect.h +++ b/src/spect.h @@ -18,8 +18,6 @@ * . * ***************************************************************************/ -#define PROGRAM_NAME _T("Voice Editor") - #define FRAME_WIDTH 1000 // max width for 8000kHz frame #define MAX_DISPLAY_FREQ 9500 #define FRAME_HEIGHT 240 @@ -88,7 +86,7 @@ typedef struct { struct SpectFrame { int keyframe; - int amp_adjust; + short amp_adjust; float length_adjust; double rms; @@ -96,8 +94,8 @@ struct SpectFrame float pitch; float length; float dx; - int nx; - int markers; + unsigned short nx; + short markers; int max_y; USHORT *spect; // sqrt of harmonic amplitudes, 1-nx at 'pitch'