Audio singal input and output example for DISCO-F746. Input: MEMS mic, Output: CN10 OUT, Acoustic effect: echo and frequency shift. DISCO-F746 によるオーディオ信号入出力.入力:MEMS マイク,出力:CN10 OUT,音響効果:エコー,周波数変換.

Dependencies:   F746_GUI F746_SAI_IO

Committer:
MikamiUitOpen
Date:
Sun Oct 02 10:44:58 2016 +0000
Revision:
6:38f7dce055d0
7

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen 6:38f7dce055d0 1 /* mbed Microcontroller Library
MikamiUitOpen 6:38f7dce055d0 2 * Copyright (c) 2006-2013 ARM Limited
MikamiUitOpen 6:38f7dce055d0 3 *
MikamiUitOpen 6:38f7dce055d0 4 * Licensed under the Apache License, Version 2.0 (the "License");
MikamiUitOpen 6:38f7dce055d0 5 * you may not use this file except in compliance with the License.
MikamiUitOpen 6:38f7dce055d0 6 * You may obtain a copy of the License at
MikamiUitOpen 6:38f7dce055d0 7 *
MikamiUitOpen 6:38f7dce055d0 8 * http://www.apache.org/licenses/LICENSE-2.0
MikamiUitOpen 6:38f7dce055d0 9 *
MikamiUitOpen 6:38f7dce055d0 10 * Unless required by applicable law or agreed to in writing, software
MikamiUitOpen 6:38f7dce055d0 11 * distributed under the License is distributed on an "AS IS" BASIS,
MikamiUitOpen 6:38f7dce055d0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MikamiUitOpen 6:38f7dce055d0 13 * See the License for the specific language governing permissions and
MikamiUitOpen 6:38f7dce055d0 14 * limitations under the License.
MikamiUitOpen 6:38f7dce055d0 15 */
MikamiUitOpen 6:38f7dce055d0 16 #ifndef MBED_CALLCHAIN_H
MikamiUitOpen 6:38f7dce055d0 17 #define MBED_CALLCHAIN_H
MikamiUitOpen 6:38f7dce055d0 18
MikamiUitOpen 6:38f7dce055d0 19 #include "FunctionPointer.h"
MikamiUitOpen 6:38f7dce055d0 20 #include <string.h>
MikamiUitOpen 6:38f7dce055d0 21
MikamiUitOpen 6:38f7dce055d0 22 namespace mbed {
MikamiUitOpen 6:38f7dce055d0 23
MikamiUitOpen 6:38f7dce055d0 24 /** Group one or more functions in an instance of a CallChain, then call them in
MikamiUitOpen 6:38f7dce055d0 25 * sequence using CallChain::call(). Used mostly by the interrupt chaining code,
MikamiUitOpen 6:38f7dce055d0 26 * but can be used for other purposes.
MikamiUitOpen 6:38f7dce055d0 27 *
MikamiUitOpen 6:38f7dce055d0 28 * Example:
MikamiUitOpen 6:38f7dce055d0 29 * @code
MikamiUitOpen 6:38f7dce055d0 30 * #include "mbed.h"
MikamiUitOpen 6:38f7dce055d0 31 *
MikamiUitOpen 6:38f7dce055d0 32 * CallChain chain;
MikamiUitOpen 6:38f7dce055d0 33 *
MikamiUitOpen 6:38f7dce055d0 34 * void first(void) {
MikamiUitOpen 6:38f7dce055d0 35 * printf("'first' function.\n");
MikamiUitOpen 6:38f7dce055d0 36 * }
MikamiUitOpen 6:38f7dce055d0 37 *
MikamiUitOpen 6:38f7dce055d0 38 * void second(void) {
MikamiUitOpen 6:38f7dce055d0 39 * printf("'second' function.\n");
MikamiUitOpen 6:38f7dce055d0 40 * }
MikamiUitOpen 6:38f7dce055d0 41 *
MikamiUitOpen 6:38f7dce055d0 42 * class Test {
MikamiUitOpen 6:38f7dce055d0 43 * public:
MikamiUitOpen 6:38f7dce055d0 44 * void f(void) {
MikamiUitOpen 6:38f7dce055d0 45 * printf("A::f (class member).\n");
MikamiUitOpen 6:38f7dce055d0 46 * }
MikamiUitOpen 6:38f7dce055d0 47 * };
MikamiUitOpen 6:38f7dce055d0 48 *
MikamiUitOpen 6:38f7dce055d0 49 * int main() {
MikamiUitOpen 6:38f7dce055d0 50 * Test test;
MikamiUitOpen 6:38f7dce055d0 51 *
MikamiUitOpen 6:38f7dce055d0 52 * chain.add(second);
MikamiUitOpen 6:38f7dce055d0 53 * chain.add_front(first);
MikamiUitOpen 6:38f7dce055d0 54 * chain.add(&test, &Test::f);
MikamiUitOpen 6:38f7dce055d0 55 * chain.call();
MikamiUitOpen 6:38f7dce055d0 56 * }
MikamiUitOpen 6:38f7dce055d0 57 * @endcode
MikamiUitOpen 6:38f7dce055d0 58 */
MikamiUitOpen 6:38f7dce055d0 59
MikamiUitOpen 6:38f7dce055d0 60 typedef FunctionPointer* pFunctionPointer_t;
MikamiUitOpen 6:38f7dce055d0 61
MikamiUitOpen 6:38f7dce055d0 62 class CallChain {
MikamiUitOpen 6:38f7dce055d0 63 public:
MikamiUitOpen 6:38f7dce055d0 64 /** Create an empty chain
MikamiUitOpen 6:38f7dce055d0 65 *
MikamiUitOpen 6:38f7dce055d0 66 * @param size (optional) Initial size of the chain
MikamiUitOpen 6:38f7dce055d0 67 */
MikamiUitOpen 6:38f7dce055d0 68 CallChain(int size = 4);
MikamiUitOpen 6:38f7dce055d0 69 virtual ~CallChain();
MikamiUitOpen 6:38f7dce055d0 70
MikamiUitOpen 6:38f7dce055d0 71 /** Add a function at the end of the chain
MikamiUitOpen 6:38f7dce055d0 72 *
MikamiUitOpen 6:38f7dce055d0 73 * @param function A pointer to a void function
MikamiUitOpen 6:38f7dce055d0 74 *
MikamiUitOpen 6:38f7dce055d0 75 * @returns
MikamiUitOpen 6:38f7dce055d0 76 * The function object created for 'function'
MikamiUitOpen 6:38f7dce055d0 77 */
MikamiUitOpen 6:38f7dce055d0 78 pFunctionPointer_t add(void (*function)(void));
MikamiUitOpen 6:38f7dce055d0 79
MikamiUitOpen 6:38f7dce055d0 80 /** Add a function at the end of the chain
MikamiUitOpen 6:38f7dce055d0 81 *
MikamiUitOpen 6:38f7dce055d0 82 * @param tptr pointer to the object to call the member function on
MikamiUitOpen 6:38f7dce055d0 83 * @param mptr pointer to the member function to be called
MikamiUitOpen 6:38f7dce055d0 84 *
MikamiUitOpen 6:38f7dce055d0 85 * @returns
MikamiUitOpen 6:38f7dce055d0 86 * The function object created for 'tptr' and 'mptr'
MikamiUitOpen 6:38f7dce055d0 87 */
MikamiUitOpen 6:38f7dce055d0 88 template<typename T>
MikamiUitOpen 6:38f7dce055d0 89 pFunctionPointer_t add(T *tptr, void (T::*mptr)(void)) {
MikamiUitOpen 6:38f7dce055d0 90 return common_add(new FunctionPointer(tptr, mptr));
MikamiUitOpen 6:38f7dce055d0 91 }
MikamiUitOpen 6:38f7dce055d0 92
MikamiUitOpen 6:38f7dce055d0 93 /** Add a function at the beginning of the chain
MikamiUitOpen 6:38f7dce055d0 94 *
MikamiUitOpen 6:38f7dce055d0 95 * @param function A pointer to a void function
MikamiUitOpen 6:38f7dce055d0 96 *
MikamiUitOpen 6:38f7dce055d0 97 * @returns
MikamiUitOpen 6:38f7dce055d0 98 * The function object created for 'function'
MikamiUitOpen 6:38f7dce055d0 99 */
MikamiUitOpen 6:38f7dce055d0 100 pFunctionPointer_t add_front(void (*function)(void));
MikamiUitOpen 6:38f7dce055d0 101
MikamiUitOpen 6:38f7dce055d0 102 /** Add a function at the beginning of the chain
MikamiUitOpen 6:38f7dce055d0 103 *
MikamiUitOpen 6:38f7dce055d0 104 * @param tptr pointer to the object to call the member function on
MikamiUitOpen 6:38f7dce055d0 105 * @param mptr pointer to the member function to be called
MikamiUitOpen 6:38f7dce055d0 106 *
MikamiUitOpen 6:38f7dce055d0 107 * @returns
MikamiUitOpen 6:38f7dce055d0 108 * The function object created for 'tptr' and 'mptr'
MikamiUitOpen 6:38f7dce055d0 109 */
MikamiUitOpen 6:38f7dce055d0 110 template<typename T>
MikamiUitOpen 6:38f7dce055d0 111 pFunctionPointer_t add_front(T *tptr, void (T::*mptr)(void)) {
MikamiUitOpen 6:38f7dce055d0 112 return common_add_front(new FunctionPointer(tptr, mptr));
MikamiUitOpen 6:38f7dce055d0 113 }
MikamiUitOpen 6:38f7dce055d0 114
MikamiUitOpen 6:38f7dce055d0 115 /** Get the number of functions in the chain
MikamiUitOpen 6:38f7dce055d0 116 */
MikamiUitOpen 6:38f7dce055d0 117 int size() const;
MikamiUitOpen 6:38f7dce055d0 118
MikamiUitOpen 6:38f7dce055d0 119 /** Get a function object from the chain
MikamiUitOpen 6:38f7dce055d0 120 *
MikamiUitOpen 6:38f7dce055d0 121 * @param i function object index
MikamiUitOpen 6:38f7dce055d0 122 *
MikamiUitOpen 6:38f7dce055d0 123 * @returns
MikamiUitOpen 6:38f7dce055d0 124 * The function object at position 'i' in the chain
MikamiUitOpen 6:38f7dce055d0 125 */
MikamiUitOpen 6:38f7dce055d0 126 pFunctionPointer_t get(int i) const;
MikamiUitOpen 6:38f7dce055d0 127
MikamiUitOpen 6:38f7dce055d0 128 /** Look for a function object in the call chain
MikamiUitOpen 6:38f7dce055d0 129 *
MikamiUitOpen 6:38f7dce055d0 130 * @param f the function object to search
MikamiUitOpen 6:38f7dce055d0 131 *
MikamiUitOpen 6:38f7dce055d0 132 * @returns
MikamiUitOpen 6:38f7dce055d0 133 * The index of the function object if found, -1 otherwise.
MikamiUitOpen 6:38f7dce055d0 134 */
MikamiUitOpen 6:38f7dce055d0 135 int find(pFunctionPointer_t f) const;
MikamiUitOpen 6:38f7dce055d0 136
MikamiUitOpen 6:38f7dce055d0 137 /** Clear the call chain (remove all functions in the chain).
MikamiUitOpen 6:38f7dce055d0 138 */
MikamiUitOpen 6:38f7dce055d0 139 void clear();
MikamiUitOpen 6:38f7dce055d0 140
MikamiUitOpen 6:38f7dce055d0 141 /** Remove a function object from the chain
MikamiUitOpen 6:38f7dce055d0 142 *
MikamiUitOpen 6:38f7dce055d0 143 * @arg f the function object to remove
MikamiUitOpen 6:38f7dce055d0 144 *
MikamiUitOpen 6:38f7dce055d0 145 * @returns
MikamiUitOpen 6:38f7dce055d0 146 * true if the function object was found and removed, false otherwise.
MikamiUitOpen 6:38f7dce055d0 147 */
MikamiUitOpen 6:38f7dce055d0 148 bool remove(pFunctionPointer_t f);
MikamiUitOpen 6:38f7dce055d0 149
MikamiUitOpen 6:38f7dce055d0 150 /** Call all the functions in the chain in sequence
MikamiUitOpen 6:38f7dce055d0 151 */
MikamiUitOpen 6:38f7dce055d0 152 void call();
MikamiUitOpen 6:38f7dce055d0 153
MikamiUitOpen 6:38f7dce055d0 154 #ifdef MBED_OPERATORS
MikamiUitOpen 6:38f7dce055d0 155 void operator ()(void) {
MikamiUitOpen 6:38f7dce055d0 156 call();
MikamiUitOpen 6:38f7dce055d0 157 }
MikamiUitOpen 6:38f7dce055d0 158 pFunctionPointer_t operator [](int i) const {
MikamiUitOpen 6:38f7dce055d0 159 return get(i);
MikamiUitOpen 6:38f7dce055d0 160 }
MikamiUitOpen 6:38f7dce055d0 161 #endif
MikamiUitOpen 6:38f7dce055d0 162
MikamiUitOpen 6:38f7dce055d0 163 private:
MikamiUitOpen 6:38f7dce055d0 164 void _check_size();
MikamiUitOpen 6:38f7dce055d0 165 pFunctionPointer_t common_add(pFunctionPointer_t pf);
MikamiUitOpen 6:38f7dce055d0 166 pFunctionPointer_t common_add_front(pFunctionPointer_t pf);
MikamiUitOpen 6:38f7dce055d0 167
MikamiUitOpen 6:38f7dce055d0 168 pFunctionPointer_t* _chain;
MikamiUitOpen 6:38f7dce055d0 169 int _size;
MikamiUitOpen 6:38f7dce055d0 170 int _elements;
MikamiUitOpen 6:38f7dce055d0 171
MikamiUitOpen 6:38f7dce055d0 172 /* disallow copy constructor and assignment operators */
MikamiUitOpen 6:38f7dce055d0 173 private:
MikamiUitOpen 6:38f7dce055d0 174 CallChain(const CallChain&);
MikamiUitOpen 6:38f7dce055d0 175 CallChain & operator = (const CallChain&);
MikamiUitOpen 6:38f7dce055d0 176 };
MikamiUitOpen 6:38f7dce055d0 177
MikamiUitOpen 6:38f7dce055d0 178 } // namespace mbed
MikamiUitOpen 6:38f7dce055d0 179
MikamiUitOpen 6:38f7dce055d0 180 #endif
MikamiUitOpen 6:38f7dce055d0 181