Код: Выделить всё
#include "stdafx.h"
#include <fstream.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "cstring.h"
//#include "aon.h"
//#include "playpcm.h"
int SoundPlay(char*,int,int,double);
char * fileout="output.pcm";
int DIAL_LEN;
int counter=0;
//float FloatPointer,PackStep;
const Freq=44100;
int BufPointer=0;
ofstream ofl;
ifstream dial;
int SumFileSize=0;
void List(STRING)
{
}
void fatal(char*)
{
}
long GetFileSize(STRING file)
{
ifstream ifl(file.Get(),ios::binary);
if (!ifl)
{
List(STRING("Невозможно узнать размер файла: '")+file);
return 0;
}
ifl.seekg(0,ios::end);
long flen=ifl.tellg();
ifl.close();
return flen;
}
char *digit0_9[]=
{
"0.pcm",
"1.pcm",
"2.pcm",
"3.pcm",
"4.pcm",
"5.pcm",
"6.pcm",
"7.pcm",
"8.pcm",
"9.pcm"
};
char *digit10_19[]=
{
"10.pcm",
"11.pcm",
"12.pcm",
"13.pcm",
"14.pcm",
"15.pcm",
"16.pcm",
"17.pcm",
"18.pcm",
"19.pcm",
};
char * digit20_90[]=
{
NULL,
NULL,
"20.pcm",
"30.pcm",
"40.pcm",
"50.pcm",
"60.pcm",
"70.pcm",
"80.pcm",
"90.pcm"
};
void AddToFile(char * path, char * s, double speed)
{
char str[256];
strcpy(str,"numplay\\");
strcat(str,s);
ifstream ifl(str,ios::binary);
if (!ifl)
{
List("AddToFile() - can't open ifl");
return;
}
ofstream ofl;
ofl.open(path, ios::binary | ios::app);
if (!ofl)
{
List("AddToFile() - can't open ofl");
}
ofl.seekp(0,ios::end);
do
{
//берем из файла байт
char n=ifl.get();
//обязательно проверить, откуда берется 255 !
//if (n!=255 && n!=0)
if (ifl.eof()) break;
ofl.put(n);
} while(1);
ofl.close();
}
//добавляет к файлу данные
void AddFile(char *s, int calcsz, int GenerateTone)
{
char str[256];
strcpy(str,"numplay\\");
strcat(str,s);
if (calcsz)
{
SumFileSize+=GetFileSize(str);
return;
}
ifstream ifl(str,ios::binary);
if (!ifl)
{
List("AddFile() - can't open file");
return;
}
do
{
//берем из файла байт
char n=ifl.get();
//обязательно проверить, откуда берется 255 !
//if (n!=255 && n!=0)
if (ifl.eof()) break;
/*
BufPointer=FloatPointer;
SoundBuf[BufPointer*2]=n;
SoundBuf[BufPointer*2+1]=
if (FloatPointer>2*Freq) {List("BufPointer>=2*Freq"); break;}
*/
ofl.put(n);
if (GenerateTone) ofl.put(n);
else ofl.put(char(127));
} while(1);
}
void play_two_digit(char * path_file, int x)
{
double speed=1.0;
if (x>=0 && x<=9)
{
AddToFile(path_file, digit0_9[0], speed);
AddToFile(path_file, digit0_9[x], speed);
}
else if (x>=10 && x<=19)
{
AddToFile(path_file, digit10_19[x-10], speed);
}
else if (x>=20 && x<=99)
{
AddToFile(path_file, digit20_90[x/10], speed);
int k=x%10;
if (k)
AddToFile(path_file, digit0_9[x%10], speed);
if (!k && (x/10)>=6 )
{
AddToFile(path_file, digit0_9[0], speed);
}
}
}
void playtwo(int x, int CalcSize,int GenerateTone)
{
if (x>=0 && x<=9)
{
AddFile(digit0_9[0],CalcSize,GenerateTone);
AddFile(digit0_9[x],CalcSize,GenerateTone);
}
else if (x>=10 && x<=19)
{
AddFile(digit10_19[x-10],CalcSize,GenerateTone);
}
else if (x>=20 && x<=99)
{
AddFile(digit20_90[x/10],CalcSize,GenerateTone);
int k=x%10;
if (k)
AddFile(digit0_9[x%10],CalcSize,GenerateTone);
if (!k && (x/10)>=6 )
{
AddFile(digit0_9[0],CalcSize,GenerateTone);
}
}
else if (x>100)
{
char buf[32];
itoa(x,buf,10);
AddFile(digit0_9[buf[0]-'0'],CalcSize,GenerateTone);
AddFile(digit0_9[buf[1]-'0'],CalcSize,GenerateTone);
AddFile(digit0_9[buf[2]-'0'],CalcSize,GenerateTone);
}
}
//52912
void NumberToPcm(int n, int x,int y, int GenerateTone)
{
counter=BufPointer=0;
//начинаем играть файл
ofl.open("output.pcm", ios::binary);
DIAL_LEN=GetFileSize("dial440.pcm");
dial.open("dial440.pcm", ios::binary);
if (!dial) {List("can't open dial440.pcm");return;}
if (!ofl) { List("can't create distination file");return; }
AddFile(digit0_9[n], FALSE, GenerateTone);
if (x!=-1) playtwo(x, FALSE,GenerateTone);
if (y!=-1) playtwo(y, FALSE,GenerateTone);
char silen[1024];
for(int j=0; j<sizeof(silen); j++) silen[j]=char(127);
ofl.write(silen,sizeof(silen));
ofl.close();
dial.close();
}
void PlayIP(int a,int b,int c,int d, double amplif)
{
int GenerateTone=1;
ofl.open("output.pcm", ios::binary);
playtwo(a, FALSE,GenerateTone);
playtwo(b, FALSE,GenerateTone);
playtwo(c, FALSE,GenerateTone);
playtwo(d, FALSE,GenerateTone);
ofl.close();
SoundPlay("output.pcm",11025,2, amplif);
}
void PlayTelephonNumber( STRING Number, int GenTon, double amplif)
{
List("Clock generate");
if (Number.Len()==5)
{
// для 7 и 6 не будет правильно
int x=Number[0]-'0',
y=(Number[1]-'0')*10+Number[2]-'0',
z=(Number[3]-'0')*10+Number[4]-'0';
NumberToPcm(x,y,z,0); //FASLE- не
}
else
{
ofl.open("output.pcm", ios::binary);
for(int i=0; i<Number.Len(); i++)
{
AddFile(digit0_9[Number[i]-'0'], FALSE, GenTon);
}
ofl.close();
}
SoundPlay("output.pcm",11025,2, amplif);
}