예제 #1
0
int
main (int argc, char **argv)
{

	ALuint helloBuffer, helloSource;
	ALuint fileSize;
#define FILE_NAME "s2.snd"
	int n;	
	int16* buffer;
	FILE* file;

  // make sure s3esound is ready (tends to skip a few seconds of audio on startup)
	int channel = s3eSoundGetFreeChannel();
	int rate = s3eSoundChannelGetInt(channel, S3E_CHANNEL_RATE);
	int volume = s3eSoundChannelGetInt(channel, S3E_CHANNEL_VOLUME);
  
	//s3eAudioPlay(FILE_NAME, 1);
	//alutSleep(5);

	s3eSoundChannelRegister(channel, S3E_CHANNEL_STOP_AUDIO, test_close, NULL);
	file = fopen(FILE_NAME, "rb");

	if( file ) {
		fseek(file, 0L, SEEK_END);
		fileSize = ftell(file);
		fseek(file, 0L, SEEK_SET);
		buffer = (int16*)malloc(fileSize);
		n = fread(buffer, sizeof(int16), fileSize / sizeof(int16), file);
		fclose(file);
		//s3eAudioPlayFromBuffer(buffer, n, 0);
		channel = s3eSoundGetFreeChannel();
		s3eSoundChannelSetInt(channel, S3E_CHANNEL_RATE, 8000);
		//s3eSoundChannelSetInt(channel, S3E_CHANNEL_VOLUME, 19);

		s3eSoundChannelPlay(channel, buffer, n, 1, 0);
		while( !g_closed ) {
			alutSleep(1);
		}
		free(buffer);
	}
	s3eSoundChannelSetInt(channel, S3E_CHANNEL_RATE, rate);

	alutInit (&argc, argv);
	helloBuffer = alutCreateBufferHelloWorld ();
	alGenSources (1, &helloSource);
	alSourcei (helloSource, AL_BUFFER, helloBuffer);
	alSourcePlay (helloSource);
	alutSleep (20);
	s3eSoundChannelSetInt(channel, S3E_CHANNEL_VOLUME, volume);
	alutExit ();
	return EXIT_SUCCESS;
}
예제 #2
0
void Sounds::playSound(Sounds::Sound* sound) {
	if(Settings::getInstance()->soundEnabled == false)
		return;
	int channel = s3eSoundGetFreeChannel();
	if(s3eSoundChannelPlay(channel, sound->buffer, sound->fileSize/2, 1, 0) == S3E_RESULT_ERROR) {
		char buffer[200];
		sprintf(buffer, "Error in s3eSoundChannelPlay: %s", s3eSoundGetErrorString());
		IGLog(buffer);
	}
}
void ResourceManager::PlayAudio(uint32 audioHandle)
{
    if(audioHandle == 0 || audioHandle >= audioData->size() || audioData->at(audioHandle) == null)
    {
        return;
    }

    int channel = s3eSoundGetFreeChannel();

    s3eSoundChannelPlay(channel, audioData->at(audioHandle), audioSizes->at(audioHandle)/2, 1, 0);
}
	unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath)
	{
					
		
		int channel = s3eSoundGetFreeChannel();
		
		s3eSoundChannelPlay(channel, g_SoundBuffer, g_SoundFileSize/2, 1, 0);
		
		if (s3eSoundGetError()!= S3E_SOUND_ERR_NONE)
		{
			IwAssertMsg(GAME, this, ("Play sound %s Failed. Error Code : %s", pszFilePath, s3eSoundGetErrorString()));	
		}

		return channel;

	}
예제 #5
0
	unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
	{
		SoundFxMap::iterator it = g_pSoundFxMap->find(pszFilePath) ;
		
		int16* buff = 0 ;
		if( it==g_pSoundFxMap->end() ) {
			preloadEffect(pszFilePath) ;
		}
		buff = (*g_pSoundFxMap)[pszFilePath].data ;

		int channel = s3eSoundGetFreeChannel();
		
		s3eSoundChannelPlay(channel, buff, (*g_pSoundFxMap)[pszFilePath].size/2, (bLoop ? 0 : 1), 0);
		
		if (s3eSoundGetError()!= S3E_SOUND_ERR_NONE) {
			IwAssertMsg(GAME, false, ("Play sound %s Failed. Error Code : %s", pszFilePath, s3eSoundGetErrorString()));	
		}

		return channel;

	}
예제 #6
0
	unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
	{
		// Changing file path to full path
		std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);

		SoundFxMap::iterator it = g_pSoundFxMap->find(fullPath) ;
		
		int16* buff = 0 ;
		if( it==g_pSoundFxMap->end() ) {
			preloadEffect(fullPath.c_str()) ;
		}
		buff = (*g_pSoundFxMap)[fullPath].data ;

		int channel = s3eSoundGetFreeChannel();
		
		s3eSoundChannelPlay(channel, buff, (*g_pSoundFxMap)[fullPath].size/2, (bLoop ? 0 : 1), 0);
		
		if (s3eSoundGetError()!= S3E_SOUND_ERR_NONE) {
			IwAssertMsg(GAME, false, ("Play sound %s Failed. Error Code : %s", fullPath.c_str(), s3eSoundGetErrorString()));	
		}

		return channel;

	}
