mirror of https://github.com/sipwise/sems.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.0 KiB
60 lines
1.0 KiB
#include "AmRingTone.h"
|
|
#include <math.h>
|
|
|
|
#include "log.h"
|
|
|
|
#define PI 3.14159
|
|
|
|
AmRingTone::AmRingTone(int length, int on, int off, int f, int f2)
|
|
: AmAudio(),
|
|
length(length),
|
|
on_period(on),
|
|
off_period(off),
|
|
freq(f),freq2(f2)
|
|
{}
|
|
|
|
AmRingTone::~AmRingTone()
|
|
{}
|
|
|
|
int AmRingTone::read(unsigned int user_ts, unsigned int size)
|
|
{
|
|
int t = user_ts % ((on_period + off_period)<<3);
|
|
|
|
if(length < 0)
|
|
return -1;
|
|
|
|
if(t >= on_period<<3){
|
|
|
|
memset((unsigned char*)samples,0,size);
|
|
|
|
return size;
|
|
}
|
|
|
|
short* s = (short*)((unsigned char*)samples);
|
|
for(unsigned int i=0; i<PCM16_B2S(size); i++, s++, t++){
|
|
|
|
if(t < on_period<<3){
|
|
float fs = sin((float(t*freq)/8000.0)*2.0*PI)*15000.0;
|
|
if(freq2 != 0)
|
|
fs += sin((float(t*freq2)/8000.0)*2.0*PI)*15000.0;
|
|
*s = (short)(fs);
|
|
}
|
|
else
|
|
*s = 0;
|
|
|
|
}
|
|
|
|
if(length != 0){
|
|
length -= PCM16_B2S(size) / 8;
|
|
if(!length)
|
|
length--;
|
|
}
|
|
|
|
return size;
|
|
}
|
|
|
|
int AmRingTone::write(unsigned int user_ts, unsigned int size)
|
|
{
|
|
return -1;
|
|
}
|