The purpose of this assignment is to introduce you to programming with one-dimensional arrays.
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:
StdAudio.read(filename)
returns a double[]
array containing
the samples (between –1 and +1) from the file specified as an argument.
StdAudio.play(samples)
sends the double[]
array of samples
to standard audio.
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
StdAudio.read()
.
StdAudio.play()
.
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.
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
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.
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.
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· ··
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
a
through j
(the first row of the alphabetic transcription, interpreted as the digits 1
through 0
), as well as commas and periods, is interpreted as a number.The complete set of Braille characters and modifiers required for this task is shown below, followed by a few sample executions.
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 |
changeSpeed()
function from Princeton's Conjunction Function assignment.
The Braille transcribed is inspired by the Braille Translator assignment in Acessibility Education.