Просмотр исходного кода

Restored OGG loading functionality in new audio system

Ivan Safrin 10 лет назад
Родитель
Сommit
e2d71a2d90

+ 4 - 4
build/osx/TemplateApp/TemplateApp.xcodeproj/project.pbxproj

@@ -9,7 +9,6 @@
 /* Begin PBXBuildFile section */
 		6D6FD3E11BF122A2005AA8E9 /* PolycodeView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6D6FD3E01BF122A2005AA8E9 /* PolycodeView.mm */; };
 		6DD2D0B61BEEDC150026D85C /* libportaudio.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6DD2D0B51BEEDC150026D85C /* libportaudio.a */; };
-		6DD2D0B81BEEDCC90026D85C /* white.png in Resources */ = {isa = PBXBuildFile; fileRef = 6DD2D0B71BEEDCC80026D85C /* white.png */; };
 		8A825F271B82A2680039E823 /* libportaudio.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A825F261B82A2680039E823 /* libportaudio.a */; };
 		8A825F291B82A29B0039E823 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A825F281B82A29B0039E823 /* CoreAudio.framework */; };
 		8A825F2E1B82A2C80039E823 /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A825F2C1B82A2B10039E823 /* AudioUnit.framework */; };
@@ -31,12 +30,12 @@
 		8A86536B1B729559009F94DD /* PolycodeTemplateApp.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8A86536A1B729559009F94DD /* PolycodeTemplateApp.mm */; };
 		8A8653701B72C431009F94DD /* default.pak in Resources */ = {isa = PBXBuildFile; fileRef = 8A86536F1B72C431009F94DD /* default.pak */; };
 		8A8653961B752DBE009F94DD /* main_icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 8A8653951B752DBE009F94DD /* main_icon.png */; };
