Making a sound file from an integer sequence

To do exactly what I describe below you will need:

  1. Select an integer sequence (i.e., a subset of the positive integers).
  2. Pick an integer sequence for which you can generate many terms. (How many? At a sampling rate of 44100 samples per second, you'll need all the terms up to 44100k to generate sound k seconds in length.)

    For the sake of illustration, suppose we choose the Ulam numbers.

  3. Generate all the needed terms of the sequence and create a file of them, one term per line (let's call this file the sequence file)
  4. For the Ulam numbers, this file begins like this:

    1
    2
    3
    4
    6
    8
    11
    13
    16
    

    and here is the whole file.

    The standard is to create a list with all terms less than 106. This will result in a sound file that is 22.675 seconds long.

  5. Run the python script listToSoundPlus.py on your list to generate a sound (.wav) file.
  6. If you are running listToSound.py on the command line, you should use it like this:

    > python listToSoundPlus.py < ulam10^6.txt
    

    This directs your operating system to run Python with the script listToSoundPlus.py using ulam10^6.txt as input.

    (If this doesn't work, try using listToSoundPlusAsk.py instead. Run this with the command

    > python listToSoundPlusAsk.py 
    
    and you will be asked to enter the input file name (e.g., ulam10^6.txt)).

    NOTE: For the above to work, you will need the module soundfile installed. If you run the script without soundfile, Python will complain. To install soundfile from the command line try

    > pip install soundfile
    
    If that fails, try
    sudo pip install soundfile
    

    This will request password, to all pip superuser privileges, which may be necessary to, for example, create directories.

    When the script runs successfully, the output will be a file called output.wav.

    In addition, the script will print information about the sequence. Specifically, it will count how many terms of the sequence fall into each residue class mod 2 through 12. Also, how many terms are less than each power of 10 and the density up to each power of ten is printed.

  7. Listen to the output sound file.
  8. Open the file in Audacity and listen.