Random CSV classification list

I am designing a music shuffler in MATLAB and I need some help. I have MATLAB randomly shuffling songs and throwing in DJ's from Fallout every once in a while. I would like to have matlab create a CSV list and classify songs with a number between 1 and 10, based on how recently the song has played. Then using the randi command I would like to to choose songs with higher numbers, that haven't played recently giving them priority and making them more likely to be chosen. Every time a song plays we would make it lose one point, and so on and so fourth. And I would like to make it so that after a while it can gain points back based on a couple hours or whatever I decide on. I'm not sure how many songs I will have in the final program. The goal is for about 1000, but I only have about 20 in testing.
I have taken an entry level class to MATLAB and never understood anything about CSVs or how to have MATLAB modify them so I'm going to need a great deal of help! I'm also not great at understanding how to properly name functions, and as this will need to be a function I'll probbaly need help with that. If you have any improvements or ideas you want to make, feel free to do so. This is just for fun so I'm always open to stuff like that.
Thanks!
Here is the code that I have so far so you guys have something to go off of...
%HOLD control c to stop because it won't stop on it's own
mus = dir('mus/*.m4a');
dj = dir('dj/*.m4a');
while true
rd = randi(length(dj),1,1);
[a, Fs] = audioread(strcat(dj(rd).folder,"/",dj(rd).name));
plot(a(:,1))
title(dj(rd).name(1:end-4));
p = audioplayer(a,Fs);
play(p)
pause(length(a)/Fs);
for ii=1:randi(4)+3
rR = randi(length(mus),1,1);
[a2, Fs2] = audioread(strcat(mus(rR).folder,"/",mus(rR).name));
plot(a2(:,1))
title(mus(rR).name(1:end-4));
p = audioplayer(a2,Fs2);
play(p)
pause(length(a2)/Fs2);
end
end

Antworten (1)

Image Analyst
Image Analyst am 29 Mär. 2019

1 Stimme

I don't know what CSV files have to do with anything unless you want to read and write some data to a csv text file.
You might look into csvread(), csvwrite(), and randperm() and randi().

10 Kommentare

Walter Roberson
Walter Roberson am 29 Mär. 2019
Note that csvread() and csvwrite() and dlmread() and dlmwrite() are effectively restricted to numeric values only.
If you want a mix of characters (such as song names) and numeric values, then your choices include:
  1. textscan()
  2. xlsread(), provided you are on MS Windows with Excel installed
  3. readtable()
  4. fgetl() + sscanf(), or fscanf()
  5. fileread() as one big character vector, then use tools such as regexp() to parse it
Ian Mason
Ian Mason am 29 Mär. 2019
It really doesn't have to be a CSV file. I'm mainly looking for a way for matlab to catagorize the songs to keep it from repeating a select few. Thats just what a friend reccomended, but if you guys have better ideas I would love to hear them!
Walter Roberson
Walter Roberson am 29 Mär. 2019
.mat files are (typically) more or less efficient to load and save, and can contain any data type.
A .csv file would be useful if you wanted to be able to examine the information in some other program.
If you wanted to be able to import playlists from other applications such as iTunes or spotify, then formats such as XML might be useful.
Ian Mason
Ian Mason am 29 Mär. 2019
Interesting. I figured I wouldn't end up importing from iTunes, and just keeping raw files around.
I'm thinking I would just end up using a .mat file and building off that. How would I start some sort of classifaction system to help train matlab to figure out what to play next? And I figure after that code I will have a line telling it that if it still chooses the same song, that it already did, to choose again.
Ian Mason
Ian Mason am 29 Mär. 2019
Fascinating! I'm trying to make it less random I guess. My goal is to have point values from 1 to 10, saying how long ago the song was played and that if the song is played it should immidately move to the bottom, in order to keep it from just continuing to play Luck Be a Lady. Does that make sense?
Image Analyst
Image Analyst am 30 Mär. 2019
So if you have a random order of the numbers 1-10, then when you want to play the 11th song, do you want to use the same original 10 song order, or do you want to generate a new order? If it's a new order, there is a possibility the 11th song could be the same as the 10th song unless you check for that and reshuffle in that case.
Ian Mason
Ian Mason am 1 Apr. 2019
So I intend to have a couple hundered songs, at least, in this program. With testing, I only have about 20ish, since my matlab files are being stored in the cloud and I don't want to pay for more storage. As I have these hundreds of songs I want matlab to have a priority on what to play and when, to reduce likelyhood of songs repeating. Thats why I reccomended 1-10 as a classifaction system. I'm thinking that this will still allow some vairability so that there are x ammount of songs classified as 10s, and 9s and so on. I'm just not sure how to go about even starting something like this.
Walter Roberson
Walter Roberson am 1 Apr. 2019
What would the classification be based on? Would you be performing some kind of feature analysis on the songs to figure out what the high-rated songs had but the lower-rated songs did not, and that analysis should be used to predict whether additional songs would be high rated or not? For example, the analysis might notice that you consistently rated songs with cowbell higher, and so additional songs should have priority if they have more cowbell.
Image Analyst
Image Analyst am 1 Apr. 2019
Why not just make two lists: one for locally stored music files, and one for those in the cloud? Then you could randomly intersperse your 10 local files so that they always fall within, say, the first 30 files in the list.

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Version

R2018b

Gefragt:

am 29 Mär. 2019

Kommentiert:

am 1 Apr. 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by