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; }
//----------------------------------------------------------------------------- CIwSoundManager::CIwSoundManager() { IW_CALLSTACK("CIwSoundManager::CIwSoundManager") IW_SINGLETON_SET(SoundManager); m_GroupIdentity = new CIwSoundGroup; m_ParamsIdentity = new CIwSoundParams; m_SoundInsts = NULL; m_SoundInstPtrs = NULL; m_NumActiveInsts = 0; m_Flags = ACTIVE_F; m_MasterVol = IW_GEOM_ONE; m_MasterPan = 0; m_MasterPitch = IW_GEOM_ONE; // Allocate our own channels so that they can be used to override Segundo // channels where necessary int cfgChannels = 8; s3eConfigGetInt("SOUND", "MaxChannels", &cfgChannels); int32 s3eChannels = s3eSoundGetInt(S3E_SOUND_NUM_CHANNELS); m_MaxInsts = MIN(cfgChannels, s3eChannels); s_ChannelsPCM8 = new CIwChannelPCM8[m_MaxInsts]; s_ChannelsPCM16 = new CIwChannelPCM16[m_MaxInsts]; s_ChannelsADPCM = new CIwChannelADPCM[m_MaxInsts]; m_SoundInsts = new CIwSoundInst[m_MaxInsts]; m_SoundInstPtrs = new CIwSoundInst*[m_MaxInsts]; for (uint32 i = 0; i < m_MaxInsts; i++) m_SoundInstPtrs[i] = &m_SoundInsts[i]; }
void SoundSystemS3E::init(int channels_num) { _channels.reserve(channels_num); for (int i = 0; i < channels_num; ++i) { ChannelS3E *channel = new ChannelS3E(this, i); _channels.push_back(channel); } check(); log::messageln("S3E_SOUND_OUTPUT_FREQ: %d", s3eSoundGetInt(S3E_SOUND_OUTPUT_FREQ)); }
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; }
float SimpleAudioEngine::getEffectsVolume() { return s3eSoundGetInt(S3E_SOUND_VOLUME) / (float)GEOM_ONE_FP8; }
void ExampleRender() { const int textHeight = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_HEIGHT); int y = GetYBelowButtons() + 3 * textHeight; const int x = 10; if (s3eSoundGetInt(S3E_SOUND_STEREO_ENABLED)) { s3eDebugPrintf(x, y, 0, "`x666666Stereo sound output supported and enabled"); } else { s3eDebugPrintf(x, y, 0, "`x666666SStereo sound output disabled or unsupported"); } y += textHeight; y += textHeight; /*if (ogg_hlp->get_nChannels() == 2) s3eDebugPrintf(x, y, 0, "`x666666Input: Stereo"); else s3eDebugPrintf(x, y, 0, "`x666666Input: Mono");*/ /*if (ogg_hlp->get_outputStereoMode() == COggVorbisFileHelper::STEREO_MODE_MONO) { if (!(ogg_hlp->get_nChannels() == 2)) s3eDebugPrintf(x, y, 0, "`x666666Output: Mono"); else s3eDebugPrintf(x, y, 0, "`x666666Output: Mono (left channel of stereo input)"); } else { const char* modeLRString; switch (ogg_hlp->get_outputStereoMode()) { case COggVorbisFileHelper::STEREO_MODE_LEFT: modeLRString = "left only"; break; case COggVorbisFileHelper::STEREO_MODE_RIGHT: modeLRString = "right only"; break; default: modeLRString = "left and right"; break; } s3eDebugPrintf(x, y, 0, "`x666666Output: Stereo (%s)", modeLRString); } y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666Input freq: %ld", ogg_hlp->get_rate()); y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666Output freq: %d", ogg_hlp->get_outputrate()); y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666g_OutputIsStereo: %d", ogg_hlp->get_outputIsStereo()); y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666Buffer: %.2f",ogg_hlp->get_decbuf()*100); y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666Total Samples: %ld", (long)ogg_hlp->get_nsamples()); y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666Total time: %.0f", ogg_hlp->get_time_length()); y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666Current time: %.0f (%0.f%%)", ogg_hlp->get_current_time(),ogg_hlp->get_current_time()/ogg_hlp->get_time_length()*100); y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666Resample: %d - Quality: %d)", g_EnableResample,g_ResampleQuality); y += textHeight; s3eDebugPrintf(x, y, 0, "`x666666Status: %s", ogg_hlp->get_statusstr().c_str()); y += textHeight; y += textHeight; y += textHeight; */ s3eDebugPrintf(x, y, 0, "`x666666channels playing: %i", GetNumOggChannels()); }
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; }
float SimpleAudioEngine::getEffectsVolume() { return s3eSoundGetInt(S3E_SOUND_VOLUME); }