JuliaAudio / PortAudio.jl

PortAudio wrapper for the Julia programming language, compatible with the JuliaAudio family of packages
Other
115 stars 20 forks source link

Provide more information about unanticipated host errors #53

Open sairus7 opened 3 years ago

sairus7 commented 3 years ago

Can't get sound stream from audio input (mic), tried on several machines running Windows 10:

using PortAudio
devices = PortAudio.devices()
for d in devices
    try
        stream = PortAudioStream(d.name, 2, 0) # same errors with 4, 0
        @show stream
    catch err
        @error err
    end
end

Any ideas?

bramtayl commented 3 years ago

Hi @sairus7 can you give a bit more info here? What errors do you get? What devices do you have, and how many work?

sairus7 commented 3 years ago

I have the same errors on different machines, for example:

julia> devices = PortAudio.devices()
10-element Vector{PortAudio.PortAudioDevice}:
 PortAudio.PortAudioDevice("Microsoft Sound Mapper - Input", "MME", 2, 0, 44100.0, 0, 0.09, 0.09, 0.18, 0.18)
 PortAudio.PortAudioDevice("Microphone (Realtek High Defini", "MME", 2, 0, 44100.0, 1, 0.09, 0.09, 0.18, 0.18)
 PortAudio.PortAudioDevice("Microsoft Sound Mapper - Output", "MME", 0, 2, 44100.0, 2, 0.09, 0.09, 0.18, 0.18)
 PortAudio.PortAudioDevice("Speakers (Realtek High Definiti", "MME", 0, 2, 44100.0, 3, 0.09, 0.09, 0.18, 0.18)
 PortAudio.PortAudioDevice("Realtek Digital Output (Realtek", "MME", 0, 2, 44100.0, 4, 0.09, 0.09, 0.18, 0.18)
 PortAudio.PortAudioDevice("Microphone (Realtek HD Audio Mic input)", "Windows WDM-KS", 2, 0, 48000.0, 5, 0.01, 0.01, 0.04, 0.04)
 PortAudio.PortAudioDevice("SPDIF Out (Realtek HDA SPDIF Out)", "Windows WDM-KS", 0, 2, 44100.0, 6, 0.01, 0.01, 0.04, 0.04)
 PortAudio.PortAudioDevice("Microphone Array (Realtek HD Audio Mic Array input)", "Windows WDM-KS", 4, 0, 48000.0, 7, 0.01, 0.01, 0.04, 0.04)
 PortAudio.PortAudioDevice("Stereo Mix (Realtek HD Audio Stereo input)", "Windows WDM-KS", 2, 0, 48000.0, 8, 0.01, 0.01, 0.04, 0.04)
 PortAudio.PortAudioDevice("Speakers (Realtek HD Audio output)", "Windows WDM-KS", 0, 2, 48000.0, 9, 0.01, 0.01, 0.04, 0.04)

julia> for d in devices
           try
               stream = PortAudioStream(d.name, 2, 0) # same errors with 4, 0
               @show stream
           catch err
               @error err
           end
       end
┌ Error: ErrorException("libportaudio: Can't write to an input only stream")
└ @ Main REPL[8]:6
┌ Error: ErrorException("libportaudio: Can't write to an input only stream")
└ @ Main REPL[8]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[8]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[8]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[8]:6
┌ Error: ErrorException("libportaudio: Unanticipated host error")
└ @ Main REPL[8]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[8]:6
┌ Error: ErrorException("libportaudio: Unanticipated host error")
└ @ Main REPL[8]:6
┌ Error: ErrorException("libportaudio: Unanticipated host error")
└ @ Main REPL[8]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[8]:6
sairus7 commented 3 years ago

At the same time I can get a couple of sink streams (speakers):

julia> for d in devices
           try
               stream = PortAudioStream(d.name, 0, 2)
               @show stream
           catch err
               @error err
           end
       end
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[4]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[4]:6
stream = PortAudioStream{Float32}
  Samplerate: 44100.0Hz

  2 channel sink: "Microsoft Sound Mapper - Output"
stream = PortAudioStream{Float32}
  Samplerate: 44100.0Hz

  2 channel sink: "Speakers (Realtek High Definiti"
stream = PortAudioStream{Float32}
  Samplerate: 44100.0Hz

  2 channel sink: "Realtek Digital Output (Realtek"
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[4]:6
┌ Error: ErrorException("libportaudio: Unanticipated host error")
└ @ Main REPL[4]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[4]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[4]:6
┌ Error: ErrorException("libportaudio: Unanticipated host error")
└ @ Main REPL[4]:6
bramtayl commented 3 years ago

Hmm, well, the Invalid number of channels errors are expected. Several of your devices only support input or output channels. We could potentially throw this error earlier from julia.

The Can't write to an input only stream errors should have been fixed on master by https://github.com/JuliaAudio/PortAudio.jl/commit/0187b4937ddc854a52e7722d85768bf8cb2cd934 . Maybe try again on master?

Not sure about the Unanticipated host errors though. libportaudio does provide a mechanism for gettting more information about unanticipated host errors, so we could potentially do that when these kind of errors are thrown.

sairus7 commented 3 years ago

Yes, tried this on master and got at least two working input streams:

julia> for d in devices
           try
               stream = PortAudioStream(d.name, 2, 0) # same errors with 4, 0
               @show stream
           catch err
               @error err
           end
       end
stream = PortAudioStream{Float32}
  Samplerate: 44100.0Hz

  2 channel source: "Microsoft Sound Mapper - Input"
stream = PortAudioStream{Float32}
  Samplerate: 44100.0Hz

  2 channel source: "Microphone (Realtek High Defini"
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[7]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[7]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[7]:6
┌ Error: ErrorException("libportaudio: Unanticipated host error")
└ @ Main REPL[7]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[7]:6
┌ Error: ErrorException("libportaudio: Unanticipated host error")
└ @ Main REPL[7]:6
┌ Error: ErrorException("libportaudio: Unanticipated host error")
└ @ Main REPL[7]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[7]:6

julia> for d in devices
           try
               stream = PortAudioStream(d.name, 4, 0) # same errors with 4, 0
               @show stream
           catch err
               @error err
           end
       end
stream = PortAudioStream{Float32}
  Samplerate: 44100.0Hz

  4 channel source: "Microsoft Sound Mapper - Input"
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[8]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[8]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[8]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[8]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[8]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[8]:6
┌ Error: ErrorException("libportaudio: Unanticipated host error")
└ @ Main REPL[8]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[8]:6
┌ Error: ErrorException("libportaudio: Invalid number of channels")
└ @ Main REPL[8]:6