本文整理汇总了C++中running_machine::sample_rate方法的典型用法代码示例。如果您正苦于以下问题:C++ running_machine::sample_rate方法的具体用法?C++ running_machine::sample_rate怎么用?C++ running_machine::sample_rate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类running_machine
的用法示例。
在下文中一共展示了running_machine::sample_rate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: filterTableInit
static void filterTableInit(running_machine &machine)
{
int sample_rate = machine.sample_rate();
uint16_t uk;
/* Parameter calculation has not been moved to a separate function */
/* by purpose. */
const float filterRefFreq = 44100.0f;
float yMax = 1.0f;
float yMin = 0.01f;
float yAdd;
float yTmp, rk, rk2;
float resDyMax;
float resDyMin;
float resDy;
filterTable = std::make_unique<float[]>(0x800);
bandPassParam = std::make_unique<float[]>(0x800);
uk = 0;
for ( rk = 0; rk < 0x800; rk++ )
{
filterTable[uk] = (((expf(rk/0x800*logf(400.0f))/60.0f)+0.05f)
*filterRefFreq) / sample_rate;
if ( filterTable[uk] < yMin )
filterTable[uk] = yMin;
if ( filterTable[uk] > yMax )
filterTable[uk] = yMax;
uk++;
}
/*extern float bandPassParam[0x800]; */
yMax = 0.22f;
yMin = 0.05f; /* less for some R1/R4 chips */
yAdd = (yMax-yMin)/2048.0f;
yTmp = yMin;
uk = 0;
/* Some C++ compilers still have non-local scope! */
for ( rk2 = 0; rk2 < 0x800; rk2++ )
{
bandPassParam[uk] = (yTmp*filterRefFreq) / sample_rate;
yTmp += yAdd;
uk++;
}
/*extern float filterResTable[16]; */
resDyMax = 1.0f;
resDyMin = 2.0f;
resDy = resDyMin;
for ( uk = 0; uk < 16; uk++ )
{
filterResTable[uk] = resDy;
resDy -= (( resDyMin - resDyMax ) / 15 );
}
filterResTable[0] = resDyMin;
filterResTable[15] = resDyMax;
}
示例2: sdlaudio_init
//============================================================
// osd_start_audio_stream
//============================================================
void sdlaudio_init(running_machine &machine)
{
if (LOG_SOUND)
sound_log = fopen(SDLMAME_SOUND_LOG, "w");
// skip if sound disabled
if (machine.sample_rate() != 0)
{
// attempt to initialize SDL
if (sdl_init(machine))
return;
machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(sdl_cleanup_audio), &machine));
// set the startup volume
machine.osd().set_mastervolume(attenuation);
}
return;
}
示例3: sdl_cleanup_audio
static void sdl_cleanup_audio(running_machine &machine)
{
// if nothing to do, don't do it
if (machine.sample_rate() == 0)
return;
// kill the buffers and dsound
sdl_kill(machine);
sdl_destroy_buffers();
// print out over/underflow stats
if (buffer_overflows || buffer_underflows)
mame_printf_verbose("Sound buffer: overflows=%d underflows=%d\n", buffer_overflows, buffer_underflows);
if (LOG_SOUND)
{
fprintf(sound_log, "Sound buffer: overflows=%d underflows=%d\n", buffer_overflows, buffer_underflows);
fclose(sound_log);
}
}
示例4: sdl_init
//============================================================
// sdl_init
//============================================================
static int sdl_init(running_machine &machine)
{
int n_channels = 2;
int audio_latency;
SDL_AudioSpec aspec, obtained;
char audio_driver[16] = "";
if (initialized_audio)
{
sdl_cleanup_audio(machine);
}
mame_printf_verbose("Audio: Start initialization\n");
#if (SDLMAME_SDL2)
strncpy(audio_driver, SDL_GetCurrentAudioDriver(), sizeof(audio_driver));
#else
SDL_AudioDriverName(audio_driver, sizeof(audio_driver));
#endif
mame_printf_verbose("Audio: Driver is %s\n", audio_driver);
initialized_audio = 0;
sdl_xfer_samples = SDL_XFER_SAMPLES;
stream_in_initialized = 0;
stream_loop = 0;
// set up the audio specs
aspec.freq = machine.sample_rate();
aspec.format = AUDIO_S16SYS; // keep endian independent
aspec.channels = n_channels;
aspec.samples = sdl_xfer_samples;
aspec.callback = sdl_callback;
aspec.userdata = 0;
if (SDL_OpenAudio(&aspec, &obtained) < 0)
goto cant_start_audio;
initialized_audio = 1;
snd_enabled = 1;
mame_printf_verbose("Audio: frequency: %d, channels: %d, samples: %d\n",
obtained.freq, obtained.channels, obtained.samples);
sdl_xfer_samples = obtained.samples;
audio_latency = downcast<sdl_options &>(machine.options()).audio_latency();
// pin audio latency
if (audio_latency > MAX_AUDIO_LATENCY)
{
audio_latency = MAX_AUDIO_LATENCY;
}
else if (audio_latency < 1)
{
audio_latency = 1;
}
// compute the buffer sizes
stream_buffer_size = machine.sample_rate() * 2 * sizeof(INT16) * audio_latency / MAX_AUDIO_LATENCY;
stream_buffer_size = (stream_buffer_size / 1024) * 1024;
if (stream_buffer_size < 1024)
stream_buffer_size = 1024;
// create the buffers
if (sdl_create_buffers())
goto cant_create_buffers;
mame_printf_verbose("Audio: End initialization\n");
return 0;
// error handling
cant_create_buffers:
cant_start_audio:
mame_printf_verbose("Audio: Initialization failed. SDL error: %s\n", SDL_GetError());
return 0;
}
示例5: osd_update_audio_stream
void osd_update_audio_stream(running_machine &machine, INT16 *buffer, int samples_this_frame)
{
if (wavptr && (machine.sample_rate() != 0))
wav_add_data_16((wav_file*)wavptr, buffer, samples_this_frame * 2);
}
示例6: wswan_ch_set_freq
static void wswan_ch_set_freq( running_machine &machine, struct CHAN *ch, UINT16 freq )
{
freq &= 0x7ff; // docs say freq is 11bits and a few games (Morita Shougi, World Stadium + others) write 0x800 causing a divide by 0 crash
ch->freq = freq;
ch->period = machine.sample_rate() / ( 3072000 / ( ( 2048 - freq ) << 5 ) );
}
示例7: dsound_init
static HRESULT dsound_init(running_machine &machine)
{
HRESULT result;
// create the DirectSound object
result = DirectSoundCreate(NULL, &dsound, NULL);
if (result != DS_OK)
{
mame_printf_error(_WINDOWS("Error creating DirectSound: %08x\n"), (UINT32)result);
goto error;
}
// get the capabilities
dsound_caps.dwSize = sizeof(dsound_caps);
result = IDirectSound_GetCaps(dsound, &dsound_caps);
if (result != DS_OK)
{
mame_printf_error(_WINDOWS("Error getting DirectSound capabilities: %08x\n"), (UINT32)result);
goto error;
}
// set the cooperative level
result = IDirectSound_SetCooperativeLevel(dsound, win_window_list->hwnd, DSSCL_PRIORITY);
if (result != DS_OK)
{
mame_printf_error(_WINDOWS("Error setting DirectSound cooperative level: %08x\n"), (UINT32)result);
goto error;
}
// make a format description for what we want
stream_format.wBitsPerSample = 16;
stream_format.wFormatTag = WAVE_FORMAT_PCM;
stream_format.nChannels = 2;
stream_format.nSamplesPerSec = machine.sample_rate();
stream_format.nBlockAlign = stream_format.wBitsPerSample * stream_format.nChannels / 8;
stream_format.nAvgBytesPerSec = stream_format.nSamplesPerSec * stream_format.nBlockAlign;
// compute the buffer size based on the output sample rate
stream_buffer_size = stream_format.nSamplesPerSec * stream_format.nBlockAlign * downcast<windows_options &>(machine.options()).audio_latency() / 10;
stream_buffer_size = (stream_buffer_size / 1024) * 1024;
if (stream_buffer_size < 1024)
stream_buffer_size = 1024;
LOG(("stream_buffer_size = %d\n", stream_buffer_size));
// create the buffers
result = dsound_create_buffers();
if (result != DS_OK)
goto error;
// start playing
result = IDirectSoundBuffer_Play(stream_buffer, 0, 0, DSBPLAY_LOOPING);
if (result != DS_OK)
{
mame_printf_error(_WINDOWS("Error playing: %08x\n"), (UINT32)result);
goto error;
}
return DS_OK;
// error handling
error:
dsound_destroy_buffers();
dsound_kill();
return result;
}