annotate src/audio/symbian/SDL_epocaudio.cpp @ 4005:fb74445b4d19 SDL-1.2

Added Markus Mertama to the CREDITS file for the S60 port.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 05 Jul 2007 04:53:36 +0000
parents e85e65aec22f
children a1b03ba2fcd0
rev   line source
3975
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 Library General Public License for more details.
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 Sam Lantinga
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 slouken@devolution.com
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 /*
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 SDL_epocaudio.cpp
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 Epoc based SDL audio driver implementation
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 Markus Mertama
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 #ifdef SAVE_RCSID
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 static char rcsid =
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 "@(#) $Id: SDL_epocaudio.c,v 0.0.0.0 2001/06/19 17:19:56 hercules Exp $";
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 #include <stdlib.h>
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 #include <stdio.h>
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 #include <string.h>
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 #include <errno.h>
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 #include <unistd.h>
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 #include <fcntl.h>
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 #include <signal.h>
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 #include <sys/time.h>
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 #include <sys/ioctl.h>
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 #include <sys/stat.h>
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 #include "epoc_sdl.h"
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 #include <e32hal.h>
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 extern "C" {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 #include "SDL_audio.h"
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 #include "SDL_error.h"
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 #include "SDL_audiomem.h"
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 #include "SDL_audio_c.h"
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 #include "SDL_timer.h"
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 #include "SDL_audiodev_c.h"
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 #include "SDL_epocaudio.h"
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 #include "streamplayer.h"
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 //#define DEBUG_AUDIO
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 /* Audio driver functions */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 static int EPOC_OpenAudio(SDL_AudioDevice *thisdevice, SDL_AudioSpec *spec);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 static void EPOC_WaitAudio(SDL_AudioDevice *thisdevice);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 static void EPOC_PlayAudio(SDL_AudioDevice *thisdevice);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 static Uint8 *EPOC_GetAudioBuf(SDL_AudioDevice *thisdevice);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 static void EPOC_CloseAudio(SDL_AudioDevice *thisdevice);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 static void EPOC_ThreadInit(SDL_AudioDevice *thisdevice);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 static int Audio_Available(void);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 static SDL_AudioDevice *Audio_CreateDevice(int devindex);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 static void Audio_DeleteDevice(SDL_AudioDevice *device);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 //void sos_adump(SDL_AudioDevice* thisdevice, void* data, int len);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 #ifdef __WINS__
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 #define DODUMP
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89 #ifdef DODUMP
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 NONSHARABLE_CLASS(TDump)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 public:
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 TInt Open();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 void Close();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 void Dump(const TDesC8& aDes);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 private:
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 RFile iFile;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 RFs iFs;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 };
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 TInt TDump::Open()
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 TInt err = iFs.Connect();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 if(err == KErrNone)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 #ifdef __WINS__
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 _LIT(target, "C:\\sdlau.raw");
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108 #else
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 _LIT(target, "E:\\sdlau.raw");
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 err = iFile.Replace(iFs, target, EFileWrite);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 return err;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 void TDump::Close()
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 iFile.Close();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 iFs.Close();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 void TDump::Dump(const TDesC8& aDes)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 iFile.Write(aDes);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 NONSHARABLE_CLASS(CSimpleWait) : public CTimer
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 public:
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 void Wait(TTimeIntervalMicroSeconds32 aWait);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 static CSimpleWait* NewL();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 private:
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 CSimpleWait();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 void RunL();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 };
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 CSimpleWait* CSimpleWait::NewL()
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 CSimpleWait* wait = new (ELeave) CSimpleWait();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 CleanupStack::PushL(wait);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 wait->ConstructL();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 CleanupStack::Pop();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 return wait;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 void CSimpleWait::Wait(TTimeIntervalMicroSeconds32 aWait)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 After(aWait);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 CActiveScheduler::Start();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 CSimpleWait::CSimpleWait() : CTimer(CActive::EPriorityStandard)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 CActiveScheduler::Add(this);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 void CSimpleWait::RunL()
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 CActiveScheduler::Stop();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 const TInt KAudioBuffers(2);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 NONSHARABLE_CLASS(CEpocAudio) : public CBase, public MStreamObs, public MStreamProvider
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 public:
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 static void* NewL(TInt BufferSize, TInt aFill);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 inline static CEpocAudio& Current(SDL_AudioDevice* thisdevice);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 static void Free(SDL_AudioDevice* thisdevice);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 void Wait();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 void Play();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 // void SetBuffer(const TDesC8& aBuffer);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177 void ThreadInitL(TAny* aDevice);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 void Open(TInt iRate, TInt iChannels, TUint32 aType, TInt aBytes);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 ~CEpocAudio();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 TUint8* Buffer();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 TBool SetPause(TBool aPause);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 #ifdef DODUMP
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 void Dump(const TDesC8& aBuf) {iDump.Dump(aBuf);}
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 private:
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 CEpocAudio(TInt aBufferSize);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 void Complete(TInt aState, TInt aError);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 TPtrC8 Data();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 void ConstructL(TInt aFill);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 private:
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 TInt iBufferSize;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 CStreamPlayer* iPlayer;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 TInt iBufferRate;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 TInt iRate;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195 TInt iChannels;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 TUint32 iType;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 TInt iPosition;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 TThreadId iTid;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 TUint8* iAudioPtr;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 TUint8* iBuffer;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201 // TTimeIntervalMicroSeconds iStart;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 TTime iStart;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203 TInt iTune;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204 CSimpleWait* iWait;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 #ifdef DODUMP
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 TDump iDump;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208 };
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 inline CEpocAudio& CEpocAudio::Current(SDL_AudioDevice* thisdevice)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 return *static_cast<CEpocAudio*>((void*)thisdevice->hidden);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 /*
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 TBool EndSc(TAny*)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219 CActiveScheduler::Stop();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 LOCAL_C void CleanScL()
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224 CIdle* d = CIdle::NewLC(CActive:::EPriorityIdle);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225 d->Start(TCallBack(EndSc));
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 CActiveScheduler::Start();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229 */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
230
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231 void CEpocAudio::Free(SDL_AudioDevice* thisdevice)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
233 CEpocAudio* ea = static_cast<CEpocAudio*>((void*)thisdevice->hidden);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 if(ea)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236 ASSERT(ea->iTid == RThread().Id());
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
237 delete ea;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238 thisdevice->hidden = NULL;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
240 CActiveScheduler* as = CActiveScheduler::Current();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
241 ASSERT(as->StackDepth() == 0);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242 delete as;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
243 CActiveScheduler::Install(NULL);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
244 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
245 ASSERT(thisdevice->hidden == NULL);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
246 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
247
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
248 CEpocAudio::CEpocAudio(TInt aBufferSize) : iBufferSize(aBufferSize), iPosition(-1)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 void* CEpocAudio::NewL(TInt aBufferSize, TInt aFill)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
254 CEpocAudio* eAudioLib = new (ELeave) CEpocAudio(aBufferSize);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
255 CleanupStack::PushL(eAudioLib);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
256 eAudioLib->ConstructL(aFill);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
257 CleanupStack::Pop();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
258 return eAudioLib;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
259 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
260
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
261 void CEpocAudio::ConstructL(TInt aFill)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
262 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
263 iBuffer = (TUint8*) User::AllocL(KAudioBuffers * iBufferSize);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
264 memset(iBuffer, aFill, KAudioBuffers * iBufferSize);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
265 iAudioPtr = iBuffer;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
266 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
267
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
268
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
269 TBool CEpocAudio::SetPause(TBool aPause)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
270 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
271 if(aPause && iPosition >= 0)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
272 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
273 iPosition = -1;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
274 if(iPlayer != NULL)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
275 iPlayer->Stop();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
276 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
277 if(!aPause && iPosition < 0)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
278 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
279 iPosition = 0;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
280 if(iPlayer != NULL)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
281 iPlayer->Start();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
282 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
283 return iPosition < 0;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
284 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
285
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
286 void CEpocAudio::ThreadInitL(TAny* aDevice)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
287 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
288 iTid = RThread().Id();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
289 CActiveScheduler* as = new (ELeave) CActiveScheduler();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
290 CActiveScheduler::Install(as);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
291
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
292 EpocSdlEnv::AppendCleanupItem(TSdlCleanupItem((TSdlCleanupOperation)EPOC_CloseAudio, aDevice));
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
293
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
294 iWait = CSimpleWait::NewL();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
295
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
296 iPlayer = new (ELeave) CStreamPlayer(*this, *this);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
297 iPlayer->ConstructL();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
298 iPlayer->OpenStream(iRate, iChannels, iType);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
299
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
300 #ifdef DODUMP
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
301 User::LeaveIfError(iDump.Open());
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
302 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
303 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
304
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
305
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
306
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
307 TUint8* CEpocAudio::Buffer()
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
308 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
309 iStart.UniversalTime();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
310 // iStart = iPlayer->Position();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
311 return iAudioPtr;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
312
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
313 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
314
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
315 CEpocAudio::~CEpocAudio()
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
316 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
317 if(iWait != NULL)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
318 iWait->Cancel();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
319 delete iWait;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
320 if(iPlayer != NULL)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
321 iPlayer->Close();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
322 delete iPlayer;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
323 delete iBuffer;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
324 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
325
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
326 void CEpocAudio::Complete(TInt aState, TInt aError)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
327 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
328 if(aState == MStreamObs::EClose)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
329 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
330 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
331 if(iPlayer->Closed())
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
332 return;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
333 switch(aError)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
334 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
335 case KErrUnderflow:
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
336 case KErrInUse:
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
337 iPlayer->Start();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
338 break;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
339 case KErrAbort:
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
340 iPlayer->Open();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
341 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
342 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
343
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
344
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
345 void sos_adump(SDL_AudioDevice* thisdevice, void* data, int len)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
346 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
347 #ifdef DODUMP
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
348 const TPtrC8 buf((TUint8*)data, len);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
349 CEpocAudio::Current(thisdevice).Dump(buf);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
350 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
351 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
352
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
353 const TInt KClip(256);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
354
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
355 TPtrC8 CEpocAudio::Data()
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
356 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
357 if(iPosition < 0)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
358 return KNullDesC8();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
359
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
360 TPtrC8 data(iAudioPtr + iPosition, KClip);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
361
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
362 #ifdef DODUMP
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
363 iDump.Dump(data);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
364 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
365
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
366 iPosition += KClip;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
367 if(iPosition >= iBufferSize)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
368 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
369
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
370 /* if(iAudioPtr == iBuffer)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
371 iAudioPtr = iBuffer + iBufferSize;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
372 else
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
373 iAudioPtr = iBuffer;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
374 */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
375 iAudioPtr += iBufferSize;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
376
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
377 if((iAudioPtr - iBuffer) >= KAudioBuffers * iBufferSize)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
378 iAudioPtr = iBuffer;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
379
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
380 iPosition = -1;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
381 if(iWait->IsActive())
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
382 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
383 iWait->Cancel();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
384 CActiveScheduler::Stop();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
385 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
386 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
387 return data;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
388 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
389
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
390
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
391
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
392
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
393 void CEpocAudio::Play()
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
394 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
395 iPosition = 0;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
396 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
397
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
398 void CEpocAudio::Wait()
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
399 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
400 if(iPosition >= 0 /*&& iPlayer->Playing()*/)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
401 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
402 const TInt64 bufMs = TInt64(iBufferSize - KClip) * TInt64(1000000);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
403 const TInt64 specTime = bufMs / TInt64(iRate * iChannels * 2);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
404 iWait->After(specTime);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
405
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
406 CActiveScheduler::Start();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
407 TTime end;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
408 end.UniversalTime();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
409 const TTimeIntervalMicroSeconds delta = end.MicroSecondsFrom(iStart);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
410
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
411
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
412 // const TTimeIntervalMicroSeconds end = iPlayer->Position();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
413
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
414
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
415
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
416
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
417 const TInt diff = specTime - delta.Int64();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
418
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
419 if(diff > 0 && diff < 200000)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
420 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
421 User::After(diff);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
422 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
423
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
424 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
425 else
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
426 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
427 User::After(10000);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
428 // iWait->Wait(10000); //just give some time...
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
429 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
430 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
431
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
432 void CEpocAudio::Open(TInt aRate, TInt aChannels, TUint32 aType, TInt aBytes)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
433 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
434 iRate = aRate;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
435 iChannels = aChannels;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
436 iType = aType;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
437 iBufferRate = iRate * iChannels * aBytes; //1/x
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
438 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
439
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
440
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
441 /* Audio driver bootstrap functions */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
442
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
443 AudioBootStrap EPOCAudio_bootstrap = {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
444 "epoc\0\0\0",
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
445 "EPOC streaming audio\0\0\0",
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
446 Audio_Available,
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
447 Audio_CreateDevice
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
448 };
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
449
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
450
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
451 static SDL_AudioDevice *Audio_CreateDevice(int /*devindex*/)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
452 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
453 SDL_AudioDevice *thisdevice;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
454
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
455 /* Initialize all variables that we clean on shutdown */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
456 thisdevice = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
457 if ( thisdevice ) {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
458 memset(thisdevice, 0, (sizeof *thisdevice));
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
459 thisdevice->hidden = NULL; /*(struct SDL_PrivateAudioData *)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
460 malloc((sizeof thisdevice->hidden)); */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
461 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
462 if ( (thisdevice == NULL) /*|| (thisdevice->hidden == NULL) */) {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
463 SDL_OutOfMemory();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
464 if ( thisdevice ) {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
465 free(thisdevice);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
466 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
467 return(0);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
468 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
469 // memset(thisdevice->hidden, 0, (sizeof *thisdevice->hidden));
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
470
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
471 /* Set the function pointers */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
472 thisdevice->OpenAudio = EPOC_OpenAudio;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
473 thisdevice->WaitAudio = EPOC_WaitAudio;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
474 thisdevice->PlayAudio = EPOC_PlayAudio;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
475 thisdevice->GetAudioBuf = EPOC_GetAudioBuf;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
476 thisdevice->CloseAudio = EPOC_CloseAudio;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
477 thisdevice->ThreadInit = EPOC_ThreadInit;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
478 thisdevice->free = Audio_DeleteDevice;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
479
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
480 return thisdevice;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
481 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
482
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
483
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
484 static void Audio_DeleteDevice(SDL_AudioDevice *device)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
485 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
486 //free(device->hidden);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
487 free(device);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
488 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
489
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
490 static int Audio_Available(void)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
491 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
492 return(1); // Audio stream modules should be always there!
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
493 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
494
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
495
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
496 static int EPOC_OpenAudio(SDL_AudioDevice *thisdevice, SDL_AudioSpec *spec)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
497 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
498 SDL_TRACE("SDL:EPOC_OpenAudio");
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
499
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
500
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
501 TUint32 type = KMMFFourCCCodePCM16;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
502 TInt bytes = 2;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
503
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
504 switch(spec->format)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
505 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
506 case AUDIO_U16LSB:
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
507 type = KMMFFourCCCodePCMU16;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
508 break;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
509 case AUDIO_S16LSB:
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
510 type = KMMFFourCCCodePCM16;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
511 break;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
512 case AUDIO_U16MSB:
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
513 type = KMMFFourCCCodePCMU16B;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
514 break;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
515 case AUDIO_S16MSB:
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
516 type = KMMFFourCCCodePCM16B;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
517 break;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
518 //8 bit not supported!
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
519 case AUDIO_U8:
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
520 case AUDIO_S8:
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
521 default:
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
522 spec->format = AUDIO_S16LSB;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
523 };
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
524
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
525
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
526
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
527 if(spec->channels > 2)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
528 spec->channels = 2;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
529
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
530 spec->freq = CStreamPlayer::ClosestSupportedRate(spec->freq);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
531
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
532
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
533 /* Allocate mixing buffer */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
534 const TInt buflen = spec->size;// * bytes * spec->channels;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
535 // audiobuf = NULL;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
536
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
537 TRAPD(err, thisdevice->hidden = static_cast<SDL_PrivateAudioData*>(CEpocAudio::NewL(buflen, spec->silence)));
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
538 if(err != KErrNone)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
539 return -1;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
540
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
541 CEpocAudio::Current(thisdevice).Open(spec->freq, spec->channels, type, bytes);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
542
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
543 CEpocAudio::Current(thisdevice).SetPause(ETrue);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
544
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
545 // isSDLAudioPaused = 1;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
546
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
547 thisdevice->enabled = 0; /* enable only after audio engine has been initialized!*/
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
548
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
549 /* We're ready to rock and roll. :-) */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
550 return(0);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
551 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
552
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
553
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
554 static void EPOC_CloseAudio(SDL_AudioDevice* thisdevice)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
555 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
556 #ifdef DEBUG_AUDIO
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
557 SDL_TRACE("Close audio\n");
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
558 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
559
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
560 CEpocAudio::Free(thisdevice);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
561 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
562
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
563
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
564 static void EPOC_ThreadInit(SDL_AudioDevice *thisdevice)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
565 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
566 SDL_TRACE("SDL:EPOC_ThreadInit");
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
567 CEpocAudio::Current(thisdevice).ThreadInitL(thisdevice);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
568 RThread().SetPriority(EPriorityMore);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
569 thisdevice->enabled = 1;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
570 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
571
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
572 /* This function waits until it is possible to write a full sound buffer */
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
573 static void EPOC_WaitAudio(SDL_AudioDevice* thisdevice)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
574 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
575 #ifdef DEBUG_AUDIO
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
576 SDL_TRACE1("wait %d audio\n", CEpocAudio::AudioLib().StreamPlayer(KSfxChannel).SyncTime());
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
577 TInt tics = User::TickCount();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
578 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
579
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
580 CEpocAudio::Current(thisdevice).Wait();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
581
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
582 #ifdef DEBUG_AUDIO
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
583 TInt ntics = User::TickCount() - tics;
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
584 SDL_TRACE1("audio waited %d\n", ntics);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
585 SDL_TRACE1("audio at %d\n", tics);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
586 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
587 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
588
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
589
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
590
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
591 static void EPOC_PlayAudio(SDL_AudioDevice* thisdevice)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
592 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
593 if(CEpocAudio::Current(thisdevice).SetPause(SDL_GetAudioStatus() == SDL_AUDIO_PAUSED))
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
594 SDL_Delay(500); //hold on the busy loop
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
595 else
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
596 CEpocAudio::Current(thisdevice).Play();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
597
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
598 #ifdef DEBUG_AUDIO
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
599 SDL_TRACE("buffer has audio data\n");
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
600 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
601
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
602
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
603 #ifdef DEBUG_AUDIO
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
604 SDL_TRACE1("Wrote %d bytes of audio data\n", buflen);
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
605 #endif
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
606 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
607
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
608 static Uint8 *EPOC_GetAudioBuf(SDL_AudioDevice* thisdevice)
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
609 {
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
610 return CEpocAudio::Current(thisdevice).Buffer();
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
611 }
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
612
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
613
e85e65aec22f Added S60 port.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
614