From e2de64d6f1beb9e492daf5b886e19933c1fa41dd Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- mpeglib/lib/util/audio/dspWrapper.cpp | 193 ++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 mpeglib/lib/util/audio/dspWrapper.cpp (limited to 'mpeglib/lib/util/audio/dspWrapper.cpp') diff --git a/mpeglib/lib/util/audio/dspWrapper.cpp b/mpeglib/lib/util/audio/dspWrapper.cpp new file mode 100644 index 00000000..cd9afa57 --- /dev/null +++ b/mpeglib/lib/util/audio/dspWrapper.cpp @@ -0,0 +1,193 @@ +/* + a wrapper for the audioDevice. + Copyright (C) 1998 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + +#include "dspWrapper.h" +#include "audioIO.h" + + +#include "../../frame/pcmFrame.h" +#include "../../frame/floatFrame.h" + +#include + +using namespace std; + +DSPWrapper::DSPWrapper() { + currentFormat=new PCMFrame(0); + lopenDevice=false; + lopenMixer=false; + + audioConstruct(); +} + +DSPWrapper::~DSPWrapper() { + if (lopenDevice) { + audioClose(); + } + if (lopenMixer) { + mixerClose(); + } + audioDestruct(); + delete currentFormat; +} + + +int DSPWrapper::isOpenDevice() { + return lopenDevice; +} + +int DSPWrapper::openDevice() { + if (lopenDevice==true) { + return true; + } + lopenDevice=audioOpen(); + return lopenDevice; +} + +int DSPWrapper::closeDevice() { + if (isOpenDevice() == true) { + audioClose(); + currentFormat->setFrameFormat(-1,-1); + lopenDevice=false; + } + return true; +} + + +int DSPWrapper::isOpenMixer() { + return lopenMixer; +} + + +int DSPWrapper::getAudioBufferSize() { + return ::getAudioBufferSize(); +} + + +int DSPWrapper::openMixer() { + lopenMixer=mixerOpen(); + return lopenMixer; +} + +int DSPWrapper::closeMixer() { + if (isOpenMixer() == true) { + mixerClose(); + lopenMixer=false; + } + return true; +} + + +int DSPWrapper::audioPlay(char *buf, int len) { + return audioWrite(buf,len); +} + +int DSPWrapper::audioSetup(int stereo,int sampleSize,int lSigned, + int lBigEndian,int freq) { + + + if (isOpenDevice()==false) { + cout << "device not open"<getSampleSize() != sampleSize) { + cout << "FIXME: pcmFrame with sampleSize:"<setFrameFormat(stereo,freq); + return true; +} + +int DSPWrapper::audioSetup(AudioFrame* audioFrame) { + if (audioFrame == NULL) { + cout << "audioFrame NULL: DSPWrapper:audioSetup"<isFormatEqual(currentFormat)==false) { + audioSetup(audioFrame->getStereo(),audioFrame->getSampleSize(), + audioFrame->getSigned(),audioFrame->getBigEndian(), + audioFrame->getFrequenceHZ()); + } + return true; +} + + +int DSPWrapper::audioPlay(PCMFrame* pcmFrame) { + if (pcmFrame == NULL) { + cout << "pcmFrame NULL: DSPWrapper:audioPlay"<isFormatEqual(currentFormat)==false) { + audioSetup(pcmFrame->getStereo(),pcmFrame->getSampleSize(), + pcmFrame->getSigned(),pcmFrame->getBigEndian(), + pcmFrame->getFrequenceHZ()); + } + int len=pcmFrame->getLen()*2; + int played=audioPlay((char*)pcmFrame->getData(),len); + return (len == played); +} + + +// +// Misuse our internal currentFormat for the float->int conversion. +// + +int DSPWrapper::audioPlay(FloatFrame* floatFrame) { + if (floatFrame == NULL) { + cout << "floatFrame NULL: DSPWrapper:audioPlay"<isFormatEqual(currentFormat)==false) { + audioSetup(floatFrame->getStereo(),floatFrame->getSampleSize(), + floatFrame->getSigned(),floatFrame->getBigEndian(), + floatFrame->getFrequenceHZ()); + } + + int tmpLen=currentFormat->getLen(); + if (tmpLen < floatFrame->getLen()) { + delete currentFormat; + currentFormat=new PCMFrame(floatFrame->getLen()); + floatFrame->copyFormat(currentFormat); + } + currentFormat->clearrawdata(); + currentFormat->putFloatData(floatFrame->getData(),floatFrame->getLen()); + return audioPlay(currentFormat); +} + +void DSPWrapper::audioFlush() { + closeDevice(); +} + + +void DSPWrapper::setVolume(float leftPercent,float rightPercent) { + if (isOpenMixer()) { + mixerSetVolume((int)leftPercent,(int)rightPercent); + } else { + cout << "cannot set Mixer settings:not open!"<print("currentFormat"); + +} -- cgit v1.2.3