I had not even thought about my first line except that I don't know how to create a zero length file > somefile in awk yet.
I use the system() function to do this task at the moment...
You might have noticed that I removed that system() call in the code I suggested. Scrutinizer has already shown you how to create a zero length file entirely using awk using printf with a redirection. But, since your code always creates this file with data, there is no need to do that. You can create a file (and remove any pre-existing contents, if there were any) in awk just like you can in the shell by redirecting an output command, such as the way I did with:
I should, however, have added:
after that line to flush the output buffer and release the file descriptor.
You could certainly change the script from:
to:
and avoid invoking an extra shell to run your awk script.
But, if you want your script to process command-line options, using getopts in the shell is much easier than trying to duplicate its capabilities inside awk. And, if you have a configuration file that should always be given as the first file operand to your script (and you don't want users to have to type that configuration file's name every time they invoke your script), it is easier to process if you use a shell script to invoke awk instead of just having a awk only script:
versus:
And, if you're creating temp files in your script that you want to remove when your script is done, the following two scripts are equally efficient as to the number of processes invoked:
versus:
but the shell version will remove the temp file even if the script is killed (except by kill -9) while the awk version will leave the temp file laying around if it is killed. And the shell version can have multiple instances running without them interfering with each other because it creates a unique temp file for each running script while the awk version has a single temp file that will be removed by the 1st instance that exits leaving other running instances with no temp file to process (producing errors when sox tries to process the non-existent temp file).
As frequently happens, this is another instance where UNIX systems give you several ways to do things and you need to decide which best suits your needs.
These 2 Users Gave Thanks to Don Cragun For This Post:
Don...
Your code did not work initially I had to do some minor changes. BYTES is removed as the number '8' is bit depth per sample and will never change.
The reason is I want everything in this project to be pure ASCII including waveform generation; therefore 16 bit depth is a none starter and has two problems:-
1) You have to tell sox whether the two bytes per sample are big or little endian on raw data.
This is not necessary on 8 bit data.
2) Because of 1) there will ALWAYS be binary values and this defeats text mode waveform generation.
This also means I can create an arbitrary waveform in any text editor...
LBNL. I have no intention at this point of deleting the TMPFILEs so I have commented 'rm' out...
Mods to your code:-
It now works...
A derivative of your code will be my starting point many thanks.
BTW your code answered my next question about global variables thanks for that too.
Hi all...
This is the very start of all of the waveforms...
SINEWAVE16, SINEWAVE64, TRIANGLE16 and TRIANGLE64 have not yet been worked out WRT to correct values but this is the finished waveform generation variable and file section.
All file lengths are 524288 bytes in size.
During doing this I got the error:-
"""
/usr/bin/awk: /tmp/pulseplus64.raw makes too many open files
source line number <somenumber>
"""
And www.unix.com came to the rescue yet again:- nawk - file limits
All criticisms welcome...
Hi all...
This is the very start of all of the waveforms...
SINEWAVE16, SINEWAVE64, TRIANGLE16 and TRIANGLE64 have not yet been worked out WRT to correct values but this is the finished waveform generation variable and file section.
All file lengths are 524288 bytes in size.
During doing this I got the error:-
"""
/usr/bin/awk: /tmp/pulseplus64.raw makes too many open files
source line number <somenumber>
"""
And www.unix.com came to the rescue yet again:- nawk - file limits
All criticisms welcome...
Hi wisecracker,
You didn't have to go searching for the too many open files problem; it was already discussed in this thread. (Take a look at post #8 in this thread again.)
Your comments say that ARBITRARY can be any length from 2 to 1024 bytes, but that isn't really true. Any change to the length of that string would also require a change tot he LOOPS variable. And, with the way you are creating the strings you're writing to your files, ARBITRARY (and all of the waveforms have to have lengths that are a power of two.
Any time you are doing the same thing more than two or three times, I strongly suggest that you consider using a function. The following gets rid of your hard coded loop counts for various input waveform lengths, runs a little faster (since space is only needed for one .5Mb string instead of growing each of your waveform strings to .5Mb), and makes it much easier if you ever want to create shorter or longer files (just change the SIZE variable to a different value that is still a power of 2):
This User Gave Thanks to Don Cragun For This Post:
# defined, $VER will not be expanded in an awk string constant.
This made me smile...
It is not meant to be a variable at all.
As I am still an ancient AMIGA _fanatic_ this is how any executable file in the AMIGA directory tree displays what the program and its version is when _asked_. $VER is always the first 4 characters followed by a space and after that is pure text. I use underscores instead of other spaces.
So if you see anything of mine it will always have $VER in it. In AudioScope the '$' is escaped so as not to be confused with a variable in 'sh'...
It is a quirk of mine...
All of the files are now created but I forgot about the 'close()' you mentioned in post 8, my bad.
Anyhow it looks as though this creation will be yours too... ;oD
Once again you have added to my learning and I had thought about a function but was not sure at this stage where to start.
As for the ARBITRARY waveform size anything greater that 480,000 bytes is OK and that was my next job...
2 questions:-
Eventually for the ARBITRARY generation I was going to call the shell command ed as this is difinitve on all versions of Linux and UNIX flavours.
1) Which editor would you use to call?
2) Is it possible to save the file without a newline?
I have checked three editors, 'Gedit' is my GUI editor of choice, 'ed' and 'vi(m)'. I might be missing something with 'ed' and 'vi(m)' as I am no expert by any stretch of the imagination...
Hello
I use a bash script to creating the hosts file /etc/hosts
But there is a bug inside my output and I want to fix this.
My Array looks like this:
205,IP 111.122.133.20
205,HOST2 unas
205,HOST1 unas15533
205,COMMENT # UNAS
775,IP ... (9 Replies)
Hi all...
Well I have not been inactive but working out how to make OSX 10.14.x command line audio player have a variable sample rate.
This is a back door as afplay does not have a sample rate flag unlike aplay for ALSA, in Linux flavours.
This is a DEMO only but a derivative of it will... (2 Replies)
Hi all...
I intend to do an Audio Function Generator using Awk, (already started thanks to Don), but the biggest thing I have struggled with was variable frequency.
I was going to generate differing sized waveforms on the fly but that would that would mean the frequencies are dependent on any... (2 Replies)
This is a small program as a tester for a basic sweep generator for bandwidth testing of AudioScope.sh.
This DEMO is only capable of 4KHz down to about 85Hz and back due to the low bit rate, but it is proof of concept for a much wider variant using a much higher bit rate.
The file generated... (4 Replies)
I'm trying to record audio using Audacity 2.0.5 installed from SlackBuilds. My system is 64-bit Slackware 14.1 and a sound card is Intel HD Audio. I didn't change my sound system to OSS. (Default sound system in Slackware 14.1 is ALSA, isn't it?) First, I set Internal Microphone slider in KMix... (2 Replies)
A very simple crude sinewave generator.
The file required is generated inside the code, is linear interpolated and requires /dev/audio to work. Ensure you have this device, if not the download oss-compat from your OS's repository...
It lasts for about 8 seconds before exiting and saves a... (5 Replies)
IKHz_SW_OSX.py
A DEMO mono _pure_ sinewave generator using standard text mode Python 2.6.7 to at least 2.7.3.
This code is EASILY modifyable to Python version 3.x.x...
This DEMO kids level 1KHz generator is mainly for a MacBook Pro, (13 inch in my case), OSX 10.7.5 and above. See below...... (0 Replies)