Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Playing sound on the N8 device
Forum Updated to NodeBB v4.3 + New Features

Playing sound on the N8 device

Scheduled Pinned Locked Moved Mobile and Embedded
1 Posts 1 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jon21569
    wrote on last edited by
    #1

    I have been trying to get sound to work on the n8, and so far without success. I have tried QSound, Phonon, and SoundMixerController from the instructions from the link http://tamss60.tamoggemon.com/2010/04/22/proper-sound-and-background-music-with-qt-for-symbian/. I am doing this for a game so I would like to play multiple sounds at once so I would prefer the SoundMixerController.

    Here is some of the code.

    SoundTest.pro file
    @
    ###########################
    QT += core gui
    phonon
    phononfix

    TARGET = SoundTest
    TEMPLATE = app

    SOURCES += main.cpp
    SoundTestWidget.cpp
    s60sound/SoundMixerContainer.cpp
    s60sound/MyActive.cpp
    s60sound/CWavLoader.cpp
    s60sound/CSndMixer.cpp
    s60sound/CMixerThread.cpp

    HEADERS += SoundTestWidget.h
    s60sound/TSample.h
    s60sound/TAudioShared.h
    s60sound/SoundMixerContainer.h
    s60sound/MyActive.h
    s60sound/CWavLoader.h
    s60sound/CSndMixer.h
    s60sound/CMixerThread.h

    symbian {
    TARGET.UID3 = 0xe3fd4b63
    include($$PWD/../../symbianpkgrules.pri)
    LIBS += -lcone
    -leikcore
    -lefsrv
    -lavkon
    -lmediaclientaudio
    -lmediaclientaudiostream
    -lcentralrepository
    -lhal
    -lws32
    myFiles.sources = rsc*.wav
    DEPLOYMENT += myFiles

    symbian-abld|symbian-sbsv2 {
         # ro-section in gui can exceed default allocated space, so move rw-section a little further
         QMAKE_LFLAGS.ARMCC += --rw-base 0x800000
         QMAKE_LFLAGS.GCCE += -Tdata 0xC00000
    }
    
    # TARGET.CAPABILITY +=
    TARGET.EPOCSTACKSIZE = 0x14000
    TARGET.EPOCHEAPSIZE = 0x020000 0x800000
    

    }
    ###########################
    @

    CSoundMixerContainer.cpp
    @
    ###########################
    /*

    • Copyright © 2008 Nokia Corporation.
      */

    #include "SoundMixerContainer.h"
    #include <eikenv.h>
    #include "CSndMixer.h"
    #include "CWavLoader.h"

    // Profile settings
    #include <centralrepository.h>
    #include <ProfileEngineSDKCRKeys.h>

    _LIT(KEffectFile, "cow.wav");

    CSoundMixerContainer::CSoundMixerContainer()
    {

    }
    

    CSoundMixerContainer* CSoundMixerContainer::NewL()
    {
    CSoundMixerContainer* self = NewLC();
    CleanupStack::Pop( self );
    return self;
    }

    CSoundMixerContainer* CSoundMixerContainer::NewLC()
    {
    CSoundMixerContainer* self = new( ELeave )CSoundMixerContainer();
    CleanupStack::PushL( self );
    self->ConstructL();
    return self;
    }

    void CSoundMixerContainer::ConstructL()
    {
    // load sound samples
    CWavLoader* wavLoader = CWavLoader::NewLC();

    iEffectCow = wavLoader->LoadL(KEffectFile&#40;&#41;&#41;;
    
    CleanupStack::PopAndDestroy( wavLoader &#41;;
    
    // create sound mixer
    iSndMixer = CSndMixer::NewL(&#41;;
    }
    

    CSoundMixerContainer::~CSoundMixerContainer()
    {
    delete iSndMixer;
    delete iEffectCow.iData;
    }

    void CSoundMixerContainer::HandleGainingForeground()
    {
    // application gets focused
    // this function is called first time when application starts
    // that's why there's no need to start timer and sound in constructor
    // if the mixer is manually stopped, it should not be started when focus is gained
    StartMixer();
    }

    void CSoundMixerContainer::HandleLosingForeground()
    {
    // application loses focus
    // so stop moving blocks and playing sound
    StopMixer();
    }

    void CSoundMixerContainer::StartMixer()
    {
    if (!IsProfileSilent())
    {
    iSndMixer->Resume();
    }
    }

    void CSoundMixerContainer::StopMixer()
    {
    iSndMixer->Pause();
    }

    void CSoundMixerContainer::PlayCow()
    {
    iSndMixer->Play( iEffectCow, 2, 16000, 256 );
    }

    void CSoundMixerContainer::VolumeUp()
    {
    TInt volume = iSndMixer->Volume();
    volume += 10;
    if( volume > 100 ) volume = 100;

    iSndMixer->SetVolume( volume );
    }

    void CSoundMixerContainer::VolumeDown()
    {
    TInt volume = iSndMixer->Volume();
    volume -= 10;
    if( volume < 0 ) volume = 0;

    iSndMixer->SetVolume( volume );
    }

    // ---------------------------------------------------------
    // CSoundMixerContainer::IsProfileSilent()
    // Used for determining whether current profile is silent.
    // This means that sounds should not be played.
    // ---------------------------------------------------------

    TBool CSoundMixerContainer::IsProfileSilent()
    {
    return false;
    CRepository* centralRepository = CRepository::NewLC(KCRUidProfileEngine);
    TInt value;
    // Get the ringing type of the active profile
    User::LeaveIfError(centralRepository->Get(KProEngActiveRingingType, value));
    CleanupStack::PopAndDestroy(centralRepository);
    return (value == 4); // 4 = Silent
    }

    // End of File
    ###########################
    @

    @
    //Code to play sounds
    ###########################
    CSoundMixerContainer *m_sounds;

    m_sounds = new CSoundMixerContainer();
    m_sounds->ConstructL();

    m_sounds->PlayCow();
    ###########################
    @

    [EDIT: code formatting, Volker]

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved