diff --git a/core/AmAdvancedAudio.cpp b/core/AmAdvancedAudio.cpp index 6a41935c..78d9d935 100644 --- a/core/AmAdvancedAudio.cpp +++ b/core/AmAdvancedAudio.cpp @@ -223,7 +223,7 @@ int AmAudioDelay::write(unsigned int user_ts, unsigned int size) { } int AmAudioDelay::read(unsigned int user_ts, unsigned int size) { - sarr.read((unsigned int) (user_ts - delay*8000.0), (short*) ((unsigned char*) samples), size >> 1); + sarr.read((unsigned int) (user_ts - delay*(float)SYSTEM_SAMPLERATE), (short*) ((unsigned char*) samples), size >> 1); return size; } diff --git a/core/AmAudio.cpp b/core/AmAudio.cpp index 594436c4..43613440 100644 --- a/core/AmAudio.cpp +++ b/core/AmAudio.cpp @@ -39,8 +39,6 @@ #include -#define SYSTEM_SAMPLERATE 8000 // fixme: sr per session - /** \brief structure to hold loaded codec instances */ struct CodecContainer { @@ -140,7 +138,7 @@ AmAudioSimpleFormat::AmAudioSimpleFormat(int codec_id) : AmAudioFormat(), codec_id(codec_id) { codec = getCodec(); - rate = 8000; + rate = SYSTEM_SAMPLERATE; channels = 1; } @@ -275,6 +273,7 @@ AmAudio::~AmAudio() } void AmAudio::setFormat(AmAudioFormat* new_fmt) { + DBG("set format to %p --------------------------\n", new_fmt); fmt.reset(new_fmt); fmt->resetCodec(); } @@ -377,10 +376,10 @@ int AmAudio::encode(unsigned int size) { int s = size; - // if(!fmt.get()){ - // DBG("no encode fmt\n"); - // return 0; - // } +// if(!fmt.get()){ +// DBG("no encode fmt\n"); +// return 0; +// } amci_codec_t* codec = fmt->getCodec(); long h_codec = fmt->getHCodec(); diff --git a/core/AmAudio.h b/core/AmAudio.h index cc8187bc..d26a74ff 100644 --- a/core/AmAudio.h +++ b/core/AmAudio.h @@ -47,6 +47,8 @@ using std::string; #define PCM16_B2S(b) ((b) >> 1) #define PCM16_S2B(s) ((s) << 1) +#define SYSTEM_SAMPLERATE 8000 // fixme: sr per session + class SdpPayload; class CodecContainer; diff --git a/core/AmAudioMixIn.h b/core/AmAudioMixIn.h index 28636974..fdb06a2c 100644 --- a/core/AmAudioMixIn.h +++ b/core/AmAudioMixIn.h @@ -33,8 +33,8 @@ #define MAX_PACKETLENGTH_MS 30 -#define MAX_BUF_SAMPLES 8000 * MAX_PACKETLENGTH_MS / 1000 -#define DEFAULT_SAMPLE_RATE 8000 // eh... +#define MAX_BUF_SAMPLES SYSTEM_SAMPLERATE * MAX_PACKETLENGTH_MS / 1000 +#define DEFAULT_SAMPLE_RATE SYSTEM_SAMPLERATE // eh... /** * \brief \ref AmAudio to mix in every n seconds a file diff --git a/core/AmDtmfDetector.cpp b/core/AmDtmfDetector.cpp index 8006ceba..0116b308 100644 --- a/core/AmDtmfDetector.cpp +++ b/core/AmDtmfDetector.cpp @@ -462,7 +462,7 @@ AmSemsInbandDtmfDetector::AmSemsInbandDtmfDetector(AmKeyPressSink *keysink) m_last(' '), m_idx(0), m_count(0), - SAMPLERATE(8000) + SAMPLERATE(SYSTEM_SAMPLERATE) { /* precalculate 2 * cos (2 PI k / N) */ for(unsigned i = 0; i < NELEMSOF(rel_cos2pik); i++) { diff --git a/core/AmJitterBuffer.h b/core/AmJitterBuffer.h index 30937ecf..65ae7392 100644 --- a/core/AmJitterBuffer.h +++ b/core/AmJitterBuffer.h @@ -29,11 +29,12 @@ #define _AmJitterBuffer_h_ #include "amci/amci.h" +#include "AmAudio.h" #include "AmThread.h" #include "SampleArray.h" -#define INITIAL_JITTER 640 // 80 miliseconds -#define MAX_JITTER 16000 // 2 seconds +#define INITIAL_JITTER 80 * SYSTEM_SAMPLERATE / 1000 // 80 miliseconds +#define MAX_JITTER 2 * SYSTEM_SAMPLERATE // 2 seconds #define RESYNC_THRESHOLD 2 class Packet { diff --git a/core/AmMediaProcessor.cpp b/core/AmMediaProcessor.cpp index 8616aa19..7d2110cc 100644 --- a/core/AmMediaProcessor.cpp +++ b/core/AmMediaProcessor.cpp @@ -26,6 +26,7 @@ */ #include "AmMediaProcessor.h" +#include "AmSession.h" #include "AmRtpStream.h" #include @@ -212,7 +213,7 @@ void AmMediaProcessorThread::run() events.processEvents(); processDtmfEvents(); - ts += 80; // 10 ms + ts += 10 * SYSTEM_SAMPLERATE / 1000; // 10 ms timeradd(&tick,&next_tick,&next_tick); } } diff --git a/core/AmMediaProcessor.h b/core/AmMediaProcessor.h index d727860b..e32c1f19 100644 --- a/core/AmMediaProcessor.h +++ b/core/AmMediaProcessor.h @@ -28,8 +28,9 @@ #ifndef _AmMediaProcessor_h_ #define _AmMediaProcessor_h_ -#include "AmSession.h" #include "AmEventQueue.h" +#include "amci/amci.h" // AUDIO_BUFFER_SIZE +class AmSession; #include using std::set; diff --git a/core/AmMultiPartyMixer.cpp b/core/AmMultiPartyMixer.cpp index 089b42a9..27f1640a 100644 --- a/core/AmMultiPartyMixer.cpp +++ b/core/AmMultiPartyMixer.cpp @@ -37,7 +37,7 @@ // the internal delay of the mixer (between put and get) #define MIXER_DELAY_MS 20 -#define MIXER_DELAY MIXER_DELAY_MS*8 // 8000/1000 +#define MIXER_DELAY MIXER_DELAY_MS*SYSTEM_SAMPLERATE/1000 AmMultiPartyMixer::AmMultiPartyMixer() : channels(), diff --git a/core/AmPlayoutBuffer.cpp b/core/AmPlayoutBuffer.cpp index 50e0317b..5c1a8055 100644 --- a/core/AmPlayoutBuffer.cpp +++ b/core/AmPlayoutBuffer.cpp @@ -42,7 +42,7 @@ #define PI 3.14 -#define MAX_DELAY 8000 /* 1 second */ +#define MAX_DELAY SYSTEM_SAMPLERATE*1 /* 1 second */ AmPlayoutBuffer::AmPlayoutBuffer(AmPLCBuffer *plcbuffer) : r_ts(0),w_ts(0), diff --git a/core/AmPlayoutBuffer.h b/core/AmPlayoutBuffer.h index 4d0fc2c0..d84322f2 100644 --- a/core/AmPlayoutBuffer.h +++ b/core/AmPlayoutBuffer.h @@ -42,18 +42,18 @@ using std::multiset; #define EXP_THRESHOLD 20 #define SHR_THRESHOLD 180 -#define WSOLA_START_OFF 80 +#define WSOLA_START_OFF 10 * SYSTEM_SAMPLERATE / 1000 #define WSOLA_SCALED_WIN 50 -// the maximum packet size that will be processed -// 640 is 80ms @ 8khz -#define MAX_PACKET_SAMPLES 640 -// search segments of size TEMPLATE_SEG samples -#define TEMPLATE_SEG 80 +// the maximum packet size that will be processed (80ms) +#define MAX_PACKET_SAMPLES 80 * SYSTEM_SAMPLERATE / 1000 +// search segments of size TEMPLATE_SEG samples (10 ms) +#define TEMPLATE_SEG 10 * SYSTEM_SAMPLERATE / 1000 // Maximum value: AUDIO_BUFFER_SIZE / 2 // Note: plc result get stored in our back buffer -#define PLC_MAX_SAMPLES (160*4) +// maximum of 80ms PLC +#define PLC_MAX_SAMPLES (4*20*SYSTEM_SAMPLERATE / 1000) class AmPLCBuffer; diff --git a/core/AmPlugIn.cpp b/core/AmPlugIn.cpp index 53760acf..055ee2ac 100644 --- a/core/AmPlugIn.cpp +++ b/core/AmPlugIn.cpp @@ -92,7 +92,7 @@ amci_codec_t _codec_tevent = { amci_payload_t _payload_tevent = { -1, "telephone-event", - 8000, + 8000, // telephone-event has always SR 8000 -1, CODEC_TELEPHONE_EVENT, -1 diff --git a/core/AmRingTone.cpp b/core/AmRingTone.cpp index fc0df291..17e28bb8 100644 --- a/core/AmRingTone.cpp +++ b/core/AmRingTone.cpp @@ -34,9 +34,9 @@ int AmRingTone::read(unsigned int user_ts, unsigned int size) for(unsigned int i=0; i> 2) /* maximum pitch OLA window */ #define HISTORYLEN (PITCH_MAX * 3 + POVERLAPMAX) /* history buff length*/ #define NDEC 2 /* 2:1 decimation */ -#define CORRLEN 160 /* 20 msec correlation length */ +#define CORRLEN 20 * SYSTEM_SAMPLERATE / 1000 /* 20 msec correlation length */ #define CORRBUFLEN (CORRLEN + PITCH_MAX) /* correlation buffer length */ #define CORRMINPOWER ((Float)250.) /* minimum power */ #define EOVERLAPINCR 32 /* end OLA increment per frame,4 ms */ -#define FRAMESZ 80 /* 10 msec at 8 KHz */ +#define FRAMESZ (10 * SYSTEM_SAMPLERATE / 1000) /* 10 msec */ #define ATTENFAC ((Float).2) /* attenu. factor per 10 ms frame */ -#define ATTENINCR (ATTENFAC/FRAMESZ) /* attenuation per sample */ +#define ATTENINCR (ATTENFAC/(Float)(FRAMESZ)) /* attenuation per sample */ /** \brief LowcFE erased frame generator for fec (plc) */ class LowcFE {