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
chvol(8)						      System Manager's Manual							  chvol(8)

NAME
chvol - changes the attributes of a volume SYNOPSIS
/sbin/chvol [-l] [-r blocks] [-w blocks] [-t blocks] [-c on | off] [-A] special domain OPTIONS
Activates a volume after an incomplete addvol or rmvol operation. Turns I/O consolidation mode on or off. Displays the range of I/O transfer sizes, in 512-byte blocks, as calculated by the kernel, based on the disk's geometry: rblks displays the minimum, the maximum, and the preferred transfer size for reads. wblks displays the minimum, the maximum, and the preferred transfer size for writes. Specifies the maximum number of 512-byte blocks that the file system reads from the disk at one time. Specifies the maximum number of dirty, 512-byte blocks that the file system will cache in-memory (per volume in a domain). Dirty means that the data has been written by the application but the file system has cached it in memory so it has not yet been written to disk. The number of blocks must be in multiples of 16. The valid range is 0-32768. The default (when a volume is added to a domain) is 16,384 blocks. For optimal performance, specify blocks in multiples of wblks (as specified by the -w option) and multiples of rblks (as specified by the -r option). Specifies the maximum number of 512-byte blocks that the file system writes to the disk at one time. OPERANDS
Specifies the block special device name, such as /dev/disk/dsk2c. Specifies the name of the file domain. DESCRIPTION
The chvol command enables you to change the attributes of a volume in an active domain. For example, the file system can consolidate a number of I/O transfers into a single, large I/O transfer. The larger the I/O transfer, the better the file-system performance. If you attempt to change the attributes of a volume in a domain that is not active, an error message is produced. The initial I/O transfer parameter for both reads and writes is typically 128 or 256 blocks, depending on the disk driver's preferred I/O transfer rate. Once you change the I/O transfer parameters with the -r option or the -w option, the parameters remain fixed until you change them again. The values for the I/O transfer parameters are limited by the device driver. Every device has a minimum and maximum value for the size of the reads and writes it can handle. If you set a value that is outside of the range that the device driver allows, the device automatically resets the value to the largest or smallest it can handle. By default, the I/O consolidation mode (cmode) is on. The cmode must be on for the I/O transfer parameters to take effect. You can use the -c option to turn the cmode off, which sets the I/O transfer parameter to one page. Interrupting an rmvol operation can leave the volume in an inaccessible state. If a volume does not allow new allocations after an rmvol operation, use the chvol command with the -A option to reactivate the volume. Using the chvol command without any options displays the current cmode and the I/O transfer parameters. RESTRICTIONS
The values for the wblks and rblks attributes are limited by the device driver. You must be the root user to use this command. EXAMPLES
The following example displays the cmode and the I/O transfer parameters of the /dev/disk/dsk1c volume in the domain1 file domain: # chvol /dev/disk/dsk1c domain1 rblks = 128 wblks = 128 cmode = on thresh = 16,384 The following example additionally toggles the cmode: # chvol -c off /dev/disk/dsk1c domain1 # chvol /dev/disk/dsk1c domain1 rblks = 128 wblks = 128 cmode = off thresh = 16,384 The following example continues by changing the I/O transfer parameters of reads (rblks) and writes (wblks) from 128 blocks to 256 blocks. Note that the cmode is off and must be on before the parameters take effect: # chvol -r 256 -w 256 -c on /dev/disk/dsk1c domain1 chvol /dev/disk/dsk1c domain1 rblks = 256 wblks = 256 cmode = on thresh = 16,384 The following example shows the I/O transfer range on domain1: # chvol -l /dev/disk/dsk0a domain1 chvol /dev/disk/dsk0a domain1 rblks: min = 16 max = 32768 pref = 256 wblks: min = 16 max = 32768 pref = 256 SEE ALSO
advfs(4), showfdmn(8) chvol(8)
All times are GMT -4. The time now is 09:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy