Jump to content

  • Log In with Google      Sign In   
  • Create Account

XAudio2 controlling the pulse rate of a loop


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Naruto-kun   Members   -  Reputation: 339

Like
0Likes
Like

Posted 31 August 2014 - 09:58 AM

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?

 

Thanks.



Sponsor:

#2 Nik02   Crossbones+   -  Reputation: 2923

Like
0Likes
Like

Posted 01 September 2014 - 01:50 AM

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.


Niko Suni


#3 Naruto-kun   Members   -  Reputation: 339

Like
0Likes
Like

Posted 01 September 2014 - 12:28 PM

That's my point...I know that's what I want to do in theory but I cant seem to find anything on how the API will let me do that.



#4 Nik02   Crossbones+   -  Reputation: 2923

Like
0Likes
Like

Posted 02 September 2014 - 02:10 AM

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[i] = sample * 32767;

}
 

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


Edited by Nik02, 02 September 2014 - 06:22 AM.

Niko Suni





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS