Sponsored Content
Top Forums Shell Programming and Scripting Simple Scientific calculator for ADE, the UNIX environment for the AMIGA A1200(HD). Post 303037057 by wisecracker on Monday 22nd of July 2019 12:33:42 PM
Old 07-22-2019
A very practical use of scicalc and this will be the last upload...
I am creating an audio function generator and wanted to use ASCII only for all of the waveforms so that a simple arbitrary waveform could be created using a text editor, and all other waveforms can be edited too.
Well this is not fast but generates a sinewave in pure ASCII only. It is a practical use of 'scicalc'.
Code:
#!/bin/sh

# #!/usr/local/bin/dash
# text_sinewaves.sh

WAVEFORM=""

# 64 bytes per cycle:
# for ANGLE in $( seq 0.0 5.625 359.0 )
# 8 bytes per cycle:
for ANGLE in $( seq 0.0 45.0 359.0 )
do
    FLOAT=$( ~/Desktop/Code/Shell/scicalc "(((sin((${ANGLE}*pi)/180)+1)/2.0)*94)+32" )
    # Don't use awk's """int()""" function as it rounds down only, use """printf "%.0f" ...""" instead.
    WAVEFORM=${WAVEFORM}$( printf \\$( printf "%03o" $( printf "%.0f" "${FLOAT}" ) ) )
done
echo "${WAVEFORM}"
echo "Length = ${#WAVEFORM} bytes."

