diff options
| -rw-r--r-- | src/qmmp/effect.h | 2 | ||||
| -rw-r--r-- | src/qmmp/output.h | 2 | ||||
| -rw-r--r-- | src/qmmp/qmmpaudioengine.cpp | 55 | ||||
| -rw-r--r-- | src/qmmp/soundcore.cpp | 34 |
4 files changed, 44 insertions, 49 deletions
diff --git a/src/qmmp/effect.h b/src/qmmp/effect.h index 2ed82269c..85a37081f 100644 --- a/src/qmmp/effect.h +++ b/src/qmmp/effect.h @@ -73,7 +73,7 @@ public: * Creates a list of enabled effects. * @param parent Parent object of all created Effect objects. */ - static QList<Effect*> create(QObject *parent); + static QList<Effect*> create(QObject *parent = 0); /*! * Returns a list of effect factories. */ diff --git a/src/qmmp/output.h b/src/qmmp/output.h index 5b864a7b0..45fb1ad50 100644 --- a/src/qmmp/output.h +++ b/src/qmmp/output.h @@ -109,7 +109,7 @@ public: * @param parent Parent object. * @return Output subclass object. */ - static Output *create(QObject *parent); + static Output *create(QObject *parent = 0); /*! * Returns a list of output factories. */ diff --git a/src/qmmp/qmmpaudioengine.cpp b/src/qmmp/qmmpaudioengine.cpp index 5ebcee90d..fef8fc2e2 100644 --- a/src/qmmp/qmmpaudioengine.cpp +++ b/src/qmmp/qmmpaudioengine.cpp @@ -102,8 +102,7 @@ bool QmmpAudioEngine::enqueue(InputSource *source) } if(!m_output) { - m_output = createOutput(decoder); - if(!m_output) + if(!(m_output = createOutput(decoder))) return FALSE; } m_decoders.enqueue(decoder); @@ -121,6 +120,7 @@ qint64 QmmpAudioEngine::totalTime() void QmmpAudioEngine::setEQ(double bands[10], double preamp) { + mutex()->lock(); set_preamp(0, 1.0 + 0.0932471 *preamp + 0.00279033 * preamp * preamp); set_preamp(1, 1.0 + 0.0932471 *preamp + 0.00279033 * preamp * preamp); for (int i=0; i<10; ++i) @@ -129,35 +129,16 @@ void QmmpAudioEngine::setEQ(double bands[10], double preamp) set_gain(i,0, 0.03*value+0.000999999*value*value); set_gain(i,1, 0.03*value+0.000999999*value*value); } + mutex()->unlock(); } void QmmpAudioEngine::setEQEnabled(bool on) { + mutex()->lock(); m_useEQ = on; + mutex()->unlock(); } -/*void QmmpAudioEngine::configure(quint32 srate, int chan, int bps) -{ - Effect* effect = 0; - m_freq = srate; - m_chan = chan; - m_bps = bps; - foreach(effect, m_effects) - { - effect->configure(srate, chan, bps); - srate = effect->sampleRate(); - chan = effect->channels(); - bps = effect->bitsPerSample(); - } - m_chan = chan; - if (m_output) - { - m_output->configure(srate, chan, bps); - if (!m_output_buf) - m_output_buf = new unsigned char[Qmmp::globalBufferSize()]; - } -}*/ - void QmmpAudioEngine::seek(qint64 time) { if (m_output && m_output->isRunning()) @@ -244,6 +225,8 @@ void QmmpAudioEngine::stop() } reset(); m_decoder = 0; + while(!m_effects.isEmpty()) //delete effects + delete m_effects.takeFirst(); } qint64 QmmpAudioEngine::produceSound(char *data, qint64 size, quint32 brate, int chan) @@ -323,9 +306,8 @@ void QmmpAudioEngine::run() } m_decoder = m_decoders.dequeue(); - m_output->start(); mutex()->unlock(); - + m_output->start(); sendMetaData(); while (! m_done && ! m_finish) @@ -487,6 +469,9 @@ void QmmpAudioEngine::sendMetaData() Output *QmmpAudioEngine::createOutput(Decoder *d) { + while(!m_effects.isEmpty()) //delete effects + delete m_effects.takeFirst(); + m_ap = d->audioParameters(); Output *output = Output::create(0); if(!output) @@ -497,13 +482,25 @@ Output *QmmpAudioEngine::createOutput(Decoder *d) } if (!output->initialize()) { - qWarning("SoundCore: unable to initialize output"); + qWarning("QmmpAudioEngine: unable to initialize output"); delete output; output = 0; StateHandler::instance()->dispatch(Qmmp::FatalError); return FALSE; } - output->configure(m_ap.sampleRate(), m_ap.channels(), m_ap.bits()); + m_effects = Effect::create(); + quint32 srate = m_ap.sampleRate(); + int chan = m_ap.channels(); + int bps = m_ap.bits(); + + foreach(Effect *effect, m_effects) + { + effect->configure(srate, chan, bps); + srate = effect->sampleRate(); + chan = effect->channels(); + bps = effect->bitsPerSample(); + } + m_chan = chan; + output->configure(srate, chan, bps); return output; } - diff --git a/src/qmmp/soundcore.cpp b/src/qmmp/soundcore.cpp index 271711847..aba3a4c2c 100644 --- a/src/qmmp/soundcore.cpp +++ b/src/qmmp/soundcore.cpp @@ -93,7 +93,7 @@ bool SoundCore::play(const QString &source, bool queue) else m_inputSource->ioDevice()->open(QIODevice::ReadOnly); return decode(); - return TRUE; + //return TRUE; } void SoundCore::stop() @@ -136,25 +136,21 @@ void SoundCore::setEQ(double bands[10], double preamp) for (int i = 0; i < 10; ++i) m_bands[i] = bands[i]; m_preamp = preamp; - if (m_decoder) + if (m_engine) { - m_engine->mutex()->lock (); m_engine->setEQ(m_bands, m_preamp); m_engine->setEQEnabled(m_useEQ); - m_engine->mutex()->unlock(); } } void SoundCore::setEQEnabled(bool on) { - /*m_useEQ = on; - if (m_decoder) + m_useEQ = on; + if (m_engine) { - m_decoder->mutex()->lock (); - m_decoder->setEQ(m_bands, m_preamp); - m_decoder->setEQEnabled(on); - m_decoder->mutex()->unlock(); - }*/ + m_engine->setEQ(m_bands, m_preamp); + m_engine->setEQEnabled(on); + } } void SoundCore::setVolume(int L, int R) @@ -174,14 +170,14 @@ int SoundCore::rightVolume() void SoundCore::setSoftwareVolume(bool b) { - /*SoftwareVolume::setEnabled(b); - if (m_decoder) - m_decoder->mutex()->lock(); + SoftwareVolume::setEnabled(b); //TODO move to engine settings + if (m_engine) + m_engine->mutex()->lock(); delete m_volumeControl; m_volumeControl = VolumeControl::create(this); connect(m_volumeControl, SIGNAL(volumeChanged(int, int)), SIGNAL(volumeChanged(int, int))); - if (m_decoder) - m_decoder->mutex()->unlock();*/ + if (m_engine) + m_engine->mutex()->unlock(); } bool SoundCore::softwareVolume() @@ -240,6 +236,9 @@ bool SoundCore::decode() connect(m_engine, SIGNAL(playbackFinished()), SIGNAL(finished())); } + setEQ(m_bands, m_preamp); + setEQEnabled(m_useEQ); + if(m_engine->enqueue(m_inputSource)) { m_inputSource->setParent(m_engine); @@ -251,8 +250,7 @@ bool SoundCore::decode() return FALSE; } - setEQ(m_bands, m_preamp); - setEQEnabled(m_useEQ); + qDebug ("ok"); return TRUE; |
