@@ -6,7 +6,6 @@ package portaudio
66
77// #cgo pkg-config: portaudio-2.0
88// #include <portaudio.h>
9- // extern PaStreamCallback* paStreamCallback;
109import "C"
1110
1211import (
@@ -60,10 +59,6 @@ const (
6059 OutputUnderflowed Error = C .paOutputUnderflowed
6160 HostApiNotFound Error = C .paHostApiNotFound
6261 InvalidHostApi Error = C .paInvalidHostApi
63- CanNotReadFromACallbackStream Error = C .paCanNotReadFromACallbackStream
64- CanNotWriteToACallbackStream Error = C .paCanNotWriteToACallbackStream
65- CanNotReadFromAnOutputOnlyStream Error = C .paCanNotReadFromAnOutputOnlyStream
66- CanNotWriteToAnInputOnlyStream Error = C .paCanNotWriteToAnInputOnlyStream
6762 IncompatibleStreamHostApi Error = C .paIncompatibleStreamHostApi
6863 BadBufferPtr Error = C .paBadBufferPtr
6964)
@@ -399,8 +394,6 @@ type Stream struct {
399394 paStream unsafe.Pointer
400395 inParams , outParams * C.PaStreamParameters
401396 in , out * reflect.SliceHeader
402- timeInfo StreamCallbackTimeInfo
403- flags StreamCallbackFlags
404397 args []reflect.Value
405398 callback reflect.Value
406399 closed bool
@@ -438,47 +431,6 @@ func delStream(s *Stream) {
438431 delete (streams , s .id )
439432}
440433
441- // StreamCallbackTimeInfo contains timing information for the
442- // buffers passed to the stream callback.
443- type StreamCallbackTimeInfo struct {
444- InputBufferAdcTime , CurrentTime , OutputBufferDacTime time.Duration
445- }
446-
447- // StreamCallbackFlags are flag bit constants for the statusFlags to StreamCallback.
448- type StreamCallbackFlags C.PaStreamCallbackFlags
449-
450- // PortAudio stream callback flags.
451- const (
452- // In a stream opened with FramesPerBufferUnspecified,
453- // InputUnderflow indicates that input data is all silence (zeros)
454- // because no real data is available.
455- //
456- // In a stream opened without FramesPerBufferUnspecified,
457- // InputUnderflow indicates that one or more zero samples have been inserted
458- // into the input buffer to compensate for an input underflow.
459- InputUnderflow StreamCallbackFlags = C .paInputUnderflow
460-
461- // In a stream opened with FramesPerBufferUnspecified,
462- // indicates that data prior to the first sample of the
463- // input buffer was discarded due to an overflow, possibly
464- // because the stream callback is using too much CPU time.
465- //
466- // Otherwise indicates that data prior to one or more samples
467- // in the input buffer was discarded.
468- InputOverflow StreamCallbackFlags = C .paInputOverflow
469-
470- // Indicates that output data (or a gap) was inserted,
471- // possibly because the stream callback is using too much CPU time.
472- OutputUnderflow StreamCallbackFlags = C .paOutputUnderflow
473-
474- // Indicates that output data will be discarded because no room is available.
475- OutputOverflow StreamCallbackFlags = C .paOutputOverflow
476-
477- // Some of all of the output data will be used to prime the stream,
478- // input data may be zero.
479- PrimingOutput StreamCallbackFlags = C .paPrimingOutput
480- )
481-
482434// OpenStream creates an instance of a Stream.
483435//
484436// For an input- or output-only stream, p.Output.Device or p.Input.Device must be nil, respectively.
@@ -494,11 +446,7 @@ func OpenStream(p StreamParameters, args ...interface{}) (*Stream, error) {
494446 delStream (s )
495447 return nil , err
496448 }
497- cb := C .paStreamCallback
498- if ! s .callback .IsValid () {
499- cb = nil
500- }
501- paErr := C .Pa_OpenStream (& s .paStream , s .inParams , nil , C .double (p .SampleRate ), C .ulong (p .FramesPerBuffer ), C .PaStreamFlags (p .Flags ), cb , unsafe .Pointer (s .id ))
449+ paErr := C .Pa_OpenStream (& s .paStream , s .inParams , nil , C .double (p .SampleRate ), C .ulong (p .FramesPerBuffer ), C .PaStreamFlags (p .Flags ), nil , unsafe .Pointer (s .id ))
502450 if paErr != C .paNoError {
503451 delStream (s )
504452 return nil , newError (paErr )
@@ -627,21 +575,6 @@ func (s *Stream) Start() error {
627575 return newError (C .Pa_StartStream (s .paStream ))
628576}
629577
630- //export streamCallback
631- func streamCallback (inputBuffer , outputBuffer unsafe.Pointer , frames C.ulong , timeInfo * C.PaStreamCallbackTimeInfo , statusFlags C.PaStreamCallbackFlags , userData unsafe.Pointer ) {
632- // defer func() {
633- // // Don't let PortAudio silently swallow panics.
634- // if x := recover(); x != nil {
635- // buf := make([]byte, 1<<10)
636- // for runtime.Stack(buf, true) == len(buf) {
637- // buf = make([]byte, 2*len(buf))
638- // }
639- // fmt.Fprintf(os.Stderr, "panic in portaudio stream callback: %s\n\n%s", x, buf)
640- // os.Exit(2)
641- // }
642- // }()
643- }
644-
645578// Stop terminates audio processing. It waits until all pending
646579// audio buffers have been played before it returns.
647580func (s * Stream ) Stop () error {
@@ -702,12 +635,6 @@ func (s *Stream) AvailableToRead() (int, error) {
702635// Read uses the buffer provided to OpenStream.
703636// The number of samples to read is determined by the size of the buffer.
704637func (s * Stream ) Read () error {
705- if s .callback .IsValid () {
706- return CanNotReadFromACallbackStream
707- }
708- if s .in == nil {
709- return CanNotReadFromAnOutputOnlyStream
710- }
711638 buf , frames , err := getBuffer (s .in , s .inParams )
712639 if err != nil {
713640 return err
0 commit comments