diff options
-rw-r--r-- | muse/muse/audio.cpp | 44 | ||||
-rw-r--r-- | muse/muse/audioprefetch.cpp | 7 | ||||
-rw-r--r-- | muse/muse/audioprefetch.h | 2 | ||||
-rw-r--r-- | muse/muse/midiseq.cpp | 11 | ||||
-rw-r--r-- | muse/muse/muse.cpp | 10 | ||||
-rw-r--r-- | muse/muse/wavetrack.cpp | 5 | ||||
-rw-r--r-- | muse/muse/wavetrack.h | 3 |
7 files changed, 47 insertions, 35 deletions
diff --git a/muse/muse/audio.cpp b/muse/muse/audio.cpp index b5bda655..c42a91e8 100644 --- a/muse/muse/audio.cpp +++ b/muse/muse/audio.cpp @@ -366,7 +366,11 @@ void Audio::process(unsigned frames) unsigned framePos = _pos.frame(); - if (state == PLAY) { // TODO: only when looping? + if (state == PLAY) { + // + // clear prefetch FIFO if left/right locators + // have changed + // unsigned llmark = song->lPos().frame(); unsigned rrmark = song->rPos().frame(); @@ -374,13 +378,7 @@ void Audio::process(unsigned frames) // // invalidate audio prefetch buffer // -#if 0 - WaveTrackList* tl = song->waves(); - for (iWaveTrack it = tl->begin(); it != tl->end(); ++it) { - WaveTrack* track = *it; - track->clearPrefetchFifo(); - } -#endif + audioPrefetch->getFifo()->clear(); audioPrefetch->msgSeek(framePos); lmark = llmark; rmark = rrmark; @@ -475,18 +473,21 @@ void Audio::process(unsigned frames) // printf("process %3d\n", fifo->count()); if (fifo->count() == 0) { printf("MusE::Audio: fifo underflow at 0x%x\n", curTickPos); + audioPrefetch->msgTick(); } else { bool msg = true; do { unsigned fifoPos = fifo->readPos(); if (fifoPos != framePos) { -// if (msg) { - printf("Muse::Audio: wrong prefetch data 0x%x, expected 0x%x\n", + if (msg) { + printf("Muse::Audio: wrong prefetch data 0x%x, expected 0x%x\n", fifoPos, framePos); msg = false; -// } - fifo->get(); + } + if (fifoPos > framePos) + break; + fifo->get(); // discard buffer } else { _curReadIndex = fifo->ridx; @@ -494,7 +495,7 @@ void Audio::process(unsigned frames) } } while (fifo->count()); if (_curReadIndex == -1) { - seek(_pos); + seek(_pos + frames); } } } @@ -528,19 +529,20 @@ void Audio::process(unsigned frames) song->bounceTrack->process(); if (isPlaying()) { - if (!freewheel()) - audioPrefetch->msgTick(framePos); + if (!freewheel()) { + // + // consume prefetch buffer + // + if (_curReadIndex != -1) { + audioPrefetch->getFifo()->get(); + audioPrefetch->msgTick(); + } + } if (recording && (_bounce == 0 || _bounce == 1)) audioWriteback->trigger(); _pos += frames; curTickPos = nextTickPos; } - - // - // consume prefetch buffer - // - if (_curReadIndex != -1) - audioPrefetch->getFifo()->get(); } //--------------------------------------------------------- diff --git a/muse/muse/audioprefetch.cpp b/muse/muse/audioprefetch.cpp index 23f895f7..e498169e 100644 --- a/muse/muse/audioprefetch.cpp +++ b/muse/muse/audioprefetch.cpp @@ -110,12 +110,10 @@ void AudioPrefetch::processMsg1(const void* m) // trigger audio prefetch with next buffer position //--------------------------------------------------------- -void AudioPrefetch::msgTick(unsigned pos) +void AudioPrefetch::msgTick() { PrefetchMsg msg; msg.id = PREFETCH_TICK; -// msg.pos = pos; -// msg.serialNo = 0; if (fifo.count() < FIFO_BUFFER/3) { while (sendMsg1(&msg, sizeof(msg))) { printf("AudioPrefetch::msgTick(): send failed!\n"); @@ -178,8 +176,7 @@ void AudioPrefetch::prefetch(bool seekFlag) if (!seekFlag && ((audio->isRecording() && track->recordFlag()) || !audio->isPlaying())) continue; int ch = track->channels(); - float** bpp = track->prefetchBuffer(widx); - track->fetchData(writePos, segmentSize, bpp); + track->fetchData(writePos, segmentSize, widx); } writePos += segmentSize; fifo.put(); diff --git a/muse/muse/audioprefetch.h b/muse/muse/audioprefetch.h index b456989a..14e8096c 100644 --- a/muse/muse/audioprefetch.h +++ b/muse/muse/audioprefetch.h @@ -43,7 +43,7 @@ class AudioPrefetch : public Thread { ~AudioPrefetch(); virtual void start(int); - void msgTick(unsigned pos); + void msgTick(); void msgSeek(unsigned pos); bool seekDone() const { return seekCount == 0; } Fifo1* getFifo() { return &fifo; } diff --git a/muse/muse/midiseq.cpp b/muse/muse/midiseq.cpp index 5fac0c5c..fd79ff43 100644 --- a/muse/muse/midiseq.cpp +++ b/muse/muse/midiseq.cpp @@ -345,6 +345,7 @@ void MidiSeq::threadStart(void*) rt_param.sched_priority); } } + // timer = new PosixTimer; // if (!timer->initTimer()) { // delete timer; @@ -381,9 +382,11 @@ void MidiSeq::updatePollFd() if (!isRunning()) return; clearPollFd(); - int timerFd = timer->getFd(); - if (timerFd != -1) - addPollFd(timerFd, POLLIN, midiTick, this, 0); + if (timer) { + int timerFd = timer->getFd(); + if (timerFd != -1) + addPollFd(timerFd, POLLIN, midiTick, this, 0); + } addPollFd(toThreadFdr, POLLIN, ::readMsg, this, 0); @@ -415,6 +418,8 @@ void MidiSeq::threadStop() bool MidiSeq::initRealtimeTimer() { + if (!timer) + return false; if (!timer->setTimerFreq(config.rtcTicks)) return false; if (!timer->startTimer()) diff --git a/muse/muse/muse.cpp b/muse/muse/muse.cpp index 19bc5ab1..48d7414a 100644 --- a/muse/muse/muse.cpp +++ b/muse/muse/muse.cpp @@ -238,10 +238,18 @@ bool MusE::seqStart() strerror(rv)); pthread_attr_destroy(attributes); } -#if 0 +#if 1 + // + // start audio prefetch threads with realtime + // priority + // audioPrefetch->start(0); audioWriteback->start(0); #else + // + // start audio prefetch threads as normal + // (non realtime) threads + // audioPrefetch->start(realTimePriority-5); audioWriteback->start(realTimePriority-5); #endif diff --git a/muse/muse/wavetrack.cpp b/muse/muse/wavetrack.cpp index 80e2ae84..76d7bdf3 100644 --- a/muse/muse/wavetrack.cpp +++ b/muse/muse/wavetrack.cpp @@ -72,8 +72,9 @@ WaveTrack::~WaveTrack() // called from prefetch thread //--------------------------------------------------------- -void WaveTrack::fetchData(unsigned pos, unsigned samples, float** bp) +void WaveTrack::fetchData(unsigned pos, unsigned samples, int widx) { + float** bp = readBuffer[widx]; for (int i = 0; i < channels(); ++i) memset(bp[i], 0, samples * sizeof(float)); PartList* pl = parts(); @@ -323,7 +324,7 @@ void WaveTrack::collectInputData() unsigned framePos = audio->pos().frame(); if (audio->freewheel()) { // when freewheeling, read data direct from file: - fetchData(framePos, segmentSize, buffer); + // TODO: fetchData(framePos, segmentSize, buffer); } else { int idx = audio->curReadIndex(); diff --git a/muse/muse/wavetrack.h b/muse/muse/wavetrack.h index 3b5c36ec..f77c210d 100644 --- a/muse/muse/wavetrack.h +++ b/muse/muse/wavetrack.h @@ -59,7 +59,7 @@ class WaveTrack : public AudioTrack { virtual void read(QDomNode); virtual void write(Xml&) const; - virtual void fetchData(unsigned pos, unsigned frames, float** bp); + virtual void fetchData(unsigned pos, unsigned frames, int); virtual void setChannels(int n); virtual bool hasAuxSend() const { return true; } @@ -70,7 +70,6 @@ class WaveTrack : public AudioTrack { void recordBeat(); virtual void stopRecording(const AL::Pos&, const AL::Pos&); virtual void process(); - float** prefetchBuffer(int idx) { return readBuffer[idx]; } }; |