void AudioCapture::run() { m_userStop = false; while (!m_userStop) { m_mutex.lock(); if (m_pause == false && m_captureSize != 0) { if (readAudio(m_captureSize) == true) { processData(); } else { //qDebug() << "Error reading data from audio source"; usleep(5000); } } else usleep(15000); m_mutex.unlock(); } }
void IniConfig::read () { char *path = NULL; ini_fd_t ini = 0; char *configPath; size_t length; #ifdef _WIN32 path = (char *) getenv("USERPROFILE"); #endif #ifdef HAVE_UNIX path = (char *) getenv("HOME"); #endif if (!path) goto IniConfig_read_error; length = strlen(path) + strlen(DIR_NAME) + strlen(FILE_NAME) + 3; configPath = (char *) malloc(length); if (! configPath) goto IniConfig_read_error; sprintf(configPath, "%s/%s", path, DIR_NAME); #ifdef HAVE_UNIX // Make sure the config path exists if (!opendir(configPath)) mkdir(configPath, 0755); #endif #ifdef _WIN32 CreateDirectory(configPath, NULL); #endif /* sprintf on top of itself fails nowadays. */ strcat(configPath, "/"); strcat(configPath, FILE_NAME); // Opens an existing file or creates a new one ini = ini_open (configPath, "w", ";"); // Unable to open file? if (!ini) goto IniConfig_read_error; clear (); // This may not exist here... status &= readSidplay2 (ini); status &= readConsole (ini); status &= readAudio (ini); status &= readEmulation (ini); ini_close (ini); return; IniConfig_read_error: if (ini) ini_close (ini); clear (); status = false; }
BeatController::BeatController(QAudioDeviceInfo inputDevice, uint16_t recordSize, uint32_t sampleRate, uint16_t m_bandCount, QObject *parent) : QObject(parent) { m_RecordSize = recordSize; m_Buffer = new SoundBuffer(recordSize); m_Analyser = new BeatAnalyser(m_bandCount,sampleRate,recordSize); m_inputDevice = QAudioDeviceInfo(inputDevice); m_FFT = new FFT(recordSize); m_FFT->setSoundBuffer(m_Buffer); m_Analyser->setFFT(m_FFT); QAudioFormat audioFormat; audioFormat.setSampleRate(sampleRate); audioFormat.setChannelCount(1); audioFormat.setSampleSize(16); audioFormat.setSampleType(QAudioFormat::SignedInt); audioFormat.setByteOrder(QAudioFormat::LittleEndian); audioFormat.setCodec("audio/pcm"); //QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice()); if (!m_inputDevice.isFormatSupported(audioFormat)) { qWarning() << "Default format not supported - trying to use nearest"; audioFormat = m_inputDevice.nearestFormat(audioFormat); } m_audioInput = new QAudioInput(m_inputDevice, audioFormat, this); m_ioDevice = m_audioInput->start(); connect(m_ioDevice, SIGNAL(readyRead()), this, SLOT(readAudio())); }
void AudioCapture::run() { m_userStop = false; while (!m_userStop) { m_mutex.lock(); if (m_pause == false && m_captureSize != 0) { if (readAudio(m_captureSize) == true) { processData(); emit dataProcessed(m_fftMagnitudeBuffer, m_maxMagnitude, m_signalPower); } else qDebug() << "Error reading data from audio source"; } else usleep(15000); m_mutex.unlock(); } }
uint8_t tsHeader::open(const char *name) { char *idxName=(char *)malloc(strlen(name)+6); bool r=false; FP_TYPE appendType=FP_DONT_APPEND; uint32_t append; char *type; uint64_t startDts; uint32_t version=0; sprintf(idxName,"%s.idx2",name); indexFile index; if(!index.open(idxName)) { printf("[tsDemux] Cannot open index file %s\n",idxName); free(idxName); return false; } if(!index.readSection("System")) { printf("[tsDemux] Cannot read system section\n"); goto abt; } type=index.getAsString("Type"); if(!type || type[0]!='T') { printf("[tsDemux] Incorrect or not found type\n"); goto abt; } version=index.getAsUint32("Version"); if(version!=ADM_INDEX_FILE_VERSION) { GUI_Error_HIG("Error","This file's index has been created with an older version of avidemux.\nPlease delete the idx2 file and reopen."); goto abt; } append=index.getAsUint32("Append"); printf("[tsDemux] Append=%"PRIu32"\n",append); if(append) appendType=FP_APPEND; if(!parser.open(name,&appendType)) { printf("[tsDemux] Cannot open root file (%s)\n",name); goto abt; } if(!readVideo(&index)) { printf("[tsDemux] Cannot read Video section of %s\n",idxName); goto abt; } if(!readAudio(&index,name)) { printf("[tsDemux] Cannot read Audio section of %s => No audio\n",idxName); } if(!readIndex(&index)) { printf("[tsDemux] Cannot read index for file %s\n",idxName); goto abt; } updateIdr(); updatePtsDts(); _videostream.dwLength= _mainaviheader.dwTotalFrames=ListOfFrames.size(); printf("[tsDemux] Found %d video frames\n",_videostream.dwLength); if(_videostream.dwLength)_isvideopresent=1; //*********** tsPacket=new tsPacketLinear(videoPid); if(tsPacket->open(name,appendType)==false) { printf("tsDemux] Cannot tsPacket open the file\n"); goto abt; } r=true; for(int i=0;i<listOfAudioTracks.size();i++) { ADM_tsTrackDescriptor *desc=listOfAudioTracks[i]; ADM_audioStream *audioStream=ADM_audioCreateStream(&desc->header,desc->access); if(!audioStream) { }else { desc->stream=audioStream; audioStream->setLanguage(desc->language); } } abt: free(idxName); index.close(); printf("[tsDemuxer] Loaded %d\n",r); return r; }
uint8_t psHeader::open(const char *name) { char idxName[strlen(name)+4]; bool r=false; FP_TYPE appendType=FP_DONT_APPEND; uint32_t append; char *type; sprintf(idxName,"%s.idx",name); indexFile index; if(!index.open(idxName)) { printf("[psDemux] Cannot open index file %s\n",idxName); return false; } if(!index.readSection("System")) { printf("[psDemux] Cannot read system section\n"); goto abt; } type=index.getAsString("Type"); if(!type || type[0]!='P') { printf("[psDemux] Incorrect or not found type\n"); goto abt; } append=index.getAsUint32("Append"); if(append) appendType=FP_APPEND; if(!parser.open(name,&appendType)) { printf("[psDemux] Cannot open root file\n",name); goto abt; } if(!readVideo(&index)) { printf("[psDemux] Cannot read Video section of %s\n",idxName); goto abt; } if(!readAudio(&index,name)) { printf("[psDemux] Cannot read Audio section of %s\n",idxName); goto abt; } if(!readIndex(&index)) { printf("[psDemux] Cannot read index for file %s\n",idxName); goto abt; } updatePtsDts(); _videostream.dwLength= _mainaviheader.dwTotalFrames=ListOfFrames.size(); printf("[psDemux] Found %d video frames\n",_videostream.dwLength); if(_videostream.dwLength)_isvideopresent=1; //*********** psPacket=new psPacketLinear(0xE0); if(psPacket->open(name,append)==false) { printf("psDemux] Cannot psPacket open the file\n"); goto abt; } r=true; abt: index.close(); printf("[psDemuxer] Loaded %d\n",r); return r; }
uint8_t psHeader::open(const char *name) { char *idxName=(char *)malloc(strlen(name)+6); bool r=false; FP_TYPE appendType=FP_DONT_APPEND; uint32_t append; char *type; uint64_t startDts; uint32_t version=0; sprintf(idxName,"%s.idx2",name); indexFile index; if(!index.open(idxName)) { printf("[psDemux] Cannot open index file %s\n",idxName); free(idxName); return false; } if(!index.readSection("System")) { printf("[psDemux] Cannot read system section\n"); goto abt; } version=index.getAsUint32("Version"); if(version!=ADM_INDEX_FILE_VERSION) { GUI_Error_HIG(QT_TRANSLATE_NOOP("psdemuxer","Error"), QT_TRANSLATE_NOOP("psdemuxer","This file's index has been created with an older version of avidemux.\nPlease delete the idx2 file and reopen.")); goto abt; } type=index.getAsString("Type"); if(!type || type[0]!='P') { printf("[psDemux] Incorrect or not found type\n"); goto abt; } append=index.getAsUint32("Append"); printf("[psDemux] Append=%" PRIu32"\n",append); if(append) appendType=FP_APPEND; if(!parser.open(name,&appendType)) { printf("[psDemux] Cannot open root file %s\n",name); goto abt; } if(!readVideo(&index)) { printf("[psDemux] Cannot read Video section of %s\n",idxName); goto abt; } if(!readAudio(&index,name)) { printf("[psDemux] Cannot read Audio section of %s => No audio\n",idxName); } if(!readIndex(&index)) { printf("[psDemux] Cannot read index for file %s\n",idxName); goto abt; } if(readScrReset(&index)) { ADM_info("Adjusting timestamps\n"); // Update PTS/DTS of video taking SCR Resets into account int nbPoints=listOfScrGap.size(); int index=0; uint64_t pivot=listOfScrGap[0].position; uint64_t timeOffset=0; uint32_t nbImage=ListOfFrames.size(); for(int i=0;i<nbImage;i++) { dmxFrame *frame=ListOfFrames[i]; if(frame->startAt>pivot) // next gap { timeOffset=listOfScrGap[index].timeOffset; index++; if(index>=nbPoints) pivot=0xfffffffffffffffLL; else pivot=listOfScrGap[index].position; } if(frame->dts!=ADM_NO_PTS) frame->dts+=timeOffset; if(frame->pts!=ADM_NO_PTS) frame->pts+=timeOffset; } ADM_info("Adjusted %d scr reset out of %d\n",(int)index,(int)nbPoints); ADM_info("Updating audio with list of SCR\n"); for(int i=0;i<listOfAudioTracks.size();i++) listOfAudioTracks[i]->access->setScrGapList(&listOfScrGap) ; } updatePtsDts(); _videostream.dwLength= _mainaviheader.dwTotalFrames=ListOfFrames.size(); printf("[psDemux] Found %d video frames\n",_videostream.dwLength); if(_videostream.dwLength)_isvideopresent=1; //*********** psPacket=new psPacketLinear(0xE0); if(psPacket->open(name,appendType)==false) { printf("psDemux] Cannot psPacket open the file\n"); goto abt; } r=true; for(int i=0;i<listOfAudioTracks.size();i++) { ADM_psTrackDescriptor *desc=listOfAudioTracks[i]; ADM_audioStream *audioStream=ADM_audioCreateStream(&desc->header,desc->access); if(!audioStream) { }else { desc->stream=audioStream; } } abt: index.close(); free(idxName); printf("[psDemuxer] Loaded %d\n",r); return r; }