2017-03-19 91 views
1

我試圖瞭解Superpowered SDK,但對於Android和C++以及音頻信號都是新的。我在這裏有頻域範例: https://github.com/superpoweredSDK/Low-Latency-Android-Audio-iOS-Audio-Engine/tree/master/Examples_Android/FrequencyDomainAndroid SuperPowered SDK音頻 - 頻域範例 - memset頻率操作

在我的Nexus 5X上運行。在FrequencyDomain.cpp文件:

static SuperpoweredFrequencyDomain *frequencyDomain; 
static float *magnitudeLeft, *magnitudeRight, *phaseLeft, *phaseRight, *fifoOutput, *inputBufferFloat; 
static int fifoOutputFirstSample, fifoOutputLastSample, stepSize, fifoCapacity; 

#define FFT_LOG_SIZE 11 // 2^11 = 2048 

static bool audioProcessing(void * __unused clientdata, short int *audioInputOutput, int numberOfSamples, int __unused samplerate) { 
SuperpoweredShortIntToFloat(audioInputOutput, inputBufferFloat, (unsigned int)numberOfSamples); // Converting the 16-bit integer samples to 32-bit floating point. 
frequencyDomain->addInput(inputBufferFloat, numberOfSamples); // Input goes to the frequency domain. 

// In the frequency domain we are working with 1024 magnitudes and phases for every channel (left, right), if the fft size is 2048. 
while (frequencyDomain->timeDomainToFrequencyDomain(magnitudeLeft, magnitudeRight, phaseLeft, phaseRight)) { 
    // You can work with frequency domain data from this point. 


// This is just a quick example: we remove the magnitude of the first 20 bins, meaning total bass cut between 0-430 Hz. 
    memset(magnitudeLeft, 0, 80); 
    memset(magnitudeRight, 0, 80); 

我理解的前20個箱是如何從0-430赫茲的位置: How do I obtain the frequencies of each value in an FFT?

,但我不明白的80 memset的價值...是4 * 20,它是4個字節的浮動* 20個分檔? magnitudeLeft是否保存所有頻率的數據?那麼我將如何刪除,例如,從中間或最後的10個頻率的箱子?謝謝!

回答

3

magnitudeLeft和magnitudeRight中的每個值都是一個浮點數,它是32位,4個字節。

memset需要多個字節參數,所以20個bin * 4個字節= 80個字節。 memset用這種方法清除前20個bin。

magnitudeLeft和magnitudeRight都代表1024個浮點數的全頻範圍。它們的大小始終是FFT大小除以2,因此在示例中爲2048/2。

從中間和頂部卸下看起來像:

memset的(& magnitudeLeft [index_of_first_bin_to_remove],0,number_of_bins *的sizeof(浮動));

請注意,第一個參數不會與sizeof(float)相乘,因爲編譯器知道magnitudeLeft是一個float,所以它會自動輸入正確的地址。