From 690dd7a33ddc90678367d73adf313533536e10f2 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Fri, 29 Apr 2016 23:57:30 +0100 Subject: Apply clang-format --- src/modules/snd/libkvisnd.cpp | 684 +++++++++++++++++++++--------------------- 1 file changed, 340 insertions(+), 344 deletions(-) (limited to 'src/modules/snd/libkvisnd.cpp') diff --git a/src/modules/snd/libkvisnd.cpp b/src/modules/snd/libkvisnd.cpp index ff0779868..a3af9bea0 100644 --- a/src/modules/snd/libkvisnd.cpp +++ b/src/modules/snd/libkvisnd.cpp @@ -37,51 +37,51 @@ #include #ifdef COMPILE_PHONON_SUPPORT - #include - #include - #include - #include +#include +#include +#include +#include #endif //!COMPILE_PHONON_SUPPORT #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) - #include +#include #else //!COMPILE_ON_WINDOWS - #include - #include - #include - - #ifdef COMPILE_ESD_SUPPORT - #include - #endif //COMPILE_ESD_SUPPORT - - #ifdef COMPILE_OSS_SUPPORT - #include - #include - #ifdef HAVE_LINUX_SOUNDCARD_H - #include - #else - // Hint by Andy Fawcett: Thnx :) - #ifdef HAVE_SYS_SOUNDCARD_H - #include - #else - #ifdef HAVE_MACHINE_SOUNDCARD_H - #include - #else - #warning "Ops.. have no soundcard.h ? ... we're going to fail here :/" - #endif - #endif - #endif - #ifdef COMPILE_AUDIOFILE_SUPPORT - #include - #endif //COMPILE_AUDIOFILE_SUPPORT - #endif //COMPILE_OSS_SUPPORT +#include +#include +#include + +#ifdef COMPILE_ESD_SUPPORT +#include +#endif //COMPILE_ESD_SUPPORT + +#ifdef COMPILE_OSS_SUPPORT +#include +#include +#ifdef HAVE_LINUX_SOUNDCARD_H +#include +#else +// Hint by Andy Fawcett: Thnx :) +#ifdef HAVE_SYS_SOUNDCARD_H +#include +#else +#ifdef HAVE_MACHINE_SOUNDCARD_H +#include +#else +#warning "Ops.. have no soundcard.h ? ... we're going to fail here :/" +#endif +#endif +#endif +#ifdef COMPILE_AUDIOFILE_SUPPORT +#include +#endif //COMPILE_AUDIOFILE_SUPPORT +#endif //COMPILE_OSS_SUPPORT #endif static KviSoundPlayer * g_pSoundPlayer = 0; KviSoundPlayer::KviSoundPlayer() -: QObject() + : QObject() { m_pThreadList = new KviPointerList; m_pThreadList->setAutoDelete(true); @@ -92,32 +92,32 @@ KviSoundPlayer::KviSoundPlayer() m_pLastUsedSoundPlayerEntry = NULL; - m_pSoundSystemDict = new KviPointerHashTable(17,false); + m_pSoundSystemDict = new KviPointerHashTable(17, false); m_pSoundSystemDict->setAutoDelete(true); #ifdef COMPILE_PHONON_SUPPORT - m_pSoundSystemDict->insert("phonon",new KviSoundPlayerEntry(KVI_PTR2MEMBER(KviSoundPlayer::playPhonon),KVI_PTR2MEMBER(KviSoundPlayer::cleanupPhonon))); + m_pSoundSystemDict->insert("phonon", new KviSoundPlayerEntry(KVI_PTR2MEMBER(KviSoundPlayer::playPhonon), KVI_PTR2MEMBER(KviSoundPlayer::cleanupPhonon))); #endif //!COMPILE_PHONON_SUPPORT #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) - m_pSoundSystemDict->insert("winmm",new KviSoundPlayerEntry(KVI_PTR2MEMBER(KviSoundPlayer::playWinmm),KVI_PTR2MEMBER(KviSoundPlayer::cleanupWinmm))); + m_pSoundSystemDict->insert("winmm", new KviSoundPlayerEntry(KVI_PTR2MEMBER(KviSoundPlayer::playWinmm), KVI_PTR2MEMBER(KviSoundPlayer::cleanupWinmm))); #else //!COMPILE_ON_WINDOWS - #ifdef COMPILE_OSS_SUPPORT - #ifdef COMPILE_AUDIOFILE_SUPPORT - m_pSoundSystemDict->insert("oss+audiofile",new KviSoundPlayerEntry(KVI_PTR2MEMBER(KviSoundPlayer::playOssAudiofile),KVI_PTR2MEMBER(KviSoundPlayer::cleanupOssAudiofile))); - #endif //COMPILE_AUDIOFILE_SUPPORT - m_pSoundSystemDict->insert("oss",new KviSoundPlayerEntry(KVI_PTR2MEMBER(KviSoundPlayer::playOss),KVI_PTR2MEMBER(KviSoundPlayer::cleanupOss))); - #endif //COMPILE_OSS_SUPPORT +#ifdef COMPILE_OSS_SUPPORT +#ifdef COMPILE_AUDIOFILE_SUPPORT + m_pSoundSystemDict->insert("oss+audiofile", new KviSoundPlayerEntry(KVI_PTR2MEMBER(KviSoundPlayer::playOssAudiofile), KVI_PTR2MEMBER(KviSoundPlayer::cleanupOssAudiofile))); +#endif //COMPILE_AUDIOFILE_SUPPORT + m_pSoundSystemDict->insert("oss", new KviSoundPlayerEntry(KVI_PTR2MEMBER(KviSoundPlayer::playOss), KVI_PTR2MEMBER(KviSoundPlayer::cleanupOss))); +#endif //COMPILE_OSS_SUPPORT - #ifdef COMPILE_ESD_SUPPORT - m_pSoundSystemDict->insert("esd",new KviSoundPlayerEntry(KVI_PTR2MEMBER(KviSoundPlayer::playEsd),KVI_PTR2MEMBER(KviSoundPlayer::cleanupEsd))); - #endif //COMPILE_ESD_SUPPORT +#ifdef COMPILE_ESD_SUPPORT + m_pSoundSystemDict->insert("esd", new KviSoundPlayerEntry(KVI_PTR2MEMBER(KviSoundPlayer::playEsd), KVI_PTR2MEMBER(KviSoundPlayer::cleanupEsd))); +#endif //COMPILE_ESD_SUPPORT #endif //!COMPILE_ON_WINDOWS - m_pSoundSystemDict->insert("qt",new KviSoundPlayerEntry(KVI_PTR2MEMBER(KviSoundPlayer::playQt),KVI_PTR2MEMBER(KviSoundPlayer::cleanupQt))); - m_pSoundSystemDict->insert("null",new KviSoundPlayerEntry(KVI_PTR2MEMBER(KviSoundPlayer::playNull),KVI_PTR2MEMBER(KviSoundPlayer::cleanupNull))); + m_pSoundSystemDict->insert("qt", new KviSoundPlayerEntry(KVI_PTR2MEMBER(KviSoundPlayer::playQt), KVI_PTR2MEMBER(KviSoundPlayer::cleanupQt))); + m_pSoundSystemDict->insert("null", new KviSoundPlayerEntry(KVI_PTR2MEMBER(KviSoundPlayer::playNull), KVI_PTR2MEMBER(KviSoundPlayer::cleanupNull))); } KviSoundPlayer::~KviSoundPlayer() @@ -162,9 +162,9 @@ void KviSoundPlayer::cleanupAfterLastPlayerEntry() m_pLastUsedSoundPlayerEntry = NULL; } -void KviSoundPlayer::getAvailableSoundSystems(QStringList *l) +void KviSoundPlayer::getAvailableSoundSystems(QStringList * l) { - KviPointerHashTableIterator it(*m_pSoundSystemDict); + KviPointerHashTableIterator it(*m_pSoundSystemDict); while(it.current()) { l->append(it.currentKey()); @@ -200,8 +200,9 @@ bool KviSoundPlayer::event(QEvent * e) if(e->type() == KVI_THREAD_EVENT) { KviThread * t = ((KviThreadEvent *)e)->sender(); - if(!t)return true; // huh ? - delete (KviSoundThread *)t; + if(!t) + return true; // huh ? + delete(KviSoundThread *)t; return true; } return QObject::event(e); @@ -222,22 +223,22 @@ void KviSoundPlayer::detectSoundSystem() #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) KVI_OPTION_STRING(KviOption_stringSoundSystem) = "winmm"; #else - #ifdef COMPILE_ESD_SUPPORT - esd_format_t format = ESD_BITS16 | ESD_STREAM | ESD_PLAY | ESD_MONO; - int esd_fd = esd_play_stream(format, 8012, NULL, "kvirc"); - if(esd_fd >= 0) - { - KVI_OPTION_STRING(KviOption_stringSoundSystem) = "esd"; - return; - } - #endif - #ifdef COMPILE_OSS_SUPPORT - #ifdef COMPILE_AUDIOFILE_SUPPORT - KVI_OPTION_STRING(KviOption_stringSoundSystem) = "oss+audiofile"; - return; - #endif - KVI_OPTION_STRING(KviOption_stringSoundSystem) = "oss"; - #endif +#ifdef COMPILE_ESD_SUPPORT + esd_format_t format = ESD_BITS16 | ESD_STREAM | ESD_PLAY | ESD_MONO; + int esd_fd = esd_play_stream(format, 8012, NULL, "kvirc"); + if(esd_fd >= 0) + { + KVI_OPTION_STRING(KviOption_stringSoundSystem) = "esd"; + return; + } +#endif +#ifdef COMPILE_OSS_SUPPORT +#ifdef COMPILE_AUDIOFILE_SUPPORT + KVI_OPTION_STRING(KviOption_stringSoundSystem) = "oss+audiofile"; + return; +#endif + KVI_OPTION_STRING(KviOption_stringSoundSystem) = "oss"; +#endif KVI_OPTION_STRING(KviOption_stringSoundSystem) = "qt"; return; @@ -245,7 +246,7 @@ void KviSoundPlayer::detectSoundSystem() } #ifdef COMPILE_PHONON_SUPPORT -bool KviSoundPlayer::playPhonon(const QString &szFileName) +bool KviSoundPlayer::playPhonon(const QString & szFileName) { if(isMuted()) return true; @@ -253,7 +254,7 @@ bool KviSoundPlayer::playPhonon(const QString &szFileName) Phonon::MediaSource media(QUrl::fromLocalFile(szFileName)); if(!m_pPhononPlayer) - m_pPhononPlayer = Phonon::createPlayer(Phonon::MusicCategory,media); + m_pPhononPlayer = Phonon::createPlayer(Phonon::MusicCategory, media); else m_pPhononPlayer->setCurrentSource(media); @@ -263,9 +264,9 @@ bool KviSoundPlayer::playPhonon(const QString &szFileName) { QString szError = m_pPhononPlayer->errorString(); if(szError.isEmpty()) - qDebug("Phonon player in error state: can't play media '%s'",szFileName.isEmpty() ? "" : szFileName.toUtf8().data()); + qDebug("Phonon player in error state: can't play media '%s'", szFileName.isEmpty() ? "" : szFileName.toUtf8().data()); else - qDebug("Phonon player in error state: %s (can't play media '%s')",szError.toUtf8().data(),szFileName.isEmpty() ? "" : szFileName.toUtf8().data()); + qDebug("Phonon player in error state: %s (can't play media '%s')", szError.toUtf8().data(), szFileName.isEmpty() ? "" : szFileName.toUtf8().data()); return false; } @@ -285,72 +286,74 @@ void KviSoundPlayer::cleanupPhonon() #endif //!COMPILE_PHONON_SUPPORT #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) - bool KviSoundPlayer::playWinmm(const QString &szFileName) - { - sndPlaySound(szFileName.toLocal8Bit().data(),SND_ASYNC | SND_NODEFAULT); +bool KviSoundPlayer::playWinmm(const QString & szFileName) +{ + sndPlaySound(szFileName.toLocal8Bit().data(), SND_ASYNC | SND_NODEFAULT); + return true; +} + +void KviSoundPlayer::cleanupWinmm() +{ + // FIXME: how to stop playing on windows ? +} +#else //!COMPILE_ON_WINDOWS +#ifdef COMPILE_OSS_SUPPORT +#ifdef COMPILE_AUDIOFILE_SUPPORT +bool KviSoundPlayer::playOssAudiofile(const QString & szFileName) +{ + if(isMuted()) return true; + KviOssAudiofileSoundThread * t = new KviOssAudiofileSoundThread(szFileName); + if(!t->start()) + { + delete t; + return false; } + return true; +} - void KviSoundPlayer::cleanupWinmm() +void KviSoundPlayer::cleanupOssAudiofile() +{ +} +#endif //COMPILE_AUDIOFILE_SUPPORT +bool KviSoundPlayer::playOss(const QString & szFileName) +{ + if(isMuted()) + return true; + KviOssSoundThread * t = new KviOssSoundThread(szFileName); + if(!t->start()) { - // FIXME: how to stop playing on windows ? + delete t; + return false; } -#else //!COMPILE_ON_WINDOWS - #ifdef COMPILE_OSS_SUPPORT - #ifdef COMPILE_AUDIOFILE_SUPPORT - bool KviSoundPlayer::playOssAudiofile(const QString &szFileName) - { - if(isMuted()) return true; - KviOssAudiofileSoundThread * t = new KviOssAudiofileSoundThread(szFileName); - if(!t->start()) - { - delete t; - return false; - } - return true; - } - - void KviSoundPlayer::cleanupOssAudiofile() - { - } - #endif //COMPILE_AUDIOFILE_SUPPORT - bool KviSoundPlayer::playOss(const QString &szFileName) - { - if(isMuted()) return true; - KviOssSoundThread * t = new KviOssSoundThread(szFileName); - if(!t->start()) - { - delete t; - return false; - } - return true; - } + return true; +} - void KviSoundPlayer::cleanupOss() - { - } - #endif //COMPILE_OSS_SUPPORT - #ifdef COMPILE_ESD_SUPPORT - bool KviSoundPlayer::playEsd(const QString &szFileName) - { - if(isMuted()) - return true; - KviEsdSoundThread * t = new KviEsdSoundThread(szFileName); - if(!t->start()) - { - delete t; - return false; - } - return true; - } +void KviSoundPlayer::cleanupOss() +{ +} +#endif //COMPILE_OSS_SUPPORT +#ifdef COMPILE_ESD_SUPPORT +bool KviSoundPlayer::playEsd(const QString & szFileName) +{ + if(isMuted()) + return true; + KviEsdSoundThread * t = new KviEsdSoundThread(szFileName); + if(!t->start()) + { + delete t; + return false; + } + return true; +} - void KviSoundPlayer::cleanupEsd() - { - } - #endif //COMPILE_ESD_SUPPORT +void KviSoundPlayer::cleanupEsd() +{ +} +#endif //COMPILE_ESD_SUPPORT #endif //!COMPILE_ON_WINDOWS -bool KviSoundPlayer::playQt(const QString &szFileName) +bool KviSoundPlayer::playQt(const QString & szFileName) { if(isMuted()) return true; @@ -374,7 +377,7 @@ void KviSoundPlayer::cleanupNull() { } -bool KviSoundPlayer::play(const QString &szFileName) +bool KviSoundPlayer::play(const QString & szFileName) { if(isMuted()) return true; @@ -384,14 +387,11 @@ bool KviSoundPlayer::play(const QString &szFileName) if(!e) { if( - (!KVI_OPTION_STRING(KviOption_stringSoundSystem).isEmpty()) && - (!KviQString::equalCI(KVI_OPTION_STRING(KviOption_stringSoundSystem),"unknown")) - ) + (!KVI_OPTION_STRING(KviOption_stringSoundSystem).isEmpty()) && (!KviQString::equalCI(KVI_OPTION_STRING(KviOption_stringSoundSystem), "unknown"))) { qDebug( - "Sound system '%s' is not valid, you may want to re-configure it in the options dialog...", - KVI_OPTION_STRING(KviOption_stringSoundSystem).toUtf8().data() - ); + "Sound system '%s' is not valid, you may want to re-configure it in the options dialog...", + KVI_OPTION_STRING(KviOption_stringSoundSystem).toUtf8().data()); return false; // detection already attempted (and failed?) } @@ -415,9 +415,8 @@ bool KviSoundPlayer::play(const QString &szFileName) return (this->*r)(szFileName); } - -KviSoundThread::KviSoundThread(const QString &szFileName) -: KviThread() +KviSoundThread::KviSoundThread(const QString & szFileName) + : KviThread() { g_pSoundPlayer->registerSoundThread(this); m_szFileName = szFileName; @@ -443,230 +442,229 @@ void KviSoundThread::run() { play(); #if !defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MINGW) - postEvent(g_pSoundPlayer,new KviThreadEvent(KVI_THREAD_EVENT_SUCCESS)); + postEvent(g_pSoundPlayer, new KviThreadEvent(KVI_THREAD_EVENT_SUCCESS)); #endif } - #if !defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MINGW) - #ifdef COMPILE_OSS_SUPPORT - #ifdef COMPILE_AUDIOFILE_SUPPORT - KviOssAudiofileSoundThread::KviOssAudiofileSoundThread(const QString &szFileName) - : KviSoundThread(szFileName) - { - } +#ifdef COMPILE_OSS_SUPPORT +#ifdef COMPILE_AUDIOFILE_SUPPORT +KviOssAudiofileSoundThread::KviOssAudiofileSoundThread(const QString & szFileName) + : KviSoundThread(szFileName) +{ +} - KviOssAudiofileSoundThread::~KviOssAudiofileSoundThread() - { - } +KviOssAudiofileSoundThread::~KviOssAudiofileSoundThread() +{ +} - void KviOssAudiofileSoundThread::play() - { - #define BUFFER_FRAMES 4096 +void KviOssAudiofileSoundThread::play() +{ +#define BUFFER_FRAMES 4096 - AFfilehandle file; - AFframecount framesRead; - int sampleFormat, sampleWidth, channelCount, format, freq; - float frameSize; - void * buffer; + AFfilehandle file; + AFframecount framesRead; + int sampleFormat, sampleWidth, channelCount, format, freq; + float frameSize; + void * buffer; - file = afOpenFile(m_szFileName.toUtf8().data(),"r",NULL); - if(!file) - { - qDebug("libaudiofile could not open the file %s",m_szFileName.toUtf8().data()); - qDebug("giving up playing sound..."); - return; // screwed up - } + file = afOpenFile(m_szFileName.toUtf8().data(), "r", NULL); + if(!file) + { + qDebug("libaudiofile could not open the file %s", m_szFileName.toUtf8().data()); + qDebug("giving up playing sound..."); + return; // screwed up + } - sampleFormat = -1; + sampleFormat = -1; - afGetVirtualSampleFormat(file, AF_DEFAULT_TRACK, &sampleFormat, &sampleWidth); + afGetVirtualSampleFormat(file, AF_DEFAULT_TRACK, &sampleFormat, &sampleWidth); - if(sampleFormat == -1) - { - qDebug("libaudiofile couldn't find the sample format for file %s",m_szFileName.toUtf8().data()); - qDebug("giving up playing sound..."); - afCloseFile(file); - return; // screwed up - } + if(sampleFormat == -1) + { + qDebug("libaudiofile couldn't find the sample format for file %s", m_szFileName.toUtf8().data()); + qDebug("giving up playing sound..."); + afCloseFile(file); + return; // screwed up + } - frameSize = afGetVirtualFrameSize(file, AF_DEFAULT_TRACK, 1); - channelCount = afGetVirtualChannels(file, AF_DEFAULT_TRACK); - buffer = KviMemory::allocate(int(BUFFER_FRAMES * frameSize)); + frameSize = afGetVirtualFrameSize(file, AF_DEFAULT_TRACK, 1); + channelCount = afGetVirtualChannels(file, AF_DEFAULT_TRACK); + buffer = KviMemory::allocate(int(BUFFER_FRAMES * frameSize)); - int audiofd_c = open("/dev/dsp", O_WRONLY /*| O_EXCL | O_NDELAY*/); + int audiofd_c = open("/dev/dsp", O_WRONLY /*| O_EXCL | O_NDELAY*/); - QFile audiofd; + QFile audiofd; - if(audiofd_c < 0) - { - qDebug("Could not open audio device /dev/dsp! [OSS+AUDIOFILE]"); - qDebug("(the device is probably busy, errno = %d)",errno); - goto exit_thread; - } + if(audiofd_c < 0) + { + qDebug("Could not open audio device /dev/dsp! [OSS+AUDIOFILE]"); + qDebug("(the device is probably busy, errno = %d)", errno); + goto exit_thread; + } - audiofd.open(audiofd_c,QIODevice::WriteOnly); // ???? what the heck is this for ? + audiofd.open(audiofd_c, QIODevice::WriteOnly); // ???? what the heck is this for ? - if (sampleWidth == 8) - format = AFMT_U8; - else if(sampleWidth == 16) - format = AFMT_S16_NE; + if(sampleWidth == 8) + format = AFMT_U8; + else if(sampleWidth == 16) + format = AFMT_S16_NE; - if(ioctl(audiofd.handle(),SNDCTL_DSP_SETFMT, &format) == -1) - { - qDebug("Could not set format width to DSP! [OSS]"); - goto exit_thread; - } + if(ioctl(audiofd.handle(), SNDCTL_DSP_SETFMT, &format) == -1) + { + qDebug("Could not set format width to DSP! [OSS]"); + goto exit_thread; + } - if (ioctl(audiofd.handle(),SNDCTL_DSP_CHANNELS, &channelCount) == -1) - { - qDebug("Could not set DSP channels! [OSS]"); - goto exit_thread; - } + if(ioctl(audiofd.handle(), SNDCTL_DSP_CHANNELS, &channelCount) == -1) + { + qDebug("Could not set DSP channels! [OSS]"); + goto exit_thread; + } - freq = (int) afGetRate(file, AF_DEFAULT_TRACK); - if (ioctl(audiofd.handle(), SNDCTL_DSP_SPEED, &freq) == -1) - { - qDebug("Could not set DSP speed %d! [OSS]",freq); - goto exit_thread; - } + freq = (int)afGetRate(file, AF_DEFAULT_TRACK); + if(ioctl(audiofd.handle(), SNDCTL_DSP_SPEED, &freq) == -1) + { + qDebug("Could not set DSP speed %d! [OSS]", freq); + goto exit_thread; + } - framesRead = afReadFrames(file, AF_DEFAULT_TRACK, buffer, BUFFER_FRAMES); + framesRead = afReadFrames(file, AF_DEFAULT_TRACK, buffer, BUFFER_FRAMES); - while(!m_bTerminate && (framesRead > 0)) - { - audiofd.write((char *)buffer,(int)(framesRead * frameSize)); - framesRead = afReadFrames(file, AF_DEFAULT_TRACK, buffer,BUFFER_FRAMES); - } + while(!m_bTerminate && (framesRead > 0)) + { + audiofd.write((char *)buffer, (int)(framesRead * frameSize)); + framesRead = afReadFrames(file, AF_DEFAULT_TRACK, buffer, BUFFER_FRAMES); + } - exit_thread: - audiofd.close(); - if(audiofd_c >= 0)close(audiofd_c); - afCloseFile(file); - KviMemory::free(buffer); - } - #endif //COMPILE_AUDIOFILE_SUPPORT +exit_thread: + audiofd.close(); + if(audiofd_c >= 0) + close(audiofd_c); + afCloseFile(file); + KviMemory::free(buffer); +} +#endif //COMPILE_AUDIOFILE_SUPPORT +KviOssSoundThread::KviOssSoundThread(const QString & szFileName) + : KviSoundThread(szFileName) +{ +} - KviOssSoundThread::KviOssSoundThread(const QString &szFileName) - : KviSoundThread(szFileName) - { - } +KviOssSoundThread::~KviOssSoundThread() +{ +} - KviOssSoundThread::~KviOssSoundThread() - { - } +void KviOssSoundThread::play() +{ +#define OSS_BUFFER_SIZE 16384 - void KviOssSoundThread::play() - { - #define OSS_BUFFER_SIZE 16384 + if(!m_szFileName.endsWith(QString(".au"))) + { + qDebug("Oss only player supports only *.au files"); + return; + } - if(!m_szFileName.endsWith(QString(".au"))) - { - qDebug("Oss only player supports only *.au files"); - return; - } + QFile f(m_szFileName); + int fd = -1; + char buf[OSS_BUFFER_SIZE]; + int iDataLen = 0; + int iSize = 0; - QFile f(m_szFileName); - int fd = -1; - char buf[OSS_BUFFER_SIZE]; - int iDataLen = 0; - int iSize = 0; + if(!f.open(QIODevice::ReadOnly)) + { + qDebug("Could not open sound file %s! [OSS]", m_szFileName.toUtf8().data()); + return; + } - if(!f.open(QIODevice::ReadOnly)) - { - qDebug("Could not open sound file %s! [OSS]",m_szFileName.toUtf8().data()); - return; - } + iSize = f.size(); - iSize = f.size(); + if(iSize < 24) + { + qDebug("Could not play sound, file %s too small! [OSS]", m_szFileName.toUtf8().data()); + goto exit_thread; + } - if(iSize < 24) - { - qDebug("Could not play sound, file %s too small! [OSS]",m_szFileName.toUtf8().data()); - goto exit_thread; - } + if(f.read(buf, 24) < 24) + { + qDebug("Error while reading the sound file header (%s)! [OSS]", m_szFileName.toUtf8().data()); + goto exit_thread; + } - if(f.read(buf,24) < 24) - { - qDebug("Error while reading the sound file header (%s)! [OSS]",m_szFileName.toUtf8().data()); - goto exit_thread; - } + iSize -= 24; - iSize -= 24; + fd = open("/dev/audio", O_WRONLY /* | O_EXCL | O_NDELAY*/); + if(fd < 0) + { + qDebug("Could not open device file /dev/audio!"); + qDebug("Maybe other program is using the device? Hint: fuser -uv /dev/audio"); + goto exit_thread; + } - fd = open("/dev/audio", O_WRONLY /* | O_EXCL | O_NDELAY*/); - if(fd < 0) + while(!m_bTerminate && (iSize > 0)) + { + int iCanRead = OSS_BUFFER_SIZE - iDataLen; + if(iCanRead > 0) + { + int iToRead = iSize > iCanRead ? iCanRead : iSize; + int iReaded = f.read(buf + iDataLen, iToRead); + if(iReaded < 1) { - qDebug("Could not open device file /dev/audio!"); - qDebug("Maybe other program is using the device? Hint: fuser -uv /dev/audio"); + qDebug("Error while reading the file data (%s)! [OSS]", m_szFileName.toUtf8().data()); goto exit_thread; } - - - while(!m_bTerminate && (iSize > 0)) + iSize -= iReaded; + iDataLen += iReaded; + } + if(iDataLen > 0) + { + int iWritten = write(fd, buf, iDataLen); + if(iWritten < 0) { - int iCanRead = OSS_BUFFER_SIZE - iDataLen; - if(iCanRead > 0) - { - int iToRead = iSize > iCanRead ? iCanRead : iSize; - int iReaded = f.read(buf + iDataLen,iToRead); - if(iReaded < 1) - { - qDebug("Error while reading the file data (%s)! [OSS]",m_szFileName.toUtf8().data()); - goto exit_thread; - } - iSize -= iReaded; - iDataLen += iReaded; - } - if(iDataLen > 0) + if((errno != EINTR) && (errno != EAGAIN)) { - int iWritten = write(fd,buf,iDataLen); - if(iWritten < 0) - { - if((errno != EINTR) && (errno != EAGAIN)) - { - qDebug("Error while writing the audio data (%s)! [OSS]",m_szFileName.toUtf8().data()); - goto exit_thread; - } - } - iDataLen -= iWritten; - } else { - // nothing to write ???? + qDebug("Error while writing the audio data (%s)! [OSS]", m_szFileName.toUtf8().data()); goto exit_thread; } } - - exit_thread: - f.close(); - if(fd > 0)close(fd); + iDataLen -= iWritten; + } + else + { + // nothing to write ???? + goto exit_thread; } + } +exit_thread: + f.close(); + if(fd > 0) + close(fd); +} - #endif //COMPILE_OSS_SUPPORT +#endif //COMPILE_OSS_SUPPORT - #ifdef COMPILE_ESD_SUPPORT +#ifdef COMPILE_ESD_SUPPORT - KviEsdSoundThread::KviEsdSoundThread(const QString &szFileName) - : KviSoundThread(szFileName) - { - } +KviEsdSoundThread::KviEsdSoundThread(const QString & szFileName) + : KviSoundThread(szFileName) +{ +} - KviEsdSoundThread::~KviEsdSoundThread() - { - } +KviEsdSoundThread::~KviEsdSoundThread() +{ +} - void KviEsdSoundThread::play() - { - // ESD has a really nice API - if(!esd_play_file(NULL,m_szFileName.toUtf8().data(),1)) // this is sync.. FIXME: it can't be stopped! - qDebug("Could not play sound %s! [ESD]",m_szFileName.toUtf8().data()); - } +void KviEsdSoundThread::play() +{ + // ESD has a really nice API + if(!esd_play_file(NULL, m_szFileName.toUtf8().data(), 1)) // this is sync.. FIXME: it can't be stopped! + qDebug("Could not play sound %s! [ESD]", m_szFileName.toUtf8().data()); +} - #endif //COMPILE_ESD_SUPPORT +#endif //COMPILE_ESD_SUPPORT #endif //!COMPILE_ON_WINDOWS - /* @doc: snd.play @type: @@ -695,19 +693,19 @@ static bool snd_kvs_cmd_play(KviKvsModuleCommandCall * c) { QString szFile; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("file name",KVS_PT_STRING,0,szFile) + KVSM_PARAMETER("file name", KVS_PT_STRING, 0, szFile) KVSM_PARAMETERS_END(c) if(szFile.isEmpty() || (!KviFileUtils::fileExists(szFile))) { - if(!c->hasSwitch('q',"quiet")) - c->warning(__tr2qs("Sound file '%Q' not found"),&szFile); + if(!c->hasSwitch('q', "quiet")) + c->warning(__tr2qs("Sound file '%Q' not found"), &szFile); return true; } if(!g_pSoundPlayer->play(szFile)) { - if(!c->hasSwitch('q',"quiet")) - c->warning(__tr2qs("Unable to play sound '%Q'"),&szFile); + if(!c->hasSwitch('q', "quiet")) + c->warning(__tr2qs("Unable to play sound '%Q'"), &szFile); } return true; @@ -716,16 +714,17 @@ static bool snd_kvs_cmd_play(KviKvsModuleCommandCall * c) static bool snd_kvs_cmd_autodetect(KviKvsModuleCommandCall * c) { g_pSoundPlayer->detectSoundSystem(); - if(KviQString::equalCI(KVI_OPTION_STRING(KviOption_stringSoundSystem),"null")) + if(KviQString::equalCI(KVI_OPTION_STRING(KviOption_stringSoundSystem), "null")) { - c->window()->outputNoFmt(KVI_OUT_SYSTEMERROR,__tr2qs("Sorry, I can't find a sound system to use on this machine")); - } else { - c->window()->output(KVI_OUT_SYSTEMMESSAGE,__tr2qs("Sound system detected to: %s"),KVI_OPTION_STRING(KviOption_stringSoundSystem).toUtf8().data()); + c->window()->outputNoFmt(KVI_OUT_SYSTEMERROR, __tr2qs("Sorry, I can't find a sound system to use on this machine")); + } + else + { + c->window()->output(KVI_OUT_SYSTEMMESSAGE, __tr2qs("Sound system detected to: %s"), KVI_OPTION_STRING(KviOption_stringSoundSystem).toUtf8().data()); } return true; } - /* @doc: snd.mute @type: @@ -784,7 +783,6 @@ static bool snd_kvs_cmd_unmute(KviKvsModuleCommandCall * c) Returns if the sounds muted */ - static bool snd_kvs_fnc_ismuted(KviKvsModuleFunctionCall * c) { c->returnValue()->setBoolean(g_pSoundPlayer->isMuted()); @@ -795,12 +793,12 @@ static bool snd_module_init(KviModule * m) { g_pSoundPlayer = new KviSoundPlayer(); - KVSM_REGISTER_SIMPLE_COMMAND(m,"autodetect",snd_kvs_cmd_autodetect); - KVSM_REGISTER_SIMPLE_COMMAND(m,"play",snd_kvs_cmd_play); - KVSM_REGISTER_SIMPLE_COMMAND(m,"mute",snd_kvs_cmd_mute); - KVSM_REGISTER_SIMPLE_COMMAND(m,"unmute",snd_kvs_cmd_unmute); + KVSM_REGISTER_SIMPLE_COMMAND(m, "autodetect", snd_kvs_cmd_autodetect); + KVSM_REGISTER_SIMPLE_COMMAND(m, "play", snd_kvs_cmd_play); + KVSM_REGISTER_SIMPLE_COMMAND(m, "mute", snd_kvs_cmd_mute); + KVSM_REGISTER_SIMPLE_COMMAND(m, "unmute", snd_kvs_cmd_unmute); - KVSM_REGISTER_FUNCTION(m,"isMuted",snd_kvs_fnc_ismuted); + KVSM_REGISTER_FUNCTION(m, "isMuted", snd_kvs_fnc_ismuted); return true; } @@ -817,21 +815,21 @@ static bool snd_module_can_unload(KviModule *) return !(g_pSoundPlayer->havePlayingSounds()); } -static bool snd_module_ctrl(KviModule *,const char * operation,void * param) +static bool snd_module_ctrl(KviModule *, const char * operation, void * param) { - if(kvi_strEqualCI(operation,"getAvailableSoundSystems")) + if(kvi_strEqualCI(operation, "getAvailableSoundSystems")) { // we expect param to be a pointer to QStringList - QStringList *l=(QStringList *)param; + QStringList * l = (QStringList *)param; g_pSoundPlayer->getAvailableSoundSystems(l); return true; } - if(kvi_strEqualCI(operation,"detectSoundSystem")) + if(kvi_strEqualCI(operation, "detectSoundSystem")) { g_pSoundPlayer->detectSoundSystem(); return true; } - if(kvi_strEqualCI(operation,"play")) + if(kvi_strEqualCI(operation, "play")) { QString * pszFileName = (QString *)param; if(pszFileName) @@ -841,16 +839,14 @@ static bool snd_module_ctrl(KviModule *,const char * operation,void * param) return false; } - KVIRC_MODULE( - "Sound", // module name - "4.0.0", // module version - "(C) 2002 Szymon Stefanek (pragma at kvirc dot net)," \ - "Juanjo Alvarez (juanjux at yahoo dot es)", // author & (C) - "Sound playing commands", - snd_module_init, - snd_module_can_unload, - snd_module_ctrl, - snd_module_cleanup, - 0 -) + "Sound", // module name + "4.0.0", // module version + "(C) 2002 Szymon Stefanek (pragma at kvirc dot net)," + "Juanjo Alvarez (juanjux at yahoo dot es)", // author & (C) + "Sound playing commands", + snd_module_init, + snd_module_can_unload, + snd_module_ctrl, + snd_module_cleanup, + 0) -- cgit v1.3.1-10-gc9f91