removes commented-out old code

This commit is contained in:
Spencer Russell 2016-03-20 00:28:56 -04:00
parent 559dca24c2
commit 8ee46f5125
2 changed files with 7 additions and 190 deletions

View file

@ -12,6 +12,7 @@ include("libportaudio.jl")
export PortAudioSink, PortAudioSource
const DEFAULT_BUFSIZE=4096
const POLL_SECONDS=0.005
# initialize PortAudio on module load
Pa_Initialize()
@ -104,7 +105,7 @@ function SampleTypes.unsafe_write(sink::PortAudioSink, buf::SampleBuf)
transpose!(sink.pabuf, sink.jlbuf)
Pa_WriteStream(sink.stream, sink.pabuf, n, false)
written += n
sleep(0.005)
sleep(POLL_SECONDS)
end
sink.busy = false
if length(sink.waiters) > 0
@ -136,7 +137,7 @@ function SampleTypes.unsafe_read!(source::PortAudioSource, buf::SampleBuf)
bufend = n+read
@devec buf[bufstart:bufend, :] = source.jlbuf[1:n, :]
read += n
sleep(0.005)
sleep(POLL_SECONDS)
end
source.busy = false
@ -148,190 +149,4 @@ function SampleTypes.unsafe_read!(source::PortAudioSource, buf::SampleBuf)
read
end
# type Pa_AudioStream <: AudioStream
# root::AudioMixer
# info::DeviceInfo
# show_warnings::Bool
# stream::PaStream
# sformat::PaSampleFormat
# sbuffer::Array{Real}
# sbuffer_output_waiting::Integer
# parent_may_use_buffer::Bool
#
# """
# Get device parameters needed for opening with portaudio
# default is input as 44100/16bit int, same as CD audio type input
# """
# function Pa_AudioStream(device_index, channels=2, input=false,
# sample_rate::Integer=44100,
# framesPerBuffer::Integer=2048,
# show_warnings::Bool=false,
# sample_format::PaSampleFormat=paInt16)
# require_portaudio_init()
# stream = Pa_OpenStream(device_index, channels, input, sample_format,
# Cdouble(sample_rate), Culong(framesPerBuffer))
# Pa_StartStream(stream)
# root = AudioMixer()
# datatype = PaSampleFormat_to_T(sample_format)
# sbuf = ones(datatype, framesPerBuffer)
# this = new(root, DeviceInfo(sample_rate, framesPerBuffer),
# show_warnings, stream, sample_format, sbuf, 0, false)
# info("Scheduling PortAudio Render Task...")
# if input
# @schedule(pa_input_task(this))
# else
# @schedule(pa_output_task(this))
# end
# this
# end
# end
#
# """
# Blocking read from a Pa_AudioStream that is open as input
# """
# function read_Pa_AudioStream(stream::Pa_AudioStream)
# while true
# while stream.parent_may_use_buffer == false
# sleep(0.001)
# end
# buffer = deepcopy(stream.sbuffer)
# stream.parent_may_use_buffer = false
# return buffer
# end
# end
#
# """
# Blocking write to a Pa_AudioStream that is open for output
# """
# function write_Pa_AudioStream(stream::Pa_AudioStream, buffer)
# retval = 1
# sbufsize = length(stream.sbuffer)
# inputlen = length(buffer)
# if(inputlen > sbufsize)
# info("Overflow at write_Pa_AudioStream")
# retval = 0
# elseif(inputlen < sbufsize)
# info("Underflow at write_Pa_AudioStream")
# retval = -1
# end
# while true
# while stream.parent_may_use_buffer == false
# sleep(0.001)
# end
# for idx in 1:min(sbufsize, inputlen)
# stream.sbuffer[idx] = buffer[idx]
# end
# stream.parent_may_use_buffer = false
# end
# retval
# end
#
# ############ Internal Functions ############
#
# function portaudio_task(stream::PortAudioStream)
# info("PortAudio Render Task Running...")
# n = bufsize(stream)
# buffer = zeros(AudioSample, n)
# try
# while true
# while Pa_GetStreamReadAvailable(stream.stream) < n
# sleep(0.005)
# end
# Pa_ReadStream(stream.stream, buffer, n, stream.show_warnings)
# # assume the root is always active
# rendered = render(stream.root.renderer, buffer, stream.info)::AudioBuf
# for i in 1:length(rendered)
# buffer[i] = rendered[i]
# end
# for i in (length(rendered)+1):n
# buffer[i] = 0.0
# end
# while Pa_GetStreamWriteAvailable(stream.stream) < n
# sleep(0.005)
# end
# Pa_WriteStream(stream.stream, buffer, n, stream.show_warnings)
# end
# catch ex
# warn("Audio Task died with exception: $ex")
# Base.show_backtrace(STDOUT, catch_backtrace())
# end
# end
#
# """
# Get input device data, pass as a producer, no rendering
# """
# function pa_input_task(stream::Pa_AudioStream)
# info("PortAudio Input Task Running...")
# n = bufsize(stream)
# datatype = PaSampleFormat_to_T(stream.sformat)
# # bigger ccall buffer to avoid overflow related errors
# buffer = zeros(datatype, n * 8)
# try
# while true
# while Pa_GetStreamReadAvailable(stream.stream) < n
# sleep(0.005)
# end
# while stream.parent_may_use_buffer
# sleep(0.005)
# end
# err = ccall((:Pa_ReadStream, libportaudio), PaError,
# (PaStream, Ptr{Void}, Culong),
# stream.stream, buffer, n)
# handle_status(err, stream.show_warnings)
# stream.sbuffer[1: n] = buffer[1: n]
# stream.parent_may_use_buffer = true
# sleep(0.005)
# end
# catch ex
# warn("Audio Input Task died with exception: $ex")
# Base.show_backtrace(STDOUT, catch_backtrace())
# end
# end
#
# """
# Send output device data, no rendering
# """
# function pa_output_task(stream::Pa_AudioStream)
# info("PortAudio Output Task Running...")
# n = bufsize(stream)
# try
# while true
# navail = stream.sbuffer_output_waiting
# if navail > n
# info("Possible output buffer overflow in stream")
# navail = n
# end
# if (navail > 1) & (stream.parent_may_use_buffer == false) &
# (Pa_GetStreamWriteAvailable(stream.stream) < navail)
# Pa_WriteStream(stream.stream, stream.sbuffer,
# navail, stream.show_warnings)
# stream.parent_may_use_buffer = true
# else
# sleep(0.005)
# end
# end
# catch ex
# warn("Audio Output Task died with exception: $ex")
# Base.show_backtrace(STDOUT, catch_backtrace())
# end
# end
end # module PortAudio

View file

@ -1,9 +1,11 @@
#!/usr/bin/env julia
using BaseTestNext
using PortAudio
@testset "PortAudio Tests" begin
@test false
println("DEVICES FOUND:")
for d in PortAudio.devices()
println(d)
end
exit(0)