Jump to content
  • Advertisement
Sign in to follow this  

XAudio2 controlling the pulse rate of a loop

This topic is 1364 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys


Im having a tough time figuring out the MS documentation here. I have a tone that I want to loop, where depending on the conditions I input, it will either be a solid tone, or a set of beep pulses. However I need to change the rate at which the beeps pulse without changing the pitch/frequency of the tone. Any ideas?



Share this post

Link to post
Share on other sites

This is audio synthesis, MSDN cannot really guess what audio you want to play :)


Anyway, modulate (multiply) your beep sound (which is solid frequency) with a square wave that is at much lower frequency and clamped from 0 to 1. The square wave will provide the beep period.

Share this post

Link to post
Share on other sites

The API supports speeding up playback of a whole voice, but in your case - since the pulse frequency and beep tone frequency are independent - you need to mix the sound yourself to get the desired effect. XAudio does not (IIRC) support modulating two streams out of the box.


This tutorial shows you how to do streaming from a file; in your case, instead of submitting data loaded from file, you'd submit the data you mixed in memory.


The formula would be something like this (somewhat metacode):



Tau = pi * 2 // full phase of a sine

BeepTone = 880 * Tau / sampleRate // 880 Hz beep

PulseFrequency = 1 / sampleRate; // low frequency oscillator frequency for pulse; you can modify this. Currently 1 pulse per second.

signed int16 soundBuffer[bufferSize]; // this is the buffer you'd submit to the source voice; assuming 16-bit mono

for i = 0 to bufferSize -1


    // synthesis: multiply a solid 880Hz sine with square pulse of 1Hz

    float sample = sin(BeepTone * i) * squarewave(PulseFrequency * i); // square wave range should be 0 to 1 

    // scale to signed int16 range

    soundBuffer = sample * 32767;


// soundBuffer now contains the mixed wave to submit to source voice

Edited by Nik02

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!