Skip to content

Commit c5837e8

Browse files
committed
2 parents 0041534 + 4097eac commit c5837e8

File tree

4 files changed

+57
-9
lines changed

4 files changed

+57
-9
lines changed

src/AudioConfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@
175175
#if ESP_IDF_VERSION_MAJOR < 4 && !defined(I2S_COMM_FORMAT_STAND_I2S)
176176
# define I2S_COMM_FORMAT_STAND_I2S (I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_LSB)
177177
# define I2S_COMM_FORMAT_STAND_MSB (I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB)
178+
# define I2S_COMM_FORMAT_STAND_PCM_LONG (I2S_COMM_FORMAT_PCM | I2S_COMM_FORMAT_PCM_LONG)
179+
# define I2S_COMM_FORMAT_STAND_PCM_SHORT (I2S_COMM_FORMAT_PCM | I2S_COMM_FORMAT_PCM_SHORT)
180+
178181
typedef int eps32_i2s_sample_rate_type;
179182
#else
180183
typedef uint32_t eps32_i2s_sample_rate_type;

src/AudioI2S/I2SESP32.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class I2SBase {
5252
.dma_buf_len = I2S_BUFFER_SIZE,
5353
.use_apll = (bool) cfg.use_apll,
5454
.tx_desc_auto_clear = I2S_AUTO_CLEAR,
55-
.fixed_mclk = (eps32_i2s_sample_rate_type) (cfg.use_apll ? cfg.sample_rate * cfg.apll_frequency_factor : 0 )
55+
.fixed_mclk = (int) (cfg.use_apll ? cfg.sample_rate * cfg.apll_frequency_factor : 0 )
5656

5757
};
5858
i2s_config = i2s_config_new;
@@ -223,9 +223,9 @@ class I2SBase {
223223
case I2S_LEFT_JUSTIFIED_FORMAT:
224224
return (i2s_comm_format_t) I2S_COMM_FORMAT_STAND_MSB;
225225
case I2S_PCM_LONG:
226-
return (i2s_comm_format_t) I2S_COMM_FORMAT_PCM_LONG;
226+
return (i2s_comm_format_t) I2S_COMM_FORMAT_STAND_PCM_LONG;
227227
case I2S_PCM_SHORT:
228-
return (i2s_comm_format_t) I2S_COMM_FORMAT_PCM_SHORT;
228+
return (i2s_comm_format_t) I2S_COMM_FORMAT_STAND_PCM_SHORT;
229229

230230
default:
231231
LOGE("unsupported mode");

src/AudioTools.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@
3939
* @brief typedefs for Default
4040
*
4141
*/
42-
namespace audio_tools {
42+
43+
using namespace audio_tools;
4344

4445
#if defined(__linux__) || defined(_WIN32) || defined(__APPLE__)
4546
typedef PortAudioStream DefaultStream;
4647
#elif defined(ESP32) || defined(ESP8266) || defined(__SAMD21G18A__)
4748
typedef I2SStream DefaultStream;
4849
#endif
49-
50-
}

src/AudioTools/AudioPlayer.h

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ namespace audio_tools {
5959
return selectStream(index);
6060
}
6161

62+
/// same as selectStream - I just prefer this name
63+
virtual Stream* selectStream(char* path, char* fileName) {
64+
return selectStream(path,fileName);
65+
}
66+
6267
/// Sets the timeout which is triggering to move to the next stream. - the default value is 500 ms
6368
virtual void setTimeoutAutoNext(int millisec) {
6469
timeout_auto_next_value = millisec;
@@ -149,7 +154,7 @@ namespace audio_tools {
149154
typedef File AudioFile;
150155
#elif SD_FAT_TYPE == 1
151156
typedef SdFat32 AudioFs;
152-
typedef File32 AudioDir;
157+
//typedef File32 AudioDir;
153158
typedef File32 AudioFile;
154159
#elif SD_FAT_TYPE == 2
155160
typedef SdExFat AudioFs;
@@ -205,12 +210,19 @@ namespace audio_tools {
205210
virtual Stream* selectStream(int index) override {
206211
idx_pos = index<0 ? 0 : index;
207212
file.close();
208-
file = getFile(start_path, idx_pos);
213+
file = getFileByPos(start_path, idx_pos);
209214
file.getName(file_name, MAX_FILE_LEN);
210215
LOGW("-> selectStream: %d '%s'", idx_pos, file_name);
211216
return file ? &file : nullptr;
212217
}
213218

219+
virtual Stream* selectStream(char* path, char* fileName) override {
220+
file.close();
221+
file = getFileByPath(path, fileName);
222+
LOGW("-> selectStream: %s%s", path, fileName);
223+
return file ? &file : nullptr;
224+
}
225+
214226
/// Defines the regex filter criteria for selecting files. E.g. ".*Bob Dylan.*"
215227
void setFileFilter(const char* filter) {
216228
file_name_pattern = (char*)filter;
@@ -251,7 +263,7 @@ namespace audio_tools {
251263
}
252264

253265
/// Determines the file at the indicated index (starting with 0)
254-
AudioFile getFile(const char* dirStr, int pos) {
266+
AudioFile getFileByPos(const char* dirStr, int pos) {
255267
AudioFile dir;
256268
AudioFile result;
257269
if (sd.exists(dirStr)){
@@ -270,6 +282,31 @@ namespace audio_tools {
270282
return result;
271283
}
272284

285+
AudioFile getFileByPath(char* path, char* fileName) {
286+
AudioFile dir;
287+
if (!dir.open(path)) {//("/21/" , "001.mp3")
288+
LOGE("directory: %s not open", path);
289+
}
290+
else
291+
{
292+
if (!dir.isDir()) {
293+
LOGE("directory: %s is not dictory", path);
294+
}
295+
else
296+
{
297+
if (!file.open(&dir, fileName, O_RDWR)) {
298+
LOGE("file: %s not open", path);
299+
}
300+
else
301+
{
302+
LOGD("-> getFileByPath: '%s': %d", path, fileName);
303+
}
304+
}
305+
}
306+
dir.close();
307+
return file;
308+
}
309+
273310
/// Recursively walk the directory tree to find the file at the indicated pos.
274311
void getFileAtIndex(AudioFile dir, size_t pos, size_t& idx, AudioFile& result) {
275312
LOGD("%s: %d", LOG_METHOD, idx);
@@ -308,6 +345,7 @@ namespace audio_tools {
308345
}
309346
}
310347
}
348+
311349
};
312350

313351
#endif
@@ -608,6 +646,14 @@ namespace audio_tools {
608646
return active;
609647
}
610648

649+
/// moves to selected file
650+
virtual bool setPath(char* path, char* fileName) {
651+
LOGD(LOG_METHOD);
652+
previous_stream = false;
653+
active = setStream(p_source->selectStream(path, fileName));
654+
return active;
655+
}
656+
611657
/// moves to previous file
612658
virtual bool previous(int offset=1) {
613659
LOGD(LOG_METHOD);

0 commit comments

Comments
 (0)