File Conversion

CMdaAudioConvertUtility shares many of the calls of CMda-AudioRecorderUtility. They both derive from CMdaAudioClip-Utility, although the reasoning for the common base class is now not very clear. The two classes cover very different use cases - CMdaAudioConvertUtility is typically used to copy from one file to another, with some format conversion action. It is different from the other APIs in this section in that it does not involve using the microphone or the speaker.

Because of their shared base class, using CMdaAudioConvertUtility is very similar to using CMdaAudioRecorderUtility. Opening looks like:

void

CConvertAudio:

:ConvertL(const TDesC& aFromFileName, const TDesC& aToFileName)

iUtility->OpenL(aFromFileName, aToFileName); }

Again, the suffix for the filename is the main way of selecting the format - if you state that the output is c: \temp.wav, then the file will be a WAV file.

Because it shares many API features with CMdaAudioRecorder-Utility, the client code that drives this class is again based on MoscoStateChangeEvent callbacks, with very similar parameters. This example is typical:

void CConvertAudio::MoscoStateChangeEvent(CBase* aObject,

Tint aPreviousState, Tint aCurrentState, Tint aErrorCode)

_ASSERT_DEBUG(aObject == iUtility, User::Invariant());

aObject = aObject; // to stop warning Tint error = aErrorCode;

if (aPreviousState == CMdaAudioConvertUtility::ENotReady && aCurrentState == CMdaAudioConvertUtility::EOpen)

// have opened the file

else if (aPreviousState == CMdaAudioConvertUtility::EPlaying && aCurrentState == CMdaAudioConvertUtility::EOpen)

// normal termination iObserver->ConvertComplete(KErrNone);

// stop now iObserver->ConvertComplete(aErrorCode);

The structure is very similar to that of the recorder. We'll assume you have read Section 5.4 and look at the bit that differs - OnOpenL(). Again this is virtually the same as for recording, for example:

void CConvertAudio::OnOpenL()

// let's convert to 16-bit PCM

iUtility->SetDestinationDataiypeL(KMMFFourCCCodePCM16);

iUtility->ConvertL();

In this example, we explicitly try to request 16-bit PCM. If this is not supported, we treat it as a fatal error. Again, as with recording, we could decide to ignore the error, say, and just use the default. However, the requirements for conversion are often different - this is often used when sending a file to another end user to ensure that a known, 'common' file format is used. In that case, we usually want to be fussy about the format and treat problems as an error. As with recording, if you want to override the sample rate, the mono-stereo setting, etc. from the default, do it before you call ConvertL(). The calls are very similar.

You can use conversion sequences to append to an existing file as well as copying. If you want to ensure you are making a copy, delete the file first:

iFs.Delete(iToFileName); // Ignore errors

If you want to use the append functionality, be careful about setting data types, sample rates, etc. As with recording, it is best not to do this when you are appending, as the values are read from the existing file.

You can use a play window to convert only a portion of the original. If you only want part of the file, a play window is preferred to using CropL() or CropFromTheBeginningL() to remove part of the output - generating a file and then removing some of it is less efficient.

Conversion potentially uses different sets of plug-ins to playing or recording - don't assume that, just because you can play format A and record format B, you can convert from format A to format B.

0 0

Post a comment

  • Receive news updates via email from this site