×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Nokia Developer Expert
    Join Date
    Apr 2003
    Location
    United Kingdom
    Posts
    95

    Could not able to convert audio format

    Hi All,

    I am trying to convert the Raw Audio stream which is recorded using the TInputSream example provided by symbian. My problem is when I call ConvertUtility method it is writing 0 bytes to output Descriptor. I run the code in the debug mode and checked that Error number in MoscoStateChangeEvent is 0 only.

    What could be the problem with this code. Please help.


    #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->SetMax();
    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;
    }

    iConverter->BufferWriteL(aBuffer,*buffer);


    buf.Append(_L(" full, err "));
    buf.AppendNum(aError);
    iAppView->AddMessage(buf);

    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 TMdaUB16RawAudioCodec; //(TMdaPcmWavCodec::E16BitPcm);

    //iCodecSrc->iBits=16; */

    iCodec = new (ELeave) TMdaPcmWavCodec(TMdaPcmWavCodec::E16BitPcm);
    };

    void log_test::MoscoStateChangeEvent(CBase* aObject, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
    {
    if (aErrorCode == KErrNone)
    {
    TBuf<32> buf(_L("Input err "));
    buf.AppendNum(aErrorCode);
    // iAudioConvertUtility->OpenL(fileSrc,fileDest,iSrcType->iFormat,iDestType->iFormat,iCodecSrc,&iSettings1,iCodec,&iSettings);
    }
    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();
    //Temp1.TrimAll();
    /*_LIT(FilenameSrc, "temp.wav");
    _LIT(FilenameDest, "\\system\\note1.wav"); */

    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);
    //iAudioConvertUtility->OpenL(FilenameSrc,FilenameDest); //,iDestType->iFormat,iCodec,&iSettings);
    file.Write(*(*idesdesc).iDes);

    // delete isrcdesc;
    // delete idesdesc;

    }

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    16

    Anyone with a solution to Raw Audio->(Wav or amr) for 7610 phone?

    Did you or anyone else come up with a solution to this problem?

  3. #3
    Regular Contributor
    Join Date
    Mar 2004
    Location
    Novi Sad - Serbia
    Posts
    63

    AMR codec

    I use CPcmToAmrEncoder and CAmrToPcmDecoder classes to do the PCM to AMR coding/decoding.

    I tested that on Nokia6600 and it works fine for me.

    Just search this forum for these classes and you'll find some examples.

    I hope this can help you.

  4. #4
    Regular Contributor
    Join Date
    Jun 2005
    Location
    Philippines
    Posts
    163

    Re: AMR codec

    Quote Originally Posted by sasa
    I use CPcmToAmrEncoder and CAmrToPcmDecoder classes to do the PCM to AMR coding/decoding.

    I tested that on Nokia6600 and it works fine for me.

    Just search this forum for these classes and you'll find some examples.

    I hope this can help you.
    Would this work on 6680 phone or on Symbian v8.0?

  5. #5
    Regular Contributor
    Join Date
    Jun 2005
    Location
    Philippines
    Posts
    163

    Smile Using CMMFCodec

    Just for documentation purposes, I was able to convert using the CMMFCodec class and the standard TFourCC codes. This works in 6680. For S60 SDK FP2 I did not find documentation in the help files. The documentation can be found in the header files, namely, <mmf\common\mmffourcc.h> and <mmf\common\mmfcodec.h>.

    I was able to convert from PCM to u-law.

  6. #6
    Nokia Developer Champion
    Join Date
    Mar 2004
    Location
    Czech Republic
    Posts
    2,037

    Re: Could not able to convert audio format

    Hi,

    use CMMFCodec for PCM<->AMR conversion (works on both N6680 and N6630 phones).. For recodring directly into AMR use CMMFDevSound class
    Bye
    STeN

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •