mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 00:57:44 +00:00
SoundPlayer: Implement playlist shuffle mode
The shuffling algorithm uses a naïve bloom filter to provide random uniformity, avoiding items that were recently played. With 32 bits, double hashing, and an error rate of ~10%, this bloom filter should be able to hold around ~16 keys, which should be sufficient to give the illusion of fairness to the shuffling algorithm. This avoids having to shuffle the playlist itself (user might have spent quite a bit of time to sort them, so it's not a good idea to mess with it), or having to create a proxy model that shuffles (that could potentially use quite a bit of memory).
This commit is contained in:
parent
0812965f50
commit
314b8a374b
7 changed files with 106 additions and 11 deletions
|
@ -24,6 +24,10 @@ public:
|
|||
File,
|
||||
Playlist,
|
||||
};
|
||||
enum class ShuffleMode {
|
||||
None,
|
||||
Shuffling,
|
||||
};
|
||||
|
||||
explicit Player(Audio::ClientConnection& audio_client_connection);
|
||||
virtual ~Player() { }
|
||||
|
@ -34,10 +38,13 @@ public:
|
|||
StringView loaded_filename() const { return m_loaded_filename; }
|
||||
|
||||
PlayState play_state() const { return m_play_state; }
|
||||
void set_play_state(PlayState state);
|
||||
void set_play_state(PlayState);
|
||||
|
||||
LoopMode loop_mode() const { return m_loop_mode; }
|
||||
void set_loop_mode(LoopMode mode);
|
||||
void set_loop_mode(LoopMode);
|
||||
|
||||
ShuffleMode shuffle_mode() const { return m_shuffle_mode; }
|
||||
void set_shuffle_mode(ShuffleMode);
|
||||
|
||||
double volume() const { return m_volume; }
|
||||
void set_volume(double value);
|
||||
|
@ -52,11 +59,12 @@ public:
|
|||
virtual void loop_mode_changed(LoopMode) = 0;
|
||||
virtual void time_elapsed(int) = 0;
|
||||
virtual void file_name_changed(StringView) = 0;
|
||||
virtual void playlist_loaded(StringView, bool) { }
|
||||
virtual void audio_load_error(StringView, StringView) { }
|
||||
virtual void volume_changed(double) { }
|
||||
virtual void total_samples_changed(int) { }
|
||||
virtual void sound_buffer_played(RefPtr<Audio::Buffer>, [[maybe_unused]] int sample_rate, [[maybe_unused]] int samples_played) { }
|
||||
virtual void playlist_loaded(StringView, bool) = 0;
|
||||
virtual void audio_load_error(StringView, StringView) = 0;
|
||||
virtual void shuffle_mode_changed(ShuffleMode) = 0;
|
||||
virtual void volume_changed(double) = 0;
|
||||
virtual void total_samples_changed(int) = 0;
|
||||
virtual void sound_buffer_played(RefPtr<Audio::Buffer>, [[maybe_unused]] int sample_rate, [[maybe_unused]] int samples_played) = 0;
|
||||
|
||||
protected:
|
||||
void done_initializing()
|
||||
|
@ -71,6 +79,7 @@ private:
|
|||
Playlist m_playlist;
|
||||
PlayState m_play_state;
|
||||
LoopMode m_loop_mode;
|
||||
ShuffleMode m_shuffle_mode;
|
||||
|
||||
Audio::ClientConnection& m_audio_client_connection;
|
||||
PlaybackManager m_playback_manager;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue