×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Super Contributor
    Join Date
    Jul 2008
    Posts
    2,020

    CMdaAudioRecorder audio loop "stutters"

    Hello Folks,
    I am using CMdaAudioRec like this:
    Code:
    /*
     * AudioPlayer.cpp
     *
     *  Created on: 02.02.2010
     *      Author: TAMHAN
     */
    
    #include <Mda\Common\Resource.h>
    #include <BAUTILS.H>
     
    #include "AudioPlayer.h"
     
     
    CAudioPlayer* CAudioPlayer::NewL(MExamplePlayStateObserver& aObserver)
        {
        CAudioPlayer* self = CAudioPlayer::NewLC(aObserver);
        CleanupStack::Pop(self);
        return self;
        }
     
     
    CAudioPlayer* CAudioPlayer::NewLC(MExamplePlayStateObserver& aObserver)
        {
        CAudioPlayer* self = new (ELeave) CAudioPlayer(aObserver);
        CleanupStack::PushL(self);
        self->ConstructL();
        return self;
        }
     
     
    CAudioPlayer::CAudioPlayer(MExamplePlayStateObserver& aObserver)
    :iObserver(aObserver),iVolume(5)
        {
     
        }
     
     
    CAudioPlayer::~CAudioPlayer()
    {
    	delete iExampleTimer;
     
        if(iPlayerUtility)
        {
        	iPlayerUtility->Stop();
        	iPlayerUtility->Close();
        }
     
        delete iPlayerUtility;
    }
     
    void CAudioPlayer::ConstructL()
    {
    	iExampleTimer = CExampleTimer::NewL(CActive::EPriorityStandard,*this);
    	iPlayerUtility=NULL;
    	ReportStateAndTime();
    }
     
    void CAudioPlayer::TimerExpired(TAny* /*aTimer*/,TInt aError)
    {
    	// update states first.
    	ReportStateAndTime();
     
    	iPlayerUtility->PlayL();
    	
    	if(iExampleTimer && aError != KErrCancel)	
    	{
    		iExampleTimer->After(KReFreshTimeOut);
    	}
    }
     
     
    void CAudioPlayer::PlayL(const TDesC& aFileName)
    {
    	iCurrentFile.iName.Copy(aFileName);
     
    	if(iExampleTimer)	
    	{
    		iExampleTimer->Cancel();
    	}
     
    	if(iPlayerUtility)
        {
        	iPlayerUtility->Stop(); // stop any play/rec
        	iPlayerUtility->Close();// close previously opened file.
        }
     
    	delete iPlayerUtility;	  // and then we can delete it.
    	iPlayerUtility = NULL;
    	iPlayerUtility = CMdaAudioRecorderUtility::NewL(*this);
        iPlayerUtility->OpenFileL(iCurrentFile.iName);
     
    	if(iExampleTimer)	
    	{
    		iExampleTimer->After(KReFreshTimeOut);
    	}
    }
     
    void CAudioPlayer::StopL(void)
    {
    	if(iExampleTimer)
    	{
    		iExampleTimer->Cancel();
    	}
     
        if(iPlayerUtility)
        {
        	iPlayerUtility->Stop();
        }
     
        ReportStateAndTime();
    }
     
    void CAudioPlayer::SetVolume(TInt& aVolume)
    {
    	if(aVolume < 1)
    		aVolume = 1;
    	else if(aVolume > 10)
    		aVolume = 10;
     
    	iVolume = aVolume;// save to internal value always
    	if(iPlayerUtility) // and if utility exists, set it to it as well.
    	{
    		TInt Vol = ((iPlayerUtility->MaxVolume() * iVolume) / 10);
    		iPlayerUtility->SetVolume(Vol);
    	}
    }
     
     
    void CAudioPlayer::ReportStateAndTime(void)
    {
    	TInt CurrPosition(0),FileDuration(0);
     
    	CMdaAudioClipUtility::TState CurrState(CMdaAudioClipUtility::ENotReady);
     
    	if(iPlayerUtility)
    	{
    		CurrState =  iPlayerUtility->State();
     
    		TInt64 HelpPos = iPlayerUtility->Position().Int64();	
    		// micro seconds, thus lets make it seconds for UIs
    		CurrPosition = HelpPos / 1000000;
     
    		// and with playing its the file duration.
    		HelpPos = iPlayerUtility->Duration().Int64();	
    		FileDuration = HelpPos / 1000000;
    	}
     
    	// update valus to the UI
    	iObserver.StateUpdate(CurrState,CurrPosition,FileDuration);
    }
     
     
    void CAudioPlayer::MoscoStateChangeEvent(CBase* aObject, TInt aPreviousState, TInt aCurrentState, TInt /*aErrorCode*/)
    {
    	if(aObject == iPlayerUtility)
    	{
    		ReportStateAndTime();
     
    		switch(aCurrentState)
    		{
    		case CMdaAudioClipUtility::EOpen:
    			{
    				// only when first opening files.
    				// also called with aCurrentState == EOpen, when
    				// playing or recording finishes.
    				if(aPreviousState == CMdaAudioClipUtility::ENotReady)
    				{
    					TInt Vol = ((iVolume * iPlayerUtility->MaxVolume()) / 10);
    					iPlayerUtility->SetVolume(Vol);
     
    					TRAPD(err,iPlayerUtility->PlayL(););
    				}
    			}
    			break;
    		case CMdaAudioClipUtility::EPlaying:
    		case CMdaAudioClipUtility::ERecording:
    		case CMdaAudioClipUtility::ENotReady:
    		default: // no need to do anything on these states.
    			break;
    		}
    	}
    }
    The issue is that whenever PlayL gets called, the whole program hands for about a second and no sound is played -> no gapless playback.

    As I need this for a computer game, it would be ideal if some sort of possiblity is given to avoid the 1sec delay whenever the MP3 is restarted!

    All the best
    Tam Hanna
    The lines above are the best I have to offer.If anyone of you is of more advanced knowledge, I ask for your patience and understanding! - unknown arab poet
    http://www.tamoggemon.com - Symbian blog - Windows Phone blog
    My other blogs:
    webOS blog iPhone blog BlackBerry blog Samsung bada blog Android blog

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,169

    Re: CMdaAudioRecorder audio loop "stutters"

    you propably should not call the playL in our TimerExpired function, it propably just messes things up badly. So if you want to play the file faster, do call the CAudioPlayer::PlayL() beforehand, and do not start the play automatically when the file is openened, but when ever you need it, of course before calling the iPlayerUtility->PlayL(), make sure the file has been opened. Then to loop, just wait for the event indicating that the play has stopped and play again without re-opening the file.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    39

    Re: CMdaAudioRecorder audio loop "stutters"

    Quote Originally Posted by tamhanna View Post
    Hello Folks,
    I am using CMdaAudioRec like this:
    Code:
    /*
     * AudioPlayer.cpp
     *
     *  Created on: 02.02.2010
     *      Author: TAMHAN
     */
    
    #include <Mda\Common\Resource.h>
    #include <BAUTILS.H>
     
    #include "AudioPlayer.h"
     
     
    CAudioPlayer* CAudioPlayer::NewL(MExamplePlayStateObserver& aObserver)
        {
        CAudioPlayer* self = CAudioPlayer::NewLC(aObserver);
        CleanupStack::Pop(self);
        return self;
        }
     
     
    CAudioPlayer* CAudioPlayer::NewLC(MExamplePlayStateObserver& aObserver)
        {
        CAudioPlayer* self = new (ELeave) CAudioPlayer(aObserver);
        CleanupStack::PushL(self);
        self->ConstructL();
        return self;
        }
     
     
    CAudioPlayer::CAudioPlayer(MExamplePlayStateObserver& aObserver)
    :iObserver(aObserver),iVolume(5)
        {
     
        }
     
     
    CAudioPlayer::~CAudioPlayer()
    {
    	delete iExampleTimer;
     
        if(iPlayerUtility)
        {
        	iPlayerUtility->Stop();
        	iPlayerUtility->Close();
        }
     
        delete iPlayerUtility;
    }
     
    void CAudioPlayer::ConstructL()
    {
    	iExampleTimer = CExampleTimer::NewL(CActive::EPriorityStandard,*this);
    	iPlayerUtility=NULL;
    	ReportStateAndTime();
    }
     
    void CAudioPlayer::TimerExpired(TAny* /*aTimer*/,TInt aError)
    {
    	// update states first.
    	ReportStateAndTime();
     
    	iPlayerUtility->PlayL();
    	
    	if(iExampleTimer && aError != KErrCancel)	
    	{
    		iExampleTimer->After(KReFreshTimeOut);
    	}
    }
     
     
    void CAudioPlayer::PlayL(const TDesC& aFileName)
    {
    	iCurrentFile.iName.Copy(aFileName);
     
    	if(iExampleTimer)	
    	{
    		iExampleTimer->Cancel();
    	}
     
    	if(iPlayerUtility)
        {
        	iPlayerUtility->Stop(); // stop any play/rec
        	iPlayerUtility->Close();// close previously opened file.
        }
     
    	delete iPlayerUtility;	  // and then we can delete it.
    	iPlayerUtility = NULL;
    	iPlayerUtility = CMdaAudioRecorderUtility::NewL(*this);
        iPlayerUtility->OpenFileL(iCurrentFile.iName);
     
    	if(iExampleTimer)	
    	{
    		iExampleTimer->After(KReFreshTimeOut);
    	}
    }
     
    void CAudioPlayer::StopL(void)
    {
    	if(iExampleTimer)
    	{
    		iExampleTimer->Cancel();
    	}
     
        if(iPlayerUtility)
        {
        	iPlayerUtility->Stop();
        }
     
        ReportStateAndTime();
    }
     
    void CAudioPlayer::SetVolume(TInt& aVolume)
    {
    	if(aVolume < 1)
    		aVolume = 1;
    	else if(aVolume > 10)
    		aVolume = 10;
     
    	iVolume = aVolume;// save to internal value always
    	if(iPlayerUtility) // and if utility exists, set it to it as well.
    	{
    		TInt Vol = ((iPlayerUtility->MaxVolume() * iVolume) / 10);
    		iPlayerUtility->SetVolume(Vol);
    	}
    }
     
     
    void CAudioPlayer::ReportStateAndTime(void)
    {
    	TInt CurrPosition(0),FileDuration(0);
     
    	CMdaAudioClipUtility::TState CurrState(CMdaAudioClipUtility::ENotReady);
     
    	if(iPlayerUtility)
    	{
    		CurrState =  iPlayerUtility->State();
     
    		TInt64 HelpPos = iPlayerUtility->Position().Int64();	
    		// micro seconds, thus lets make it seconds for UIs
    		CurrPosition = HelpPos / 1000000;
     
    		// and with playing its the file duration.
    		HelpPos = iPlayerUtility->Duration().Int64();	
    		FileDuration = HelpPos / 1000000;
    	}
     
    	// update valus to the UI
    	iObserver.StateUpdate(CurrState,CurrPosition,FileDuration);
    }
     
     
    void CAudioPlayer::MoscoStateChangeEvent(CBase* aObject, TInt aPreviousState, TInt aCurrentState, TInt /*aErrorCode*/)
    {
    	if(aObject == iPlayerUtility)
    	{
    		ReportStateAndTime();
     
    		switch(aCurrentState)
    		{
    		case CMdaAudioClipUtility::EOpen:
    			{
    				// only when first opening files.
    				// also called with aCurrentState == EOpen, when
    				// playing or recording finishes.
    				if(aPreviousState == CMdaAudioClipUtility::ENotReady)
    				{
    					TInt Vol = ((iVolume * iPlayerUtility->MaxVolume()) / 10);
    					iPlayerUtility->SetVolume(Vol);
     
    					TRAPD(err,iPlayerUtility->PlayL(););
    				}
    			}
    			break;
    		case CMdaAudioClipUtility::EPlaying:
    		case CMdaAudioClipUtility::ERecording:
    		case CMdaAudioClipUtility::ENotReady:
    		default: // no need to do anything on these states.
    			break;
    		}
    	}
    }
    The issue is that whenever PlayL gets called, the whole program hands for about a second and no sound is played -> no gapless playback.

    As I need this for a computer game, it would be ideal if some sort of possiblity is given to avoid the 1sec delay whenever the MP3 is restarted!

    All the best
    Tam Hanna
    I think CMdaAuioOutputSream would be better solution if you want to play continuose sound or even want to do something like sound mixing.

  4. #4
    Super Contributor
    Join Date
    Jul 2008
    Posts
    2,020

    Re: CMdaAudioRecorder audio loop "stutters"

    Quote Originally Posted by symbianyucca View Post
    you propably should not call the playL in our TimerExpired function, it propably just messes things up badly. So if you want to play the file faster, do call the CAudioPlayer::PlayL() beforehand, and do not start the play automatically when the file is openened, but when ever you need it, of course before calling the iPlayerUtility->PlayL(), make sure the file has been opened. Then to loop, just wait for the event indicating that the play has stopped and play again without re-opening the file.
    Hi,
    the problem is that I want the thing to loop. How do I get it to do so?
    The lines above are the best I have to offer.If anyone of you is of more advanced knowledge, I ask for your patience and understanding! - unknown arab poet
    http://www.tamoggemon.com - Symbian blog - Windows Phone blog
    My other blogs:
    webOS blog iPhone blog BlackBerry blog Samsung bada blog Android blog

  5. #5
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,169

    Re: CMdaAudioRecorder audio loop "stutters"

    you have the event callback there, so determine when it is stopped playing, and just play again..

Similar Threads

  1. Recording audio in loop, crashes on N70
    By hsundt in forum Mobile Java Media (Graphics & Sounds)
    Replies: 3
    Last Post: 2010-12-29, 15:22
  2. Replies: 6
    Last Post: 2007-07-11, 08:33
  3. Recording an audio stream using the Series 60 emulator
    By rastapasta in forum Symbian Media (Closed)
    Replies: 4
    Last Post: 2007-04-23, 11:46
  4. Half Duplex Audio Streaming
    By subhrajyotisaha in forum Symbian Media (Closed)
    Replies: 0
    Last Post: 2006-05-25, 04:39
  5. RunL() method is not being called
    By dotcdotc in forum Symbian
    Replies: 9
    Last Post: 2004-12-13, 11:25

Posting Permissions

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