Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Binary file added report/trumpet_comparison.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added report_archive/trumpet_comparison.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added report_archive/trumpet_sample_spectrogram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added report_archive/trumpet_wavetable_spectrogram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions resampler/analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import librosa
import librosa.display
import matplotlib.pyplot as plt
import numpy as np

def compute_spectrogram(audio_path):
# Load audio file
y, sr = librosa.load(audio_path)
# Compute spectrogram
D = librosa.amplitude_to_db(np.abs(librosa.stft(y)), ref=np.max)
return D, sr

# Compute spectrograms for both files
D1, sr1 = compute_spectrogram('samples/Trumpet.wav')
D2, sr2 = compute_spectrogram('report/Trumpet_wavetable.wav')

# Create figure with 2x2 grid
plt.figure(figsize=(15, 10))

# Plot original spectrogram (magma)
plt.subplot(2, 2, 1)
librosa.display.specshow(D1, sr=sr1, x_axis='time', y_axis='log', cmap='magma')
plt.colorbar(format='%+2.0f dB')
plt.title('Original Trumpet Sample (Bflat3)')

# Plot wavetable spectrogram (viridis)
plt.subplot(2, 2, 2)
librosa.display.specshow(D2, sr=sr2, x_axis='time', y_axis='log', cmap='viridis')
plt.colorbar(format='%+2.0f dB')
plt.title('Wavetable Recreation of Trumpet (Bflat3)')

# Plot combined spectrogram (spanning bottom row)
plt.subplot(2, 1, 2)
# Plot original first with higher alpha
librosa.display.specshow(D1, sr=sr1, x_axis='time', y_axis='log', cmap='magma', alpha=0.7)
# Plot wavetable second with lower alpha
librosa.display.specshow(D2, sr=sr2, x_axis='time', y_axis='log', cmap='viridis', alpha=0.3)
plt.colorbar(format='%+2.0f dB')
plt.title('Combined View (Original in Magma, Wavetable in Viridis)')

plt.tight_layout()

# Save the figure
plt.savefig('report/trumpet_comparison.png')

# Show the figure
plt.show()
Loading