finish clipped
This commit is contained in:
parent
32046afb19
commit
b5ca6f3f6b
@ -1,4 +1,5 @@
|
||||
## Background
|
||||
Included here is a simple python script used to generate and play some sine waves, specified by the assignment. This script will play a tone, so please ensure your default audio output is properly configured (and not too loud) for your listening enviornment
|
||||
|
||||
## Setup
|
||||
Potential libraries needed for debian-based gnu+linux
|
||||
@ -15,4 +16,24 @@ pip install -r requirnments.txt
|
||||
python3 main.py
|
||||
```
|
||||
|
||||
## Reflections, Results, Analysis
|
||||
## View Source
|
||||
[main.py](./main.py)
|
||||
|
||||
## Access outputs
|
||||
[sine.wav](./sine.wav)
|
||||
|
||||
[clipped.wav](./clipped.wav)
|
||||
|
||||
## Reflections, Results, Analysis
|
||||
Overall this portfolio assignment went well. Though I have worked with audio analysis and editing in the past (in a limited capacity), this was my first opportunity to create computer audio at the bit level, and in that regard it was rather exciting and interesting.
|
||||
|
||||
In retrospect, my decision to implement this assignment as a python script seems to have been a good choice. The provided libraries were helpful in providing the raw trigonmetric math and unit casting, without abstracting away the discrete transformation steps needed to get to the result. The calls to `scipy.io.wavfile.write` and `sounddevice.play` were easy and succinct, which allowed me to focus on usage of `numpy` to generate the proper signals with the requested parameters. I did consider implementing this assignment in Rust; this likely would have been fun at the risk of getting caught up in using algorithms from a less-mature library and a more hand-on approach to managing data structures.
|
||||
|
||||
The most challenging part of this assignment was understanding the relationship between time, the wave angle and amplitude to generate the wave. This took some tinkering and iterations to lead to my result.
|
||||
|
||||
My primary technical resources for this assignment were viewing the API documentation for the various libraries
|
||||
* [Numpy](https://numpy.org/doc/stable/reference/index.html)
|
||||
* [sounddevice.play](https://python-sounddevice.readthedocs.io/en/0.3.12/api.html#sounddevice.play)
|
||||
* [scipy.io.wavfile.write](https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.wavfile.write.html)
|
||||
|
||||
I consider this portfolio assignment complete
|
BIN
code/clipped/clipped.wav
Normal file
BIN
code/clipped/clipped.wav
Normal file
Binary file not shown.
@ -1,21 +1,34 @@
|
||||
from os.path import dirname, join as pjoin
|
||||
import string
|
||||
from scipy.io import wavfile as wav
|
||||
import numpy as np
|
||||
import scipy.io
|
||||
import sounddevice
|
||||
import sounddevice as sd
|
||||
import math
|
||||
|
||||
print("Portfolio assignment 1: Clipped")
|
||||
print("This program will create (overwrite) sine.wav and clipped.wav per specification\n and will play clipped.wav to the default audio output")
|
||||
|
||||
# part 1: building and writing the sine wave
|
||||
# starting example: https://www.geeksforgeeks.org/numpy-sin-python/
|
||||
min_amp = np.iinfo(np.int16).min # = -32767
|
||||
max_amp = np.iinfo(np.int16).max # = 32767
|
||||
|
||||
in_array = [0, math.pi / 2, np.pi / 3, np.pi]
|
||||
print ("Input array : \n", in_array)
|
||||
|
||||
Sin_Values = np.sin(in_array)
|
||||
print ("\nSine values : \n", Sin_Values)
|
||||
sample_rate = 48000 # samples/second
|
||||
|
||||
# part 2: building and writing clipped wave
|
||||
def generate(amp: float):
|
||||
frequency = 440 # cycles/second aka Hz
|
||||
duration = 1 # seconds
|
||||
time = np.linspace(0, duration, int(sample_rate * duration), endpoint=False) # array of discrete time values
|
||||
angle = 2 * np.pi * frequency * time # radians 2π(f * t)
|
||||
wave = amp * max_amp * np.sin(angle)
|
||||
return wave.astype(np.int16)
|
||||
|
||||
# part 3: playing audio
|
||||
def write(wave, name: string):
|
||||
wav.write(name, sample_rate, wave)
|
||||
|
||||
def play(wave):
|
||||
sd.play(wave, samplerate=sample_rate, blocking=True, loop=False)
|
||||
|
||||
sine = generate(0.25)
|
||||
clipped = np.clip(generate(0.5), math.floor(min_amp/4.0), math.ceil(max_amp/4.0))
|
||||
|
||||
write(sine,'sine.wav')
|
||||
write(clipped,'clipped.wav')
|
||||
play(clipped)
|
BIN
code/clipped/sine.wav
Normal file
BIN
code/clipped/sine.wav
Normal file
Binary file not shown.
@ -1,3 +1,6 @@
|
||||
### Thursday 17-Oct-2024
|
||||
📝 Today, I finished work on the [clipped](./code/clipped/README.md) assignment. My retrospective thoughts and experience with this work are found within.
|
||||
|
||||
### Sunday 13-Oct-2024
|
||||
📝 Today I posted [my introduction in the course zulip](https://cs516sound-fall2024.zulip.cs.pdx.edu/#narrow/stream/455-introductions/topic/intro/near/76245) and noted a brief background of myself and my motivation for taking the course. My introduction was the first, and I expect to see others from my classmates follow soon
|
||||
|
||||
|
Reference in New Issue
Block a user