void AudioSoundIo::stopProcessing() { soundio_outstream_destroy(m_outstream); m_outstream = NULL; delete[] m_outBuf; m_outBuf = NULL; }
//============================================================================== // MAIN //============================================================================== int main(int argc,char **argv) { pthread_t test; printf("SFemtoZ!\n"); int c; while ((c = getopt (argc, argv, "t:v")) != -1) switch (c) { case 't': if(pthread_create(&test,NULL,thread_test,optarg)) { printf("error thread test\n"); } break; case 'v': verbose=TRUE; break; } char sfzfile[50]; strcpy(sfzfile,USBPATH); strcat(sfzfile,argv[optind]); printf("Load SFZ: %s\n",sfzfile); loadsfz(sfzfile); //printsfz(); loadsounds(); int fd; if(( fd = serialOpen("/dev/ttyAMA0",57600))<0) { printf("serialOpen ERROR:\n",strerror(errno)); return 1; } if(configuresoundio()!=0) return 1; signal(SIGINT,exit_cli); signal(SIGTERM,exit_cli); run = TRUE; while(run) { if(serialDataAvail(fd)>2) { int type=serialGetchar(fd); while(type!=0x99 && type!= 0xB9) type=serialGetchar(fd); int note=serialGetchar(fd); int vel=serialGetchar(fd); //printf("MIDI%i(%i,%i)\n",type,note,vel); if(type==0x99) noteOn(note,vel); else midiCC(note,vel); } // soundio_wait_events(soundio); } //FINISH pthread_cancel(test); soundio_outstream_destroy(outstream); soundio_device_unref(device); soundio_destroy(soundio); serialClose(fd); freesounds(); freesfz(); return 0; }
int main(int argc, char **argv) { char *exe = argv[0]; enum SoundIoBackend backend = SoundIoBackendNone; char *device_id = NULL; bool raw = false; char *stream_name = NULL; double latency = 0.0; int sample_rate = 0; for (int i = 1; i < argc; i += 1) { char *arg = argv[i]; if (arg[0] == '-' && arg[1] == '-') { if (strcmp(arg, "--raw") == 0) { raw = true; } else { i += 1; if (i >= argc) { return usage(exe); } else if (strcmp(arg, "--backend") == 0) { if (strcmp(argv[i], "dummy") == 0) { backend = SoundIoBackendDummy; } else if (strcmp(argv[i], "alsa") == 0) { backend = SoundIoBackendAlsa; } else if (strcmp(argv[i], "pulseaudio") == 0) { backend = SoundIoBackendPulseAudio; } else if (strcmp(argv[i], "jack") == 0) { backend = SoundIoBackendJack; } else if (strcmp(argv[i], "coreaudio") == 0) { backend = SoundIoBackendCoreAudio; } else if (strcmp(argv[i], "wasapi") == 0) { backend = SoundIoBackendWasapi; } else { fprintf(stderr, "Invalid backend: %s\n", argv[i]); return 1; } } else if (strcmp(arg, "--device") == 0) { device_id = argv[i]; } else if (strcmp(arg, "--name") == 0) { stream_name = argv[i]; } else if (strcmp(arg, "--latency") == 0) { latency = atof(argv[i]); } else if (strcmp(arg, "--sample-rate") == 0) { sample_rate = atoi(argv[i]); } else { return usage(exe); } } } else { return usage(exe); } } struct SoundIo *soundio = soundio_create(); if (!soundio) { fprintf(stderr, "out of memory\n"); return 1; } int err = (backend == SoundIoBackendNone) ? soundio_connect(soundio) : soundio_connect_backend(soundio, backend); if (err) { fprintf(stderr, "Unable to connect to backend: %s\n", soundio_strerror(err)); return 1; } fprintf(stderr, "Backend: %s\n", soundio_backend_name(soundio->current_backend)); soundio_flush_events(soundio); int selected_device_index = -1; if (device_id) { int device_count = soundio_output_device_count(soundio); for (int i = 0; i < device_count; i += 1) { struct SoundIoDevice *device = soundio_get_output_device(soundio, i); bool select_this_one = strcmp(device->id, device_id) == 0 && device->is_raw == raw; soundio_device_unref(device); if (select_this_one) { selected_device_index = i; break; } } } else { selected_device_index = soundio_default_output_device_index(soundio); } if (selected_device_index < 0) { fprintf(stderr, "Output device not found\n"); return 1; } struct SoundIoDevice *device = soundio_get_output_device(soundio, selected_device_index); if (!device) { fprintf(stderr, "out of memory\n"); return 1; } fprintf(stderr, "Output device: %s\n", device->name); if (device->probe_error) { fprintf(stderr, "Cannot probe device: %s\n", soundio_strerror(device->probe_error)); return 1; } struct SoundIoOutStream *outstream = soundio_outstream_create(device); if (!outstream) { fprintf(stderr, "out of memory\n"); return 1; } outstream->write_callback = write_callback; outstream->underflow_callback = underflow_callback; outstream->name = stream_name; outstream->software_latency = latency; outstream->sample_rate = sample_rate; if (soundio_device_supports_format(device, SoundIoFormatFloat32NE)) { outstream->format = SoundIoFormatFloat32NE; write_sample = write_sample_float32ne; } else if (soundio_device_supports_format(device, SoundIoFormatFloat64NE)) { outstream->format = SoundIoFormatFloat64NE; write_sample = write_sample_float64ne; } else if (soundio_device_supports_format(device, SoundIoFormatS32NE)) { outstream->format = SoundIoFormatS32NE; write_sample = write_sample_s32ne; } else if (soundio_device_supports_format(device, SoundIoFormatS16NE)) { outstream->format = SoundIoFormatS16NE; write_sample = write_sample_s16ne; } else { fprintf(stderr, "No suitable device format available.\n"); return 1; } if ((err = soundio_outstream_open(outstream))) { fprintf(stderr, "unable to open device: %s", soundio_strerror(err)); return 1; } fprintf(stderr, "Software latency: %f\n", outstream->software_latency); fprintf(stderr, "'p\\n' - pause\n" "'u\\n' - unpause\n" "'P\\n' - pause from within callback\n" "'c\\n' - clear buffer\n" "'q\\n' - quit\n"); if (outstream->layout_error) fprintf(stderr, "unable to set channel layout: %s\n", soundio_strerror(outstream->layout_error)); if ((err = soundio_outstream_start(outstream))) { fprintf(stderr, "unable to start device: %s\n", soundio_strerror(err)); return 1; } for (;;) { soundio_flush_events(soundio); int c = getc(stdin); if (c == 'p') { fprintf(stderr, "pausing result: %s\n", soundio_strerror(soundio_outstream_pause(outstream, true))); } else if (c == 'P') { want_pause = true; } else if (c == 'u') { want_pause = false; fprintf(stderr, "unpausing result: %s\n", soundio_strerror(soundio_outstream_pause(outstream, false))); } else if (c == 'c') { fprintf(stderr, "clear buffer result: %s\n", soundio_strerror(soundio_outstream_clear_buffer(outstream))); } else if (c == 'q') { break; } else if (c == '\r' || c == '\n') { // ignore } else { fprintf(stderr, "Unrecognized command: %c\n", c); } } soundio_outstream_destroy(outstream); soundio_device_unref(device); soundio_destroy(soundio); return 0; }