void WriteFileToRegistry(const char * const pFilePath) { HKEY hKey = OpenRegistryKey("RegistryTest"); std::string strSubName = "Part"; std::string strSizeName = "Size"; size_t ulIndex = 1; auto splitFile = SplitFile(pFilePath); for (size_t i = 0; i < splitFile.size(); ++i) { std::string strFullName(strSubName + std::to_string(ulIndex)); WriteRegistryKeyString(hKey, strFullName.c_str(), splitFile[i].data(), READ_WRITE_SIZE); ++ulIndex; } CloseHandle(hKey); }
void AudioRendererSettings::ReadRegistryKeyString(HKEY hKey, LPCTSTR& lpSubKey, LPCTSTR& data) { DWORD dwSize = MAX_REG_LENGTH; DWORD dwType = REG_SZ; LONG error = RegQueryValueEx(hKey, lpSubKey, NULL, &dwType, (PBYTE)data, &dwSize); if (error != ERROR_SUCCESS) { if (error == ERROR_FILE_NOT_FOUND) { Log(" create default value for %s", lpSubKey); WriteRegistryKeyString(hKey, lpSubKey, data); } else if (error == ERROR_MORE_DATA) Log(" too much data, corrupted registry setting(?): %s", lpSubKey); else Log(" error: %d subkey: %s", error, lpSubKey); } }
void AudioRendererSettings::SaveSettingsToRegistry(HKEY hKey) { USES_CONVERSION; if (!hKey) { // Try to access the setting root "Software\Team MediaPortal\Audio Renderer" RegOpenKeyEx(HKEY_CURRENT_USER, folder, NULL, KEY_ALL_ACCESS, &hKey); } enableTimestretchingData = m_bUseTimeStretching ? 1 : 0; WASAPIExclusiveData = m_WASAPIShareMode == AUDCLNT_SHAREMODE_EXCLUSIVE ? 1 : 0; WASAPIUseEventModeData = m_bWASAPIUseEventMode ? 1 : 0; //devicePeriodData = m_hnsPeriod; AC3EncodingData = m_lAC3Encoding; AC3bitrateData = m_AC3bitrate / 1000; maxBiasData = m_dMaxBias * 10000; minBiasData = m_dMinBias * 10000; audioDelayData = m_lAudioDelay; logSampleTimesData = m_bLogSampleTimes ? 1 : 0; logDebugData = m_bLogDebug ? 1: 0; HWBasedRefClockData = m_bHWBasedRefClock ? 1 : 0; enableSyncAdjustmentData = m_bEnableSyncAdjustment ? 1 : 0; forceSamplingRateData = m_nForceSamplingRate; forceBitDepthData = m_nForceBitDepth; resamplingQualityData = m_nResamplingQuality; speakerConfigData = m_lSpeakerConfig; forceChannelMixingData = m_bForceChannelMixing ? 1 : 0; releaseDeviceOnStopData = m_bReleaseDeviceOnStop ? 1 : 0; expandMonoToStereoData = m_bExpandMonoToStereo ? 1 : 0; quality_USE_QUICKSEEKData = m_bQuality_USE_QUICKSEEK; quality_USE_AA_FILTERData = m_bQuality_USE_AA_FILTER; quality_AA_FILTER_LENGTHData = m_lQuality_AA_FILTER_LENGTH; quality_SEQUENCE_MSData = m_lQuality_SEQUENCE_MS; quality_SEEKWINDOW_MSData = m_lQuality_SEEKWINDOW_MS; quality_OVERLAP_MSData = m_lQuality_OVERLAP_MS; LPCTSTR WASAPIPreferredDeviceData = W2T(m_wWASAPIPreferredDeviceId); WriteRegistryKeyDword(hKey, enableTimestretching, enableTimestretchingData); WriteRegistryKeyDword(hKey, WASAPIExclusive, WASAPIExclusiveData); WriteRegistryKeyDword(hKey, WASAPIUseEventMode, WASAPIUseEventModeData); //WriteRegistryKeyDword(hKey, devicePeriod, devicePeriodData); WriteRegistryKeyDword(hKey, AC3Encoding, AC3EncodingData); WriteRegistryKeyDword(hKey, AC3bitrate, AC3bitrateData); WriteRegistryKeyDword(hKey, maxBias, maxBiasData); WriteRegistryKeyDword(hKey, minBias, minBiasData); WriteRegistryKeyDword(hKey, audioDelay, audioDelayData); WriteRegistryKeyDword(hKey, logSampleTimes, logSampleTimesData); WriteRegistryKeyDword(hKey, logDebug, logDebugData); WriteRegistryKeyDword(hKey, HWBasedRefClock, HWBasedRefClockData); WriteRegistryKeyDword(hKey, enableSyncAdjustment, enableSyncAdjustmentData); WriteRegistryKeyDword(hKey, forceSamplingRate, forceSamplingRateData); WriteRegistryKeyDword(hKey, forceBitDepth, forceBitDepthData); WriteRegistryKeyDword(hKey, resamplingQuality, resamplingQualityData); WriteRegistryKeyDword(hKey, speakerConfig, speakerConfigData); WriteRegistryKeyDword(hKey, forceChannelMixing, forceChannelMixingData); WriteRegistryKeyDword(hKey, releaseDeviceOnStop, releaseDeviceOnStopData); WriteRegistryKeyDword(hKey, expandMonoToStereo, expandMonoToStereoData); WriteRegistryKeyDword(hKey, quality_USE_QUICKSEEK, quality_USE_QUICKSEEKData); WriteRegistryKeyDword(hKey, quality_USE_AA_FILTER, quality_USE_AA_FILTERData); WriteRegistryKeyDword(hKey, quality_AA_FILTER_LENGTH, quality_AA_FILTER_LENGTHData); WriteRegistryKeyDword(hKey, quality_SEQUENCE_MS, quality_SEQUENCE_MSData); WriteRegistryKeyDword(hKey, quality_SEEKWINDOW_MS, quality_SEEKWINDOW_MSData); WriteRegistryKeyDword(hKey, quality_OVERLAP_MS, quality_OVERLAP_MSData); WriteRegistryKeyString(hKey, WASAPIPreferredDevice, WASAPIPreferredDeviceData); }
void AudioRendererSettings::LoadSettingsFromRegistry() { USES_CONVERSION; // this is required for T2W macro Log("Loading settings from registry"); HKEY hKey; char* lpData = new char[MAX_REG_LENGTH]; // settings from Reclock - watch CPU usage when enabling these! /*bool usequickseek = false; bool useaafilter = false; //seems clearer without it int aafiltertaps = 56; //Def=32 doesnt matter coz its not used int seqms = 120; //reclock original is 82 int seekwinms = 28; //reclock original is 28 int overlapms = seekwinms; //reduces cutting sound if this is large int seqmslfe = 180; //larger value seems to preserve low frequencies better int seekwinmslfe = 42; //as percentage of seqms int overlapmslfe = seekwinmslfe; //reduces cutting sound if this is large */ LPCTSTR WASAPIPreferredDeviceData = new TCHAR[MAX_REG_LENGTH]; ZeroMemory((void*)WASAPIPreferredDeviceData, MAX_REG_LENGTH); // Try to access the setting root "Software\Team MediaPortal\Audio Renderer" RegOpenKeyEx(HKEY_CURRENT_USER, folder, NULL, KEY_ALL_ACCESS, &hKey); if (hKey) { ReadRegistryKeyDword(hKey, enableTimestretching, enableTimestretchingData); ReadRegistryKeyDword(hKey, WASAPIExclusive, WASAPIExclusiveData); ReadRegistryKeyDword(hKey, WASAPIUseEventMode, WASAPIUseEventModeData); ReadRegistryKeyDword(hKey, devicePeriod, devicePeriodData); ReadRegistryKeyDword(hKey, AC3Encoding, AC3EncodingData); ReadRegistryKeyDword(hKey, AC3bitrate, AC3bitrateData); ReadRegistryKeyDword(hKey, maxBias, maxBiasData); ReadRegistryKeyDword(hKey, minBias, minBiasData); ReadRegistryKeyDword(hKey, audioDelay, audioDelayData); ReadRegistryKeyDword(hKey, logSampleTimes, logSampleTimesData); ReadRegistryKeyDword(hKey, logDebug, logDebugData); ReadRegistryKeyDword(hKey, HWBasedRefClock, HWBasedRefClockData); ReadRegistryKeyDword(hKey, enableSyncAdjustment, enableSyncAdjustmentData); ReadRegistryKeyDword(hKey, forceSamplingRate, forceSamplingRateData); ReadRegistryKeyDword(hKey, forceBitDepth, forceBitDepthData); ReadRegistryKeyDword(hKey, resamplingQuality, resamplingQualityData); ReadRegistryKeyDword(hKey, speakerConfig, speakerConfigData); ReadRegistryKeyDword(hKey, forceChannelMixing, forceChannelMixingData); ReadRegistryKeyDword(hKey, releaseDeviceOnStop, releaseDeviceOnStopData); ReadRegistryKeyDword(hKey, expandMonoToStereo, expandMonoToStereoData); // SoundTouch quality settings ReadRegistryKeyDword(hKey, quality_USE_QUICKSEEK, quality_USE_QUICKSEEKData); ReadRegistryKeyDword(hKey, quality_USE_AA_FILTER, quality_USE_AA_FILTERData); ReadRegistryKeyDword(hKey, quality_AA_FILTER_LENGTH, quality_AA_FILTER_LENGTHData); ReadRegistryKeyDword(hKey, quality_SEQUENCE_MS, quality_SEQUENCE_MSData); ReadRegistryKeyDword(hKey, quality_SEEKWINDOW_MS, quality_SEEKWINDOW_MSData); ReadRegistryKeyDword(hKey, quality_OVERLAP_MS, quality_OVERLAP_MSData); ReadRegistryKeyString(hKey, WASAPIPreferredDevice, WASAPIPreferredDeviceData); Log(" EnableTimestrecthing: %d", enableTimestretchingData); Log(" WASAPIExclusive: %d", WASAPIExclusiveData); Log(" WASAPIUseEventMode: %d", WASAPIUseEventModeData); Log(" AC3Encoding: %d (0 = disabled, 1 = auto, 2 = forced)", AC3EncodingData); Log(" AC3bitrate: %d", AC3bitrateData); Log(" MaxBias: %d", maxBiasData); Log(" MinBias: %d", minBiasData); Log(" AudioDelay: %d", audioDelayData); Log(" LogSampleTimes: %d", logSampleTimesData); Log(" LogDebug: %d", logDebugData); Log(" HWBasedRefClock: %d", HWBasedRefClockData); Log(" EnableSyncAdjustment: %d", enableSyncAdjustmentData); Log(" ForceSamplingRate: %d", forceSamplingRateData); Log(" ForceBitDepth: %d", forceBitDepthData); Log(" ResamplingQuality: %s", ResamplingQualityAsString(resamplingQualityData)); Log(" SpeakerConfig: %d", speakerConfigData); Log(" ForceChannelMixing: %d", forceChannelMixingData); Log(" ReleaseDeviceOnStop: %d", releaseDeviceOnStopData); Log(" ExpandMonoToStereo: %d", expandMonoToStereoData); Log(" quality_USE_QUICKSEEK: %d", quality_USE_QUICKSEEKData); Log(" quality_USE_AA_FILTER: %d", quality_USE_AA_FILTERData); Log(" quality_AA_FILTER_LENGTH: %d", quality_AA_FILTER_LENGTHData); Log(" quality_SEQUENCE_MS: %d", quality_SEQUENCE_MSData); Log(" quality_SEEKWINDOW_MS: %d", quality_SEEKWINDOW_MSData); Log(" quality_OVERLAP_MS: %d", quality_OVERLAP_MSData); Log(" DevicePeriod: %d (1 = minimal, 0 = driver default, other user defined)", devicePeriodData); Log(" WASAPIPreferredDevice: %s", WASAPIPreferredDeviceData); m_bUseWASAPI = true; if (enableTimestretchingData > 0) m_bUseTimeStretching = true; else m_bUseTimeStretching = false; if (WASAPIExclusiveData > 0) m_WASAPIShareMode = AUDCLNT_SHAREMODE_EXCLUSIVE; else m_WASAPIShareMode = AUDCLNT_SHAREMODE_SHARED; if (WASAPIUseEventModeData > 0) m_bWASAPIUseEventMode = true; else m_bWASAPIUseEventMode = false; if (expandMonoToStereoData > 0) m_bExpandMonoToStereo = true; else m_bExpandMonoToStereo = false; if (AC3EncodingData == DISABLED || AC3EncodingData == AUTO || AC3EncodingData == FORCED) m_lAC3Encoding = AC3EncodingData; else m_lAC3Encoding = 0; m_dMaxBias = (double)maxBiasData / 10000.0; m_dMinBias = (double)minBiasData / 10000.0; m_lAudioDelay = audioDelayData; if (logSampleTimesData > 0) m_bLogSampleTimes = true; else m_bLogSampleTimes = false; if (logDebugData > 0) m_bLogDebug = true; else m_bLogDebug = false; if (HWBasedRefClockData > 0) m_bHWBasedRefClock = true; else m_bHWBasedRefClock = false; if (enableSyncAdjustmentData > 0) m_bEnableSyncAdjustment = true; else m_bEnableSyncAdjustment = false; bool AC3EncodingForced = AC3EncodingData == FORCED; bool sampleRateAllowed = AllowedValue(gAllowedSampleRates, sizeof(gAllowedSampleRates) / sizeof(int), forceSamplingRateData); bool bitDepthAllowed = AllowedValue(gAllowedBitDepths, sizeof(gAllowedBitDepths) / sizeof(int), forceBitDepthData); if (AC3EncodingForced) { if (sampleRateAllowed && (forceSamplingRateData != 48000 && forceSamplingRateData != 44100)) { Log(" Warning: AC3 encoding forced and sampling rate set to non-matching!"); sampleRateAllowed = false; } } else if (AC3EncodingData == AUTO && (forceSamplingRateData != 48000 && forceSamplingRateData != 44100 && forceSamplingRateData != 0)) Log(" Warning: Using other than 48000 hz or 44100 hz sampling rates will disable AC3 encoding!"); if (sampleRateAllowed || forceSamplingRateData == 0) m_nForceSamplingRate = forceSamplingRateData; else { m_nForceSamplingRate = 0; if (forceSamplingRateData != 0) Log(" invalid forced sample rate!"); } if (bitDepthAllowed && !AC3EncodingForced || forceBitDepthData == 0) m_nForceBitDepth = forceBitDepthData; else { m_nForceBitDepth = 0; if (forceBitDepthData != 0) Log(" invalid forced bit depth!"); } if (AllowedValue(gAllowedResamplingQualities, sizeof(gAllowedResamplingQualities) / sizeof(int), resamplingQualityData)) m_nResamplingQuality = resamplingQualityData; else { m_nResamplingQuality = 4; Log(" invalid resampling quality setting, using 4 (SRC_LINEAR)"); } if (AllowedValue(gAllowedAC3bitrates, sizeof(gAllowedAC3bitrates) / sizeof(int), AC3bitrateData)) m_AC3bitrate = AC3bitrateData * 1000; else { m_AC3bitrate = DEFAULT_AC3_BITRATE; Log(" invalid AC3 bitrate, using 448"); } m_hnsPeriod = devicePeriodData; if (forceChannelMixingData > 0) m_bForceChannelMixing = true; else m_bForceChannelMixing = false; // TODO validate channel mask if (speakerConfigData > 0) { m_lSpeakerConfig = speakerConfigData; m_lSpeakerCount = ChannelCount(m_lSpeakerConfig); if (AC3EncodingForced && m_lSpeakerCount > 6 && m_bForceChannelMixing) { m_lSpeakerConfig = KSAUDIO_SPEAKER_5POINT1_SURROUND; m_lSpeakerCount = 6; Log(" Warning: incompatible settings. ForceChannelMixing + AC3 encoding forced + more than 6 channels"); } } else m_lSpeakerConfig = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; if (releaseDeviceOnStopData > 0) m_bReleaseDeviceOnStop = true; else m_bReleaseDeviceOnStop = false; if (quality_USE_QUICKSEEKData > 0) m_bQuality_USE_QUICKSEEK = true; else m_bQuality_USE_QUICKSEEK = false; if (quality_USE_AA_FILTERData > 0) m_bQuality_USE_AA_FILTER = true; else m_bQuality_USE_AA_FILTER = false; delete[] m_wWASAPIPreferredDeviceId; m_wWASAPIPreferredDeviceId = new WCHAR[MAX_REG_LENGTH]; wcsncpy(m_wWASAPIPreferredDeviceId, T2W(WASAPIPreferredDeviceData), MAX_REG_LENGTH); delete[] WASAPIPreferredDeviceData; } else // no settings in registry, create default values { Log("Failed to open %s", folder); Log("Initializing registry with default settings"); LONG result = RegCreateKeyEx(HKEY_CURRENT_USER, folder, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL); if (result == ERROR_SUCCESS) { Log("Success creating master key"); WriteRegistryKeyDword(hKey, enableTimestretching, enableTimestretchingData); WriteRegistryKeyDword(hKey, WASAPIExclusive, WASAPIExclusiveData); WriteRegistryKeyDword(hKey, WASAPIUseEventMode, WASAPIUseEventModeData); WriteRegistryKeyDword(hKey, devicePeriod, devicePeriodData); WriteRegistryKeyDword(hKey, AC3Encoding, AC3EncodingData); WriteRegistryKeyDword(hKey, AC3bitrate, AC3bitrateData); WriteRegistryKeyDword(hKey, maxBias, maxBiasData); WriteRegistryKeyDword(hKey, minBias, minBiasData); WriteRegistryKeyDword(hKey, audioDelay, audioDelayData); WriteRegistryKeyDword(hKey, logSampleTimes, logSampleTimesData); WriteRegistryKeyDword(hKey, logDebug, logDebugData); WriteRegistryKeyDword(hKey, HWBasedRefClock, HWBasedRefClockData); WriteRegistryKeyDword(hKey, enableSyncAdjustment, enableSyncAdjustmentData); WriteRegistryKeyDword(hKey, forceSamplingRate, forceSamplingRateData); WriteRegistryKeyDword(hKey, forceBitDepth, forceBitDepthData); WriteRegistryKeyDword(hKey, resamplingQuality, resamplingQualityData); WriteRegistryKeyDword(hKey, speakerConfig, speakerConfigData); WriteRegistryKeyDword(hKey, forceChannelMixing, forceChannelMixingData); WriteRegistryKeyDword(hKey, releaseDeviceOnStop, releaseDeviceOnStopData); WriteRegistryKeyDword(hKey, expandMonoToStereo, expandMonoToStereoData); WriteRegistryKeyDword(hKey, quality_USE_QUICKSEEK, quality_USE_QUICKSEEKData); WriteRegistryKeyDword(hKey, quality_USE_AA_FILTER, quality_USE_AA_FILTERData); WriteRegistryKeyDword(hKey, quality_AA_FILTER_LENGTH, quality_AA_FILTER_LENGTHData); WriteRegistryKeyDword(hKey, quality_SEQUENCE_MS, quality_SEQUENCE_MSData); WriteRegistryKeyDword(hKey, quality_SEEKWINDOW_MS, quality_SEEKWINDOW_MSData); WriteRegistryKeyDword(hKey, quality_OVERLAP_MS, quality_OVERLAP_MSData); delete[] m_wWASAPIPreferredDeviceId; m_wWASAPIPreferredDeviceId = new WCHAR[MAX_REG_LENGTH]; wcsncpy(m_wWASAPIPreferredDeviceId, T2W(WASAPIPreferredDeviceData), MAX_REG_LENGTH); WriteRegistryKeyString(hKey, WASAPIPreferredDevice, WASAPIPreferredDeviceData); } else Log("Error creating master key %d", result); } delete[] lpData; RegCloseKey (hKey); }