Add dsp interpreter to Mac build. Core audio buffering.
This commit is contained in:
parent
1533091151
commit
298bf08fc0
|
@ -22,27 +22,31 @@
|
|||
|
||||
AudioUnit audioUnit;
|
||||
|
||||
#define BUFSIZE 8192
|
||||
u8 samples_temp[BUFSIZE];
|
||||
// ~ 93 ms
|
||||
#define BUFSIZE (4 * 1024 * 4)
|
||||
static u8 samples_temp[BUFSIZE];
|
||||
|
||||
std::atomic<int> samples_wptr;
|
||||
int samples_rptr;
|
||||
cResetEvent bufferEmpty(false, true);
|
||||
static std::atomic<int> samples_wptr;
|
||||
static std::atomic<int> samples_rptr;
|
||||
static cResetEvent bufferEmpty(false, true);
|
||||
|
||||
OSStatus coreaudio_callback(void* ctx, AudioUnitRenderActionFlags* flags, const AudioTimeStamp* ts,
|
||||
static OSStatus coreaudio_callback(void* ctx, AudioUnitRenderActionFlags* flags, const AudioTimeStamp* ts,
|
||||
UInt32 bus, UInt32 frames, AudioBufferList* abl)
|
||||
{
|
||||
verify(frames <= 1024);
|
||||
|
||||
for (int i = 0; i < abl->mNumberBuffers; i++) {
|
||||
if ((samples_rptr + abl->mBuffers[i].mDataByteSize) % BUFSIZE > samples_wptr) {
|
||||
for (int i = 0; i < abl->mNumberBuffers; i++)
|
||||
{
|
||||
u32 buf_size = abl->mBuffers[i].mDataByteSize;
|
||||
if ((samples_wptr - samples_rptr + BUFSIZE) % BUFSIZE < buf_size)
|
||||
{
|
||||
//printf("Core Audio: buffer underrun");
|
||||
memset(abl->mBuffers[i].mData, '\0', abl->mBuffers[i].mDataByteSize);
|
||||
memset(abl->mBuffers[i].mData, '\0', buf_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(abl->mBuffers[i].mData, samples_temp + samples_rptr, abl->mBuffers[i].mDataByteSize);
|
||||
samples_rptr = (samples_rptr + abl->mBuffers[i].mDataByteSize) % BUFSIZE;
|
||||
memcpy(abl->mBuffers[i].mData, samples_temp + samples_rptr, buf_size);
|
||||
samples_rptr = (samples_rptr + buf_size) % BUFSIZE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,11 +119,21 @@ static void coreaudio_init()
|
|||
|
||||
static u32 coreaudio_push(void* frame, u32 samples, bool wait)
|
||||
{
|
||||
if (wait)
|
||||
bufferEmpty.Wait();
|
||||
|
||||
memcpy(&samples_temp[samples_wptr], frame, samples * 4);
|
||||
samples_wptr = (samples_wptr + samples * 4) % BUFSIZE;
|
||||
int byte_size = samples * 4;
|
||||
while (true)
|
||||
{
|
||||
int space = (samples_rptr - samples_wptr + BUFSIZE) % BUFSIZE;
|
||||
if (space != 0 && byte_size > space - 1)
|
||||
{
|
||||
if (!wait)
|
||||
break;
|
||||
bufferEmpty.Wait();
|
||||
continue;
|
||||
}
|
||||
memcpy(&samples_temp[samples_wptr], frame, byte_size);
|
||||
samples_wptr = (samples_wptr + byte_size) % BUFSIZE;
|
||||
break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -193,6 +193,7 @@
|
|||
84B7BF861B72871600F9733F /* EmuGLView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B7BF851B72871600F9733F /* EmuGLView.swift */; };
|
||||
AE1E293B2095FB1600FC6BA2 /* rec_cpp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AE1E293A2095FB1600FC6BA2 /* rec_cpp.cpp */; };
|
||||
AE1E294020A96B0B00FC6BA2 /* rec_x64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AE1E293F20A96B0B00FC6BA2 /* rec_x64.cpp */; };
|
||||
AE8C27342111A31100D4D8F4 /* dsp_interp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AE8C27332111A31100D4D8F4 /* dsp_interp.cpp */; };
|
||||
EBDF374F1BB96581001191B5 /* audiobackend_coreaudio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EBDF374D1BB96581001191B5 /* audiobackend_coreaudio.cpp */; };
|
||||
EBDF37511BB969EE001191B5 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EBDF37501BB969EE001191B5 /* CoreAudio.framework */; };
|
||||
EBDF37531BB969F8001191B5 /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EBDF37521BB969F8001191B5 /* AudioUnit.framework */; };
|
||||
|
@ -545,6 +546,7 @@
|
|||
AE1E292B20947D4700FC6BA2 /* xbyak_util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xbyak_util.h; sourceTree = "<group>"; };
|
||||
AE1E293A2095FB1600FC6BA2 /* rec_cpp.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rec_cpp.cpp; sourceTree = "<group>"; };
|
||||
AE1E293F20A96B0B00FC6BA2 /* rec_x64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rec_x64.cpp; sourceTree = "<group>"; };
|
||||
AE8C27332111A31100D4D8F4 /* dsp_interp.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = dsp_interp.cpp; sourceTree = "<group>"; };
|
||||
EBDF374D1BB96581001191B5 /* audiobackend_coreaudio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = audiobackend_coreaudio.cpp; sourceTree = "<group>"; };
|
||||
EBDF374E1BB96581001191B5 /* audiobackend_coreaudio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = audiobackend_coreaudio.h; sourceTree = "<group>"; };
|
||||
EBDF37501BB969EE001191B5 /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; };
|
||||
|
@ -929,6 +931,7 @@
|
|||
84B7BDCD1B72720100F9733F /* aica_mem.h */,
|
||||
84B7BDCE1B72720100F9733F /* dsp.cpp */,
|
||||
84B7BDCF1B72720100F9733F /* dsp.h */,
|
||||
AE8C27332111A31100D4D8F4 /* dsp_interp.cpp */,
|
||||
84B7BDD01B72720100F9733F /* sgc_if.cpp */,
|
||||
84B7BDD11B72720100F9733F /* sgc_if.h */,
|
||||
);
|
||||
|
@ -1470,6 +1473,7 @@
|
|||
84B7BEAF1B72720200F9733F /* cfg.cpp in Sources */,
|
||||
84B7BF521B72720200F9733F /* ubc.cpp in Sources */,
|
||||
84B7BF121B72720200F9733F /* zip_unchange.c in Sources */,
|
||||
AE8C27342111A31100D4D8F4 /* dsp_interp.cpp in Sources */,
|
||||
84B7BF421B72720200F9733F /* blockmanager.cpp in Sources */,
|
||||
84B7BEE21B72720200F9733F /* zip_add_dir.c in Sources */,
|
||||
84967CC91B8F49EE005F1140 /* pngset.c in Sources */,
|
||||
|
|
Loading…
Reference in New Issue