// Initialize Sound Card ------------------------------------------------------ static int Sound_Init_SoundCard (void) { int i; AUDIOINFO Audio_Infos; ConsolePrintf (Msg_Get (MSG_Sound_Init_Soundcard), Sound.SampleRate); ConsolePrint ("\n"); Audio_Infos.nDeviceId = Sound.SoundCard; Audio_Infos.wFormat = AUDIO_FORMAT_16BITS | AUDIO_FORMAT_STEREO; // FIXME: Stereo ? Audio_Infos.nSampleRate = audio_sample_rate = Sound.SampleRate; if (AOpenAudio(&Audio_Infos) != AUDIO_ERROR_NONE) { Quit_Msg ("%s", Msg_Get (MSG_Sound_Init_Error_Audio)); return (MEKA_ERR_FAIL); } // FIXME: original sound engine was trying different sample rate on failure // Unused // Maybe it was intended to check out number of channels there ? // AGetAudioCaps (Audio_Infos.nDeviceId, &Audio_Caps); // Open voices if (AOpenVoices(Sound.Voices_Max) != AUDIO_ERROR_NONE) { Quit_Msg ("%s", Msg_Get (MSG_Sound_Init_Error_Voices)); return (MEKA_ERR_FAIL); } ASetAudioMixerValue (AUDIO_MIXER_MASTER_VOLUME, 256); // Allocate voices and waveforms Sound.Voices = Memory_Alloc (sizeof (t_voice) * Sound.Voices_Max); for (i = 0; i < Sound.Voices_Max; i++) { if (ACreateAudioVoice(&Sound.Voices[i].hVoice) != AUDIO_ERROR_NONE) { Quit_Msg (Msg_Get (MSG_Sound_Init_Error_Voice_N), i); return (MEKA_ERR_FAIL); } ASetVoicePanning(Sound.Voices[i].hVoice, 128); // Center voice Sound.Voices[i].lpWave = NULL; Sound.Voices[i].playing = FALSE; } // FIXME: is this needed ? AUpdateAudio (); // FIXME: is this needed ? // Check frame sample rate audio_sample_rate = nominal_sample_rate = Audio_Infos.nSampleRate; return (MEKA_ERR_OK); }
int main(void) { AUDIOINFO info; LPAUDIOMODULE lpModule; LPAUDIOWAVE lpWave; HAC hVoice; BOOL stopped; /* initialize audio library */ AInitialize(); /* open audio device */ info.nDeviceId = AUDIO_DEVICE_MAPPER; info.wFormat = AUDIO_FORMAT_16BITS | AUDIO_FORMAT_STEREO; info.nSampleRate = 44100; AOpenAudio(&info); /* load module and waveform file */ ALoadModuleFile("test.s3m", &lpModule, 0); ALoadWaveFile("test.wav", &lpWave, 0); /* open voices for module and waveform */ AOpenVoices(lpModule->nTracks + 1); /* play the module file */ APlayModule(lpModule); ASetModuleVolume(64); /* play the waveform through a voice */ ACreateAudioVoice(&hVoice); APlayVoice(hVoice, lpWave); ASetVoiceVolume(hVoice, 48); ASetVoicePanning(hVoice, 128); /* program main execution loop */ printf("Playing module and waveform, press any key to stop.\n"); while (!kbhit()) { /* update audio system */ AUpdateAudio(); /* restart waveform if stopped */ AGetVoiceStatus(hVoice, &stopped); if (stopped) APlayVoice(hVoice, lpWave); /* check if the module is stopped */ AGetModuleStatus(&stopped); if (stopped) break; } /* stop playing the waveform */ AStopVoice(hVoice); ADestroyAudioVoice(hVoice); /* stop playing the module */ AStopModule(); ACloseVoices(); /* release the waveform & module */ AFreeWaveFile(lpWave); AFreeModuleFile(lpModule); /* close audio device */ ACloseAudio(); return 0; }
void osd_update_audio(void) { if (seal_sample_rate == 0) return; AUpdateAudio(); }
int main(void) { AUDIOINFO info; LPAUDIOWAVE lpWave; HAC hVoice[NUMVOICES]; BOOL stopped; UINT n, m; /* initialize audio library */ AInitialize(); /* open audio device */ info.nDeviceId = AUDIO_DEVICE_MAPPER; info.wFormat = AUDIO_FORMAT_16BITS | AUDIO_FORMAT_STEREO; info.nSampleRate = 44100; AOpenAudio(&info); /* load waveform file */ ALoadWaveFile("test.wav", &lpWave, 0); /* open and allocate voices */ AOpenVoices(NUMVOICES); for (n = 0; n < NUMVOICES; n++) { ACreateAudioVoice(&hVoice[n]); ASetVoiceVolume(hVoice[n], 64); ASetVoicePanning(hVoice[n], n & 1 ? 0 : 255); } /* program main execution loop */ printf("Playing waveform, press any key to stop.\n"); for (n = m = 0; !kbhit() && n < 48 - 7; n++) { /* play chord C-E-G */ APlayVoice(hVoice[m+0], lpWave); APlayVoice(hVoice[m+1], lpWave); APlayVoice(hVoice[m+2], lpWave); ASetVoiceFrequency(hVoice[m+0], FREQ(aPeriodTable[n+0])); ASetVoiceFrequency(hVoice[m+1], FREQ(aPeriodTable[n+4])); ASetVoiceFrequency(hVoice[m+2], FREQ(aPeriodTable[n+7])); m = (m + 3) % NUMVOICES; /* wait until note finishes */ do { /* update audio system */ AUpdateAudio(); AGetVoiceStatus(hVoice[0], &stopped); } while (!stopped); } /* stop and release voices */ for (n = 0; n < NUMVOICES; n++) { AStopVoice(hVoice[n]); ADestroyAudioVoice(hVoice[n]); } ACloseVoices(); /* release the waveform file */ AFreeWaveFile(lpWave); /* close audio device */ ACloseAudio(); return 0; }