int main(int argc, char *argv[]) { // Open the network Network yarp; Port p; p.open("/sender"); // Get a portaudio read device. Property conf; conf.put("device","portaudio"); conf.put("read", ""); conf.put("samples", 44100*rec_seconds); //conf.put("rate", 16000); PolyDriver poly(conf); IAudioGrabberSound *get; // Make sure we can read sound poly.view(get); if (get==NULL) { printf("cannot open interface\n"); return 1; } //Grab and send Sound s; while (true) { double t1=yarp::os::Time::now(); get->getSound(s); double t2=yarp::os::Time::now(); printf("acquired %f seconds\n", t2-t1); p.write(s); } return 0; }
int main(int argc, char *argv[]) { // Open the network Network yarp; Port p; p.open("/sender"); // Get a portaudio read device. Property conf; conf.put("device","portaudio"); conf.put("read", ""); //conf.put("samples", 4096); //conf.put("rate", 16000); PolyDriver poly(conf); IAudioGrabberSound *get; // Make sure we can read sound poly.view(get); if (get==NULL) { printf("cannot open interface\n"); return 1; } //Grab and send Sound s; while (true) { get->getSound(s); p.write(s); } return 0; }
bool DevicePipe::updateService() { IFrameGrabberImage *imgSource; IAudioGrabberSound *sndSource; IAudioVisualGrabber *imgSndSource; IAudioVisualStream *sourceType; IAudioRender *sndSink; IFrameWriterImage *imgSink; IFrameWriterAudioVisual *imgSndSink; IAudioVisualStream *sinkType; source.view(imgSource); source.view(sndSource); source.view(imgSndSource); source.view(sourceType); sink.view(imgSink); sink.view(sndSink); sink.view(imgSndSink); sink.view(sinkType); if (sourceType!=NULL) { if (!(sourceType->hasAudio()&&sourceType->hasVideo())) { imgSndSource = NULL; } } if (sinkType!=NULL) { if (!(sinkType->hasAudio()&&sinkType->hasVideo())) { imgSndSink = NULL; } } if (imgSndSource!=NULL&&imgSndSink!=NULL) { ImageOf<PixelRgb> tmp; Sound tmpSound; imgSndSource->getAudioVisual(tmp,tmpSound); imgSndSink->putAudioVisual(tmp,tmpSound); printf("piped %dx%d image, %dx%d sound\n", tmp.width(), tmp.height(), tmpSound.getSamples(), tmpSound.getChannels()); } else if (imgSource!=NULL&&imgSink!=NULL) { ImageOf<PixelRgb> tmp; imgSource->getImage(tmp); imgSink->putImage(tmp); printf("piped %dx%d image\n", tmp.width(), tmp.height()); } else if (sndSource!=NULL&&sndSink!=NULL) { Sound tmp; sndSource->getSound(tmp); sndSink->renderSound(tmp); printf("piped %dx%d sound\n", tmp.getSamples(), tmp.getChannels()); } else { printf("Don't know how to pipe between these devices.\n"); printf("Piping is very limited at the moment.\n"); printf("You're probably better off writing some short custom code.\n"); return false; } return true; }
int main(int argc, char *argv[]) { // Open the network Network yarp; BufferedPort<Sound> pReceiver; pReceiver.open("/receiver"); //Network::connect("/sender", "/receiver"); Port pSender; pSender.open("/sender"); // Get an audio write device. Property conf; conf.put("device","portaudio"); conf.put("samples", "4096"); conf.put("write", "1"); PolyDriver polyRender(conf); if(!polyRender.isValid()) { printf("cannot open interface \n"); return 1; } IAudioRender *put; // Get a portaudio read device. //Property conf; conf.put("device","portaudio"); conf.put("read", ""); //conf.put("samples", 4096); //conf.put("rate", 16000); PolyDriver polyGrabber(conf); if(!polyRender.isValid()) { printf("cannot open interface \n"); return 1; } IAudioGrabberSound *get; /* // Make sure we can write sound polyRender.view(put); if (put==NULL) { printf("cannot open interface\n"); return 1; } //Receive and render Sound *s; while (true) { s = p.read(false); if (s!=NULL) put->renderSound(*s); } return 0; */ /* // Make sure we can read sound polyGrabber.view(get); if (get==NULL) { printf("cannot open interface\n"); return 1; } //Grab and send Sound s; while (true) { get->getSound(s); p.write(s); } return 0; */ // echo from microphone to headphones, superimposing an annoying tone double vv=0; while(true){ Sound s; get->getSound(s); for (int i=0; i<s.getSamples(); i++) { double now = Time::now(); static double first = now; now -= first; if ((long int) (now*2) % 2 == 0) { vv += 0.08; } else { vv += 0.04; } double dv = 500*sin(vv); for (int j=0; j<s.getChannels(); j++) { int v =s.get(i,j); s.set((int)(v+dv+0.5),i,j); } } put->renderSound(s); } Network::fini(); }
int main(int argc, char *argv[]) { // initialization // Open the network Network yarp; //BufferedPort<Sound> p; Port p; p.open("/sender"); // Get a portaudio read device. Property conf; conf.put("device","portaudio"); conf.put("read", ""); // conf.put("samples", rate * rec_seconds); conf.put("samples", fixedNSample); conf.put("rate", rate); PolyDriver poly(conf); IAudioGrabberSound *get; // Make sure we can read sound poly.view(get); if (get==NULL) { printf("cannot open interface"); return 1; } else{ printf("correctly opened the interface rate: %d, number of samples: %d, number of channels %d \n",rate, rate*rec_seconds, 2); } //Grab and send Sound s; //Bottle b; //b.addString("hello"); //unsigned char* dataSound; //short* dataAnalysis; //int v1, v2; //int i = 0, j = 0; //NetInt16 v; // i = sample amd j = channels; get->startRecording(); //this is optional, the first get->getsound() will do this anyway. Stamp ts; while (true) { double t1=yarp::os::Time::now(); ts.update(); //s = p.prepare(); get->getSound(s); //v1 = s.get(i,j); //v = (NetInt16) v1; //v2 = s.get(i+1,j+1); //dataAnalysis = (short*) dataSound; p.setEnvelope(ts); p.write(s); double t2=yarp::os::Time::now(); printf("acquired %f seconds \n", t2-t1); } get->stopRecording(); //stops recording. return 0; }