0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

M5StackCore2でWAVもしくはMP3を再生する場合

Last updated at Posted at 2021-02-28

ESP8266Audioを使ってM5StackでSDカードに入っているWAV(もしくはMP3)を再生させる方法以下のように行うことができます。

#include <M5Stack.h>
#include "AudioFileSourceSD.h"
#include "AudioGeneratorWAV.h"
#include "AudioOutputI2S.h"

AudioGeneratorWAV *wav;
AudioFileSourceSD *file;
AudioOutputI2S *out;

void setup()
{
  M5.begin();

  file = new AudioFileSourceSD("/sx.wav");      
  wav = new AudioGeneratorWAV();   
  out->SetOutputModeMono(true);
  out->SetGain(1.0);
  wav->begin(file, out);
}

void loop()
{
  if(wav->isRunning()) {
    if (!wav->loop()) wav->stop();
  }
}

参考記事
https://qiita.com/ktansai/items/f0096495e2ca7fa38eb7

ですが、Core2の場合にもろもろ仕様が変わっていますので以下のようにAudioOutputI2Sの部分を変更する必要があります。

      out = new AudioOutputI2S(0, 1);
      out->SetOutputModeMono(true);
      out->SetGain(1.0);

      out = new AudioOutputI2S(0, 0);
      out->SetPinout(12, 0, 2);
      out->SetOutputModeMono(true);
      out->SetGain(1.0);
0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?