static void ReleaseVoice(opl_voice_t *voice) { opl_voice_t **rover; opl_voice_t *next; boolean double_voice; voice->channel = NULL; voice->note = 0; double_voice = voice->current_instr_voice != 0; next = voice->next; // Remove from alloced list. RemoveVoiceFromAllocedList(voice); // Search to the end of the freelist (This is how Doom behaves!) rover = &voice_free_list; while (*rover != NULL) { rover = &(*rover)->next; } *rover = voice; voice->next = NULL; if (next != NULL && double_voice && opl_drv_ver != opl_doom_1_9) { VoiceKeyOff(next); ReleaseVoice(next); } }
hdW32SoundVoiceDevice::~hdW32SoundVoiceDevice() { ReleaseVoice(); if ( buffers_ ) { alDeleteBuffers( BUFFER_COUNT, buffers_ ); HEART_CHECK_OPENAL_ERRORS(); hZeroMem( buffers_, sizeof(BUFFER_COUNT) ); } }
int AudioThread::Main() { dmsg(("Audio thread running\n")); while (true) { // read and process commands from the queue while (true) { command_t command; if (pCommandQueue->read(&command, 1) == 0) break; switch (command.type) { case command_type_note_on: dmsg(("Audio Thread: Note on received\n")); ActivateVoice(command.pitch, command.velocity); break; case command_type_note_off: dmsg(("Audio Thread: Note off received\n")); ReleaseVoice(command.pitch, command.velocity); break; } } // zero out the sum buffer for (uint u = 0; u < pAudioIO->FragmentSize * pAudioIO->Channels; u++) { pAudioSumBuffer[u] = 0.0; } // render audio from all active voices for (uint i = 0; i < MAX_AUDIO_VOICES; i++) { if (pVoices[i]->IsActive()) { pVoices[i]->RenderAudio(); } } // check clipping in the audio sum, convert to sample_type // (from 32bit to 16bit sample) and copy to output buffer float sample_point; for (uint u = 0; u < pAudioIO->FragmentSize * pAudioIO->Channels; u++) { sample_point = this->pAudioSumBuffer[u] / 4; // FIXME division by 4 just for testing purposes (to give a bit of head room when mixing multiple voices together) if (sample_point < -32768.0) sample_point = -32768.0; if (sample_point > 32767.0) sample_point = 32767.0; this->pAudioIO->pOutputBuffer[u] = (sample_t) sample_point; } // call audio driver to output sound int res = this->pAudioIO->Output(); if (res < 0) exit(EXIT_FAILURE); } }
void MantaFlextPoly::SendOutput(int voice, int pad, int value) { if(value >= 0 && voice >= 0) { ToOutFloat(2, value); ToOutFloat(1, pad); ToOutFloat(0, voice); } if(0 == value) { ReleaseVoice(voice); } }
HRESULT LoadVoices(void){ HRESULT hr; ISpObjectToken *pToken; IEnumSpObjectTokens *cpEnum; wchar_t *pDescription, *p, *ptr, szBuffer[64]; hr = _EnumTokens(SPCAT_VOICES, NULL, NULL, &cpEnum); if(hr == S_OK){ g_VoicesCount = 0; pDescription = (wchar_t *)CoTaskMemAlloc(128 * sizeof(wchar_t)); while(IEnumSpObjectTokens_Next(cpEnum, 1, &pToken, NULL) == S_OK){ hr = _GetDescription(pToken, &pDescription); if(SUCCEEDED(hr)){ g_VoicesCount++; wcscpy(g_PVoices[g_VoicesCount - 1].name, pDescription); g_PVoices[g_VoicesCount - 1].token = pToken; GetPrivateProfileStringW(S_VOICES, pDescription, NULL, szBuffer, 64, g_NotePaths.INIFile); if(*szBuffer){ p = wcstok(szBuffer, L"|", &ptr); g_PVoices[g_VoicesCount - 1].rate = _wtol(p); p = wcstok(NULL, L"|", &ptr); g_PVoices[g_VoicesCount - 1].volume = (unsigned short)_wtoi(p); g_PVoices[g_VoicesCount - 1].pitch = (short)_wtoi(ptr); } else{ ISpVoice *pVoice = CreateVoice(); ISpVoice_SetVoice(pVoice, (ISpObjectToken *)g_PVoices[g_VoicesCount - 1].token); ISpVoice_GetVolume(pVoice, &g_PVoices[g_VoicesCount - 1].volume); ISpVoice_GetRate(pVoice, &g_PVoices[g_VoicesCount - 1].rate); g_PVoices[g_VoicesCount - 1].pitch = 0; ReleaseVoice(pVoice); } if(g_VoicesCount == NELEMS(g_PVoices)) break; } if (FAILED(hr)) { ISpObjectToken_Release(pToken); break; } } CoTaskMemFree(pDescription); } else { hr = SPERR_NO_MORE_ITEMS; } return hr; }
static void InitVoices(void) { int i; // Start with an empty free list. voice_free_list = NULL; // Initialize each voice. for (i=0; i<OPL_NUM_VOICES; ++i) { voices[i].index = i; voices[i].op1 = voice_operators[0][i]; voices[i].op2 = voice_operators[1][i]; voices[i].current_instr = NULL; // Add this voice to the freelist. ReleaseVoice(&voices[i]); } }
void hdW32SoundVoiceDevice::Stop() { ReleaseVoice(); }