20
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "shared_sound.h"
|
|
19 |
#include "variant_sound.h"
|
|
20 |
|
|
21 |
void TimerCallback(TAny* aData)
|
|
22 |
{
|
|
23 |
DDriverBeagleSoundScPdd * soundscpdd = (DDriverBeagleSoundScPdd*) aData;
|
|
24 |
|
|
25 |
soundscpdd->Callback(soundscpdd->iTransferArray[0].iTransferID, KErrNone, soundscpdd->iTransferArray[0].iNumBytes);
|
|
26 |
|
|
27 |
}
|
|
28 |
|
|
29 |
|
|
30 |
DDriverBeagleSoundScPdd::DDriverBeagleSoundScPdd() : iTimer(TimerCallback,this)
|
|
31 |
{
|
|
32 |
|
|
33 |
}
|
|
34 |
|
|
35 |
DDriverBeagleSoundScPdd::~DDriverBeagleSoundScPdd()
|
|
36 |
{
|
|
37 |
iTimer.Cancel();
|
|
38 |
}
|
|
39 |
|
|
40 |
|
|
41 |
TInt DDriverBeagleSoundScPdd::DoCreate()
|
|
42 |
{
|
|
43 |
|
|
44 |
SetCaps();
|
|
45 |
|
|
46 |
BEAGLE_SOUND_DEBUG("DDriverBeagleSoundScPdd::DoCreate TxPdd");
|
|
47 |
|
|
48 |
return KErrNone;
|
|
49 |
}
|
|
50 |
|
|
51 |
void DDriverBeagleSoundScPdd::GetChunkCreateInfo(TChunkCreateInfo& aChunkCreateInfo)
|
|
52 |
{
|
|
53 |
BEAGLE_SOUND_DEBUG("DDriverBeagleSoundScPdd::GetChunkCreateInfo TxPdd");
|
|
54 |
|
|
55 |
aChunkCreateInfo.iType = TChunkCreateInfo::ESharedKernelMultiple;
|
|
56 |
aChunkCreateInfo.iMapAttr = EMapAttrFullyBlocking; // No caching
|
|
57 |
aChunkCreateInfo.iOwnsMemory = ETrue; // Using RAM pages
|
|
58 |
aChunkCreateInfo.iDestroyedDfc = NULL; // No chunk destroy DFC
|
|
59 |
}
|
|
60 |
|
|
61 |
void DDriverBeagleSoundScPdd::Caps(TDes8& aCapsBuf) const
|
|
62 |
{
|
|
63 |
|
|
64 |
BEAGLE_SOUND_DEBUG("DDriverBeagleSoundScPdd::Caps TxPdd");
|
|
65 |
|
|
66 |
// Fill the structure with zeros in case it is a newer version than we know about
|
|
67 |
aCapsBuf.FillZ(aCapsBuf.MaxLength());
|
|
68 |
|
|
69 |
// And copy the capabilities into the packaged structure
|
|
70 |
TPtrC8 ptr((const TUint8*) &iCaps, sizeof(iCaps));
|
|
71 |
aCapsBuf = ptr.Left(Min(ptr.Length(), aCapsBuf.MaxLength()));
|
|
72 |
}
|
|
73 |
|
|
74 |
TInt DDriverBeagleSoundScPdd::SetConfig(const TDesC8& aConfigBuf)
|
|
75 |
{
|
|
76 |
|
|
77 |
BEAGLE_SOUND_DEBUG("DDriverBeagleSoundScPdd::SetConfig TxPdd");
|
|
78 |
|
|
79 |
// Read the new configuration from the LDD
|
|
80 |
TCurrentSoundFormatV02 config;
|
|
81 |
TPtr8 ptr((TUint8*) &config, sizeof(config));
|
|
82 |
Kern::InfoCopy(ptr, aConfigBuf);
|
|
83 |
|
|
84 |
iConfig = config;
|
|
85 |
|
|
86 |
return KErrNone;
|
|
87 |
}
|
|
88 |
|
|
89 |
|
|
90 |
TInt DDriverBeagleSoundScPdd::SetVolume(TInt aVolume)
|
|
91 |
{
|
|
92 |
|
|
93 |
BEAGLE_SOUND_DEBUG("DDriverBeagleSoundScPdd::Setvolume TxPdd");
|
|
94 |
|
|
95 |
return KErrNone;
|
|
96 |
}
|
|
97 |
|
|
98 |
|
|
99 |
TInt DDriverBeagleSoundScPdd::StartTransfer()
|
|
100 |
{
|
|
101 |
|
|
102 |
BEAGLE_SOUND_DEBUG("DDriverBeagleSoundScPdd::starttransfer TxPdd");
|
|
103 |
|
|
104 |
//Prepare for transfer
|
|
105 |
return KErrNone;
|
|
106 |
|
|
107 |
}
|
|
108 |
|
|
109 |
TInt DDriverBeagleSoundScPdd::CalculateBufferTime(TInt aNumBytes)
|
|
110 |
{
|
|
111 |
|
|
112 |
TUint samplerate=0;
|
|
113 |
|
|
114 |
// Let the compiler perform an integer division of rates
|
|
115 |
switch(iConfig.iRate)
|
|
116 |
{
|
|
117 |
case ESoundRate7350Hz: samplerate = 7350; break;
|
|
118 |
case ESoundRate8000Hz: samplerate = 8000; break;
|
|
119 |
case ESoundRate8820Hz: samplerate = 8820; break;
|
|
120 |
case ESoundRate9600Hz: samplerate = 9600; break;
|
|
121 |
case ESoundRate11025Hz: samplerate = 11025; break;
|
|
122 |
case ESoundRate12000Hz: samplerate = 12000; break;
|
|
123 |
case ESoundRate14700Hz: samplerate = 14700; break;
|
|
124 |
case ESoundRate16000Hz: samplerate = 16000; break;
|
|
125 |
case ESoundRate22050Hz: samplerate = 22050; break;
|
|
126 |
case ESoundRate24000Hz: samplerate = 24000; break;
|
|
127 |
case ESoundRate29400Hz: samplerate = 29400; break;
|
|
128 |
case ESoundRate32000Hz: samplerate = 32000; break;
|
|
129 |
case ESoundRate44100Hz: samplerate = 44100; break;
|
|
130 |
case ESoundRate48000Hz: samplerate = 48000; break;
|
|
131 |
}
|
|
132 |
|
|
133 |
|
|
134 |
// integer division by number of channels
|
|
135 |
aNumBytes /= iConfig.iChannels;
|
|
136 |
|
|
137 |
BEAGLE_SOUND_DEBUG("DDriverBeagleSoundScPdd::iChannels =%d", iConfig.iChannels);
|
|
138 |
BEAGLE_SOUND_DEBUG("DDriverBeagleSoundScPdd::iEncoding =%d", iConfig.iEncoding);
|
|
139 |
|
|
140 |
// integer division by bytes per sample
|
|
141 |
switch(iConfig.iEncoding)
|
|
142 |
{
|
|
143 |
case ESoundEncoding8BitPCM: break;
|
|
144 |
case ESoundEncoding16BitPCM: aNumBytes /= 2; break;
|
|
145 |
case ESoundEncoding24BitPCM: aNumBytes /= 3; break;
|
|
146 |
}
|
|
147 |
|
|
148 |
return (aNumBytes * 1000) / samplerate; //return time in milliseconds
|
|
149 |
|
|
150 |
|
|
151 |
}
|
|
152 |
|
|
153 |
TInt DDriverBeagleSoundScPdd::TransferData(TUint aTransferID, TLinAddr aLinAddr, TPhysAddr /*aPhysAddr*/, TInt aNumBytes)
|
|
154 |
{
|
|
155 |
|
|
156 |
//function wil get called multiple times while transfer is in progress therefore keep fifo queue of requests
|
|
157 |
TTransferArrayInfo transfer;
|
|
158 |
|
|
159 |
transfer.iTransferID = aTransferID;
|
|
160 |
transfer.iLinAddr = aLinAddr;
|
|
161 |
transfer.iNumBytes = aNumBytes;
|
|
162 |
|
|
163 |
//calculate the amount of time required to play/record buffer
|
|
164 |
TInt buffer_play_time = CalculateBufferTime(aNumBytes);
|
|
165 |
TInt timerticks = NKern::TimerTicks(buffer_play_time);
|
|
166 |
transfer.iPlayTime = timerticks;
|
|
167 |
|
|
168 |
iTransferArray.Append(transfer);
|
|
169 |
|
|
170 |
//Timer will callback when correct time has elapsed, will return KErrInUse if transfer
|
|
171 |
//already active, this is ok becuase will be started again in callback
|
|
172 |
TInt err = iTimer.OneShot(timerticks, ETrue);
|
|
173 |
|
|
174 |
|
|
175 |
return KErrNone;
|
|
176 |
}
|
|
177 |
|
|
178 |
void DDriverBeagleSoundScPdd::StopTransfer()
|
|
179 |
{
|
|
180 |
// Stop transfer
|
|
181 |
BEAGLE_SOUND_DEBUG("DDriverBeagleSoundScPdd::stoptransfer TxPdd");
|
|
182 |
|
|
183 |
//If timer is currently active then cancel it and call back buffer
|
|
184 |
if(iTimer.Cancel())
|
|
185 |
{
|
|
186 |
Callback(iTransferArray[0].iTransferID, KErrNone, iTransferArray[0].iNumBytes);
|
|
187 |
}
|
|
188 |
|
|
189 |
|
|
190 |
}
|
|
191 |
|
|
192 |
|
|
193 |
TInt DDriverBeagleSoundScPdd::PauseTransfer()
|
|
194 |
{
|
|
195 |
BEAGLE_SOUND_DEBUG("DDriverBeagleSoundScPdd::pausetransfer TxPdd");
|
|
196 |
//Pause Transfer
|
|
197 |
|
|
198 |
return KErrNone;
|
|
199 |
}
|
|
200 |
|
|
201 |
|
|
202 |
TInt DDriverBeagleSoundScPdd::ResumeTransfer()
|
|
203 |
{
|
|
204 |
BEAGLE_SOUND_DEBUG("DDriverBeagleSoundScPdd::resumetransfer TxPdd");
|
|
205 |
//Resume Transfer
|
|
206 |
|
|
207 |
return KErrNone;
|
|
208 |
}
|
|
209 |
|
|
210 |
TInt DDriverBeagleSoundScPdd::PowerUp()
|
|
211 |
{
|
|
212 |
BEAGLE_SOUND_DEBUG("DDriverBeagleSoundScPdd::PowerUp TxPdd");
|
|
213 |
return KErrNone;
|
|
214 |
}
|
|
215 |
|
|
216 |
void DDriverBeagleSoundScPdd::PowerDown()
|
|
217 |
{
|
|
218 |
BEAGLE_SOUND_DEBUG("DDriverBeagleSoundScPdd::Powerdown TxPdd");
|
|
219 |
}
|
|
220 |
|
|
221 |
TInt DDriverBeagleSoundScPdd::CustomConfig(TInt /*aFunction*/,TAny* /*aParam*/)
|
|
222 |
{
|
|
223 |
BEAGLE_SOUND_DEBUG("DDriverBeagleSoundScPdd::customconfig TxPdd");
|
|
224 |
return KErrNotSupported;
|
|
225 |
}
|
|
226 |
|
|
227 |
|
|
228 |
void DDriverBeagleSoundScPdd::Callback(TUint aTransferID, TInt aTransferResult, TInt aBytesTransferred)
|
|
229 |
{
|
|
230 |
BEAGLE_SOUND_DEBUG("DDriverBeagleSoundScPdd::playcallback TxPdd");
|
|
231 |
//Callback when Transfer completes or is stopped
|
|
232 |
|
|
233 |
iTransferArray.Remove(0);
|
|
234 |
|
|
235 |
if(iUnitType == KSoundScTxUnit0)
|
|
236 |
{
|
|
237 |
Ldd()->PlayCallback(aTransferID, aTransferResult, aBytesTransferred);
|
|
238 |
}
|
|
239 |
else if(iUnitType == KSoundScRxUnit0)
|
|
240 |
{
|
|
241 |
Ldd()->RecordCallback(aTransferID, aTransferResult, aBytesTransferred);
|
|
242 |
}
|
|
243 |
|
|
244 |
if( iTransferArray.Count()>0)
|
|
245 |
{
|
|
246 |
iTimer.OneShot(iTransferArray[0].iPlayTime, ETrue);
|
|
247 |
}
|
|
248 |
|
|
249 |
}
|
|
250 |
|
|
251 |
TDfcQue*DDriverBeagleSoundScPdd::DfcQ(TInt /* aUnit*/ )
|
|
252 |
{
|
|
253 |
return this->DfcQ();
|
|
254 |
}
|
|
255 |
|
|
256 |
TDfcQue*DDriverBeagleSoundScPdd::DfcQ()
|
|
257 |
{
|
|
258 |
return iPhysicalDevice->iDfcQ;
|
|
259 |
}
|
|
260 |
|
|
261 |
TInt DDriverBeagleSoundScPdd::MaxTransferLen() const
|
|
262 |
{
|
|
263 |
|
|
264 |
BEAGLE_SOUND_DEBUG("DDriverBeagleSoundScPdd::MaxTransferLen TxPdd");
|
|
265 |
|
|
266 |
TInt maxlength = 200*1024;
|
|
267 |
return maxlength;
|
|
268 |
}
|
|
269 |
|
|
270 |
|
|
271 |
void DDriverBeagleSoundScPdd::SetCaps()
|
|
272 |
{
|
|
273 |
BEAGLE_SOUND_DEBUG("DDriverBeagleSoundScPdd::SetCaps TxPdd");
|
|
274 |
|
|
275 |
if(iUnitType == KSoundScTxUnit0)
|
|
276 |
{
|
|
277 |
// The data transfer direction for this unit is play
|
|
278 |
iCaps.iDirection = ESoundDirPlayback;
|
|
279 |
}
|
|
280 |
else if(iUnitType == KSoundScRxUnit0)
|
|
281 |
{
|
|
282 |
// The data transfer direction for this unit is record
|
|
283 |
iCaps.iDirection = ESoundDirRecord;
|
|
284 |
}
|
|
285 |
|
|
286 |
// This unit supports both mono and stereo
|
|
287 |
iCaps.iChannels = (KSoundMonoChannel | KSoundStereoChannel);
|
|
288 |
|
|
289 |
// This unit supports only some of the sample rates offered by Symbian OS
|
|
290 |
iCaps.iRates = (KSoundRate8000Hz | KSoundRate11025Hz | KSoundRate12000Hz | KSoundRate16000Hz |
|
|
291 |
KSoundRate22050Hz | KSoundRate24000Hz | KSoundRate32000Hz | KSoundRate44100Hz |
|
|
292 |
KSoundRate48000Hz);
|
|
293 |
|
|
294 |
// This unit only supports 16bit PCM encoding
|
|
295 |
iCaps.iEncodings = KSoundEncoding16BitPCM;
|
|
296 |
|
|
297 |
// This unit only supports interleaved data format when playing stereo; that is, a PCM data
|
|
298 |
// stream where the left and right channel samples are interleaved as L-R-L-R-L-R etc.
|
|
299 |
iCaps.iDataFormats = KSoundDataFormatInterleaved;
|
|
300 |
|
|
301 |
// The iRequestMinSize member is named badly. It is actually the value of which the length samples
|
|
302 |
// must be a multiple of. ie. The sample length % iRequestMinSize must == 0. This value must always
|
|
303 |
// be a power of 2
|
|
304 |
iCaps.iRequestMinSize = 4;
|
|
305 |
|
|
306 |
// The logarithm to base 2 of the alignment required for request arguments. DMA requests must be
|
|
307 |
// aligned to a 32 bit boundary
|
|
308 |
iCaps.iRequestAlignment = 2;
|
|
309 |
|
|
310 |
// This unit is not capable of detecting changes in hardware configuration
|
|
311 |
iCaps.iHwConfigNotificationSupport = EFalse;
|
|
312 |
}
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|