Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Keoni29 on September 24, 2011, 04:34:58 am

Title: Pulse width modulation
Post by: Keoni29 on September 24, 2011, 04:34:58 am
I want to generate custom waveforms from a wavetable so I want to know how exactly can you controll the frequency acurately since pause gives me very low frequencies.
This is the wavetable of a saw for instance:

 _    _    __   __  ____

_ ____ ____  ___  __   

I really don't know if this is going to work :P

Title: Re: Pulse width modulation
Post by: Builderboy on September 24, 2011, 04:37:28 am
Maybe use a simple for loop for your delay?  For loops are pretty fast so it would give you some of the highest control of the possible delay.
Title: Re: Pulse width modulation
Post by: Keoni29 on September 24, 2011, 04:47:59 am
Is this okay?
Code: [Select]
Lbl WAVE
.Gbd1WV is the wavetable that consists of 1's and 0's
.r1 is the delay between
.r2 is the amount of waves
for(C,0,r2
  for(B,0,31
    {Gbd1WV+B}->port
    while 1
      A+1->A
    endif A=r1
  end
end
Title: Re: Pulse width modulation
Post by: Builderboy on September 24, 2011, 04:52:25 am
Note that you will have to reset A every itteration, or else once it gets to r1, it the while loop will only execute once after that.  You could also decide to set A to r1, and decrement A instead of incrementing it, and use an End!IF A, which would make it slightly faster I believe. 
Title: Re: Pulse width modulation
Post by: Keoni29 on September 24, 2011, 05:11:01 am
Lolthatsstupid :) Changed it:
Code: [Select]
Lbl WAVE
.Gbd1WV is the wavetable that consists of 1's and 0's
.r1 is the delay between
.r2 is the amount of waves
for(C,0,r2
  for(B,0,31
    {Gbd1WV+B}->port
    r1->A
    while 1
      A-1->A
    end!if A
  end
end
Will this work?

Title: Re: Pulse width modulation
Post by: calc84maniac on September 24, 2011, 10:10:47 am
Here's a more optimized version (which will probably allow you to use more precise values for r1)
Code: [Select]
While 1
  GDB1WV
  For(32)
    {->r3}->Port
    r1
    While 1
    End!If -1
    r3+1
  End
End!If r2-1->r2

Edit: Removed an unnecessary store instruction
Title: Re: Pulse width modulation
Post by: Keoni29 on September 25, 2011, 03:20:34 am
Next step: Blending sound. The Idea is that the notes blend even if they're 3 "steps long" and another note from the other channel that is just one step long comes in the second step.

Like this:
|1  ||2  ||3  |

     [A-3]
[C-2__________]

|1  ||2  ||3  |


How do I tackle this problem?

I made a white noise generator too with pretty awesome results:
Code: [Select]
While 1
  rand^4->Port
  r1
  While 1
  End!If -1
End!If r2-1->r2
Title: Re: Pulse width modulation
Post by: Keoni29 on September 26, 2011, 01:01:38 pm
I figured that there has to be a 30% duty cycly within a duty cycle to blend the sounds from 3 channels. Can I blend the sounds acurately?