AudioFormat.cpp
Go to the documentation of this file.00001 //*** AudioFormat.cpp *** 00002 00003 #include "AudioFormat.h" 00004 #include "Debug.h" 00005 #include "Asset.h" 00006 #include "StandardLibrary.h" 00007 00008 Array<AudioFormat::AudioFormatEntry> AudioFormat::audioFormats_; 00009 00010 //*** RegisterAudioFormat *** 00011 00012 void AudioFormat::RegisterAudioFormat(bool (*TestFunction)(const Asset&),AudioFormat* (*CreateFunction)(const Asset&)) 00013 { 00014 AudioFormatEntry entry; 00015 entry.TestFunction=TestFunction; 00016 entry.CreateFunction=CreateFunction; 00017 audioFormats_.Add(entry); 00018 } 00019 00020 00021 //*** CreateAudioFormat *** 00022 00023 AudioFormat* AudioFormat::CreateAudioFormat(const Asset& asset) 00024 { 00025 // Make sure asset exists 00026 #ifdef _DEBUG 00027 if (!asset.Open()) 00028 { 00029 const char* filename=asset.GetFilename().GetString(); 00030 if (filename) 00031 { 00032 char errorMessage[1024]; 00033 SNPrintF(errorMessage,1024,"File not found: %s",filename); 00034 Assert(false,errorMessage); 00035 } 00036 else 00037 { 00038 Assert(false,"An asset could not be accessed."); 00039 } 00040 00041 return 0; 00042 } 00043 asset.Close(); 00044 #endif 00045 00046 for (int i=0; i<audioFormats_.GetItemCount(); i++) 00047 { 00048 AudioFormatEntry entry=audioFormats_.Get(i); 00049 if (entry.TestFunction(asset)) 00050 { 00051 return entry.CreateFunction(asset); 00052 } 00053 } 00054 00055 // Report unknown audio format 00056 #ifdef _DEBUG 00057 const char* filename=asset.GetFilename().GetString(); 00058 if (filename) 00059 { 00060 char errorMessage[1024]; 00061 SNPrintF(errorMessage,1024,"Unknown audio format: %s",filename); 00062 Assert(false,errorMessage); 00063 } 00064 else 00065 { 00066 Assert(false,"Unknown audio format."); 00067 } 00068 #endif 00069 00070 return 0; 00071 }
Reproduction/republishing of any material on this site without permission is strictly prohibited.
