<reponame>Marcel-Velez/CLMR<filename>clmr/datasets/gtzan_old.py
import torchaudio
from torchaudio.datasets.gtzan import gtzan_genres
from clmr.datasets import Dataset
import os 

# # https://web.archive.org/web/20220328223413/http://opihi.cs.uvic.ca/sound/genres.tar.gz

class GTZANOLD(Dataset):

    subset_map = {"train": "training", "valid": "validation", "test": "testing"}

    def __init__(self, root, download, subset):
        self.dataset = torchaudio.datasets.GTZAN(
            root=os.path.join(root,"gtzan"), download=False, subset=self.subset_map[subset]
        )
        self.labels = gtzan_genres

        self.label2idx = {}
        for idx, label in enumerate(self.labels):
            self.label2idx[label] = idx

        self.n_classes = len(self.label2idx.keys())
        print(self.dataset)

    def file_path(self, n: int) -> str:
        audio, sr, label = self.dataset[n]
        print(audio)
        exit()
        # _, fp = self.fl[n].split("\t")
        return os.path.join(self._path, fp)

    def __getitem__(self, idx):
        audio, sr, label = self.dataset[idx]
        print(audio)
        label = self.label2idx[label]
        return audio, label

    def __len__(self):
        return len(self.dataset)
