prepare to add a reference player

This commit is contained in:
tildearrow 2025-10-26 21:02:05 -05:00
parent 6738fbdbe4
commit 6589cd04b3
2 changed files with 156 additions and 0 deletions

69
src/engine/filePlayer.h Normal file
View file

@ -0,0 +1,69 @@
/**
* Furnace Tracker - multi-system chiptune tracker
* Copyright (C) 2021-2025 tildearrow and contributors
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef _FILEPLAYER_H
#define _FILEPLAYER_H
#include <mutex>
#ifdef HAVE_SNDFILE
#include "sfWrapper.h"
#else
typedef void SNDFILE;
struct SF_INFO {
int invalid;
};
#endif
class DivFilePlayer {
float** blocks;
String lastError;
SNDFILE* sf;
SF_INFO si;
size_t playPos;
int outRate;
int rateAccum;
float volume;
bool playing;
bool fileError;
std::mutex cacheMutex;
void fillBlocksNear(size_t pos);
public:
void mix(float** buf, int chans, unsigned int size);
size_t getPos();
size_t setPos(size_t newPos, unsigned int offset=0);
bool isPlaying();
void play(unsigned int offset=0);
void stop(unsigned int offset=0);
bool closeFile();
bool loadFile(const char* path);
String getLastError();
void setOutputRate(int rate);
float getVolume();
void setVolume(float vol);
DivFilePlayer();
~DivFilePlayer();
};