0

I use Ubuntu 22.04. Is there an application for converting mathematical periodical sin/cos formula (functions) to sound? For example is there a way for playing these signals:

  • cos(2π · 440 t)
  • cos t + cos 2^(1/2) t

Features:

  • I only look for free applications.

Note:

  • I have installed FFmpeg version 4.4.2 and GNU Octave, version 6.4.0 on my machine and instructions or web page which describes the way of using those for my purpose is acceptable.

1 Answer 1

0
  1. Create a file with "samples" from your formulas.
    Simple "C" or Python scripting will do the thing, unless Octave itself has means for it.
  2. Install Audacity
  3. Menu: File > Import > ... your sample-file.

Some Python -code to play with...
$ cat rawsnd.py 
#!/bin/env python

import math, sys

# trick to make CSI, ESC[ - sequences work in Windows-stupid-CMD.EXE to activate "ANSI.SYS" (as in old MS-DOS)
import os;os.system("");CSI='\x9B' # terminfo, curses, "ANSI" terminal expected

sps=44100       # sample rate, 44100 for "CD"-like
et=10           # end time, seconds
res=2**16-10        # max value for samples, UNSIGNED, < base-two-binary-max.
halfres=(res)/2     # adjust for SIGNED, Because*sin()/cos() [-1,1]
pi=3.141592653589793

Hz=440          # base frequency, at least for simple cos or sin

top=-1
bot=1

length = math.ceil(math.log(res, 256)) # bytes per sample
sys.stderr.write(str(length)+' bytes /sample\n\n')

f=open('TEST.raw','wb')
for t in range(int(et*sps)): # "t" in "samples"
  timespot=Hz*t/sps
  #
  #> cos t + cos 2^(1/2) t  # note: cos()+cos() may reach [-2,2], so scaled to half.
  #s=int(( math.cos( 2*pi*timespot )+math.cos(1.414*timpespot) )/2*halfres)
  #
  #> cos(2π · 440 t)
  s=int(math.cos( 2*pi*timespot )*halfres)
  #
  print(f'{CSI}A{s}{CSI}K')
  if s>top:
    top=s
  elif s<bot:
    bot=s
  f.write( int.to_bytes(s, length=length, byteorder='big', signed=True) )

print(f'{CSI}AValues: top; {top}, bottom; {bot}{CSI}J')
2
  • Thank you for your reply. I prefer using Audacity, at least for experimental usages. Can you provide a link for the syntax for writing complex formula as raw data in sample file? Commented May 16, 2023 at 4:50
  • My recommendation: Look up a tutorial on python programming, then look into what I have included above - you will probably need just a few hours of Python-study.
    – Hannu
    Commented May 16, 2023 at 15:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .