Skip to content

Commit

Permalink
native: Add sound test program
Browse files Browse the repository at this point in the history
  • Loading branch information
pent0 committed Aug 4, 2021
1 parent 17e98f5 commit 227de34
Show file tree
Hide file tree
Showing 10 changed files with 356 additions and 0 deletions.
117 changes: 117 additions & 0 deletions native/SoundTest/.cproject

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions native/SoundTest/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>soundtest</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.nokia.carbide.cdt.builder.carbideCPPBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>com.nokia.carbide.cdt.builder.carbideCPPBuilderNature</nature>
</natures>
</projectDescription>
Empty file.
15 changes: 15 additions & 0 deletions native/SoundTest/group/ABLD.BAT
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@ECHO OFF

REM Bldmake-generated batch file - ABLD.BAT
REM ** DO NOT EDIT **

perl -S ABLD.PL "\Dev\projects\eka2l1\native\SoundTest\group\\" %1 %2 %3 %4 %5 %6 %7 %8 %9
if errorlevel==1 goto CheckPerl
goto End

:CheckPerl
perl -v >NUL
if errorlevel==1 echo Is Perl, version 5.003_07 or later, installed?
goto End

:End
15 changes: 15 additions & 0 deletions native/SoundTest/group/bld.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
============================================================================
Name : bld.inf
Author :
Copyright : Your copyright notice
Description : This file provides the information required for building the
whole of a soundtest.
============================================================================
*/

PRJ_PLATFORMS
DEFAULT

PRJ_MMPFILES
soundtest.mmp
23 changes: 23 additions & 0 deletions native/SoundTest/group/soundtest.mmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
============================================================================
Name : soundtest.mmp
Author :
Copyright : Your copyright notice
Description : This is the project specification file for soundtest.
============================================================================
*/

TARGET soundtest.exe
TARGETTYPE exe
UID 0 0xe0c5927a

SYSTEMINCLUDE \epoc32\include

SOURCEPATH ..\src
SOURCE soundtest.cpp

LIBRARY euser.lib mmfdevsound.lib efsrv.lib

DEBUGGABLE_UDEBONLY

SECUREID 0xe0c5927a
25 changes: 25 additions & 0 deletions native/SoundTest/sis/soundtest_EKA2.pkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
; Installation file for Symbian OS 9.x for generic console application
; Installation file for soundtest EXE
;
; This is an auto-generated PKG file by Carbide.
; This file uses variables specific to Carbide builds that will not work
; on command-line builds. If you want to use this generated PKG file from the
; command-line tools you will need to modify the variables with the appropriate
; values: $(EPOCROOT), $(PLATFORM), $(TARGET)
;

;
; UID is the exe's UID
;
#{"soundtest EXE"},(0xe0c5927a),1,0,0


;Localised Vendor name
%{"Vendor-EN"}

;Unique Vendor name
:"Vendor"

"$(EPOCROOT)epoc32\release\$(PLATFORM)\$(TARGET)\soundtest.exe" -"!:\sys\bin\soundtest.exe"
"../data/sample.mp3" -"!:\private\e0c5927a\sample.mp3"

Binary file added native/SoundTest/sis/soundtest_EKA2.sis
Binary file not shown.
Binary file added native/SoundTest/sis/soundtest_EKA2.sisx
Binary file not shown.
142 changes: 142 additions & 0 deletions native/SoundTest/src/soundtest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#include <e32base.h>
#include <e32std.h>
#include <f32file.h>
#include <mmf/server/sounddevice.h>

class CAudioFileFeeder : public MDevSoundObserver {
private:
RFile iFile;
RFile iLogFile;

RFs iFs;

CMMFDevSound *iDevSound;

public:
CAudioFileFeeder(CMMFDevSound *aDevSound)
: iDevSound(aDevSound) {
}

void ConstructL() {
User::LeaveIfError(iFs.Connect(-1));
iFs.SetSessionToPrivate(EDriveC);

User::LeaveIfError(iFile.Open(iFs, _L("sample.mp3"), EFileRead | EFileShareAny));
User::LeaveIfError(iLogFile.Replace(iFs, _L("E:\\testlog.log"), EFileWrite | EFileShareAny));
}

static CAudioFileFeeder *NewLC(CMMFDevSound *aDevSound) {
CAudioFileFeeder *observer = new CAudioFileFeeder(aDevSound);
CleanupStack::PushL(observer);

observer->ConstructL();
return observer;
}

static CAudioFileFeeder *NewL(CMMFDevSound *aDevSound) {
CAudioFileFeeder *observer = NewLC(aDevSound);
CleanupStack::Pop(observer);

return observer;
}

virtual void BufferToBeFilled(CMMFBuffer *aBuffer) {
CMMFDataBuffer* dataBuffer = static_cast <CMMFDataBuffer*>(aBuffer);
aBuffer->SetLastBuffer(EFalse);

TDes8 &dataDes = dataBuffer->Data();
TUint32 originalSize = dataDes.MaxLength();

iFile.Read(dataDes);

TBuf8<256> lineToPrint;
lineToPrint.Format(_L8("Requested %d bytes, got %d bytes"), originalSize, dataDes.Length());

RDebug::Printf((const char*)lineToPrint.Ptr());
iLogFile.Write(lineToPrint);

if (dataDes.Length() != originalSize) {
aBuffer->SetLastBuffer(ETrue);
}

iDevSound->PlayData();
}

virtual void PlayError(TInt error) {
CActiveScheduler::Stop();
}

virtual void BufferToBeEmptied(CMMFBuffer *aBuffer) {
}

virtual void ConvertError(TInt aError) {

}

virtual void DeviceMessage(TUid aMessageType, const TDesC8 &aMsg) {

}

virtual void InitializeComplete(TInt aError) {

}

virtual void RecordError(TInt aError) {

}

virtual void ToneFinished(TInt aError) {

}
};

LOCAL_C void MainL() {
CMMFDevSound *devsound = CMMFDevSound::NewL();
User::LeaveIfNull(devsound);

CleanupStack::PushL(devsound);

CAudioFileFeeder *observer = CAudioFileFeeder::NewL(devsound);
CleanupStack::PushL(observer);

devsound->InitializeL(*observer, ::KMMFFourCCCodeMP3, EMMFStatePlaying);
devsound->SetVolume(6);

TMMFCapabilities caps = devsound->Capabilities();
caps.iChannels = EMMFStereo;
caps.iRate = EMMFSampleRate44100Hz;
caps.iEncoding = EMMFSoundEncoding16BitPCM;
caps.iBufferSize = 8192;

devsound->SetConfigL(caps);
devsound->PlayInitL();
devsound->PlayData();

CActiveScheduler::Start();
CleanupStack::Pop(2);
}

LOCAL_C void DoStartL() {
// Create active scheduler (to run active objects)
CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
CleanupStack::PushL(scheduler);
CActiveScheduler::Install(scheduler);

MainL();

// Delete active scheduler
CleanupStack::PopAndDestroy(scheduler);
}

GLDEF_C TInt E32Main() {
__UHEAP_MARK;
CTrapCleanup* cleanup = CTrapCleanup::New();

// Run application code inside TRAP harness, wait keypress when terminated
TRAPD(mainError, DoStartL());

delete cleanup;
__UHEAP_MARKEND;
return KErrNone;
}

0 comments on commit 227de34

Please sign in to comment.