Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

audiodrv_epoc.cpp

Go to the documentation of this file.
00001 // AUDIODRV.CPP
00002 //
00003 // (c) 2000 Alfred E. Heggestad
00004 //
00005 // This file is based on the Linux version of 'audiodrv.cpp' by Michael Schwendt
00006 //
00007 
00015 #include "audiodrv_epoc.h"
00016 #include "alaw.h"
00017 
00018 const TInt KDefaultBufSize = 8000; //TODO: determine size
00019 
00020 
00021 audioDriver::audioDriver()
00025         :audioHd(-1)
00026         ,frequency(0)
00027         ,encoding(0)
00028         ,precision(0)
00029         ,channels(0)
00030         {
00031         CTOR(audioDriver);
00032 
00033         // Reset everything.
00034         errorString = "None";
00035 #ifndef __ER6__
00036         iAlawBuffer = HBufC8::NewL(KDefaultBufSize);
00037 #endif
00038         }
00039 
00040 
00041 audioDriver::~audioDriver()
00045         {
00046         DTOR(audioDriver);
00047 #ifndef __ER6__
00048         delete iAlawBuffer;
00049 #endif
00050         }
00051 
00052 
00053 bool audioDriver::IsThere()
00059         {
00060 
00061         TInt ret = iDevSound.Open();
00062         if(ret == KErrNone)
00063                 {
00064                 iDevSound.Close();
00065                 return true;
00066                 }
00067         return false;
00068 
00069         }
00070 
00071 
00072 bool audioDriver::Open(udword inFreq, int inPrecision, int inChannels,
00073                                            int inFragments, int inFragBase)
00084         {
00085         TInt ret = iDevSound.Open();
00086 
00087         if ( ret != KErrNone )
00088                 {
00089                 errorString = "AUDIO: Could not open audio device.";
00090                 return false;
00091                 }
00092 
00093         audioHd = KErrNone; // means OK and opened
00094 
00095         // Transfer input parameters to this object.
00096         // May later be replaced with driver defaults.
00097         frequency = inFreq;
00098         precision = inPrecision;
00099         channels = inChannels;
00100         fragments = inFragments;
00101         fragSizeBase = inFragBase;
00102 
00103         // Set sample precision and type of encoding. (only 8 bit for EPOC)
00104 //      int dsp_sampleSize = 8;
00105 #ifdef __ER6__
00106         if (precision != SIDEMU_8BIT && precision != SIDEMU_16BIT )
00107 #else
00108         if (precision != SIDEMU_8BIT)
00109 #endif
00110                 {
00111                 errorString = "AUDIO: Could not set sample size.(only 8 bit for EPOC)";
00112                 return false;
00113                 }
00114 
00115 //      precision = SIDEMU_8BIT;
00116         encoding = SIDEMU_UNSIGNED_PCM;
00117 
00118         if (channels != SIDEMU_MONO)
00119                 {
00120                 errorString = "AUDIO: only Mono supported for EPOC.";
00121                 return false;
00122                 }
00123 
00124         // Set mono/stereo.
00125         int dsp_stereo;
00126         if (channels == SIDEMU_STEREO)
00127                 dsp_stereo = 1;
00128         else if (channels == SIDEMU_MONO)
00129                 dsp_stereo = 0;
00130         else
00131                 {
00132                 errorString = "AUDIO: Could not set mono/stereo.";
00133                 return false;
00134                 }
00135 
00136         // Verify and accept the number of channels the driver accepted.
00137         if (dsp_stereo == 1)
00138                 channels = SIDEMU_STEREO;
00139         else if (dsp_stereo == 0)
00140                 channels = SIDEMU_MONO;
00141         else
00142                 {
00143                 errorString = "AUDIO: Could not set mono/stereo.";
00144                 return false;
00145                 }
00146 
00147         // Set frequency.
00148 #ifdef __ER6__
00149 
00150         RMdaDevSound::TSoundFormatsSupportedBuf formats;
00151         iDevSound.PlayFormatsSupported(formats);
00152 
00153         _ELOG_P1(_L8("RMdaDevSound - formats:\n"));
00154         _ELOG_P2(_L8("  iMinRate       = %d\n"), formats().iMinRate);
00155         _ELOG_P2(_L8("  iMaxRate       = %d\n"), formats().iMaxRate);
00156         _ELOG_P2(_L8("  iEncodings     = 0x%08x\n"), formats().iEncodings);
00157         _ELOG_P2(_L8("  iChannels      = %d\n"), formats().iChannels);
00158         _ELOG_P2(_L8("  iMinBufferSize = %d\n"), formats().iMinBufferSize);
00159         _ELOG_P2(_L8("  iMaxBufferSize = %d\n"), formats().iMaxBufferSize);
00160         _ELOG_P2(_L8("  iMinVolume     = %d\n"), formats().iMinVolume);
00161         _ELOG_P2(_L8("  iMaxVolume     = %d\n"), formats().iMaxVolume);
00162 
00163         RMdaDevSound::TCurrentSoundFormatBuf format;
00164         format().iRate = frequency;
00165         if(precision==SIDEMU_8BIT)
00166                 format().iEncoding = RMdaDevSound::EMdaSoundEncoding8BitPCM;
00167         else if(precision==SIDEMU_8BIT)
00168                 format().iEncoding = RMdaDevSound::EMdaSoundEncoding16BitPCM;
00169         else
00170                 {
00171                 errorString = "AUDIO: unsupported encoding precision [precision]\n";
00172                 _ELOG_P2(_L8("%s\n"), errorString);
00173                 return false;
00174                 }
00175 
00176         format().iChannels = channels;
00177         format().iBufferSize = 0x8000;
00178         if(iDevSound.SetPlayFormat(format) != KErrNone)
00179                 {
00180                 errorString = "AUDIO: could not set config\n";
00181                 _ELOG_P2(_L8("AUDIO: Warning! Could not set config due to [%d]\n"), ret);
00182                 return false;
00183                 }
00184 
00185         blockSize = format().iBufferSize / 2;
00186         fragments = 2; //TODO: find a value for this
00187 
00188 #else
00189         if (frequency != KAlawSamplesPerSecond)
00190                 {
00191                 errorString = "AUDIO: only frequency 8000 Hz supported for EPOC ER5.";
00192                 return false;
00193                 }
00194 
00195         //
00196         // get sound device capabilites
00197         //
00198         TSoundCaps sndCaps;
00199         iDevSound.Caps(sndCaps);
00200 
00201         _ELOG_P1(_L8("RDevSound - caps:\n"));
00202         _ELOG_P2(_L8("  iService      = 0x%08x\n"), sndCaps().iService);
00203         _ELOG_P2(_L8("  iVolume       = 0x%08x\n"), sndCaps().iVolume);
00204         _ELOG_P2(_L8("  iMaxVolume    = 0x%08x\n"), sndCaps().iMaxVolume);
00205         _ELOG_P2(_L8("  iMaxFrequency = 0x%08x\n"), sndCaps().iMaxFrequency);
00206 
00207 
00208         //
00209         // configure sound device
00210         //
00211         TSoundConfig sndConfig;
00212         iDevSound.Config(sndConfig); // read the default config
00213 
00214         sndConfig().iVolume = EVolumeByValue;
00215         sndConfig().iVolumeValue = sndCaps().iMaxVolume;
00216         sndConfig().iAlawBufferSize = KDefaultBufSize;
00217 
00218         ret = iDevSound.SetConfig(sndConfig); // read the default config
00219         if(ret != KErrNone)
00220                 {
00221                 errorString = "AUDIO: could not set config\n";
00222                 _ELOG_P2(_L8("AUDIO: Warning! Could not set config due to [%d]\n"), ret);
00223                 return false;
00224                 }
00225 
00226         _ELOG_P2(_L8("AUDIO: iVolume         %d \n"), sndConfig().iVolume );
00227         _ELOG_P2(_L8("       iAlawBufferSize %d \n"), sndConfig().iAlawBufferSize );
00228 
00229         blockSize = KDefaultBufSize / 2;
00230         fragments = 2; //TODO: find a value for this
00231 
00232 #endif // __ER6__
00233 
00234 
00235 #ifndef __ER6__
00236         // prepare the buffer
00237         ret = iDevSound.PreparePlayAlawBuffer(); // This *must* be done before reading the Buffer size!!!
00238         if(ret != KErrNone)
00239                 {
00240                 errorString = "AUDIO: could not prepare alaw buffer\n";
00241                 _ELOG_P2(_L8("AUDIO: Warning! could not prepare alaw buffer due to [%d]\n"), ret);
00242                 return false;
00243                 }
00244 #endif
00245 
00246         return true; // success !
00247         }
00248 
00249 
00250 void audioDriver::Close()
00255         {
00256         if (audioHd != (-1))
00257                 {
00258                 iDevSound.Close();
00259                 audioHd = (-1);
00260                 }
00261         }
00262 
00263 void audioDriver::Play(ubyte* pBuffer, int bufferSize)
00273         {
00274         if (audioHd != (-1))
00275                 {
00276 
00277                 TRequestStatus stat;
00278 
00279 #ifdef __ER6__
00280 
00281                 TPtrC8 ptr(pBuffer, bufferSize);
00282                 iDevSound.PlayData(stat, ptr);
00283 
00284 #else
00285                 //
00286                 // convert from linear PCM to aLaw first
00287                 //
00288                 TPtr8 alawPtr = iAlawBuffer->Des();
00289                 alawPtr.SetLength(bufferSize);
00290                 Alaw::conv_u8bit_alaw(pBuffer, &alawPtr[0], bufferSize);
00291 
00292                 //
00293                 // and then play the alaw buffer
00294                 //
00295                 iDevSound.PlayAlawData(stat, alawPtr);
00296 
00297 #endif // __ER6__
00298 
00299                 User::WaitForRequest(stat);
00300                 TInt ret = stat.Int();
00301                 if(ret != KErrNone)
00302                         {
00303                         _ELOG_P2(_L8("AUDIO: Warning! could not play due to %d\n"), ret);
00304                         User::After(1000000);
00305                         }
00306 
00307                 }
00308 
00309         }
00310 
00311 
00312 TInt audioDriver::VolumeDelta(TInt aDelta)
00316         {
00317 #ifdef __ER6__
00318         RMdaDevSound::TSoundFormatsSupportedBuf formats;
00319         iDevSound.PlayFormatsSupported(formats);
00320         const TInt min = formats().iMinVolume;
00321         const TInt max = formats().iMaxVolume;
00322         const TInt steps = (max - min) / 16;
00323 
00324         const TInt new_volume = iDevSound.PlayVolume() + (aDelta*steps);
00325         if(new_volume > max)
00326                 iDevSound.SetPlayVolume(max);
00327         else if(new_volume < min)
00328                 iDevSound.SetPlayVolume(min);
00329         else
00330                 iDevSound.SetPlayVolume(new_volume);
00331         return iDevSound.PlayVolume();
00332 #else
00333         TSoundConfig sndConfig;
00334         iDevSound.Config(sndConfig); // read the default config
00335         sndConfig().iVolumeValue += aDelta;
00336         const TInt ret = iDevSound.SetConfig(sndConfig); // read the default config
00337         if(ret != KErrNone)
00338                 {
00339                 _ELOG_P2(_L8("AUDIO: Warning! could not set config due to %d\n"), ret);
00340                 }
00341         iDevSound.Config(sndConfig); // read the default config again
00342         return sndConfig().iVolumeValue;
00343 #endif // __ER6__
00344         }
00345 
00346 
00347 // EOF - AUDIODRV.CPP

Generated on Tue Feb 8 04:13:56 2005 for Esidplay by doxygen 1.3.3