[comp.sys.apple2] What's wrong with this Pascal program?

myb@cernvax.cern.ch (michel bornand) (05/24/91)

Hi everybody. Here is a simple Pascal program for Apple IIGS with should
produce a sound at 16kHz. It does not work. What's wrong with it?
What did I miss?

Pascal testsound;

uses types,sound;

var gparms:SoundParamBlock;
    oneangle:array[1..16]of byte;

begin
     oneangle[1]:=$40;
     oneangle[2]:=$50;
     oneangle[3]:=$60;
     oneangle[4]:=$70;
     oneangle[5]:=$80;
     oneangle[6]:=$90;
     oneangle[7]:=$A0;
     oneangle[8]:=$B0;
     oneangle[9]:=$C0;
     oneangle[10]:=$B0;
     oneangle[11]:=$A0;
     oneangle[12]:=$90;
     oneangle[13]:=$80;
     oneangle[14]:=$70;
     oneangle[15]:=$60;
     oneangle[16]:=$50;
     gparms.waveStart:=@oneangle[1];
     gparms.waveSize:=16;
     gparms.fredOffset:=311;
     gparms.DOCBuffer:=1;
     gparms.bufferSize:=$0800;
     gparms.nextWave:=@gparms;
     gparms.volSetting:=255;
     FFStartSound($0A01,@gparms);

end.

Thank you for all suggestions.

myb@cernvm.cern.ch

myb@cernvax.cern.ch (michel bornand) (05/24/91)

Hi everybody! Here is a simple Pascal program for Apple IIGS which should
produce a sound at 16kHz. It does not work. What's wrong with it?
What did I miss?


program testsound;

uses types,sound;

var oneangle:array[1..16] of byte;
    gsoundparms:SoundParamBlock;

begin

     oneangle[1]:=$40;
     oneangle[2]:=$50;
     oneangle[3]:=$60;
     oneangle[4]:=$70;
     oneangle[5]:=$80;
     oneangle[6]:=$90;
     oneangle[7]:=$A0;
     oneangle[8]:=$B0;
     oneangle[9]:=$C0;
     oneangle[10]:=$B0;
     oneangle[11]:=$A0;
     oneangle[12]:=$90;
     oneangle[13]:=$80;
     oneangle[14]:=$70;
     oneangle[15]:=$60;
     oneangle[16]:=$50;

     gsoundparms.waveStart:=@oneangle;
     gsoundparms.waveSize:=16;
     gsoundparms.freqOffset:=311;
     gsoundparms.DOCBuffer:=1;
     gsoundparms.bufferSize:=$0800;
     gsoundparms.nextwave:=@gsoundparms;
     gsoundparms.volSetting:=255;

     FFStartSound($0A01,@gsoundparms);

end.

Thank you for all suggestions.

Micky

lanmaint@nssdca.gsfc.nasa.gov (Dave Yoest) (05/24/91)

In article <5397@cernvax.cern.ch>, myb@cernvax.cern.ch (michel bornand) writes...
>Hi everybody! Here is a simple Pascal program for Apple IIGS which should
>produce a sound at 16kHz. It does not work. What's wrong with it?
>What did I miss?
> 
>Thank you for all suggestions.
> 
>Micky

Your code may (or may not be) fine since I've never programed an 
Apple, but I suspect that you probably can't hear a 16KHZ tone
anyway. The frequency response of the human ear rolls off above
10-14 KHZ, so you may need LOTS of volume to detect an audio
signal at frequencies above 15KHZ and even then it may not be 
detectable. Do you have access to an oscilliscope, if so then
connect a probe to the audio output and see if you are generating
the signal electrically. It's also possible that IF you can hear
a 16KHZ tone, that the speaker you're using won't reproduce a tone
at that frequency. (DO dogs respond in any way when you test your
program?)  8)

Dave Yoest
LAN M&O section supervisor
NASA/Goddard Space Flight Center
Greenbelt, Md. USA

DYOEST@128.183.43.16
DYOEST@zaphod.gsfc.nasa.gov

lanmaint@nssdcb.gsfc.nasa.gov (Dave Yoest) (05/25/91)

In article <5397@cernvax.cern.ch>, myb@cernvax.cern.ch (michel bornand) writes...
>Hi everybody! Here is a simple Pascal program for Apple IIGS which should
>produce a sound at 16kHz. It does not work. What's wrong with it?
>What did I miss?
> 

code deleted

>Thank you for all suggestions.
> 
>Micky



Well,

 I don't know any apple, so you code might be fine, it might not work 
 at all. But keep the following in mind.

 1. The frequency response of the human ear rolls off at roughly
    14 KHZ. This means that at high frequencies you will need
    much more volume than the frequencies under 10KHZ. At some
    point you won't be able to hear the tone at all. This varies
    from individual to individual, and some rare individuals may
    be able to hear to 20 KHZ, but 16 KHZ is in the range where
    many people will not be able to detect the tone.

 2. The speaker you are driving must be able to produce a 16KHZ
    tone. The speaker built into the monitor you are using might
    not be capable of producing a tone at this frequency.



