Sponsored Content
Top Forums Programming A Function To Create A 1 Second Sinewave WAVE Beep File In Python. Post 302930838 by DGPickett on Wednesday 7th of January 2015 04:29:09 PM
Old 01-07-2015
Reminds me of an early C project I wrote myself 21 yrs. ago, which does a pure 440 hz sine wave with one byte samples and low sample rate:

Code:
 
a440.c
======
 
#include <stdio.h>
#ifdef BORLAND
#include <stdlib.h>
#endif
#include <math.h>
char hdr[]={'R', 'I', 'F', 'F', 0, 0, 0, 0, 'W', 'A', 'V', 'E', 'f', 'm', 't', 32, 16, 0, 0, 0, 1, 0, 1, 0, 17, '+', 0, 0, 17, '+', 0, 0, 1, 0, 8, 0, 'd', 'a', 't', 'a', 0, 0, 0, 0};
FILE * f ;
main(argc,argv)
int argc;
char**argv;
{
  #define SAMPLES 600L
  #define FREQ 440
  #define SPS 11025
  #define PI 3.1415927
  long i ;
  float w, x ;
  if ( argc < 2 )
  {
    fprintf( stderr, "Usage is '%s filename'\n", argv[0] ) ;
    exit( -1 ) ;
  }
  if ( !( f = fopen( argv[1], "wb" ) ) )
  {
    fprintf( stderr, "Can't open '%s' to write\n", argv[1] ) ;
    exit( -2 ) ;
  }
  w = 2 * PI * FREQ / SPS ;
  i = SAMPLES + 36 ;
  hdr[4] = i % 256 ;
  hdr[5] = ( i / 256 ) % 256 ;
  hdr[6] = ( i / 65536L ) % 256 ;
  hdr[7] = i / 16777216L ;
  i = SAMPLES ;
  hdr[40] = i % 256 ;
  hdr[41] = ( i / 256 ) % 256 ;
  hdr[42] = ( i / 65536L ) % 256 ;
  hdr[43] = i / 16777216L ;
  for( i = 0L ; i < sizeof(hdr) ; i++ )
  {
    putc( hdr[i], f ) ;
  }
  i = 0 ;
  while ( ++i <= SAMPLES )
  {
    putc( (char)( 128.0 + 127.999 * sin( w * i ) ), f ) ;
  }
  fclose( f ) ;
  exit( 0 ) ;
}


Last edited by DGPickett; 01-07-2015 at 05:46 PM..
This User Gave Thanks to DGPickett For This Post:
 

9 More Discussions You Might Find Interesting

1. Programming

about wave file integrating.

Now I have two wave file(*.wav) at Tru64 Unix machine. I want to make a new wave file including the two wave file. how I should finish this programmer. If you know, can you give me the format of the wave file(*.wav) and Sun au file(*.au). Thank you. (1 Reply)
Discussion started by: livic
1 Replies

2. Shell Programming and Scripting

How to create SQRT function in catenate file

HI, I have a file which i catenate and using the fields in the file, I would like to get sqrt of it. I tried to man the function but it normally would need an echo as well as bc. What I am intending to find out is catenate a file where let say cat a.txt| awk ' { t= h*($3+$2); t=... (7 Replies)
Discussion started by: ahjiefreak
7 Replies

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

4. Shell Programming and Scripting

How to create .txt file by using function?

My Calling script is like below: for file in `echo $LIST_OF_FILES` --listing filenames eg, xyz_meta_20110501_00000789.tar do file_name=`basename $file` <call a function to create .txt file in below format> done Want to generate a .txt file that contains below data in ksh: ... (3 Replies)
Discussion started by: vedanta
3 Replies

5. Windows & DOS: Issues & Discussions

A SOX 1KHz Sinewave Generator Using A Batch File...

Hi all... I don't think this has been done before but I am open to being corrected... This batch file generates a 65536 byte binary file to give 8 seconds of pure sinewave at the earphone/speaker output(s)... It uses ONLY a default Windows 32 bit installation, to Windows 7, except for the... (0 Replies)
Discussion started by: wisecracker
0 Replies

6. Shell Programming and Scripting

Create function

I would like to make a perl function , this function could send mail via SMTP and also could import a text file into mail content , that mean I have a text file , want to use this function to send mail via SMTP , the mail content is the text file , would advise how to write this script ? thanks (1 Reply)
Discussion started by: ust3
1 Replies

7. Shell Programming and Scripting

Python - Function print vs return - whats wrong

All, I have a basic buzz program written in python with return function. If i change return with print,it works fine but i want to know whats wrong with return statement.Can anyone help me whats wrong with this #!/usr/bin/python def div4and6(s,e): for i in range(s,e+1): if... (5 Replies)
Discussion started by: oky
5 Replies

