void initializeMenuFlames(boolean includeTitle, color *colors[COLS][(ROWS + MENU_FLAME_ROW_PADDING)], signed short colorSources[MENU_FLAME_COLOR_SOURCE_COUNT][4], signed short flames[COLS][(ROWS + MENU_FLAME_ROW_PADDING)][3], unsigned char mask[COLS][ROWS]) { short i, j, k, colorSourceCount; const char title[MENU_TITLE_HEIGHT][MENU_TITLE_WIDTH+1] = { "######## ######## ###### ####### #### ### #########", " ## ### ## ### ## ### ## ## ## # ## #", " ## ## ## ## ## ### ## # ## # ## #", " ## ## ## ## # # ## # # ## # ## ", " ## ## ## ## ## ## ## ## ## # ## # ", " ## ## ## ## ## ### ## ## ## # ## # ", " ###### ## ### ## #### ## ## ## # ####### ", " ## ## ## ## ## #### ## ## ## # ## # ", " ## ## ## ## ## ### ## ## ##### ## # ## # ", " ## ## ## ## ### ## ## ### ## ## # ## ", " ## ## ## ## ## # # ## ## ## # ## ", " ## ## ## ## ### ## ### ## ### # ## #", " ## ## ## ## ### ## ### ### ### # ## #", "######## #### ### ###### ##### ###### #########", " ## ", " ########## ", " ## ", " ## ", " #### ", }; for (i=0; i<COLS; i++) { for (j=0; j<ROWS; j++) { mask[i][j] = 0; } } for (i=0; i<COLS; i++) { for (j=0; j<(ROWS + MENU_FLAME_ROW_PADDING); j++) { colors[i][j] = NULL; for (k=0; k<3; k++) { flames[i][j][k] = 0; } } } // Seed source color random components. for (i=0; i<MENU_FLAME_COLOR_SOURCE_COUNT; i++) { for (k=0; k<4; k++) { colorSources[i][k] = rand_range(0, 1000); } } // Put some flame source along the bottom row. colorSourceCount = 0; for (i=0; i<COLS; i++) { colors[i][(ROWS + MENU_FLAME_ROW_PADDING)-1] = &flameSourceColor; colorSourceCount++; } if (includeTitle) { // Wreathe the title in flames, and mask it in black. for (i=0; i<MENU_TITLE_WIDTH; i++) { for (j=0; j<MENU_TITLE_HEIGHT; j++) { if (title[j][i] != ' ') { colors[(COLS - MENU_TITLE_WIDTH)/2 + i + MENU_TITLE_OFFSET_X][(ROWS - MENU_TITLE_HEIGHT)/2 + j + MENU_TITLE_OFFSET_Y] = &flameTitleColor; colorSourceCount++; mask[(COLS - MENU_TITLE_WIDTH)/2 + i + MENU_TITLE_OFFSET_X][(ROWS - MENU_TITLE_HEIGHT)/2 + j + MENU_TITLE_OFFSET_Y] = 100; } } } // Anti-alias the mask. antiAlias(mask); } #ifdef BROGUE_ASSERTS assert(colorSourceCount <= MENU_FLAME_COLOR_SOURCE_COUNT); #endif // Simulate the background flames for a while for (i=0; i<100; i++) { updateMenuFlames(colors, colorSources, flames); } }
void Dictionary::createDictionary(std::string outputDir) { //open output file std::fstream outputFile; outputFile.open(outputDir+"W.txt", std::ios::out); if (!outputFile.is_open()) { std::cout << "Text file open error!"; return; } //prepare to read file AudioFormatManager formatManager; formatManager.registerBasicFormats(); kiss_fft_cfg fwd= kiss_fft_alloc(FFT_SIZE,0,NULL,NULL); // HARD CODING HERE. REQUIRES MODIFICATION float fs = 44100; int nChannels = 2; numSamplesToRead = round(fs*SECS_PER_BLOCK); numSamplesPerBlock = numSamplesToRead/DOWNSAMPLE_RATE; AudioSampleBuffer buffer(nChannels, numSamplesToRead); float* audioBuffer = new float[numSamplesToRead]; for (int track = 21; track<=108; track++) { // ANY BETTER WAYS TO DEAL WITH FILENAMES?? std::string strFileDir = sampleFileFolder + "MAPS_ISOL_NO_M_S0_M"+std::to_string(track)+"_AkPnBcht.wav"; File audioFileS0(strFileDir); AudioFormatReader* reader; if (audioFileS0.exists()) { reader = formatManager.createReaderFor(audioFileS0); } else { strFileDir = sampleFileFolder + "MAPS_ISOL_NO_M_S1_M"+std::to_string(track)+"_AkPnBcht.wav"; File audioFileS1(strFileDir); reader = formatManager.createReaderFor(audioFileS1); } reader->read(&buffer, 0, numSamplesToRead, fs, true, true); float* leftBuffer = buffer.getSampleData(0); float* rightBuffer = buffer.getSampleData(1); for (int i=0; i<numSamplesToRead; i++) { audioBuffer[i] = (leftBuffer[i]+rightBuffer[i])/2; } antiAlias(audioBuffer, numSamplesToRead); for (int i=0; i<numSamplesPerBlock; i++) { audio[i].real( audioBuffer[i*DOWNSAMPLE_RATE]*hammWin(i, numSamplesPerBlock) ); audio[i].imag(0); } for (int i = numSamplesPerBlock; i<FFT_SIZE; i++) { audio[i].real(0); audio[i].imag(0); } kiss_fft(fwd, (kiss_fft_cpx*) audio, (kiss_fft_cpx*)spectrum); for (int i = 0; i<FFT_SIZE/2; i++) { W[i][track-21] = abs(spectrum[i]); //HARD CODING HERE! } delete reader; } delete [] audioBuffer; for(int i = 0; i< FFT_SIZE/2; i++){ for (int j = 0; j<N_NOTES; j++) { // fwrite(&W[i][j], sizeof(float), 1, file); outputFile << W[i][j] << "\t"; } outputFile<<std::endl; } outputFile.close(); }