SignalData::SignalData() { qDebug() << "SignalData ctor" << this; connect(&mSampler, SIGNAL(dataArrived()), SLOT(fetchSamples())); connect(&mSampler, SIGNAL(started()), this, SIGNAL(started())); connect(&mSampler, SIGNAL(finished()), this, SIGNAL(finished())); connect(&mSampler, SIGNAL(terminated()), this, SIGNAL(finished())); connect(&mSampler, SIGNAL(error(QString)), this, SIGNAL(error(QString))); const QMetaObject metaObject = Sample::staticMetaObject; const QMetaEnum metaEnum = metaObject.enumerator(metaObject.indexOfEnumerator("Marker")); for (int i = 0; i < metaEnum.keyCount(); i++) { mSamples.insert((Sample::Marker)metaEnum.value(i), QVector<Sample>()); mBoundingRects.insert((Sample::Marker)metaEnum.value(i), QRectF()); } }
int AOS4_sound_handler::audioTask() { uint32 sigMask; unsigned long clockAdvance = 40; unsigned int nSamples = (441*clockAdvance) / 10; unsigned int toFetch = nSamples*2; boost::int16_t samples[AHI_BUF_SIZE]; _closing = false; AHIDevice = -1; PlayBuffer[0] = (UBYTE*)IExec->AllocMem(BUFSIZE, MEMF_SHARED|MEMF_CLEAR); PlayBuffer[1] = (UBYTE*)IExec->AllocMem(BUFSIZE, MEMF_SHARED|MEMF_CLEAR); if (!PlayBuffer[0] || !PlayBuffer[1]) { log_error(_("AOS4: Unable to allocate memory for audio buffer!")); throw SoundException("AOS4: Unable to allocate memory for audio buffer!"); } if ((AHImp=(struct MsgPort*) IExec->AllocSysObjectTags(ASOT_PORT, TAG_DONE)) != NULL) { if ((AHIio=(struct AHIRequest *) IExec->AllocSysObjectTags(ASOT_IOREQUEST, ASOIOR_Size, sizeof(struct AHIRequest), ASOIOR_ReplyPort, AHImp, TAG_DONE)) != NULL) { AHIio->ahir_Version = 4; AHIDevice = IExec->OpenDevice(AHINAME, 0, (struct IORequest *)AHIio, 0); if (AHIDevice) { if (AHImp) IExec->FreeSysObject(ASOT_PORT, AHImp); AHImp = 0; if (AHIio) IExec->FreeSysObject(ASOT_IOREQUEST, (struct IORequest *)AHIio); AHIio = 0; if (PlayBuffer[0]) IExec->FreeMem(PlayBuffer[0],BUFSIZE); PlayBuffer[0] = 0; if (PlayBuffer[1]) IExec->FreeMem(PlayBuffer[1],BUFSIZE); PlayBuffer[1] = 0; log_error(_("AOS4: Unable to open AHI Device!")); throw SoundException("AOS4: Unable to open AHI Device!"); } IAHI = (struct AHIIFace *) IExec->GetInterface( (struct Library *) AHIio->ahir_Std.io_Device, "main", 1, NULL ); } else { if (PlayBuffer[0]) IExec->FreeMem(PlayBuffer[0],BUFSIZE); PlayBuffer[0] = 0; if (PlayBuffer[1]) IExec->FreeMem(PlayBuffer[1],BUFSIZE); PlayBuffer[1] = 0; if (AHImp) IExec->FreeSysObject(ASOT_PORT, AHImp); AHImp = 0; log_error(_("AOS4: Unable to CreateIORequest!")); throw SoundException("AOS4: Unable to CreateIORequest!"); } } else { if (PlayBuffer[0]) IExec->FreeMem(PlayBuffer[0],BUFSIZE); PlayBuffer[0] = 0; if (PlayBuffer[1]) IExec->FreeMem(PlayBuffer[1],BUFSIZE); PlayBuffer[1] = 0; log_error(_("AOS4: Unable to CreateMsgPort for AHI Device!")); throw SoundException("AOS4: Unable to CreateMsgPort for AHI Device!"); } AHIiocopy = IExec->AllocSysObjectTags(ASOT_IOREQUEST,ASOIOR_Duplicate,AHIio,TAG_DONE); if(! AHIiocopy) { if (AHImp) IExec->FreeSysObject(ASOT_PORT, AHImp); AHImp = 0; if (AHIio) IExec->FreeSysObject(ASOT_IOREQUEST, (struct IORequest *)AHIio); AHIio = 0; if (PlayBuffer[0]) IExec->FreeMem(PlayBuffer[0],BUFSIZE); PlayBuffer[0] = 0; if (PlayBuffer[1]) IExec->FreeMem(PlayBuffer[1],BUFSIZE); PlayBuffer[1] = 0; log_error(_("AOS4: Not enough memory for AHIiocopy!")); throw SoundException("AOS4: Not enough memory for AHIiocopy!"); } AHICurBuf = 0; Buffer = 0; BufferPointer = PlayBuffer[0]; BufferFill = 0; AHIReqSent[0] = false; AHIReqSent[1] = false; AHIios[0]=AHIio; AHIios[1]=(AHIRequest*)AHIiocopy; log_debug(_("AOS4: audioTask:Initialize timer..")); TimerInit(); log_debug(_("AOS4: audioTask:Starting Timer..")); TimerReset(RESET_TIME); while (true) { sigMask = SIGBREAKF_CTRL_C | _timerSig; uint32 sigGot = IExec->Wait(sigMask); if (sigGot & SIGBREAKF_CTRL_C) { _closing = true; log_debug(_("AOS4: Closing Audio Thread..")); break; } if (sigGot & _timerSig) { IExec->GetMsg(_port); if (!sound_handler::isPaused()) { while (toFetch && !_closing) { unsigned int n = std::min(toFetch, AHI_BUF_SIZE); if (!_closing) fetchSamples((boost::int16_t*)&samples, n); toFetch -= n; } toFetch = nSamples*2; } if (!_closing) TimerReset(RESET_TIME); } } log_debug(_("AOS4: Cleaning Audio Stuff..")); if (AHIios[0]) { if (!IExec->CheckIO((struct IORequest *) AHIios[0])) { IExec->AbortIO((struct IORequest *) AHIios[0]); IExec->WaitIO((struct IORequest *) AHIios[0]); } } if(AHIios[1]) { // Only if the second request was started if (!IExec->CheckIO((struct IORequest *) AHIios[1])) { IExec->AbortIO((struct IORequest *) AHIios[1]); IExec->WaitIO((struct IORequest *) AHIios[1]); } } if(!AHIDevice) if (AHIio) IExec->CloseDevice((struct IORequest *)AHIio); if (AHIio) IExec->FreeSysObject(ASOT_IOREQUEST,(struct IORequest *)AHIio); AHIio = 0; if (AHIiocopy) IExec->FreeMem(AHIiocopy,sizeof(struct AHIRequest)); AHIiocopy = 0; if (AHImp) IExec->FreeSysObject(ASOT_PORT, AHImp); AHImp = 0; if (IAHI) IExec->DropInterface((struct Interface*) IAHI); IAHI = 0; if (PlayBuffer[0]) IExec->FreeMem(PlayBuffer[0],BUFSIZE); PlayBuffer[0] = 0; if (PlayBuffer[1]) IExec->FreeMem(PlayBuffer[1],BUFSIZE); PlayBuffer[1] = 0; log_debug(_("AOS4: Exit Audio Thread..")); log_debug(_("AOS4: audioTask:Close timer..")); TimerExit(); return(RETURN_OK); }