Browse Source

espeakedit: remove support for importing the old SPC2 files (these are not present when building the project)

master
Reece H. Dunn 9 years ago
parent
commit
aa3bc83139
2 changed files with 6 additions and 203 deletions
  1. 5
    162
      src/spect.cpp
  2. 1
    41
      src/spect.h

+ 5
- 162
src/spect.cpp View File

delete spect; delete spect;
} }


int SpectFrame::ImportSPC2(wxInputStream& stream, float &time_acc)
{//===============================================================
int ix;
int size;
unsigned short *spect_data;
CYCLE cy;
CYCLE *p;
float len;
static char peak_factor[8] = {4,5,11,20,20,25,32,32};

stream.Read(&cy,44);
size = SPC2_size_cycle(&cy);

p = (CYCLE *)malloc(size);
if(p == NULL)
{
return(1);
}
stream.SeekI(-44,wxFromCurrent);
stream.Read(p,size);

time = time_acc;
len = cy.length / 15625.0;
time_acc += len;
pitch = float(cy.pitch) / 16.0;
nx = cy.n_harm;
dx = pitch;

for(ix=0; ix<7; ix++)
{
peaks[ix].pkfreq = cy.peak_data[ix].freq * peak_factor[ix];
if(peaks[ix].pkfreq == 0)
peaks[ix].pkfreq = default_freq[ix];

peaks[ix].pkheight = cy.peak_data[ix].height * 40;
peaks[ix].pkwidth = cy.peak_data[ix].width_l * 12;
peaks[ix].pkright = cy.peak_data[ix].width_r * 12;
}
for(ix=7; ix<=8; ix++)
{
peaks[ix].pkfreq = default_freq[ix]; // default
peaks[ix].pkheight = 0;
peaks[ix].pkwidth = peaks[ix].pkright = default_width[ix];
}
if(((cy.flags & 0x80)==0) && (peaks[1].pkheight > 0))
keyframe = 1;

if(cy.flags & 0x08)
markers |= 4;
if(cy.flags & 0x10)
markers |= 2;
if(cy.flags & 0x04)
markers |= 8;

if(nx>0)
{
spect_data = new USHORT[nx];

if(spect_data == NULL)
{
wxLogError(_T("Failed to allocate memory"));
return(1);
}

max_y = 0;
for(ix=0; ix<nx; ix++)
{
spect_data[ix] = p->data[ix];
if(spect_data[ix] > max_y)
max_y = spect_data[ix];
}
}
else
{
nx = int(8000/dx);
spect_data = new USHORT[nx];
if(spect_data == NULL)
{
wxLogError(_T("Failed to allocate memory"));
return(1);
}
for(ix=0; ix<nx; ix++)
spect_data[ix] = 1;
max_y = 1;
}
spect = spect_data;
free(p);
return(0);
} // end of ImportSPC2





int SpectFrame::Load(wxInputStream& stream, int file_format_type) int SpectFrame::Load(wxInputStream& stream, int file_format_type)
} }




