Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

SetFrequencyRatio() does not seem to work for me. Below is the source code I'm using. It reads the frequency with GetFrequencyRatio before and after calling SetFrequencyRatio(1.3). But it prints out 1.0 even after the call to SetFrequencyRatio(1.3) and I don't know why. What am I doing wrong?

#include <windows.h>
#include <stdio.h>
#include <XAudio2.h>

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) {
    WAVEFORMATEX format;
    format.wFormatTag = 1;
    format.nChannels = 1;
    format.nSamplesPerSec = 44100;
    format.nAvgBytesPerSec = 44100;
    format.nBlockAlign = 1;
    format.wBitsPerSample = 8;
    format.cbSize = 0;

    CoInitializeEx(NULL, COINIT_MULTITHREADED);

    IXAudio2* pXAudio2 = NULL;
    IXAudio2SourceVoice* source = NULL;
    IXAudio2MasteringVoice* master = NULL;

    HRESULT hr;
    if ( FAILED(hr = XAudio2Create( &pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR ) ) ) {
        MessageBox(0, L"hi", L"hi", 0);
        return hr;
    }

    if ( FAILED(hr = pXAudio2->CreateMasteringVoice(&master ) ) ) {
        MessageBox(0, L"hi", L"hi", 0);
        return hr;
    }

    if ( FAILED(hr = pXAudio2->CreateSourceVoice(&source, &format, 0, XAUDIO2_MAX_FREQ_RATIO ) ) ) {
        MessageBox(0, L"hi", L"hi", 0);
        return hr;
    }

    float freq = 0.0;
    source->GetFrequencyRatio(&freq);

    char str[30];
    sprintf(str, "%f", freq);
    MessageBoxA(0, str, str, 0);

    if ( FAILED(hr = source->SetFrequencyRatio(1.3) ) ) {
        MessageBox(0, L"hi", L"hi", 0);
        return hr;
    }
    pXAudio2->CommitChanges(0);

    source->GetFrequencyRatio(&freq);
    sprintf(str, "%f", freq);
    MessageBoxA(0, str, str, 0);

    return 0;
}
share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.