Results; editing for both for loops:
Code:
Last login: Mon Jul 22 16:18:46 on ttys000
AMIGA:amiga~> cd Desktop/Code/Shell
AMIGA:amiga~/Desktop/Code/Shell> ./text_sinewaves.sh
OTX]aeimpsvxz|}~~~}|zxvspmiea]XTOJFA=951.+(&$"!   !"$&(+.159=AFJ
Length = 64 bytes.
AMIGA:amiga~/Desktop/Code/Shell> ./text_sinewaves.sh
Op~pO. .
Length = 8 bytes.
AMIGA:amiga~/Desktop/Code/Shell> _

How does it work:
First things first, there are 95 normal printable ASCII characters from ASCII 32 decimal " ", and ASCII 126 decimal "~".
The _centreline_ character is ASCII 79 decimal "O", (not ZERO but capital O).
So we have three conditions to take care of, the minimum value must be no less than ASCII 32 " ", the centreline pseudo-DC ASCII 79 "O", (Direct Current level), and finally the maximum value must be no more ASCII 126 "~".

Now consider the expression "(((sin((${ANGLE}*pi)/180)+1)/2.0)*94)+32" ...
There is no need for any start and end parentheses as this is catered for inside 'scicalc'; it does not matter if you add them though.
As 'sin(x)' from 0 to 360 degrees goes from 0 to +1 to 0 to -1 and finally back to 0 again we have to remove the negative part so +1 is added to every calculated result.
This now moves the values to 1 to 2 to 1 to 0 and finally back to 1 again.
When that is done those values are divided by 2 to give the range 0.5 to 1 to 0.5 to 0 and finally back to 0.5.
0.5 is now the centreline, or DC, and this is now multiplied by the (number_of_printable_characters - 1).
We are not done yet; as this will go from 0.0 to 94.0 then the whole has to be shifted up so 0.0 becomes 32.0 and 94.0 becomes 126.0 so 32 must be finally added, and voila, using the script 8 or 64 byte ASCII single cycle pseudo-sinewave is created.
I hope this is lucid enough.
Note that 'printf "%.0f" ' is used to create the integer values, see the code...
(And also doing this manually would take ages.)
Enjoy...

Bazza.

Last edited by wisecracker; 07-22-2019 at 01:49 PM.. Reason: Code tags, adding spaces.
 

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple script to return environment variable

HI , In the below script I am trying to return the value of the environment variable TIBCO_HOME to the caller #! /usr/bin/csh set VAR_NAME=$1 echo VAR_NAME On the aix console.. set to setenv TIBCO_HOME /app/tibco When I execute the script... myscript.sh TIBCO_HOME, the script... (5 Replies)
Discussion started by: bce_groups
5 Replies

2. Shell Programming and Scripting

How to calculate unix epoch time with DC(Calculator)

Hi All, In our code we are using below code to calculate the UNIX Epoch Time from the time stamp present in the file. Can any one explain how the DC operates in below command and how we calculate the UNIX EPOCH time from this. Date incide the file is 20:26:51 Output we get is 1289943554... (3 Replies)
Discussion started by: mithunpatel
3 Replies

3. Shell Programming and Scripting

Simple maths calculator loop.

Hi, I am trying to make a maths calculator that: 1. Prompts the user for a number. 2. Prompts the user for an operation (add, subtract, divide or multiply) 3. Prompts the user for a number. 4. Prompts the user for another operation (same as above) OR the option to get the result for the... (4 Replies)
Discussion started by: johnthebaptist
4 Replies

4. Shell Programming and Scripting

Simple calculator with menu input - Need Help

I am trying to make a calculator. The user Enters number 1, chooses and operation, enters number 2, then chooses another operation or for the answer to be displayed. eg. 1 + 1 = or 1 + 1 + 2 + 1 = Both of these should be possible. #!/bin/bash read -p "what's the first number? " n1... (3 Replies)
Discussion started by: redshine6
3 Replies

5. Homework & Coursework Questions

Simple Calculator

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known/data: Script a simple calculator. In the command line enter the script file /home/etc/mycalc or /home/etc/mycalc 1 +... (6 Replies)
Discussion started by: herb bertz
6 Replies

6. Programming

Casio FX-CG50 Scientific Calculator and Python

Well, I think I must have this for Christmas! Python on the Casio FX-CG50 with Data Acquisition YT: CASIO fx-CG50 E-CON4 Movie YT: Update Your CG50 Operating System. Now Includes Python! (OS update) This is a great deal on Amazon! See YT Code Tag Video (9 Replies)
Discussion started by: Neo
9 Replies
PERLAMIGA(1)						 Perl Programmers Reference Guide					      PERLAMIGA(1)

NAME
perlamiga - Perl under Amiga OS NOTE
Perl 5.8.0 cannot be built in AmigaOS. You can use either the maintenance release Perl 5.6.1 or the development release Perl 5.7.2 in Ami- gaOS. See "PERL 5.8.0 BROKEN IN AMIGAOS" if you want to help fixing this problem. SYNOPSIS
One can read this document in the following formats: man perlamiga multiview perlamiga.guide to list some (not all may be available simultaneously), or it may be read as is: either as README.amiga, or pod/perlamiga.pod. A recent version of perl for the Amiga can be found at the Geek Gadgets section of the Aminet: http://www.aminet.net/~aminet/dev/gg/index.html DESCRIPTION
Prerequisites for Compiling Perl on AmigaOS Unix emulation for AmigaOS: ixemul.library You need the Unix emulation for AmigaOS, whose most important part is ixemul.library. For a minimum setup, get the latest versions of the following packages from the Aminet archives ( http://www.aminet.net/~aminet/ ): ixemul-bin ixemul-env-bin pdksh-bin Note also that this is a minimum setup; you might want to add other packages of ADE (the Amiga Developers Environment). Version of Amiga OS You need at the very least AmigaOS version 2.0. Recommended is version 3.1. Starting Perl programs under AmigaOS Start your Perl program foo with arguments "arg1 arg2 arg3" the same way as on any other platform, by perl foo arg1 arg2 arg3 If you want to specify perl options "-my_opts" to the perl itself (as opposed to your program), use perl -my_opts foo arg1 arg2 arg3 Alternately, you can try to get a replacement for the system's Execute command that honors the #!/usr/bin/perl syntax in scripts and set the s-Bit of your scripts. Then you can invoke your scripts like under UNIX with foo arg1 arg2 arg3 (Note that having *nixish full path to perl /usr/bin/perl is not necessary, perl would be enough, but having full path would make it easier to use your script under *nix.) Shortcomings of Perl under AmigaOS Perl under AmigaOS lacks some features of perl under UNIX because of deficiencies in the UNIX-emulation, most notably: o fork() o some features of the UNIX filesystem regarding link count and file dates o inplace operation (the -i switch) without backup file o umask() works, but the correct permissions are only set when the file is finally close()d INSTALLATION
Change to the installation directory (most probably ADE:), and extract the binary distribution: lha -mraxe x perl-$VERSION-bin.lha or tar xvzpf perl-$VERSION-bin.tgz (Of course you need lha or tar and gunzip for this.) For installation of the Unix emulation, read the appropriate docs. Accessing documentation Manpages for Perl on AmigaOS If you have "man" installed on your system, and you installed perl manpages, use something like this: man perlfunc man less man ExtUtils.MakeMaker to access documentation for different components of Perl. Start with man perl Note: You have to modify your man.conf file to search for manpages in the /ade/lib/perl5/man/man3 directory, or the man pages for the perl library will not be found. Note that dot (.) is used as a package separator for documentation for packages, and as usual, sometimes you need to give the section - 3 above - to avoid shadowing by the less(1) manpage. Perl HTML Documentation on AmigaOS If you have some WWW browser available, you can build HTML docs. Cd to directory with .pod files, and do like this cd /ade/lib/perl5/pod pod2html After this you can direct your browser the file perl.html in this directory, and go ahead with reading docs. Alternatively you may be able to get these docs prebuilt from "CPAN". Perl GNU Info Files on AmigaOS Users of "Emacs" would appreciate it very much, especially with "CPerl" mode loaded. You need to get latest "pod2info" from "CPAN", or, alternately, prebuilt info pages. Perl LaTeX Documentation on AmigaOS Can be constructed using "pod2latex". BUILDING PERL ON AMIGAOS
Here we discuss how to build Perl under AmigaOS. Build Prerequisites for Perl on AmigaOS You need to have the latest ixemul (Unix emulation for Amiga) from Aminet. Getting the Perl Source for AmigaOS You can either get the latest perl-for-amiga source from Ninemoons and extract it with: tar xvzpf perl-$VERSION-src.tgz or get the official source from CPAN: http://www.cpan.org/src/5.0 Extract it like this tar xvzpf perl-$VERSION.tar.gz You will see a message about errors while extracting Configure. This is normal and expected. (There is a conflict with a similarly-named file configure, but it causes no harm.) Making Perl on AmigaOS Remember to use a hefty wad of stack (I use 2000000) sh configure.gnu --prefix=/gg Now type make depend Now! make Testing Perl on AmigaOS Now run make test Some tests will be skipped because they need the fork() function: io/pipe.t, op/fork.t, lib/filehand.t, lib/open2.t, lib/open3.t, lib/io_pipe.t, lib/io_sock.t Installing the built Perl on AmigaOS Run make install PERL 5.8.0 BROKEN IN AMIGAOS As told above, Perl 5.6.1 was still good in AmigaOS, as was 5.7.2. After Perl 5.7.2 (change #11423, see the Changes file, and the file pod/perlhack.pod for how to get the individual changes) Perl dropped its internal support for vfork(), and that was very probably the step that broke AmigaOS (since the ixemul library has only vfork). The build finally fails when the ext/DynaLoader is being built, and PERL ends up as "0" in the produced Makefile, trying to run "0" does not quite work. Also, executing miniperl in backticks seems to generate nothing: very probably related to the (v)fork problems. Fixing the breakage requires someone quite familiar with the ixemul library, and how one is supposed to run external commands in AmigaOS without fork(). AUTHORS
Norbert Pueschel, pueschel@imsdd.meb.uni-bonn.de Jan-Erik Karlsson, trg@privat.utfors.se SEE ALSO
perl(1). perl v5.8.0 2003-02-18 PERLAMIGA(1)
All times are GMT -4. The time now is 12:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy