From 1bbea304d74955649550a9ac468b4698f63cc49d Mon Sep 17 00:00:00 2001 From: yanmorin <yanmorin> Date: Mon, 17 Oct 2005 02:04:55 +0000 Subject: [PATCH] Some fix and improvment. Remove a useless loop, yeah! Add * and # to qt... --- src/audio/ringbuffer.cpp | 3 +-- src/audio/tonegenerator.cpp | 46 ++++++++++++++++++---------------- src/gui/official/PhoneLine.cpp | 2 +- src/managerimpl.cpp | 3 ++- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/audio/ringbuffer.cpp b/src/audio/ringbuffer.cpp index 983e3e87a3..d8f30deee4 100644 --- a/src/audio/ringbuffer.cpp +++ b/src/audio/ringbuffer.cpp @@ -21,7 +21,6 @@ */ -#include <iostream> //debug #include <assert.h> #include <stdlib.h> #include <string.h> @@ -102,7 +101,7 @@ RingBuffer::Put(void* buffer, int toCopy, unsigned short volume) { if (volume!=100) { int16* src16 = (int16*)src; int int16len = (block >> 1); - for (int i=0; i< int16len; i++) { src16[i] = src16[i] * volume / 100; } + for (int i=0; i < int16len; i++) { src16[i] = src16[i] * volume / 100; } } // bcopy(src, dest, len) bcopy (src, mBuffer + pos, block); diff --git a/src/audio/tonegenerator.cpp b/src/audio/tonegenerator.cpp index bfe33b0fe9..606fd5e691 100644 --- a/src/audio/tonegenerator.cpp +++ b/src/audio/tonegenerator.cpp @@ -31,7 +31,7 @@ #include "../manager.h" #include "../user_cfg.h" -int AMPLITUDE = 8192; +int AMPLITUDE = 32767; /////////////////////////////////////////////////////////////////////////////// @@ -60,33 +60,38 @@ ToneThread::run (void) { bool started = false; // How long do 'size' samples play ? - // unsigned int play_time = (size * 1000) / SAMPLING_RATE; - unsigned int pause = (size * 1000) / SAMPLING_RATE; + unsigned int play_time = (size * 1000) / SAMPLING_RATE; ManagerImpl& manager = Manager::instance(); manager.getAudioDriver()->flushMain(); - while (!testCancel()) { + // this loop can be outside the stream, since we put the volume inside the ringbuffer + for (int j = 0; j < size; j++) { + k = j<<1; // channels is 2 (global.h) + // split in two + buf_ctrl_vol[k] = buf_ctrl_vol[k+1] = buffer[j]; + // * spkrVolume/100; + } + // Create a new stereo buffer with the volume adjusted //spkrVolume = manager.getSpkrVolume(); - for (int j = 0; j < size; j++) { - k = j<<1; // channels is 2 (global.h) - // split in two - buf_ctrl_vol[k] = buf_ctrl_vol[k+1] = buffer[j]; - // * spkrVolume/100; - } - // Push the tone to the audio FIFO - manager.getAudioDriver()->putMain(buf_ctrl_vol, SAMPLES_SIZE(size)); + // size = number of int16 * 2 (two channels) * + // int16 are the buf_ctrl_vol + // unsigned char are the sample_ptr inside ringbuffer + + int size_in_char = size * 2 * (sizeof(int16)/sizeof(unsigned char)); + while (!testCancel()) { + manager.getAudioDriver()->putMain(buf_ctrl_vol, size_in_char); // The first iteration will start the audio stream if not already. - if (!started) { - started = true; - manager.getAudioDriver()->startStream(); - } + if (!started) { + started = true; + manager.getAudioDriver()->startStream(); + } // next iteration later, sound is playing. - this->sleep (pause); // this is not a pause, this is the sound that play + this->sleep(play_time); // this is not a pause, this is the sound that play } } @@ -173,8 +178,7 @@ ToneGenerator::generateSin (int lowerfreq, int higherfreq, int16* ptr, int len) var2 = (double)2 * (double)M_PI * (double)lowerfreq / (double)SAMPLING_RATE; for(int t = 0; t < len; t++) { - ptr[t] = (int16)((double)(AMPLITUDE >> 2) * sin(var1 * t) + - (double)(AMPLITUDE >> 2) * sin(var2 * t)); + ptr[t] = (int16)((double)(AMPLITUDE >> 1) * ((sin(var1 * t) + sin(var2 * t)))); } } @@ -251,8 +255,8 @@ ToneGenerator::buildTone (unsigned int idCountry, unsigned int idTones, int16* t count = 0; byte_max = byte + byte_temp; for (int j = byte_temp; j < byte_max; j++) { - temp[j] = buffer[count++]; - } + temp[j] = buffer[count++]; // copy each int16 data... + } byte_temp += byte; str = str.substr(str.find(',') + 1, str.length()); diff --git a/src/gui/official/PhoneLine.cpp b/src/gui/official/PhoneLine.cpp index 83bc43c83f..cc9de470e1 100644 --- a/src/gui/official/PhoneLine.cpp +++ b/src/gui/official/PhoneLine.cpp @@ -197,7 +197,7 @@ PhoneLine::sendKey(Qt::Key c) break; default: - if (QChar(c).isDigit()) { + if (QChar(c).isDigit() || c == Qt::Key_Asterisk || c == Qt::Key_NumberSign) { if(!mCall) { mSession.playDtmf(c); mBuffer += c; diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index e45e562f2e..58893427ea 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -528,7 +528,7 @@ ManagerImpl::playDtmf(char code) buf_ctrl_vol[k] = buf_ctrl_vol[k+1] = _buf[j]; // * spkrVolume/100; } - + _toneMutex.enterMutex(); AudioLayer *audiolayer = getAudioDriver(); audiolayer->urgentRingBuffer().flush(); @@ -544,6 +544,7 @@ ManagerImpl::playDtmf(char code) } else { audiolayer->sleep(pulselen); } + _toneMutex.leaveMutex(); //setZonetone(false); delete[] buf_ctrl_vol; buf_ctrl_vol = 0; returnValue = true; -- GitLab