Browse Source

espeakedit: remove wxWidgets from spect.cpp

master
Reece H. Dunn 9 years ago
parent
commit
e2ba3703bb
4 changed files with 122 additions and 41 deletions
  1. 1
    0
      Makefile.am
  2. 83
    0
      src/libespeak-ng/ieee80.c
  3. 35
    36
      src/spect.cpp
  4. 3
    5
      src/spect.h

+ 1
- 0
Makefile.am View File

src/libespeak-ng/compiledict.c \ src/libespeak-ng/compiledict.c \
src/libespeak-ng/compilembrola.c \ src/libespeak-ng/compilembrola.c \
src/libespeak-ng/dictionary.c \ src/libespeak-ng/dictionary.c \
src/libespeak-ng/ieee80.c \
src/libespeak-ng/intonation.c \ src/libespeak-ng/intonation.c \
src/libespeak-ng/numbers.c \ src/libespeak-ng/numbers.c \
src/libespeak-ng/readclause.c \ src/libespeak-ng/readclause.c \

+ 83
- 0
src/libespeak-ng/ieee80.c View File

/*
* 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 <math.h>

#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;
}

+ 35
- 36
src/spect.cpp View File

* <http://www.gnu.org/licenses/>. * * <http://www.gnu.org/licenses/>. *
***************************************************************************/ ***************************************************************************/



#include "wx/wx.h"

#include "speak_lib.h" #include "speak_lib.h"
#include "speech.h" #include "speech.h"
#include "phoneme.h" #include "phoneme.h"
#include "synthesize.h" #include "synthesize.h"
#include "voice.h" #include "voice.h"
#include "spect.h" #include "spect.h"
#include "wx/wfstream.h"
#include "wx/txtstrm.h"
#include "wx/datstrm.h"


#include <math.h> #include <math.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h>
#include <string.h>


extern "C" double ConvertFromIeeeExtended(unsigned char *bytes);
extern "C" int PeaksToHarmspect(wavegen_peaks_t *peaks, int pitch, int *htab, int control); extern "C" int PeaksToHarmspect(wavegen_peaks_t *peaks, int pitch, int *htab, int control);


extern unsigned char pk_shape1[]; extern unsigned char pk_shape1[];
static int default_klt_bw[N_PEAKS] = static int default_klt_bw[N_PEAKS] =
{89,90,140,260,260,260,500,500,500}; {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) float polint(float xa[],float ya[],int n,float x)






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; 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) 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<N_PEAKS; ix++) for(ix=0; ix<N_PEAKS; ix++)
{ {
frame.formants[ix].freq = s.Read16();
frame.formants[ix].bandw = s.Read16();
frame.peaks[ix].pkfreq = s.Read16();
if((frame.peaks[ix].pkheight = s.Read16()) > 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.keyframe = 1;
frame.peaks[ix].pkwidth = s.Read16();
frame.peaks[ix].pkright = s.Read16();


if(file_format_type == 2) 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);
} }
} }


{ {
for(ix=0; ix<N_KLATTP2; ix++) for(ix=0; ix<N_KLATTP2; ix++)
{ {
frame.klatt_param[ix] = s.Read16();
fread(frame.klatt_param + ix,sizeof(short),1,stream);
} }
} }




if(spect_data == NULL) if(spect_data == NULL)
{ {
wxLogError(_T("Failed to allocate memory"));
fprintf(stderr,"Failed to allocate memory\n");
return(1); return(1);
} }


frame.max_y = 0; frame.max_y = 0;
for(ix=0; ix<frame.nx; ix++) for(ix=0; ix<frame.nx; ix++)
{ {
x = spect_data[ix] = s.Read16();
fread(&x,sizeof(short),1,stream);
spect_data[ix] = x;
if(x > frame.max_y) frame.max_y = x; if(x > frame.max_y) frame.max_y = x;
} }
frame.spect = spect_data; frame.spect = spect_data;
int set_max_y=0; int set_max_y=0;
float time_offset; 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); fprintf(stderr, "Failed to open: '%s'", filename);
return(0); return(0);

+ 3
- 5
src/spect.h View File

* <http://www.gnu.org/licenses/>. * * <http://www.gnu.org/licenses/>. *
***************************************************************************/ ***************************************************************************/


#define PROGRAM_NAME _T("Voice Editor")

#define FRAME_WIDTH 1000 // max width for 8000kHz frame #define FRAME_WIDTH 1000 // max width for 8000kHz frame
#define MAX_DISPLAY_FREQ 9500 #define MAX_DISPLAY_FREQ 9500
#define FRAME_HEIGHT 240 #define FRAME_HEIGHT 240
struct SpectFrame struct SpectFrame
{ {
int keyframe; int keyframe;
int amp_adjust;
short amp_adjust;
float length_adjust; float length_adjust;
double rms; double rms;


float pitch; float pitch;
float length; float length;
float dx; float dx;
int nx;
int markers;
unsigned short nx;
short markers;
int max_y; int max_y;
USHORT *spect; // sqrt of harmonic amplitudes, 1-nx at 'pitch' USHORT *spect; // sqrt of harmonic amplitudes, 1-nx at 'pitch'



Loading…
Cancel
Save