Integrated program of 4 different kinds of application programs for processing sound signal. 4種類のサウンド信号処理を統合したプログラム.
Dependencies: F746_GUI F746_SAI_IO FrequencyResponseDrawer SD_PlayerSkeleton UIT_FFT_Real
mbed_src_STM/common/CallChain.cpp@0:224dccbc4edd, 2016-08-15 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon Aug 15 07:18:07 2016 +0000
- Revision:
- 0:224dccbc4edd
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:224dccbc4edd | 1 | #include "CallChain.h" |
MikamiUitOpen | 0:224dccbc4edd | 2 | #include "cmsis.h" |
MikamiUitOpen | 0:224dccbc4edd | 3 | |
MikamiUitOpen | 0:224dccbc4edd | 4 | namespace mbed { |
MikamiUitOpen | 0:224dccbc4edd | 5 | |
MikamiUitOpen | 0:224dccbc4edd | 6 | CallChain::CallChain(int size) : _chain(), _size(size), _elements(0) { |
MikamiUitOpen | 0:224dccbc4edd | 7 | _chain = new pFunctionPointer_t[size](); |
MikamiUitOpen | 0:224dccbc4edd | 8 | } |
MikamiUitOpen | 0:224dccbc4edd | 9 | |
MikamiUitOpen | 0:224dccbc4edd | 10 | CallChain::~CallChain() { |
MikamiUitOpen | 0:224dccbc4edd | 11 | clear(); |
MikamiUitOpen | 0:224dccbc4edd | 12 | delete _chain; |
MikamiUitOpen | 0:224dccbc4edd | 13 | } |
MikamiUitOpen | 0:224dccbc4edd | 14 | |
MikamiUitOpen | 0:224dccbc4edd | 15 | pFunctionPointer_t CallChain::add(void (*function)(void)) { |
MikamiUitOpen | 0:224dccbc4edd | 16 | return common_add(new FunctionPointer(function)); |
MikamiUitOpen | 0:224dccbc4edd | 17 | } |
MikamiUitOpen | 0:224dccbc4edd | 18 | |
MikamiUitOpen | 0:224dccbc4edd | 19 | pFunctionPointer_t CallChain::add_front(void (*function)(void)) { |
MikamiUitOpen | 0:224dccbc4edd | 20 | return common_add_front(new FunctionPointer(function)); |
MikamiUitOpen | 0:224dccbc4edd | 21 | } |
MikamiUitOpen | 0:224dccbc4edd | 22 | |
MikamiUitOpen | 0:224dccbc4edd | 23 | int CallChain::size() const { |
MikamiUitOpen | 0:224dccbc4edd | 24 | return _elements; |
MikamiUitOpen | 0:224dccbc4edd | 25 | } |
MikamiUitOpen | 0:224dccbc4edd | 26 | |
MikamiUitOpen | 0:224dccbc4edd | 27 | pFunctionPointer_t CallChain::get(int i) const { |
MikamiUitOpen | 0:224dccbc4edd | 28 | if (i < 0 || i >= _elements) |
MikamiUitOpen | 0:224dccbc4edd | 29 | return NULL; |
MikamiUitOpen | 0:224dccbc4edd | 30 | return _chain[i]; |
MikamiUitOpen | 0:224dccbc4edd | 31 | } |
MikamiUitOpen | 0:224dccbc4edd | 32 | |
MikamiUitOpen | 0:224dccbc4edd | 33 | int CallChain::find(pFunctionPointer_t f) const { |
MikamiUitOpen | 0:224dccbc4edd | 34 | for (int i = 0; i < _elements; i++) |
MikamiUitOpen | 0:224dccbc4edd | 35 | if (f == _chain[i]) |
MikamiUitOpen | 0:224dccbc4edd | 36 | return i; |
MikamiUitOpen | 0:224dccbc4edd | 37 | return -1; |
MikamiUitOpen | 0:224dccbc4edd | 38 | } |
MikamiUitOpen | 0:224dccbc4edd | 39 | |
MikamiUitOpen | 0:224dccbc4edd | 40 | void CallChain::clear() { |
MikamiUitOpen | 0:224dccbc4edd | 41 | for(int i = 0; i < _elements; i ++) { |
MikamiUitOpen | 0:224dccbc4edd | 42 | delete _chain[i]; |
MikamiUitOpen | 0:224dccbc4edd | 43 | _chain[i] = NULL; |
MikamiUitOpen | 0:224dccbc4edd | 44 | } |
MikamiUitOpen | 0:224dccbc4edd | 45 | _elements = 0; |
MikamiUitOpen | 0:224dccbc4edd | 46 | } |
MikamiUitOpen | 0:224dccbc4edd | 47 | |
MikamiUitOpen | 0:224dccbc4edd | 48 | bool CallChain::remove(pFunctionPointer_t f) { |
MikamiUitOpen | 0:224dccbc4edd | 49 | int i; |
MikamiUitOpen | 0:224dccbc4edd | 50 | |
MikamiUitOpen | 0:224dccbc4edd | 51 | if ((i = find(f)) == -1) |
MikamiUitOpen | 0:224dccbc4edd | 52 | return false; |
MikamiUitOpen | 0:224dccbc4edd | 53 | if (i != _elements - 1) |
MikamiUitOpen | 0:224dccbc4edd | 54 | memmove(_chain + i, _chain + i + 1, (_elements - i - 1) * sizeof(pFunctionPointer_t)); |
MikamiUitOpen | 0:224dccbc4edd | 55 | delete f; |
MikamiUitOpen | 0:224dccbc4edd | 56 | _elements --; |
MikamiUitOpen | 0:224dccbc4edd | 57 | return true; |
MikamiUitOpen | 0:224dccbc4edd | 58 | } |
MikamiUitOpen | 0:224dccbc4edd | 59 | |
MikamiUitOpen | 0:224dccbc4edd | 60 | void CallChain::call() { |
MikamiUitOpen | 0:224dccbc4edd | 61 | for(int i = 0; i < _elements; i++) |
MikamiUitOpen | 0:224dccbc4edd | 62 | _chain[i]->call(); |
MikamiUitOpen | 0:224dccbc4edd | 63 | } |
MikamiUitOpen | 0:224dccbc4edd | 64 | |
MikamiUitOpen | 0:224dccbc4edd | 65 | void CallChain::_check_size() { |
MikamiUitOpen | 0:224dccbc4edd | 66 | if (_elements < _size) |
MikamiUitOpen | 0:224dccbc4edd | 67 | return; |
MikamiUitOpen | 0:224dccbc4edd | 68 | _size = (_size < 4) ? 4 : _size + 4; |
MikamiUitOpen | 0:224dccbc4edd | 69 | pFunctionPointer_t* new_chain = new pFunctionPointer_t[_size](); |
MikamiUitOpen | 0:224dccbc4edd | 70 | memcpy(new_chain, _chain, _elements * sizeof(pFunctionPointer_t)); |
MikamiUitOpen | 0:224dccbc4edd | 71 | delete _chain; |
MikamiUitOpen | 0:224dccbc4edd | 72 | _chain = new_chain; |
MikamiUitOpen | 0:224dccbc4edd | 73 | } |
MikamiUitOpen | 0:224dccbc4edd | 74 | |
MikamiUitOpen | 0:224dccbc4edd | 75 | pFunctionPointer_t CallChain::common_add(pFunctionPointer_t pf) { |
MikamiUitOpen | 0:224dccbc4edd | 76 | _check_size(); |
MikamiUitOpen | 0:224dccbc4edd | 77 | _chain[_elements] = pf; |
MikamiUitOpen | 0:224dccbc4edd | 78 | _elements ++; |
MikamiUitOpen | 0:224dccbc4edd | 79 | return pf; |
MikamiUitOpen | 0:224dccbc4edd | 80 | } |
MikamiUitOpen | 0:224dccbc4edd | 81 | |
MikamiUitOpen | 0:224dccbc4edd | 82 | pFunctionPointer_t CallChain::common_add_front(pFunctionPointer_t pf) { |
MikamiUitOpen | 0:224dccbc4edd | 83 | _check_size(); |
MikamiUitOpen | 0:224dccbc4edd | 84 | memmove(_chain + 1, _chain, _elements * sizeof(pFunctionPointer_t)); |
MikamiUitOpen | 0:224dccbc4edd | 85 | _chain[0] = pf; |
MikamiUitOpen | 0:224dccbc4edd | 86 | _elements ++; |
MikamiUitOpen | 0:224dccbc4edd | 87 | return pf; |
MikamiUitOpen | 0:224dccbc4edd | 88 | } |
MikamiUitOpen | 0:224dccbc4edd | 89 | |
MikamiUitOpen | 0:224dccbc4edd | 90 | } // namespace mbed |