i know a better way

This commit is contained in:
tildearrow 2021-12-07 04:32:42 -05:00
parent 7490ed89a1
commit 4cba677c04
5 changed files with 4 additions and 132 deletions

View file

@ -1,99 +0,0 @@
#include <sndfile.h>
#include <string.h>
#include "file.h"
#include "taAudio.h"
void TAAudioFile::onProcess(unsigned char* buf, int nframes) {
if (audioProcCallback!=NULL) {
audioProcCallback(audioProcCallbackUser,inBufs,outBufs,desc.inChans,desc.outChans,desc.bufsize);
}
/*
float* fbuf=(float*)buf;
for (size_t j=0; j<desc.bufsize; j++) {
for (size_t i=0; i<desc.outChans; i++) {
fbuf[j*desc.outChans+i]=outBufs[i][j];
}
}*/
}
void* TAAudioFile::getContext() {
return file;
}
bool TAAudioFile::quit() {
if (!initialized) return false;
if (file!=NULL) {
sf_close(file);
file=NULL;
}
if (running) {
running=false;
}
for (int i=0; i<desc.outChans; i++) {
delete[] outBufs[i];
}
delete[] outBufs;
initialized=false;
return true;
}
bool TAAudioFile::setRun(bool run) {
if (!initialized) return false;
SDL_PauseAudioDevice(ai,!run);
running=run;
return running;
}
bool TAAudioFile::init(TAAudioDesc& request, TAAudioDesc& response) {
if (initialized) return false;
TAAudioDesc desc=request;
if (desc.inChans>0) return false;
memset(si,0,sizeof(SF_INFO));
si.channels=request.outChans;
si.samplerate=request.rate;
switch (request.outFormat) {
case TA_AUDIO_FORMAT_F32:
si.format=SF_FORMAT_FLOAT;
break;
case TA_AUDIO_FORMAT_F64:
si.format=SF_FORMAT_DOUBLE;
break;
case TA_AUDIO_FORMAT_U8:
si.format=SF_FORMAT_PCM_U8;
break;
case TA_AUDIO_FORMAT_S8:
si.format=SF_FORMAT_PCM_S8;
break;
case TA_AUDIO_FORMAT_S16:
si.format=SF_FORMAT_PCM_16;
break;
case TA_AUDIO_FORMAT_S32:
si.format=SF_FORMAT_PCM_32;
break;
default:
return false;
}
si.format|=SF_FORMAT_WAV;
file=sf_open(request.name.c_str(),SFM_WRITE,&si);
if (file==NULL) return false;
if (desc.outChans>0) {
outBufs=new float*[desc.outChans];
for (int i=0; i<desc.outChans; i++) {
outBufs[i]=new float[desc.bufsize];
}
}
response=desc;
initialized=true;
return true;
}

View file

@ -1,18 +0,0 @@
#include "taAudio.h"
#include <sndfile.h>
class TAAudioFile: public TAAudio {
float** iInBufs;
float** iOutBufs;
SNDFILE* file;
SF_INFO si;
public:
void onProcess(unsigned char* buf, int nframes);
void* getContext();
bool quit();
bool setRun(bool run);
bool init(TAAudioDesc& request, TAAudioDesc& response);
};

View file

@ -5,7 +5,6 @@
#ifdef HAVE_JACK
#include "../audio/jack.h"
#endif
#include "../audio/file.h"
#include "platform/genesis.h"
#include "platform/genesisext.h"
#include "platform/sms.h"
@ -708,9 +707,6 @@ bool DivEngine::init() {
case DIV_AUDIO_SDL:
output=new TAAudioSDL;
break;
case DIV_AUDIO_FILE:
output=new TAAudioFile;
break;
default:
logE("invalid audio engine!\n");
return false;

View file

@ -13,8 +13,7 @@ enum DivStatusView {
enum DivAudioEngines {
DIV_AUDIO_JACK=0,
DIV_AUDIO_SDL,
DIV_AUDIO_FILE
DIV_AUDIO_SDL
};
struct DivChannelState {
@ -66,8 +65,6 @@ class DivEngine {
DivChannelState chan[17];
DivAudioEngines audioEngine;
String outName;
short vibTable[64];
blip_buffer_t* bb[2];
@ -108,11 +105,8 @@ class DivEngine {
// set the view mode.
void setView(DivStatusView which);
// open audio output file.
bool openAudioOut(String filename);
// initialize the engine.
bool init();
// initialize the engine. optionally provide an output file name.
bool init(String outName="");
DivEngine():
chans(0),

View file

@ -116,8 +116,7 @@ bool pLoops(String val) {
}
bool pOutput(String val) {
e.setAudio(DIV_AUDIO_FILE);
return e.openAudioOut(val);
return false;
}
bool needsValue(String param) {