int main (int argc, char *argv[]) { /* * Use /dev/dsp as the default device because the system administrator * may select the device using the {!xlink ossctl} program or some other * methods */ char *name_out = "/dev/dsp"; /* * It's recommended to provide some method for selecting some other * device than the default. We use command line argument but in some cases * an environment variable or some configuration file setting may be better. */ if (argc > 1) name_out = argv[1]; /* * It's mandatory to use O_WRONLY in programs that do only playback. Other * modes may cause increased resource (memory) usage in the driver. It may * also prevent other applications from using the same device for * recording at the same time. */ fd_out = open_audio_device (name_out, O_WRONLY); while (1) write_sinewave (); exit (0); }
void main() { prepareudpsender(); fp = fopen("oss_data1.txt", "w"); if(fp == NULL){ puts("Cannot open test file."); fclose(fp); exit(-1); } char *name_in = "/dev/dsp"; fd_in = open_audio_device (name_in, O_RDONLY); int index; for(index = 0; index < 400; index++){ process_input(); } printf("\n"); fclose(fp); closeudpsender(); exit (0); }
gint process_thread_command(struct con_win *cwin) { gint ret = 0; enum thread_cmd cmd = 0; g_mutex_lock(cwin->cstate->c_mutex); cmd = cwin->cstate->cmd; g_mutex_unlock(cwin->cstate->c_mutex); /* Stop playing */ if (cmd == CMD_PLAYBACK_STOP) ret = CMD_PLAYBACK_STOP; /* Pause playing */ else if (cmd == CMD_PLAYBACK_PAUSE) { /* Wait for resume command to come through */ ao_close(cwin->clibao->ao_dev); g_mutex_lock(cwin->cstate->c_mutex); while (cwin->cstate->cmd == CMD_PLAYBACK_PAUSE) g_cond_wait(cwin->cstate->c_cond, cwin->cstate->c_mutex); /* A stop command may have been given while waiting for resume */ if (cwin->cstate->cmd == CMD_PLAYBACK_STOP) ret = CMD_PLAYBACK_STOP; /* Received a resume command */ else if (cwin->cstate->cmd == CMD_PLAYBACK_RESUME) ret = CMD_PLAYBACK_RESUME; g_mutex_unlock(cwin->cstate->c_mutex); if (open_audio_device(0, 0, TRUE, cwin) == -1) { g_warning("Unable to resume"); } } /* Seek to a new position */ else if (cmd == CMD_PLAYBACK_SEEK) ret = CMD_PLAYBACK_SEEK; return ret; }
std::shared_ptr<cainteoir::audio> cainteoir::open_audio_device( const char *device, const rdf::graph &aDocMetadata, const rdf::uri &aDocument, const rdf::graph &aVoiceMetadata, const rdf::uri &aVoice) { rql::results data = rql::select(aVoiceMetadata, rql::subject == aVoice); int channels = rql::select_value<int>(data, rql::predicate == rdf::tts("channels")); int frequency = rql::select_value<int>(data, rql::predicate == rdf::tts("frequency")); const rdf::uri &format = rql::object(rql::select(data, rql::predicate == rdf::tts("audio-format")).front()); return open_audio_device(device, aDocMetadata, aDocument, format, channels, frequency); }
static int unsuspend(struct userdata *u) { pa_assert(u); pa_assert(u->fd < 0); pa_log_info("Resuming..."); if (open_audio_device(u, u->sink ? &u->sink->sample_spec : &u->source->sample_spec) < 0) return -1; build_pollfd(u); pa_log_info("Device resumed."); return 0; }
int pa__init(pa_module *m) { struct userdata *u = NULL; bool record = true, playback = true; pa_sample_spec ss; pa_channel_map map; pa_modargs *ma = NULL; uint32_t buffer_length_msec; int fd = -1; pa_sink_new_data sink_new_data; pa_source_new_data source_new_data; char const *name; char *name_buf; bool namereg_fail; pa_assert(m); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("failed to parse module arguments."); goto fail; } if (pa_modargs_get_value_boolean(ma, "record", &record) < 0 || pa_modargs_get_value_boolean(ma, "playback", &playback) < 0) { pa_log("record= and playback= expect a boolean argument."); goto fail; } if (!playback && !record) { pa_log("neither playback nor record enabled for device."); goto fail; } u = pa_xnew0(struct userdata, 1); if (!(u->smoother = pa_smoother_new(PA_USEC_PER_SEC, PA_USEC_PER_SEC * 2, true, true, 10, pa_rtclock_now(), true))) goto fail; /* * For a process (or several processes) to use the same audio device for both * record and playback at the same time, the device's mixer must be enabled. * See mixerctl(1). It may be turned off for playback only or record only. */ u->mode = (playback && record) ? O_RDWR : (playback ? O_WRONLY : (record ? O_RDONLY : 0)); ss = m->core->default_sample_spec; if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) { pa_log("failed to parse sample specification"); goto fail; } u->frame_size = pa_frame_size(&ss); u->minimum_request = pa_usec_to_bytes(PA_USEC_PER_SEC / MAX_RENDER_HZ, &ss); buffer_length_msec = 100; if (pa_modargs_get_value_u32(ma, "buffer_length", &buffer_length_msec) < 0) { pa_log("failed to parse buffer_length argument"); goto fail; } u->buffer_size = pa_usec_to_bytes(1000 * buffer_length_msec, &ss); if (u->buffer_size < 2 * u->minimum_request) { pa_log("buffer_length argument cannot be smaller than %u", (unsigned)(pa_bytes_to_usec(2 * u->minimum_request, &ss) / 1000)); goto fail; } if (u->buffer_size > MAX_BUFFER_SIZE) { pa_log("buffer_length argument cannot be greater than %u", (unsigned)(pa_bytes_to_usec(MAX_BUFFER_SIZE, &ss) / 1000)); goto fail; } u->device_name = pa_xstrdup(pa_modargs_get_value(ma, "device", DEFAULT_DEVICE)); if ((fd = open_audio_device(u, &ss)) < 0) goto fail; u->core = m->core; u->module = m; m->userdata = u; pa_memchunk_reset(&u->memchunk); u->rtpoll = pa_rtpoll_new(); pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll); u->rtpoll_item = NULL; build_pollfd(u); if (u->mode != O_WRONLY) { name_buf = NULL; namereg_fail = true; if (!(name = pa_modargs_get_value(ma, "source_name", NULL))) { name = name_buf = pa_sprintf_malloc("solaris_input.%s", pa_path_get_filename(u->device_name)); namereg_fail = false; } pa_source_new_data_init(&source_new_data); source_new_data.driver = __FILE__; source_new_data.module = m; pa_source_new_data_set_name(&source_new_data, name); source_new_data.namereg_fail = namereg_fail; pa_source_new_data_set_sample_spec(&source_new_data, &ss); pa_source_new_data_set_channel_map(&source_new_data, &map); pa_proplist_sets(source_new_data.proplist, PA_PROP_DEVICE_STRING, u->device_name); pa_proplist_sets(source_new_data.proplist, PA_PROP_DEVICE_API, "solaris"); pa_proplist_sets(source_new_data.proplist, PA_PROP_DEVICE_DESCRIPTION, "Solaris PCM source"); pa_proplist_sets(source_new_data.proplist, PA_PROP_DEVICE_ACCESS_MODE, "serial"); pa_proplist_setf(source_new_data.proplist, PA_PROP_DEVICE_BUFFERING_BUFFER_SIZE, "%lu", (unsigned long) u->buffer_size); if (pa_modargs_get_proplist(ma, "source_properties", source_new_data.proplist, PA_UPDATE_REPLACE) < 0) { pa_log("Invalid properties"); pa_source_new_data_done(&source_new_data); goto fail; } u->source = pa_source_new(m->core, &source_new_data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY); pa_source_new_data_done(&source_new_data); pa_xfree(name_buf); if (!u->source) { pa_log("Failed to create source object"); goto fail; } u->source->userdata = u; u->source->parent.process_msg = source_process_msg; pa_source_set_asyncmsgq(u->source, u->thread_mq.inq); pa_source_set_rtpoll(u->source, u->rtpoll); pa_source_set_fixed_latency(u->source, pa_bytes_to_usec(u->buffer_size, &u->source->sample_spec)); pa_source_set_get_volume_callback(u->source, source_get_volume); pa_source_set_set_volume_callback(u->source, source_set_volume); u->source->refresh_volume = true; } else u->source = NULL; if (u->mode != O_RDONLY) { name_buf = NULL; namereg_fail = true; if (!(name = pa_modargs_get_value(ma, "sink_name", NULL))) { name = name_buf = pa_sprintf_malloc("solaris_output.%s", pa_path_get_filename(u->device_name)); namereg_fail = false; } pa_sink_new_data_init(&sink_new_data); sink_new_data.driver = __FILE__; sink_new_data.module = m; pa_sink_new_data_set_name(&sink_new_data, name); sink_new_data.namereg_fail = namereg_fail; pa_sink_new_data_set_sample_spec(&sink_new_data, &ss); pa_sink_new_data_set_channel_map(&sink_new_data, &map); pa_proplist_sets(sink_new_data.proplist, PA_PROP_DEVICE_STRING, u->device_name); pa_proplist_sets(sink_new_data.proplist, PA_PROP_DEVICE_API, "solaris"); pa_proplist_sets(sink_new_data.proplist, PA_PROP_DEVICE_DESCRIPTION, "Solaris PCM sink"); pa_proplist_sets(sink_new_data.proplist, PA_PROP_DEVICE_ACCESS_MODE, "serial"); if (pa_modargs_get_proplist(ma, "sink_properties", sink_new_data.proplist, PA_UPDATE_REPLACE) < 0) { pa_log("Invalid properties"); pa_sink_new_data_done(&sink_new_data); goto fail; } u->sink = pa_sink_new(m->core, &sink_new_data, PA_SINK_HARDWARE|PA_SINK_LATENCY); pa_sink_new_data_done(&sink_new_data); pa_assert(u->sink); u->sink->userdata = u; u->sink->parent.process_msg = sink_process_msg; pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq); pa_sink_set_rtpoll(u->sink, u->rtpoll); pa_sink_set_fixed_latency(u->sink, pa_bytes_to_usec(u->buffer_size, &u->sink->sample_spec)); pa_sink_set_max_request(u->sink, u->buffer_size); pa_sink_set_max_rewind(u->sink, u->buffer_size); pa_sink_set_get_volume_callback(u->sink, sink_get_volume); pa_sink_set_set_volume_callback(u->sink, sink_set_volume); pa_sink_set_get_mute_callback(u->sink, sink_get_mute); pa_sink_set_set_mute_callback(u->sink, sink_set_mute); u->sink->refresh_volume = u->sink->refresh_muted = true; } else u->sink = NULL; pa_assert(u->source || u->sink); u->sig = pa_signal_new(SIGPOLL, sig_callback, u); if (u->sig) ioctl(u->fd, I_SETSIG, S_MSG); else pa_log_warn("Could not register SIGPOLL handler"); if (!(u->thread = pa_thread_new("solaris", thread_func, u))) { pa_log("Failed to create thread."); goto fail; } /* Read mixer settings */ if (u->sink) { if (sink_new_data.volume_is_set) u->sink->set_volume(u->sink); else u->sink->get_volume(u->sink); if (sink_new_data.muted_is_set) u->sink->set_mute(u->sink); else u->sink->get_mute(u->sink); pa_sink_put(u->sink); } if (u->source) { if (source_new_data.volume_is_set) u->source->set_volume(u->source); else u->source->get_volume(u->source); pa_source_put(u->source); } pa_modargs_free(ma); return 0; fail: if (u) pa__done(m); else if (fd >= 0) close(fd); if (ma) pa_modargs_free(ma); return -1; }