Пример #1
0
 void processAudio(AudioBuffer &buffer)
 {
     // Reasonably assume we will not have more than 32 channels
     float*  ins[32];
     float*  outs[32];
     int     n = buffer.getChannels();
     
     if ( (fDSP.getNumInputs() < 32) && (fDSP.getNumOutputs() < 32) ) {
         
         // create the table of input channels
         for(int ch=0; ch<fDSP.getNumInputs(); ++ch) {
             ins[ch] = buffer.getSamples(ch%n);
         }
         
         // create the table of output channels
         for(int ch=0; ch<fDSP.getNumOutputs(); ++ch) {
             outs[ch] = buffer.getSamples(ch%n);
         }
         
         // read OWL parameters and updates corresponding Faust Widgets zones
         fUI.update(); 
         
         // Process the audio samples
         fDSP.compute(buffer.getSize(), ins, outs);
     }
 }
Пример #2
0
int main(int argc, char *argv[]) {
    yarp::os::Network yarp;

    // see if user has supplied audio device
    Property p;
    if (argc>1) {
        p.fromCommand(argc,argv);
    }

    // otherwise default device is "portaudio"
    if (!p.check("device")) {
        p.put("device","portaudio");
        p.put("write",1);
        p.put("delay",1);
    }

    // start the echo service running
    Echo echo;
    echo.open(p);

    // process the keyboard
    bool muted = false;
    bool saving = false;
    bool help = false;
    ConstString fname = "audio_%06d.wav";
    int ct = 0;
    bool done = false;
    while (!done) {
        if (help) {
            printf("  Press return to mute/unmute\n");
            printf("  Type \"s\" to set start/stop saving audio in memory\n");
            printf("  Type \"write filename.wav\" to write saved audio to a file\n");
            printf("  Type \"buf NUMBER\" to set buffering delay (default is 0)\n");
            printf("  Type \"write\" or \"w\" to write saved audio with same/default name\n");
            printf("  Type \"q\" to quit\n");
            printf("  Type \"help\" to see this list again\n");
            help = false;
        } else {
            printf("Type \"help\" for usage\n");
        }
        
        ConstString keys = Network::readString();
        Bottle b(keys);
        ConstString cmd = b.get(0).asString();
        if (b.size()==0) {
            muted = !muted;
            echo.mute(muted);
            printf("%s\n", muted?"Muted":"Audible again");
        } else if (cmd=="help") {
            help = true;
        } else if (cmd=="s") {
            saving = !saving;
            echo.save(saving);
            printf("%s\n", saving?"Saving":"Stopped saving");
            if (saving) {
                printf("  Type \"s\" again to stop saving\n");
            }
        } else if (cmd=="write"||cmd=="w") {
            if (b.size()==2) {
                fname = b.get(1).asString();
            }
            char buf[2560];
            sprintf(buf,fname.c_str(),ct);
            echo.saveFile(buf);
            ct++;
        } else if (cmd=="q"||cmd=="quit") {
            done = true;
        } else if (cmd=="buf"||cmd=="b") {
            padding = b.get(1).asInt();
            printf("Buffering at %d\n", padding);
        }
    }

    echo.close();

    return 0;
}
int main(int argc, char *argv[]) {
    yarp::os::Network yarp;
    
    
    //pre-setup some memory mapping stuff right away
    printf("\n\nInitializing memory mapped files in the /tmp directory to hold audio data\n\n");
    
    //build a vector of short zeros
    short *initialAudioArray;
    initialAudioArray = (short *)malloc(kMappedFileSize_samples*sizeof(short));
    for (int i=0;i<kMappedFileSize_samples;i++){
    	initialAudioArray[i]=(short)0;
    }
    
    //write the zeros to a file to initialize it
    FILE *fid=fopen("/tmp/AudioDataDump.dat","w");
    fwrite(initialAudioArray,sizeof(short),kMappedFileSize_samples,fid);
    fclose(fid);
    
 	//memory map the file
 	//these were declared globally so that we can get to them from the callback
    int mappedFileID=open("/tmp/AudioDataDump.dat",O_RDWR);
   	mappedAudioData=(short *)mmap(0, kMappedFileSize_bytes, PROT_READ | PROT_WRITE, MAP_SHARED , mappedFileID, 0);
	close(mappedFileID);  //the double colon forces to call the close() from outside of this namespace (because it's obscured by the method close() 

	//make a "file" that holds a single int to keep index of frames written and initialize with a zero
    FILE *fid2=fopen("/tmp/lastFrameIndex.dat","w");
    int dummyInt=0;
    fwrite(&dummyInt,sizeof(int),1,fid2);
    fclose(fid2);
    
    //make a "file" that holds a single int to keep index of the last sample written and initialize with a zero
    FILE *fid3=fopen("/tmp/lastSampleIndex.dat","w");
    int dummyInt2=0;
    fwrite(&dummyInt2,sizeof(int),1,fid3);
    fclose(fid3);
    
	//memory map the index file
	int lastFrameFileID = open("/tmp/lastFrameIndex.dat",O_RDWR);
   	lastFrameIndex=(int *)mmap(0, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED , lastFrameFileID, 0);
	close(lastFrameFileID);

	//memory map the last sample index file
	int lastSampleFileID = open("/tmp/lastSampleIndex.dat",O_RDWR);
   	lastSampleIndex=(int *)mmap(0, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED , lastSampleFileID, 0);
	close(lastSampleFileID);


	//****now you are ready to write frames into this memory****//
    
     

    // see if user has supplied audio device
    Property p;
    if (argc>1) {
        p.fromCommand(argc,argv);
    }

    // otherwise default device is "portaudio"
    if (!p.check("device")) {
        p.put("device","portaudio");
        p.put("write",1);
        p.put("delay",1);
    }

    // start the echo service running
    Echo echo;
    echo.open(p);

    // process the keyboard
    bool muted = false;
    bool saving = false;
    bool help = false;
    ConstString fname = "audio_%06d.wav";
    int ct = 0;
    bool done = false;
    while (!done) {
        if (help) {
            printf("  Press return to mute/unmute\n");
            printf("  Type \"s\" to set start/stop saving audio in memory\n");
            printf("  Type \"write filename.wav\" to write saved audio to a file\n");
            printf("  Type \"buf NUMBER\" to set buffering delay (default is 0)\n");
            printf("  Type \"write\" or \"w\" to write saved audio with same/default name\n");
            printf("  Type \"q\" to quit\n");
            printf("  Type \"help\" to see this list again\n");
            help = false;
        } else {
            printf("Type \"help\" for usage\n");
        }
        
        ConstString keys = Network::readString();
        Bottle b(keys);
        ConstString cmd = b.get(0).asString();
        if (b.size()==0) {
            muted = !muted;
            echo.mute(muted);
            printf("%s\n", muted?"Muted":"Audible again");
        } else if (cmd=="help") {
            help = true;
        } else if (cmd=="s") {

            saving = !saving;
            echo.save(saving);
            printf("%s\n", saving?"Saving":"Stopped saving");
            if (saving) {
                printf("  Type \"s\" again to stop saving\n");
            }
        } else if (cmd=="write"||cmd=="w") {
            if (b.size()==2) {
                fname = b.get(1).asString();
            }
            char buf[2560];
            sprintf(buf,fname.c_str(),ct);
            echo.saveFile(buf);
            ct++;
        } else if (cmd=="q"||cmd=="quit") {
            done = true;
        } else if (cmd=="buf"||cmd=="b") {
            padding = b.get(1).asInt();
            printf("Buffering at %d\n", padding);
        }
    }

    echo.close();

    return 0;
}
Пример #4
0
 EchoPatch() : fUI(patches.getCurrentPatchProcessor())
 {
     fDSP.init(int(getSampleRate()));		// Init Faust code with the OWL sampling rate
     fDSP.buildUserInterface(&fUI);			// Maps owl parameters and faust widgets 
 }