Skip to content
Snippets Groups Projects
Commit f3f23ef0 authored by yanmorin's avatar yanmorin
Browse files

Try to remove the sound bug for the tone
But I don't understand there is one...
parent 1bbea304
No related branches found
No related tags found
No related merge requests found
...@@ -201,7 +201,7 @@ AudioLayer::audioCallback (const void *inputBuffer, void *outputBuffer, ...@@ -201,7 +201,7 @@ AudioLayer::audioCallback (const void *inputBuffer, void *outputBuffer,
toGet = (normalAvail < (int)framesPerBuffer) ? normalAvail : framesPerBuffer; toGet = (normalAvail < (int)framesPerBuffer) ? normalAvail : framesPerBuffer;
// MIC_CHANNELS * SAMPLE_BYTES // MIC_CHANNELS * SAMPLE_BYTES
//_debug("%d vs %d : %d\t", normalAvail, (int)framesPerBuffer, toGet); //_debug("mainsndringbuffer.get: %d vs %d : %d\n", normalAvail, (int)framesPerBuffer, toGet);
if (toGet) { if (toGet) {
_mainSndRingBuffer.Get(out, SAMPLES_SIZE(toGet), _manager.getSpkrVolume()); _mainSndRingBuffer.Get(out, SAMPLES_SIZE(toGet), _manager.getSpkrVolume());
} else { } else {
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
...@@ -94,7 +93,7 @@ RingBuffer::Put(void* buffer, int toCopy, unsigned short volume) { ...@@ -94,7 +93,7 @@ RingBuffer::Put(void* buffer, int toCopy, unsigned short volume) {
while(toCopy) { while(toCopy) {
block = toCopy; block = toCopy;
if (block > mBufferSize - pos) // from current pos. to end of buffer if (block > (mBufferSize - pos)) // from current pos. to end of buffer
block = mBufferSize - pos; block = mBufferSize - pos;
// put the data inside the buffer. // put the data inside the buffer.
...@@ -105,7 +104,6 @@ RingBuffer::Put(void* buffer, int toCopy, unsigned short volume) { ...@@ -105,7 +104,6 @@ RingBuffer::Put(void* buffer, int toCopy, unsigned short volume) {
} }
// bcopy(src, dest, len) // bcopy(src, dest, len)
bcopy (src, mBuffer + pos, block); bcopy (src, mBuffer + pos, block);
src += block; src += block;
pos = (pos + block) % mBufferSize; pos = (pos + block) % mBufferSize;
toCopy -= block; toCopy -= block;
...@@ -142,6 +140,7 @@ RingBuffer::Get(void *buffer, int toCopy, unsigned short volume) { ...@@ -142,6 +140,7 @@ RingBuffer::Get(void *buffer, int toCopy, unsigned short volume) {
dest = (samplePtr) buffer; dest = (samplePtr) buffer;
copied = 0; copied = 0;
//fprintf(stderr, "get start... ");
while(toCopy) { while(toCopy) {
block = toCopy; block = toCopy;
if (block > (mBufferSize - mStart)) if (block > (mBufferSize - mStart))
...@@ -154,6 +153,7 @@ RingBuffer::Get(void *buffer, int toCopy, unsigned short volume) { ...@@ -154,6 +153,7 @@ RingBuffer::Get(void *buffer, int toCopy, unsigned short volume) {
} }
// bcopy(src, dest, len) // bcopy(src, dest, len)
bcopy (mBuffer + mStart, dest, block); bcopy (mBuffer + mStart, dest, block);
//_debug("get %d chars at address %ld, mBufferSize=%d, toCopy=%d\n", block, mBuffer+mStart, mBufferSize, toCopy);
dest += block; dest += block;
mStart = (mStart + block) % mBufferSize; mStart = (mStart + block) % mBufferSize;
toCopy -= block; toCopy -= block;
......
...@@ -60,7 +60,7 @@ ToneThread::run (void) { ...@@ -60,7 +60,7 @@ ToneThread::run (void) {
bool started = false; bool started = false;
// How long do 'size' samples play ? // How long do 'size' samples play ?
unsigned int play_time = (size * 1000) / SAMPLING_RATE; unsigned int play_time = (size * 1000) / SAMPLING_RATE - 10;
ManagerImpl& manager = Manager::instance(); ManagerImpl& manager = Manager::instance();
manager.getAudioDriver()->flushMain(); manager.getAudioDriver()->flushMain();
...@@ -73,15 +73,17 @@ ToneThread::run (void) { ...@@ -73,15 +73,17 @@ ToneThread::run (void) {
// * spkrVolume/100; // * spkrVolume/100;
} }
// Create a new stereo buffer with the volume adjusted // Create a new stereo buffer with the volume adjusted
//spkrVolume = manager.getSpkrVolume(); // spkrVolume = manager.getSpkrVolume();
// Push the tone to the audio FIFO // Push the tone to the audio FIFO
// size = number of int16 * 2 (two channels) * // size = number of int16 * 2 (two channels) *
// int16 are the buf_ctrl_vol // int16 are the buf_ctrl_vol
// unsigned char are the sample_ptr inside ringbuffer // unsigned char are the sample_ptr inside ringbuffer
int size_in_char = size * 2 * (sizeof(int16)/sizeof(unsigned char)); int size_in_char = size * 2 * (sizeof(int16)/sizeof(unsigned char));
_debug(" size : %d\t size_in_char : %d\n", size, size_in_char);
while (!testCancel()) { while (!testCancel()) {
manager.getAudioDriver()->putMain(buf_ctrl_vol, size_in_char); manager.getAudioDriver()->putMain(buf_ctrl_vol, size_in_char);
// The first iteration will start the audio stream if not already. // The first iteration will start the audio stream if not already.
...@@ -176,9 +178,11 @@ ToneGenerator::generateSin (int lowerfreq, int higherfreq, int16* ptr, int len) ...@@ -176,9 +178,11 @@ ToneGenerator::generateSin (int lowerfreq, int higherfreq, int16* ptr, int len)
var1 = (double)2 * (double)M_PI * (double)higherfreq / (double)SAMPLING_RATE; var1 = (double)2 * (double)M_PI * (double)higherfreq / (double)SAMPLING_RATE;
var2 = (double)2 * (double)M_PI * (double)lowerfreq / (double)SAMPLING_RATE; var2 = (double)2 * (double)M_PI * (double)lowerfreq / (double)SAMPLING_RATE;
double amp = (double)(AMPLITUDE >> 2);
for(int t = 0; t < len; t++) { for(int t = 0; t < len; t++) {
ptr[t] = (int16)((double)(AMPLITUDE >> 1) * ((sin(var1 * t) + sin(var2 * t)))); ptr[t] = (int16)(amp * ((sin(var1 * t) + sin(var2 * t))));
} }
} }
...@@ -367,29 +371,32 @@ ToneGenerator::playRingtone (const char *fileName) { ...@@ -367,29 +371,32 @@ ToneGenerator::playRingtone (const char *fileName) {
return 0; return 0;
} }
// get length of file: // get length of file:
file.seekg (0, std::ios::end); file.seekg (0, std::ios::end);
length = file.tellg(); length = file.tellg();
file.seekg (0, std::ios::beg); file.seekg (0, std::ios::beg);
// allocate memory: // allocate memory:
_src = new char [length]; _src = new char [length];
_dst = new short[length*2]; _dst = new short[length*2];
// read data as a block:
file.read (_src,length);
file.close();
// Decode file.ul
expandedsize = _ulaw->codecDecode (_dst, (unsigned char *)_src, length);
if (tonethread == NULL) { // read data as a block:
file.read (_src,length);
file.close();
// Decode file.ul
expandedsize = _ulaw->codecDecode (_dst, (unsigned char *)_src, length);
_debug("length (pre-ulaw) : %d\n", length);
_debug("expandedsize (post-ulaw) : %d\n", expandedsize);
if (tonethread == NULL) {
_debug("Thread: start tonethread\n"); _debug("Thread: start tonethread\n");
tonethread = new ToneThread ((int16*)_dst, expandedsize); tonethread = new ToneThread ((int16*)_dst, expandedsize);
tonethread->start(); tonethread->start();
} }
return 1; return 1;
} }
int int
......
...@@ -276,7 +276,6 @@ ManagerImpl::hangupCall (CALLID id) ...@@ -276,7 +276,6 @@ ManagerImpl::hangupCall (CALLID id)
return -1; return -1;
} }
int result = call->hangup(); int result = call->hangup();
deleteCall(id); deleteCall(id);
stopTone(); // stop tone, like a 700 error: number not found Not Found stopTone(); // stop tone, like a 700 error: number not found Not Found
return result; return result;
...@@ -297,7 +296,6 @@ ManagerImpl::cancelCall (CALLID id) ...@@ -297,7 +296,6 @@ ManagerImpl::cancelCall (CALLID id)
return -1; return -1;
} }
int result = call->cancel(); int result = call->cancel();
deleteCall(id); deleteCall(id);
stopTone(); stopTone();
return result; return result;
...@@ -705,11 +703,11 @@ ManagerImpl::peerHungupCall (CALLID id) ...@@ -705,11 +703,11 @@ ManagerImpl::peerHungupCall (CALLID id)
return -1; return -1;
} }
stopTone(); stopTone();
call->setState(Call::Hungup);
if (_gui) _gui->peerHungupCall(id); if (_gui) _gui->peerHungupCall(id);
deleteCall(id); deleteCall(id);
call->setState(Call::Hungup);
setCurrentCallId(0); setCurrentCallId(0);
return 1; return 1;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment