[Scummvm-cvs-logs] SF.net SVN: scummvm: [29499] scummvm/trunk/backends/platform/iphone

vinterstum at users.sourceforge.net vinterstum at users.sourceforge.net
Tue Nov 13 22:21:17 CET 2007


Revision: 29499
          http://scummvm.svn.sourceforge.net/scummvm/?rev=29499&view=rev
Author:   vinterstum
Date:     2007-11-13 13:21:17 -0800 (Tue, 13 Nov 2007)

Log Message:
-----------
Added sound support for the iPhone

Modified Paths:
--------------
    scummvm/trunk/backends/platform/iphone/osys_iphone.cpp
    scummvm/trunk/backends/platform/iphone/osys_iphone.h

Modified: scummvm/trunk/backends/platform/iphone/osys_iphone.cpp
===================================================================
--- scummvm/trunk/backends/platform/iphone/osys_iphone.cpp	2007-11-13 19:49:01 UTC (rev 29498)
+++ scummvm/trunk/backends/platform/iphone/osys_iphone.cpp	2007-11-13 21:21:17 UTC (rev 29499)
@@ -50,6 +50,10 @@
 	{0, 0, 0}
 };
 
+AQCallbackStruct OSystem_IPHONE::s_AudioQueue;
+SoundProc OSystem_IPHONE::s_soundCallback = NULL;
+void *OSystem_IPHONE::s_soundParam = NULL;
+
 OSystem_IPHONE::OSystem_IPHONE() :
 	_savefile(NULL), _mixer(NULL), _timer(NULL), _offscreen(NULL),
 	_overlayVisible(false), _overlayBuffer(NULL), _fullscreen(NULL),
@@ -572,7 +576,54 @@
 	free(mutex);
 }
 
+void OSystem_IPHONE::AQBufferCallback(void *in, AudioQueueRef inQ, AudioQueueBufferRef outQB) {
+	//printf("AQBufferCallback()\n");
+	if (s_AudioQueue.frameCount > 0 && s_soundCallback != NULL) {
+		outQB->mAudioDataByteSize = 4 * s_AudioQueue.frameCount;
+		s_soundCallback(s_soundParam, (byte *)outQB->mAudioData, outQB->mAudioDataByteSize);
+		AudioQueueEnqueueBuffer(inQ, outQB, 0, NULL);
+	} else {
+		AudioQueueStop(s_AudioQueue.queue, false);
+	}
+}
+
 bool OSystem_IPHONE::setSoundCallback(SoundProc proc, void *param) {
+	//printf("setSoundCallback()\n");
+	s_soundCallback = proc;
+	s_soundParam = param;
+
+	s_AudioQueue.dataFormat.mSampleRate = AUDIO_SAMPLE_RATE;
+	s_AudioQueue.dataFormat.mFormatID = kAudioFormatLinearPCM;
+	s_AudioQueue.dataFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
+	s_AudioQueue.dataFormat.mBytesPerPacket = 4;
+	s_AudioQueue.dataFormat.mFramesPerPacket = 1;
+	s_AudioQueue.dataFormat.mBytesPerFrame = 4;
+	s_AudioQueue.dataFormat.mChannelsPerFrame = 2;
+	s_AudioQueue.dataFormat.mBitsPerChannel = 16;
+	s_AudioQueue.frameCount = WAVE_BUFFER_SIZE;
+
+	if (AudioQueueNewOutput(&s_AudioQueue.dataFormat, AQBufferCallback, &s_AudioQueue, 0, kCFRunLoopCommonModes, 0, &s_AudioQueue.queue)) {
+		printf("Couldn't set the AudioQueue callback!\n");
+		return false;
+	}
+
+	uint32 bufferBytes = s_AudioQueue.frameCount * s_AudioQueue.dataFormat.mBytesPerFrame;
+
+	for (int i = 0; i < AUDIO_BUFFERS; i++) {
+		if (AudioQueueAllocateBuffer(s_AudioQueue.queue, bufferBytes, &s_AudioQueue.buffers[i])) {
+			printf("Error allocating AudioQueue buffer!\n");
+			return false;
+		}
+
+		AQBufferCallback(&s_AudioQueue, s_AudioQueue.queue, s_AudioQueue.buffers[i]);
+	}	
+
+	AudioQueueSetParameter(s_AudioQueue.queue, kAudioQueueParam_Volume, 1.0);
+	if (AudioQueueStart(s_AudioQueue.queue, NULL)) {
+		printf("Error starting the AudioQueue!\n");
+		return false;
+	}
+
 	return true;
 }
 
