Sponsored Content
Operating Systems OS X (Apple) An Audio Function Generator... Post 302969967 by wisecracker on Wednesday 30th of March 2016 05:13:11 PM
Old 03-30-2016
An Audio Function Generator...

Ok guys, gals and geeks...

As from today I am starting to learn awk in earnest doing something totally different.

I am going to create a pseudo-Audio_Function Generator centred around OSX 10.11.x minimum. The code below is a tester to see what the possibilities are.

All waveforms will be 6+ bit depth using ASCII characters decimal 32 - space to decimal 126 - tilde.

It requires SOX and I am not going to use any other source.

The code below is my starting point. All criticisms welcome...

I am now getting my head around making it fully programmable using awk.
The shell is SOOOO easy but this is new to me and I want to learn...

If you try it out the simple sinewave.raw file generated will only go from 500Hz to 6KHz...

Have fun... ;o)
Code:
#!/bin/sh
# FG.sh
awk '
# Clear the terminal window.
function cls()
{
	printf "\x1B[2J\x1B[H";
}

# User keyboard interrupt.
function keyboard( COMMAND )
{
	printf "Press <CR> to continue or QUIT<CR>:- ";
	getline COMMAND;
	if ( COMMAND == "QUIT" ) { exit 0 };
}
 
# Adjust the sample rate for SOX WRT its frequency.
function setrate( RATE )
{
	cls();
	FREQ=500;
	BYTES=8;
	RATE=16000;
	printf "Enter frequency required:- ";
	getline FREQ;
	RATE=(BYTES*FREQ);
	if ( RATE <= 4000 ) { RATE=4000 };
	if ( RATE >= 48000 ) { RATE=48000 };
	return RATE;
}

# Main loop...
function main()
{
	RATE=setrate();
	LOOPS=2;
	for ( LOOP = 1; LOOP <= LOOPS; ++LOOP ) { system ( "~/sox-14.4.2/sox -q -b 8 -r "RATE" -e unsigned-integer /tmp/sinewave8.raw -d trim 0 00:01 > /dev/null 2>&1" ) };
	keyboard( COMMAND );
}

# Now generate a simple sinewave and run the _main_ code.
BEGIN \
{
	system( ">" "/tmp/sinewave8.raw" );
	SINEWAVE8="Op}pN- -";
	for ( LOOP = 1; LOOP <= 16; ++LOOP ) { SINEWAVE8=SINEWAVE8 SINEWAVE8 };
	printf SINEWAVE8 > "/tmp/sinewave8.raw";
	cls();
	while( 1 ) { main() };
}'

 

8 More Discussions You Might Find Interesting

1. Programming

Python, Platform Independent, Pure Audio Sinewave Generator...

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

2. Shell Programming and Scripting

A Crude 1KHz Audio Sinewave Generator Demo...

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

3. Shell Programming and Scripting

Sequence generator

Thanks Guys This really helped (5 Replies)
Discussion started by: robert89
5 Replies

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

5. OS X (Apple)

A Bash Audio Sweep Generator...

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

6. OS X (Apple)

Variable frequency audio generator...

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

7. OS X (Apple)

A simple variable frequency sinewave audio generator.

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

8. Shell Programming and Scripting

Hostsfile generator

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)
Discussion started by: Marti95
9 Replies
Packet sample action in tc(8)					       Linux					     Packet sample action in tc(8)

NAME
sample - packet sampling tc action SYNOPSIS
tc ... action sample rate RATE group GROUP [ trunc SIZE ] [ index INDEX ] tc ... action sample index INDEX DESCRIPTION
The sample action allows sampling packets matching classifier. The packets are chosen randomly according to the rate parameter, and are sampled using the psample generic netlink channel. The user can also specify packet truncation to save user-kernel traffic. Each sample includes some informative metadata about the original packet, which is sent using netlink attributes, alongside the original packet data. The user can either specify the sample action parameters as presented in the first form above, or use an existing sample action using its index, as presented in the second form. SAMPLED PACKETS METADATA FIELDS
The metadata are delivered to userspace applications using the psample generic netlink channel, where each sample includes the following netlink attributes: PSAMPLE_ATTR_IIFINDEX The input interface index of the packet, if there is one. PSAMPLE_ATTR_OIFINDEX The output interface index of the packet. This field is not relevant on ingress sampling PSAMPLE_ATTR_ORIGSIZE The size of the original packet (before truncation) PSAMPLE_ATTR_SAMPLE_GROUP The psample group the packet was sent to PSAMPLE_ATTR_GROUP_SEQ A sequence number of the sampled packet. This number is incremented with each sampled packet of the current psample group PSAMPLE_ATTR_SAMPLE_RATE The rate the packet was sampled with OPTIONS
rate RATE The packet sample rate. RATE is the expected ratio between observed packets and sampled packets. For example, RATE of 100 will lead to an average of one sampled packet out of every 100 observed. trunc SIZE Upon set, defines the maximum size of the sampled packets, and causes truncation if needed group GROUP The psample group the packet will be sent to. The psample module defines the concept of groups, which allows the user to match spe- cific sampled packets in the case of multiple sampling rules, thus identify only the packets that came from a specific rule. index INDEX Is a unique ID for an action. When creating new action instance, this parameter allows to set the new action index. When using existing action, this parameter allows to specify the existing action index. The index must 32bit unsigned integer greater than zero. EXAMPLES
Sample one of every 100 packets flowing into interface eth0 to psample group 12: tc qdisc add dev eth0 handle ffff: ingress tc filter add dev eth0 parent ffff: matchall action sample rate 100 group 12 index 19 Use the same action instance to sample eth1 too: tc qdisc add dev eth1 handle ffff: ingress tc filter add dev eth1 parent ffff: matchall action sample index 19 SEE ALSO
tc(8), tc-matchall(8) psample(1) iproute2 31 Jan 2017 Packet sample action in tc(8)
All times are GMT -4. The time now is 04:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy