[Visualization] Resample all visualizer audio
Visualizer audio is now resampled to 44100 Hz, for consistency across the system. Signed-off-by: Christopher Snowhill <kode54@gmail.com>lastfm
parent
2e45deb8d3
commit
3a9db65b53
|
@ -36,9 +36,12 @@ using std::atomic_long;
|
||||||
@interface OutputAVFoundation : NSObject {
|
@interface OutputAVFoundation : NSObject {
|
||||||
OutputNode *outputController;
|
OutputNode *outputController;
|
||||||
|
|
||||||
BOOL r8bFlushing, r8bFlushed, r8bDone;
|
BOOL r8bDone;
|
||||||
void *r8bstate, *r8bold;
|
void *r8bstate, *r8bold;
|
||||||
|
|
||||||
|
void *r8bvis;
|
||||||
|
double lastVisRate;
|
||||||
|
|
||||||
BOOL stopInvoked;
|
BOOL stopInvoked;
|
||||||
BOOL running;
|
BOOL running;
|
||||||
BOOL stopping;
|
BOOL stopping;
|
||||||
|
@ -46,6 +49,7 @@ using std::atomic_long;
|
||||||
BOOL started;
|
BOOL started;
|
||||||
BOOL paused;
|
BOOL paused;
|
||||||
BOOL restarted;
|
BOOL restarted;
|
||||||
|
BOOL stopFlush;
|
||||||
|
|
||||||
BOOL eqEnabled;
|
BOOL eqEnabled;
|
||||||
BOOL eqInitialized;
|
BOOL eqInitialized;
|
||||||
|
|
|
@ -63,7 +63,6 @@ static OSStatus eqRenderCallback(void *inRefCon, AudioUnitRenderActionFlags *ioA
|
||||||
|
|
||||||
amountToRead = 1024;
|
amountToRead = 1024;
|
||||||
|
|
||||||
int visTabulated = 0;
|
|
||||||
float visAudio[amountToRead]; // Chunk size
|
float visAudio[amountToRead]; // Chunk size
|
||||||
|
|
||||||
if(stopping == YES || [outputController shouldContinue] == NO) {
|
if(stopping == YES || [outputController shouldContinue] == NO) {
|
||||||
|
@ -145,8 +144,65 @@ static OSStatus eqRenderCallback(void *inRefCon, AudioUnitRenderActionFlags *ioA
|
||||||
|
|
||||||
[downmixerForVis process:outputPtr
|
[downmixerForVis process:outputPtr
|
||||||
frameCount:frameCount
|
frameCount:frameCount
|
||||||
output:visAudio];
|
output:&visAudio[0]];
|
||||||
visTabulated += frameCount;
|
|
||||||
|
[visController postSampleRate:44100.0];
|
||||||
|
|
||||||
|
float visTemp[8192];
|
||||||
|
if(newFormat.mSampleRate != 44100.0) {
|
||||||
|
if(newFormat.mSampleRate != lastVisRate) {
|
||||||
|
if(r8bvis) {
|
||||||
|
for(;;) {
|
||||||
|
int samplesFlushed;
|
||||||
|
[currentPtsLock lock];
|
||||||
|
samplesFlushed = (int)r8bstate_flush(r8bvis, &visTemp[0], 8192);
|
||||||
|
[currentPtsLock unlock];
|
||||||
|
if(samplesFlushed) {
|
||||||
|
[visController postVisPCM:visTemp amount:samplesFlushed];
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[currentPtsLock lock];
|
||||||
|
r8bstate_delete(r8bvis);
|
||||||
|
r8bvis = NULL;
|
||||||
|
[currentPtsLock unlock];
|
||||||
|
}
|
||||||
|
lastVisRate = newFormat.mSampleRate;
|
||||||
|
[currentPtsLock lock];
|
||||||
|
r8bvis = r8bstate_new(1, 1024, lastVisRate, 44100.0);
|
||||||
|
[currentPtsLock unlock];
|
||||||
|
}
|
||||||
|
if(r8bvis) {
|
||||||
|
size_t inDone = 0;
|
||||||
|
int samplesProcessed;
|
||||||
|
[currentPtsLock lock];
|
||||||
|
samplesProcessed = (int)r8bstate_resample(r8bvis, &visAudio[0], frameCount, &inDone, &visTemp[0], 8192);
|
||||||
|
[currentPtsLock unlock];
|
||||||
|
if(samplesProcessed) {
|
||||||
|
[visController postVisPCM:&visTemp[0] amount:samplesProcessed];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if(r8bvis) {
|
||||||
|
for(;;) {
|
||||||
|
int samplesFlushed;
|
||||||
|
[currentPtsLock lock];
|
||||||
|
samplesFlushed = (int)r8bstate_flush(r8bvis, &visTemp[0], 8192);
|
||||||
|
[currentPtsLock unlock];
|
||||||
|
if(samplesFlushed) {
|
||||||
|
[visController postVisPCM:visTemp amount:samplesFlushed];
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[currentPtsLock lock];
|
||||||
|
r8bstate_delete(r8bvis);
|
||||||
|
r8bvis = NULL;
|
||||||
|
[currentPtsLock unlock];
|
||||||
|
[visController postVisPCM:&visAudio[0] amount:frameCount];
|
||||||
|
} else {
|
||||||
|
[visController postVisPCM:&visAudio[0] amount:frameCount];
|
||||||
|
}
|
||||||
|
|
||||||
cblas_scopy((int)(frameCount * newFormat.mChannelsPerFrame), outputPtr, 1, &inputBuffer[0], 1);
|
cblas_scopy((int)(frameCount * newFormat.mChannelsPerFrame), outputPtr, 1, &inputBuffer[0], 1);
|
||||||
amountRead = frameCount;
|
amountRead = frameCount;
|
||||||
|
@ -178,9 +234,6 @@ static OSStatus eqRenderCallback(void *inRefCon, AudioUnitRenderActionFlags *ioA
|
||||||
|
|
||||||
scale_by_volume(&inputBuffer[0], amountRead * newFormat.mChannelsPerFrame, volumeScale);
|
scale_by_volume(&inputBuffer[0], amountRead * newFormat.mChannelsPerFrame, volumeScale);
|
||||||
|
|
||||||
[visController postSampleRate:newFormat.mSampleRate];
|
|
||||||
[visController postVisPCM:visAudio amount:visTabulated];
|
|
||||||
|
|
||||||
return amountRead;
|
return amountRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -750,12 +803,13 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
|
||||||
|
|
||||||
downmixerForVis = nil;
|
downmixerForVis = nil;
|
||||||
|
|
||||||
r8bFlushing = NO;
|
|
||||||
r8bFlushed = NO;
|
|
||||||
r8bDone = NO;
|
r8bDone = NO;
|
||||||
r8bstate = NULL;
|
r8bstate = NULL;
|
||||||
r8bold = NULL;
|
r8bold = NULL;
|
||||||
|
|
||||||
|
r8bvis = NULL;
|
||||||
|
lastVisRate = 44100.0;
|
||||||
|
|
||||||
AudioComponentDescription desc;
|
AudioComponentDescription desc;
|
||||||
NSError *err;
|
NSError *err;
|
||||||
|
|
||||||
|
@ -999,6 +1053,10 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
|
||||||
r8bstate_delete(r8bold);
|
r8bstate_delete(r8bold);
|
||||||
r8bold = NULL;
|
r8bold = NULL;
|
||||||
}
|
}
|
||||||
|
if(r8bvis) {
|
||||||
|
r8bstate_delete(r8bvis);
|
||||||
|
r8bvis = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,11 +21,12 @@ struct r8bstate {
|
||||||
uint64_t inProcessed;
|
uint64_t inProcessed;
|
||||||
uint64_t outProcessed;
|
uint64_t outProcessed;
|
||||||
double sampleRatio;
|
double sampleRatio;
|
||||||
|
double dstRate;
|
||||||
r8b::CFixedBuffer<double> InBuf;
|
r8b::CFixedBuffer<double> InBuf;
|
||||||
r8b::CFixedBuffer<double> *OutBufs;
|
r8b::CFixedBuffer<double> *OutBufs;
|
||||||
r8b::CDSPResampler24 **Resamps;
|
r8b::CDSPResampler24 **Resamps;
|
||||||
r8bstate(int _channelCount, int _bufferCapacity, double srcRate, double dstRate)
|
r8bstate(int _channelCount, int _bufferCapacity, double srcRate, double _dstRate)
|
||||||
: channelCount(_channelCount), bufferCapacity(_bufferCapacity), inProcessed(0), outProcessed(0), remainder(0) {
|
: channelCount(_channelCount), bufferCapacity(_bufferCapacity), inProcessed(0), outProcessed(0), remainder(0), dstRate(_dstRate) {
|
||||||
InBuf.alloc(bufferCapacity);
|
InBuf.alloc(bufferCapacity);
|
||||||
OutBufs = new r8b::CFixedBuffer<double>[channelCount];
|
OutBufs = new r8b::CFixedBuffer<double>[channelCount];
|
||||||
Resamps = new r8b::CDSPResampler24 *[channelCount];
|
Resamps = new r8b::CDSPResampler24 *[channelCount];
|
||||||
|
@ -44,7 +45,7 @@ struct r8bstate {
|
||||||
}
|
}
|
||||||
|
|
||||||
double latency() {
|
double latency() {
|
||||||
return ((double)inProcessed * sampleRatio) - (double)outProcessed;
|
return (((double)inProcessed * sampleRatio) - (double)outProcessed) / dstRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
int resample(const float *input, size_t inCount, size_t *inDone, float *output, size_t outMax) {
|
int resample(const float *input, size_t inCount, size_t *inDone, float *output, size_t outMax) {
|
||||||
|
|
Loading…
Reference in New Issue