8-bit waveform generator??

Algorithm development and general DSP issues

Moderator: frank

soundsubs
Posts: 24
Joined: Fri Feb 25, 2011 11:49 am

8-bit waveform generator??

Post by soundsubs »

hello group. lots of good people and good helpful info here.
1st post of course so be gentle! i am excited to learn these tricks.

first, i would like to make a waveform generator for my z-dsp that takes the input from the POT1 and POT2 and calculates an 8-bit waveform based on their position. i suppose this can be realtime?

secondly, i would like to make that play back at different speeds, based on control voltage input from an outside source. this would be something like "1 volt up = 2x playback speed", etc.
yes, this would be used to make an 8 bit sound generator for my modular system.

has anyone done anything like this yet?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Yeah, you can make a waveform generator rather easily, see http://www.spinsemi.com/forum/viewtopic.php?t=28 for doing a sin and square generator. You can use the AND function to mask to 8 bits for output and you should be able to use pots for freq and amp.
Frank Thomson
Experimental Noize
soundsubs
Posts: 24
Joined: Fri Feb 25, 2011 11:49 am

Post by soundsubs »

Thanks for the reply Frank!

i saw the sin/cos generator. i tried to study it but honestly its a little over my head because im brand new at this. ive tried to look at instructions for this, but im not getting anywhere. maybe i can type it out in plain english-code

step 1: get values of pot 0 and pot 1
(these are 120 and 013 respectively)
step 2: multiply them (or add them, or later divide them, or sin them)
step 3: convert the result into a simple waveform, 8 bits
step 4: play that out repeatedly
step 5: keep looping that at a regular rate.

at one end of the pots values, say 0000, there would be silence
at the other end of the pots values, say 9999, there would be noise.

i really appreciate the help here, its like school to me.
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

First, start with the knowledge base http://www.spinsemi.com/knowledge_base.html and read it many times over, if you are new at this it may take a little bit to get used to thinking in DSP terms.

You need to better describe the steps, for example what waveform (square, sine, triangle)? Exactly what do pots 0 and 1 do (frequency, amplitude, other)? Basically, be as specific as possible. Start with a simple program idea then make it more complex as you understand more.
Frank Thomson
Experimental Noize
soundsubs
Posts: 24
Joined: Fri Feb 25, 2011 11:49 am

Post by soundsubs »

the POT's dont actually do anything but return a value based on their position. from these positions, the code would generate a waveform based on the numbers-- not a saw/sin/square necessarily but an abnormal single cycle waveform. perhaps a binary one like this:

01001011010111010100101

both knobs CCW =
00000000000000000000000 (silence)
both knobs CW =
11111111111111111111111 (white noise)
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

What is the equation or algorithm that converts the values to a signal? Just multiplying two pot inputs together would result in a constant value unless the pot inputs are constantly changing. So first define the algorithm that converts the values to a signal and what the range of the input values and results are. Don't think about how to code it in the FV-1, first define the algorithm.
Frank Thomson
Experimental Noize
soundsubs
Posts: 24
Joined: Fri Feb 25, 2011 11:49 am

Post by soundsubs »

thats exactly what i want: a static waveform until the pots are changed.
..of course i would check the pots every few milliseconds for updates.

lets start with something that generates an 8 bit waveform perhaps.
if the pots are capable of values 0-127 then lets multiply them together to make an 8 bit number?

hope that make sense?

evntually, i want to vary the playback speed of stored waveform for voltage control.. but we'll get to that.
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

You're mixing terms so I'm not clear on what you want as an output. You say "8-bit waveform" but also give an example of a binary sequence "01001011010111010100101".

So, which is it?

Start writing a program and post it here and we can comment on it and help find bugs.
Frank Thomson
Experimental Noize
soundsubs
Posts: 24
Joined: Fri Feb 25, 2011 11:49 am

Post by soundsubs »

Alright. You asked for it!

so this....

Code: Select all

; this is supposed to be an 8-bit waveform generator going into a TipTop Audio Z-DSP module. 
; it is meant to grab pot values from pot 0 and pot1, multiply them, and then write a waveform generated from that number.
; it should constantly write this waveform over and over and over. 
; it doesnt have to necessarily be "8 bits long", right now i just want to mult the 2 pot values and play it out.
; eventually, it will track "pitch" as a voltage input which will allow waveforms to playback at a set speed. 
; note: this is my first dsp programming, and i have no idea what im doing. 
; shane etter = soundsubs@gmail.com

