// entry point int main(int argc, char* argv[]) { // the vector to store the input std::vector<std::string> input = {"1", "2", "3", "4", "5", "6"}; // apply the reverse function to the input vector reverseBlock(&input, 4); // loop through the vector and print the result for (unsigned int i = 0; i < input.size();i++) { // print the element std::cout << input.at(i) << " "; } system("PAUSE"); return 0; }
int main() { // Create and init output file "out.aif" #ifdef __APPLE__ char infileName[]="voice.aif"; #else char infileName[]="../../voice.aif"; #endif char oufileName[]="out.aif"; long numChannels = 1; // DIRAC LE allows mono only, PRO can do stereo (and more) as well float sr = mAiffGetSampleRate(infileName); // get sample rate from our input file if (sr <= 0.) { printf("ERROR: File not found\n"); exit(-1); } // We stuff all our programs' state variables that we need to access in order to read from the file in a struct // You will normally pass your instance pointer "this" as userData, but since this is not a class we cannot do this here userDataStruct state; state.sNumChannels = numChannels; state.sReadPosition = 0; state.sInFileName = new char[strlen(infileName)+1]; memmove(state.sInFileName, infileName, (strlen(infileName)+1)*sizeof(char)); // First we set up DIRAC to process numChannels of audio void *dirac = DiracCreate(kDiracLambda1, kDiracQualityBest, numChannels, sr, &myReadData, (void*)&state); if (!dirac) { printf("!! ERROR !!\n\n\tCould not create DIRAC instance\n\tCheck number of channels and sample rate!\n"); exit(-1); } // Initialize our output file mAiffInitFile(oufileName, sr /* sample rate */, 16 /* bits */, numChannels); // these are arbitrary regions in the file */ #define NUM_PARTS 17 SoundFileRegion regions[NUM_PARTS] = { {0, 4257, 1.0, 1.0}, {4257, 10741, 1.0, 1.0}, {14999, -20471, 1.0, 1.5}, /* negative length means reverse playback direction */ {35470, -12161, 1.0, 1.0}, {47631, 9323, 2.0, 1.0}, {56954, 18647, 1.0, 1.5}, {75601, 9121, 2.0, 1.0}, {84722, 22903, 1.0, 1.0}, {107625, 19863, 1.0, 1.0}, {107625, 19863, 1.0, pow(2., 1./12.)}, /* repeat and change pitch */ {107625, 19863, 1.0, pow(2., 2./12.)}, /* repeat and change pitch */ {127488, 39117, 1.0, .5}, {166605, -11553, 2.0, 1.0}, {178158, 20269, 1.0, 1.0}, {198427, 17430, 2.0, 1.0}, {215857, 23309, 1.0, 1.5}, {239166, 35266, 1.0, 1.0} }; for (int i=0; i<NUM_PARTS; i++) { printf("Processing region \t%d: {start: %d, length: %d} \twith time stretch %1.2f and pitch shift %1.2f\n", i, regions[i].sStartFrameInFile, regions[i].sNumFrames, (float)regions[i].sTimeStretchFactor, (float)regions[i].sPitchShiftFactor); /* determine the region length (output) in frames by multiplying input region length with time stretch factor */ long numOutFrames = regions[i].sTimeStretchFactor * abs(regions[i].sNumFrames); /* set Dirac properties according to desired settings */ DiracSetProperty(kDiracPropertyTimeFactor, regions[i].sTimeStretchFactor, dirac); DiracSetProperty(kDiracPropertyPitchFactor, regions[i].sPitchShiftFactor, dirac); DiracSetProperty(kDiracPropertyFormantFactor, 1./regions[i].sPitchShiftFactor, dirac); /* optional */ /* allocate buffer to hold output frames */ float **audio = mAiffAllocateAudioBuffer(numChannels, numOutFrames); /* set read position to begin of region */ state.sReadPosition = regions[i].sStartFrameInFile; /* process region */ DiracProcess(audio, numOutFrames, dirac); /* fade region to prevent glitches */ if (regions[i].sNumFrames < 0) reverseBlock(audio, numChannels, numOutFrames); fadeBlock(audio, numChannels, numOutFrames); /* write region to file */ mAiffWriteData(oufileName, audio, numOutFrames, numChannels); /* get rid of audio buffer */ mAiffDeallocateAudioBuffer(audio, numChannels); /* reset Dirac instance for next region */ DiracReset(false, dirac); } // destroy DIRAC instance DiracDestroy( dirac ); // free our file name delete[] state.sInFileName; // Done! printf("\nDone!\n"); putchar(7); /* Open audio file via system call */ #ifdef __APPLE__ system("open out.aif"); #elif defined _WIN32 system("start out.aif"); #elif defined __unix__ system("xdg-open out.aif"); #endif return 0; }