void SpectSeq::Load2(wxInputStream& stream, int import, int n)
void SpectSeq::Load2(wxInputStream& stream, int n)
{//=========================================================== {//===========================================================
// continuation of load/import // continuation of load/import
int ix; int ix;
{ {
SpectFrame *frame = new SpectFrame; SpectFrame *frame = new SpectFrame;


if(import==2)
if(frame->Load(stream, file_format) != 0)
{ {
if(frame->ImportSPC2(stream,time_acc) != 0)
{
delete frame;
break;
}
}
else
{
if(frame->Load(stream, file_format) != 0)
{
delete frame;
break;
}
delete frame;
break;
} }


frames[numframes++] = frame; frames[numframes++] = frame;
} // end of SpectSeq::Load2 } // end of SpectSeq::Load2




int SPC2_size_cycle(CYCLE *cy)
/****************************/
/* Find number of bytes in cycle record */
{
int i;
i = 44 + cy->n_harm;
if(cy->flags & 1)
{
i += 4; /* label */
}
return(i);
} /* end of size_cycle */




int SpectSeq::ImportSPC2(wxInputStream & stream)
{//=============================================
// load an spectrum with an old "SPC2" format
int n_cycles = 0;
int x;
CYCLE cy;
/* count number of cycles */
while(!stream.Eof())
{
stream.TellI();
stream.Read(&cy,44);
stream.TellI();
if(stream.Eof()) break;
n_cycles++;
x = SPC2_size_cycle(&cy) - 44;
stream.SeekI(x,wxFromCurrent);
}
if(n_cycles == 0) return(0);
name = _T("");
amplitude = 100;
max_y = 0;
stream.SeekI(4); // rewind and skip header
Load2(stream,2,n_cycles);
return(0);
}



int SpectSeq::Load(wxInputStream & stream) int SpectSeq::Load(wxInputStream & stream)
{//======================================= {//=======================================
id1 = s.Read32(); id1 = s.Read32();
id2 = s.Read32(); id2 = s.Read32();


if(id1 == FILEID1_SPC2)
{
stream.SeekI(4);
return(ImportSPC2(stream));
}
else
if((id1 == FILEID1_SPECTSEQ) && (id2 == FILEID2_SPECTSEQ)) if((id1 == FILEID1_SPECTSEQ) && (id2 == FILEID2_SPECTSEQ))
{ {
file_format = 0; // eSpeak formants file_format = 0; // eSpeak formants
amplitude = s.Read16(); amplitude = s.Read16();
max_y = s.Read16(); max_y = s.Read16();
s.Read16(); s.Read16();
Load2(stream,0,n);
Load2(stream,n);


for(ix=0; ix<numframes; ix++) for(ix=0; ix<numframes; ix++)
{ {

+ 1
- 41
src/spect.h View File

} peak_t; } peak_t;




//===============================================================================================
// Old "SPC2" format

typedef struct {
unsigned char freq; /* *factor for f0-f7 of [4,5,11,20,20,25,32,32] */
unsigned char height;
unsigned char width_l; /* * 8 Hz */
unsigned char width_r; /* * 8 Hz */
} PEAKS7;

/* flags: bit 0 label is present in data[]
bit 1 mark cycle - blue background
bit 2 mark cycle - green square
bit 3 mark cycle - 'lengthen' indicator
bit 4 mark cycle - 'standard'
bit 7 hide peaks
*/

typedef struct {
short pitch; /* pitch of fundamental, 1/16 Hz */
short length; /* length in 1/15625 sec */
unsigned char n_harm; /* number of harmonic data, h1 ... hn */
unsigned char flags; /* bits 0 */
unsigned char aspiration;
unsigned char hf_voicing;
unsigned char spare1;
unsigned char spare2;
unsigned char spare3;
unsigned char spare4;
PEAKS7 peak_data[7];
unsigned char data[1]; /* firstly harmonic data, then f3,f4,f5 data */
} CYCLE; /* VARIABLE LENGTH Structure */

extern int SPC2_size_cycle(CYCLE *cy);
//==============================================================================================



class SpectFrame class SpectFrame
{//============= {//=============
public: public:
SpectFrame(SpectFrame *copy=NULL); SpectFrame(SpectFrame *copy=NULL);
~SpectFrame(); ~SpectFrame();
int ImportSPC2(wxInputStream &stream, float &time_acc);
int Load(wxInputStream &stream, int file_format_type); int Load(wxInputStream &stream, int file_format_type);


void ZeroPeaks(); void ZeroPeaks();
public: public:
SpectSeq(int nframes=0); SpectSeq(int nframes=0);
~SpectSeq(); ~SpectSeq();
int ImportSPC2(wxInputStream& stream);
int Load(wxInputStream& stream); int Load(wxInputStream& stream);


void InterpolatePeaks(int on); void InterpolatePeaks(int on);




private: private:
void Load2(wxInputStream& stream, int import, int n);
void Load2(wxInputStream& stream, int n);
void InterpolatePeak(int peak); void InterpolatePeak(int peak);
}; };

Loading…
Cancel
Save