PDA

View Full Version : SOUND command and variable array



flotulopex
- 25th March 2007, 12:12
Hello,

I'm (trying) playing sounds within an array.

Unfortunately, I don't get it working.

This is an extract of my (simplyfied) code.

...
Vsnd var byte [4]
Vsnd.0 = 121
Vsnd.1 = 120
Vsnd.2 = 119
Vsnd.3 = 116

FOR A = 0 to 3
SOUND Speaker,[Vsnd.A,10]
NEXT
...
Any idea what I'm doing wrong?

mat janssen
- 25th March 2007, 12:43
try:
FOR A = 0 to 3
SOUND Speaker,[Vsnd(A),10]
NEXT

flotulopex
- 25th March 2007, 13:37
Tried this one already.

Doesn't work either.

This one doesn't work aswel:
FOR A = 0 to 3
SOUND Speaker,[Vsnd.0(A),100]
NEXT

mat janssen
- 25th March 2007, 14:11
That is not what I typed.
Did you give "speaker" a portnumber?

Acetronics2
- 25th March 2007, 14:35
Hi, Flotul

What about Vsnd[A] instead ( Vsnd(A) or Vsnd.A ) ???

Did you also check the tones are compatible with your speaker bandwidth ???

just a thought ... for High audio frequencies.

Alain

flotulopex
- 25th March 2007, 14:44
mat janssen,

Don't worry: I copied/pasted your example "as it is" and it didn't work. I then posted another try I made. Sorry for the confusion.

I tried with both brakets or parenthesis; never works....

Yes, the sounds can be made correctly when not in this kind of referencing loop.

Still searching.

Acetronics2
- 25th March 2007, 14:50
Tried Brackets Here also ???

Vsnd.0 = 121
Vsnd.1 = 120
Vsnd.2 = 119
Vsnd.3 = 116


Vsnd.0 is bit 0 of Byte Vsnd ( which is also different from Vsnd[A] !!! ) ... can't work properly here !!!

Alain

flotulopex
- 25th March 2007, 15:08
Acetronics,

I'm not sure to understand your remark.

I tried this:
SOUND Speaker,[Vsnd(A),10]
and
SOUND Speaker,[Vsnd.0(A),10]
and
SOUND Speaker,(Vsnd[A],10)
and
SOUND Speaker,(Vsnd.0[A],10)

In fact, I get a sound but it is a much lower frequency than compared to when I play the sound like SOUND Speaker,[121,10].

Acetronics2
- 25th March 2007, 18:32
Tried THIS ???
...

Vsnd var byte [4]

Vsnd[0] = 121
Vsnd[1] = 120
Vsnd[2] = 119
Vsnd[3] = 116

FOR A = 0 to 3
SOUND Speaker,[Vsnd[A],10]
NEXT A

...

Alain

skimask
- 25th March 2007, 18:44
Acetronics,

I'm not sure to understand your remark.

I tried this:
SOUND Speaker,[Vsnd(A),10]
and
SOUND Speaker,[Vsnd.0(A),10]
and
SOUND Speaker,(Vsnd[A],10)
and
SOUND Speaker,(Vsnd.0[A],10)

In fact, I get a sound but it is a much lower frequency than compared to when I play the sound like SOUND Speaker,[121,10].

Do you have a cap on the output like the manual suggests? What kind of speaker are you driving? What's you OSC? Which PIC are you using?

speaker var portb.1:a var byte:for a=0 to 255:sound speaker,[a,50]:next a

or maybe:

vsnd var byte[3]:vsnd[0]=10:vsnd[1]=30:vsnd[2]=75:vsnd[3]=120
a var byte:for a=0 to 3:sound speaker,[vsnd[a],50]:next a

flotulopex
- 26th March 2007, 20:44
Thank you ACETRONICS,

You gave me the correct syntax.

Just to make sure, I tried this that works too:
Vsnd var byte [4]
Vsnd(0) = 121
Vsnd(1) = 120
Vsnd(2) = 119
Vsnd(3) = 116

FOR A = 0 to 3
SOUND Speaker,[Vsnd(A),10]
NEXT A
I personally would have appreciate to see this kind of example in the Compiler's manual instead of bothering you... I read it a few times, but without any clear example, it stayed unclear to me.

Thanks a lot for your help.

Acetronics2
- 27th March 2007, 11:00
Hi, Flotul

Just remember the same things must have EXACTLY the same name ...

I do not know if brackets and parenthesis (?) really work the same manner ... but manual says "Brackets" !!! ... so let's write Brackets !!!

no bad surprises involved ...

Alain

flotulopex
- 27th March 2007, 11:56
Thank you for pointing this out.

Manual shows "brackets" and this is maybe why I wanted to try with parenthesis too ;)

Again, there is almost anything needed in the manual - same as in the data-sheets.

Unfortunately, it is not always comprehensible for beginners like me.