File main.cpp¶
File List > examples > WavPlayer > main.cpp
Go to the documentation of this file
Source Code¶
#include "daisy_seed.h"
using namespace daisy;
static constexpr const size_t kTransferSize = 16384;
static DaisySeed hw;
static SdmmcHandler sdmmc;
static FatFSInterface fsi;
static WavPlayer<kTransferSize> player;
void AudioCallback(AudioHandle::InputBuffer in,
AudioHandle::OutputBuffer out,
size_t size)
{
for(size_t i = 0; i < size; i++)
{
// Fill two channels of data per sample
float samps[2];
player.Stream(samps, 2);
out[0][i] = samps[0];
out[1][i] = samps[1];
}
}
int main(void)
{
hw.Init(true);
SdmmcHandler::Config sdcfg;
sdcfg.Defaults();
sdcfg.speed = SdmmcHandler::Speed::STANDARD;
sdcfg.width = SdmmcHandler::BusWidth::BITS_1;
sdmmc.Init(sdcfg);
fsi.Init(FatFSInterface::Config::Media::MEDIA_SD);
f_mount(&fsi.GetSDFileSystem(), "/", 1);
if (player.Init("loop.wav") != WavPlayer<kTransferSize>::Result::Ok) {
// Error..
while(true) {
// Blink really fast if there was a problem
hw.SetLed((System::GetNow() & 127) < 63);
}
}
player.SetLooping(true);
player.SetPlaying(true);
player.Restart();
hw.StartAudio(AudioCallback);
while(1)
{
hw.SetLed((System::GetNow() & 511) < 255);
player.Prepare();
}
}