Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl9Doniz committed Apr 30, 2024
1 parent eacb633 commit 292b906
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 15 deletions.
Binary file modified __pycache__/constellations.cpython-310.pyc
Binary file not shown.
Binary file modified __pycache__/fft_just_do_it.cpython-310.pyc
Binary file not shown.
Binary file modified __pycache__/hashes.cpython-310.pyc
Binary file not shown.
6 changes: 3 additions & 3 deletions constellations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
from scipy.io.wavfile import read
from scipy import signal
from fft_just_do_it import *

def create_constellation(audio, Fs, chunk_size=1000):
window_length_seconds = 0.05
Expand All @@ -17,10 +18,9 @@ def create_constellation(audio, Fs, chunk_size=1000):
amount_to_pad = window_length_samples - chunk.size % window_length_samples
padded_chunk = np.pad(chunk, (0, amount_to_pad))

# Зменшуємо розмір вікна nperseg
nperseg = min(window_length_samples, len(padded_chunk))

frequencies, times, stft_result = signal.stft(
frequencies, times, stft_result = stft(
padded_chunk, Fs, nperseg=nperseg, nfft=nperseg, return_onesided=True
)

Expand Down Expand Up @@ -48,6 +48,6 @@ def create_constellation(audio, Fs, chunk_size=1000):
return constellation_map

if __name__ == "__main__":
Fs, audio_input = read("Rain Over Me.wav")
Fs, audio_input = read("data/Rain Over Me.wav")
constellation = create_constellation(audio_input, Fs)
print(constellation)
Binary file modified database.pickle
Binary file not shown.
4 changes: 2 additions & 2 deletions finding.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from constellations import create_constellation
from hashes import create_hashes

Fs, audio_input = read("data/Rain Over Me.wav")
Fs, audio_input = read("video.wav")

constellation = create_constellation(audio_input, Fs)
hashes = create_hashes(constellation, None)
Expand Down Expand Up @@ -44,5 +44,5 @@ def score_songs(hashes):

scores = score_songs(hashes)
for song_index, score in scores:
print(f"{song_index_lookup[song_index]=}: Score of {score[1]} at {score[0]}")
print(f"{song_index_lookup[song_index]=}")

9 changes: 2 additions & 7 deletions hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@

def create_hashes(constellation_map, song_id=None):
hashes = {}
for idx, (time, freq) in enumerate(constellation_map):
for other_time, other_freq in constellation_map[idx : idx + 100]:
for _, (time, freq) in enumerate(constellation_map):
for other_time, other_freq in constellation_map:
diff = other_time - time
if diff <= 1 or diff > 10:
continue
freq_binned = freq / upper_frequency * (2 ** frequency_bits)
other_freq_binned = other_freq / upper_frequency * (2 ** frequency_bits)
hash = int(freq_binned) | (int(other_freq_binned) << 10) | (int(diff) << 20)
hashes[hash] = (time, song_id)
return hashes

if __name__ == "__main__":
print(create_hashes([1,2,3], 2))
11 changes: 8 additions & 3 deletions tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Print the song index
for index, filename in database.items():
print(f"Index: {index}, Filename: {filename}")
import pickle

# Open the pickle file in binary read mode
with open("database.pickle", "rb") as db_file:
# Load the contents of the pickle file
database = pickle.load(db_file)

print(database)
File renamed without changes.

0 comments on commit 292b906

Please sign in to comment.