Esempio n. 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;
}
int CIwChannelADPCM::GenerateAudio(s3eSoundGenAudioInfo* pInfo)
{
    int16* aTarget = pInfo->m_Target;
    int aLength = pInfo->m_NumSamples;
    int mix = pInfo->m_Mix;

    if (!pos)
    {
        //First time GenerateAudio is called for this sample
        //Take the sample data from pInfo->m_OrigStart,pInfo->m_OrigNumSamples. This is what was passed to
        //s3eSoundChannelPlay
        pos = pInfo->m_OrigStart;
        end_pos = (pInfo->m_OrigStart + (pInfo->m_OrigNumSamples &~1));
        CIwSoundDataADPCM* pSData = (CIwSoundDataADPCM*)s3eSoundChannelGetInt(pInfo->m_Channel, S3E_CHANNEL_USERVAR);

        m_SamplesPerBlock = pSData->GetSamplesPerBlock();
        m_BlockAlign  = pSData->GetBlockAlignment();
        m_SamplesRemaining = pSData->GetSampleCount();
        m_LastBlock = 0;

#ifdef WRITE_FILE
        op = fopen ("c:\\op.raw", "Rwb");
#endif


        bres_accum = 0;
        count = 0;
        s_1 = 0             ;
        s_2 = 0;
        bufferstep = 0;
        index = 0;

    }

    int relative_rate = (s3eSoundChannelGetInt(pInfo->m_Channel, S3E_CHANNEL_RATE)*0x1000)/s3eSoundGetInt(S3E_SOUND_OUTPUT_FREQ);
    int volume = s3eSoundChannelGetInt(pInfo->m_Channel, S3E_CHANNEL_VOLUME);

    int endSample = 0;
    int ret = GenerateADPCMAudioFast(aTarget, aLength, relative_rate, volume, mix, &endSample);
    if (endSample)
    {
        pInfo->m_EndSample = S3E_TRUE;
        pos = NULL;
    }
    return ret;
}