Anybody used the AudioConvertUtility. Will it work?
| Mon, 2003-06-09 09:11 | |
|
Hi,
I am struggling for last one week on this problem. After successfully calling OpenL() the output descriptor's size is 0. Why? It is not converting or I have to call some other method? I am attaching the code for it. Thanks and Regards, Venkat // TInputStream.cpp // // Copyright (c) 2003 Symbian Ltd. All rights reserved. // #include <f32file.h> #include <barsread.h> #include <eikbtpan.h> #include <eikcmbut.h> #include <eiklabel.h> #include <eikmover.h> #include <eikbtgpc.h> #include <eikon.hrh> #include <eikon.rsg> #include "TInputStream.h" #include <MdaAudioSampleEditor.h> const TInt KBufferSize = 16000; _LIT(KRecorderFile, "C:\\System\\Apps\\record.wav"); RFs fs; RFile file; // // CTInputStreamAppView // CTInputStreamAppView::CTInputStreamAppView(): CCoeControl() {} CTInputStreamAppView::~CTInputStreamAppView() { delete iBitmapGc; delete iBitmapDev; delete iBitmap; } void CTInputStreamAppView::ConstructL(const TRect& aRect) { CreateWindowL(); SetRect(aRect); ActivateL(); const CFont* font = ControlEnv()->NormalFont(); iFontHeight = font->HeightInPixels(); iFontAscent = font->AscentInPixels(); iBitmap = new(ELeave) CFbsBitmap; User::LeaveIfError(iBitmap->Create(aRect.Size(),Window().DisplayMode())); iBitmapDev = CFbsBitmapDevice::NewL(iBitmap); iBitmapDev->CreateContext(iBitmapGc); iBitmapGc->UseFont(font); iBitmapGc->SetBrushStyle(CGraphicsContext::ESolidBrush); iBitmapGc->SetBrushColor(KRgbWhite); iBitmapGc->Clear(); } void CTInputStreamAppView::AddMessage(const TDesC& aMessage) { iBitmapGc->CopyRect(TPoint(0,-iFontHeight),Rect()); const TRect messageRect(0,Rect().iBr.iY - iFontHeight,Rect().iBr.iX,Rect().iBr.iY); iBitmapGc->DrawText(aMessage,messageRect,iFontAscent); Window().Invalidate(); } void CTInputStreamAppView:raw(const TRect& aRect) const { CWindowGc& gc = SystemGc(); gc.BitBlt(aRect.iTl,iBitmap,aRect); } // // CTInputStreamAppUi // CTInputStreamAppUi::~CTInputStreamAppUi() { delete iInput; delete iOutput; iBuffer.ResetAndDestroy(); if (iAppView) { RemoveFromStack(iAppView); delete iAppView; } if(iConverter) delete iConverter; } void CTInputStreamAppUi::ConstructL() { BaseConstructL(); iAppView = new(ELeave) CTInputStreamAppView; iAppView->ConstructL(ClientRect()); AddToStackL(iAppView); iSettings.iChannels = TMdaAudioDataSettings::EChannelsMono; iSettings.iSampleRate= TMdaAudioDataSettings::ESampleRate8000Hz; iInput = CMdaAudioInputStream::NewL(*this); iInput->Open(&iSettings); iOutput = CMdaAudioOutputStream::NewL(*this); iOutput->Open(&iSettings); iConverter = new (ELeave) log_test; iConverter->ConstructL(); TDes8* buffer = new(ELeave) TBuf8<KBufferSize>; buffer->SetMax(); CleanupStack::PushL(buffer); User::LeaveIfError(iBuffer.Append(buffer)); CleanupStack::Pop(buffer); buffer = new(ELeave) TBuf8<KBufferSize>; buffer->SetMax(); CleanupStack::PushL(buffer); User::LeaveIfError(iBuffer.Append(buffer)); CleanupStack::Pop(buffer); buffer = new(ELeave) TBuf8<KBufferSize>; buffer->SetMax(); CleanupStack::PushL(buffer); User::LeaveIfError(iBuffer.Append(buffer)); CleanupStack::Pop(buffer); } void CTInputStreamAppUi::HandleCommandL(TInt aCommand) { switch (aCommand) { case ETInputStreamCmdRecord: RecordL(); break; case ETInputStreamCmdPlay: PlayL(); break; case EAknSoftkeyBack: CEikAppUi::Exit(); break; } } void CTInputStreamAppUi::MaiscOpenComplete(TInt aError) { if (aError != KErrNone) { TBuf<32> buf(_L("Input err ")); buf.AppendNum(aError); iAppView->AddMessage(buf); } OpenCompleteL(aError); } void CTInputStreamAppUi::MaiscBufferCopied(TInt aError, const TDesC8& aBuffer) { TDes8* buffer = new(ELeave) TBuf8<KBufferSize>; buffer->Trim(); //buffer->Append('v'); TBuf<32> buf(_L("Buf ")); if (&aBuffer == iBuffer[0]) buf.AppendNum(1); else if (&aBuffer == iBuffer[1]) buf.AppendNum(2); else if (&aBuffer == iBuffer[2]) { buf.AppendNum(3); iState = EOpen; } buf.Append(_L(" full, err ")); buf.AppendNum(aError); iAppView->AddMessage(buf); iConverter->BufferWriteL(aBuffer,*buffer); User::LeaveIfError(aError); } void CTInputStreamAppUi::MaiscRecordComplete(TInt aError) { iState = EOpen; TBuf<32> buf(_L("Record complete, err ")); file.Flush(); file.Close(); fs.Close(); iAppView->AddMessage(_L("File Closed")); buf.AppendNum(aError); iAppView->AddMessage(buf); User::LeaveIfError(aError); } void CTInputStreamAppUi::MaoscOpenComplete(TInt aError) { if (aError != KErrNone) { TBuf<32> buf(_L("Output err ")); buf.AppendNum(aError); iAppView->AddMessage(buf); } OpenCompleteL(aError); } void CTInputStreamAppUi::MaoscBufferCopied(TInt aError, const TDesC8& aBuffer) { TBuf<32> buf(_L("Buf ")); if (&aBuffer == iBuffer[0]) buf.AppendNum(1); else if (&aBuffer == iBuffer[1]) buf.AppendNum(2); else if (&aBuffer == iBuffer[2]) buf.AppendNum(3); buf.Append(_L(" played, err ")); buf.AppendNum(aError); iAppView->AddMessage(buf); User::LeaveIfError(aError); } void CTInputStreamAppUi::MaoscPlayComplete(TInt aError) { iState = EOpen; if (aError == KErrUnderflow) aError = KErrNone; TBuf<32> buf(_L("Play complete, err ")); buf.AppendNum(aError); iAppView->AddMessage(buf); User::LeaveIfError(aError); } void CTInputStreamAppUi::OpenCompleteL(TInt aError) { User::LeaveIfError(aError); if (iState == EClosed) { iState = EFirstOpenSuccessful; } else { iState = EOpen; iAppView->AddMessage(_L("Ready")); iInput->SetGain(iInput->MaxGain()); iOutput->SetVolume(iOutput->MaxVolume() / 2); } } void CTInputStreamAppUi::RecordL() { User::LeaveIfError(fs.Connect()); //CleanupClosePushL(file); file.Replace(fs,KRecorderFile, EFileShareAny | EFileStream | EFileWrite); if (iState != EOpen) User::Leave(KErrNotReady); iState = ERecording; iAppView->AddMessage(_L("File Opened")); for (TInt index = 0; index < iBuffer.Count(); index++) { iInput->ReadL(*iBuffer[index]); } } void CTInputStreamAppUi::PlayL() { if (iState != EOpen) User::Leave(KErrNotReady); iState = EPlaying; for (TInt index = 0; index < iBuffer.Count(); index++) { iOutput->WriteL(*iBuffer[index]); } } // // CTInputStreamApp // TUid CTInputStreamApp::AppDllUid() const { return KUidMdaAudioInputStreamingTestApp; } CApaDocument* CTInputStreamApp::CreateDocumentL() { return new(ELeave) CTInputStreamDocument(*this); } // // CTInputStreamDocument // CTInputStreamDocument::CTInputStreamDocument(CEikApplication& aApp) : CAknDocument(aApp) {} CEikAppUi* CTInputStreamDocument::CreateAppUiL() { return new (ELeave) CTInputStreamAppUi; } EXPORT_C CApaApplication* NewApplication() { return new CTInputStreamApp; } GLDEF_C TInt E32Dll(TDllReason) { return KErrNone; } log_test::log_test() { } void log_test::ConstructL() { iAudioConvertUtility = CMdaAudioConvertUtility::NewL(*this); iDestType = new (ELeave) CMdaAudioType; iSrcType = new (ELeave) CMdaAudioType; iSrcType->iFormat = new TMdaRawAudioClipFormat; iDestType->iFormat = new TMdaWavClipFormat; iSettings.iChannels = 1; //TMdaAudioDataSettings::EChannelsMono; iSettings.iSampleRate =8000; //TMdaAudioDataSettings::ESampleRate8000Hz; iSettings1.iChannels = 1; //TMdaAudioDataSettings::EChannelsMono; iSettings1.iSampleRate =8000; //TMdaAudioDataSettings::ESampleRate8000Hz; iCodecSrc = new TMdaU8PcmRawAudioCodec; //(TMdaPcmWavCodec::E16BitPcm); iCodec = new (ELeave) TMdaPcmWavCodec(TMdaPcmWavCodec::E8BitPcm); /*TMdaMulawWavCodec */ isrcdesc = NULL; idesdesc = NULL; }; void log_test::MoscoStateChangeEvent(CBase* aObject, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode) { TTimeIntervalMicroSeconds temp(0); if (aErrorCode == KErrNone) { TBuf<32> buf(_L("Input err ")); buf.AppendNum(aErrorCode); file.Write(*(*idesdesc).iDes); } return; } log_test::~log_test() { if(iAudioConvertUtility) delete iAudioConvertUtility; if(isrcfrmt) delete isrcfrmt; if(itarfrmt) delete itarfrmt; } void log_test::BufferWriteL(const TDesC8& aTemp1, TDes8& aTemp2) { aTemp2.TrimAll(); aTemp2.Zero(); //Temp1.TrimAll(); _LIT(FilenameSrc, "temp.wav"); //aTemp2.Append(aTemp1); /*_LIT(FilenameDest, "\\system\\note1.wav"); */ if(isrcdesc) delete isrcdesc; if(idesdesc) delete idesdesc; isrcdesc = new(ELeave) TMdaDesClipLocation(aTemp1); idesdesc = new(ELeave) TMdaDesClipLocation(aTemp2); fileSrc=new TMdaFileClipLocation (FilenameSrc); // fileDest= new TMdaFileClipLocation(FilenameDest); */ iAudioConvertUtility->OpenL(isrcdesc,idesdesc,iSrcType->iFormat,iDestType->iFormat,iCodecSrc,&iSettings1,iCodec,&iSettings); //User::WaitForAnyRequest(); //iAudioConvertUtility->OpenL(FilenameSrc,FilenameDest); //,iDestType->iFormat,iCodec,&iSettings); // delete isrcdesc; // delete idesdesc; } |
|






