Exemplo n.º 1
0
AudioBuffer* AudioManager::load(const std::string& filePath,DataStream* stream){
	AudioBuffer* ret=find(filePath);
	if(ret!=0){
		return ret;
	}
	unsigned char* wavBuffer=0;
	do{
		BasicWAVEHeader header;
		wavBuffer=loadwav(stream->data(),stream->size(),&header);
		if(!wavBuffer){
			DebugLog("Load audio failed:%s",filePath.c_str());
			break;
		}

		ALuint buffer= createBufferFromWave(wavBuffer,header);
		if(!buffer){
			DebugLog("Create Buffer From Wave Failed");
			break;
		}
		ret=new AudioBuffer(buffer,filePath);
		_bufferMap[filePath]=ret;
		DebugLog("load %s success!",filePath.c_str());
	}while(0);
	TC_DELETE_ARRAY(wavBuffer);
	return ret;
}
Exemplo n.º 2
0
    result Wav::testAndLoadFile(MemoryFile *aReader)
    {
		delete[] mData;
		mData = 0;
		mSampleCount = 0;
		mChannels = 1;
        int tag = aReader->read32();
		if (tag == MAKEDWORD('O','g','g','S')) 
        {
			return loadogg(aReader);

		} 
        else if (tag == MAKEDWORD('R','I','F','F')) 
        {
			return loadwav(aReader);
		}
		else if (tag == MAKEDWORD('f', 'L', 'a', 'C'))
		{
			return loadflac(aReader);
		}
		else if (loadmp3(aReader) == SO_NO_ERROR)
		{
			return SO_NO_ERROR;
		}

		return FILE_LOAD_FAILED;
    }
Exemplo n.º 3
0
    int Wav::testAndLoadFile(DataReader *aReader)
    {
		delete[] mData;
		mData = 0;
		mSampleCount = 0;
        int tag = aReader->read32();
		if (tag == MAKEDWORD('O','g','g','S')) 
        {
		 	aReader->seek(0);
			int e = 0;
			stb_vorbis *v = 0;
			if (aReader->isMemoryFile())
            {
				v = stb_vorbis_open_memory(aReader->currentData(), aReader->dataLength(), &e, 0);
            }
			else
            {
				v = stb_vorbis_open_file(aReader->filePtr(), 0, &e, 0);
            }

			if (0 != v)
            {
				return loadogg(v);
            }
			return FILE_LOAD_FAILED;
		} 
        else if (tag == MAKEDWORD('R','I','F','F')) 
        {
			return loadwav(aReader);
		}
		return FILE_LOAD_FAILED;
    }
Exemplo n.º 4
0
    result Wav::testAndLoadFile(File *aReader)
    {
		delete[] mData;
		mData = 0;
		mSampleCount = 0;
        int tag = aReader->read32();
		if (tag == MAKEDWORD('O','g','g','S')) 
        {
			return loadogg(aReader);

		} 
        else if (tag == MAKEDWORD('R','I','F','F')) 
        {
			return loadwav(aReader);
		}
		return FILE_LOAD_FAILED;
    }
Exemplo n.º 5
0
	result WavStream::parse(File *aFile)
	{
		int tag = aFile->read32();
		int res = SO_NO_ERROR;
		if (tag == MAKEDWORD('O', 'g', 'g', 'S'))
		{
			res = loadogg(aFile);
		}
		else
		if (tag == MAKEDWORD('R', 'I', 'F', 'F'))
		{
			res = loadwav(aFile);
		}
		else
		{
			res = FILE_LOAD_FAILED;
		}
		return res;
	}
Exemplo n.º 6
0
	void WavStream::load(const char *aFilename)
	{
		delete[] mFilename;
		mFilename = 0;
		mSampleCount = 0;
		FILE * fp = fopen(aFilename, "rb");
		if (!fp) return;
		int tag = read32(fp);
		if (tag == MAKEDWORD('O','g','g','S'))
		{
			loadogg(fp);
		}
		if (tag == MAKEDWORD('R','I','F','F'))
		{
			loadwav(fp);
		}

		int len = strlen(aFilename);
		mFilename = new char[len+1];
		memcpy(mFilename, aFilename, len);
		mFilename[len] = 0;

		fclose(fp);
	}