Hi guys and gals I am new here and a complete novice on/to AppleScript.
(Apologies for any typos.)
I have searched everywhere to manipulate binary, that is 0x00 to 0xFF, so I had to resort to going down a level to the bash shell and let that do it for me.
I am going to jump in at the deep end and try to do an Audio Function Generator.
To show I mean business I bragged about writing a sophisticiated shell script as a text mode calibrated AudioScope, from DC to around 20KHz, using the MBP inline 4 pole mic/ear socket.
You will find the full history of it here so far, it has had a magazine write up and has 5 stars here:-
I knew absolutely nothing about shell scripting in Jan 2013 when I started this project much like ApplScripting now.
So you guys and gals are going to be my mentors, hopefully I can create an Arbitratry Audio Function Generator using basic Apple Scripting. This will be developed on an MBP, circa August 2012, OSX 10.7.5 with full XCode and used on a virgin iMac OSX 10.11.5 default install.
Here is the very beginning of my attempt at Applescript-ing and works perfectly well.
My question is it is ugly and relies on shell commands to create the binary files, is there an official way in AppleScripts to create binary files, simply?
Just noticed the word-wrapping, be aware…
Is there a better way?
TIA.
Bazza, G0LCU.
do shell script "#!/bin/bash
> /tmp/sinewave.wav
> /tmp/squarewave.wav
printf '%b' '\\x52\\x49\\x46\\x46\\x24\\x00\\x01\\x00\\x57\\x41\\x56\\x45\\x66\\x6d\\x74\\x20\\x10\\x00\\x00\\x00\\x01\\x00\\x01\\x00\\x40\\x1f\\x00\\x00\\x40\\x1f\\x00\\x00\\x01\\x00\\x08\\x00\\x64\\x61\\x74\\x61\\x00\\x00\\x01\\x00' >> /tmp/sinewave.wav
printf '%b' '\\x52\\x49\\x46\\x46\\x24\\x00\\x01\\x00\\x57\\x41\\x56\\x45\\x66\\x6d\\x74\\x20\\x10\\x00\\x00\\x00\\x01\\x00\\x01\\x00\\x40\\x1f\\x00\\x00\\x40\\x1f\\x00\\x00\\x01\\x00\\x08\\x00\\x64\\x61\\x74\\x61\\x00\\x00\\x01\\x00' >> /tmp/squarewave.wav
for waveform in {0..8191}
do
printf '%b' '\\x80\\x26\\x00\\x26\\x7F\\xD9\\xFF\\xD9' >> /tmp/sinewave.wav
printf '%b' '\\xFF\\xFF\\xFF\\xFF\\x00\\x00\\x00\\x00' >> /tmp/squarewave.wav
done
"
repeat
display dialog "Audio Function Generator, Version 0.00.01." buttons {"Sine", "Square", "Quit"} default button "Quit"
if result = {button returned:"Sine"} then
do shell script "/usr/bin/afplay /tmp/sinewave.wav"
else if result = {button returned:"Square"} then
do shell script "/usr/bin/afplay /tmp/squarewave.wav"
else if result = {button returned:"Quit"} then
exit repeat
end if
end repeat