diff --git a/daemon/src/audio/sound/dtmf.cpp b/daemon/src/audio/sound/dtmf.cpp index 914e616efcec7c2ade4e7c500b860069931ef576..65e567ab1161dd2f77fe9863f4d257abce1b2aec 100644 --- a/daemon/src/audio/sound/dtmf.cpp +++ b/daemon/src/audio/sound/dtmf.cpp @@ -43,20 +43,20 @@ void DTMF::startTone(char code) newTone_ = code; } -bool DTMF::generateDTMF(SFLDataFormat* buffer, size_t n) -{ - if (!buffer) return false; +using std::vector; +bool DTMF::generateDTMF(vector<SFLDataFormat> &buffer) +{ try { if (currentTone_ != 0) { // Currently generating a DTMF tone if (currentTone_ == newTone_) { // Continue generating the same tone - dtmfgenerator_.getNextSamples(buffer, n); + dtmfgenerator_.getNextSamples(buffer); return true; } else if (newTone_ != 0) { // New tone requested - dtmfgenerator_.getSamples(buffer, n, newTone_); + dtmfgenerator_.getSamples(buffer, newTone_); currentTone_ = newTone_; return true; } else { @@ -68,7 +68,7 @@ bool DTMF::generateDTMF(SFLDataFormat* buffer, size_t n) // Not generating any DTMF tone if (newTone_) { // Requested to generate a DTMF tone - dtmfgenerator_.getSamples(buffer, n, newTone_); + dtmfgenerator_.getSamples(buffer, newTone_); currentTone_ = newTone_; return true; } diff --git a/daemon/src/audio/sound/dtmf.h b/daemon/src/audio/sound/dtmf.h index 90b17715b82eaee2cc7c0fd636497e7543f78c47..885c37d3bea9a5eb5afc7c451abc6682dda654dc 100644 --- a/daemon/src/audio/sound/dtmf.h +++ b/daemon/src/audio/sound/dtmf.h @@ -58,10 +58,9 @@ class DTMF { /** * Copy the sound inside the sampling* buffer - * @param buffer : a SFLDataFormat* buffer - * @param n : The size to generate + * @param buffer : a vector of SFLDataFormat */ - bool generateDTMF(SFLDataFormat* buffer, size_t n); + bool generateDTMF(std::vector<SFLDataFormat> &buffer); private: char currentTone_; diff --git a/daemon/src/audio/sound/dtmfgenerator.cpp b/daemon/src/audio/sound/dtmfgenerator.cpp index 61a840f3e57718d6f3814d0f22b77455f5f34273..433978d8a0ca61cff4e6094b86c46ad053923208 100644 --- a/daemon/src/audio/sound/dtmfgenerator.cpp +++ b/daemon/src/audio/sound/dtmfgenerator.cpp @@ -37,7 +37,6 @@ #include <cassert> #include "dtmfgenerator.h" -#include "global.h" /* * Tone frequencies @@ -81,14 +80,13 @@ DTMFGenerator::~DTMFGenerator() delete [] toneBuffers_[i]; } +using std::vector; + /* * Get n samples of the signal of code code */ -void DTMFGenerator::getSamples(SFLDataFormat* buffer, size_t n, unsigned char code) +void DTMFGenerator::getSamples(vector<SFLDataFormat> &buffer, unsigned char code) { - if (!buffer) - throw DTMFException("Invalid parameter value"); - code = toupper(code); if (code >= '0' and code <= '9') @@ -112,6 +110,7 @@ void DTMFGenerator::getSamples(SFLDataFormat* buffer, size_t n, unsigned char co } size_t i; + const size_t n = buffer.size(); for (i = 0; i < n; ++i) buffer[i] = state.sample[i % sampleRate_]; @@ -122,15 +121,13 @@ void DTMFGenerator::getSamples(SFLDataFormat* buffer, size_t n, unsigned char co * Get next n samples (continues where previous call to * genSample or genNextSamples stopped */ -void DTMFGenerator::getNextSamples(SFLDataFormat* buffer, size_t n) +void DTMFGenerator::getNextSamples(vector<SFLDataFormat> &buffer) { - if (!buffer) - throw DTMFException("Invalid parameter"); - if (state.sample == 0) throw DTMFException("DTMF generator not initialized"); size_t i; + const size_t n = buffer.size(); for (i = 0; i < n; i++) buffer[i] = state.sample[(state.offset + i) % sampleRate_]; diff --git a/daemon/src/audio/sound/dtmfgenerator.h b/daemon/src/audio/sound/dtmfgenerator.h index 9eb8105db567fc05513b5ad28ec5d025b18d8074..25e29443cb815cdf4df59bff3569974952fe37b5 100644 --- a/daemon/src/audio/sound/dtmfgenerator.h +++ b/daemon/src/audio/sound/dtmfgenerator.h @@ -38,6 +38,7 @@ #include <stdexcept> #include <string> +#include <vector> #include "noncopyable.h" #include "tone.h" @@ -100,19 +101,17 @@ class DTMFGenerator { /* * Get n samples of the signal of code code - * @param buffer a SFLDataFormat pointer to an allocated buffer - * @param n number of sampling to get, should be lower or equal to buffer size + * @param buffer a SFLDataFormat vector * @param code dtmf code to get sound */ - void getSamples(SFLDataFormat* buffer, size_t n, unsigned char code); + void getSamples(std::vector<SFLDataFormat> &buffer, unsigned char code); /* * Get next n samples (continues where previous call to * genSample or genNextSamples stopped - * @param buffer a SFLDataFormat pointer to an allocated buffer - * @param n number of sampling to get, should be lower or equal to buffer size + * @param buffer a SFLDataFormat vector */ - void getNextSamples(SFLDataFormat* buffer, size_t n); + void getNextSamples(std::vector<SFLDataFormat> &buffer); private: diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index 4138cf3630e3cdc2278f73e7e5ccdb71c26ceaf9..1d4e1652928a9763ed89e30dfabbdbd8a95cf42c 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -1301,24 +1301,22 @@ void ManagerImpl::playDtmf(char code) // this buffer is for mono // TODO <-- this should be global and hide if same size - SFLDataFormat *buf = new SFLDataFormat[size]; + std::vector<SFLDataFormat> buf(size); // Handle dtmf dtmfKey_->startTone(code); // copy the sound - if (dtmfKey_->generateDTMF(buf, size)) { + if (dtmfKey_->generateDTMF(buf)) { // Put buffer to urgentRingBuffer // put the size in bytes... // so size * 1 channel (mono) * sizeof (bytes for the data) // audiolayer->flushUrgent(); audiodriver_->startStream(); - audiodriver_->putUrgent(buf, size * sizeof(SFLDataFormat)); + audiodriver_->putUrgent(&(*buf.begin()), size * sizeof(SFLDataFormat)); } // TODO Cache the DTMF - - delete [] buf; } // Multi-thread