Experimental awk audio converter for CygWin and AudioScope.sh
Development machine:- Standard MBP 13 inch, OSX 10.7.5...
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin11)
Copyright (C) 2007 Free Software Foundation, Inc.
Scenario:- Audio capture for AudioScope.sh for CygWin without ANY third party installs.
I am trying my hardest to get a very fast CD quality to 8 bit mono converter for CygWin.
In the process I am learning awk with a difference.
I have a shell version but it is very slow speed wise making it totally unusable for CygWin.
I have a fully working embedded audio capture using SoundRecorder.exe for CygWin using Windows Vista and 7, and I assume 8.x too.
It autosaves as a .WAV file, stereo, 16 bit signed depth at 44100 Hz sampling rate.
There are NO default tools to convert the audio to my usable state so awk is my only way for CygWin.
(There are for OSX and Linux however.)
I needed to convert this to a raw file at quantised 8 bit unsigned depth.
My MBP awk does not have the function strtonum() so the code below is a workaround.
With my limited knowledge of awk, I could only do this in two separate awk stages.
As 'dd' and 'od' ARE part of a default CygWin install then creating a pseudo file was easy.
using 'od' in the script creates a very large file formatted exactly like this:-
This gave me S1 to $8 per line input where $1, $3, $5 and $7 are the signed 16 bit left hand channel.
$2, $4, $6 and $8 are the 16 bit signed right hand channel.
Thus the first awk script converts the signed 16 bit decimal to unsigned 8 bit decimal, left hand channel only.
The second awk script then converts the unsigned 8 bit decimal to a pure binary file 44100 bytes in size.
It all works and is seriously quick on this MBP but it looks seriously ugly too.
This WHOLE shell script takes around 0.5 seconds to complete:-
Ignore the '\' after BEGIN, etc, as this is my way if making it a little easier for me to read.
Please tear it apart and if there are better methods please point me in the right direction...
Many thanks guys...
I await the flak...
Last edited by wisecracker; 10-31-2014 at 07:06 PM..
Reason: Correct minor spelling errors...
Hi shamrock...
The signed 16 bit decimal equivalent cannot go less that -32768 and no greater than 32767.
The centreline is zero.
Add 32768 to the signed decimal to shift the centreline to 32768, the minimum now sits at zero and the maximum at 65535.
Divide the result by 256 gives a centreline of 128, minimum of zero and maximum of 255.
Try it and find out.
Nothing more sinister, and accurate enough for a further quantise to 4 bit depth for AudioScope.sh...
HTH...
---------- Post updated 01-11-14 at 09:41 AM ---------- Previous update was 31-10-14 at 11:13 PM ----------
Got it into one block realising that the numbers already exist as numbers and not strings...
I am happy with the results now and shaved off another two tenths of a second execution time...
EDIT:
Now tested on CygWin and completes the cycle in around 1.5 seconds. Highly acceptable...
Last edited by wisecracker; 11-01-2014 at 07:32 AM..
Reason: See above...
I think you can simplify that awk code by telling it to use all whitespace as record separators. One statement instead of four. Then you just tell it to process the "odd" lines -- 1, 3, 5, ...
You can get rid of the BEGIN block by feeding variables into awk on the commandline. This also lets you script the value of the outputfile.
I started adding pipes and stuff then saw the BINMODE, and realized that's probably why you were forced to use temp files. Oh well.
Along with a few others, you have been extremely helpful with AudioScope.sh over its 21 month lifetime.
All I can say is many thanks.
I will try this baby of yours out and see how it goes on CygWin, as that is the platform that it is aimed at...
Bazza.
---------- Post updated 02-11-14 at 01:44 PM ---------- Previous update was 01-11-14 at 06:59 PM ----------
Hi Corona688...
Just this minute tried your code.
Had to add a '(' in red below to get it to run but ot only delivers 1 byte instead of 48000.
Results:- ---------- Post updated at 06:02 PM ---------- Previous update was at 01:44 PM ----------
This is an even smaller version for the LHS only and works a real treat in CygWin...
Thanks C688 for mentioning the removal BEGIN ...
Listening tests were more than good, now I have to attempt to obtain a conversion to 8000Hz sampling rate for the frequency counter part of AudioScope.sh...
I have a simple idea to test and will post here when done.
If I get you right, what you want to do per sample point is strip the low byte and then XOR with 0X80. Try this with mere shell (recent bash) builtins:
AudioScope Project.
(Apologies for any typos.)
For the few following......
AudioScope.sh...
Now at Version 0.60.00.
Well this baby has come a long way since its inception in January 2013. It is now at Version 0.60.00. It is MUCH more Apple centric now with a new OSX Sierra minimum _silent_... (7 Replies)
One my friend wrote one script on his machine linux, when I try to use it under cygwin I recive one error about the command awk. Is there someone can suggest me the way to fix the error? The script is wrote using gawk and I have no idea what kind of comand is used by cygwin.
This is the script:... (8 Replies)
Boy oh boy, with only a MONO mic input to use AudioScope gets much more difficult when the ALTDC board is included.
It needs, so far, two hits at the MIC input with a single hit at the HEADPHONE audio output.
The first at the highest practical resolution for the AC component and the second... (0 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)
Hello,
Can someone please help me on this.:confused:
I have a file which has more than 1 million lines (XML file).
What I need is:
Search for "abcd" in the input file > output the result into a output.txt (colloum1)
Search for "efghi" in the input file > output the result in to... (3 Replies)