Пример #1
0
int16* LoadWav(const char* filename, int* sizeOut)
{
    RiffHeader header;
    Chunk chunk;

    int16* rtn = NULL;
    FILE* f = fopen(filename, "r");
    fseek(f, 0, SEEK_END);
    int size = ftell(f);
    s3eDebugTracePrintf("filesize = %d", size);
    fseek(f, 0, SEEK_SET);
    fread(&header, 1, sizeof(header), f);
    s3eDebugTracePrintf("%d %.4s %.4s %u", sizeof(header), header.m_ChunkID, header.m_RIFFType, header.m_ChunkSize);

    while (1)
    {
        fread(&chunk, 1, sizeof(chunk), f);
        if (!strncmp(chunk.m_ChunkID, "data", 4))
        {
            rtn = (int16*)malloc(chunk.m_ChunkSize);
            fread(rtn, 1, chunk.m_ChunkSize, f);
            *sizeOut = chunk.m_ChunkSize;
            break;
        }
        fseek(f, chunk.m_ChunkSize, SEEK_CUR);
    }

    fclose(f);
    return rtn;
}
Пример #2
0
void WallLevel::BrickPlaced(BrickTarget *target, Brick *brick)
{
    string checkWord = target->GetPrefix();
    checkWord += brick->GetSuffix();

    s3eDebugTracePrintf("%d - Placing brick %s at target %s", mgr->GetCurrentClockTime(), brick->debugId, target->debugId);
    brick->SetBaseLocation(target->GetBaseLocation());

    if(wordBuilder->IsValidWord(checkWord.c_str()))
    {
        brickCourses[target->xPos] = target->yPos;
        if(bricks[brick->xPos] == null)
        {
            bricks[brick->xPos] = new Brick(mgr, this, brick->xPos);
        }
        brickTargets[target->xPos] = null;
        target->Stop();
        FillTargets();
    }
    else
    {
        brick->AddTransformation(new TranslationTransformation(new ShakerLocSource));
        uint32 shakeEndTime = brick->GetAge(mgr->GetCurrentClockTime()) + BAD_BRICK_DELAY_MILLIS;
        brick->SetLifespan(shakeEndTime);
        s3eDebugTracePrintf("Shaking brick %s until time %d", brick->debugId, shakeEndTime);
    }
}
Пример #3
0
bool COggVorbisFileHelper::set_outputStereoMode( STEREO_MODE val )
{
	s3eResult res = S3E_RESULT_ERROR;
	int32 bStereo = 0;
	if(nSoundChannel == -1) return false;
	if (val != STEREO_MODE_MONO)
	{
		bStereo = s3eSoundGetInt(S3E_SOUND_STEREO_ENABLED);
		if(!bStereo)
		{
			s3eDebugTracePrintf("Stereo mode not supported\n");
			return false;
		}
		res =  s3eSoundChannelRegister(nSoundChannel, S3E_CHANNEL_GEN_AUDIO_STEREO, GenerateAudioCallback, this);
		if(res == S3E_RESULT_ERROR)
		{
			s3eDebugTracePrintf("Stereo mode cannot be set\n"); 
			return false;
		}
	}
	else
	{
	    s3eSoundChannelUnRegister(nSoundChannel, S3E_CHANNEL_GEN_AUDIO_STEREO);
	}

	stereoOutputMode = val;
	return true;
}
Пример #4
0
void ExampleInit()
{
    g_UseSoundPool = s3eSoundPoolAvailable() == S3E_TRUE;
    
    // Read in sound data
    // s3eSoundSetInt(S3E_SOUND_DEFAULT_FREQ, 8000);
    DIR* d = opendir(".");
    int count = 0;
    struct dirent* ent;
    while ((ent = readdir(d)))
    {
        int len = strlen(ent->d_name);
        if (len < 4 || stricmp(ent->d_name+len-4, ".wav"))
            continue;

        Load(count, ent->d_name);
        s3eDebugTracePrintf("loaded sound %d (%d)", g_Samples[count], g_SampleDataLen[count]);

        ent->d_name[len-4] = '\0';
        g_Buttons[count] = strdup(ent->d_name);
        AddButton(g_Buttons[count], 20, 20 + 70 * count, 300, 50, (s3eKey)(s3eKey1 + count));
        if (++count == MAX_SAMPLES)
            break;
    }

    RegisterCallbacks();
}
Пример #5
0
COggVorbisFileHelper::~COggVorbisFileHelper()
{
	stop();
	bStopDecoding = true;
	while(mDecThread.thread_status == CThread::TRUNNING) 
	{
		s3eDebugTracePrintf("waiting decoding thread terminating\n");
		s3eDeviceYield(10);
	}

	if(mDecBuffer != NULL)
	{
		delete mDecBuffer;
		mDecBuffer = NULL;
	}
	//cleanup();

	if(res_contR)	speex_resampler_destroy(res_contR);
	if(res_contL)	speex_resampler_destroy(res_contL);

	delete [] iFilterBufferL;
	delete [] iFilterBufferR;
	delete [] dFilterCoefficients;

	delete [] m_outL;
	delete [] m_outR;

	/*if(nStatus != OH_NAN) ov_clear(&vf);*/
	
}
Пример #6
0
int32 SampleEnded(s3eSoundPoolEndSampleInfo* pInfo, void* userData)
{
    s3eDebugTracePrintf("sample ended = %d", pInfo->m_SampleId);

    g_SampleState[pInfo->m_SampleId] = 0;

    return 1;
}
Пример #7
0
int32 ChannelEnded(s3eSoundEndSampleInfo* pInfo, void* userData)
{
    s3eDebugTracePrintf("channel ended = %d", pInfo->m_Channel);
    
    g_SampleState[pInfo->m_Channel] = 0;
    
    return 1;
}
bool ExampleCheckQuit()
{
    bool rtn = s3eDeviceCheckQuitRequest()
    || (s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_PRESSED)
    || (s3eKeyboardGetState(s3eKeyAbsBSK) & S3E_KEY_STATE_PRESSED);
    if (rtn)
        s3eDebugTracePrintf("quiting example");
    return rtn;
}
Пример #9
0
void BrickTarget::Stop()
{
    Sprite::Stop();

    s3eDebugTracePrintf("%d - Stopping BT: %s", mgr->GetCurrentClockTime(), debugId);
    if(prefixSprite != null)
    {
        prefixSprite->Stop();
    }
}
Пример #10
0
 OggVorbis_File * handle()
 {
     if(vf_.datasource == 0)
     {
         int res = ov_open_callbacks(&buffer_, &vf_, 0, 0, ovMemoryCallbacks);
         IwAssertMsg(AUDIO_OGGFILE, res >= 0, ("Failed to open ogg stream: %d", res));
         
         vorbis_info * info = ov_info(handle(), -1);
         s3eDebugTracePrintf("rate: %d", static_cast<int>(info->rate));
     }
     return &vf_;
 }