예제 #7
0
bool COggVorbisFileHelper::init( std::string fin_str,bool bResample /*= true*/,int nResQuality/*=0*/, char* pData /*= NULL*/, uint32 iSize /*= 0*/)
{
	cleanup();

#if defined(HAVE_PTHREAD)
	pthread_mutex_lock(&mutex1);
#endif	

	nSoundChannel = s3eSoundGetFreeChannel();
	if(nSoundChannel == -1)
	{
		m_strLastError.clear();
		m_strLastError = "Cannot open a sound channel.";
		s3eDebugTracePrintf("%s\n",m_strLastError.c_str());
		cleanup();
#if defined(HAVE_PTHREAD)
		pthread_mutex_unlock(&mutex1);
#endif
		return false;
	}
	s3eSoundChannelRegister(nSoundChannel, S3E_CHANNEL_GEN_AUDIO, GenerateAudioCallback, this);
	s3eSoundChannelRegister(nSoundChannel, S3E_CHANNEL_END_SAMPLE, EndSampleCallback, this);

	ov_callbacks callbacks;
	callbacks.read_func = read_func;
	callbacks.seek_func = seek_func;
	callbacks.close_func = close_func;
	callbacks.tell_func = tell_func;

	if (pData != NULL)
	{
		oggvorbis_filein = s3eFileOpenFromMemory(pData, iSize);
	}
	else
	{
		if(false /*oggvorbis_filein != NULL*/)
		{
			if(s3eFileClose(oggvorbis_filein) == S3E_RESULT_ERROR)
			{
				m_strLastError.clear();
				m_strLastError = "Cannot close old file"; 
				s3eDebugTracePrintf("%s\n",m_strLastError.c_str());
				cleanup();
#if defined(HAVE_PTHREAD)
				pthread_mutex_unlock(&mutex1);
#endif
				return false;
			}
		}
		oggvorbis_filein = s3eFileOpen(fin_str.c_str(),"rb");
	}
	

	if(oggvorbis_filein == NULL)
	{
		m_strLastError.clear();
		m_strLastError = "Cannot open file " + fin_str; 
		s3eDebugTracePrintf("%s\n",m_strLastError.c_str());
		cleanup();
#if defined(HAVE_PTHREAD)
		pthread_mutex_unlock(&mutex1);
#endif
		return false;
	}

	if(ov_open_callbacks(oggvorbis_filein, &vf, NULL, 0, callbacks) < 0)
	{
		m_strLastError.clear();
		m_strLastError = "Input does not appear to be an Ogg bitstream.";
		s3eDebugTracePrintf("%s\n",m_strLastError.c_str());
		cleanup();
#if defined(HAVE_PTHREAD)
		pthread_mutex_unlock(&mutex1);
#endif
		return false;
	}

	/* Throw the comments plus a few lines about the bitstream we're
		decoding */
	{
		char **ptr=ov_comment(&vf,-1)->user_comments;
		vorbis_info *vi=ov_info(&vf,-1);
		//while(*ptr)
		//{
		//	fprintf(stderr,"%s\n",*ptr);
		//	++ptr;
		//}
		total_samples = ov_pcm_total(&vf,-1);
		time_length = ov_time_total_func(&vf,-1);
		nChannels = vi->channels;
		nRate	= vi->rate;

		s3eSoundChannelSetInt(nSoundChannel, S3E_CHANNEL_RATE, nRate);
		nOutputRate = s3eSoundGetInt(S3E_SOUND_OUTPUT_FREQ);

	
		int gcd = GCD(nRate, nOutputRate);
		nW = nRate  / gcd;
		nL = nOutputRate / gcd;


		dResampleFactor = (float)nOutputRate / (float)vi->rate;	// 0 - 4.0 ?

		int err;
		bEnableResampling = bResample;
		nResampleQuality = nResQuality;

		if(bEnableResampling)
		{
			if(res_contL)	speex_resampler_destroy(res_contL);
			res_contL =  speex_resampler_init(1,nRate,nOutputRate,nResampleQuality,&err);

			
			if(res_contR) speex_resampler_destroy(res_contR);
			res_contR =  speex_resampler_init(1,nRate,nOutputRate,nResampleQuality,&err);

			if(err != RESAMPLER_ERR_SUCCESS)
			{
				m_strLastError.clear();
				m_strLastError = "Cannot start resampler.";
				s3eDebugTracePrintf("%s\n",m_strLastError.c_str());
				cleanup();
#if defined(HAVE_PTHREAD)
				pthread_mutex_unlock(&mutex1);
#endif
				return false;
			}
		}
		else
		{
			int fs = min(nRate, nOutputRate);
			double fc = (fs/2) / (double)nOutputRate; // half the input sample rate (eg nyquist limit of input)
			// Generate filter coefficients
			wsfirLP(dFilterCoefficients, nFilterCoefficients, W_BLACKMAN, fc);

			if(dResampleFactor != 1)
				s3eDebugErrorShow(S3E_MESSAGE_CONTINUE,"Resample factor not 1 but resampling disabled");
		}


		s3eDebugTracePrintf("\nBitstream is %d channel, %ldHz\n",vi->channels,vi->rate);
		s3eDebugTracePrintf("\nDecoded length: %ld samples\n",(long)total_samples);
		s3eDebugTracePrintf("Encoded by: %s\n\n",ov_comment(&vf,-1)->vendor);
		s3eDebugTracePrintf("Resampling by rational factor %d / %d", nW, nL);
	}

	bStopDecoding = false;
	nStatus = OH_READY;
#if defined(HAVE_PTHREAD)
	pthread_mutex_unlock(&mutex1);
#endif
	return true;
}