first commit

This commit is contained in:
2019-08-13 12:17:37 -05:00
commit d5d82eff27
107 changed files with 6112 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar
.iml
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/.idea
/out/*

View File

@@ -0,0 +1,30 @@
# Lab 1: ArrayLists
## Overview
In this assignment you will make use of the WavFile class to read and write .wav audio files.
## Details
### ArrayList Requirement
This assignment is meant as a review of material covered in SE1011. You are required to use at least one ArrayList object.
### Using a Supplied Class
For this assignment, you will need to make use of the WavFile.java file ([javadoc](http://msoe.us/taylor/se1021/WavFile.html)). You may change package for WavFile class or place it in the appropriate folder within your project.
### Basic Program Flow
Youll need to create one class called Lab1 which should be in a package named the same as your MSOE username (e.g., taylor). Note: Do not place all of the functionality for your program in main. Prior to coding, decide on how you plan to encapsulate functionality into multiple methods. This class must contain your program that makes use of the WavFile class to do the following:
Ask the user to enter 0, 1, 2, or 3. If the user enters anything other than one of those four options, the program should reprompt the user to enter one of the four options (it should continue to do this forever).
If the user enters 0, the program should exit.
If the user enters 1, the program should prompt the user to enter a filename (without the .wav extension) and then read the file in and write a separate .wav file with all of the audio samples placed in reverse order. For example, if the user enters cymbal, the output file should be called cymbalRev.wav. Once this has been completed, the program should return to the prompt which asks the user to enter 0, 1, 2, or 3.
If the user enters 2, then the program should ask the user for a filename (without an extension) and a frequency. The program should then create a .wav file containing one second worth of audio that represents a tone at the specified frequency. Once this has been completed, the program should return to the prompt which asks the user to enter 0, 1, 2, or 3.
Optional: If the user enters 3, then the program should ask the user for a filename (without an extension) and two frequencies. The program should then create a .wav file containing one second worth of audio in stereo. One frequency should be on one channel and the other frequency on the other channel. Once this has been completed, the program should return to the prompt which asks the user to enter 0, 1, 2, or 3.
Note: Your program must not crash on menu selection regardless of what the user enters for a menu option.
### Hints
- To generate one second of audio, make sure that the numFrames and the sampleRate contain the same value.
- You may use cymbal.wav and ominous.wav as sample .wav files. You may wish to use the WavFile.toString() method to determine appropriate values to pass the multi-argument WavFile constructor.
- Place the .wav file in the project folder (in the same folder/directory that contains the src folder (not in the src folder)).
- To generate a tone at a given frequency you should generate a sine wave with values between -1.0 and 1.0 at the specified frequency. The formula to use for this is sin(2π×i×freqsampleRate)sin(2π×i×freqsampleRate). Where ii is the counter in the loop generating samples. Since the sampleRatesampleRate is the number of samples per second, if you desire one second worth of sound, youll need to generate sampleRatesampleRate samples.
- To generate stereo audio you will need to set the number of channels to two and interleave the audio samples for each channel in the ArrayList of samples. Said another way, the samples for the first channel should be placed only at even indices and the samples for the second channel should be placed only at odd indices.
- Once you have placed the samples into the WavFile object, be sure to call .close() to be sure the file has been written completely.

View File

@@ -0,0 +1,146 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<!--
If you set the basedir property below, then all reported file
names will be relative to the specified directory. See
http://checkstyle.sourceforge.net/5.x/config.html#Checker
<property name="basedir" value="${basedir}"/>
-->
<property name="fileExtensions" value="java, properties, xml"/>
<!-- See http://checkstyle.sf.net/config_sizes.html -->
<module name="FileLength"/>
<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="FileTabCharacter"/>
<!-- Checks for Headers -->
<module name="RegexpHeader">
<property name="header" value= "/\*\n \* SE1021"/>
</module>
<module name="TreeWalker">
<!-- Checks for Javadoc comments. -->
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
<module name="JavadocMethod">
<property name="minLineCount" value="1"/>
<property name="scope" value="public"/>
<property name="allowMissingPropertyJavadoc" value="true"/>
<property name="ignoreMethodNamesRegex" value="main"/>
<property name="allowedAnnotations" value=" "/>
</module>
<module name="JavadocType">
<property name="authorFormat" value="\S"/>
<property name="versionFormat" value="\S"/>
</module>
<module name="JavadocVariable">
<property name="scope" value="public"/>
</module>
<module name="JavadocStyle">
<property name="checkFirstSentence" value="false"/>
<property name="checkEmptyJavadoc" value="true"/>
</module>
<!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sf.net/config_naming.html -->
<module name="ConstantName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>
<!-- Checks for imports -->
<!-- See http://checkstyle.sf.net/config_import.html -->
<module name="AvoidStarImport"/>
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
<module name="RedundantImport"/>
<module name="UnusedImports">
<property name="processJavadoc" value="false"/>
</module>
<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->
<module name="LineLength">
<property name="max" value="120"/>
</module>
<module name="MethodLength"/>
<module name="ParameterNumber"/>
<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="GenericWhitespace"/>
<module name="MethodParamPad"/>
<module name="NoWhitespaceBefore"/>
<module name="ParenPad"/>
<!-- Modifier Checks -->
<!-- See http://checkstyle.sf.net/config_modifier.html -->
<module name="ModifierOrder"/>
<!-- Checks for blocks. You know, those {}'s -->
<!-- See http://checkstyle.sf.net/config_blocks.html -->
<module name="AvoidNestedBlocks"/>
<module name="EmptyBlock"/>
<module name="LeftCurly"/>
<module name="NeedBraces"/>
<module name="RightCurly"/>
<!-- Checks for common coding problems -->
<!-- See http://checkstyle.sf.net/config_coding.html -->
<module name="AvoidInlineConditionals"/>
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MagicNumber">
<property name="ignoreNumbers" value="-1, 0, 1, 2, 3, 4"/>
<property name="ignoreAnnotation" value="true"/>
</module>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<!-- find incomplete autogenerated code -->
<module name="TodoComment">
<property name="format" value="(TODO)|(FIXME)|(Todo)|(to do)"/>
</module>
<module name="RegexpSinglelineJava">
<property name="format" value=" e\.printStackTrace\(\);"/>
<property name="ignoreComments" value="true"/>
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="\* Created by [a-zA-Z 0-9]+ on [0-9]{1,2}/[0-9]{1,2}/[0-9]{4}\."/>
<property name="message" value="Autogenerated class comment"/>
</module>
<!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sf.net/config_misc.html -->
<module name="UpperEll"/>
<module name="MissingOverride"/>
<module name="IllegalCatch"/>
<module name="IllegalThrows"/>
<module name="OneTopLevelClass"/>
<module name="Indentation">
<property name="arrayInitIndent" value="8"/>
<property name="lineWrappingIndentation" value="8"/>
</module>
</module>
</module>

View File

@@ -0,0 +1,112 @@
/*
* SE1021 091
* Winter 2017
* Lab 1 - ArrayLists
* Name: Trevor Barnes
* Created: 11/30/2017
*/
import edu.msoe.taylor.audio.WavFile;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
/**
* Uses ArrayList to read and write .wav files.
* @author barnestr
* @version 1.0
*/
public class Lab1 {
static Scanner in = new Scanner(System.in);
static final int SAMPLE_RATE = 8000;
static final int VALID_BITS = 8;
public static void main(String[] args) {
int option = introOption();
if (option == 1){
fileReverser();
} else if (option == 2) {
singleToneGenerator();
} else if (option == 3) {
doubleToneGenerator();
} else {
System.exit(0);
}
}
static int option;
/**
* Displays options for user
* @return option from user
*/
private static int introOption() {
do {
System.out.println("Enter an option (0,1,2,3) to initiate.\n" +
"0. Exits Program\n" +
"1. Create a reversed version of a .wav file.\n" +
"2. Create a .wav file containing a one second tone at a given frequency.\n" +
"3. Create a .wav file containing a one second stereo sound with two tones given " +
"frequencies.\n");
option = in.nextInt();
} while (option < 0 || option > 3);
return option;
}
/**
* Reverses given file
*/
public static void fileReverser() {
System.out.println("Enter a .wav filename (without .wav extension) with audio samples to be placed in " +
"reverse order.");
String filename = in.next();
WavFile original = new WavFile(filename + ".wav");
ArrayList samples = original.getSamples();
Collections.reverse(samples);
WavFile file = new WavFile(filename + "Rev.wav", 1, original.getValidBits(),
original.getValidBits(), original.getSampleRate());
file.close();
}
/**
* Generates a .wav file with a one second tone
*/
public static void singleToneGenerator() {
System.out.println("Enter a .wav filename (without .wav extension) to be created.");
String filename = in.next();
System.out.println("Enter the frequency of tone to be created.");
int frequency = in.nextInt();
ArrayList samples = new ArrayList();
for (int i = 0; i<SAMPLE_RATE; i++) {
samples.add(Math.sin(2*Math.PI*i*(frequency/SAMPLE_RATE)));
}
WavFile file = new WavFile(filename + ".wav", 1, SAMPLE_RATE, VALID_BITS, SAMPLE_RATE);
file.setSamples(samples);
file.close();
}
/**
* Generates a .wav file with two one second tones in stereo
*/
public static void doubleToneGenerator() {
System.out.println("Enter a .wav filename (without .wav extension) of stereo file to be created.");
String filename = in.next();
System.out.println("Enter the first frequency of tone to be created.");
int frequency1 = in.nextInt();
System.out.println("Enter the second frequency of tone to be created.");
int frequency2 = in.nextInt();
ArrayList samples = new ArrayList();
for (int i = 0; i<SAMPLE_RATE; i = i + 2) {
samples.add(Math.sin(2*Math.PI*i*(frequency1/SAMPLE_RATE)));
}
for (int i = 1; i<SAMPLE_RATE; i = i + 2) {
samples.add(Math.sin(2*Math.PI*i*(frequency2/SAMPLE_RATE)));
}
WavFile file = new WavFile(filename + ".wav", 2, SAMPLE_RATE, VALID_BITS, SAMPLE_RATE);
file.setSamples(samples);
file.close();
}
}

View File

@@ -0,0 +1 @@
# ignore