Forum posts: 363
Calling OpenL does only that - it opens the stream for further processing. You have to call methods in the CMdaAudioClipUtility base class to actually convert anything.
Please help me.
Regards,
Venkat
Forum posts: 363
I admit the API isn't very clear about what to do. But, for conversion, just use PlayL after calling OpenL and you should be done!
Happy coding,
Pawel
void CConvert::MoscoStateChangeEvent(CBase* aObject, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
{
if ( aErrorCode != KErrNone ) {
iAudioConvertUtility->Stop();
iAudioConvertUtility->Close();
return;
}
if (iAudioConvertUtility == aObject) {
if ( aPreviousState == 0 && aCurrentState == 1 ) {
iAudioConvertUtility->PlayL();
} else if ( aPreviousState == 1 && aCurrentState == 2 ) {
// iState = EConvertStart;
} else if ( aPreviousState == 2 && aCurrentState == 1 ) {
// iState = EConvertDone;
CActiveScheduler::Stop();
iAudioConvertUtility->Stop();
iAudioConvertUtility->Close();
}
}
My code creates the file but with 0 bytes of size. I try also to make the call of PlayL() following of the call to OpenL() function and I obtained a MdaAudioSampleEd panic with value 1.
I don't know what is the problem. I don't have any more idea about how to make a audio convertion.
May anyone help me please?