Suggestions:

 1. Try generating a 12KHZ tone. You should be able to hear that.
    Then a 13KHZ, Then 14KHZ etc. You may be able to determine if
    you can hear a 16KHZ tone. If you've never heard a 16KHZ tone
    before, you might not have a concept of what a tone of that
    frequency sounds like. I used to work on a lot of TV equipment
    , and with practice could detect the Horizontal oscillator
    frequency (actually the resonation of mechanical parts in the
    horizontal) at 15,734 HZ. It took some time to gain this ability
    because I didn't have the concept of a 15KHZ tone at first. The 
    step-up method might help you gain this concept.

 2. Preferred.... Use an oscilliscope connected to the audio output
    and look for the electrical signal that you want to drive the 
    speaker with. This method will also allow you to verify the
    accuracy of the frequency.


 3. See if the dogs in your area respond. 8-)


Dave Yoest
LAN M&O Section Supervisor
NASA/Goddard Space Flight Center
Greenbelt, Md. 20771

DYOEST@128.183.43.16
DYOEST@zaphod.gsfc.nasa.gov

jmuller@Stardent.COM (Jim Muller) (05/25/91)

In <5395@cernvax.cern.ch> myb@cernvax.cern.ch (michel bornand) writes:
>Here is a simple Pascal program...  What's wrong with it?

  [program deleted]

Pardon me but this triggered one of my pet peeves.  As far as can be told
by anyone who looks at your program and only your program, there isn't
anything wrong with it.  Is there anything wrong with how you used some
of the other stuff from the programming environment?  I dunno'!  You asked
the wrong question, because if there is a problem, it isn't in the Pascal
at all.  It is somewhere else.
----------------------
What's wrong with this?

program foo;
#include 'zip1.h'
#include 'zip2.h'
#include 'zip3.h'
main
{
};
(...yawn...oh, I forgot, AT&T changed /usr/include/sys/zip1.h last month,
so we need to put in a #define...or maybe we should leave it alone so it
will be portable and just compile wtih -D<whatever>...)
----------------------
What the world needs is a good set of rules, and enough exceptions that
nobody has to obey them.  Even better, let's have more Standards!  The
more Standards, the better!
-- 
                            __~o\____      ------------|\-----|
Jim Muller               ~ '-0-----0-`    --------|~--o|\|---:|  { repeat as }
jmuller@stardent.com -~-~----~-----~~------------o|-----o|----|  { necessary }

parkern@jacobs.CS.ORST.EDU (Neil Parker) (05/25/91)

In article <5395@cernvax.cern.ch> myb@cernvax.cern.ch (michel bornand) writes:
>Hi everybody. Here is a simple Pascal program for Apple IIGS with should
>produce a sound at 16kHz. It does not work. What's wrong with it?
>What did I miss?

Well...now that I'm at home where my manuals are, I guess I'll take a stab
at this...

>Pascal testsound;
 ^^^^^^
 Huh?  Do you mean "Program testsound;"?
>
>uses types,sound;
>
>var gparms:SoundParamBlock;
>    oneangle:array[1..16]of byte;
               ^^^
	       I don't know what version of Pascal you're using, but if
	       it's TML Pascal, you'll need "packed" in front of "array"--
	       otherwise your 8-bit bytes will all be 16 bits wide...
>
>begin
>[lotsa oneangle assignments deleted]
>     gparms.waveStart:=@oneangle[1];
>     gparms.waveSize:=16;
                       ^^
		       This says your waveform is 16 *PAGES* long, not
		       16 bytes!  The smallest possible waveform is 1
		       page.
>     gparms.fredOffset:=311;
>     gparms.DOCBuffer:=1;
                        ^
			Toolbox Ref 3 says the HIGH byte is significant,
			not the low byte--this should be $100, not 1.
>     gparms.bufferSize:=$0800;
                          ^^^^
			  Only the lowest 3 bits of this field are
			  significant.  The DOC buffer will be 2^bufferSize
			  pages long.  (Note that the resolution bits will
			  also be initialized from this value, so changing
			  it will change the pitch of your tone.)
>     gparms.nextWave:=@gparms;
>     gparms.volSetting:=255;
>     FFStartSound($0A01,@gparms);
>
>end.
 ^^^
 Does your Pascal compiler generate an implicit QUIT call when execution
 "runs off the end" like this?  I seem to recall reading somewhere that
 QUIT shuts down the tools, including the Sound Manager...

Speaking of shutting down tools, did you remember to call SoundStartUp?  I
didn't see see it anywhere in your code sample...

Suggestions:

     * Find out how your compiler handles array packing.
     * Make sure the length of your waveform is a multiple of 256.
     * Read pages 47-3 through 47-5 of Toolbox Ref 3.

		    - Neil Parker
--
Neil Parker                 No cute ASCII art...no cute quote...no cute
parkern@jacobs.cs.orst.edu  disclaimer...no deposit, no return...
parker@corona.uoregon.edu   (This space intentionally left blank:           )