+		8A9D4BE31BF25DE0002FD7DD /* BUGSHUFFLE.ogg in Resources */ = {isa = PBXBuildFile; fileRef = 8A9D4BE21BF25DE0002FD7DD /* BUGSHUFFLE.ogg */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
 		6D6FD3E01BF122A2005AA8E9 /* PolycodeView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = PolycodeView.mm; path = ../../../../src/view/osx/PolycodeView.mm; sourceTree = "<group>"; };
 		6DD2D0B51BEEDC150026D85C /* libportaudio.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libportaudio.a; path = ../../../../lib/osx/libportaudio.a; sourceTree = "<group>"; };
-		6DD2D0B71BEEDCC80026D85C /* white.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = white.png; path = ../../../../../THU/HELLMOUTH/App/Resources/Resources/textures/white.png; sourceTree = "<group>"; };
 		8A825F261B82A2680039E823 /* libportaudio.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libportaudio.a; path = ../../../../lib/osx/libportaudio.a; sourceTree = "<group>"; };
 		8A825F281B82A29B0039E823 /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; };
 		8A825F2A1B82A2A50039E823 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
@@ -63,6 +62,7 @@
 		8A86536E1B72C301009F94DD /* PolycodeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolycodeView.h; path = ../../../../include/polycode/view/osx/PolycodeView.h; sourceTree = "<group>"; };
 		8A86536F1B72C431009F94DD /* default.pak */ = {isa = PBXFileReference; lastKnownFileType = file; name = default.pak; path = ../../../../assets/default/default.pak; sourceTree = "<group>"; };
 		8A8653951B752DBE009F94DD /* main_icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = main_icon.png; path = ../../../../assets/icons/main_icon.png; sourceTree = "<group>"; };
+		8A9D4BE21BF25DE0002FD7DD /* BUGSHUFFLE.ogg */ = {isa = PBXFileReference; lastKnownFileType = file; name = BUGSHUFFLE.ogg; path = ../../../../../Hellmouth/Resources/Sounds/music/BUGSHUFFLE.ogg; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -119,10 +119,10 @@
 				8A8653351B72931C009F94DD /* AppDelegate.h */,
 				8A8653361B72931C009F94DD /* AppDelegate.m */,
 				6D6FD3E01BF122A2005AA8E9 /* PolycodeView.mm */,
+				8A9D4BE21BF25DE0002FD7DD /* BUGSHUFFLE.ogg */,
 				8A86536E1B72C301009F94DD /* PolycodeView.h */,
 				8A86536F1B72C431009F94DD /* default.pak */,
 				8A86533A1B72931C009F94DD /* Images.xcassets */,
-				6DD2D0B71BEEDCC80026D85C /* white.png */,
 				8A8653951B752DBE009F94DD /* main_icon.png */,
 				8A86533C1B72931C009F94DD /* MainMenu.xib */,
 				8A8653331B72931C009F94DD /* Supporting Files */,
@@ -207,10 +207,10 @@
 			isa = PBXResourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				6DD2D0B81BEEDCC90026D85C /* white.png in Resources */,
 				8A86533B1B72931C009F94DD /* Images.xcassets in Resources */,
 				8A8653961B752DBE009F94DD /* main_icon.png in Resources */,
 				8A86533E1B72931C009F94DD /* MainMenu.xib in Resources */,
+				8A9D4BE31BF25DE0002FD7DD /* BUGSHUFFLE.ogg in Resources */,
 				8A8653701B72C431009F94DD /* default.pak in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;

+ 2 - 0
build/osx/TemplateApp/TemplateApp/PolycodeTemplateApp.mm

@@ -25,6 +25,8 @@ PolycodeTemplateApp::PolycodeTemplateApp(PolycodeView *view) {
     test->scissorBox.setRect(100, 50, 100, 30);
     scene->addChild(test);
     
+    Sound *music = new Sound("BUGSHUFFLE.ogg");
+    music->Play();
     
     Services()->getInput()->addEventListener(this, InputEvent::EVENT_KEYDOWN);
 }

+ 0 - 1
include/polycode/core/PolySound.h

@@ -156,7 +156,6 @@ namespace Polycode {
         */
         // NOAL_TODO
         
-		void soundError(const String& err);
 		void soundCheck(bool result, const String& err);
 		static unsigned long readByte32(const unsigned char buffer[4]);		
 		static unsigned short readByte16(const unsigned char buffer[2]);

+ 17 - 51
src/core/PolySound.cpp

@@ -174,11 +174,7 @@ Sound::~Sound() {
 
 void Sound::soundCheck(bool result, const String& err) {
 	if(!result)
-		soundError(err);
-}
-
-void Sound::soundError(const String& err) {
-	Logger::log("SOUND ERROR: %s\n", err.c_str());
+		Logger::log(err);
 }
 
 unsigned long Sound::readByte32(const unsigned char data[4]) {
@@ -372,6 +368,8 @@ Number Sound::getSampleAsNumber(unsigned int offset, unsigned int channel) {
 
 bool Sound::loadBytes(const char *data, int size, int channels, unsigned int freq, SoundFormat format) {
     
+    printf("LOADING %d bytes in %d channels of %d freq\n", size, channels, freq);
+    
     if(format == SoundFormatUnsupported) {
         Logger::log("[%s] Error: sound format unsupported!\n", fileName.c_str());
         return false;
@@ -397,7 +395,6 @@ bool Sound::loadBytes(const char *data, int size, int channels, unsigned int fre
         break;
     }
     
-    
     for(int i=0; i < numSamples; i++){
         for(int c=0; c < channels; c++) {
             switch(format) {
@@ -431,24 +428,16 @@ unsigned int Sound::getFrequency() {
 
 bool Sound::loadOGG(const String& fileName) {
 #ifndef NO_OGG
-    /*
-//	floatBuffer.clear();
+
 	vector<char> data;
-	
-	alGenBuffers(1, &buffer);
-	int endian = 0;             // 0 for Little-Endian, 1 for Big-Endian
 	int bitStream;
 	long bytes;
-	char array[BUFFER_SIZE];    // Local fixed size array
-	CoreFile *f;
-	ALenum format;
-	ALsizei freq;
+	char array[BUFFER_SIZE];
 	
-	// Open for binary reading
-	f = Services()->getCore()->openFile(fileName.c_str(), "rb");
+	CoreFile *f = Services()->getCore()->openFile(fileName.c_str(), "rb");
 	if(!f) {
-		soundError("Error loading OGG file!\n");
-		return buffer;
+        Logger::log("Error loading OGG file!\n");
+        return false;
 	}
 	vorbis_info *pInfo;
 	OggVorbis_File oggFile;	
@@ -460,39 +449,18 @@ bool Sound::loadOGG(const String& fileName) {
 	callbacks.tell_func = custom_tellfunc;
 	
 	ov_open_callbacks( (void*)f, &oggFile, NULL, 0, callbacks);
-//	ov_open(f, &oggFile, NULL, 0);
-	// Get some information about the OGG file
 	pInfo = ov_info(&oggFile, -1);
-	
-	// Check the number of channels... always use 16-bit samples
-	if (pInfo->channels == 1)
-		format = AL_FORMAT_MONO16;
-	else
-		format = AL_FORMAT_STEREO16;
-	// end if
-	
-	// The frequency of the sampling rate
-	freq = pInfo->rate;	
+
 	do {
-		// Read up to a buffer's worth of decoded sound data
-		bytes = ov_read(&oggFile, array, BUFFER_SIZE, endian, 2, 1, &bitStream);
-		// Append to end of buffer
+		bytes = ov_read(&oggFile, array, BUFFER_SIZE, 0, 2, 1, &bitStream);
 		data.insert(data.end(), array, array + bytes);
 	} while (bytes > 0);
+    
+    bool retVal = loadBytes(data.data(), data.size(), pInfo->channels, pInfo->rate, SoundFormat16);
 	ov_clear(&oggFile);
-	
-	sampleLength = data.size() / sizeof(unsigned short);
-	
-	alBufferData(buffer, format, &data[0], static_cast<ALsizei>(data.size()), freq);
-	
-	if(generateFloatBuffer) {
-		int32_t *ptr32 = (int32_t*) &data[0];
-		for(int i=0; i < data.size()/4; i++ ) {
-			floatBuffer.push_back(((Number)ptr32[i])/((Number)INT32_MAX));
-		}	
-	}
-     */
-	return false;
+    return retVal;
+#else
+    return false;
 #endif
 }
 
@@ -508,7 +476,7 @@ bool Sound::loadWAV(const String& fileName) {
     // Open for binary reading
     f = Services()->getCore()->openFile(fileName.c_str(), "rb");
     if (!f) {
-        soundError("LoadWav: Could not load wav from " + fileName);
+        Logger::log("LoadWav: Could not load wav from " + fileName);
         return false;
     }
     
@@ -601,9 +569,7 @@ bool Sound::loadWAV(const String& fileName) {
     
     Services()->getCore()->closeFile(f);
     f = NULL;
-    
-    
-    
+
     return loadBytes(&data[0], data.size(), channels, frequency, format);
 
 }