From 532bac1e0793ddcf878ebf46a92bf9ec6a3f0e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B8=CC=86=20=D0=90?= =?UTF-8?q?=D1=88=D0=B0=D0=BD=D0=B8=D0=BD?= Date: Tue, 9 Feb 2016 04:41:35 +0300 Subject: [PATCH] buffer size in seconds to float decibel commented --- StreamingKit/StreamingKit/STKAudioPlayer.h | 6 +- StreamingKit/StreamingKit/STKAudioPlayer.m | 120 ++++++++++----------- 2 files changed, 63 insertions(+), 63 deletions(-) diff --git a/StreamingKit/StreamingKit/STKAudioPlayer.h b/StreamingKit/StreamingKit/STKAudioPlayer.h index bfdaeb3..cfd9af5 100644 --- a/StreamingKit/StreamingKit/STKAudioPlayer.h +++ b/StreamingKit/StreamingKit/STKAudioPlayer.h @@ -91,7 +91,7 @@ typedef struct /// The size of the internal I/O read buffer. This data in this buffer is transient and does not need to be larger. UInt32 readBufferSize; /// The size of the decompressed buffer (Default is 10 seconds which uses about 1.7MB of RAM) - UInt32 bufferSizeInSeconds; + float bufferSizeInSeconds; /// Number of seconds of decompressed audio is required before playback first starts for each item (Default is 0.5 seconds. Must be larger than bufferSizeInSeconds) Float32 secondsRequiredToStartPlaying; /// Seconds after a seek is performed before data needs to come in (after which the state will change to playing/buffering) @@ -256,11 +256,11 @@ typedef void(^STKFrameFilter)(UInt32 channelsPerFrame, UInt32 bytesPerFrame, UIn /// Reads the peak power in decibals for the given channel (0 or 1). /// Return values are between -60 (low) and 0 (high). --(float) peakPowerInDecibelsForChannel:(NSUInteger)channelNumber; +//-(float) peakPowerInDecibelsForChannel:(NSUInteger)channelNumber; /// Reads the average power in decibals for the given channel (0 or 1) /// Return values are between -60 (low) and 0 (high). --(float) averagePowerInDecibelsForChannel:(NSUInteger)channelNumber; +//-(float) averagePowerInDecibelsForChannel:(NSUInteger)channelNumber; /// Sets the gain value (from -96 low to +24 high) for an equalizer band (0 based index) -(void) setGain:(float)gain forEqualizerBand:(int)bandIndex; diff --git a/StreamingKit/StreamingKit/STKAudioPlayer.m b/StreamingKit/StreamingKit/STKAudioPlayer.m index b5dcfe7..22564be 100755 --- a/StreamingKit/StreamingKit/STKAudioPlayer.m +++ b/StreamingKit/StreamingKit/STKAudioPlayer.m @@ -52,15 +52,15 @@ #define kOutputBus 0 #define kInputBus 1 -#define STK_DBMIN (-60) -#define STK_DBOFFSET (-74.0) +//#define STK_DBMIN (-60) +//#define STK_DBOFFSET (-74.0) #define STK_LOWPASSFILTERTIMESLICE (0.0005) -#define STK_DEFAULT_PCM_BUFFER_SIZE_IN_SECONDS (2 * 60) +#define STK_DEFAULT_PCM_BUFFER_SIZE_IN_SECONDS (0.1) #define STK_DEFAULT_SECONDS_REQUIRED_TO_START_PLAYING (1) #define STK_DEFAULT_SECONDS_REQUIRED_TO_START_PLAYING_AFTER_BUFFER_UNDERRUN (7.5) #define STK_MAX_COMPRESSED_PACKETS_FOR_BITRATE_CALCULATION (4096) -#define STK_DEFAULT_READ_BUFFER_SIZE (64 * 1024) +#define STK_DEFAULT_READ_BUFFER_SIZE (128 * 1024) #define STK_DEFAULT_PACKET_BUFFER_SIZE (2048) #define STK_DEFAULT_GRACE_PERIOD_AFTER_SEEK_SECONDS (0.5) @@ -1734,10 +1734,10 @@ static void AudioFileStreamPacketsProc(void* clientData, UInt32 numberBytes, UIn self->pcmBufferFrameStartIndex = 0; self->pcmBufferUsedFrameCount = 0; - self->peakPowerDb[0] = STK_DBMIN; - self->peakPowerDb[1] = STK_DBMIN; - self->averagePowerDb[0] = STK_DBMIN; - self->averagePowerDb[1] = STK_DBMIN; +// self->peakPowerDb[0] = STK_DBMIN; +// self->peakPowerDb[1] = STK_DBMIN; +// self->averagePowerDb[0] = STK_DBMIN; +// self->averagePowerDb[1] = STK_DBMIN; OSSpinLockUnlock(&pcmBufferSpinLock); } @@ -3233,58 +3233,58 @@ static OSStatus OutputRenderCallback(void* inRefCon, AudioUnitRenderActionFlags* [self.delegate plotGraphWithBuffer:*(_floatBuffers) andLength:frameCount]; } - SInt16* samples16 = (SInt16*)frames; - SInt32* samples32 = (SInt32*)frames; - UInt32 countLeft = 0; - UInt32 countRight = 0; - Float32 decibelsLeft = STK_DBMIN; - Float32 peakValueLeft = STK_DBMIN; - Float64 totalValueLeft = 0; - Float32 previousFilteredValueOfSampleAmplitudeLeft = 0; - Float32 decibelsRight = STK_DBMIN; - Float32 peakValueRight = STK_DBMIN; - Float64 totalValueRight = 0; - Float32 previousFilteredValueOfSampleAmplitudeRight = 0; - - if (bytesPerFrame / channelsPerFrame == 2) - { - for (int i = 0; i < frameCount * channelsPerFrame; i += channelsPerFrame) - { - Float32 absoluteValueOfSampleAmplitudeLeft = abs(samples16[i]); - Float32 absoluteValueOfSampleAmplitudeRight = abs(samples16[i + 1]); - - CALCULATE_METER(Left); - CALCULATE_METER(Right); - } - } - else if (bytesPerFrame / channelsPerFrame == 4) - { - for (int i = 0; i < frameCount * channelsPerFrame; i += channelsPerFrame) - { - Float32 absoluteValueOfSampleAmplitudeLeft = abs(samples32[i]) / 32768.0; - Float32 absoluteValueOfSampleAmplitudeRight = abs(samples32[i + 1]) / 32768.0; - - CALCULATE_METER(Left); - CALCULATE_METER(Right); - } - } - else - { - return; - } - - peakPowerDb[0] = MIN(MAX(decibelsLeft, -60), 0); - peakPowerDb[1] = MIN(MAX(decibelsRight, -60), 0); - - if (countLeft > 0) - { - averagePowerDb[0] = MIN(MAX(totalValueLeft / frameCount, -60), 0); - } - - if (countRight != 0) - { - averagePowerDb[1] = MIN(MAX(totalValueRight / frameCount, -60), 0); - } +// SInt16* samples16 = (SInt16*)frames; +// SInt32* samples32 = (SInt32*)frames; +// UInt32 countLeft = 0; +// UInt32 countRight = 0; +// Float32 decibelsLeft = STK_DBMIN; +// Float32 peakValueLeft = STK_DBMIN; +// Float64 totalValueLeft = 0; +// Float32 previousFilteredValueOfSampleAmplitudeLeft = 0; +// Float32 decibelsRight = STK_DBMIN; +// Float32 peakValueRight = STK_DBMIN; +// Float64 totalValueRight = 0; +// Float32 previousFilteredValueOfSampleAmplitudeRight = 0; +// +// if (bytesPerFrame / channelsPerFrame == 2) +// { +// for (int i = 0; i < frameCount * channelsPerFrame; i += channelsPerFrame) +// { +// Float32 absoluteValueOfSampleAmplitudeLeft = abs(samples16[i]); +// Float32 absoluteValueOfSampleAmplitudeRight = abs(samples16[i + 1]); +// +// CALCULATE_METER(Left); +// CALCULATE_METER(Right); +// } +// } +// else if (bytesPerFrame / channelsPerFrame == 4) +// { +// for (int i = 0; i < frameCount * channelsPerFrame; i += channelsPerFrame) +// { +// Float32 absoluteValueOfSampleAmplitudeLeft = abs(samples32[i]) / 32768.0; +// Float32 absoluteValueOfSampleAmplitudeRight = abs(samples32[i + 1]) / 32768.0; +// +// CALCULATE_METER(Left); +// CALCULATE_METER(Right); +// } +// } +// else +// { +// return; +// } +// +// peakPowerDb[0] = MIN(MAX(decibelsLeft, -60), 0); +// peakPowerDb[1] = MIN(MAX(decibelsRight, -60), 0); +// +// if (countLeft > 0) +// { +// averagePowerDb[0] = MIN(MAX(totalValueLeft / frameCount, -60), 0); +// } +// +// if (countRight != 0) +// { +// averagePowerDb[1] = MIN(MAX(totalValueRight / frameCount, -60), 0); +// } }]; } }