libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
wavplayer.h
Go to the documentation of this file.
1/* Current Limitations:
2- 1x Playback speed only
3- 16-bit, mono files only (otherwise fun weirdness can happen).
4- Only 1 file playing back at a time.
5- Not sure how this would interfere with trying to use the SDCard/FatFs outside of
6this module. However, by using the extern'd SDFile, etc. I think that would break things.
7*/
8#pragma once
9#ifndef DSY_WAVPLAYER_H
10#define DSY_WAVPLAYER_H
11#include "daisy_core.h"
12#include "util/wav_format.h"
13#include "ff.h"
14
15#define WAV_FILENAME_MAX \
16 256
18namespace daisy
19{
20// TODO: add bitrate, samplerate, length, etc.
27
28/*
29TODO:
30- Make template-y to reduce memory usage.
31*/
32
33
38{
39 public:
42
44 void Init(const char* search_path);
45
49 int Open(size_t sel);
50
54 int Close();
55
58
60 void Prepare();
61
63 void Restart();
64
68 inline void SetLooping(bool loop) { looping_ = loop; }
69
71 inline bool GetLooping() const { return looping_; }
72
74 inline size_t GetNumberFiles() const { return file_cnt_; }
75
77 inline size_t GetCurrentFile() const { return file_sel_; }
78
79 private:
80 enum BufferState
81 {
82 BUFFER_STATE_IDLE,
83 BUFFER_STATE_PREPARE_0,
84 BUFFER_STATE_PREPARE_1,
85 };
86
87 BufferState GetNextBuffState();
88
89 static constexpr size_t kMaxFiles = 8;
90 static constexpr size_t kBufferSize = 4096;
91 WavFileInfo file_info_[kMaxFiles];
92 size_t file_cnt_, file_sel_;
93 BufferState buff_state_;
94 int16_t buff_[kBufferSize];
95 size_t read_ptr_;
96 bool looping_, playing_;
97 FIL fil_;
98};
99
100} // namespace daisy
101
102#endif
Definition leddriver.h:33
Definition wavplayer.h:38
void Init(const char *search_path)
WavPlayer()
Definition wavplayer.h:40
void SetLooping(bool loop)
Definition wavplayer.h:68
size_t GetCurrentFile() const
Definition wavplayer.h:77
int16_t Stream()
~WavPlayer()
Definition wavplayer.h:41
int Open(size_t sel)
bool GetLooping() const
Definition wavplayer.h:71
size_t GetNumberFiles() const
Definition wavplayer.h:74
Hardware defines and helpers for daisy field platform.
Definition index.h:2
Definition wav_format.h:39
Definition wavplayer.h:23
char name[256]
Definition wavplayer.h:25
WAV_FormatTypeDef raw_data
Definition wavplayer.h:24
#define WAV_FILENAME_MAX
Definition wavplayer.h:15