rdax	pot0,1		;read pot0 value, keep value positive between 0 and 1
wrax	reg1,0		;put this value to register3
rdax	pot1,-1		;read pot1 value, flip its sign to get negative between -1 and 0
wrax	reg2,0		;put this value to register4
; here is where the stupid starts!

skp run, loop
clr			;clear the accumulator
wrax reg1,0		;write accumulator to register1, multiplied by reg1 value which was pot0
wrax reg2,0		;write accumulator to register2, multiplied by reg2 value which was pot1
mulx reg1		;put the value from reg1 into accumulator	
mulx reg2		;put the value from reg2 into accumulator
wrax	dacl,0
loop:
; wow. ive stared at this for 4 hours now and generated silence with this code!
...does nothing.

im trying to just repeatedly loop the output which should be a multiplication of the two pot values.
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

OK, I see the logic but it is a little off, try this:

Code: Select all


; skp run,xxx means it will only execute the code between the skp
; command and the xxx label the first time the code is run, used for
; initilization so having the write to the dac in the skp section means 
; it will only be written to the first pass of code, not what you want
; 

skp run, loop
clr         ;clear the accumulator
wrax reg1,0      ;write accumulator to register1 which is 0 so it is cleared
wrax reg2,0      ;write accumulator to register2 so also cleared
loop:

rdax   pot0,1      ;read pot0 value, keep value positive between 0 and 1
wrax   reg1,0      ;put this value to register 1
rdax   pot1,-1      ;read pot1 value, flip its sign to get negative between -1 and 0
wrax   reg2,0      ;put this value to register2
rdax reg1      ;put the value from reg1 into accumulator   
mulx reg2      ;multiply by reg2
wrax   dacl,0
But there is a easier way to do this (haven't run piece of either code so watch for typos):

Code: Select all

clr ; clear accumulator
rdax pot1,-1  ; Read pot 1 * -1.0 into accumulator
mulx pot0  ; Multiply accumulator by pot 0
wrax dacl,0 ; write to left dac output

Frank Thomson
Experimental Noize
soundsubs
Posts: 24
Joined: Fri Feb 25, 2011 11:49 am

Post by soundsubs »

Thanks Frank.

first i tried:

Code: Select all

; this is supposed to be an 8-bit waveform generator going into a TipTop Audio Z-DSP module. 
; it is meant to grab pot values from pot 0 and pot1, multiply them, and then write a waveform generated from that number.
; it should constantly write this waveform over and over and over. 
; it doesnt have to necessarily be "8 bits long", right now i just want to mult the 2 pot values and play it out.
; eventually, it will track "pitch" as a voltage input which will allow waveforms to playback at a set speed. 
; note: this is my first dsp programming, and i have no idea what im doing. 
; shane etter = soundsubs@gmail.com

rdax	pot0,1		;read pot0 value, keep value positive between 0 and 1
wrax	reg1,0		;put this value to register3
rdax	pot1,-1		;read pot1 value, flip its sign to get negative between -1 and 0
wrax	reg2,0		;put this value to register4
; here is where the stupid starts!

; skp run,xxx means it will only execute the code between the skp 
; command and the xxx label the first time the code is run, used for 
; initilization so having the write to the dac in the skp section means 
; it will only be written to the first pass of code, not what you want 
; 

skp run, loop 
clr         ;clear the accumulator 
wrax reg1,0      		;write accumulator to register1 which is 0 so it is cleared 
wrax reg2,0      		;write accumulator to register2 so also cleared 
loop: 

rdax   pot0,1      		;read pot0 value, keep value positive between 0 and 1 
wrax   reg1,0      		;put this value to register 1 
rdax   pot1,-1      	;read pot1 value, flip its sign to get negative between -1 and 0 
wrax   reg2,0      		;put this value to register2 
rdax reg1,1      		;put the value from reg1 into accumulator    
mulx reg2      		;multiply by reg2 
wrax   dacl,0
that didnt do anything (but 'pop' once)

and then this:

Code: Select all

; this is supposed to be an 8-bit waveform generator going into a TipTop Audio Z-DSP module. 
; it is meant to grab pot values from pot 0 and pot1, multiply them, and then write a waveform generated from that number.
; it should constantly write this waveform over and over and over. 
; it doesnt have to necessarily be "8 bits long", right now i just want to mult the 2 pot values and play it out.
; eventually, it will track "pitch" as a voltage input which will allow waveforms to playback at a set speed. 
; note: this is my first dsp programming, and i have no idea what im doing. 
; shane etter = soundsubs@gmail.com

rdax	pot0,1		;read pot0 value, keep value positive between 0 and 1
wrax	reg1,0		;put this value to register3
rdax	pot1,-1		;read pot1 value, flip its sign to get negative between -1 and 0
wrax	reg2,0		;put this value to register4
; here is where the stupid starts!

; skp run,xxx means it will only execute the code between the skp 
; command and the xxx label the first time the code is run, used for 
; initilization so having the write to the dac in the skp section means 
; it will only be written to the first pass of code, not what you want 
; 

clr ; clear accumulator 
rdax pot1,-1  ; Read pot 1 * -1.0 into accumulator 
mulx pot0  ; Multiply accumulator by pot 0 
wrax dacl,0 ; write to left dac output 
...with the same single 'pop' then nothing.

i wonder what/where writes the stored accumulator value over and over?
perhaps we need to generate a binary value, of xxx length, over and over?
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Actually the code is doing exactly what it is designed to do, the problem is that it does not generate any sort of waveform.

If pot0 = 0.5 and pot1 = 0.25 then pot0*pot1 = 0.125, a constant DC value, not a waveform so the FV-1 outputs 0.125 and you hear nothing because it is DC.

You need to define a function that creates a waveform, multiplying two pot inputs does not do that.
Frank Thomson
Experimental Noize
soundsubs
Posts: 24
Joined: Fri Feb 25, 2011 11:49 am

Post by soundsubs »

wow. i didnt think i could do it but i actually googled through the entire internet looking for an answer. im still not sure how to do this, so i'll be dumb and just post an easier method.

if we define the "oscillator" in a preset table, we should be able to play back that table at an audio rate repeatedly and get sound.
in this case the numbers are voltages output to the DAC
for example
playing 123456789 over and over would be a ramp waveform
and 987654321 over and over would be a sawtooth.
and 000099999 over and over would be a square wave
and so on.
to apply this to the fv-1 language, im not sure if we'd have to place it into the head of the delay memory and selectively read out portions of this now-stored table?
or maybe thats totally the wrong way to go about it?
staring at the sawtooth/sine/square wave programs and examples is frying my brain; im finding it pretty much tantamount to rocket science going from 0 (where i am) to "i can make a program", partly because ive never seen this before and partly because the wiki (and this forum, to some extent) have no examples for complete noobs like me.
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

OK, the FV-1 is not really designed for wavetable synthesis so we typically have to define signal generation in terms of some algorithm that can be looped.

This site and the chip are not really designed for a beginner, most people either have learned DSP in school/on the job, or they are experienced micro-controller programmers and are moving into DSP or are experienced analog audio designers (pedals, amps, etc.) and are moving into the DSP field for some reason. So this site and chip are really geared to the engineer or product designer.

So, if you don't have experience in at least one of the above areas the chip is going to drive you bonkers because it requires some understanding of all three areas to really use it.

I would recommend that you first learn about basic micro-controller programming, the 8051 series (from Intel) is a nice basic one. You would not use it for audio processing but it is a good way to learn the basics of micro programming. The FV-1 is a DSP which is a special form of micro and is a bit more complex to understand than an 8051 (8051 does not have circular memory, no log or exp functions, etc.)
Frank Thomson
Experimental Noize
peterv
Posts: 17
Joined: Fri Nov 20, 2009 3:43 am
Location: Netherlands
Contact:

Post by peterv »

Re: This site and the chip are not really designed for a beginner, most people either have learned DSP in school/on the job, or they are experienced micro-controller programmers and are moving into DSP or are experienced analog audio designers (pedals, amps, etc.) and are moving into the DSP field for some reason. So this site and chip are really geared to the engineer or product designer.

I think, I can add value to Frank's statement. Myself I've got about 20 years of experience in programming in assembler, smalltalk, C and C++ as a professional at multinationals. The FV-1 DSP processor is not too difficult to learn but the inner workings of, as an example, the filters are. Most of the hurdles I've hit during my project could be resolved reading this excellent forum and the, again, excellent supporting documentation and samples on this site and, last but not least, the perfect support by Frank if requested( being world class!!) . One observation that is different from the microprocessor world is not being able to debug/read out registers

Piet
Post Reply