Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed_dtmf_generator.cpp
00001 #include "mbed_dtmf_generator.hpp" 00002 #include "snd_wave_generator/SineWave.h" 00003 #include "snd_wave_generator/WaveCombo.h" 00004 #include <iostream> 00005 #include <sstream> 00006 #include <string> 00007 00008 using namespace snd_wave_generator; 00009 00010 MbedDtmfGenerator::MbedDtmfGenerator() : 00011 generator(16000) 00012 { 00013 std::cout << "Init Wave" << "\r" << std::endl; 00014 makeWaves(); 00015 } 00016 00017 void MbedDtmfGenerator::makeKeyWave(int pos, int row, int col) 00018 { 00019 std::cout << "Init Key Wave #" << pos << " R" << row << "C" << col << "\r" << std::endl; 00020 std::auto_ptr<WaveCombo> wave(new WaveCombo()); 00021 wave->add(colWaves[col].get()); 00022 wave->add(rowWaves[row].get()); 00023 00024 waves[pos] = wave; 00025 } 00026 00027 void MbedDtmfGenerator::makeWaves() 00028 { 00029 static int colFreq[4] = { 1209, 1336, 1477, 1633 }; 00030 static int rowFreq[4] = { 697, 770, 852, 941 }; 00031 00032 for(int i = 0; i < 4; ++i) { 00033 std::cout << "Init ColWave " << i << " hz=" << colFreq[i] << "\r" << std::endl; 00034 colWaves[i].reset(new SineWave(colFreq[i])); 00035 00036 std::cout << "Init RowWave " << i << " hz=" << rowFreq[i] << "\r" << std::endl; 00037 rowWaves[i].reset(new SineWave(rowFreq[i])); 00038 } 00039 00040 makeKeyWave(0, 3, 1); 00041 for(int row = 0; row < 3; ++row) { 00042 for(int col = 0; col < 3; ++col) { 00043 makeKeyWave(row * 3 + col + 1, row, col); 00044 } 00045 } 00046 for(int ltr=0; ltr < 4; ++ltr) { 00047 makeKeyWave(ltr+10, ltr, 3); 00048 } 00049 makeKeyWave(14, 3, 0); 00050 makeKeyWave(15, 3, 2); 00051 } 00052 00053 Wave * MbedDtmfGenerator::getWaveFor(char ch) 00054 { 00055 int index = -1; 00056 if (ch >= '0' && ch <= '9') { 00057 index = ch - '0'; 00058 } 00059 else if (ch >= 'A' && ch <= 'D') { 00060 index = ch - 'A' + 10; 00061 } 00062 else if (ch == '*') { 00063 index = 14; 00064 } 00065 else if (ch == '#') { 00066 index = 15; 00067 } 00068 std::cout << "Wave for '" << ch << "' => " << index << "\r" << std::endl; 00069 return this->waves[index].get(); 00070 } 00071 00072 void MbedDtmfGenerator::play(char ch) 00073 { 00074 Wave *wave = getWaveFor(ch); 00075 std::cout << "Play Wave '" << ch << "'" << "\r" << std::endl; 00076 if (wave) { 00077 generator.play(getWaveFor(ch)); 00078 } 00079 else { 00080 std::cout << "No wave !\r" << std::endl; 00081 } 00082 } 00083 00084 void MbedDtmfGenerator::stop() 00085 { 00086 std::cout << "Stop Wave" << "\r" << std::endl; 00087 generator.stop(); 00088 }
Generated on Wed Jul 13 2022 16:23:43 by
1.7.2