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/audioIO_SunOS.cpp | 167 +++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 mpeglib/lib/util/audio/audioIO_SunOS.cpp (limited to 'mpeglib/lib/util/audio/audioIO_SunOS.cpp') diff --git a/mpeglib/lib/util/audio/audioIO_SunOS.cpp b/mpeglib/lib/util/audio/audioIO_SunOS.cpp new file mode 100644 index 00000000..4e9958a1 --- /dev/null +++ b/mpeglib/lib/util/audio/audioIO_SunOS.cpp @@ -0,0 +1,167 @@ +/* this file is a part of amp software, (C) tomislav uzelac 1996,1997 + + Origional code by: tomislav uzelac + Modified by: + * Andrew Richards - moved code from audio.c + * Jim Crumley - ported some code from other audioIO_'s + + */ + +#include +#include +#include +#include +#include +#include +#include "audioIO.h" +#include + +/* declare these static to effectively isolate the audio device */ + +static int audio_fd; +static audio_info_t auinfo; + + +int audioConstruct(){ + audio_fd=-1; + return true; +} + +void audioDestruct() { + +} + + +/* audioOpen() */ +/* should open the audio device and perform any special initialization */ +/* returns the file descriptior of the audio device */ + +int audioOpen() { + AUDIO_INITINFO(&auinfo); + + if ((audio_fd = open("/dev/audio",O_RDWR))==-1) { + perror("unable to open the audio device"); + } + // Ok here something important if your programm forks: + if (audio_fd > 0) { + if (fcntl(audio_fd,F_SETFD,true) < 0) { + perror("fcntl socket");exit(1); + } + } + + DB(audio, msg("Audio device opened on %d\n",audio_fd) ); + return (audio_fd > 0); +} + +/* audioFlush() */ +/* should flush the audio device */ + +inline void audioFlush() { + DB(audio, msg("audio: flush %d\n",audio_fd) ); +} + + +/* audioClose() */ +/* should close the audio device and perform any special shutdown */ + +void audioClose() { + close(audio_fd); +} + + +/** + Audio init assumes that the audiodevice is open. It initializes + it to the given values +*/ + +void audioInit(int sampleSize ,int frequency, int stereo,int sign, int big){ + + if (ioctl(audio_fd,AUDIO_GETINFO,&auinfo)<0) + perror("Unable to get audio info"); + + auinfo.play.precision=sampleSize; + auinfo.play.encoding=AUDIO_ENCODING_LINEAR; + auinfo.play.channels=(stereo ? 2 : 1); + DB(audio, msg("setting sample rate to %d Hz",frequency) ); + auinfo.play.sample_rate=frequency; + if (ioctl(audio_fd,AUDIO_SETINFO,&auinfo)<0) + perror("Unable to set audio info"); + +} + +/* + only code this if your system can change the volume while + playing +*/ + + +int getAudioBufferSize() { + int buf; + if (ioctl(audio_fd,AUDIO_GETINFO,&auinfo) == -1) { + perror("ioctl getAudioBufferSize using default"); + buf=1024*65; + } else { + buf=auinfo.play.buffer_size; + } + return buf; +} + + +void mixerSetVolume(int leftVolume,int rightVolume) { + int volume; + + volume=(leftVolume+rightVolume)/2; + auinfo.play.gain=(volume*255)/100; + + // now normalize to values 0...32 + leftVolume=(32*leftVolume)/100; + rightVolume=(32*rightVolume)/100; + + // eg : leftVolume=32, rightVolume=32 => balance=32 + // eg : leftVolume=0, rightVolume=32 => balance=64 + // eg : leftVolume=32, rightVolume=0 => balance=0 + + //cout << "leftVolume:"<