int pulse_initialize(struct iaxc_audio_driver *d, int sample_rate) { pa_simple *sp = NULL; pa_simple *sr = NULL; if (!sample_rate || sample_rate < 8000) sample_rate = 8000; ss.channels = 1; ss.rate = sample_rate; ss.format = PA_SAMPLE_S16LE; // record stream pointer sr = pa_simple_new(NULL, "QRadioLink", PA_STREAM_RECORD, NULL, "Iax2-Client", &ss, NULL, NULL, NULL ); // playback stream pointer sp = pa_simple_new(NULL, "QRadioLink", PA_STREAM_PLAYBACK, NULL, "Iax2-Client", &ss, NULL, NULL, NULL ); d->priv = sr; d->priv2 = sp; d->initialize = pulse_initialize; /* This function */ d->destroy = pulse_destroy; /* Implemented to flush buffers and then free resources */ d->select_devices = pulse_select_devices; /* Bogey function, pulse audio connects via resource thread */ d->selected_devices = pulse_selected_devices; /* Same as above */ d->start = pulse_start; d->stop = pulse_stop; d->output = pulse_output; /* playback stream */ d->input = pulse_input; /* record stream */ d->input_level_get = pulse_input_level_get; d->input_level_set = pulse_input_level_set; d->output_level_get = pulse_output_level_get; d->output_level_set = pulse_output_level_set; d->play_sound = pulse_play_sound; d->stop_sound = pulse_stop_sound; return 0; }
static void* pulse_thread(void* context) { sem_t* init = (sem_t*)context; pa_sample_spec ss; ss.format = PA_SAMPLE_S16LE; ss.channels = 2; ss.rate = g_sample_rate; int err; g_pulse = pa_simple_new(NULL, g_appname, PA_STREAM_PLAYBACK, NULL, g_appname, &ss, NULL, NULL, &err); if (!g_pulse) { snprintf(g_lasterror, c_nlasterror, "failed to connect to pulse server: %d", err); } sem_post(init); if (!g_pulse) return 0; pa_simple* s = g_pulse; short samples[c_nsamples*2]; g_running = true; while (g_running) { g_callback(samples, c_nsamples); if (0 > pa_simple_write(s, samples, sizeof(samples), NULL)) break; } pa_simple_flush(s, NULL); pa_simple_free(s); g_pulse = 0; return 0; }
Dialup::Dialup(int len) { buffsize = len; buffind = 0; buffer = new unsigned char[len]; int err; pa_sample_spec spec; pa_buffer_attr bfat; bfat.maxlength = -1; bfat.fragsize = -1; spec.format = PA_SAMPLE_U8; spec.channels = 2; spec.rate = 44100; audiosrv = pa_simple_new( 0, // default pulseaudio server "phone_dialup", // app name PA_STREAM_RECORD, 0, // default device "phone dialup rosnode", //description &spec, 0, // default channel map &bfat, &err // get error codes ); if (!audiosrv) throw pa_exception(err); }
static void pulse_setup (sw_handle * handle, sw_format * format) { struct pa_sample_spec ss; pa_stream_direction_t dir; int error; if (format->channels > PA_CHANNELS_MAX) { fprintf(stderr, __FILE__": pulse_setup(): The maximum number of channels supported is %d, while %d have been requested.\n", PA_CHANNELS_MAX, format->channels); return; } ss.format = PA_SAMPLE_FLOAT32; ss.rate = format->rate; ss.channels = format->channels; if (handle->driver_flags == O_RDONLY) { dir = PA_STREAM_RECORD; } else if (handle->driver_flags == O_WRONLY) { dir = PA_STREAM_PLAYBACK; } else { return; } if (!(handle->custom_data = pa_simple_new(NULL, "Sweep", dir, NULL, "Sweep Stream", &ss, NULL, NULL, &error))) { fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); return; } handle->driver_rate = ss.rate; handle->driver_channels = ss.channels; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { const mxArray *Data = prhs[0]; int16_t *data = (int16_t*)mxGetData(prhs[0]); size_t r = mxGetN(Data); // PA code pa_simple *s; pa_sample_spec ss; ss.format = PA_SAMPLE_S16LE; ss.channels = 1; ss.rate = 22050; s = pa_simple_new(NULL, // Use the default server. "knife-alien", // Our application's name. PA_STREAM_PLAYBACK, NULL, // Use the default device. "Music", // Description of our stream. &ss, // Our sample format. NULL, // Use default channel map NULL, // Use default buffering attributes. NULL // Ignore error code. ); pa_simple_write(s,data,(size_t)r,NULL); }
/** \fn init \brief Take & initialize the device */ uint8_t pulseSimpleAudioDevice::init(uint8_t channels, uint32_t fq) { pa_simple *s; pa_sample_spec ss; int er; #ifdef ADM_PULSE_INT16 ss.format = PA_SAMPLE_S16NE; #else ss.format = PA_SAMPLE_FLOAT32NE;//PA_SAMPLE_S16NE; //FIXME big endian #endif ss.channels = channels; ss.rate =fq; instance= pa_simple_new(NULL, // Use the default server. "Avidemux2", // Our application's name. PA_STREAM_PLAYBACK, NULL, // Use the default device. "Sound", // Description of our stream. &ss, // Our sample format. NULL, // Use default channel map NULL , // Use default buffering attributes. &er // Ignore error code. ); if(!instance) { printf("[PulseSimple] open failed\n"); return 0; } printf("[PulseSimple] open ok\n"); return 1; }
void sound_pulse_init() { pa_sample_spec ss; pa_buffer_attr ba; ss.format = PA_SAMPLE_S16NE; ss.channels = 2; ss.rate = 48000; g_setenv("PULSE_PROP_media.role", "game", TRUE); ba.minreq = -1; ba.maxlength = -1; ba.prebuf = -1; ba.tlength = (1024*8)/2; s = pa_simple_new(NULL, // Use the default server. "PerfectZX", // Our application's name. PA_STREAM_PLAYBACK, NULL, // Use the default device. "Sound", // Description of our stream. &ss, // Our sample format. NULL, // Use default channel map &ba, // Use custom buffering attributes. NULL // Ignore error code. ); bufferFrames = SNDFRAME_LEN * ss.rate / 1000; sound_buffer = calloc( bufferFrames, sizeof(SNDFRAME) ); }
static int init(struct xmp_context *ctx) { struct xmp_options *o = &ctx->o; pa_sample_spec ss; int error; ss.format = PA_SAMPLE_S16NE; ss.channels = o->outfmt & XMP_FMT_MONO ? 1 : 2; ss.rate = o->freq; s = pa_simple_new(NULL, /* Use the default server */ "xmp", /* Our application's name */ PA_STREAM_PLAYBACK, NULL, /* Use the default device */ "Music", /* Description of our stream */ &ss, /* Our sample format */ NULL, /* Use default channel map */ NULL, /* Use default buffering attributes */ &error); /* Ignore error code */ if (s == 0) { fprintf(stderr, "pulseaudio error: %s\n", pa_strerror(error)); return XMP_ERR_DINIT; } return xmp_smix_on(ctx); }
int main(int argc, char*argv[]) { /* The sample type to use */ static const pa_sample_spec ss = { .format = PA_SAMPLE_S16LE, .rate = 44100, .channels = 2 }; pa_simple *s = NULL; int ret = 1; int error; /* Create the recording stream */ if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error))) { fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); goto finish; } for (;;) { uint8_t buf[BUFSIZE]; /* Record some data ... */ if (pa_simple_read(s, buf, sizeof(buf), &error) < 0) { fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n", pa_strerror(error)); goto finish; } /* And write it to STDOUT */ if (loop_write(STDOUT_FILENO, buf, sizeof(buf)) != sizeof(buf)) { fprintf(stderr, __FILE__": write() failed: %s\n", strerror(errno)); goto finish; } } ret = 0; finish: if (s) pa_simple_free(s); return ret; }
int sound_init_pulse() { pa_sample_spec ss; pa_buffer_attr buf; ss.format = PA_SAMPLE_U8; ss.channels = 1; ss.rate = 48000; buf.maxlength=8192; buf.tlength=4096; buf.prebuf=4096; buf.minreq=4096; buf.fragsize=4096; pulse_s = pa_simple_new(NULL,"fbzx",PA_STREAM_PLAYBACK,NULL,"Spectrum",&ss,NULL,&buf,NULL); if (pulse_s==NULL) { return -1; } ordenador.sign=0; ordenador.format=0; ordenador.channels=1; ordenador.freq=48000; ordenador.buffer_len=4096; return 0; }
RTC::ReturnCode_t PulseAudioInput::onActivated(RTC::UniqueId ec_id) { RTC_DEBUG(("onActivated start")); try { pa_cvolume cv; // mp_vol = pa_cvolume_reset(&cv, 1); // pa_cvolume_init(mp_vol); m_spec.format = getFormat(m_formatstr); m_spec.channels = (uint8_t)m_channels; m_simple = pa_simple_new( NULL, //!< Server name, or NULL for default "PulseAudioInput", //!< A descriptive name for this client (application name, ...) PA_STREAM_RECORD, //!< Open this stream for recording or playback? NULL, //!< Sink (resp. source) name, or NULL for default "record", //!< A descriptive name for this client (application name, song title, ...) &m_spec, //!< The sample type to use NULL, //!< The channel map to use, or NULL for default NULL, //!< Buffering attributes, or NULL for default &m_err ); //!< A pointer where the error code is stored when the routine returns NULL. It is OK to pass NULL here. if ( m_simple == NULL ) { throw m_err; } } catch (...) { std::string error_str = pa_strerror(m_err); RTC_WARN(("pa_simple_new() failed onActivated:%s", error_str.c_str())); } is_active = true; RTC_DEBUG(("onActivated finish")); return RTC::RTC_OK; }
ad_rec_t * ad_open_dev(const char *dev, int32 samples_per_sec) { ad_rec_t *handle; pa_simple *pa; pa_sample_spec ss; int error; ss.format = PA_SAMPLE_S16LE; ss.channels = 1; ss.rate = 16000; //samples_per_sec; pa = pa_simple_new(NULL, "ASR", PA_STREAM_RECORD, dev, "Speech", &ss, NULL, NULL, &error); if (pa == NULL) { fprintf(stderr, "Error opening audio device %s for capture: %s\n", dev, pa_strerror(error)); return NULL; } if ((handle = (ad_rec_t *) calloc(1, sizeof(ad_rec_t))) == NULL) { fprintf(stderr, "Failed to allocate memory for ad device\n"); return NULL; } handle->pa = pa; handle->recording = 0; handle->sps = samples_per_sec; handle->bps = sizeof(int16); return handle; }
int _openPlay(char *identificacion) { int error; if (!(sp = pa_simple_new(NULL, identificacion, PA_STREAM_PLAYBACK, NULL, "record", &ss, NULL, NULL, &error))) return error; return 0; }
int _openRecord(char *identificacion) { int error; if (!(sr = pa_simple_new(NULL, identificacion, PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error))) return error; return 0; }
static int pulseaudio_allocate_voice(ALLEGRO_VOICE *voice) { PULSEAUDIO_VOICE *pv = al_malloc(sizeof(PULSEAUDIO_VOICE)); pa_sample_spec ss; pa_buffer_attr ba; ss.channels = al_get_channel_count(voice->chan_conf); ss.rate = voice->frequency; if (voice->depth == ALLEGRO_AUDIO_DEPTH_UINT8) ss.format = PA_SAMPLE_U8; else if (voice->depth == ALLEGRO_AUDIO_DEPTH_INT16) ss.format = PA_SAMPLE_S16NE; #if PA_API_VERSION > 11 else if (voice->depth == ALLEGRO_AUDIO_DEPTH_INT24) ss.format = PA_SAMPLE_S24NE; #endif else if (voice->depth == ALLEGRO_AUDIO_DEPTH_FLOAT32) ss.format = PA_SAMPLE_FLOAT32NE; else { ALLEGRO_ERROR("Unsupported PulseAudio sound format.\n"); al_free(pv); return 1; } ba.maxlength = 0x10000; // maximum length of buffer ba.tlength = 0x2000; // target length of buffer ba.prebuf = 0; // minimum data size required before playback starts ba.minreq = 0; // minimum size of request ba.fragsize = -1; // fragment size (recording) pv->s = pa_simple_new(NULL, // Use the default server. al_get_app_name(), PA_STREAM_PLAYBACK, NULL, // Use the default device. "Allegro Voice", &ss, NULL, // Use default channel map &ba, NULL // Ignore error code. ); if (!pv->s) { al_free(pv); return 1; } voice->extra = pv; pv->frame_size = ss.channels * al_get_audio_depth_size(voice->depth); pv->status = PV_STOPPED; pv->buffer_mutex = al_create_mutex(); pv->poll_thread = al_create_thread(pulseaudio_update, (void*)voice); al_start_thread(pv->poll_thread); return 0; }
bool WaveOutPulseAudio::OpenWaveOutDevice(int pSampleRate, int pOutputChannels) { pa_sample_spec tOutputFormat; int tRes; pa_usec_t tLatency; LOG(LOG_VERBOSE, "Trying to open the wave out device"); if (mWaveOutOpened) return false; mSampleRate = pSampleRate; mAudioChannels = pOutputChannels; LOG(LOG_VERBOSE, "Desired device is %s", mDesiredDevice.c_str()); if ((mDesiredDevice == "") || (mDesiredDevice == "auto") || (mDesiredDevice == "automatic")) { LOG(LOG_VERBOSE, "Using default audio device"); mDesiredDevice = ""; } tOutputFormat.format = PA_SAMPLE_S16LE; tOutputFormat.rate = mSampleRate; tOutputFormat.channels = mAudioChannels; // create a new playback stream if (!(mOutputStream = pa_simple_new(NULL, "Homer-Conferencing", PA_STREAM_PLAYBACK, (mDesiredDevice != "" ? mDesiredDevice.c_str() : NULL) /* dev Name */, GetStreamName().c_str(), &tOutputFormat, NULL, NULL, &tRes))) { LOG(LOG_ERROR, "Couldn't create PulseAudio stream because %s(%d)", pa_strerror(tRes), tRes); return false; } if ((tLatency = pa_simple_get_latency(mOutputStream, &tRes)) == (pa_usec_t) -1) { LOG(LOG_ERROR, "Couldn't determine the latency of the output stream because %s(%d)", pa_strerror(tRes), tRes); pa_simple_free(mOutputStream); mOutputStream = NULL; return false; } mCurrentDevice = mDesiredDevice; //###################################################### //### give some verbose output //###################################################### LOG(LOG_INFO, "PortAudio wave out opened..."); LOG(LOG_INFO," ..sample rate: %d", mSampleRate); LOG(LOG_INFO," ..channels: %d", pOutputChannels); LOG(LOG_INFO," ..desired device: %s", mDesiredDevice.c_str()); LOG(LOG_INFO," ..selected device: %s", mCurrentDevice.c_str()); LOG(LOG_INFO," ..latency: %"PRIu64" seconds", (uint64_t)tLatency * 1000 * 1000); LOG(LOG_INFO," ..sample format: %d", PA_SAMPLE_S16LE); mWaveOutOpened = true; return true; }
void mpgplayer::run() { if(mpg123_init() != MPG123_OK) qDebug("Error initilizing mpg123"); const char **test = mpg123_supported_decoders(); int error; mpg123_handle *mh = mpg123_new(test[0],&error); if(!mpg123_feature(MPG123_FEATURE_DECODE_LAYER3)) { qDebug("You do not seem to have mp3 decoding support"); return; } mpg123_format_none(mh); if(mpg123_format(mh,samplerate,MPG123_STEREO,MPG123_ENC_SIGNED_16)!=MPG123_OK) qDebug("Error in initilizing format decoder"); qDebug(test[0]); mpg123_open(mh,"/home/eli/Projects/groove-evan/Animal.mp3"); net = TData; pa_simple *s; pa_sample_spec ss; ss.format = PA_SAMPLE_S16NE; ss.rate = samplerate; ss.channels = 2; s =pa_simple_new(NULL,"Groove",PA_STREAM_PLAYBACK ,NULL,"Music",&ss,NULL,NULL,NULL); unsigned char bytes[1024]; size_t bsize = 1024; size_t done = 0; bool stop = false; playing=true; while(!stop) { switch(net) { case TWait: usleep(100); break; case TData: if(mpg123_read(mh,bytes,bsize,&done)==MPG123_DONE) { net=TFinish; } pa_simple_write(s,bytes,done,&error); break; case TAbort: stop = true; break; case TFinish: pa_simple_drain(s,&error); stop = true; break; default: break; } } qDebug("Finsihed playback"); pa_simple_free(s); mpg123_exit(); }
/* SoundPlayer constructor */ SoundPlayer::SoundPlayer() { // Create a new playback int error; static const pa_sample_spec ss = {PA_SAMPLE_S16LE, 24000, 1}; if (!(connection = pa_simple_new(NULL, NULL, PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error))) { fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); } }
int initialize_pulse(audio_format *format) { if(format->bits_per_sample==16) audio_spec.format=PA_SAMPLE_S16LE; audio_spec.rate=format->sample_rate; audio_spec.channels=format->num_channels; handle = pa_simple_new(NULL,NULL, PA_STREAM_PLAYBACK,NULL,"playback",&audio_spec,NULL,NULL,&error); return 0; }
Error AudioDriverPulseAudio::init() { active = false; thread_exited = false; exit_thread = false; pcm_open = false; samples_in = NULL; samples_out = NULL; mix_rate = GLOBAL_DEF("audio/mix_rate",44100); speaker_mode = SPEAKER_MODE_STEREO; channels = 2; pa_sample_spec spec; spec.format = PA_SAMPLE_S16LE; spec.channels = channels; spec.rate = mix_rate; int latency = GLOBAL_DEF("audio/output_latency", 25); buffer_size = nearest_power_of_2(latency * mix_rate / 1000); pa_buffer_attr attr; // set to appropriate buffer size from global settings attr.tlength = buffer_size; // set them to be automatically chosen attr.prebuf = (uint32_t)-1; attr.maxlength = (uint32_t)-1; attr.minreq = (uint32_t)-1; int error_code; pulse = pa_simple_new( NULL, // default server "Godot", // application name PA_STREAM_PLAYBACK, NULL, // default device "Sound", // stream description &spec, NULL, // use default channel map &attr, // use buffering attributes from above &error_code ); if (pulse == NULL) { fprintf(stderr, "PulseAudio ERR: %s\n", pa_strerror(error_code));\ ERR_FAIL_COND_V(pulse == NULL, ERR_CANT_OPEN); } samples_in = memnew_arr(int32_t, buffer_size * channels); samples_out = memnew_arr(int16_t, buffer_size * channels); mutex = Mutex::create(); thread = Thread::create(AudioDriverPulseAudio::thread_func, this); return OK; }
int main(int argc, char*argv[]) { /* The sample type to use */ static const pa_sample_spec ss = { .format = PA_SAMPLE_S16LE, .rate = 44100, .channels = 2 }; pa_simple *inStream = NULL; pa_simple *outStream = NULL; int ret = 1; int error; /* Create the recording stream */ if (!(inStream = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error))) { fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); goto finish; } /* Create the playback stream */ if (!(outStream = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error))) { fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); goto finish; } for (;;) { uint8_t buf[BUFSIZE]; /* Record some data ... */ if (pa_simple_read(inStream, buf, sizeof(buf), &error) < 0) { fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n", pa_strerror(error)); goto finish; } if (pa_simple_write(outStream, buf, sizeof(buf), &error) < 0) { fprintf(stderr, __FILE__": pa_simple_write() failed: %s\n", pa_strerror(error)); goto finish; } } ret = 0; finish: if (inStream) pa_simple_free(inStream); if (outStream) pa_simple_free(outStream); return ret; }
LinuxAudio::LinuxAudio() { /* Pulseaudio apparently requires the format to be set up in a slightly different way to OSS on FreeBSD. We do it here. */ AudioFormat.format = PA_SAMPLE_S16LE; AudioFormat.rate = 16000; AudioFormat.channels = 1; int Error = 0; Device = pa_simple_new(NULL, "abfplayer", PA_STREAM_PLAYBACK, NULL, "ABF Audio Book", &AudioFormat, NULL, NULL, &Error); }
BOOL pulseaudio_open_audio() { if (pulseaudio_audiodev_is_open) return TRUE; if (!(s = pa_simple_new(NULL, "Arnold", PA_STREAM_PLAYBACK, NULL, "playback", &sampleSpec, NULL, &bufferAttr, &error))) { fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); return FALSE; } pulseaudio_audiodev_is_open = TRUE; return TRUE; }
cst_audiodev *audio_open_pulseaudio(unsigned int sps, int channels, cst_audiofmt fmt) { cst_audiodev *ad; int err=0; /* Pulseaudio specific stuff */ pa_sample_spec *ss; pa_simple *s; ss = cst_alloc(pa_sample_spec,1); ss->rate = sps; ss->channels = channels; switch (fmt) { case CST_AUDIO_LINEAR16: if (CST_LITTLE_ENDIAN) ss->format = PA_SAMPLE_S16LE; else ss->format = PA_SAMPLE_S16BE; break; case CST_AUDIO_LINEAR8: ss->format = PA_SAMPLE_U8; break; case CST_AUDIO_MULAW: ss->format = PA_SAMPLE_ULAW; break; default: return NULL; break; } s = pa_simple_new( NULL, /* use default server */ "flite", PA_STREAM_PLAYBACK, NULL, /* use default device */ "Speech", ss, NULL, /* default channel map */ NULL, /* default buffering attributes */ &err); if (err < 0) return NULL; /* Write hardware parameters to flite audio device data structure */ ad = cst_alloc(cst_audiodev, 1); ad->real_sps = ad->sps = sps; ad->real_channels = ad->channels = channels; ad->real_fmt = ad->fmt = fmt; ad->platform_data = (void *) s; return ad; }
static int pulse_open(void) { pa_sample_spec ss; ss.format = PA_SAMPLE_S16NE; ss.channels = 1; ss.rate = 44100; s = pa_simple_new(NULL, "PSIndustrializer", PA_STREAM_PLAYBACK, NULL, "sound", &ss, NULL, NULL, NULL); if (!s) return -1; return 0; }
UINT8 Pulse_Start(void* drvObj, UINT32 deviceID, AUDIO_OPTS* options, void* audDrvParam) { DRV_PULSE* drv = (DRV_PULSE*)drvObj; UINT64 tempInt64; UINT8 retVal8; if (drv->devState != 0) return 0xD0; // already running drv->audDrvPtr = audDrvParam; if (options == NULL) options = &defOptions; drv->pulseFmt.channels = options->numChannels; drv->pulseFmt.rate = options->sampleRate; tempInt64 = (UINT64)options->sampleRate * options->usecPerBuf; drv->bufSmpls = (UINT32)((tempInt64 + 500000) / 1000000); drv->bufSize = (options->numBitsPerSmpl * drv->pulseFmt.channels / 8) * drv->bufSmpls; drv->bufCount = options->numBuffers ? options->numBuffers : 10; if (options->numBitsPerSmpl == 8) drv->pulseFmt.format = PA_SAMPLE_U8; else if (options->numBitsPerSmpl == 16) drv->pulseFmt.format = PA_SAMPLE_S16NE; else if (options->numBitsPerSmpl == 24) drv->pulseFmt.format = PA_SAMPLE_S24NE; else if (options->numBitsPerSmpl == 32) drv->pulseFmt.format = PA_SAMPLE_S32NE; else return 0xCF; drv->canPause = 1; drv->hPulse = pa_simple_new(NULL, "libvgm", PA_STREAM_PLAYBACK, NULL, drv->streamDesc, &drv->pulseFmt, NULL, NULL, NULL); if(!drv->hPulse) return 0xC0; OSSignal_Reset(drv->hSignal); retVal8 = OSThread_Init(&drv->hThread, &PulseThread, drv); if (retVal8) { pa_simple_free(drv->hPulse); return 0xC8; // CreateThread failed } drv->bufSpace = (UINT8*)malloc(drv->bufSize); drv->devState = 1; drv->pauseThread = 0x00; OSSignal_Signal(drv->hSignal); return AERR_OK; }
static int qpa_init_in (HWVoiceIn *hw, struct audsettings *as) { int error; static pa_sample_spec ss; struct audsettings obt_as = *as; PAVoiceIn *pa = (PAVoiceIn *) hw; ss.format = audfmt_to_pa (as->fmt, as->endianness); ss.channels = as->nchannels; ss.rate = as->freq; obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness); pa->s = pa_simple_new ( conf.server, "qemu", PA_STREAM_RECORD, conf.source, "pcm.capture", &ss, NULL, /* channel map */ NULL, /* buffering attributes */ &error ); if (!pa->s) { qpa_logerr (error, "pa_simple_new for capture failed\n"); goto fail1; } audio_pcm_init_info (&hw->info, &obt_as); hw->samples = conf.samples; pa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift); if (!pa->pcm_buf) { dolog ("Could not allocate buffer (%d bytes)\n", hw->samples << hw->info.shift); goto fail2; } if (audio_pt_init (&pa->pt, qpa_thread_in, hw, AUDIO_CAP, AUDIO_FUNC)) { goto fail3; } return 0; fail3: free (pa->pcm_buf); pa->pcm_buf = NULL; fail2: pa_simple_free (pa->s); pa->s = NULL; fail1: return -1; }
static int pulseaudio_allocate_recorder(ALLEGRO_AUDIO_RECORDER *r) { PULSEAUDIO_RECORDER *pa; pa = al_calloc(1, sizeof(*pa)); if (!pa) { ALLEGRO_ERROR("Unable to allocate memory for PULSEAUDIO_RECORDER.\n"); return 1; } pa->ss.channels = al_get_channel_count(r->chan_conf); pa->ss.rate = r->frequency; if (r->depth == ALLEGRO_AUDIO_DEPTH_UINT8) pa->ss.format = PA_SAMPLE_U8; else if (r->depth == ALLEGRO_AUDIO_DEPTH_INT16) pa->ss.format = PA_SAMPLE_S16NE; #if PA_API_VERSION > 11 else if (r->depth == ALLEGRO_AUDIO_DEPTH_INT24) pa->ss.format = PA_SAMPLE_S24NE; #endif else if (r->depth == ALLEGRO_AUDIO_DEPTH_FLOAT32) pa->ss.format = PA_SAMPLE_FLOAT32NE; else { ALLEGRO_ERROR("Unsupported PulseAudio sound format (depth).\n"); al_free(pa); return 1; } /* maximum length of the PulseAudio buffer. -1 => let the server decide. */ pa->ba.maxlength = -1; /* fragment size (bytes) controls how much data is returned back per read. The documentation recommends -1 for default behavior, but that sets a latency of around 2 seconds. Lower value decreases latency but increases overhead. The following attempts to set it (the base latency) to 1/8 of a second. */ pa->ba.fragsize = (r->sample_size * r->frequency) / 8; pa->s = pa_simple_new(NULL, al_get_app_name(), PA_STREAM_RECORD, NULL, "Allegro Audio Recorder", &pa->ss, NULL, &pa->ba, NULL); if (!pa->s) { ALLEGRO_ERROR("pa_simple_new() failed.\n"); al_free(pa); return 1; } r->thread = al_create_thread(pulse_audio_update_recorder, r); r->extra = pa; return 0; };
int main() { pa_sample_spec ss; ss.format = PA_SAMPLE_S16LE; ss.channels = 1; ss.rate = 96000; pa_buffer_attr ba; ba.maxlength = (uint32_t)-1; ba.tlength = 0; ba.prebuf = (uint32_t)-1; ba.minreq = (uint32_t)-1; ba.fragsize = (uint32_t)-1; pa_simple* s_rec = pa_simple_new(NULL, "echo", PA_STREAM_RECORD, NULL, "Record", &ss, NULL, &ba, NULL); pa_simple* s_play = pa_simple_new(NULL, "echo", PA_STREAM_PLAYBACK, NULL, "Echo", &ss, NULL, &ba, NULL); if (!s_rec) { fprintf(stderr, "Pulse rec failed.\n"); return 1; } if (!s_play) { fprintf(stderr, "Pulse play failed.\n"); return 1; } char buffer[sizeof(short) * 128]; for (;;) { pa_simple_read(s_rec, buffer, sizeof(buffer), NULL); pa_simple_write(s_play, buffer, sizeof(buffer), NULL); } return 0; }
void PulseAudioPCMOutputDriver::InitDevice() { if (!m_driver) { int errorCode = -1; m_driver = pa_simple_new(nullptr, APP_NAME, PA_STREAM_PLAYBACK, NULL, "playback", &m_selectedCaps, nullptr, nullptr, &errorCode); if(!m_driver) { AWS_LOGSTREAM_ERROR(CLASS_NAME, " error initializing device " << pa_strerror(errorCode)); } } }