@@ -580,11 +631,11 @@
 }
 
 int OSystem_IPHONE::getOutputSampleRate() const {
-	return 22050;
+	return AUDIO_SAMPLE_RATE;
 }
 
 void OSystem_IPHONE::quit() {
-	//exit(0);
+	AudioQueueDispose(s_AudioQueue.queue, true);
 }
 
 void OSystem_IPHONE::setWindowCaption(const char *caption) {

Modified: scummvm/trunk/backends/platform/iphone/osys_iphone.h
===================================================================
--- scummvm/trunk/backends/platform/iphone/osys_iphone.h	2007-11-13 19:49:01 UTC (rev 29498)
+++ scummvm/trunk/backends/platform/iphone/osys_iphone.h	2007-11-13 21:21:17 UTC (rev 29499)
@@ -27,24 +27,28 @@
 
 #include "graphics/surface.h"
 
-// #include <AudioToolbox/AudioQueue.h>
-// 
-// /* Audio Resources */
-// #define AUDIO_BUFFERS 3
-// #define AUDIO_PRECACHE 4
-// #define WAVE_BUFFER_SIZE 735
-// #define WAVE_BUFFER_BANKS 25
-// 
-// typedef struct AQCallbackStruct {
-//     AudioQueueRef queue;
-//     UInt32 frameCount;
-//     AudioQueueBufferRef mBuffers[AUDIO_BUFFERS];
-//     AudioStreamBasicDescription mDataFormat;
-// } AQCallbackStruct;
+#include <AudioToolbox/AudioQueue.h>
 
+#define AUDIO_BUFFERS 3
+#define WAVE_BUFFER_SIZE 735
+#define AUDIO_SAMPLE_RATE 44100
+
+typedef void (*SoundProc)(void *param, byte *buf, int len);
+ 
+typedef struct AQCallbackStruct {
+    AudioQueueRef queue;
+    uint32 frameCount;
+    AudioQueueBufferRef buffers[AUDIO_BUFFERS];
+    AudioStreamBasicDescription dataFormat;
+} AQCallbackStruct;
+
 class OSystem_IPHONE : public OSystem {
 protected:
+
 	static const OSystem::GraphicsMode s_supportedGraphicsModes[];
+	static AQCallbackStruct s_AudioQueue;
+	static SoundProc s_soundCallback;
+	static void *s_soundParam;
 	
 	Common::SaveFileManager *_savefile;
 	Audio::Mixer *_mixer;
@@ -127,7 +131,6 @@
 	virtual void unlockMutex(MutexRef mutex);
 	virtual void deleteMutex(MutexRef mutex);
 
-	typedef void (*SoundProc)(void *param, byte *buf, int len);
 	virtual bool setSoundCallback(SoundProc proc, void *param);
 	virtual void clearSoundCallback();
 	virtual int getOutputSampleRate() const;
@@ -139,6 +142,9 @@
 	virtual Common::SaveFileManager *getSavefileManager();
 	virtual Audio::Mixer *getMixer();
 	virtual Common::TimerManager *getTimerManager();
+	
+protected:
+	static void AQBufferCallback(void *in, AudioQueueRef inQ, AudioQueueBufferRef outQB);
 };
 
 #endif


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list