int AudioIO::audioCallback(float *inputBuffer, float *outputBuffer, unsigned long framesPerBuffer) { if(framesPerBuffer != audioParameters.bufferSize) { printf("expected %ld frames in audio callback, got %ld\n", audioParameters.bufferSize, framesPerBuffer); exit(0); } static float *inputPtr; if(useAudioInputFile) { readAudioBufferFromFile(); inputPtr = audioFileBuffer; } else { inputPtr = inputBuffer; } float *spectrumMapInputBufferPtr = spectrumMapInputBuffer; float *outputPtr = (float *) outputBuffer; unsigned long i = 0; while(i < audioParameters.bufferSize) { *spectrumMapInputBufferPtr++ = *inputPtr; if(echoAudio) { *outputPtr++ = *inputPtr++; *outputPtr++ = *inputPtr++; } else { inputPtr += 2; } i++; } processAudio(spectrumMapInputBuffer); return 0; }
void AmMediaProcessorThread::run() { struct timeval now,next_tick,diff,tick; unsigned int ts = 0; tick.tv_sec = 0; tick.tv_usec = 10000; // 10 ms gettimeofday(&now,NULL); timeradd(&tick,&now,&next_tick); while(true){ gettimeofday(&now,NULL); if(timercmp(&now,&next_tick,<)){ struct timespec sdiff,rem; timersub(&next_tick,&now,&diff); sdiff.tv_sec = diff.tv_sec; sdiff.tv_nsec = diff.tv_usec * 1000; if(sdiff.tv_nsec > 2000) // 2 ms nanosleep(&sdiff,&rem); } processAudio(ts); events.processEvents(); processDtmfEvents(); ts += 80; // 10 ms timeradd(&tick,&next_tick,&next_tick); } }
void CDMRRX::processBit(bool b) { WRITE_BIT(m_buffer, m_pos, b); m_pos++; if (m_pos == DMR_FRAME_LENGTH_BITS) { // CUtils::dump("DMR Frame bytes", m_buffer, DMR_FRAME_LENGTH_BYTES); switch (m_type) { case SYNC_AUDIO: { CAMBEFEC fec; unsigned int ber = fec.regenerateDMR(m_buffer); LogMessage("%u [Audio Sync] BER=%.1f%%", m_slotNo, float(ber) / 1.41F); m_n = 0U; if (m_socket != NULL && m_slotNo == m_udpSlot) writeAMBE(m_buffer); } break; case SYNC_DATA: processDataSync(m_buffer); break; case SYNC_NONE: processAudio(m_buffer); break; default: break; } m_type = SYNC_NONE; m_count++; if (m_count >= 10U) { if (m_idleBits == 0U) m_idleBits = 1U; LogMessage("Signal lost, BER=%.1f%%", float(m_idleErrs * 100U) / float(m_idleBits)); m_receiving = false; m_idleBits = 0U; m_idleErrs = 0U; } } if (m_pos == (DMR_FRAME_LENGTH_BITS + DMR_CACH_LENGTH_BITS)) { // CUtils::dump("DMR CACH bytes", m_buffer + DMR_FRAME_LENGTH_BYTES, DMR_CACH_LENGTH_BYTES); processCACH(m_buffer + DMR_FRAME_LENGTH_BYTES); m_pos = 0U; } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) , _inProgress(false) { // Preload icons for faster switching iconMicrophone = new QIcon(":/images/microphone.png"); iconRecord = new QIcon(":/images/record.png"); iconProcess = new QIcon(":/images/process.png"); iconNetwork = new QIcon(":/images/network.png"); connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(orientationChanged())); #ifdef Q_WS_MAEMO_5 setAttribute(Qt::WA_Maemo5StackedWindow); setAttribute(Qt::WA_Maemo5AutoOrientation); #endif ui->setupUi(this); QAction * aboutAction = new QAction(tr("About EchoPrint"), this); connect(aboutAction, SIGNAL(triggered()), this, SLOT(on_echoNestButton_clicked())); ui->menuBar->addAction(aboutAction); nam = new QNetworkAccessManager(this); recorder = new RecorderMobility(this, DEFAULT_FILE); connect(recorder, SIGNAL(durationChanged(qint64)), this, SLOT(updateProgress(qint64))); connect(recorder, SIGNAL(error(QMediaRecorder::Error)), this, SLOT(displayErrorMessage())); connect(this, SIGNAL(captureFinished()), this, SLOT(processAudio())); connect(this, SIGNAL(resultReady(const EchoNestSong *)), this, SLOT(showResult(const EchoNestSong *))); #ifdef USE_LIBECHONEST Echonest::Config::instance()->setAPIKey(API_KEY.toLatin1()); #endif timer = new QTimer(this); timer->setSingleShot(true); connect(timer, SIGNAL(timeout()), this, SLOT(stopCapture())); }
void HelmStandaloneEditor::getNextAudioBlock(const AudioSourceChannelInfo& buffer) { ScopedLock lock(getCriticalSection()); int num_samples = buffer.buffer->getNumSamples(); int synth_samples = std::min(num_samples, MAX_BUFFER_PROCESS); processControlChanges(); processModulationChanges(); MidiBuffer midi_messages; midi_manager_->removeNextBlockOfMessages(midi_messages, num_samples); processMidi(midi_messages); processKeyboardEvents(midi_messages, num_samples); for (int b = 0; b < num_samples; b += synth_samples) { int current_samples = std::min<int>(synth_samples, num_samples - b); processAudio(buffer.buffer, mopo::NUM_CHANNELS, current_samples, b); } }
void AmMediaProcessorThread::run() { stop_requested = false; struct timeval now,next_tick,diff,tick; // wallclock time unsigned long long ts = 0;//4294417296; tick.tv_sec = 0; tick.tv_usec = 1000*WC_INC_MS; gettimeofday(&now,NULL); timeradd(&tick,&now,&next_tick); while(!stop_requested.get()){ gettimeofday(&now,NULL); if(timercmp(&now,&next_tick,<)){ struct timespec sdiff,rem; timersub(&next_tick,&now,&diff); sdiff.tv_sec = diff.tv_sec; sdiff.tv_nsec = diff.tv_usec * 1000; if(sdiff.tv_nsec > 2000000) // 2 ms nanosleep(&sdiff,&rem); } processAudio(ts); events.processEvents(); processDtmfEvents(); ts = (ts + WC_INC) & WALLCLOCK_MASK; timeradd(&tick,&next_tick,&next_tick); } }
void JsonApiHandlerWS::processApi(const string &data, const Params ¶msGET) { VAR_UNUSED(paramsGET); //not used for websocket Params jsonRoot; Params jsonData; //parse the json data json_error_t jerr; json_t *jroot = json_loads(data.c_str(), 0, &jerr); if (!jroot || !json_is_object(jroot)) { cDebugDom("network") << "Error loading json : " << jerr.text; return; } char *d = json_dumps(jroot, JSON_INDENT(4)); if (d) { cDebugDom("network") << d; free(d); } //decode the json root object into jsonParam jansson_decode_object(jroot, jsonRoot); json_t *jdata = json_object_get(jroot, "data"); if (jdata) jansson_decode_object(jdata, jsonData); //Format: { msg: "type", msg_id: id, data: {} } if (jsonRoot["msg"] == "login") { //check for if username/password matches string user = Utils::get_config_option("calaos_user"); string pass = Utils::get_config_option("calaos_password"); if (Utils::get_config_option("cn_user") != "" && Utils::get_config_option("cn_pass") != "") { user = Utils::get_config_option("cn_user"); pass = Utils::get_config_option("cn_pass"); } //Not logged in, need to wait for a correct login if (user != jsonData["cn_user"] || pass != jsonData["cn_pass"]) { cDebugDom("network") << "Login failed!"; json_t *jret = json_object(); json_object_set_new(jret, "success", json_string("false")); sendJson("login", jret, jsonRoot["msg_id"]); //Close the connection on login failure closeConnection.emit(WebSocketFrame::CloseCodeNormal, "login failed!"); } else { json_t *jret = json_object(); json_object_set_new(jret, "success", json_string("true")); sendJson("login", jret, jsonRoot["msg_id"]); loggedin = true; } } else if (loggedin) //only process other api if loggedin { if (jsonRoot["msg"] == "get_home") processGetHome(jsonData, jsonRoot["msg_id"]); else if (jsonRoot["msg"] == "get_state") processGetState(jdata, jsonRoot["msg_id"]); else if (jsonRoot["msg"] == "get_states") processGetStates(jsonData, jsonRoot["msg_id"]); else if (jsonRoot["msg"] == "query") processQuery(jsonData, jsonRoot["msg_id"]); else if (jsonRoot["msg"] == "get_param") processGetParam(jsonData, jsonRoot["msg_id"]); else if (jsonRoot["msg"] == "set_param") processSetParam(jsonData, jsonRoot["msg_id"]); else if (jsonRoot["msg"] == "del_param") processDelParam(jsonData, jsonRoot["msg_id"]); else if (jsonRoot["msg"] == "set_state") processSetState(jsonData, jsonRoot["msg_id"]); else if (jsonRoot["msg"] == "get_playlist") processGetPlaylist(jsonData, jsonRoot["msg_id"]); else if (jsonRoot["msg"] == "get_io") processGetIO(jdata, jsonRoot["msg_id"]); else if (jsonRoot["msg"] == "audio") processAudio(jdata, jsonRoot["msg_id"]); else if (jsonRoot["msg"] == "audio_db") processAudioDb(jdata, jsonRoot["msg_id"]); else if (jsonRoot["msg"] == "get_timerange") processGetTimerange(jsonData, jsonRoot["msg_id"]); else if (jsonRoot["msg"] == "set_timerange") processSetTimerange(jdata, jsonRoot["msg_id"]); else if (jsonRoot["msg"] == "autoscenario") processAutoscenario(jdata, jsonRoot["msg_id"]); // else if (jsonParam["action"] == "get_cover") // processGetCover(); // else if (jsonParam["action"] == "get_camera_pic") // processGetCameraPic(); // else if (jsonParam["action"] == "config") // processConfig(jroot); } json_decref(jroot); }
void JsonApiHandlerHttp::processApi(const string &data, const Params ¶msGET) { jsonParam.clear(); //parse the json data json_error_t jerr; json_t *jroot = json_loads(data.c_str(), 0, &jerr); if (!jroot || !json_is_object(jroot)) { cDebugDom("network") << "Error loading json : " << jerr.text << ". No JSON, trying with GET parameters."; jsonParam = paramsGET; if (jroot) { json_decref(jroot); jroot = nullptr; } } else { char *d = json_dumps(jroot, JSON_INDENT(4)); if (d) { cDebugDom("network") << d; free(d); } //decode the json root object into jsonParam jansson_decode_object(jroot, jsonParam); } //check for if username/password matches string user = Utils::get_config_option("calaos_user"); string pass = Utils::get_config_option("calaos_password"); if (Utils::get_config_option("cn_user") != "" && Utils::get_config_option("cn_pass") != "") { user = Utils::get_config_option("cn_user"); pass = Utils::get_config_option("cn_pass"); } if (user != jsonParam["cn_user"] || pass != jsonParam["cn_pass"]) { cDebugDom("network") << "Login failed!"; Params headers; headers.Add("Connection", "close"); headers.Add("Content-Type", "text/html"); string res = httpClient->buildHttpResponse(HTTP_400, headers, HTTP_400_BODY); sendData.emit(res); closeConnection.emit(0, string()); if (jroot) { json_decref(jroot); jroot = nullptr; } return; } //check action now if (jsonParam["action"] == "get_home") processGetHome(); else if (jsonParam["action"] == "get_state") processGetState(jroot); else if (jsonParam["action"] == "get_states") processGetStates(); else if (jsonParam["action"] == "query") processQuery(); else if (jsonParam["action"] == "get_param") processGetParam(); else if (jsonParam["action"] == "set_param") processSetParam(); else if (jsonParam["action"] == "del_param") processDelParam(); else if (jsonParam["action"] == "set_state") processSetState(); else if (jsonParam["action"] == "get_playlist") processGetPlaylist(); else if (jsonParam["action"] == "poll_listen") processPolling(); else if (jsonParam["action"] == "get_cover") processGetCover(); else if (jsonParam["action"] == "get_camera_pic") processGetCameraPic(); else if (jsonParam["action"] == "get_timerange") processGetTimerange(); else if (jsonParam["action"] == "camera") processCamera(); else { if (!jroot) { Params headers; headers.Add("Connection", "close"); headers.Add("Content-Type", "text/html"); string res = httpClient->buildHttpResponse(HTTP_400, headers, HTTP_400_BODY); sendData.emit(res); closeConnection.emit(0, string()); if (jroot) json_decref(jroot); return; } if (jsonParam["action"] == "config") processConfig(jroot); else if (jsonParam["action"] == "get_io") processGetIO(jroot); else if (jsonParam["action"] == "audio") processAudio(jroot); else if (jsonParam["action"] == "audio_db") processAudioDb(jroot); else if (jsonParam["action"] == "set_timerange") processSetTimerange(jroot); else if (jsonParam["action"] == "autoscenario") processAutoscenario(jroot); } if (jroot) json_decref(jroot); }
//!xerces start element event void amis::io::NcxFileReader::startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes) { char *node_name_ = XMLString::transcode(qname); string node_name; node_name.assign(node_name_); XMLString::release(&node_name_); if (node_name.compare("navMap") == 0) { mListType = 0; } //if this is a heading node else if (node_name.compare("navPoint") == 0) { processHeading(&attributes); } else if(node_name.compare("docTitle") == 0) { mpTitle = new amis::MediaGroup(); mpCurrentMediaGroup = mpTitle; } else if(node_name.compare("docAuthor") == 0) { mpAuthor = new amis::MediaGroup(); mpCurrentMediaGroup = mpAuthor; } else if(node_name.compare("navLabel") == 0) { processNavLabel(&attributes); } else if(node_name.compare("text") == 0) { processText(&attributes); } else if(node_name.compare("audio") == 0) { processAudio(&attributes); } else if(node_name.compare("navTarget") == 0) { processNavTarget(&attributes); } else if(node_name.compare("pageTarget") == 0) { processPageTarget(&attributes); } else if(node_name.compare("content") == 0) { string src; src.assign(SimpleAttrs::get("src", &attributes)); if (mListType == 0) mpCurrentNavPoint->setContent(src); else if(mListType == 2) mpCurrentPageTarget->setContent(src); else if(mListType == 1) mpCurrentNavTarget->setContent(src); } else if(node_name.compare("navList") == 0) { mListType = 1; string class_value; class_value.assign(SimpleAttrs::get("class", &attributes)); int idx = mpNavModel->addNavList(class_value); amis::dtb::nav::NavList* p_list = mpNavModel->getNavList(idx); } else if(node_name.compare("pageList") == 0) { mListType = 2; amis::dtb::nav::PageList* p_list = mpNavModel->getPageList(); } else if(node_name.compare("navInfo") == 0) { mpCurrentMediaGroup = new amis::MediaGroup(); if (mListType == 0) mpNavModel->getNavMap()->setNavInfo(mpCurrentMediaGroup); else if (mListType == 2) mpNavModel->getPageList()->setNavInfo(mpCurrentMediaGroup); else if (mListType == 1) mpNavModel->getNavLists()->back()->setNavInfo(mpCurrentMediaGroup); } else if(node_name.compare("smilCustomTest") == 0) { processCustomTest(&attributes); } }