sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "sound_util.h"
|
sl@0
|
19 |
|
sl@0
|
20 |
// Translation table for RMdaDevSound::TMdaSoundEncoding set
|
sl@0
|
21 |
|
sl@0
|
22 |
_LIT(KStrEMdaSoundEncoding8BitPCM, "EMdaSoundEncoding8BitPCM");
|
sl@0
|
23 |
_LIT(KStrEMdaSoundEncoding16BitPCM, "EMdaSoundEncoding16BitPCM");
|
sl@0
|
24 |
_LIT(KStrEMdaSoundEncoding8BitALaw, "EMdaSoundEncoding8BitALaw");
|
sl@0
|
25 |
_LIT(KStrEMdaSoundEncoding8BitMuLaw, "EMdaSoundEncoding8BitMuLaw");
|
sl@0
|
26 |
|
sl@0
|
27 |
// NB! Wrong member for negative testing
|
sl@0
|
28 |
_LIT(KStrEMdaSoundEncoding40BitPCM, "EMdaSoundEncoding40BitPCM");
|
sl@0
|
29 |
_LIT(KStrNull, "");
|
sl@0
|
30 |
|
sl@0
|
31 |
const CDataWrapperBase::TEnumEntryTable TSoundUtil::iEnumTableSoundEncoding[] =
|
sl@0
|
32 |
{
|
sl@0
|
33 |
// Enum as a descriptor Enum
|
sl@0
|
34 |
KStrEMdaSoundEncoding8BitPCM, RMdaDevSound::EMdaSoundEncoding8BitPCM,
|
sl@0
|
35 |
KStrEMdaSoundEncoding16BitPCM, RMdaDevSound::EMdaSoundEncoding16BitPCM,
|
sl@0
|
36 |
KStrEMdaSoundEncoding8BitALaw, RMdaDevSound::EMdaSoundEncoding8BitALaw,
|
sl@0
|
37 |
KStrEMdaSoundEncoding8BitMuLaw, RMdaDevSound::EMdaSoundEncoding8BitMuLaw,
|
sl@0
|
38 |
KStrEMdaSoundEncoding40BitPCM, 0x00000040,
|
sl@0
|
39 |
KStrNull, -1
|
sl@0
|
40 |
};
|
sl@0
|
41 |
|
sl@0
|
42 |
/**
|
sl@0
|
43 |
* Loading of generinc sound driver required for RMDaDevSound interface
|
sl@0
|
44 |
*
|
sl@0
|
45 |
* @param aLll LDD driver name
|
sl@0
|
46 |
* @param aPdd PDD driver name
|
sl@0
|
47 |
*
|
sl@0
|
48 |
* @return System wide error
|
sl@0
|
49 |
*
|
sl@0
|
50 |
* @leave no
|
sl@0
|
51 |
*/
|
sl@0
|
52 |
TInt TSoundUtil::LoadSoundDrivers(const TDesC& aLdd, const TDesC& aPdd)
|
sl@0
|
53 |
{
|
sl@0
|
54 |
TInt rerr = KErrNone;
|
sl@0
|
55 |
|
sl@0
|
56 |
rerr = User::LoadPhysicalDevice(aPdd);
|
sl@0
|
57 |
if(rerr != KErrNone && rerr != KErrAlreadyExists)
|
sl@0
|
58 |
{
|
sl@0
|
59 |
return rerr;
|
sl@0
|
60 |
}
|
sl@0
|
61 |
rerr = User::LoadLogicalDevice(aLdd);
|
sl@0
|
62 |
if(rerr != KErrNone && rerr != KErrAlreadyExists)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
return rerr;
|
sl@0
|
65 |
}
|
sl@0
|
66 |
return KErrNone;
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
/**
|
sl@0
|
70 |
* Un-loading of generinc sound driver required for RMDaDevSound interface
|
sl@0
|
71 |
*
|
sl@0
|
72 |
* @param aLll LDD driver name
|
sl@0
|
73 |
* @param aPdd PDD driver name
|
sl@0
|
74 |
*
|
sl@0
|
75 |
* @return System wide error
|
sl@0
|
76 |
*
|
sl@0
|
77 |
* @leave no
|
sl@0
|
78 |
*/
|
sl@0
|
79 |
TInt TSoundUtil::FreeSoundDrivers(const TDesC& aLdd, const TDesC& aPdd)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
TInt rerr = KErrNone;
|
sl@0
|
82 |
|
sl@0
|
83 |
rerr = User::FreePhysicalDevice(aPdd);
|
sl@0
|
84 |
if(rerr != KErrNone && rerr != KErrAlreadyExists)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
return rerr;
|
sl@0
|
87 |
}
|
sl@0
|
88 |
rerr = User::FreeLogicalDevice(aLdd);
|
sl@0
|
89 |
if(rerr != KErrNone && rerr != KErrAlreadyExists)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
return rerr;
|
sl@0
|
92 |
}
|
sl@0
|
93 |
return KErrNone;
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
/**
|
sl@0
|
97 |
* Store current RBuf8 content into the binary file
|
sl@0
|
98 |
*
|
sl@0
|
99 |
* @param aFile file name to save audio data
|
sl@0
|
100 |
*
|
sl@0
|
101 |
* @return System wide error
|
sl@0
|
102 |
*
|
sl@0
|
103 |
* @leave System wide error
|
sl@0
|
104 |
*/
|
sl@0
|
105 |
TInt TSoundUtil::RAudioBuffer::SaveAudioDataL(const TDesC& aFile)
|
sl@0
|
106 |
{
|
sl@0
|
107 |
RFs fsSession;
|
sl@0
|
108 |
::CleanupClosePushL(fsSession);
|
sl@0
|
109 |
User::LeaveIfError(fsSession.Connect());
|
sl@0
|
110 |
TInt err = KErrNone;
|
sl@0
|
111 |
RFile file;
|
sl@0
|
112 |
err = file.Create(fsSession, aFile, EFileStream | EFileWrite);
|
sl@0
|
113 |
if (!err)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
err = file.Write(*this);
|
sl@0
|
116 |
|
sl@0
|
117 |
file.Close();
|
sl@0
|
118 |
}
|
sl@0
|
119 |
fsSession.Close();
|
sl@0
|
120 |
CleanupStack::PopAndDestroy();
|
sl@0
|
121 |
return err;
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
/**
|
sl@0
|
125 |
* Load binary file content into RBuf8
|
sl@0
|
126 |
*
|
sl@0
|
127 |
* @param aFile file name where to load audio data
|
sl@0
|
128 |
*
|
sl@0
|
129 |
* @return System wide error
|
sl@0
|
130 |
*
|
sl@0
|
131 |
* @leave System wide error
|
sl@0
|
132 |
*/
|
sl@0
|
133 |
TInt TSoundUtil::RAudioBuffer::LoadAudioDataL(const TDesC& aFile)
|
sl@0
|
134 |
{
|
sl@0
|
135 |
RFs fsSession;
|
sl@0
|
136 |
::CleanupClosePushL(fsSession);
|
sl@0
|
137 |
User::LeaveIfError(fsSession.Connect());
|
sl@0
|
138 |
TFindFile findFile(fsSession);
|
sl@0
|
139 |
TInt err = findFile.FindByDir(aFile, KStrNull);
|
sl@0
|
140 |
if ( err == KErrNone )
|
sl@0
|
141 |
{
|
sl@0
|
142 |
const TDesC& fileName=findFile.File();
|
sl@0
|
143 |
RFile file;
|
sl@0
|
144 |
err = file.Open(fsSession, fileName, EFileStream | EFileRead);
|
sl@0
|
145 |
if (!err)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
err = file.Read(*this);
|
sl@0
|
148 |
file.Close();
|
sl@0
|
149 |
}
|
sl@0
|
150 |
}
|
sl@0
|
151 |
fsSession.Close();
|
sl@0
|
152 |
CleanupStack::PopAndDestroy();
|
sl@0
|
153 |
return err;
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
/**
|
sl@0
|
157 |
* Delete file
|
sl@0
|
158 |
*
|
sl@0
|
159 |
* @param aFile file name to delete
|
sl@0
|
160 |
*
|
sl@0
|
161 |
* @return System wide error
|
sl@0
|
162 |
*
|
sl@0
|
163 |
* @leave System wide error
|
sl@0
|
164 |
*/
|
sl@0
|
165 |
TInt TSoundUtil::DeleteFileL(const TDesC& aFile)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
RFs fsSession;
|
sl@0
|
168 |
CleanupClosePushL(fsSession);
|
sl@0
|
169 |
User::LeaveIfError(fsSession.Connect());
|
sl@0
|
170 |
TInt err;
|
sl@0
|
171 |
err = fsSession.Delete(aFile);
|
sl@0
|
172 |
fsSession.Close();
|
sl@0
|
173 |
CleanupStack::PopAndDestroy();
|
sl@0
|
174 |
return err;
|
sl@0
|
175 |
}
|