本文整理汇总了C++中Pa_CloseStream函数的典型用法代码示例。如果您正苦于以下问题:C++ Pa_CloseStream函数的具体用法?C++ Pa_CloseStream怎么用?C++ Pa_CloseStream使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Pa_CloseStream函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main( void )
{
PaStreamParameters outputParameters;
PaError pa_err;
SF_INFO sfinfo;
signal( SIGINT, interrupt );
gen_default_drums();
pa_err = Pa_Initialize();
outputParameters.device = Pa_GetDefaultOutputDevice();
outputParameters.channelCount = CHANNELS;
outputParameters.sampleFormat = paFloat32;
outputParameters.suggestedLatency =
Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL;
pa_err = Pa_OpenStream( &stream, NULL, &outputParameters, SAMPLE_RATE,
BUFFER_SIZE, paClipOff, audio_callback, NULL );
sfinfo.samplerate = SAMPLE_RATE;
sfinfo.channels = CHANNELS;
sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT;
wave_output = sf_open( OUTPUT_FILE, SFM_WRITE, &sfinfo );
srand( time( 0 ) );
bass_z = 0.0f;
bass_freq = midi_to_hz( BASE_NOTE );
pa_err = Pa_StartStream( stream );
while( 1 )
Pa_Sleep( 1000 );
sf_close( wave_output );
pa_err = Pa_StopStream( stream );
pa_err = Pa_CloseStream( stream );
Pa_Terminate();
return 0;
}
示例2: Pa_AbortStream
audioSink::~audioSink (void) {
if ((ostream != NULL) && !Pa_IsStreamStopped (ostream)) {
paCallbackReturn = paAbort;
(void) Pa_AbortStream (ostream);
while (!Pa_IsStreamStopped (ostream))
Pa_Sleep (1);
writerRunning = false;
}
writerRunning = false;
if (ostream != NULL)
Pa_CloseStream (ostream);
ostream = NULL;
if (portAudio)
Pa_Terminate ();
delete _O_Buffer;
delete[] outTable;
}
示例3: delete_fluid_portaudio_driver
/*
* delete_fluid_portaudio_driver
*/
int
delete_fluid_portaudio_driver(fluid_audio_driver_t *p)
{
fluid_portaudio_driver_t* dev;
PaError err;
dev = (fluid_portaudio_driver_t*)p;
if (dev == NULL) return FLUID_OK;
/* PortAudio section */
if (dev->stream) Pa_CloseStream (dev->stream);
err = Pa_Terminate();
if (err != paNoError)
printf ("PortAudio termination error: %s\n", Pa_GetErrorText (err) );
FLUID_FREE (dev);
return FLUID_OK;
}
示例4: stop_portAudio
//-----------------------------------------------------------------------------
// Name: void stop_portAudio()
// Desc: //Stops Port Audio
//-----------------------------------------------------------------------------
void stop_portAudio()
{
PaError err;
/* Stop audio stream */
err = Pa_StopStream( g_stream );
if (err != paNoError) {
printf( "PortAudio error: stop stream: %s\n", Pa_GetErrorText(err));
}
/* Close audio stream */
err = Pa_CloseStream(g_stream);
if (err != paNoError) {
printf("PortAudio error: close stream: %s\n", Pa_GetErrorText(err));
}
/* Terminate audio stream */
err = Pa_Terminate();
if (err != paNoError) {
printf("PortAudio error: terminate: %s\n", Pa_GetErrorText(err));
}
}
示例5: Pa_CloseStream
int AudioStreamManager::StopAudio() {
PaError err;
err = Pa_CloseStream(audioStream);
if (err != paNoError) goto error;
soundDelegate->didEndPlay();
printf("Finished. gNumNoInputs = %d\n", numNoInputs);
Pa_Terminate();
return 0;
error:
Pa_Terminate();
fprintf(stderr, "An error occured while using the portaudio stream\n");
fprintf(stderr, "Error number: %d\n", err);
fprintf(stderr, "Error message: %s\n", Pa_GetErrorText(err));
soundDelegate->didEndPlay();
return -1;
}
示例6: uninit
static void uninit(struct ao *ao, bool cut_audio)
{
struct priv *priv = ao->priv;
if (priv->stream) {
if (!cut_audio && Pa_IsStreamActive(priv->stream) == 1) {
pthread_mutex_lock(&priv->ring_mutex);
priv->play_remaining = true;
pthread_mutex_unlock(&priv->ring_mutex);
check_pa_ret(Pa_StopStream(priv->stream));
}
check_pa_ret(Pa_CloseStream(priv->stream));
}
pthread_mutex_destroy(&priv->ring_mutex);
Pa_Terminate();
}
示例7: Pa_StopStream
bool PaInstance::stopStream ()
{
PaError error;
error = Pa_StopStream(mAudioStream);
if (error != paNoError)
{
errorHandler(error);
return false;
}
error = Pa_CloseStream(mAudioStream);
if (error != paNoError)
{
errorHandler(error);
return false;
}
return true;
}
示例8: while
/*
Blocks until data can be written.
If no data can be written in 2ms*100 the stream gets restarted.
returns the amount of data that can be written.
*/
unsigned int PortAudio::getWriteAvailable()
{
size_t writeAvailable = 0;
int waitCount = 0;
int failCount = 0;
while( writeAvailable == 0 ) {
writeAvailable = ringbuf.getWriteAvailable();
if( writeAvailable == 0 ) {
usleep(200000); //200 ms
//LOG4CXX_DEBUG(narratorPaLog, "getWriteAvailable = 0, Pa_IsStreamActive = " << Pa_IsStreamActive(pStream));
}
if(waitCount++ > 10) {
LOG4CXX_ERROR(narratorPaLog, "getWriteAvailable waittime exceeded, restarting stream");
mError = Pa_AbortStream(pStream);
// If abortstream fails, try reopening
if(failCount++ > 0 || ( mError != paNoError && mError != paStreamIsStopped )) {
LOG4CXX_ERROR(narratorPaLog, "Failed to abort stream, trying to close and reopen: " << Pa_GetErrorText(mError));
mError = Pa_CloseStream(pStream);
if(mError != paNoError)
LOG4CXX_ERROR(narratorPaLog, "Failed to close stream: " << Pa_GetErrorText(mError));
isOpen = false;
open(mRate, mChannels);
}
mError = Pa_StartStream(pStream);
if(mError != paNoError) LOG4CXX_ERROR(narratorPaLog, "Failed to start stream: " << Pa_GetErrorText(mError));
isStarted = true;
waitCount = 0;
}
}
//LOG4CXX_DEBUG(narratorPaLog, "getWriteAvailable = " << writeAvailable << ", Pa_IsStreamActive = " << Pa_IsStreamActive(pStream));
return writeAvailable;
}
示例9: Pa_StopStream
void AudioDevice::addCallback(AudioProcessor *audioProcessor_)
{
audioProcessor = audioProcessor_;
audioProcessor->setNumInputChannels(numInputs);
audioProcessor->setNumOutputChannels(numOutputs);
audioProcessor->setSampleRate(sampleRate);
audioProcessor->setBufferSize(bufferSize);
audioProcessor->prepareToPlay(sampleRate, bufferSize);
if(stream)
{
Pa_StopStream(&stream);
Pa_CloseStream(&stream);
}
err = Pa_OpenStream(&stream,
&inputParameters,
&outputParameters,
sampleRate,
bufferSize,
paClipOff,
&callback,
audioProcessor);
if( err != paNoError )
{
std::cout<<"Couldn't open stream"<<std::endl;
std::cout<< "Error message: "<< Pa_GetErrorText( err )<<std::endl;
}
std::cout<< "Error message: "<< Pa_GetErrorText( err )<<std::endl;
err = Pa_StartStream( stream );
if( err != paNoError )
{
std::cout<<"Couldn't start stream"<<std::endl;
std::cout<< "Error message: "<< Pa_GetErrorText( err )<<std::endl;
}
}
示例10: play_sound
//void* play_sound(void* void_input) {
void* play_sound(void* void_input) {
(void) void_input;
PaStream *stream;
printf("PortAudio Test: output sawtooth wave.\n");
/* Initialize our data for use by callback. */
data.left_phase = data.right_phase = 0.0;
/* Initialize library before making any other calls. */
err = Pa_Initialize();
if( err != paNoError ) goto error;
/* Open an audio I/O stream. */
err = Pa_OpenDefaultStream( &stream,
0, /* no input channels */
2, /* stereo output */
paFloat32, /* 32 bit floating point output */
SAMPLE_RATE,
256, /* frames per buffer */
patestCallback,
&data );
if( err != paNoError ) goto error;
err = Pa_StartStream( stream );
if( err != paNoError ) goto error;
/* Sleep for several seconds. */
Pa_Sleep(NUM_SECONDS*1000);
err = Pa_StopStream( stream );
if( err != paNoError ) goto error;
err = Pa_CloseStream( stream );
if( err != paNoError ) goto error;
Pa_Terminate();
printf("Test finished.\n");
return NULL;
error:
Pa_Terminate();
fprintf( stderr, "An error occured while using the portaudio stream\n" );
fprintf( stderr, "Error number: %d\n", err );
fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
return NULL;
}
示例11: Pa_StopStream
int PortAudioRecordBackend::closeVuMeterStream() {
int err;
if(vuMeterStream != NULL) {
err = Pa_StopStream(vuMeterStream);
if(err != paNoError) {
qDebug("Error stopping stream:\n %s", Pa_GetErrorText(err));
return -1;
}
err = Pa_CloseStream(vuMeterStream);
if(err != paNoError) {
qDebug("Error closing stream:\n %s", Pa_GetErrorText(err));
return -2;
}
vuMeterStream = NULL;
}
return 0;
}
示例12: Q_ASSERT
void AudioCapturePortAudio::uninitialize()
{
Q_ASSERT(stream != NULL);
PaError err;
/* -- Now we stop the stream -- */
err = Pa_StopStream( stream );
if( err != paNoError )
qDebug() << "PortAudio error: " << Pa_GetErrorText( err );
/* -- don't forget to cleanup! -- */
err = Pa_CloseStream( stream );
if( err != paNoError )
qDebug() << "PortAudio error: " << Pa_GetErrorText( err );
stream = NULL;
err = Pa_Terminate();
if( err != paNoError )
qDebug() << "PortAudio error: " << Pa_GetErrorText( err );
}
示例13: snd_close
void snd_close(void)
{
Pa_StopStream(stream);
Pa_CloseStream(stream);
Pa_Terminate();
free((void*) srconv_stream.data_in);
free(srconv_stream.data_out);
free((void*) srconv_record.data_in);
free(srconv_record.data_out);
free(pa_pcm_buf);
free(encode_buf);
delete[] stream_buf;
delete[] record_buf;
stream_buf = record_buf = nullptr;
delete dsp;
dsp = nullptr;
}
示例14: Pa_AbortStream
void
CPaCommon::Close()
{
if (stream)
{
int err = Pa_AbortStream(stream);
if (err != paNoError)
{
cout << "PortAudio error: " << Pa_GetErrorText(err) << endl;
}
err = Pa_CloseStream(stream);
if (err != paNoError)
{
cout << "PortAudio error: " << Pa_GetErrorText(err) << endl;
}
stream = NULL;
device_changed = true;
}
}
示例15: Pa_CloseStream
void CVoiceRecorder::DeInit(void)
{
if (m_bEnabled)
{
m_bEnabled = false;
Pa_CloseStream(m_pAudioStream);
Pa_Terminate();
// Assumes now that PACallback will not be called in this context
m_CS.Lock();
m_CS.Unlock();
// Assumes now that PACallback is not executing in this context
m_pAudioStream = NULL;
m_iSpeexOutgoingFrameSampleCount = 0;
speex_encoder_destroy(m_pSpeexEncoderState);
m_pSpeexEncoderState = NULL;
speex_preprocess_state_destroy(m_pSpeexPreprocState);
m_pSpeexPreprocState = NULL;
free(m_pOutgoingBuffer);
m_pOutgoingBuffer = NULL;
m_VoiceState = VOICESTATE_AWAITING_INPUT;
m_SampleRate = SAMPLERATE_WIDEBAND;
m_pAudioStream = NULL;
m_iSpeexOutgoingFrameSampleCount = 0;
m_uiOutgoingReadIndex = 0;
m_uiOutgoingWriteIndex = 0;
m_bIsSendingVoiceData = false;
m_ulTimeOfLastSend = 0;
m_uiBufferSizeBytes = 0;
}
}