Пример #11
0
void COggVorbisFileHelper::cleanup()
{
	if(nSoundChannel >= 0) s3eSoundChannelStop(nSoundChannel);
	bStopDecoding = true;
	while(mDecThread.thread_status == CThread::TRUNNING) 
	{
		s3eDebugTracePrintf("waiting decoding thread terminating\n");
		s3eDeviceYield(10);
	}
	if(nSoundChannel != -1)
	{
		s3eSoundChannelUnRegister(nSoundChannel, S3E_CHANNEL_GEN_AUDIO_STEREO);
		s3eSoundChannelUnRegister(nSoundChannel, S3E_CHANNEL_GEN_AUDIO);
		s3eSoundChannelUnRegister(nSoundChannel, S3E_CHANNEL_END_SAMPLE);
	}

	//m_resampler.clear();


	total_samples = 0;
	nChannels = 0;
	nRate = 0;
	time_length = 0;
	current_time	= 0;
	current_sample	= 0;
	current_section = 0;
	nSoundChannel	= -1;
	nOutputRate		= 0;
	bOutputIsStereo = -1;
	dResampleFactor	= 0;
	wait_counter = 0;
	nStatus = OH_NAN;
	nW	= 0;
	nL	= 0;

	bStopDecoding = false;
	stereoOutputMode = STEREO_MODE_MONO;

	rcb_len = 0;

	ov_clear(&vf);
	oggvorbis_filein = NULL;

	if(vi)
	{
		vorbis_info_clear(vi);
		vi = NULL;
	}

	nResampleQuality = 0;
	bEnableResampling = false;

}
Пример #12
0
bool LevelSelectMainUpdate()
{

    if (!LevelUpdate())
    {
        s3eDebugTracePrintf("Level Select Update returned false, exiting..");
        return false;
    }

    if (g_ClearScreen)
	{
		LevelRender();
	}
    //s3eSurfaceShow();
    s3eDeviceYield(FRAMETIME);
    return true;
}
Пример #13
0
bool ExamplesMainUpdate()
{
    s3eDeviceYield(0);
    s3eKeyboardUpdate();
    s3ePointerUpdate();

    int64 start = s3eTimerGetMs();

    if (!ExampleUpdate() || ExampleCheckQuit())
    {
        s3eDebugTracePrintf("ExampleUpdate returned false, exiting..");
        return false;
    }

    // Clear the screen
    if (g_ClearScreen)
        IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F);

    ButtonsRender();

    if (g_DrawCursor)
        CursorRender();

    SoftkeysRender();

    // User code render
    ExampleRender();

    // Attempt frame rate
    while ((s3eTimerGetMs() - start) < MS_PER_FRAME)
    {
        int32 yield = (int32) (MS_PER_FRAME - (s3eTimerGetMs() - start));
        if (yield<0)
            break;
        s3eDeviceYield(yield);
    }

    IwGxFlush();
    IwGxSwapBuffers();

    return true;
}
static void AppendMessageColourV(Colour colour, const char* fmt, va_list args)
{
    if (!g_NumMessages)
        return;

    // Add message to the array in a circlular manner, overwriting older messages when array is full
    g_MessageIdx += 1;

    if (g_MessageIdx == g_NumMessages)
        g_LoopMessages = true;

    g_MessageIdx = g_MessageIdx % g_NumMessages;
    char* message = g_Messages[g_MessageIdx];

    const char* colourStr;
    switch (colour)
    {
        case BLUE:
            colourStr = "`x6666ee";
            break;
        case GREEN:
            colourStr = "`x66ee66";
            break;
        case RED:
            colourStr = "`xee6666";
            break;
        case WHITE:
            colourStr = "`x000000";
            break;
        case BLACK:
        default:
            colourStr = "`x666666";
            break;
    }

    strcpy(message, colourStr);
    vsnprintf(message+8, g_MessageLen-8-1, fmt, args);
    s3eDebugTracePrintf("Append Message: %s", message+8);
}
Пример #15
0
bool ExampleUpdate()
{
    for (int i = 0; i < MAX_SAMPLES; i++)
    {
        if (!g_Buttons[i])
            break;
        if (CheckButton(g_Buttons[i]) & S3E_KEY_STATE_RELEASED)
        {
            s3eDebugTracePrintf("pressed button %d", i);
            
            if (i % 2)
            {
                if (!Play(i, 1))
                    g_SampleState[i] = 1;
            }
            else
            {
                switch(g_SampleState[i])
                {
                case 0:
                    if (!Play(i, 3))
                        g_SampleState[i] = 1;
                    break;
                case 1:
                    if (!Pause(i))
                        g_SampleState[i] = 2;                        
                    break;
                case 2:
                    if (!Resume(i))
                        g_SampleState[i] = 1;                        
                    break;
                }
            }
        }
    }

    return true;
}
bool ExamplesMainUpdate() {
    s3eKeyboardUpdate();
    s3ePointerUpdate();

    if (!ExampleUpdate())
    {
        s3eDebugTracePrintf("ExampleUpdate returned false, exiting..");
        return false;
    }

    if (g_ClearScreen)
        s3eSurfaceClear(0xff,0xff,0xff);

    ExampleRender();
    ButtonsRender();
    SoftkeysRender();

    if (g_DrawCursor)
        CursorRender();

    s3eSurfaceShow();
    s3eDeviceYield(FRAMETIME);
    return true;
}
Пример #17
0
void ButtonsRender()
{
    int previousDebugTextSize = s3eDebugGetInt(S3E_DEBUG_FONT_SCALE);
    int fontScale = g_ButtonScale;
    char buf[128];

    // select double sized text
    if (previousDebugTextSize != (int)g_ButtonScale)
        s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, g_ButtonScale);

    // find out the dimensions of the font
    const int textWidthDefault = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_WIDTH);
    const int textHeight = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_HEIGHT);

    // get the current pointer position and selection state
    int pointerX = s3ePointerGetX();
    int pointerY = s3ePointerGetY();
    s3ePointerState pointerState = s3ePointerGetState(S3E_POINTER_BUTTON_SELECT);

    int x = 10;
    int y = 50;
    
    g_SelectedButton = 0;

    // draw the buttons
    for (Button* iter = g_ButtonsHead; iter; iter = iter->m_Next)
    {
        if (!iter->m_Display)
            continue;

        if (g_HideDisabledButtons && !iter->m_Enabled)
            continue;

        fontScale = g_ButtonScale;
        int textWidth = textWidthDefault;
        if (s3eDebugGetInt(S3E_DEBUG_FONT_SCALE) != fontScale)
            s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, fontScale);

        if (iter->m_Key != S3E_KEY_INVALID)
        {
            if (s3eKeyboardGetState(iter->m_Key) & S3E_KEY_STATE_PRESSED)
            {
                g_SelectedButton = iter;
                s3eDebugTracePrintf("button selected using key");
            }
        }

        if (iter->m_Key != S3E_KEY_INVALID)
        {
            char keyName[32];
            s3eKeyboardGetDisplayName(keyName, iter->m_Key);
            if (iter->m_Enabled)
                snprintf(buf, sizeof(buf), "`x000000%s: %s", keyName, iter->m_Name);
            else
                snprintf(buf, sizeof(buf), "`xa0a0a0%s: %s", keyName, iter->m_Name);
        }
        else
        {
            if (iter->m_Enabled)
                snprintf(buf, sizeof(buf), "`x000000%s", iter->m_Name);
            else
                snprintf(buf, sizeof(buf), "`xa0a0a0%s", iter->m_Name);
        }

        int len = strlen(buf) - 8;
        int _x0 = x - 2;
        int _y0 = y - 4;
        int _h = textHeight + 4;
        int _y1 = _y0 + _h;
        int _w;
        int _x1;
        int textOffset = 0;
        
        // Scale down font size if button contents are too long for screen
        while (true)
        {
            _w = (textWidth * len) + 8;
            
            _x1 = _x0 + _w;

            if (fontScale == 1 || _x1 <= s3eSurfaceGetInt(S3E_SURFACE_WIDTH))
                break;

            fontScale -= 1;
            s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, fontScale);
            textWidth = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_WIDTH);
            textOffset += (textHeight-s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_HEIGHT))/2;
        }

        if (pointerX >= _x0 && pointerX <= _x1 &&
            pointerY >= _y0 && pointerY <= _y1 && iter->m_Enabled)
        {
            if (pointerState & S3E_POINTER_STATE_DOWN)
                DrawRect(_x0, _y0, _w, _h, 0, 255, 0);
            else
                DrawRect(_x0, _y0, _w, _h, 255, 0, 0);

            if (pointerState & S3E_POINTER_STATE_RELEASED)
                g_SelectedButton = iter;
        }
        else
        {
            if (iter->m_Enabled)
                DrawRect(_x0, _y0, _w, _h, 255, 0, 0);
            else
                DrawRect(_x0, _y0, _w, _h, 127, 0, 0);
        }

        s3eDebugPrint(x, y+textOffset,  buf, 0);

        // Store button's position and size
        iter->m_XPos = _x0;
        iter->m_YPos = _y0;
        iter->m_Width = _w;
        iter->m_Height = _h;

        y = y + textHeight * 2;
    }

    if (g_SelectedButton && g_SelectedButton->m_Callback)
        g_SelectedButton->m_Callback(g_SelectedButton);

    if (previousDebugTextSize != fontScale)
        s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, previousDebugTextSize);

    g_YBelowButtons = y;
}
Пример #18
0
int COggVorbisFileHelper::decode()
{
#if defined(HAVE_PTHREAD)
	pthread_mutex_lock(&mutex1);
#endif
	int cb_len = sizeof(convbuffer) -rcb_len-16;
	char* p = convbuffer + 16; //pre buffer
	memcpy(p,remaing_convbuffer,rcb_len);
	p = p+rcb_len;
	long ret=ov_read_func(&vf,p,cb_len,0,2,1,&current_section);
#if defined(HAVE_PTHREAD)
	pthread_mutex_unlock(&mutex1);
#endif

    if (ret == 0)
	{
      /* EOF */
      return EOF;
    } 
	else if (ret < 0) 
	{
		if(ret==OV_EBADLINK)
		{
			m_strLastError = "Corrupt bitstream section! Exiting.";
			s3eDebugTracePrintf("%s\n",m_strLastError.c_str());
			return ERR;
		}

    }
	else 
	{
		if(bStopDecoding) return EOS;

		int nr_samples = (ret + rcb_len)/sizeof(ogg_int16_t);
		
		if(!bEnableResampling) //store samples in the circular buffer
		{
			for(int k=0;k<nr_samples;k++)
			{
				//ogg_int16_t val = *(ogg_int16_t*)(convbuffer+k*sizeof(ogg_int16_t));
				if(bStopDecoding) return EOS;
				if(nStatus == OH_BUFFERING)
				{
					if(mDecBuffer->GetBusy() >= mDecBuffer->GetCapacity() * m_dBufferingMaxCapacity || k == nr_samples - 1)
					{
						s3eDebugTracePrintf("buffering complete. Playing now..\n");
						nStatus = OH_PLAYING;
						Wait_counter(0);
					}
				}
				while(!mDecBuffer->Enqueue(*(ogg_int16_t*)(convbuffer+k*sizeof(ogg_int16_t))))
				{
					s3eDeviceYieldUntilEvent(10);
					if(bStopDecoding) return EOS;/*fprintf(stderr,"Buffer full\n")*/;
					if(nStatus == OH_BUFFERING) 
					{
						s3eDebugTracePrintf("buffering complete. Playing now..\n");
						nStatus = OH_PLAYING;
						Wait_counter(0);
					}
					return BFF;
				}

			}

			return EOK;
		}

		if (get_nChannels() == 2) nr_samples /= 2;

		for(int k=0;k<nr_samples;k++)
		{
			if (get_nChannels() == 2) 
			{
				m_tmpbufL[k] = *(ogg_int16_t*)(convbuffer+k*2*sizeof(ogg_int16_t));
				m_tmpbufR[k] = *(ogg_int16_t*)(convbuffer+(k*2+1)*sizeof(ogg_int16_t));
			} 
			else 
			{
				m_tmpbufL[k] = *(ogg_int16_t*)(convbuffer+k*sizeof(ogg_int16_t));
			}
		}
		
		unsigned int inlengthL = nr_samples;
		unsigned int inlengthR = nr_samples;

		unsigned int inused = 0;   // output
		unsigned int outputL,outputR;
		outputL= m_outbufsizeL;
		outputR= m_outbufsizeR;
		if (get_nChannels() == 2)  // stereo input
		{		

			speex_resampler_process_int(res_contL,0,m_tmpbufL,&inlengthL,m_outL,&outputL);
			speex_resampler_process_int(res_contR,0,m_tmpbufR,&inlengthR,m_outR,&outputR);


			if(outputL != outputR)
			{
				s3eDebugTracePrintf("Left and Right channels out of sync\n");
			}

			if(inlengthL != inlengthR)
			{
				s3eDebugTracePrintf("Left and Right channels out of sync\n");
			}

			inused = inlengthL*2;

		}
		else
		{
			speex_resampler_process_interleaved_int(res_contL,m_tmpbufL,&inlengthL,m_outL,&outputL);
			
			inused = inlengthL;

		}


		p = convbuffer + inused * sizeof(ogg_int16_t);
		rcb_len = ret- inused*sizeof(ogg_int16_t);

		memcpy(remaing_convbuffer,p,rcb_len);


		for(unsigned int k = 0;k< outputL;k++)
		{
			if(bStopDecoding) return EOS;
			if(k%50 == 0) s3eDeviceYield(1);


			if(nStatus == OH_BUFFERING)
			{
				if(mDecBuffer->GetBusy() >= mDecBuffer->GetCapacity() * m_dBufferingMaxCapacity || k == nr_samples - 1)
				{
					s3eDebugTracePrintf("buffering complete. Playing now..\n");
					nStatus = OH_PLAYING;
					Wait_counter(0);
				}
			}
			while(!mDecBuffer->Enqueue((ogg_int16_t)m_outL[k]))
			{
				s3eDeviceYieldUntilEvent(10);
				if(bStopDecoding) return EOS;/*fprintf(stderr,"Buffer full\n")*/;
				if(nStatus == OH_BUFFERING) 
				{
					s3eDebugTracePrintf("buffering complete. Playing now..\n");
					nStatus = OH_PLAYING;
					Wait_counter(0);
				}
				return BFF;
			}
			if(get_nChannels() == 2)
			{
				while(!mDecBuffer->Enqueue((ogg_int16_t)m_outR[k]))
				{
					s3eDeviceYieldUntilEvent(10);
					if(bStopDecoding) return EOS;/*fprintf(stderr,"Buffer full\n")*/;
					if(nStatus == OH_BUFFERING) 
					{
						s3eDebugTracePrintf("buffering complete. Playing now..\n");
						nStatus = OH_PLAYING;
						Wait_counter(0);
					}
					return BFF;
				}
			}
		}

    }

	return EOK;
}
Пример #19
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;
}
Пример #20
0
void WallLevel::CheckValidWord()
{
    if(selectedTarget == null || selectedBrick == null)
    {
        return;
    }

    string checkWord = selectedTarget->GetPrefix();
    checkWord += selectedBrick->GetSuffix();

    StateVariable points = mgr->GetStateManager()->GetVar(VAR_POINTS);
    if(wordBuilder->IsValidWord(checkWord.c_str()))
    {
        mgr->GetResourceManager()->PlayAudio(SOUND_DING);
        points.intValue++;
    }
    else
    {
        mgr->GetResourceManager()->PlayAudio(SOUND_BUZZ);
        points.intValue -= 2;
        if(points.intValue < 0)
        {
            points.intValue = 0;
        }
    }
    mgr->GetStateManager()->SetVar(VAR_POINTS, points);

    CIwFVec2 curLocation((float)selectedBrick->GetBaseLocation().x, (float)selectedBrick->GetBaseLocation().y);
    CIwFVec2 targetLocation((float)selectedTarget->GetBaseLocation().x, (float)selectedTarget->GetBaseLocation().y);

    float orientation = IW_ANGLE_TO_RADIANS(0);

    CIwFVec2 normal;
    normal.x = (float)cos(orientation);
    normal.y = (float)sin(orientation);

    CIwFVec2 cp1 = curLocation + normal * 120;
    CIwFVec2 cp2 =  (targetLocation - curLocation) / 2;
    cp2 += curLocation + cp2 + normal * cp2.GetLength();

    PathFollowingSprite *path = new PathFollowingSprite(mgr);

    path->SetTotalPathTimeMillis(2000);
    path->AddSegment(new PathSegmentBezier(Convert(curLocation), Convert(cp1), Convert(cp2), Convert(targetLocation)));
    path->SetCompletionCallback(selectedBrick, (EventCallbackPtr)&Brick::PlaceBrick, path);
    path->SetLoopCount(1);
    mgr->RegisterGameObject(path);

    selectedBrick->SetParent(path);
    selectedBrick->target = selectedTarget;
    selectedTarget->Hide();

    selectedBrick->staticBrick = true;
    selectedTarget->staticTarget = true;

    bricks[selectedBrick->xPos] = null;

    s3eDebugTracePrintf("%d - Pathing brick %s", mgr->GetCurrentClockTime(), selectedBrick->debugId);

    selectedBrick = null;
    selectedTarget = null;
}
Пример #21
0
void initWwise()
{
    IW_CALLSTACK("initWwise");

    if (!s3eWwiseAvailable())
    {
        s3eDebugOutputString("Can't load Wwise");
        s3eDebugOutputString(s3eExtGetErrorString());
        return;
    }

    s3eDebugOutputString("Successfully loaded s3eWwise extension");

    s3eWwiseMemSettings memSettings;
    memSettings.uMaxNumPools = 10;

    s3eWwiseResult memoryMgr = s3eWwiseMemoryMgrInit(&memSettings);
    if(memoryMgr  != s3eWwise_Success )
        s3eDebugTracePrintf("Failed to init Wwise memory manager. Error code = %d", memoryMgr);
    else
        s3eDebugOutputString("Wwise memory manager init");

    s3eWwiseStreamMgrSettings streamSettings;
    s3eWwiseStreamMgrGetDefaultSettings(&streamSettings);
    streamMgr = s3eWwiseStreamMgrCreate(&streamSettings);
    s3eDebugOutputString(streamMgr ? "Wwise stream manager init" : "FAILED TO INIT STREAM");

    s3eWwiseInitSettings settings;
    s3eWwisePlatformInitSettings platformSettings;
    s3eWwiseSoundEngineGetDefaultInitSettings(&settings);
    s3eWwiseSoundEngineGetDefaultPlatformInitSettings(&platformSettings);
    s3eWwiseResult soundEngine = s3eWwiseSoundEngineInit(&settings, &platformSettings);
    if(soundEngine  != s3eWwise_Success )
        s3eDebugTracePrintf("Failed to init Wwise. Error code = %d", soundEngine);
    else
        s3eDebugOutputString("Init Wwise Successfully");

    s3eWwiseMusicSettings musicSettings;
    s3eWwiseMusicEngineGetDefaultInitSettings(&musicSettings);
    s3eWwiseResult musicEngine = s3eWwiseMusicEngineInit(&musicSettings);
    if( musicEngine != s3eWwise_Success )
        s3eDebugTracePrintf("Failed to init music. Error code = %d", musicEngine);
    else
        s3eDebugOutputString("Init Music Successfully");

    s3eWwiseCommSettings commSettings;
    s3eWwiseCommGetDefaultInitSettings(&commSettings);
    s3eWwiseResult commEngine = s3eWwiseCommInit(&commSettings);
    if( commEngine != s3eWwise_Success )
    {
        std::stringstream ss;
        ss << "Failed to Init Comm: error code = " << commEngine;
        s3eDebugOutputString(ss.str().c_str());
    }
    else
        s3eDebugOutputString("Init Comm Successfully");

    s3eWwiseBankID bankId;

    // Setup paths
    s3eWwiseStreamMgrSetCurrentLanguage("French(Canada)");
    s3eWwiseLowLevelIOSetBasePath("Audio/iOS/");

    s3eDebugOutputString("Path setup done");

    ///s3eWwiseResult loadInit = s3eWwiseSoundEngineLoadBankWithID(AK::BANKS::INIT, S3E_WWISE_DEFAULT_POOL_ID);
    s3eWwiseResult loadInit = s3eWwiseSoundEngineLoadBankNamed("Init.bnk", S3E_WWISE_DEFAULT_POOL_ID, &bankId);
    if(loadInit  != s3eWwise_Success )
    {
        s3eDebugOutputString("Failed to load sound bank");
        s3eDebugTracePrintf("Error code = %d", loadInit);
    }
    else
        s3eDebugOutputString("Loaded sound bank");

    //s3eWwiseResult loadHuman = s3eWwiseSoundEngineLoadBankWithID(AK::BANKS::HUMAN, S3E_WWISE_DEFAULT_POOL_ID);
    s3eWwiseResult loadHuman = s3eWwiseSoundEngineLoadBankNamed("Human.bnk", S3E_WWISE_DEFAULT_POOL_ID, &bankId);
    if( loadHuman != s3eWwise_Success )
    {
        s3eDebugOutputString("Failed to load sound bank");
        s3eDebugTracePrintf("Error code = %d", loadHuman);
    }
    else
        s3eDebugOutputString("Loaded sound bank");

    s3eWwiseResult loadCar = s3eWwiseSoundEngineLoadBankNamed("Car.bnk", S3E_WWISE_DEFAULT_POOL_ID, &bankId);
    if( loadCar != s3eWwise_Success )
    {
        s3eDebugOutputString("Failed to load sound bank");
        s3eDebugTracePrintf("Error code = %d", loadCar);
    }
    else
        s3eDebugOutputString("Loaded sound bank");

    s3eWwiseSoundEngineRegisterGameObjWithName(gameObjectID, "Human");
    s3eWwiseSoundEngineRegisterGameObj(carID);
}