8. Shell Programming and Scripting

Python etree.ElementTree findall function

Hi everyone. I'm trying to learn python as it relates to parsing xml, and I thought I would start by trying to create an easy (or I thought would be easy) function to match on a certain attribute in an xml file and print out it's related attribute. Here's an example to hopeful make sense of... (0 Replies)
Discussion started by: timj123
0 Replies

9. Programming

Create a C source and compile inside Python 1.4.0 to 3.7.0 in Python for ALL? platforms...

Hi all... As you know I like making code backwards compatible for as many platforms as possible. This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies
mppenc(1)																 mppenc(1)

NAME
mppenc - Musepack lossy audio codec encoder SYNOPSIS
mppenc [--options] [input_file] [output_file] DESCRIPTION
mppenc is a Musepack lossy audio codec encoder. Musepack is a lossy audio codec specifically optimized for transparent compression of stereo audio at bitrates of 160-180 kbit/s. INPUT FILES
- STDIN (only RIFF WAVE files) /dev/audio soundcard (OSS, 44.1 kHz) *.wav RIFF WAVE file *.raw|cdr RAW PCM file (2ch, 16bit, 44.1kHz) *.pac|lpac LPAC file (Windows only) *.fla|flac FLAC file *.ape Monkey's Audio file (APE extension only) *.rka|rkau RK Audio file (Windows only) *.sz SZIP file *.shn Shorten file *.wv Wavpack file .ofr OptimFROG file (Windows only) Currently only 32, 37.8, 44.1 and 48 kHz, 1-8 channels, 8-32 bit linear PCM is supported. When using one of the lossless compressed for- mats, a proper binary must be installed within the system's $PATH. OUTPUT FILES
*.mpc Musepack file *.mp+|mpp MPEGplus file (deprecated) - STDOUT OPTIONS
--quality 0.00 below telephone, poor quality (~ 20 kbps) --quality 1.00 below telephone, poor quality (~ 30 kbps) --quality 2.00 --telephone telephone, low quality (~ 60 kbps) --quality 3.00 --thumb thumb, low/medium quality (~ 90 kbps) --quality 4.00 --radio radio, medium quality (~ 130 kbps) --quality 5.00 --standard --normal normal (default), high quality (~ 180 kbps) --quality 6.00 --extreme --xtreme extreme, excellent quality (~ 210 kbps) --quality 7.00 --insane insane, excellent quality (~ 240 kbps) --quality 8.00 --braindead braindead, excellent quality (~ 270 kbps) --quality 9.00 above braindead, excellent quality (~ 300 kbps) --quality 10.00 above braindead, excellent quality (~ 350 kbps) In addition, quality scale is effective centesimally (i.e. --quality 4.25). --silent repress console messages (default: off) --verbose increase verbosity (default: off) --longhelp print long help --stderr FILE append messages to file --neveroverwrite never overwrite existing output file (default: off) --interactive ask to overwrite an existing output file (default: on) --overwrite overwrite existing output file (default: off) --deleteinput delete input file after encoding (default: off) --beep beep when encoding is finished (default: off) --unicode unicode input from console (Unix only) --tag key=value add tag 'key' with 'value' as contents --tagfile key=file add tags, take values from a file --tag key add tags, take values from console --artist 'value' shortcut for --tag 'Artist=value' --album 'value' shortcut for --tag 'Album=value' Other possible keys are: debutalbum, publisher, conductor, title, subtitle, track, comment, composer, copyright, publicationright, file- name, recordlocation, recorddate, ean/upc, year, releasedate, genre, media, index, isrc, abstract, bibliography, introplay, media, lan- guage... --skip x skip the first x seconds (default: 0.0) --dur x stop encoding after at most x seconds of encoded audio --fade x fadein+out in seconds --fadein x fadein in seconds (default: 0.0) --fadeout x fadeout in seconds (default: 0.0) --fadeshape x fade shape, see http://www.uni-jena.de/~pfk/mpc/img/fade.png (default: 1.0) --scale x scale input signal by x (default: 1.00000) --scale x,y scale input signal, separate for each channel EXAMPLES
mppenc inputfile.wav mppenc inputfile.wav outputfile.mpc mppenc --radio inputfile.wav outputfile.mpc mppenc --silent --radio --pns 0.25 inputfile.wav outputfile.mpc mppenc --nmt 12 --tmn 28 inputfile.wav outputfile.mpc AUTHOR
This manual page was written by Jorge Salamero Sanz <bencer@cauterized.net> for the Debian system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 any later version published by the Free Software Foundation. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. 12 June 2007 mppenc(1)
All times are GMT -4. The time now is 05:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy