Ejemplo n.º 1
0
					bool processI16(int16_t* _output, const int16_t* _microphone, const int16_t* _feedback, int32_t _nbSample) {
						bool ret = false;
						int32_t processingSize = MAX_PROCESSING_BLOCK_SIZE*m_nbChannel;
						// due to the fact we allocate the data in the stack:
						int32_t nbCycle = _nbSample/processingSize;
						if (_nbSample - int32_t(_nbSample/processingSize)*processingSize != 0 ) {
							nbCycle++;
						}
						for (int32_t bbb=0; bbb<nbCycle; ++bbb) {
							float output[processingSize];
							float feedback[processingSize];
							float microphone[processingSize];
							int32_t offset = bbb*processingSize;
							int32_t nbData = std::min(processingSize,
							                          _nbSample - offset);
							for (size_t iii=0; iii<nbData; ++iii) {
								microphone[iii] = float(_microphone[offset+iii])/32767.0f;
								feedback[iii] = float(_feedback[offset+iii])/32767.0f;
							}
							ret = processFloat(output, feedback, microphone, nbData);
							for (size_t iii=0; iii<nbData; ++iii) {
								_output[offset+iii] = int16_t(float(output[iii])*32767.0f);
							}
						}
						return ret;
					}
Ejemplo n.º 2
0
					void process(void* _output, const void* _input, const void* _inputFeedback, size_t _nbChunk) {
						switch (m_format) {
							case audio::format_int16:
								processI16(reinterpret_cast<int16_t*>(_output),
								           reinterpret_cast<const int16_t*>(_inputFeedback),
								           reinterpret_cast<const int16_t*>(_input),
								           _nbChunk);
								break;
							case audio::format_float:
								processFloat(reinterpret_cast<float*>(_output),
								             reinterpret_cast<const float*>(_inputFeedback),
								             reinterpret_cast<const float*>(_input),
								             _nbChunk);
								break;
							default:
								AA_RIVER_ERROR("Can not Echo remove with unsupported format : " << m_format);
								break;
						}
					}
Ejemplo n.º 3
0
/** process will execute the operation that is specified in the saved string.
 *  The format of the operations is specified in kart_characteristics.xml.
 */
void XmlCharacteristic::process(CharacteristicType type, Value value,
                                bool *is_set) const
{
    if (m_values[type].empty())
        // That value was not changed in this configuration
        return;

    switch (getType(type))
    {
    case TYPE_FLOAT:
        processFloat(m_values[type], value.f, is_set);
        break;
    case TYPE_BOOL:
        processBool(m_values[type], value.b, is_set);
        break;
    case TYPE_FLOAT_VECTOR:
    {
        const std::vector<std::string> processors =
            StringUtils::split(m_values[type], ' ');
        // If the array should be completely replaced
        // That has to happen when the size is not the same or it is not yet set
        bool shouldReplace = false;
        if (*is_set)
        {
            if (processors.size() != value.fv->size())
                shouldReplace = true;
            else
            {
                std::vector<float>::iterator fit = value.fv->begin();
                for (const std::string &processor : processors)
                {
                    processFloat(processor, &*fit, is_set);
                    if (!*is_set)
                    {
                        Log::error("XmlCharacteristic::process", "Can't process %s",
                            processor.c_str());
                        value.fv->clear();
                        break;
                    }
                    fit++;
                }
            }
        }
        else
            shouldReplace = true;

        if (shouldReplace)
        {
            value.fv->resize(processors.size());
            std::vector<float>::iterator fit = value.fv->begin();
            for (const std::string &processor : processors)
            {
                *is_set = false;
                processFloat(processor, &*fit, is_set);

                if (!*is_set)
                {
                    Log::error("XmlCharacteristic::process", "Can't process %s",
                        getName(type).c_str());
                    value.fv->clear();
                    break;
                }
                fit++;
            }
        }
        break;
    }
    case TYPE_INTERPOLATION_ARRAY:
    {
        const std::vector<std::string> processors =
            StringUtils::split(m_values[type], ' ');
        // If the interpolation array should be completely replaced
        // That has to happen when the format is not the same
        bool shouldReplace = false;
        if (*is_set)
        {
            if (processors.size() != value.fv->size())
                shouldReplace = true;
            else
            {
                for (const std::string &processor : processors)
                {
                    std::vector<std::string> pair = StringUtils::split(processor, ':');
                    if (pair.size() != 2)
                        Log::error("XmlCharacteristic::process",
                            "Can't process %s: Wrong format", getName(type).c_str());
                    else
                    {
                        float x;
                        if (!StringUtils::fromString(pair[0], x))
                            Log::error("XmlCharacteristic::process",
                                "Can't process %s: Not a float", getName(type).c_str());
                        else
                        {
                            // Search the index of this x value
                            bool found = false;
                            for (unsigned int i = 0; i < value.ia->size(); i++)
                            {
                                if (value.ia->getX(i) == x)
                                {
                                    float val;
                                    processFloat(pair[1], &val, is_set);
                                    value.ia->setY(i, val);
                                    found = true;
                                    break;
                                }
                            }
                            if (!found)
                            {
                                // The searched value was not found so we have
                                // a different format
                                shouldReplace = true;
                                break;
                            }
                        }
                    }
                }
            }
        }
        else
            // It's not yet set, so we will the current content
            shouldReplace = true;

        if (shouldReplace)
        {
            value.ia->clear();
            // Replace all values
            for (const std::string &processor : processors)
            {
                std::vector<std::string> pair = StringUtils::split(processor,':');
                if (pair.size() != 2)
                    Log::error("XmlCharacteristic::process",
                        "Can't process %s: Wrong format", getName(type).c_str());
                else
                {
                    float x;
                    if (!StringUtils::fromString(pair[0], x))
                        Log::error("XmlCharacteristic::process",
                            "Can't process %s: Not a float", getName(type).c_str());
                    else
                    {
                        float val;
                        *is_set = false;
                        processFloat(pair[1], &val, is_set);
                        if (!*is_set)
                        {
                            Log::error("XmlCharacteristic::process", "Can't process %s",
                                getName(type).c_str());
                            value.ia->clear();
                            break;
                        }
                        value.ia->push_back(x, val);
                    }
                }
            }
        }
        break;
    }
    default:
        Log::fatal("XmlCharacteristic::process", "Unknown type for %s",
                   getName(type).c_str());
    }
}   // process