The purpose of this assignment is to introduce you to programming with one-dimensional arrays.


  1. Reverse sound wave.  When an object vibrates, it creates a wave of air pressure, which we hear as sound. With digital audio, we model a sound wave as a sequence of audio samples. Each sample is a number between –1 and +1 that represents the change in pressure of the sound wave at a specific point in time. By sampling the sound wave many times per second, we can represent the sound accurately.

    The StdAudio class uses a sampling rate of 44,100 Hz, which means that every second of digital audio contains 44,100 samples. You will use these two array-based functions for reading and playing audio samples:

    Write a program ReverseSoundWave.java that takes the name of an audio file as a command-line argument and plays it in reverse order. Your program should

    Here are a few sample executions. Before running each example, make a prediction of what you think the reveresed audio will sound like.

    ~/Desktop/arrays> javac-introcs ReverseSoundWave.java
    ~/Desktop/arrays> java-introcs ReverseSoundWave A.wav
    
    
    
    ~/Desktop/arrays> java-introcs ReverseSoundWave AMajorScale.wav
    
    
    
    ~/Desktop/arrays> java-introcs ReverseSoundWave HelloWorld.wav
    
    
    
    ~/Desktop/arrays> java-introcs ReverseSoundWave ReverseHelloWorld.wav
    
    
    
    ~/Desktop/arrays> java-introcs ReverseSoundWave RowYourBoat.wav
    
    
    
    ~/Desktop/arrays> java-introcs ReverseSoundWave PacMan.wav
    
    
    

    Playing music backward can sound creepy or demonic. On the other hand, playing a video backward is a popular effect on social media platforms such as TikTok.


  2. Superposition of sound waves.  A sound wave is a mechancial wave and is subject to the principle of superposition. This means that to combine two (or more) sound waves, you simply add the corresponding samples together. For example, to create a chord, superpose the sounds for the individual notes. To create a musical composition, superpose the sounds from the individual instruments or voices.

    Superposing three sound waves to make a chord

    Write a program Superpose.java that reads a number of sound files (all of the same length) and plays the sound that results by superposing those sounds together. Your program should take the names of the sound files as command-line arguments.

    ~/Desktop/arrays> javac-introcs Superpose.java
    ~/Desktop/arrays> java-introcs Superpose SynthA.wav
    
    
    
    ~/Desktop/arrays> java-introcs Superpose SynthC#.wav
    
    
    
    ~/Desktop/arrays> java-introcs Superpose SynthE.wav
    
    
    
    ~/Desktop/arrays> java-introcs Superpose SynthA.wav SynthC#.wav SynthE.wav
    
    
    
    ~/Desktop/arrays> java-introcs Superpose TwinkleMelody.wav TwinkleHarmony.wav
    
    
    
    ~/Desktop/arrays> java-introcs Superpose PacMan1.wav PacMan2.wav
    
    
    
    ~/Desktop/arrays> java-introcs Superpose Bell1.wav Bell2.wav Bell3.wav
    
    
    
    ~/Desktop/arrays> java-introcs Superpose Crane1.wav Crane2.wav Crane3.wav Crane4.wav
    
    
    
    ~/Desktop/arrays> java-introcs Superpose InvertedSynthA.wav
    
    
    
    ~/Desktop/arrays> java-introcs Superpose SynthA.wav InvertedSynthA.wav
    
    
    


  3. The Chipmunk Effect.  In this exercise, we will speed up a sound file by resampling it, at a rate \(\alpha > 1\), which results in faster. In turn, this will raise the pitch of the sound and lead to the classic Chipmunk effect.

    The resampling works as follows: If the existing sound has \(n\) samples, then the new sound will have \(\lfloor n / \alpha\rfloor\) samples, and sample \(i\) of the new sound corresponds to sample \(\lfloor\alpha \cdot i\rfloor\) of the existing sound (both assume zero-indexing, i.e., that the first entry of the array corresponds to \(i = 0\)). As a reminder, the floor function \(\lfloor x \rfloor\) returns the largest integer less than or equal to \(x\). You can compute this function in Java by casting x to an integer or by calling Math.floor(x).

    Write a program ChipmunkEffect.java that takes two command-line arguments: a string filename and a double alpha. Your program should change the speed of the sound specified by the filename, and play the resampled sound.

    chipmunk effect diagram

    Here are some sample executions:

    ~/Desktop/arrays> javac-introcs ChipmunkEffect.java
    ~/Desktop/arrays> java-introcs ChipmunkEffect KevinWayne.wav 1.0
    
    
    
    ~/Desktop/arrays> java-introcs ChipmunkEffect KevinWayne.wav 1.5
    
    
    
    ~/Desktop/arrays> java-introcs ChipmunkEffect SebastianCaldas.wav 1.0
    
    
    
    ~/Desktop/arrays> java-introcs ChipmunkEffect SebastianCaldas.wav 1.7
    
    
    

    This type of filter is a popular voice effect that you can apply on social media platforms such as TikTok.


  4. Braille transcriber. Braille (named after its creator, Louis Braille) is a tactile writing system developed in the early 19th century, originally for transcribing French. It has since been adopted as the de facto standard writing system for the blind and visually impaired worldwide (including for languages written in non-latin script; see, e.g., Bharati Braille). Braille characters consist of raised dots in a \(3 \times 2\) grid, with a unique dot pattern for each letter in the alphabet. The image below shows the transcription to Braille of the basic Latin alphabet, where large circles represent raised dots:
    Braille representation of the latin alphabet

    We will represent \(3 \times 2\) dot patterns as \(3 \times 2\) boolean[][] arrays, where boolean[i][j] is true if there is a raised dot in the \(i\)th row and \(j\)th column (and is false otherwise). For example, the character A is represented by [[true, false], [false, false], [false, false]] and O by [[true, false], [false, true], [true, false]]. The space character ' ' is represented by a grid with no raised dots, i.e., [[false, false], [false, false], [false, false]].

    Your task is to write a program BrailleTranscriber.java that receives a String command-line argument and outputs a boolean[][][] array representing the case-insensitive transcription of the string into Braille. In more detail, the \(i\)th element of the array should correspond to the boolean[][] that corresponds to the \(i\)th character of the string. You may assume that the string only contains alphabetic upper- or lower-case characters and spaces.

    We include the class BooleansToBraille.java that converts a boolean[][][] array into a formatted string with the BooleansToBraille.convert() method. Here are a few sample executions:

    ~/Desktop/arrays> javac-introcs BooleansToBraille.java BrailleTranscriber.java
    ~/Desktop/arrays> java-introcs BrailleTranscriber "accessibility" 
    o· oo oo o· ·o ·o ·o o· ·o o· ·o ·o oo 
    ·· ·· ·· ·o o· o· o· o· o· o· o· oo ·o 
    ·· ·· ·· ·· o· o· ·· ·· ·· o· ·· o· oo 
    
    ~/Desktop/arrays> java-introcs BrailleTranscriber "Hello World" 
    o· o· o· o· o· ·· ·o o· o· o· oo 
    oo ·o o· o· ·o ·· oo ·o oo o· ·o 
    ·· ·· o· o· o· ·· oo o· o· o· ·· 
    
  5. Extra credit: Braille transcription with formatting. BrailleTranscriber.java does not faithfully represent capitalization or punctuation. In this part of the assignment, we will augment the transcriber with a small subset of Unified English Braille in order to do so.

    In addition to standard punctuation (comma, period, colon, semicolon, hyphen, exclamation and question marks), BrailleTranscriberDeluxe.java should also implement

    The complete set of Braille characters and modifiers required for this task is shown below, followed by a few sample executions.

    Braille representation of the latin alphabet
    Here are a few sample executions:
    ~/Desktop/arrays> javac-introcs BooleansToBraille.java BrailleTranscriberDeluxe.java
    ~/Desktop/arrays> java-introcs BrailleTranscriberDeluxe COS125 
    ·· oo ·· o· ·· ·o o· o· o· o· 
    ·· ·· ·· ·o ·· o· o· ·· o· ·o 
    o· ·· o· o· o· o· oo ·· ·· ··
    ~/Desktop/arrays> java-introcs BrailleTranscriberDeluxe Stop! 
    ·· ·o ·o o· oo ·· 
    ·· o· oo ·o o· oo 
    o· o· o· o· o· o· 
    ~/Desktop/arrays> java-introcs BrailleTranscriberDeluxe "35 Olden St." 
    o· oo o· ·· ·· o· o· oo o· oo ·· ·· ·o ·o ·· 
    o· ·· ·o ·· ·· ·o o· ·o ·o ·o ·· ·· o· oo oo 
    oo ·· ·· ·· o· o· o· ·· ·· o· ·· o· o· o· ·o
    


    Submission. Submit ReverseSoundWave.java, Superpose.java, ChipmunkEffect.java, and BrailleTranscriber.java; optionally, submit BrailleTranscriberDeluxe.java. Also submit a readme.txt file and answer the questions. Do not use Java features that have not yet been introduced in the course (such as functions).


    Grading.
    File Points
    ReverseSoundWave.java 9
    Superpose.java 9
    ChipmunkEffect.java 9
    BrailleTranscriber.java 9
    BrailleTranscriberDeluxe.java 5
    readme.txt 4
    Total 40 + 5

    This assignment was developed by Sebastian Caldas, Marcel Dall'Agnol and Kevin Wayne. The Reverse and Superposition exercises were based on Song Generator by Daniel Zingaro. The Chipmunk Effect exercise is based on the changeSpeed() function from Princeton's Conjunction Function assignment. The Braille transcribed is inspired by the Braille Translator assignment in Acessibility Education.
    Copyright © 2025.
    Credits.