Sponsored Content
Top Forums Shell Programming and Scripting Experimental awk audio converter for CygWin and AudioScope.sh Post 302923291 by wisecracker on Saturday 1st of November 2014 05:41:39 AM
Old 11-01-2014
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...
Code:
#!/bin/bash
# 16to8bit_new.sh
> /tmp/sample.raw
> /tmp/leftbinary
> /tmp/signed16bit.txt
dd if=/dev/urandom of=/tmp/sample.raw bs=1 count=176400 > /dev/null 2>&1
od -td2 -An /tmp/sample.raw > /tmp/signed16bit.txt
awk --characters-as-bytes 'BEGIN \
{
	BINMODE=3;
	FS=" ";
}
{
	if ($1=="")
		exit;
	# $1,$3,$5,$7 are the left hand channel.
	# $2,$4,$6,$8 are the right hand channel.
	$1=(int(($1+32768)/256));
	# $2=(int(($2+32768)/256));
	$3=(int(($3+32768)/256));
	# $4=(int(($4+32768)/256));
	$5=(int(($5+32768)/256));
	# $6=(int(($6+32768)/256));
	$7=(int(($7+32768)/256));
	# $8=(int(($8+32768)/256));
	printf("%c%c%c%c",$1,$3,$5,$7) > "/tmp/leftbinary";
	# printf("%c%c%c%c",$2,$4,$6,$8) > "/tmp/rightbinary";
}' < /tmp/signed16bit.txt

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...
 

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Row to column converter using Awk or grep?

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)
Discussion started by: Needhelp2
3 Replies

2. Slackware

Problems with audio recording in Audacity 2.0.5. Slackware64 14.1; Intel HD Audio.

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)
Discussion started by: qzxcvbnm
2 Replies

3. What is on Your Mind?

AudioScope...

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)
Discussion started by: wisecracker
0 Replies

4. UNIX for Beginners Questions & Answers

Command awk under CYGWIN

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)
Discussion started by: Tapiocapioca
8 Replies

5. OS X (Apple)

AudioScope Project.

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)
Discussion started by: wisecracker
7 Replies
mlib_ImageColorRGB2HSL(3MLIB)				    mediaLib Library Functions				     mlib_ImageColorRGB2HSL(3MLIB)

NAME
mlib_ImageColorRGB2HSL - RGB to HSL color conversion SYNOPSIS
cc [ flag... ] file... -lmlib [ library... ] #include <mlib.h> mlib_status mlib_ImageColorRGB2HSL(mlib_image *dst, const mlib_image *src); DESCRIPTION
The mlib_ImageColorRGB2HSL() function performs a conversion from red/green/blue to hue/saturation/lightness. The source and destination images must be three-channel images. It uses the following equations: V = max(R, G, B) Vmin = min(R, G, B) L = (V + Vmin)/2 S = (V - Vmin)/(V + Vmin) if L <= 1/2 S = (V - Vmin)/(2 - V - Vmin) if L > 1/2 H = (5.0 + (V - B)/(V - Vmin))/6 if R = V and G = Vmin H = (1.0 - (V - G)/(V - Vmin))/6 if R = V and B = Vmin H = (1.0 + (V - R)/(V - Vmin))/6 if G = V and B = Vmin H = (3.0 - (V - B)/(V - Vmin))/6 if G = V and R = Vmin H = (3.0 + (V - G)/(V - Vmin))/6 if B = V and R = Vmin H = (5.0 - (V - R)/(V - Vmin))/6 if B = V and G = Vmin H = 0.0 if R = G = B where 0 <= R, G, B, V, Vmin, L, S <= 1 and 0 <= H < 1. Assuming a pixel in the source image is (r, g, b) and its corresponding pixel in the destination image is (h, s, l), then for MLIB_BYTE images, the following applies: R = r/255 G = g/255 B = b/255 h = H*256 s = S*255 l = L*255 for MLIB_SHORT images, the following applies: R = (r + 32768)/65535 G = (g + 32768)/65535 B = (b + 32768)/65535 h = H*65536 - 32768 s = S*65535 - 32768 l = L*65535 - 32768 for MLIB_USHORT images, the following applies: R = r/65535 G = g/65535 B = b/65535 h = H*65536 s = S*65535 l = L*65535 and for MLIB_INT images, the following applies: R = (r + 2147483648)/4294967295 G = (g + 2147483648)/4294967295 B = (b + 2147483648)/4294967295 h = H*4294967296 - 2147483648 s = S*4294967295 - 2147483648 l = L*4294967295 - 2147483648 PARAMETERS
The function takes the following arguments: dst Pointer to destination image. src Pointer to source image. RETURN VALUES
The function returns MLIB_SUCCESS if successful. Otherwise it returns MLIB_FAILURE. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
mlib_ImageColorHSL2RGB(3MLIB), mlib_ImageColorHSL2RGB_Fp(3MLIB), mlib_ImageColorRGB2HSL_Fp(3MLIB), attributes(5) SunOS 5.10 10 Nov 2004 mlib_ImageColorRGB2HSL(3MLIB)
All times are GMT -4. The time now is 05:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy