diff options
162 files changed, 37686 insertions, 725 deletions
diff --git a/pd/README.txt b/pd/README.txt index d0075b76..867fb10e 100644 --- a/pd/README.txt +++ b/pd/README.txt @@ -38,7 +38,7 @@ WARRANTIES, see the file, "LICENSE.txt," included in the Pd distribution. ACKNOWLEDGEMENTS. Thanks to Harry Castle, Krzysztof Czaja, Mark Danks, Christian Feldbauer, Guenter Geiger, Kerry Hagan, Trevor Johnson, Fernando Lopez-Lezcano, Adam Lindsay, Karl MacMillan, Thomas Musil, Toshinori Ohkouchi, -Winfried Ritsch, Vibeke Sorensen, Rand Steiger, Shahrokh Yadegari, David -Zicarelli, Iohannes Zmoelnig, and probably many others for contributions of -code, documentation, ideas, and expertise. This work has received generous -support from the Intel Research Council. +Winfried Ritsch, Vibeke Sorensen, Rand Steiger, Hans-Christoph Steiner, +Shahrokh Yadegari, David Zicarelli, Iohannes Zmoelnig, and probably many others +for contributions of code, documentation, ideas, and expertise. This work has +received generous support from the Intel Research Council. diff --git a/pd/delme b/pd/delme new file mode 100644 index 00000000..7363d249 --- /dev/null +++ b/pd/delme @@ -0,0 +1,682 @@ +I pd/src/s_audio_alsa.c.old +I pd/extra/bonk~ +I pd/extra/fiddle~ +I pd/extra/loop~ +I pd/extra/lrshift~ +I pd/extra/expr~ +I pd/extra/pique/pique.c.old +U pd/README.txt +U pd/LICENSE.txt +U pd/INSTALL.txt +N pd/delme +U pd/src/makefile +U pd/src/z.pd +C pd/src/configure +C pd/src/configure.in +U pd/src/makefile.dependencies +N pd/src/s_midi.c +U pd/src/d_arithmetic.c +C pd/src/d_array.c +C pd/src/d_ctl.c +U pd/src/d_dac.c +C pd/src/d_delay.c +U pd/src/d_fft.c +U pd/src/d_fftroutine.c +C pd/src/d_filter.c +C pd/src/d_global.c +U pd/src/d_math.c +U pd/src/d_mayer_fft.c +U pd/src/d_misc.c +U pd/src/d_osc.c +U pd/src/d_resample.c +U pd/src/d_soundfile.c +U pd/src/d_ugen.c +C pd/src/g_all_guis.c +C pd/src/g_all_guis.h +U pd/src/g_array.c +C pd/src/g_bang.c +C pd/src/g_canvas.c +C pd/src/g_canvas.h +C pd/src/g_editor.c +C pd/src/g_graph.c +U pd/src/g_guiconnect.c +C pd/src/g_hdial.c +C pd/src/g_hslider.c +U pd/src/g_io.c +C pd/src/g_mycanvas.c +C pd/src/g_numbox.c +C pd/src/g_readwrite.c +C pd/src/g_rtext.c +U pd/src/g_scalar.c +C pd/src/g_template.c +C pd/src/g_text.c +C pd/src/g_toggle.c +U pd/src/g_traversal.c +C pd/src/g_vdial.c +C pd/src/g_vslider.c +C pd/src/g_vumeter.c +U pd/src/install-sh +U pd/src/m_atom.c +C pd/src/m_binbuf.c +C pd/src/m_class.c +C pd/src/m_conf.c +U pd/src/m_glob.c +C pd/src/m_imp.h +U pd/src/m_memory.c +C pd/src/m_obj.c +U pd/src/m_pd.c +C pd/src/m_pd.h +C pd/src/m_sched.c +C pd/src/s_main.c +U pd/src/makefile.clean +C pd/src/makefile.in +U pd/src/z2.pd +U pd/src/makefile.nt +N pd/src/s_audio_mmio.c +C pd/src/notes.txt +U pd/src/s_entry.c +U pd/src/s_file.c +N pd/src/s_audio.c +C pd/src/s_inter.c +N pd/src/s_audio_pa.c +U pd/src/s_loader.c +N pd/src/s_audio_jack.c +C pd/src/s_path.c +N pd/src/CHANGELOG.txt +U pd/src/s_print.c +U pd/src/z3.pd +U pd/src/s_watchdog.c +U pd/src/t_main.c +U pd/src/t_tk.h +C pd/src/t_tkcmd.c +C pd/src/u_main.tk +N pd/src/configure.in.ok +U pd/src/u_pdreceive.c +U pd/src/u_pdsend.c +U pd/src/x_acoustics.c +U pd/src/x_arithmetic.c +C pd/src/x_connective.c +C pd/src/x_gui.c +U pd/src/x_interface.c +U pd/src/x_midi.c +U pd/src/x_misc.c +U pd/src/x_net.c +U pd/src/x_qlist.c +U pd/src/x_time.c +N pd/src/s_midi_pm.c +N pd/src/s_audio_alsa.c +N pd/src/makefile.nt.pa19 +N pd/src/s_midi_oss.c +N pd/src/s_stuff.h +N pd/src/s_midi_sgi.c +N pd/src/configure.in.pa_v19 +N pd/src/s_audio_oss.c +N pd/src/s_midi_mmio.c +N pd/src/configure.in.oops +C pd/doc/1.manual/index.htm +N pd/doc/1.manual/pdmanual.css +C pd/doc/1.manual/x1.htm +C pd/doc/1.manual/x2.htm +C pd/doc/1.manual/x3.htm +U pd/doc/1.manual/x4.htm +C pd/doc/1.manual/x5.htm +U pd/doc/1.manual/1.introduction.txt +N pd/doc/1.manual/fig1.4.png +U pd/doc/1.manual/fig1.2.jpg +U pd/doc/1.manual/fig1.3.jpg +N pd/doc/1.manual/fig11.1.png +U pd/doc/1.manual/fig1.5.jpg +U pd/doc/1.manual/fig3.10.jpg +U pd/doc/1.manual/fig3.1.jpg +U pd/doc/1.manual/fig3.2.jpg +U pd/doc/1.manual/fig3.3.jpg +U pd/doc/1.manual/fig3.4.jpg +U pd/doc/1.manual/fig3.5.jpg +U pd/doc/1.manual/fig3.6.jpg +U pd/doc/1.manual/fig3.7.jpg +U pd/doc/1.manual/fig3.8.jpg +U pd/doc/1.manual/fig3.9.jpg +U pd/doc/1.manual/fig7.1.jpg +U pd/doc/1.manual/fig7.2.jpg +U pd/doc/1.manual/fig7.3.jpg +U pd/doc/1.manual/fig7.4.jpg +U pd/doc/1.manual/fig7.5.jpg +U pd/doc/1.manual/fig7.6.jpg +U pd/doc/1.manual/fig8.1.jpg +U pd/doc/1.manual/fig8.2.jpg +U pd/doc/1.manual/fig8.3.jpg +U pd/doc/1.manual/fig8.4.jpg +U pd/doc/1.manual/fig8.5.jpg +U pd/doc/1.manual/fig8.6.jpg +U pd/doc/1.manual/fig9.1.jpg +U pd/doc/1.manual/fig9.2.jpg +U pd/doc/1.manual/fig9.3.jpg +N pd/doc/1.manual/fig11.2.png +N pd/doc/1.manual/fig1.1.png +U pd/doc/2.control.examples/05.counter.pd +U pd/doc/2.control.examples/19.random.pd +U pd/doc/2.control.examples/01.PART1.hello.pd +U pd/doc/2.control.examples/10.more.messages.pd +U pd/doc/2.control.examples/15.file.txt +U pd/doc/2.control.examples/08.depthfirst.pd +U pd/doc/2.control.examples/07.time.pd +U pd/doc/2.control.examples/04.messages.pd +U pd/doc/2.control.examples/17.PART3.midi.pd +U pd/doc/2.control.examples/11.review.pd +U pd/doc/2.control.examples/sendnumber.pd +U pd/doc/2.control.examples/20.weighted-random.pd +U pd/doc/2.control.examples/15.array.pd +U pd/doc/2.control.examples/dollarsign.pd +U pd/doc/2.control.examples/13.locality.pd +U pd/doc/2.control.examples/14.dollarsigns.pd +U pd/doc/2.control.examples/02.editing.pd +U pd/doc/2.control.examples/00.INTRO.txt +U pd/doc/2.control.examples/03.connections.pd +U pd/doc/2.control.examples/06.more.counters.pd +U pd/doc/2.control.examples/16.more.arrays.pd +U pd/doc/2.control.examples/dollarsign2.pd +U pd/doc/2.control.examples/09.send_receive.pd +U pd/doc/2.control.examples/12.PART2.subpatch.pd +U pd/doc/2.control.examples/21.markov.chain.pd +U pd/doc/2.control.examples/18.conditional.pd +N pd/doc/2.control.examples/23.sequencing.pd +N pd/doc/2.control.examples/22.random-walk.pd +U pd/doc/6.externs/0.README.txt +U pd/doc/6.externs/dspobj~.c +N pd/doc/6.externs/obj1.c +C pd/doc/6.externs/makefile +N pd/doc/6.externs/test-obj1.pd +N pd/doc/6.externs/test-obj3.pd +N pd/doc/6.externs/obj2.c +U pd/doc/6.externs/test-dspobj~.pd +N pd/doc/6.externs/obj3.c +N pd/doc/6.externs/obj4.c +N pd/doc/6.externs/obj5.c +N pd/doc/6.externs/test-obj2.pd +N pd/doc/6.externs/test-obj4.pd +N pd/doc/6.externs/test-obj5.pd +U pd/doc/7.stuff/audio-playpen/1_DSP_INTRO.pd +U pd/doc/7.stuff/audio-playpen/2_sampler.pd +U pd/doc/7.stuff/audio-playpen/3_filter_and_ring.pd +U pd/doc/7.stuff/audio-playpen/4_more_filters.pd +U pd/doc/7.stuff/audio-playpen/5_delay.pd +U pd/doc/7.stuff/audio-playpen/6_flanger.pd +U pd/doc/7.stuff/audio-playpen/qdelay.pd +U pd/doc/7.stuff/audio-playpen/qgain.pd +U pd/doc/7.stuff/audio-playpen/qring.pd +U pd/doc/7.stuff/audio-playpen/README.txt +U pd/doc/7.stuff/audio-playpen/qsample.pd +U pd/doc/7.stuff/audio-playpen/qslew.pd +U pd/doc/7.stuff/audio-playpen/qvd.pd +U pd/doc/7.stuff/data-structures/0.intro.txt +U pd/doc/7.stuff/data-structures/1.scalars.pd +U pd/doc/7.stuff/data-structures/4.append.pd +U pd/doc/7.stuff/data-structures/6.file.pd +U pd/doc/7.stuff/data-structures/score.txt +U pd/doc/7.stuff/data-structures/file.txt +U pd/doc/7.stuff/data-structures/5.array.pd +U pd/doc/7.stuff/data-structures/7.sequencer.pd +U pd/doc/7.stuff/data-structures/data-array.pd +U pd/doc/7.stuff/data-structures/3.setting.data.pd +U pd/doc/7.stuff/data-structures/2.getting.data.pd +U pd/doc/7.stuff/data-structures/data-start.pd +U pd/doc/7.stuff/data-structures/voice.pd +U pd/doc/7.stuff/data-structures/z.txt +U pd/doc/7.stuff/data-structures/beat-maker.pd +U pd/doc/7.stuff/data-structures/9.sliderule.pd +U pd/doc/7.stuff/data-structures/8.beat-patterns.pd +U pd/doc/7.stuff/synth/README.txt +U pd/doc/7.stuff/synth/1.poly.synth.pd +U pd/doc/7.stuff/synth/preset.pd +U pd/doc/7.stuff/synth/preset1.txt +U pd/doc/7.stuff/synth/preset2.txt +U pd/doc/7.stuff/synth/preset3.txt +U pd/doc/7.stuff/synth/preset4.txt +U pd/doc/7.stuff/synth/gadsr.pd +U pd/doc/7.stuff/synth/test-gadsr.pd +U pd/doc/7.stuff/synth/numset.pd +U pd/doc/7.stuff/synth/synthvoice.pd +U pd/doc/7.stuff/soundfile-tools/README.txt +U pd/doc/7.stuff/soundfile-tools/1.ring-mod.pd +U pd/doc/7.stuff/soundfile-tools/3.phase.vocoder.pd +U pd/doc/7.stuff/soundfile-tools/6.vocoder.pd +U pd/doc/7.stuff/soundfile-tools/4.looper.pd +U pd/doc/7.stuff/soundfile-tools/5.reverb.pd +U pd/doc/7.stuff/soundfile-tools/2.bandpass.pd +U pd/doc/7.stuff/tools/testtone.pd +U pd/doc/7.stuff/tools/load-meter.pd +U pd/doc/7.stuff/tools/latency.pd +U pd/doc/sound/bell.aiff +U pd/doc/sound/voice.wav +U pd/doc/sound/voice2.wav +U pd/doc/5.reference/0.INTRO.txt +N pd/doc/5.reference/help-append.pd +N pd/doc/5.reference/help-bang.pd +N pd/doc/5.reference/help-biquad~.pd +N pd/doc/5.reference/help-cos~.pd +N pd/doc/5.reference/help-cputime.pd +N pd/doc/5.reference/help-delay.pd +N pd/doc/5.reference/help-delwrite~.pd +N pd/doc/5.reference/help-drawnumber.pd +N pd/doc/5.reference/help-get.pd +N pd/doc/5.reference/help-key.pd +N pd/doc/5.reference/help-line~.pd +N pd/doc/5.reference/help-lop~.pd +N pd/doc/5.reference/help-makenote.pd +N pd/doc/5.reference/help-math.pd +N pd/doc/5.reference/help-message.pd +N pd/doc/5.reference/help-midi.pd +N pd/doc/5.reference/help-my_canvas.pd +N pd/doc/5.reference/help-netreceive.pd +N pd/doc/5.reference/help-netsend.pd +N pd/doc/5.reference/help-noise~.pd +N pd/doc/5.reference/help-operators.pd +N pd/doc/5.reference/help-osc~.pd +N pd/doc/5.reference/help-otherbinops.pd +N pd/doc/5.reference/help-pack.pd +N pd/doc/5.reference/help-pd.pd +N pd/doc/5.reference/help-pipe.pd +N pd/doc/5.reference/help-print.pd +N pd/doc/5.reference/help-print~.pd +N pd/doc/5.reference/help-random.pd +U pd/doc/5.reference/qlist.txt +N pd/doc/5.reference/help-receive.pd +N pd/doc/5.reference/help-rsqrt~.pd +N pd/doc/5.reference/help-select.pd +N pd/doc/5.reference/help-send.pd +N pd/doc/5.reference/help-set.pd +N pd/doc/5.reference/help-sig~.pd +N pd/doc/5.reference/help-soundfiler.pd +N pd/doc/5.reference/help-sqrt~.pd +N pd/doc/5.reference/help-struct.pd +N pd/doc/5.reference/help-tabreceive~.pd +N pd/doc/5.reference/help-tabsend~.pd +N pd/doc/5.reference/help-tabwrite.pd +N pd/doc/5.reference/help-tabwrite~.pd +N pd/doc/5.reference/help-text.pd +N pd/doc/5.reference/help-vcf~.pd +U pd/doc/5.reference/textfile.txt +N pd/doc/5.reference/help-toggle.pd +N pd/doc/5.reference/help-unpack.pd +N pd/doc/5.reference/help-until.pd +N pd/doc/5.reference/help-vd~.pd +U pd/doc/5.reference/metro.pd +U pd/doc/5.reference/x_all_guis.pd +N pd/doc/5.reference/help-textfile.pd +N pd/doc/5.reference/help-switch~.pd +N pd/doc/5.reference/help-clip~.pd +N pd/doc/5.reference/help-value.pd +N pd/doc/5.reference/help-spigot.pd +N pd/doc/5.reference/help-swap.pd +N pd/doc/5.reference/help-tabread.pd +N pd/doc/5.reference/help-bng.pd +N pd/doc/5.reference/help-line.pd +N pd/doc/5.reference/help-throw~.pd +N pd/doc/5.reference/help-send~.pd +N pd/doc/5.reference/help-vdial.pd +N pd/doc/5.reference/help-pointer.pd +N pd/doc/5.reference/help-element.pd +N pd/doc/5.reference/help-env~.pd +N pd/doc/5.reference/help-poly.pd +N pd/doc/5.reference/help-setsize.pd +N pd/doc/5.reference/help-fft~.pd +N pd/doc/5.reference/help-graph.pd +N pd/doc/5.reference/help-sigbinops.pd +U pd/doc/5.reference/setsize.txt +N pd/doc/5.reference/help-bag.pd +N pd/doc/5.reference/help-tabosc4~.pd +N pd/doc/5.reference/help-tabplay~.pd +N pd/doc/5.reference/help-tabread4~.pd +N pd/doc/5.reference/help-bang~.pd +N pd/doc/5.reference/help-stripnote.pd +N pd/doc/5.reference/help-writesf~.pd +N pd/doc/5.reference/help-gatom.pd +N pd/doc/5.reference/help-hip~.pd +N pd/doc/5.reference/help-trigger.pd +N pd/doc/5.reference/help-vu.pd +N pd/doc/5.reference/help-openpanel.pd +N pd/doc/5.reference/help-int.pd +N pd/doc/5.reference/help-vslider.pd +U pd/doc/5.reference/table.txt +U pd/doc/5.reference/0_all_guis-INTRO.txt +N pd/doc/5.reference/help-vline~.pd +N pd/doc/5.reference/help-acoustics.pd +N pd/doc/5.reference/help-acoustics~.pd +N pd/doc/5.reference/help-adc~_dac~.pd +N pd/doc/5.reference/help-bp~.pd +N pd/doc/5.reference/help-canvas.pd +N pd/doc/5.reference/help-change.pd +N pd/doc/5.reference/help-delread~.pd +N pd/doc/5.reference/help-drawpolygon.pd +N pd/doc/5.reference/help-float.pd +N pd/doc/5.reference/help-framp~.pd +N pd/doc/5.reference/help-getsize.pd +N pd/doc/5.reference/help-hdial.pd +N pd/doc/5.reference/help-hslider.pd +N pd/doc/5.reference/help-makefilename.pd +N pd/doc/5.reference/help-moses.pd +N pd/doc/5.reference/help-namecanvas.pd +N pd/doc/5.reference/help-numbox2.pd +N pd/doc/5.reference/help-phasor~.pd +N pd/doc/5.reference/help-plot.pd +N pd/doc/5.reference/help-qlist.pd +N pd/doc/5.reference/help-readsf~.pd +N pd/doc/5.reference/help-realtime.pd +N pd/doc/5.reference/help-route.pd +N pd/doc/5.reference/help-samphold~.pd +N pd/doc/5.reference/help-savepanel.pd +N pd/doc/5.reference/help-snapshot~.pd +N pd/doc/5.reference/help-sublist.pd +N pd/doc/5.reference/help-threshold~.pd +N pd/doc/5.reference/help-timer.pd +N pd/doc/5.reference/help-wrap~.pd +N pd/doc/5.reference/help-block~.pd +U pd/doc/4.fft.examples/00.INTRO.txt +U pd/doc/4.fft.examples/01.fftanalysis.pd +U pd/doc/4.fft.examples/02.noisefft.pd +U pd/doc/4.fft.examples/03.denoise.pd +U pd/doc/4.fft.examples/04.shifts.pd +U pd/doc/4.fft.examples/05.sheepgoat.pd +U pd/doc/4.fft.examples/06.sheepgoat2.pd +U pd/doc/4.fft.examples/07.tinbell.pd +U pd/doc/4.fft.examples/08.convobros.pd +U pd/doc/4.fft.examples/09.pvoc.pd +U pd/doc/4.fft.examples/10.phaselockedvoc.pd +U pd/doc/4.fft.examples/11.pianorev.pd +U pd/doc/4.fft.examples/12.sinedecomposer.pd +U pd/doc/4.fft.examples/14.waveformgrab.pd +U pd/doc/4.fft.examples/x.wav +U pd/doc/4.fft.examples/add-trace.pd +U pd/doc/4.fft.examples/osc-voice.pd +U pd/doc/4.fft.examples/13.partialtracer.pd +N pd/doc/3.audio.examples/F12.paf.pd +N pd/doc/3.audio.examples/D11.sampler.poly.pd +N pd/doc/3.audio.examples/A04.line2.pd +N pd/doc/3.audio.examples/A07.frequency.mod.pd +N pd/doc/3.audio.examples/B10.sampler.scratch.pd +N pd/doc/3.audio.examples/K02.stereo.pd +U pd/doc/3.audio.examples/adsr.pd +N pd/doc/3.audio.examples/qlist-sampler.txt +N pd/doc/3.audio.examples/J03.qlist.pd +N pd/doc/3.audio.examples/G02.delay.loop.pd +N pd/doc/3.audio.examples/F11.anharmonic.FM.pd +N pd/doc/3.audio.examples/F02.just.say.pd +U pd/doc/3.audio.examples/sampvoice.pd +U pd/doc/3.audio.examples/partial.pd +N pd/doc/3.audio.examples/F01.pulse.pd +U pd/doc/3.audio.examples/osc-voice.pd +N pd/doc/3.audio.examples/J04.more.adsr.pd +N pd/doc/3.audio.examples/C03.zipper.noise.pd +N pd/doc/3.audio.examples/B11.sampler.nodoppler.pd +U pd/doc/3.audio.examples/spectrum-partial.pd +N pd/doc/3.audio.examples/J05.vibrato.pd +N pd/doc/3.audio.examples/J06.adsr.sequenced.pd +N pd/doc/3.audio.examples/G05.execution.order.pd +N pd/doc/3.audio.examples/C06.signal.to.control.pd +N pd/doc/3.audio.examples/J09.up.downsampling.pd +N pd/doc/3.audio.examples/F06.packets.pd +N pd/doc/3.audio.examples/G09.pitchshift.pd +N pd/doc/3.audio.examples/G01.delay.pd +N pd/doc/3.audio.examples/K04.even.odd.pd +N pd/doc/3.audio.examples/B05.tabread.FM.pd +N pd/doc/3.audio.examples/D07.additive.pd +N pd/doc/3.audio.examples/K05.bandlimited.pd +N pd/doc/3.audio.examples/A03.line.pd +N pd/doc/3.audio.examples/B03.tabread4.pd +N pd/doc/3.audio.examples/E03.octave.divider.pd +N pd/doc/3.audio.examples/D02.adsr.pd +N pd/doc/3.audio.examples/A00.intro.pd +N pd/doc/3.audio.examples/A01.sinewave.pd +N pd/doc/3.audio.examples/E01.spectrum.pd +N pd/doc/3.audio.examples/D09.shepard.tone.pd +N pd/doc/3.audio.examples/A08.review.pd +N pd/doc/3.audio.examples/A00.intro.txt +N pd/doc/3.audio.examples/E05.chebychev.pd +N pd/doc/3.audio.examples/sampvoice2.pd +N pd/doc/3.audio.examples/reverb-echo.pd +N pd/doc/3.audio.examples/H05.filter.noise.pd +N pd/doc/3.audio.examples/B07.sampler.pd +N pd/doc/3.audio.examples/F08.two.cosines.pd +N pd/doc/3.audio.examples/C08.analog.sequencer.pd +N pd/doc/3.audio.examples/A06.frequency.pd +N pd/doc/3.audio.examples/A02.amplitude.pd +N pd/doc/3.audio.examples/K06.triangle.pd +N pd/doc/3.audio.examples/C01.nyquist.pd +N pd/doc/3.audio.examples/sinevoice.pd +N pd/doc/3.audio.examples/C02.sawtooth-foldover.pd +N pd/doc/3.audio.examples/G03.delay.variable.pd +N pd/doc/3.audio.examples/B06.table.switching.pd +N pd/doc/3.audio.examples/H04.filter.floyd.pd +N pd/doc/3.audio.examples/B08.sampler.loop.pd +U pd/doc/3.audio.examples/output~.pd +U pd/doc/3.audio.examples/qlist.txt +U pd/doc/3.audio.examples/qlist2.txt +N pd/doc/3.audio.examples/H01.intro.filters.pd +N pd/doc/3.audio.examples/D12.sampler.bis.pd +N pd/doc/3.audio.examples/shepvoice.pd +N pd/doc/3.audio.examples/F03.pulse.spectrum.pd +N pd/doc/3.audio.examples/H02.bandpass.pd +N pd/doc/3.audio.examples/C09.sample.hold.pd +N pd/doc/3.audio.examples/D10.sampler.notes.pd +N pd/doc/3.audio.examples/E08.phase.mod.pd +N pd/doc/3.audio.examples/D05.envelope.pitch.pd +N pd/doc/3.audio.examples/B12.sampler.transpose.pd +N pd/doc/3.audio.examples/E07.evenodd.pd +N pd/doc/3.audio.examples/H03.filter.sweep.pd +N pd/doc/3.audio.examples/B13.sampler.overlap.pd +N pd/doc/3.audio.examples/K01.pulse.width.mod.pd +N pd/doc/3.audio.examples/C07.envelope.follower.pd +N pd/doc/3.audio.examples/E06.exponential.pd +N pd/doc/3.audio.examples/F09.declickit.pd +N pd/doc/3.audio.examples/C04.control.to.signal.pd +N pd/doc/3.audio.examples/D01.envelope.gen.pd +N pd/doc/3.audio.examples/B09.sampler.loop.smooth.pd +N pd/doc/3.audio.examples/A05.output.subpatch.pd +N pd/doc/3.audio.examples/D03.envelope.dB.pd +N pd/doc/3.audio.examples/F10.sweepable.FM.pd +N pd/doc/3.audio.examples/B02.two-wavetables.pd +N pd/doc/3.audio.examples/F07.packet.spectrum.pd +N pd/doc/3.audio.examples/B01.wavetables.pd +N pd/doc/3.audio.examples/C05.sampler.oneshot.pd +N pd/doc/3.audio.examples/B04.tabread4.interpolation.pd +N pd/doc/3.audio.examples/C10.monophonic.synth.pd +N pd/doc/3.audio.examples/K03.envelope.mod.pd +N pd/doc/3.audio.examples/D06.envelope.portamento.pd +N pd/doc/3.audio.examples/E02.ring.modulation.pd +N pd/doc/3.audio.examples/D04.envelope.quartic.pd +N pd/doc/3.audio.examples/D08.table.spectrum.pd +N pd/doc/3.audio.examples/G06.octave.doubler.pd +N pd/doc/3.audio.examples/G07.shaker.pd +N pd/doc/3.audio.examples/H07.ssb.modulation.pd +N pd/doc/3.audio.examples/B14.sampler.rockafella.pd +N pd/doc/3.audio.examples/F05.ring.modulation.pd +N pd/doc/3.audio.examples/E04.difference.tone.pd +N pd/doc/3.audio.examples/E09.FM.spectrum.pd +N pd/doc/3.audio.examples/E10.complex.FM.pd +N pd/doc/3.audio.examples/F04.waveshaping.pulse.pd +N pd/doc/3.audio.examples/F13.paf.control.pd +N pd/doc/3.audio.examples/G04.control.blocksize.pd +N pd/doc/3.audio.examples/G08.reverb.pd +U pd/extra/complex-mod~.pd +N pd/extra/rev2~.pd +U pd/extra/help-complex-mod~.pd +N pd/extra/help-expr.pd +U pd/extra/help-hilbert~.pd +N pd/extra/help-rev1~.pd +N pd/extra/help-rev2~.pd +N pd/extra/rev3~.pd +N pd/extra/help-rev3~.pd +U pd/extra/hilbert~.pd +U pd/extra/README.txt +U pd/extra/rev1-final.pd +U pd/extra/rev1-stage.pd +U pd/extra/rev1~.pd +U pd/extra/choice/choice.c +C pd/extra/choice/makefile +U pd/extra/choice/README.txt +N pd/extra/choice/help-choice.pd +C pd/extra/pique/makefile +U pd/extra/pique/pique.c +N pd/extra/pique/help-pique.pd +U pd/man/pd.1 +U pd/man/pdsend.1 +U pd/man/pdreceive.1 +N pd/portaudio_v18/config.guess +N pd/portaudio_v18/config.sub +N pd/portaudio_v18/configure +N pd/portaudio_v18/configure.in +N pd/portaudio_v18/fixdir.bat +N pd/portaudio_v18/fixfile.bat +N pd/portaudio_v18/index.html +N pd/portaudio_v18/install-sh +N pd/portaudio_v18/LICENSE.txt +N pd/portaudio_v18/Makefile.in +N pd/portaudio_v18/Makefile.linux +N pd/portaudio_v18/Makefile.mingw +N pd/portaudio_v18/Makefile.solaris +N pd/portaudio_v18/README.txt +N pd/portaudio_v18/VERSION.txt +N pd/portaudio_v18/docs/index.html +N pd/portaudio_v18/docs/latency.html +N pd/portaudio_v18/docs/pa_drivermodel.c.txt +N pd/portaudio_v18/docs/pa_drivermodel.h.txt +N pd/portaudio_v18/docs/pa_impl_guide.html +N pd/portaudio_v18/docs/pa_impl_startstop.html +N pd/portaudio_v18/docs/pa_tutorial.html +N pd/portaudio_v18/docs/pa_tut_asio.html +N pd/portaudio_v18/docs/pa_tut_callback.html +N pd/portaudio_v18/docs/pa_tut_devs.html +N pd/portaudio_v18/docs/pa_tut_explore.html +N pd/portaudio_v18/docs/pa_tut_init.html +N pd/portaudio_v18/docs/pa_tut_mac.html +N pd/portaudio_v18/docs/pa_tut_mac_osx.html +N pd/portaudio_v18/docs/pa_tut_open.html +N pd/portaudio_v18/docs/pa_tut_oss.html +N pd/portaudio_v18/docs/pa_tut_over.html +N pd/portaudio_v18/docs/pa_tut_pc.html +N pd/portaudio_v18/docs/pa_tut_run.html +N pd/portaudio_v18/docs/pa_tut_rw.html +N pd/portaudio_v18/docs/pa_tut_term.html +N pd/portaudio_v18/docs/pa_tut_util.html +N pd/portaudio_v18/docs/portaudio_h.txt +N pd/portaudio_v18/docs/portaudio_icmc2001.pdf +N pd/portaudio_v18/docs/proposals.html +N pd/portaudio_v18/docs/releases.html +N pd/portaudio_v18/pablio/pablio.c +N pd/portaudio_v18/pablio/pablio.def +N pd/portaudio_v18/pablio/pablio.h +N pd/portaudio_v18/pablio/README.txt +N pd/portaudio_v18/pablio/ringbuffer.c +N pd/portaudio_v18/pablio/ringbuffer.h +N pd/portaudio_v18/pablio/test_rw.c +N pd/portaudio_v18/pablio/test_rw_echo.c +N pd/portaudio_v18/pablio/test_w_saw.c +N pd/portaudio_v18/pablio/test_w_saw8.c +N pd/portaudio_v18/pablio/pablio_pd.c +N pd/portaudio_v18/pablio/pablio_pd.h +N pd/portaudio_v18/pablio/ringbuffer_pd.c +N pd/portaudio_v18/pablio/test_w_saw_pd.c +N pd/portaudio_v18/pa_asio/Callback_adaptation_.pdf +N pd/portaudio_v18/pa_asio/pa_asio.cpp +N pd/portaudio_v18/pa_asio/Pa_ASIO.pdf +N pd/portaudio_v18/pa_asio/readme_asio_sdk_patch.txt +N pd/portaudio_v18/pa_beos/pa_beos_mk.cc +N pd/portaudio_v18/pa_beos/PlaybackNode.cc +N pd/portaudio_v18/pa_beos/PlaybackNode.h +N pd/portaudio_v18/pa_common/pa_convert.c +N pd/portaudio_v18/pa_common/pa_host.h +N pd/portaudio_v18/pa_common/pa_lib.c +N pd/portaudio_v18/pa_common/pa_trace.c +N pd/portaudio_v18/pa_common/pa_trace.h +N pd/portaudio_v18/pa_common/portaudio.h +N pd/portaudio_v18/pa_dll_switch/letter_from_tim_010817.txt +N pd/portaudio_v18/pa_dll_switch/loadPA_DLL.cpp +N pd/portaudio_v18/pa_dll_switch/PaDllEntry.h +N pd/portaudio_v18/pa_dll_switch/pa_lib.c +N pd/portaudio_v18/pa_dll_switch/portaudio.h +N pd/portaudio_v18/pa_mac/pa_mac.c +N pd/portaudio_v18/pa_mac_core/notes.txt +N pd/portaudio_v18/pa_mac_core/pa_mac_core.c +N pd/portaudio_v18/pa_sgi/Makefile +N pd/portaudio_v18/pa_sgi/pa_sgi.c +N pd/portaudio_v18/pa_sgi/pthread-Makefile +N pd/portaudio_v18/pa_sgi/pthread-pa_sgi.c +N pd/portaudio_v18/pa_tests/debug_convert.c +N pd/portaudio_v18/pa_tests/debug_dither_calc.c +N pd/portaudio_v18/pa_tests/debug_dual.c +N pd/portaudio_v18/pa_tests/debug_multi_in.c +N pd/portaudio_v18/pa_tests/debug_multi_out.c +N pd/portaudio_v18/pa_tests/debug_record.c +N pd/portaudio_v18/pa_tests/debug_record_reuse.c +N pd/portaudio_v18/pa_tests/debug_sine.c +N pd/portaudio_v18/pa_tests/debug_sine_amp.c +N pd/portaudio_v18/pa_tests/debug_sine_formats.c +N pd/portaudio_v18/pa_tests/debug_sine_getchar.c +N pd/portaudio_v18/pa_tests/debug_srate.c +N pd/portaudio_v18/pa_tests/debug_test1.c +N pd/portaudio_v18/pa_tests/paqa_devs.c +N pd/portaudio_v18/pa_tests/paqa_errs.c +N pd/portaudio_v18/pa_tests/patest1.c +N pd/portaudio_v18/pa_tests/patest_buffer.c +N pd/portaudio_v18/pa_tests/patest_clip.c +N pd/portaudio_v18/pa_tests/patest_dither.c +N pd/portaudio_v18/pa_tests/patest_hang.c +N pd/portaudio_v18/pa_tests/patest_latency.c +N pd/portaudio_v18/pa_tests/patest_leftright.c +N pd/portaudio_v18/pa_tests/patest_longsine.c +N pd/portaudio_v18/pa_tests/patest_many.c +N pd/portaudio_v18/pa_tests/patest_maxsines.c +N pd/portaudio_v18/pa_tests/patest_mono.c +N pd/portaudio_v18/pa_tests/patest_multi_sine.c +N pd/portaudio_v18/pa_tests/patest_pink.c +N pd/portaudio_v18/pa_tests/patest_record.c +N pd/portaudio_v18/pa_tests/patest_ringmix.c +N pd/portaudio_v18/pa_tests/patest_saw.c +N pd/portaudio_v18/pa_tests/patest_sine.c +N pd/portaudio_v18/pa_tests/patest_sine8.c +N pd/portaudio_v18/pa_tests/patest_sine_formats.c +N pd/portaudio_v18/pa_tests/patest_sine_time.c +N pd/portaudio_v18/pa_tests/patest_stop.c +N pd/portaudio_v18/pa_tests/patest_sync.c +N pd/portaudio_v18/pa_tests/patest_toomanysines.c +N pd/portaudio_v18/pa_tests/patest_two_rates.c +N pd/portaudio_v18/pa_tests/patest_underflow.c +N pd/portaudio_v18/pa_tests/patest_wire.c +N pd/portaudio_v18/pa_tests/pa_devs.c +N pd/portaudio_v18/pa_tests/pa_fuzz.c +N pd/portaudio_v18/pa_tests/pa_minlat.c +N pd/portaudio_v18/pa_unix_oss/low_latency_tip.txt +N pd/portaudio_v18/pa_unix_oss/Makefile +N pd/portaudio_v18/pa_unix_oss/Makefile_freebsd +N pd/portaudio_v18/pa_unix_oss/pa_unix.c +N pd/portaudio_v18/pa_unix_oss/pa_unix.h +N pd/portaudio_v18/pa_unix_oss/pa_unix_oss.c +N pd/portaudio_v18/pa_unix_oss/pa_unix_solaris.c +N pd/portaudio_v18/pa_unix_oss/recplay.c +N pd/portaudio_v18/pa_win_ds/dsound_wrapper.c +N pd/portaudio_v18/pa_win_ds/dsound_wrapper.h +N pd/portaudio_v18/pa_win_ds/pa_dsound.c +N pd/portaudio_v18/pa_win_ds/portaudio.def +N pd/portaudio_v18/pa_win_wmme/Makefile.cygwin +N pd/portaudio_v18/pa_win_wmme/pa_win_wmme.c +N pd/portaudio_v18/testcvs/changeme.txt +N pd/portmidi_osx/Makefile +N pd/portmidi_osx/pmdarwin.c +N pd/portmidi_osx/pminternal.h +N pd/portmidi_osx/pmmacosx.c +N pd/portmidi_osx/pmmacosx.h +N pd/portmidi_osx/pmtest.c +N pd/portmidi_osx/pmutil.c +N pd/portmidi_osx/pmutil.h +N pd/portmidi_osx/portmidi.h +N pd/portmidi_osx/porttime.h +N pd/portmidi_osx/ptdarwin.c +N pd/portmidi_osx/README +N pd/portmidi_osx/portmidi.c +N pd/portmidi_osx/portmidi_osx_change_log.txt + +50 conflicts created by this import. +Use the following command to help the merge: + + cvs checkout -jmiller:yesterday -jmiller pd + diff --git a/pd/doc/2.control.examples/22.random-walk.pd b/pd/doc/2.control.examples/22.random-walk.pd new file mode 100644 index 00000000..21483bdb --- /dev/null +++ b/pd/doc/2.control.examples/22.random-walk.pd @@ -0,0 +1,64 @@ +#N canvas 0 0 604 511 12; +#X floatatom 113 218 5 0 0 0 - - -; +#X obj 123 113 f; +#X obj 104 198 random 4; +#X obj 26 197 random 2; +#X floatatom 35 219 5 0 0 0 - - -; +#X obj 123 138 t b b f; +#X obj 26 253 sel 0 1; +#X obj 159 328 +; +#X obj 123 87 metro 100; +#X obj 123 65 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1 +; +#X obj 104 252 + 1; +#X floatatom 242 153 5 0 0 0 - - -; +#X obj 82 309 *; +#X msg 26 282 -1; +#X obj 242 83 moses 0; +#X obj 316 83 moses 100; +#X obj 242 107 * -1; +#X obj 407 86 * -1; +#X obj 407 111 + 200; +#X msg 60 282 1; +#X text 39 9 Random walk generator; +#X text 143 64 on/off; +#X text 298 152 output; +#X text 22 375 A random walk is a special case of a Markov chain \, +in which the states are integers and the transitions add or subtract +a small amount from the previous state to get a new one. Here the "f" +holds the state. When it gets a bang \, the previous state is added +to a random number (from 1 to 4) multiplied by a random sign (-1 or +1). The new value is then coerced into the range from 0 to 100; +#X text 35 235 sign; +#X text 113 234 magnitude; +#X text 203 313 add prev value; +#X text 200 330 to random increment; +#X text 256 30 coercion to range 0-100 \; if out of range \, reflect +; +#X text 255 60 us back in.; +#X text 323 492 updated for Pd version 0.37-1; +#X connect 1 0 5 0; +#X connect 2 0 0 0; +#X connect 2 0 10 0; +#X connect 3 0 4 0; +#X connect 3 0 6 0; +#X connect 5 0 3 0; +#X connect 5 1 2 0; +#X connect 5 2 7 1; +#X connect 6 0 13 0; +#X connect 6 1 19 0; +#X connect 7 0 14 0; +#X connect 8 0 1 0; +#X connect 9 0 8 0; +#X connect 10 0 12 1; +#X connect 11 0 1 1; +#X connect 12 0 7 0; +#X connect 13 0 12 0; +#X connect 14 0 16 0; +#X connect 14 1 15 0; +#X connect 15 0 11 0; +#X connect 15 1 17 0; +#X connect 16 0 11 0; +#X connect 17 0 18 0; +#X connect 18 0 11 0; +#X connect 19 0 12 0; diff --git a/pd/doc/2.control.examples/23.sequencing.pd b/pd/doc/2.control.examples/23.sequencing.pd new file mode 100644 index 00000000..1aa19942 --- /dev/null +++ b/pd/doc/2.control.examples/23.sequencing.pd @@ -0,0 +1,28 @@ +#N canvas 47 52 758 482 12; +#X text 465 442 updated for Pd version 0.26; +#X text 35 28 You can use "qlist" or "textfile" objects for sequencing. +Qlist is simpler to use than the (more versatile) textfile.; +#X obj 345 144 r receive1; +#X obj 441 146 r receive2; +#X msg 205 88 clear \, add receive1 1 \, add 1000 receive1 0 \, add +receive2 2 \, add 1000 receive2 0 \, add receive1 3 \, bang; +#X obj 205 129 qlist; +#X floatatom 345 170 0 0 0 0 - - -; +#X floatatom 441 171 0 0 0 0 - - -; +#X text 48 202 The "add" messages add lines to the qlist \, so that +it contains:; +#X text 155 238 receive1 1; +#X text 154 259 1000 receive1 0; +#X text 155 279 receive2 2; +#X text 153 299 1000 receive2 0; +#X text 155 317 receive1 3; +#X text 16 391 If you have more than 5 lines or so wou will probably +want to store them as a separate file and have qlist read it. You can +also write files \, set tempo \, and single step... see the help patch +for details.; +#X text 22 341 and the "bang" instructs qlist to play the sequence +by sending messages to "receive" objects. Messages starting with numbers +request that amount of delay.; +#X connect 2 0 6 0; +#X connect 3 0 7 0; +#X connect 4 0 5 0; diff --git a/pd/doc/3.audio.examples/G01.delay.pd b/pd/doc/3.audio.examples/G01.delay.pd new file mode 100644 index 00000000..6b03ed12 --- /dev/null +++ b/pd/doc/3.audio.examples/G01.delay.pd @@ -0,0 +1,48 @@ +#N canvas 19 35 777 377 12; +#X text 103 7 DELAYS; +#X text 248 79 The delwrite~ object creates the delay line \; you give +it a name and a size in milliseconds. Each delwrite~ should have a +different name.; +#N canvas 0 0 548 248 sample 0; +#N canvas 0 0 450 300 graph1 0; +#X array G01-tab 61079 float 0; +#X coords 0 1 61078 -1 200 140 1; +#X restore 100 20 graph; +#X obj 61 176 loadbang; +#X obj 60 221 soundfiler; +#X msg 61 199 read -resize ../sound/voice.wav G01-tab; +#X connect 1 0 3 0; +#X connect 3 0 2 0; +#X restore 253 337 pd sample; +#X floatatom 38 196 4 0 999 0 - - -; +#X text 81 195 <-- delay time; +#X text 46 230 read from delay line; +#X obj 38 249 delread~ delay1; +#X obj 14 87 tabplay~ G01-tab; +#X obj 14 63 metro 1000; +#X obj 14 39 loadbang; +#X text 40 146 write to delay line; +#X obj 16 303 output~; +#X obj 15 275 +~; +#X obj 24 165 delwrite~ delay1 1000; +#X text 499 348 updated for Pd version 0.37-1; +#X text 248 24 You can delay a signal using the delwrite~ and delread~ +objects. In this example \, a sample loops continuously and is added +to a delayed copy of itself.; +#X text 247 215 The delread~ object always delays the signal an integer +number of samples and does no interpolation.; +#X text 28 107 test signal to delay; +#X text 248 130 Delread~'s arguments are the name of a delwrite (of +which there should be exactly one) and an optional delay time in milliseconds +between 0 and the length of the delay line. Each delwrite~ may have +as many delread~s as you wish \, which can then function as multiple +delay taps.; +#X text 114 209 (msec); +#X connect 3 0 6 0; +#X connect 6 0 12 1; +#X connect 7 0 12 0; +#X connect 7 0 13 0; +#X connect 8 0 7 0; +#X connect 9 0 8 0; +#X connect 12 0 11 0; +#X connect 12 0 11 1; diff --git a/pd/doc/3.audio.examples/G02.delay.loop.pd b/pd/doc/3.audio.examples/G02.delay.loop.pd index 71b35253..ba355b7c 100644 --- a/pd/doc/3.audio.examples/G02.delay.loop.pd +++ b/pd/doc/3.audio.examples/G02.delay.loop.pd @@ -1,213 +1,44 @@ -#N canvas 22 1 630 601 12; -#X text 309 531 updated for Pd version 0.26; -#X floatatom 58 505 0 0 0; -#N canvas 159 26 495 266 output 0; -#X obj 338 160 t b; -#X obj 338 110 f; -#X obj 338 60 inlet; -#X text 344 29 mute; -#X obj 338 185 f; -#X msg 425 178 0; -#X msg 338 85 bang; -#X obj 338 135 moses 1; -#X obj 425 153 t b f; -#X obj 397 117 moses 1; -#X obj 83 148 dbtorms; -#X obj 397 92 r master-lvl; -#X obj 83 42 r master-lvl; -#X obj 338 210 s master-lvl; -#X obj 22 181 inlet~; -#X obj 199 41 inlet; -#X text 199 18 level; -#X obj 199 100 s master-lvl; -#X msg 96 65 set \$1; -#X obj 96 89 outlet; -#X msg 214 64 \; pd dsp 1; -#X obj 83 194 line~; -#X obj 22 212 *~; -#X obj 22 241 dac~; -#X obj 83 171 pack 0 50; -#X text 20 158 audio; -#X text 93 110 show level; -#X connect 0 0 4 0; -#X connect 1 0 7 0; -#X connect 2 0 6 0; -#X connect 4 0 13 0; -#X connect 5 0 13 0; -#X connect 6 0 1 0; -#X connect 7 0 0 0; -#X connect 7 1 8 0; -#X connect 8 0 5 0; -#X connect 9 1 4 1; -#X connect 10 0 24 0; -#X connect 11 0 1 1; -#X connect 11 0 9 0; -#X connect 12 0 10 0; -#X connect 12 0 18 0; -#X connect 14 0 22 0; -#X connect 15 0 17 0; -#X connect 15 0 20 0; -#X connect 18 0 19 0; -#X connect 21 0 22 1; -#X connect 22 0 23 0; -#X connect 22 0 23 1; -#X connect 24 0 21 0; -#X restore 29 533 pd output; -#X msg 87 505 MUTE; -#X text 126 504 <-- output amplitude; -#X obj 29 476 hip~ 5; -#X obj 29 297 -~; -#X obj 29 273 *~ 3; -#X obj 66 279 *~ 2; -#X floatatom 29 177 0 0 0; -#X obj 29 249 clip~ 0 0.667; -#X obj 39 450 delwrite~ delay1 2000; -#X floatatom 45 353 0 0 0; -#X text 79 176 <-- pitch; -#X text 75 352 <-- delay time; -#X text 238 450 write to delay line; -#X text 226 378 read from delay line; -#X text 64 426 add the original and the delayed signal; -#X obj 29 201 mtof; -#X msg 135 238 1; -#X obj 29 321 *~; -#X obj 29 225 phasor~ 0; -#X obj 135 286 tabread4~ dbtorms; -#X obj 135 262 adsr 100 100 2000 0 2000; -#X obj 29 427 +~; -#X obj 45 377 delread~ delay1 160; -#X obj 45 401 *~ 0.7; -#X text 103 401 feedback gain; +#N canvas 130 225 601 527 12; +#X floatatom 36 197 5 -30 130 0 - - -; +#X floatatom 58 322 0 0 0 0 - - -; +#X text 88 196 <-- pitch; +#X text 88 321 <-- delay time; +#X text 287 420 write to delay line; +#X text 246 346 read from delay line; +#X text 72 393 add the original and the delayed signal; +#X obj 36 233 mtof; +#X msg 111 233 1; +#X obj 37 282 *~; +#X obj 37 394 +~; +#X obj 58 370 *~ 0.7; +#X text 116 370 feedback gain; #X text 57 9 DELAYS WITH FEEDBACK; #X text 33 39 You can feed the result of a delread~ module back into its own delwrite~ \, as long as you're careful about stability. For -delays below 30 msec \, you can frequently hear teh resonant pitch. +delays below 30 msec \, you can frequently hear the resonant pitch. For longer delay times you get the famous old delay loop effect.; -#X text 32 118 We've added an amplitude control here so that teh test +#X obj 111 281 *~; +#X obj 111 257 adsr 1 100 1000 0 1000; +#X obj 37 463 output~; +#X text 32 118 We've added an amplitude control here so that the test oscillator only speaks while you're dragging the pitch up and down. -Be sure to try the shift key.; -#N canvas 0 0 600 392 conversion-tables 0; -#N canvas 0 0 450 300 graph1 0; -#X array dbtorms 123 float 1; -#A 0 0 0 1.25893e-05 1.41254e-05 1.58489e-05 1.77828e-05 1.99526e-05 -2.23872e-05 2.51189e-05 2.81838e-05 3.16228e-05 3.54813e-05 3.98107e-05 -4.46684e-05 5.01187e-05 5.62341e-05 6.30957e-05 7.07946e-05 7.94328e-05 -8.91251e-05 1e-04 0.000112202 0.000125893 0.000141254 0.000158489 0.000177828 -0.000199526 0.000223872 0.000251189 0.000281838 0.000316228 0.000354813 -0.000398107 0.000446684 0.000501187 0.000562341 0.000630957 0.000707946 -0.000794328 0.000891251 0.001 0.00112202 0.00125893 0.00141254 0.00158489 -0.00177828 0.00199526 0.00223872 0.00251189 0.00281838 0.00316228 0.00354813 -0.00398107 0.00446684 0.00501187 0.00562341 0.00630957 0.00707946 0.00794328 -0.00891251 0.01 0.0112202 0.0125893 0.0141254 0.0158489 0.0177828 0.0199526 -0.0223872 0.0251189 0.0281838 0.0316228 0.0354813 0.0398107 0.0446684 -0.0501187 0.0562341 0.0630957 0.0707946 0.0794328 0.0891251 0.1 0.112202 -0.125893 0.141254 0.158489 0.177828 0.199526 0.223872 0.251189 0.281838 -0.316228 0.354813 0.398107 0.446684 0.501187 0.562341 0.630957 0.707946 -0.794328 0.891251 1 1.12202 1.25893 1.41254 1.58489 1.77828 1.99526 -2.23872 2.51189 2.81838 3.16228 3.54813 3.98107 4.46684 5.01187 5.62341 -6.30957 7.07946 7.94328 8.91251 10 11.2202 12.5893; -#X coords 0 10 123 0 200 100 1; -#X restore 70 45 graph; -#X text 272 138 0; -#X text 274 38 10; -#X text 89 148 ------ 123 samples ------; -#N canvas 0 0 450 300 graph2 0; -#X array mtof 130 float 1; -#A 0 8.1758 8.66196 9.17702 9.72272 10.3009 10.9134 11.5623 12.2499 -12.9783 13.75 14.5676 15.4339 16.3516 17.3239 18.354 19.4454 20.6017 -21.8268 23.1247 24.4997 25.9565 27.5 29.1352 30.8677 32.7032 34.6478 -36.7081 38.8909 41.2034 43.6535 46.2493 48.9994 51.9131 55 58.2705 -61.7354 65.4064 69.2957 73.4162 77.7817 82.4069 87.3071 92.4986 97.9989 -103.826 110 116.541 123.471 130.813 138.591 146.832 155.563 164.814 -174.614 184.997 195.998 207.652 220 233.082 246.942 261.626 277.183 -293.665 311.127 329.628 349.228 369.994 391.995 415.305 440 466.164 -493.883 523.251 554.365 587.33 622.254 659.255 698.456 739.989 783.991 -830.609 880 932.328 987.767 1046.5 1108.73 1174.66 1244.51 1318.51 -1396.91 1479.98 1567.98 1661.22 1760 1864.66 1975.53 2093 2217.46 2349.32 -2489.02 2637.02 2793.83 2959.96 3135.96 3322.44 3520 3729.31 3951.07 -4186.01 4434.92 4698.64 4978.03 5274.04 5587.65 5919.91 6271.93 6644.88 -7040 7458.62 7902.13 8372.02 8869.84 9397.27 9956.06 10548.1 11175.3 -11839.8 12543.9 13289.8 14080; -#X coords 0 12000 130 0 200 100 1; -#X restore 77 222 graph; -#X text 87 330 ------ 130 samples ------; -#X text 286 315 0; -#X text 288 215 12000; -#N canvas 244 212 672 338 regenerate-tables 0; -#X msg 415 84 bang; -#X obj 415 113 t b b; -#X obj 474 177 f; -#X obj 512 177 + 1; -#X msg 483 147 0; -#X obj 415 142 until; -#X obj 474 211 t f f; -#X obj 414 238 mtof; -#X obj 405 202 sel 129; -#X obj 413 264 tabwrite mtof; -#X obj 35 227 moses 2; -#X msg 19 76 bang; -#X obj 19 105 t b b; -#X obj 90 166 f; -#X obj 128 166 + 1; -#X msg 112 138 0; -#X obj 19 134 until; -#X obj 11 194 sel 122; -#X msg 35 258 0; -#X obj 79 259 dbtorms; -#X obj 90 194 t f f; -#X obj 35 291 tabwrite dbtorms; -#X text 18 49 bang to recalculate dbtorms table; -#X text 356 50 bang to recalculate the mtof table; -#X connect 0 0 1 0; -#X connect 1 0 5 0; -#X connect 1 1 4 0; -#X connect 2 0 3 0; -#X connect 2 0 6 0; -#X connect 2 0 8 0; -#X connect 3 0 2 1; -#X connect 4 0 2 1; -#X connect 5 0 2 0; -#X connect 6 0 7 0; -#X connect 6 1 9 1; -#X connect 7 0 9 0; -#X connect 8 0 5 1; -#X connect 10 0 18 0; -#X connect 10 1 19 0; -#X connect 11 0 12 0; -#X connect 12 0 16 0; -#X connect 12 1 15 0; -#X connect 13 0 14 0; -#X connect 13 0 17 0; -#X connect 13 0 20 0; -#X connect 14 0 13 1; -#X connect 15 0 13 1; -#X connect 16 0 13 0; -#X connect 17 0 16 1; -#X connect 18 0 21 0; -#X connect 19 0 21 0; -#X connect 20 0 10 0; -#X connect 20 1 21 1; -#X restore 375 76 pd regenerate-tables; -#X restore 334 483 pd conversion-tables; -#X connect 1 0 2 1; -#X connect 2 0 1 0; -#X connect 3 0 2 2; -#X connect 5 0 2 0; -#X connect 6 0 20 0; -#X connect 7 0 6 0; -#X connect 8 0 6 1; -#X connect 9 0 18 0; -#X connect 9 0 19 0; -#X connect 10 0 7 0; -#X connect 12 0 25 0; -#X connect 18 0 21 0; -#X connect 19 0 23 0; -#X connect 20 0 24 0; -#X connect 21 0 8 0; -#X connect 21 0 10 0; -#X connect 22 0 20 1; -#X connect 23 0 22 0; -#X connect 24 0 11 0; -#X connect 24 0 5 0; -#X connect 25 0 26 0; -#X connect 26 0 24 1; +Be sure to try shift-dragging on the pitch control.; +#X text 330 495 updated for Pd version 0.37-1; +#X obj 36 257 phasor~; +#X obj 58 346 delread~ G02-del 160; +#X obj 77 419 delwrite~ G02-del 2000; +#X connect 0 0 7 0; +#X connect 0 0 8 0; +#X connect 1 0 21 0; +#X connect 7 0 20 0; +#X connect 8 0 16 0; +#X connect 9 0 10 0; +#X connect 10 0 17 0; +#X connect 10 0 17 1; +#X connect 10 0 22 0; +#X connect 11 0 10 1; +#X connect 15 0 9 1; +#X connect 16 0 15 0; +#X connect 16 0 15 1; +#X connect 20 0 9 0; +#X connect 21 0 11 0; diff --git a/pd/doc/3.audio.examples/G03.delay.variable.pd b/pd/doc/3.audio.examples/G03.delay.variable.pd index bb16de95..c2ece553 100644 --- a/pd/doc/3.audio.examples/G03.delay.variable.pd +++ b/pd/doc/3.audio.examples/G03.delay.variable.pd @@ -1,105 +1,55 @@ -#N canvas 100 17 671 522 12; -#X obj 63 306 hip~ 10; -#X floatatom 331 222; -#X obj 331 270 line~; -#X obj 331 246 pack 0 100; -#X floatatom 256 192; -#X floatatom 442 297; -#X obj 442 369 line~; -#X obj 442 345 pack 0 100; -#X obj 442 321 * 0.01; -#X floatatom 143 167; -#X obj 143 238 line~; -#X obj 143 214 pack 0 100; -#X obj 63 258 *~; -#X obj 63 282 cos~; -#X floatatom 63 135; -#X obj 63 159 mtof; -#X obj 63 183 * 0.5; -#X obj 63 330 clip~ -0.2 0.2; -#X obj 143 190 * 0.01; -#X obj 426 444 delwrite~ delay1 1000; -#X obj 63 354 +~; -#X obj 426 396 *~; -#X obj 256 336 vd~ delay1; -#X obj 256 288 *~; -#X obj 256 216 / 100; -#X floatatom 93 419; -#N canvas 159 26 495 266 output 0; -#X obj 338 160 t b; -#X obj 338 110 f; -#X obj 338 60 inlet; -#X text 344 29 mute; -#X obj 338 185 f; -#X msg 425 178 0; -#X msg 338 85 bang; -#X obj 338 135 moses 1; -#X obj 425 153 t b f; -#X obj 397 117 moses 1; -#X obj 83 148 dbtorms; -#X obj 397 92 r master-lvl; -#X obj 83 42 r master-lvl; -#X obj 338 210 s master-lvl; -#X obj 22 181 inlet~; -#X obj 199 41 inlet; -#X text 199 18 level; -#X obj 199 100 s master-lvl; -#X msg 96 65 set \$1; -#X obj 96 89 outlet; -#X msg 214 64 \; pd dsp 1; -#X obj 83 194 line~; -#X obj 22 212 *~; -#X obj 22 241 dac~; -#X obj 83 171 pack 0 50; -#X text 20 158 audio; -#X text 93 110 show level; -#X connect 0 0 4 0; -#X connect 1 0 7 0; -#X connect 2 0 6 0; -#X connect 4 0 13 0; -#X connect 5 0 13 0; -#X connect 6 0 1 0; -#X connect 7 0 0 0; -#X connect 7 1 8 0; -#X connect 8 0 5 0; -#X connect 9 1 4 1; -#X connect 10 0 24 0; -#X connect 11 0 1 1; -#X connect 11 0 9 0; -#X connect 12 0 10 0; -#X connect 12 0 18 0; -#X connect 14 0 22 0; -#X connect 15 0 17 0; -#X connect 15 0 20 0; -#X connect 18 0 19 0; -#X connect 21 0 22 1; -#X connect 22 0 23 0; -#X connect 22 0 23 1; -#X connect 24 0 21 0; -#X restore 64 447 pd output; -#X msg 122 419 MUTE; -#X text 161 418 <-- output amplitude; -#X obj 63 378 hip~ 5; -#X text 401 505 updated for Pd version 0.26; -#X obj 256 264 +~ 1; -#X obj 256 240 osc~ 0; -#X obj 256 312 +~ 1.46; -#X obj 426 420 clip~ -5 5; -#X text 43 35 This is a fuzzed FM generator going into a delay loop \, this time using a variable delay object (vd~). You can get several interesting effects this way. We have taken the precaution if clipping inside the loop to avoid instabilities. You can push the loop gain past 1 if you want \, it will just uscillate.; -#X text 184 165 <-- timbre; -#X text 96 136 <-- pitch; -#X text 300 192 <-- cycle frequency (hundredths); -#X text 361 222 <-- cycle depth (msec); -#X text 491 298 <-- feedback (hundredths); -#X text 86 9 VARIABLE DELAYS; -#X obj 63 207 osc~ 0; +#N canvas 100 17 660 504 12; +#X obj 33 305 hip~ 10; +#X floatatom 301 221 0 0 0 0 - - -; +#X obj 301 269 line~; +#X obj 301 245 pack 0 100; +#X floatatom 226 191 0 0 0 0 - - -; +#X floatatom 382 297 0 0 0 0 - - -; +#X obj 382 369 line~; +#X obj 382 345 pack 0 100; +#X obj 382 321 * 0.01; +#X floatatom 113 166 0 0 0 0 - - -; +#X obj 113 237 line~; +#X obj 113 213 pack 0 100; +#X obj 33 257 *~; +#X obj 33 281 cos~; +#X floatatom 33 134 0 0 0 0 - - -; +#X obj 33 158 mtof; +#X obj 33 182 * 0.5; +#X obj 33 329 clip~ -0.2 0.2; +#X obj 113 189 * 0.01; +#X obj 33 353 +~; +#X obj 361 395 *~; +#X obj 226 287 *~; +#X obj 226 215 / 100; +#X obj 33 377 hip~ 5; +#X obj 226 263 +~ 1; +#X obj 226 239 osc~ 0; +#X obj 226 311 +~ 1.46; +#X text 154 164 <-- timbre; +#X text 66 135 <-- pitch; +#X text 279 191 <-- cycle frequency (hundredths); +#X text 354 222 <-- cycle depth (msec); +#X text 431 298 <-- feedback (hundredths); +#X text 89 6 VARIABLE DELAYS; +#X obj 33 206 osc~ 0; +#X text 46 32 This is a fuzzed FM generator going into a delay loop +\, this time using a variable delay object (vd~). You can get several +interesting effects this way. We have taken the precaution of clipping +inside the loop to avoid instabilities. You can push the loop gain +past 1 if you want \, it will just oscillate.; +#X obj 32 409 output~; +#X obj 226 335 vd~ G03-del; +#X obj 361 443 delwrite~ G03-del 1000; +#X obj 361 419 clip~ -1 1; +#X text 387 481 updated for Pd version 0.37-1; #X connect 0 0 17 0; #X connect 1 0 3 0; -#X connect 2 0 23 1; +#X connect 2 0 21 1; #X connect 3 0 2 0; -#X connect 4 0 24 0; +#X connect 4 0 22 0; #X connect 5 0 8 0; -#X connect 6 0 21 1; +#X connect 6 0 20 1; #X connect 7 0 6 0; #X connect 8 0 7 0; #X connect 9 0 18 0; @@ -109,21 +59,19 @@ #X connect 13 0 0 0; #X connect 14 0 15 0; #X connect 15 0 16 0; -#X connect 16 0 42 0; -#X connect 17 0 20 0; +#X connect 16 0 33 0; +#X connect 17 0 19 0; #X connect 18 0 11 0; -#X connect 20 0 29 0; -#X connect 21 0 34 0; -#X connect 22 0 20 1; -#X connect 23 0 33 0; -#X connect 24 0 32 0; -#X connect 25 0 26 1; -#X connect 26 0 25 0; -#X connect 27 0 26 2; -#X connect 29 0 26 0; -#X connect 29 0 21 0; -#X connect 31 0 23 0; -#X connect 32 0 31 0; -#X connect 33 0 22 0; -#X connect 34 0 19 0; -#X connect 42 0 12 0; +#X connect 19 0 23 0; +#X connect 20 0 38 0; +#X connect 21 0 26 0; +#X connect 22 0 25 0; +#X connect 23 0 20 0; +#X connect 23 0 35 0; +#X connect 23 0 35 1; +#X connect 24 0 21 0; +#X connect 25 0 24 0; +#X connect 26 0 36 0; +#X connect 33 0 12 0; +#X connect 36 0 19 1; +#X connect 38 0 37 0; diff --git a/pd/doc/3.audio.examples/G04.control.blocksize.pd b/pd/doc/3.audio.examples/G04.control.blocksize.pd new file mode 100644 index 00000000..efae501a --- /dev/null +++ b/pd/doc/3.audio.examples/G04.control.blocksize.pd @@ -0,0 +1,79 @@ +#N canvas 100 17 637 513 12; +#N canvas 195 311 647 354 delay-writer 0; +#X obj 86 220 inlet~; +#X obj 86 326 outlet~; +#X obj 392 197 block~ 1; +#X obj 164 267 *~ 0.99; +#X obj 87 272 +~; +#X obj 165 221 inlet; +#X text 80 7 Because of the feedback \, the delwrite~ has to be computed +after the delread~. So we set the blocksize to 1 to minimize the resulting +delay.; +#X text 390 219 this object sets the; +#X text 389 236 block size for audio; +#X text 388 255 computations in this; +#X obj 165 244 delread~ G04-del; +#X obj 98 302 delwrite~ G04-del 1000; +#X text 79 183 incoming; +#X text 81 198 pulses; +#X text 165 182 delay; +#X text 166 197 time; +#X text 388 273 window. Must be a; +#X text 388 292 power of two.; +#X text 77 60 The smaller the blocksize the more expensive the computations +are \, so don't reduce it lower than you have to. Also \, it's a good +idea to isolate the portion of the patch that requires the smaller +block size \, and only run that portion that way. Here \, the pulses +that excite the delay line are computed outside this window \, and +the output level control as well.; +#X connect 0 0 4 0; +#X connect 3 0 4 1; +#X connect 4 0 1 0; +#X connect 4 0 11 0; +#X connect 5 0 10 0; +#X connect 10 0 3 0; +#X restore 153 420 pd delay-writer; +#X obj 283 384 expr 1000/$f1; +#X obj 283 358 mtof; +#X msg 153 355 1; +#X msg 192 355 0; +#X obj 153 254 metro 500; +#X obj 283 304 random 60; +#X obj 153 228 loadbang; +#X obj 283 330 + 30; +#X text 86 9 CONTROLLING DELAY WITH BLOCK~; +#X text 299 420 <-- here is the delay loop; +#X text 63 43 In situations where a delay read feeds back to a delay +write \, the minimum possible delay you can achieve is one block \, +which by default is 64 samples \, or 1.45 msec at 44100 Hz. You can +shorten the minimum delay by changing the block size. Do this in a +subpatch (open it to see how).; +#X obj 153 449 output~; +#X obj 153 387 vline~; +#X text 371 487 updated for Pd version 0.37-1; +#X text 61 124 Here we use this principle to make a harpisichord-like +sound by sending pulses into a recirculating delay line (which imitates +the travel of the wave up and down the harpsichord string.) This is +related to Karplus-Strong synthesis \, but the idea is probably much +older than their paper.; +#X text 33 328 this makes; +#X text 32 346 a rectangular; +#X text 31 384 long.; +#X text 409 366 length of delay line is; +#X text 410 384 1000/(frequency); +#X obj 192 329 del 1; +#X text 32 364 pulse 1 msec; +#X connect 0 0 12 0; +#X connect 0 0 12 1; +#X connect 1 0 0 1; +#X connect 2 0 1 0; +#X connect 3 0 13 0; +#X connect 4 0 13 0; +#X connect 5 0 3 0; +#X connect 5 0 6 0; +#X connect 5 0 21 0; +#X connect 6 0 8 0; +#X connect 7 0 5 0; +#X connect 8 0 2 0; +#X connect 13 0 0 0; +#X connect 21 0 4 0; diff --git a/pd/doc/3.audio.examples/G05.execution.order.pd b/pd/doc/3.audio.examples/G05.execution.order.pd new file mode 100644 index 00000000..d50c97a9 --- /dev/null +++ b/pd/doc/3.audio.examples/G05.execution.order.pd @@ -0,0 +1,79 @@ +#N canvas 100 17 683 605 12; +#X floatatom 424 290 0 0 100 0 - - -; +#X obj 59 404 +~; +#X text 86 9 ORDER OF EXECUTION OF DELWRITE~ AND DELREAD~/VD~; +#X text 42 29 If you're writing to and reading from a delay line \, +you have to get the write sorted before the read or else you'll never +get less than a block's delay. This patch compares a "wrong" flanger +with a "right" one:; +#X text 471 284 <-- delay in samples; +#X obj 94 490 *~; +#X obj 94 466 -~; +#N canvas 0 0 600 400 delay-writer 0; +#X obj 96 107 inlet~; +#X obj 96 180 outlet~; +#X obj 116 144 delwrite~ G05-d2 1000; +#X connect 0 0 1 0; +#X connect 0 0 2 0; +#X restore 283 403 pd delay-writer; +#N canvas 0 0 280 330 delay-reader 0; +#X obj 96 107 inlet~; +#X obj 89 267 outlet~; +#X obj 112 163 inlet~; +#X obj 89 237 +~; +#X obj 112 198 vd~ G05-d2; +#X connect 0 0 3 0; +#X connect 2 0 4 0; +#X connect 3 0 1 0; +#X connect 4 0 3 1; +#X restore 282 431 pd delay-reader; +#X obj 59 490 +~; +#X obj 424 313 / 44.1; +#X obj 59 534 output~; +#X obj 135 490 tgl 18 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 +1; +#X text 159 490 <-- off to hear left-hand side \; on to hear right +hand side.; +#X text 393 575 updated for Pd version 0.37-1; +#X obj 424 337 pack 0 30; +#N canvas 0 0 450 300 pulse 0; +#X obj 64 197 outlet~; +#X obj 63 93 phasor~ 50; +#X obj 63 119 *~ 100; +#X obj 63 144 clip~ 0.75 1.25; +#X obj 64 170 cos~; +#X connect 1 0 2 0; +#X connect 2 0 3 0; +#X connect 3 0 4 0; +#X connect 4 0 0 0; +#X restore 60 302 pd pulse; +#X obj 81 354 delwrite~ G05-d1 1000; +#X obj 82 381 vd~ G05-d1; +#X obj 424 362 line~; +#X text 44 96 To get them to go off in the correct order \, put the +delread~ and vd~ objects in subpatches. The audio connections between +the subpatches force the "reader" to be sorted after the "writer". +DSP sorting in Pd follows the hierarchy of subpatches.; +#X text 43 175 To hear the difference scroll the delay time between +0 and 100 samples. The patch at left doesn't let you get below 64 samples +\, but the patch at right can go all the way down to one sample.; +#X text 45 241 You can use the same strategy to avoid picking up unwanted +64-sample delays in send~/receive~ and throw~/catch~ pairs.; +#X connect 0 0 10 0; +#X connect 1 0 6 1; +#X connect 1 0 9 0; +#X connect 5 0 9 1; +#X connect 6 0 5 0; +#X connect 7 0 8 0; +#X connect 8 0 6 0; +#X connect 9 0 11 0; +#X connect 9 0 11 1; +#X connect 10 0 15 0; +#X connect 12 0 5 1; +#X connect 15 0 19 0; +#X connect 16 0 1 0; +#X connect 16 0 7 0; +#X connect 16 0 17 0; +#X connect 18 0 1 1; +#X connect 19 0 8 1; +#X connect 19 0 18 0; diff --git a/pd/doc/3.audio.examples/G06.octave.doubler.pd b/pd/doc/3.audio.examples/G06.octave.doubler.pd new file mode 100644 index 00000000..a95fe24e --- /dev/null +++ b/pd/doc/3.audio.examples/G06.octave.doubler.pd @@ -0,0 +1,114 @@ +#N canvas 110 17 775 614 12; +#X obj 463 303 loadbang; +#X obj 553 222 adc~ 1; +#X obj 463 358 soundfiler; +#X obj 31 394 output~; +#X obj 554 269 tabwrite~ E03-table; +#X msg 463 330 read ../sound/voice.wav E03-table; +#X obj 58 83 fiddle~ 2048; +#X obj 126 106 unpack; +#X obj 126 130 moses 1; +#X obj 199 108 mtof; +#N canvas 0 0 446 202 /SUBPATCH/ 0; +#X obj 261 30 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1 +; +#X obj 100 20 inlet~; +#X obj 99 87 *~; +#X obj 98 159 outlet~; +#X text 381 181 corner; +#X connect 0 0 2 1; +#X connect 1 0 2 0; +#X connect 2 0 3 0; +#X coords 0 0 100 100 40 18 1; +#X restore 77 329 pd; +#N canvas 0 0 446 202 /SUBPATCH/ 0; +#X obj 261 30 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 +; +#X obj 100 20 inlet~; +#X obj 99 87 *~; +#X obj 98 159 outlet~; +#X text 381 181 corner; +#X connect 0 0 2 1; +#X connect 1 0 2 0; +#X connect 2 0 3 0; +#X coords 0 0 100 100 40 18 1; +#X restore 31 329 pd; +#N canvas 414 195 613 302 looper 0; +#N canvas 0 0 450 300 graph1 0; +#X array E03-table 44103 float 0; +#X coords 0 1.02 44103 -1.02 200 130 1; +#X restore 349 22 graph; +#X text 347 161 ---- 44103 samples ----; +#X obj 35 77 +~ 1; +#X obj 35 25 phasor~ 1; +#X obj 35 50 *~ 44100; +#X obj 35 106 tabread4~ E03-table; +#X obj 35 132 outlet~; +#X text 46 238 one-second sample reader loop. You can replace this +with an adc~ if you want to go live.; +#X connect 2 0 5 0; +#X connect 3 0 4 0; +#X connect 4 0 2 0; +#X connect 5 0 6 0; +#X restore 31 30 pd looper; +#X text 547 309 re-read original sample; +#X obj 565 246 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X text 584 244 <-- record a sample; +#X text 152 314 on/off for original; +#X text 123 330 <--and processed sounds; +#X text 240 3 OCTAVE DOUBLING VIA VARIABLE COMB FILTER; +#X obj 31 367 +~; +#X obj 252 157 samplerate~; +#X obj 199 156 t f b; +#X obj 59 58 delwrite~ G06-del 100; +#X obj 79 234 delread~ G06-del; +#X obj 101 282 vd~ G06-del; +#X obj 78 306 +~; +#X obj 230 210 +; +#X obj 199 131 expr 500/$f1; +#X obj 230 262 line~; +#X obj 230 239 pack 0 20; +#X text 243 108 fundamental frequency; +#X text 311 131 1/2 period \, in msec; +#X text 286 201 estimate fiddle~ delay; +#X text 491 592 updated for Pd version 0.37-1; +#X text 159 401 We already saw how to use ring modulation to alias +a pitched sound down one octave. Here we do the reverse: filter out +all odd harmonics using a variable-delay comb filter tuned one octave +above the incoming sound. We use two taps into the delay line. The +fixed one (delread~) adjusts for the delayed output of fiddle~. The +variable one (vd~) adds to this an additional delay equal to 1/2 the +measured period of the incoming sound. THese two are added. Odd harmonics +are 180 degrees out of phase at the two taps and cancel. Even harmonics +get through - so the sound goes up an octave \, without denaturing +the timbre as a speed-up would.; +#X obj 252 183 expr 2048000/$f1; +#X text 288 216 as one window (in msec); +#X connect 0 0 5 0; +#X connect 1 0 4 0; +#X connect 5 0 2 0; +#X connect 6 2 7 0; +#X connect 7 0 8 0; +#X connect 8 1 9 0; +#X connect 9 0 27 0; +#X connect 10 0 19 1; +#X connect 11 0 19 0; +#X connect 12 0 6 0; +#X connect 12 0 11 0; +#X connect 12 0 22 0; +#X connect 14 0 4 0; +#X connect 19 0 3 0; +#X connect 19 0 3 1; +#X connect 20 0 35 0; +#X connect 21 0 26 0; +#X connect 21 1 20 0; +#X connect 23 0 25 0; +#X connect 24 0 25 1; +#X connect 25 0 10 0; +#X connect 26 0 29 0; +#X connect 27 0 21 0; +#X connect 28 0 24 0; +#X connect 29 0 28 0; +#X connect 35 0 26 1; +#X connect 35 0 23 0; diff --git a/pd/doc/3.audio.examples/G07.shaker.pd b/pd/doc/3.audio.examples/G07.shaker.pd new file mode 100644 index 00000000..1da97e8e --- /dev/null +++ b/pd/doc/3.audio.examples/G07.shaker.pd @@ -0,0 +1,80 @@ +#N canvas 159 89 808 531 12; +#X obj 21 438 output~; +#X obj 21 411 +~; +#X obj 33 192 delwrite~ G07-del 30; +#X obj 99 391 line~; +#X obj 63 391 *~; +#X obj 93 335 line~; +#X obj 57 335 *~; +#X obj 80 281 line~; +#X obj 44 281 *~; +#X obj 58 221 line~; +#X obj 22 221 *~; +#X text 51 8 THE "SHAKER"; +#X obj 279 86 + 1; +#X obj 279 109 mod 4; +#X obj 244 83 f; +#X obj 284 160 random 1000; +#X obj 244 135 t f b; +#X obj 244 37 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1 +; +#X floatatom 347 34 5 10 1000 0 - - -; +#X obj 244 242 route 0 1 2 3; +#X obj 44 255 delread~ G07-del 30; +#X obj 23 165 phasor~ 80; +#X obj 57 309 delread~ G07-del 17; +#X obj 63 365 delread~ G07-del 11; +#X obj 347 59 * 4; +#X obj 284 187 expr 2 * $f1/1000 - 0.7; +#X floatatom 23 142 5 30 1000 0 - - -; +#X obj 244 58 metro 50; +#X obj 244 218 pack 0 0 200; +#X text 23 118 frequency; +#X text 225 17 on/off; +#X text 344 13 time constant (msec); +#X text 536 511 updated for Pd version 0.37-1; +#X text 266 306 This is a time-varying comb filter \, combining four +delayed copies of the input signal. The amplitude of each delayed copy +varies randomly between -0.7 and +1.3. Each time the metronome goes +off \, one of the four delay's gains is changed in sequence. The change +occurs over the next four ticks of the metronome (so \, if the metronome +ticks every 50 msec \, each message to a line~ has a second argument +of 200.); +#X text 268 424 Any collection of four gains for the four delayed copies +of the signal (including the original) defines some sort of irregular +comb filter. The peaks and valleys of the comb filter shift constantly +as the gains change to new \, random values.; +#X connect 1 0 0 0; +#X connect 1 0 0 1; +#X connect 3 0 4 1; +#X connect 4 0 1 1; +#X connect 5 0 6 1; +#X connect 6 0 1 1; +#X connect 7 0 8 1; +#X connect 8 0 1 1; +#X connect 9 0 10 1; +#X connect 10 0 1 0; +#X connect 12 0 13 0; +#X connect 13 0 14 1; +#X connect 14 0 12 0; +#X connect 14 0 16 0; +#X connect 15 0 25 0; +#X connect 16 0 28 0; +#X connect 16 1 15 0; +#X connect 17 0 27 0; +#X connect 18 0 24 0; +#X connect 18 0 27 1; +#X connect 19 0 9 0; +#X connect 19 1 7 0; +#X connect 19 2 5 0; +#X connect 19 3 3 0; +#X connect 20 0 8 0; +#X connect 21 0 2 0; +#X connect 21 0 10 0; +#X connect 22 0 6 0; +#X connect 23 0 4 0; +#X connect 24 0 28 2; +#X connect 25 0 28 1; +#X connect 26 0 21 0; +#X connect 27 0 14 0; +#X connect 28 0 19 0; diff --git a/pd/doc/3.audio.examples/G08.reverb.pd b/pd/doc/3.audio.examples/G08.reverb.pd new file mode 100644 index 00000000..09941436 --- /dev/null +++ b/pd/doc/3.audio.examples/G08.reverb.pd @@ -0,0 +1,253 @@ +#N canvas 390 121 616 352 12; +#N canvas 0 0 499 321 test-input 0; +#X obj 75 253 outlet~; +#X obj 74 201 -~; +#X obj 74 177 *~ 3; +#X obj 111 183 *~ 2; +#X floatatom 74 81 0 0 0 0 - - -; +#X obj 74 153 clip~ 0 0.667; +#X text 124 80 <-- pitch; +#X obj 74 105 mtof; +#X msg 195 142 1; +#X obj 74 225 *~; +#X obj 74 129 phasor~ 0; +#X obj 195 190 tabread4~ dbtorms; +#X obj 195 166 adsr 100 100 2000 0 2000; +#X obj 73 54 inlet; +#N canvas 0 0 600 392 conversion-tables 0; +#N canvas 0 0 450 300 graph1 0; +#X array dbtorms 123 float 1; +#A 0 0 0 1.25893e-05 1.41254e-05 1.58489e-05 1.77828e-05 1.99526e-05 +2.23872e-05 2.51189e-05 2.81838e-05 3.16228e-05 3.54813e-05 3.98107e-05 +4.46684e-05 5.01187e-05 5.62341e-05 6.30957e-05 7.07946e-05 7.94328e-05 +8.91251e-05 1e-04 0.000112202 0.000125893 0.000141254 0.000158489 0.000177828 +0.000199526 0.000223872 0.000251189 0.000281838 0.000316228 0.000354813 +0.000398107 0.000446684 0.000501187 0.000562341 0.000630957 0.000707946 +0.000794328 0.000891251 0.001 0.00112202 0.00125893 0.00141254 0.00158489 +0.00177828 0.00199526 0.00223872 0.00251189 0.00281838 0.00316228 0.00354813 +0.00398107 0.00446684 0.00501187 0.00562341 0.00630957 0.00707946 0.00794328 +0.00891251 0.01 0.0112202 0.0125893 0.0141254 0.0158489 0.0177828 0.0199526 +0.0223872 0.0251189 0.0281838 0.0316228 0.0354813 0.0398107 0.0446684 +0.0501187 0.0562341 0.0630957 0.0707946 0.0794328 0.0891251 0.1 0.112202 +0.125893 0.141254 0.158489 0.177828 0.199526 0.223872 0.251189 0.281838 +0.316228 0.354813 0.398107 0.446684 0.501187 0.562341 0.630957 0.707946 +0.794328 0.891251 1 1.12202 1.25893 1.41254 1.58489 1.77828 1.99526 +2.23872 2.51189 2.81838 3.16228 3.54813 3.98107 4.46684 5.01187 5.62341 +6.30957 7.07946 7.94328 8.91251 10 11.2202 12.5893; +#X coords 0 10 123 0 200 100 1; +#X restore 70 45 graph; +#X text 272 138 0; +#X text 274 38 10; +#X text 89 148 ------ 123 samples ------; +#N canvas 0 0 450 300 graph2 0; +#X array mtof 130 float 1; +#A 0 8.1758 8.66196 9.17702 9.72272 10.3009 10.9134 11.5623 12.2499 +12.9783 13.75 14.5676 15.4339 16.3516 17.3239 18.354 19.4454 20.6017 +21.8268 23.1247 24.4997 25.9565 27.5 29.1352 30.8677 32.7032 34.6478 +36.7081 38.8909 41.2034 43.6535 46.2493 48.9994 51.9131 55 58.2705 +61.7354 65.4064 69.2957 73.4162 77.7817 82.4069 87.3071 92.4986 97.9989 +103.826 110 116.541 123.471 130.813 138.591 146.832 155.563 164.814 +174.614 184.997 195.998 207.652 220 233.082 246.942 261.626 277.183 +293.665 311.127 329.628 349.228 369.994 391.995 415.305 440 466.164 +493.883 523.251 554.365 587.33 622.254 659.255 698.456 739.989 783.991 +830.609 880 932.328 987.767 1046.5 1108.73 1174.66 1244.51 1318.51 +1396.91 1479.98 1567.98 1661.22 1760 1864.66 1975.53 2093 2217.46 2349.32 +2489.02 2637.02 2793.83 2959.96 3135.96 3322.44 3520 3729.31 3951.07 +4186.01 4434.92 4698.64 4978.03 5274.04 5587.65 5919.91 6271.93 6644.88 +7040 7458.62 7902.13 8372.02 8869.84 9397.27 9956.06 10548.1 11175.3 +11839.8 12543.9 13289.8 14080; +#X coords 0 12000 130 0 200 100 1; +#X restore 77 222 graph; +#X text 87 330 ------ 130 samples ------; +#X text 286 315 0; +#X text 288 215 12000; +#N canvas 244 212 672 338 regenerate-tables 0; +#X msg 415 84 bang; +#X obj 415 113 t b b; +#X obj 474 177 f; +#X obj 512 177 + 1; +#X msg 483 147 0; +#X obj 415 142 until; +#X obj 474 211 t f f; +#X obj 414 238 mtof; +#X obj 405 202 sel 129; +#X obj 413 264 tabwrite mtof; +#X obj 35 227 moses 2; +#X msg 19 76 bang; +#X obj 19 105 t b b; +#X obj 90 166 f; +#X obj 128 166 + 1; +#X msg 112 138 0; +#X obj 19 134 until; +#X obj 11 194 sel 122; +#X msg 35 258 0; +#X obj 79 259 dbtorms; +#X obj 90 194 t f f; +#X obj 35 291 tabwrite dbtorms; +#X text 18 49 bang to recalculate dbtorms table; +#X text 356 50 bang to recalculate the mtof table; +#X connect 0 0 1 0; +#X connect 1 0 5 0; +#X connect 1 1 4 0; +#X connect 2 0 3 0; +#X connect 2 0 6 0; +#X connect 2 0 8 0; +#X connect 3 0 2 1; +#X connect 4 0 2 1; +#X connect 5 0 2 0; +#X connect 6 0 7 0; +#X connect 6 1 9 1; +#X connect 7 0 9 0; +#X connect 8 0 5 1; +#X connect 10 0 18 0; +#X connect 10 1 19 0; +#X connect 11 0 12 0; +#X connect 12 0 16 0; +#X connect 12 1 15 0; +#X connect 13 0 14 0; +#X connect 13 0 17 0; +#X connect 13 0 20 0; +#X connect 14 0 13 1; +#X connect 15 0 13 1; +#X connect 16 0 13 0; +#X connect 17 0 16 1; +#X connect 18 0 21 0; +#X connect 19 0 21 0; +#X connect 20 0 10 0; +#X connect 20 1 21 1; +#X restore 375 76 pd regenerate-tables; +#X restore 260 101 pd conversion-tables; +#X connect 1 0 9 0; +#X connect 2 0 1 0; +#X connect 3 0 1 1; +#X connect 4 0 7 0; +#X connect 4 0 8 0; +#X connect 5 0 2 0; +#X connect 7 0 10 0; +#X connect 8 0 12 0; +#X connect 9 0 0 0; +#X connect 10 0 3 0; +#X connect 10 0 5 0; +#X connect 11 0 9 1; +#X connect 12 0 11 0; +#X connect 13 0 4 0; +#X restore 39 114 pd test-input; +#X text 135 6 REVERBERATOR; +#X floatatom 39 87 0 10 130 0 - - -; +#X text 76 87 <-- pitch; +#N canvas 96 169 958 610 reverb 0; +#X obj 13 19 inlet~; +#X obj 13 43 reverb-echo echo-del1 5.43216; +#X obj 277 215 +~; +#X obj 319 215 +~; +#X obj 67 276 outlet~; +#X obj 137 276 outlet~; +#X obj 238 334 +~; +#X obj 347 335 +~; +#X obj 280 334 -~; +#X obj 387 334 -~; +#X obj 237 390 +~; +#X obj 281 391 +~; +#X obj 325 392 -~; +#X obj 364 392 -~; +#X obj 324 474 *~ 0; +#X obj 282 473 *~ 0; +#X obj 237 472 *~ 0; +#X obj 365 475 *~ 0; +#X obj 632 365 inlet; +#X obj 632 437 / 200; +#X obj 632 389 min 100; +#X obj 632 412 max 0; +#X obj 238 583 delwrite~ loop-del1 60; +#X obj 283 561 delwrite~ loop-del2 71.9345; +#X obj 364 515 delwrite~ loop-del4 95.945; +#X obj 298 154 delread~ loop-del1 60; +#X obj 340 179 delread~ loop-del2 71.9345; +#X obj 408 233 delread~ loop-del4 95.945; +#X obj 386 208 delread~ loop-del3 86.7545; +#X obj 325 538 delwrite~ loop-del3 86.7545; +#X obj 13 67 reverb-echo echo-del2 8.45346; +#X obj 13 91 reverb-echo echo-del3 13.4367; +#X obj 13 115 reverb-echo echo-del4 21.5463; +#X obj 13 139 reverb-echo echo-del5 34.3876; +#X obj 13 163 reverb-echo echo-del6 55.5437; +#X text 286 42 "early echo" generators \, which also increase echo +density. Open one to see what they do.; +#X text 300 115 Get the outputs of the recirculating delays. Add the +inputs to two of them.; +#X text 420 313 Do a power-conserving mix of them in pairs. First combine +(1 \, 2) and (3 \, 4)...; +#X text 402 385 ...then (1 \, 3) and (2 \, 4); +#X text 446 469 The two mixing stages have a combined gain of 2 \, +so the recirculation gain is limited to 0.5.; +#X text 586 542 Put the signals back into the; +#X text 584 557 recirculating delays.; +#X text 29 296 Tap outputs from here.; +#X text 708 381 0 to 100 to control reverb; +#X text 719 396 time.; +#X text 691 364 feedback gain on a scale of; +#X connect 0 0 1 0; +#X connect 1 0 30 0; +#X connect 1 1 30 1; +#X connect 2 0 4 0; +#X connect 2 0 6 0; +#X connect 2 0 8 0; +#X connect 3 0 5 0; +#X connect 3 0 6 1; +#X connect 3 0 8 1; +#X connect 6 0 10 0; +#X connect 6 0 12 0; +#X connect 7 0 12 1; +#X connect 7 0 10 1; +#X connect 8 0 11 0; +#X connect 8 0 13 0; +#X connect 9 0 11 1; +#X connect 9 0 13 1; +#X connect 10 0 16 0; +#X connect 11 0 15 0; +#X connect 12 0 14 0; +#X connect 13 0 17 0; +#X connect 14 0 29 0; +#X connect 15 0 23 0; +#X connect 16 0 22 0; +#X connect 17 0 24 0; +#X connect 18 0 20 0; +#X connect 19 0 17 1; +#X connect 19 0 16 1; +#X connect 19 0 15 1; +#X connect 19 0 14 1; +#X connect 20 0 21 0; +#X connect 21 0 19 0; +#X connect 25 0 2 1; +#X connect 26 0 3 1; +#X connect 27 0 7 1; +#X connect 27 0 9 1; +#X connect 28 0 7 0; +#X connect 28 0 9 0; +#X connect 30 0 31 0; +#X connect 30 1 31 1; +#X connect 31 0 32 0; +#X connect 31 1 32 1; +#X connect 32 0 33 0; +#X connect 32 1 33 1; +#X connect 33 0 34 0; +#X connect 33 1 34 1; +#X connect 34 0 2 0; +#X connect 34 1 3 0; +#X restore 58 179 pd reverb; +#X floatatom 134 155 0 0 100 0 - - -; +#X text 169 155 <-- feedback (100 maximum); +#X obj 38 206 output~; +#X text 342 317 updated for Pd version 0.37-1; +#X text 149 180 <-- open to see how it works; +#X text 34 269 Many improvements are possible. Much better reverberators +can be found in the "extras" library.; +#X text 29 30 Here is a simple recirculating reverberator. "Feedback" +should be between 0 and 100 - if 100 \, the reverberation lasts forever. +; +#X connect 0 0 4 0; +#X connect 0 0 7 0; +#X connect 2 0 0 0; +#X connect 4 0 7 0; +#X connect 4 1 7 1; +#X connect 5 0 4 1; diff --git a/pd/doc/3.audio.examples/G09.pitchshift.pd b/pd/doc/3.audio.examples/G09.pitchshift.pd new file mode 100644 index 00000000..f0122b1b --- /dev/null +++ b/pd/doc/3.audio.examples/G09.pitchshift.pd @@ -0,0 +1,162 @@ +#N canvas 93 36 964 554 12; +#X floatatom 19 87 0 0 0 0 - - -; +#X obj 82 358 *~; +#X obj 205 295 line~; +#X floatatom 237 112 0 0 0 0 - - -; +#X text 68 9 PITCH SHIFTER; +#X obj 205 269 pack 0 200; +#X obj 237 86 r window; +#X obj 19 61 r transpose; +#X obj 19 143 exp; +#X floatatom 19 169 6 0 0 0 - - -; +#X obj 19 259 /; +#X obj 146 189 * 0.001; +#X obj 314 365 line~; +#X obj 314 340 pack 0 200; +#X floatatom 314 289 0 0 0 0 - - -; +#X obj 314 263 r delay; +#X obj 82 384 +~; +#X obj 19 410 cos~; +#X obj 19 437 *~; +#X obj 19 466 +~; +#X obj 106 317 wrap~; +#X obj 251 360 *~; +#X obj 251 393 +~; +#X obj 188 420 cos~; +#X obj 188 447 *~; +#X msg 492 56 \; transpose 0 \; window 100 \; delay 0; +#X obj 492 30 loadbang; +#X obj 264 42 delwrite~ delay1 5000; +#X obj 146 216 t b f; +#X floatatom 19 285 6 0 0 0 - - -; +#X obj 106 290 +~ 0.5; +#X obj 19 358 -~ 0.5; +#X obj 19 384 *~ 0.5; +#X obj 188 359 -~ 0.5; +#X obj 188 392 *~ 0.5; +#X obj 19 196 - 1; +#X obj 19 117 * 0.05776; +#X obj 19 222 * -1; +#X text 53 86 <-- transposition; +#X text 96 99 (halftones); +#X text 82 163 speed; +#X text 81 177 change; +#X text 281 111 <--window (msec); +#X text 54 252 tape head; +#N canvas 0 0 612 637 test-input 0; +#N canvas 0 0 450 300 graph1 0; +#X array array1 155948 float 0; +#X coords 0 1 155947 -1 200 150 1; +#X restore 150 141 graph; +#X obj 139 518 tabread4~ array1; +#X obj 139 333 r totsamps; +#X obj 139 413 /; +#X obj 139 465 *~ 0; +#X obj 139 439 phasor~ 0; +#X obj 139 492 +~ 1; +#X msg 139 386 44100; +#X obj 139 360 t b f; +#X obj 182 469 r totsamps; +#X text 153 538 sample loop for; +#X text 153 555 test signal; +#X obj 162 30 loadbang; +#X obj 139 590 outlet~; +#X obj 393 169 r readfile; +#X obj 393 199 symbol; +#X msg 392 228 read -resize \$1 array1; +#X obj 392 256 soundfiler; +#X obj 392 284 s totsamps; +#X msg 161 64 \; readfile ../sound/bell.aiff; +#X connect 1 0 13 0; +#X connect 2 0 8 0; +#X connect 3 0 5 0; +#X connect 4 0 6 0; +#X connect 5 0 4 0; +#X connect 6 0 1 0; +#X connect 7 0 3 0; +#X connect 8 0 7 0; +#X connect 8 1 3 1; +#X connect 9 0 4 1; +#X connect 12 0 19 0; +#X connect 14 0 15 0; +#X connect 15 0 16 0; +#X connect 16 0 17 0; +#X connect 17 0 18 0; +#X restore 264 11 pd test-input; +#X text 425 153 This is a classic rotating-tape-head style pitch shifter +using the vd~ variable delay object. Ther are two moving tape heads +\, each of which is loudest at the middle of its trajectory \, and +enveloped out at the moment it has to jump back (or forward) to start +another scratch. Most of the brain work is in computing how fast the +tape heads have to move to get the desired transposition.; +#X text 425 272 The "window size" is the total trajectory of the read +points in the delay line \, in milliseconds. The delay times are controlled +by a phasor~ object. The second delay time \, 180 degrees out of phase +from the first one \, is computed using the "wrap" object.; +#X text 423 362 The "window size" is the total trajectory of the read +points in the delay line \, in milliseconds. The delay times are controlled +by a phasor~ object. The second delay time \, 180 degrees out of phase +from the first one \, is computed using the "wrap" object.; +#X text 422 454 The cos~ objects compute the fadein and fadeout of +the two delay line outputs. They each traverse the positive half of +the cosine waveform (phase -0.25 to +0.25) over the time the phase +goes from one end to the other.; +#X obj 19 493 output~; +#X obj 19 316 phasor~; +#X text 689 534 updated for Pd version 0.37-1; +#X obj 314 316 max 1.5; +#X text 317 222 delay; +#X text 314 240 (msec); +#X obj 237 139 max 1; +#X text 55 265 rotation freq; +#X obj 82 410 vd~ G09-del; +#X obj 251 422 vd~ G09-del; +#X connect 0 0 36 0; +#X connect 1 0 16 0; +#X connect 2 0 1 1; +#X connect 2 0 21 1; +#X connect 3 0 55 0; +#X connect 5 0 2 0; +#X connect 6 0 3 0; +#X connect 7 0 0 0; +#X connect 8 0 9 0; +#X connect 9 0 35 0; +#X connect 10 0 29 0; +#X connect 11 0 28 0; +#X connect 12 0 16 1; +#X connect 12 0 22 1; +#X connect 13 0 12 0; +#X connect 14 0 52 0; +#X connect 15 0 14 0; +#X connect 16 0 57 0; +#X connect 17 0 18 0; +#X connect 18 0 19 0; +#X connect 19 0 49 0; +#X connect 19 0 49 1; +#X connect 20 0 21 0; +#X connect 20 0 33 0; +#X connect 21 0 22 0; +#X connect 22 0 58 0; +#X connect 23 0 24 0; +#X connect 24 0 19 1; +#X connect 26 0 25 0; +#X connect 28 0 10 0; +#X connect 28 1 10 1; +#X connect 29 0 50 0; +#X connect 30 0 20 0; +#X connect 31 0 32 0; +#X connect 32 0 17 0; +#X connect 33 0 34 0; +#X connect 34 0 23 0; +#X connect 35 0 37 0; +#X connect 36 0 8 0; +#X connect 37 0 10 0; +#X connect 44 0 27 0; +#X connect 50 0 1 0; +#X connect 50 0 31 0; +#X connect 50 0 30 0; +#X connect 52 0 13 0; +#X connect 55 0 11 0; +#X connect 55 0 5 0; +#X connect 57 0 18 1; +#X connect 58 0 24 1; diff --git a/pd/doc/3.audio.examples/K06.triangle.pd b/pd/doc/3.audio.examples/K06.triangle.pd new file mode 100644 index 00000000..ce8ac916 --- /dev/null +++ b/pd/doc/3.audio.examples/K06.triangle.pd @@ -0,0 +1,169 @@ +#N canvas 80 114 729 584 12; +#X obj 33 482 hip~ 5; +#X text 92 12 DELAYS; +#X obj 33 341 -~; +#X obj 30 241 tabread4~ mtof; +#X obj 33 317 *~ 3; +#X obj 74 318 *~ 2; +#X obj 49 266 phasor~; +#X floatatom 81 215 0 0 0 0 - - -; +#X obj 33 293 clip~ 0 0.667; +#X obj 30 190 line~; +#X obj 30 165 pack 0 1000; +#X obj 30 70 metro 1000; +#X obj 30 94 random 200; +#X obj 30 118 - 100; +#X obj 30 142 * 0.001; +#X obj 33 453 +~; +#X obj 44 374 delwrite~ delay1 2000; +#X floatatom 49 401 0 0 0 0 - - -; +#X obj 49 426 delread~ delay1 1000; +#X obj 30 47 loadbang; +#X text 210 37 You can delay a signal using the delwrite~ and delread~ +objects. In this example \, the pitch of the oscillator is varying +slightly so that the delayed signal is different from the straight +signal.; +#X text 212 99 delread always delays the signal an integer number of +samples and does no interpolation.; +#X text 211 137 The delwrite~ object creates the delay line \; you +give it a name and a size in milliseconds. Each delwrite~ should have +a different name.; +#X text 209 184 Delread~'s arguments are the name of a delwrite (of +which there should be exactly one) and a delay time in milliseconds +between 0 and the length of the delay line. Each delwrite~ may have +as many delread~s as you wish \, which function as multiple delay taps. +; +#X obj 30 215 +~ 60; +#X text 115 216 <-- pitch; +#X text 83 401 <-- delay time; +#X text 65 342 asymmetric triangle wave; +#X text 236 372 write to delay line; +#X text 232 425 read from delay line; +#X text 64 454 add the original and the delayed signal; +#N canvas 0 0 600 392 conversion-tables 0; +#N canvas 0 0 450 300 graph1 0; +#X array dbtorms 123 float 1; +#A 0 0 0 1.25893e-05 1.41254e-05 1.58489e-05 1.77828e-05 1.99526e-05 +2.23872e-05 2.51189e-05 2.81838e-05 3.16228e-05 3.54813e-05 3.98107e-05 +4.46684e-05 5.01187e-05 5.62341e-05 6.30957e-05 7.07946e-05 7.94328e-05 +8.91251e-05 1e-04 0.000112202 0.000125893 0.000141254 0.000158489 0.000177828 +0.000199526 0.000223872 0.000251189 0.000281838 0.000316228 0.000354813 +0.000398107 0.000446684 0.000501187 0.000562341 0.000630957 0.000707946 +0.000794328 0.000891251 0.001 0.00112202 0.00125893 0.00141254 0.00158489 +0.00177828 0.00199526 0.00223872 0.00251189 0.00281838 0.00316228 0.00354813 +0.00398107 0.00446684 0.00501187 0.00562341 0.00630957 0.00707946 0.00794328 +0.00891251 0.01 0.0112202 0.0125893 0.0141254 0.0158489 0.0177828 0.0199526 +0.0223872 0.0251189 0.0281838 0.0316228 0.0354813 0.0398107 0.0446684 +0.0501187 0.0562341 0.0630957 0.0707946 0.0794328 0.0891251 0.1 0.112202 +0.125893 0.141254 0.158489 0.177828 0.199526 0.223872 0.251189 0.281838 +0.316228 0.354813 0.398107 0.446684 0.501187 0.562341 0.630957 0.707946 +0.794328 0.891251 1 1.12202 1.25893 1.41254 1.58489 1.77828 1.99526 +2.23872 2.51189 2.81838 3.16228 3.54813 3.98107 4.46684 5.01187 5.62341 +6.30957 7.07946 7.94328 8.91251 10 11.2202 12.5893; +#X coords 0 10 123 0 200 100 1; +#X restore 70 45 graph; +#X text 272 138 0; +#X text 274 38 10; +#X text 89 148 ------ 123 samples ------; +#N canvas 0 0 450 300 graph2 0; +#X array mtof 130 float 1; +#A 0 8.1758 8.66196 9.17702 9.72272 10.3009 10.9134 11.5623 12.2499 +12.9783 13.75 14.5676 15.4339 16.3516 17.3239 18.354 19.4454 20.6017 +21.8268 23.1247 24.4997 25.9565 27.5 29.1352 30.8677 32.7032 34.6478 +36.7081 38.8909 41.2034 43.6535 46.2493 48.9994 51.9131 55 58.2705 +61.7354 65.4064 69.2957 73.4162 77.7817 82.4069 87.3071 92.4986 97.9989 +103.826 110 116.541 123.471 130.813 138.591 146.832 155.563 164.814 +174.614 184.997 195.998 207.652 220 233.082 246.942 261.626 277.183 +293.665 311.127 329.628 349.228 369.994 391.995 415.305 440 466.164 +493.883 523.251 554.365 587.33 622.254 659.255 698.456 739.989 783.991 +830.609 880 932.328 987.767 1046.5 1108.73 1174.66 1244.51 1318.51 +1396.91 1479.98 1567.98 1661.22 1760 1864.66 1975.53 2093 2217.46 2349.32 +2489.02 2637.02 2793.83 2959.96 3135.96 3322.44 3520 3729.31 3951.07 +4186.01 4434.92 4698.64 4978.03 5274.04 5587.65 5919.91 6271.93 6644.88 +7040 7458.62 7902.13 8372.02 8869.84 9397.27 9956.06 10548.1 11175.3 +11839.8 12543.9 13289.8 14080 ; +#X coords 0 12000 130 0 200 100 1; +#X restore 77 222 graph; +#X text 87 330 ------ 130 samples ------; +#X text 286 315 0; +#X text 288 215 12000; +#N canvas 244 212 672 338 regenerate-tables 0; +#X msg 415 84 bang; +#X obj 415 113 t b b; +#X obj 474 177 f; +#X obj 512 177 + 1; +#X msg 483 147 0; +#X obj 415 142 until; +#X obj 474 211 t f f; +#X obj 414 238 mtof; +#X obj 405 202 sel 129; +#X obj 413 264 tabwrite mtof; +#X obj 35 227 moses 2; +#X msg 19 76 bang; +#X obj 19 105 t b b; +#X obj 90 166 f; +#X obj 128 166 + 1; +#X msg 112 138 0; +#X obj 19 134 until; +#X obj 11 194 sel 122; +#X msg 35 258 0; +#X obj 79 259 dbtorms; +#X obj 90 194 t f f; +#X obj 35 291 tabwrite dbtorms; +#X text 18 49 bang to recalculate dbtorms table; +#X text 356 50 bang to recalculate the mtof table; +#X connect 0 0 1 0; +#X connect 1 0 5 0; +#X connect 1 1 4 0; +#X connect 2 0 3 0; +#X connect 2 0 6 0; +#X connect 2 0 8 0; +#X connect 3 0 2 1; +#X connect 4 0 2 1; +#X connect 5 0 2 0; +#X connect 6 0 7 0; +#X connect 6 1 9 1; +#X connect 7 0 9 0; +#X connect 8 0 5 1; +#X connect 10 0 18 0; +#X connect 10 1 19 0; +#X connect 11 0 12 0; +#X connect 12 0 16 0; +#X connect 12 1 15 0; +#X connect 13 0 14 0; +#X connect 13 0 17 0; +#X connect 13 0 20 0; +#X connect 14 0 13 1; +#X connect 15 0 13 1; +#X connect 16 0 13 0; +#X connect 17 0 16 1; +#X connect 18 0 21 0; +#X connect 19 0 21 0; +#X connect 20 0 10 0; +#X connect 20 1 21 1; +#X restore 375 76 pd regenerate-tables; +#X restore 449 418 pd conversion-tables; +#X text 427 536 updated for Pd version 0.35; +#X obj 33 510 output~; +#X connect 0 0 33 0; +#X connect 0 0 33 1; +#X connect 2 0 15 0; +#X connect 2 0 16 0; +#X connect 3 0 6 0; +#X connect 4 0 2 0; +#X connect 5 0 2 1; +#X connect 6 0 5 0; +#X connect 6 0 8 0; +#X connect 7 0 24 1; +#X connect 8 0 4 0; +#X connect 9 0 24 0; +#X connect 10 0 9 0; +#X connect 11 0 12 0; +#X connect 12 0 13 0; +#X connect 13 0 14 0; +#X connect 14 0 10 0; +#X connect 15 0 0 0; +#X connect 17 0 18 0; +#X connect 18 0 15 1; +#X connect 19 0 11 0; +#X connect 24 0 3 0; diff --git a/pd/doc/4.fft.examples/09.pvoc.pd b/pd/doc/4.fft.examples/09.pvoc.pd index 495fd535..2af30f2b 100644 --- a/pd/doc/4.fft.examples/09.pvoc.pd +++ b/pd/doc/4.fft.examples/09.pvoc.pd @@ -1,8 +1,8 @@ #N canvas 100 38 719 544 12; -#X floatatom 283 336; +#X floatatom 283 336 0 0 0 0 - - -; #X msg 569 149 bang; -#X floatatom 197 329; -#X floatatom 90 330; +#X floatatom 197 329 0 0 0 0 - - -; +#X floatatom 90 330 0 0 0 0 - - -; #N canvas 0 2 986 683 fft-analysis 0; #X obj 261 297 *~; #X obj 230 297 *~; @@ -18,7 +18,7 @@ #X obj 220 179 *~; #X obj 86 556 *~; #X obj 366 251 rfft~; -#X obj 387 53 rfft~; +#X obj 432 52 rfft~; #X obj 477 637 *~; #X obj 685 288 r window-size; #X obj 751 201 r sample-rate; @@ -64,19 +64,18 @@ #X obj 309 150 -~; #X obj 231 255 *~; #X obj 291 255 *~; -#X obj 198 51 tabreceive~ phase-imag; +#X obj 227 52 tabreceive~ phase-imag; #X obj 105 381 sig~; #X obj 88 311 t b f; #X msg 88 332 1; #X obj 102 355 /; #X obj 227 436 tabsend~ phase-real; #X obj 256 408 tabsend~ phase-imag; -#X obj 104 133 sig~ 1.5e-20; #X obj 632 180 * 0.01; #X obj 691 212 s speed; #X obj 468 251 s see-location; #X obj 598 618 block~ 2048 4; -#X floatatom 672 360; +#X floatatom 672 360 0 0 0 0 - - -; #X obj 670 339 *; #X obj 829 234 r transpo; #X obj 829 256 * 0.01; @@ -85,10 +84,11 @@ #X obj 832 320 / 440; #X obj 689 316 t b f; #X obj 88 290 r window-size; -#X floatatom 835 353; +#X floatatom 835 353 0 0 0 0 - - -; #X obj 551 543 tabreceive~ hanning; #X obj 536 488 tabread4~ sample; #X obj 502 513 tabread4~ sample; +#X obj 116 126 sig~ 1e-15; #X connect 0 0 2 1; #X connect 1 0 2 0; #X connect 2 0 65 0; @@ -115,11 +115,11 @@ #X connect 14 1 6 1; #X connect 14 1 8 1; #X connect 15 0 14 0; -#X connect 16 0 73 0; +#X connect 16 0 72 0; #X connect 17 0 44 0; #X connect 18 0 37 0; #X connect 18 0 45 0; -#X connect 18 0 70 0; +#X connect 18 0 69 0; #X connect 19 0 34 0; #X connect 20 0 22 0; #X connect 21 0 22 0; @@ -132,16 +132,16 @@ #X connect 30 0 18 0; #X connect 31 0 27 0; #X connect 31 0 50 0; -#X connect 31 0 84 0; +#X connect 31 0 83 0; #X connect 32 0 43 2; #X connect 32 0 38 1; #X connect 34 0 21 0; -#X connect 35 0 68 0; +#X connect 35 0 67 0; #X connect 36 0 39 0; #X connect 36 0 18 1; #X connect 37 0 18 1; #X connect 38 0 37 1; -#X connect 39 0 69 0; +#X connect 39 0 68 0; #X connect 40 0 43 1; #X connect 41 0 43 0; #X connect 41 1 40 0; @@ -151,7 +151,7 @@ #X connect 45 0 41 0; #X connect 47 0 49 0; #X connect 49 0 50 1; -#X connect 50 0 83 0; +#X connect 50 0 82 0; #X connect 53 0 9 0; #X connect 53 0 6 0; #X connect 54 0 55 0; @@ -172,40 +172,43 @@ #X connect 62 1 64 1; #X connect 63 0 64 0; #X connect 64 0 61 0; -#X connect 67 0 10 0; -#X connect 68 0 38 0; -#X connect 72 0 47 0; -#X connect 72 0 40 1; -#X connect 73 0 72 0; +#X connect 67 0 38 0; +#X connect 71 0 47 0; +#X connect 71 0 40 1; +#X connect 72 0 71 0; +#X connect 73 0 74 0; #X connect 74 0 75 0; #X connect 75 0 76 0; #X connect 76 0 77 0; #X connect 77 0 78 0; -#X connect 78 0 79 0; -#X connect 78 0 81 0; -#X connect 79 0 73 0; -#X connect 79 1 73 1; -#X connect 80 0 62 0; -#X connect 82 0 23 1; -#X connect 82 0 15 1; -#X connect 82 0 12 1; -#X connect 83 0 23 0; -#X connect 84 0 15 0; +#X connect 77 0 80 0; +#X connect 78 0 72 0; +#X connect 78 1 72 1; +#X connect 79 0 62 0; +#X connect 81 0 23 1; +#X connect 81 0 15 1; +#X connect 81 0 12 1; +#X connect 82 0 23 0; +#X connect 83 0 15 0; +#X connect 84 0 10 0; #X restore 43 402 pd fft-analysis; #X obj 43 488 dac~; #N canvas 260 23 647 768 phase-tables 0; -#X graph graph2 0 -1 4096 1 172 590 572 290; -#X array phase-imag 4096 float; -#X pop; -#X graph graph3 0 -1 4096 1 170 317 570 17; -#X array phase-real 4096 float; -#X pop; -#X msg 167 564 \; phase-real resize 4096 \; phase-imag resize 4096; +#N canvas 0 0 450 300 graph2 0; +#X array phase-imag 4096 float 0; +#X coords 0 1 4096 -1 400 300 1; +#X restore 172 290 graph; +#N canvas 0 0 450 300 graph3 0; +#X array phase-real 4096 float 0; +#X coords 0 1 4096 -1 400 300 1; +#X restore 170 17 graph; +#X msg 167 564 \; phase-real resize 4096 \; phase-imag resize 4096 +; #X restore 425 441 pd phase-tables; #X obj 43 428 hip~ 5; #X obj 43 458 *~; #N canvas 249 280 600 398 loc&precess 0; -#X floatatom 160 229; +#X floatatom 160 229 0 0 0 0 - - -; #X msg 270 175 set \$1; #X obj 269 207 outlet; #X obj 83 267 outlet; @@ -259,9 +262,10 @@ #X msg 37 180 0; #X text 141 13 CALCULATE HANNING; #X text 141 27 WINDOW TABLE; -#X graph graph1 0 -1 4096 1 275 581 675 281; -#X array hanning 4096 float; -#X pop; +#N canvas 0 0 450 300 graph1 0; +#X array hanning 4096 float 0; +#X coords 0 1 4096 -1 400 300 1; +#X restore 275 281 graph; #X obj 93 171 sig~; #X text 175 148 sample rate / window size; #X msg 23 144 bang; @@ -290,7 +294,7 @@ #X connect 18 0 9 0; #X restore 423 464 pd hanning-window; #X msg 31 172 \; window-size 2048 \; transpo 0 \; pd dsp 1; -#X floatatom 587 68; +#X floatatom 587 68 0 0 0 0 - - -; #N canvas 194 37 397 591 output 0; #X obj 62 191 t b; #X obj 62 144 f; @@ -336,7 +340,7 @@ #X text 261 3 PHASE VOCODER; #X obj 87 486 line~; #X obj 87 462 r master-amp; -#X text 108 30 This is a Fourier-based analysis/resynthesis tool.; +#X text 47 30 This is a Fourier-based analysis/resynthesis tool.; #X text 55 251 set location; #X text 54 265 and stop; #X text 54 279 precession; @@ -353,9 +357,10 @@ #X obj 429 363 samplerate~; #X obj 425 385 s sample-rate; #N canvas 132 255 634 327 insample 0; -#X graph graph1 0 -1 155947 1 199 168 599 18; -#X array sample 155948 float; -#X pop; +#N canvas 0 0 450 300 graph1 0; +#X array sample 155948 float 0; +#X coords 0 1 155947 -1 400 150 1; +#X restore 199 18 graph; #X obj 19 70 r read-sample; #X obj 19 95 unpack s f; #X obj 53 121 s insamprate; @@ -371,8 +376,11 @@ #X restore 425 415 pd insample; #X msg 196 146 \; read-sample ../sound/bell.aiff \; transpo 0; #X msg 196 197 \; read-sample ../sound/voice.wav \; transpo -530; -#X text 107 99 The second soundfile read button sets the transposition to correct for the 32000 sample rate of the file.; -#X text 108 50 You can move forward or backward in the sample \, or "freeze" at any point using the "precession" and "location" controls. Transposition is in hundredths of a half-tone.; +#X text 46 99 The second soundfile read button sets the transposition +to correct for the 32000 sample rate of the file.; +#X text 47 50 You can move forward or backward in the sample \, or +"freeze" at any point using the "precession" and "location" controls. +Transposition is in hundredths of a half-tone.; #X obj 569 184 tabwrite~ sample; #X connect 0 0 13 0; #X connect 1 0 50 0; diff --git a/pd/doc/5.reference/tabosc4~-help.pd b/pd/doc/5.reference/tabosc4~-help.pd index ada694e1..9caf5291 100644 --- a/pd/doc/5.reference/tabosc4~-help.pd +++ b/pd/doc/5.reference/tabosc4~-help.pd @@ -1,5 +1,5 @@ #N canvas 307 35 742 511 12; -#X floatatom 66 450 0 0 0; +#X floatatom 66 450 0 0 0 0 - - -; #N canvas 159 26 495 270 output 0; #X obj 414 196 t b; #X obj 414 134 f; @@ -54,11 +54,12 @@ #X restore 32 476 pd output; #X msg 102 450 MUTE; #X text 148 449 <--- volume in dB; -#X floatatom 32 296 4 0 0; +#X floatatom 32 296 4 0 0 0 - - -; #X obj 32 326 sig~ 100; #X obj 547 52 table table1; #X obj 547 80 table table2; -#X msg 372 287 \; table1 sinesum 512 0.5 0.5 0.5 0.5 \; table2 cosinesum 512 0 1; +#X msg 372 287 \; table1 sinesum 512 0.5 0.5 0.5 0.5 \; table2 cosinesum +512 0 1; #X text 433 474 Updated for Pd version 0.33; #X obj 20 11 tabosc4~; #X text 110 12 4-point interpolating oscillator; @@ -67,14 +68,23 @@ #X msg 156 372 set table2; #X text 372 343 click above \, start DSP \, and turn output; #X text 372 361 volume up to hear this; -#X text 14 40 tabosc4~ is a traditional computer music style wavetable lookup oscillator using 4-point polynomial interpolation. The table should have a poiwer of two points plus three "guard points" \, one at the beginning and two at the end \, which should be wraparound copies of the last point and the first two points \, respectively. The "sinesum" and "cosinesum" methods for arrays do this automatically for you if you just want to specify partial strengths.; -#X text 14 178 For good results use 512 points for up to about 15 partials \, or 32*npartials (rounded up to a power of 2) for more than 15; -#X floatatom 275 391 4 0 0; -#X text 12 233 Don't send new "sinesum" messages to tables while you're running -- instead \, use "set" messages to switch between tables.; +#X text 14 178 For good results use 512 points for up to about 15 partials +\, or 32*npartials (rounded up to a power of 2) for more than 15; +#X floatatom 275 391 4 0 0 0 - - -; +#X text 12 233 Don't send new "sinesum" messages to tables while you're +running -- instead \, use "set" messages to switch between tables. +; #X text 80 298 signal input for frequency (Hz.); #X text 46 349 message to switch tables; #X text 325 391 inlet to reset phase; #X text 166 414 creation argument initializes table; +#X text 14 40 tabosc4~ is a traditional computer music style wavetable +lookup oscillator using 4-point polynomial interpolation. The table +should have a power of two points plus three "guard points" \, one +at the beginning and two at the end \, which should be wraparound copies +of the last point and the first two points \, respectively. The "sinesum" +and "cosinesum" methods for arrays do this automatically for you if +you just want to specify partial strengths.; #X connect 0 0 1 1; #X connect 1 0 0 0; #X connect 2 0 1 2; @@ -83,4 +93,4 @@ #X connect 12 0 13 0; #X connect 13 0 1 0; #X connect 14 0 13 0; -#X connect 19 0 13 1; +#X connect 18 0 13 1; diff --git a/pd/doc/6.externs/makefile b/pd/doc/6.externs/makefile index a4e9308c..8a5657fe 100644 --- a/pd/doc/6.externs/makefile +++ b/pd/doc/6.externs/makefile @@ -10,7 +10,7 @@ pd_nt: obj1.dll obj2.dll obj3.dll obj4.dll obj5.dll dspobj~.dll .SUFFIXES: .obj .dll PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo -VC="C:\Program Files\Microsoft Visual Studio\Vc98" +VC="D:\Program Files\Microsoft Visual Studio\Vc98" PDNTINCLUDE = /I. /I\tcl\include /I..\..\src /I$(VC)\include diff --git a/pd/extra/choice/makefile b/pd/extra/choice/makefile index 074ad026..10021e24 100644 --- a/pd/extra/choice/makefile +++ b/pd/extra/choice/makefile @@ -35,7 +35,7 @@ SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 SGIINCLUDE = -I../../src .c.pd_irix5: - cc $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + $(CC) $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o rm $*.o @@ -50,7 +50,7 @@ SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ -Ofast=ip32 .c.pd_irix6: - cc $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c + $(CC) $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o rm $*.o @@ -67,7 +67,7 @@ LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \ LINUXINCLUDE = -I../../src .c.pd_linux: - cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + $(CC) $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c ld -export_dynamic -shared -o $*.pd_linux $*.o -lc -lm strip --strip-unneeded $*.pd_linux rm -f $*.o @@ -82,8 +82,8 @@ DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ -Wno-unused -Wno-parentheses -Wno-switch .c.pd_darwin: - cc $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c - cc -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o + $(CC) $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + $(CC) -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o rm -f $*.o # ---------------------------------------------------------- diff --git a/pd/extra/expr~/README.txt b/pd/extra/expr~/README.txt new file mode 100644 index 00000000..bf84f2ae --- /dev/null +++ b/pd/extra/expr~/README.txt @@ -0,0 +1,97 @@ + +You can get more information on the expr object at +http://www.crca.ucsd.edu/~yadegari/expr.html + +----------- + +New if Version 0.4 + +-access to variables (made by value object) +-multiple expression separated by ; +-added the following shorthands: + $y or $y1 = $y1[-1] and $y2 = $y2[-1] +-new functions: + if - conditional evaluation + cbrt - cube root + erf - error function + erfc - complementary error function + expm1 - exponential minus 1, + log1p - logarithm of 1 plus + isinf - is the value infinite, + finite - is the value finite + isnan -- is the resut a nan (Not a number) + copysign - copy sign of a number + ldexp - multiply floating-point number by integral power of 2 + imodf - get signed integral value from floating-point number + modf - get signed fractional value from floating-point number + drem - floating-point remainder function + + Thanks to Orm Finnendahl for adding the following functions: + fmod - floating-point remainder function + ceil - ceiling function: smallest integral value not less than argument + floor - largest integral value not greater than argument + +------------ + +New in Version 0.3 +-Full function functionality + +------------ + +The object "expr" is used for expression evaluaion of control data. + +Expr~ and fexpr~ are extentions to the expr object to work with vectors. +The expr~ object is designed to efficiently combine signal and control +stream processing by vector operations on the basis of the block size of +the environment. + +fexpr~ object provides a flexible mechanism for building FIR and +IIR filters by evaluating expressions on a sample by sample basis +and providing access to prior samples of the input and output audio +streams. When fractional offset is used, fexpr~ uses linear interpolation +to determine the value of the indexed sample. fexpr~ evaluates the +expression for every single sample and at every evaluation previous +samples (limited by the audio vector size) can be accessed. $x is used to +denote a singnal input whose samples we would like to access. The syntax +is $x followed by the inlet number and indexed by brackets, for example +$x1[-1] specifies the previous sample of the first inlet. Therefore, +if we are to build a simple filter which replaces every sample by +the average of that sample and its previous one, we would use "fexpr~ +($x1[0]+$x1[-1])/2 ". For ease of when the brackets are omitted, the +current sample is implied, so we can right the previous filter expression +as follows: " fexpr~ ($x1+$x1[-1])/2". To build IIR filters $y is used +to access the previous samples of the output stream. + +The three objects expr, expr~, and fexpr~ are implemented in the same object +so the files expr~.pd_linux and fexpr~.pd_linux are links to expr.pd_linux +This release has been compiled and tested on Linux 6.0. + +-------- + +Here are some syntax information: (refer to help-expr.pd for examples) + +Syntyax: +The syntax is very close to how expression are written in +C. Variables are specified as follows where the '#' stands +for the inlet number: +$i#: integer input variable +$f#: float input variable +$s#: symbol input variable + +Used for expr~ only: +$v#: signal (vector) input (vector by vector evaluation) + +Used for fexpr~ only: +$x#[n]: the sample from inlet # indexed by n, where n has to + satisfy 0 => n >= -vector size, + ($x# is a shorthand for $x#[0], specifying the current sample) + +$y#[n]: the output value indexed by n, where n has to + satisfy 0 > n >= -vector size, + $y[n] is a shorthand for $y1[n] + + +I'll appreciate hearing about bugs, comments, suggestions, ... + +Shahrokh Yadegari (sdy@ucsd.edu) +7/10/02 diff --git a/pd/extra/help-rev2~.pd b/pd/extra/help-rev2~.pd index cea8c5da..8f9fbaaf 100644 --- a/pd/extra/help-rev2~.pd +++ b/pd/extra/help-rev2~.pd @@ -25,6 +25,7 @@ #X obj 96 101 0; #X obj 41 355 outlet~; #X obj 279 126 inlet; +#X obj 40 175 *~; #X connect 0 0 17 0; #X connect 1 0 8 0; #X connect 2 0 3 0; @@ -47,13 +48,16 @@ #X connect 13 0 6 1; #X connect 14 0 6 1; #X connect 15 0 2 0; -#X connect 16 0 21 0; +#X connect 16 0 23 0; #X connect 17 0 18 0; #X connect 17 0 19 0; #X connect 18 0 20 0; #X connect 19 0 16 0; +#X connect 19 0 23 1; #X connect 20 0 16 0; +#X connect 20 0 23 1; #X connect 22 0 15 0; +#X connect 23 0 21 0; #X restore 17 154 pd tests; #X msg 56 35 10; #X msg 54 62 20; diff --git a/pd/extra/help-rev3~.pd b/pd/extra/help-rev3~.pd new file mode 100644 index 00000000..78ef15f5 --- /dev/null +++ b/pd/extra/help-rev3~.pd @@ -0,0 +1,136 @@ +#N canvas 70 263 765 380 12; +#X floatatom 99 212 0 0 120 0 - - -; +#X floatatom 105 340 0 0 120 0 - - -; +#N canvas 0 0 539 448 tests 0; +#X obj 67 33 inlet; +#X obj 309 189 inlet; +#X obj 235 207 line~; +#X obj 235 230 cos~; +#X obj 235 68 loadbang; +#X msg 235 91 -0.25; +#X obj 235 276 *~; +#X obj 186 309 hip~ 5; +#X floatatom 308 218 0 0 0 0 - - -; +#X obj 308 264 osc~ 440; +#X obj 308 241 mtof; +#X obj 235 253 *~ 0.1; +#X obj 308 299 *~; +#X obj 326 325 *~; +#X obj 292 330 *~; +#X msg 279 150 -0.25 \, 0.25 \$1; +#X obj 41 148 biquad~ 0 0 1 -1 0; +#X obj 63 70 t b; +#X obj 104 72 del 3; +#X obj 57 101 1; +#X obj 96 101 0; +#X obj 41 355 outlet~; +#X obj 279 126 inlet; +#X obj 51 192 *~; +#X connect 0 0 17 0; +#X connect 1 0 8 0; +#X connect 2 0 3 0; +#X connect 3 0 11 0; +#X connect 4 0 5 0; +#X connect 5 0 2 0; +#X connect 6 0 7 0; +#X connect 7 0 21 0; +#X connect 8 0 10 0; +#X connect 9 0 6 1; +#X connect 9 0 12 0; +#X connect 9 0 12 1; +#X connect 9 0 13 0; +#X connect 10 0 9 0; +#X connect 11 0 6 0; +#X connect 12 0 13 1; +#X connect 12 0 6 1; +#X connect 12 0 14 0; +#X connect 12 0 14 1; +#X connect 13 0 6 1; +#X connect 14 0 6 1; +#X connect 15 0 2 0; +#X connect 16 0 23 0; +#X connect 17 0 18 0; +#X connect 17 0 19 0; +#X connect 18 0 20 0; +#X connect 19 0 16 0; +#X connect 19 0 23 1; +#X connect 20 0 16 0; +#X connect 20 0 23 1; +#X connect 22 0 15 0; +#X connect 23 0 21 0; +#X restore 16 171 pd tests; +#X msg 55 52 10; +#X msg 53 79 20; +#X msg 52 107 100; +#X msg 51 132 500; +#X obj 16 32 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X text 36 26 impulse; +#N canvas 0 0 450 300 output 0; +#X obj 54 202 dac~; +#X obj 132 119 pack 0 100; +#X obj 132 142 line~; +#X obj 54 165 *~; +#X obj 132 97 dbtorms; +#X obj 33 42 inlet~; +#X obj 177 42 inlet; +#X obj 177 74 clip 0 120; +#X msg 257 133 \; pd dsp 1; +#X obj 98 42 inlet~; +#X obj 94 168 *~; +#X connect 1 0 2 0; +#X connect 2 0 3 1; +#X connect 2 0 10 1; +#X connect 3 0 0 0; +#X connect 4 0 1 0; +#X connect 5 0 3 0; +#X connect 6 0 7 0; +#X connect 6 0 8 0; +#X connect 7 0 4 0; +#X connect 9 0 10 0; +#X connect 10 0 0 1; +#X restore 17 340 pd output; +#X floatatom 96 144 0 0 0 0 - - -; +#X text 135 113 tone; +#X text 134 129 pitch; +#X text 140 212 level \, dB; +#X floatatom 134 234 0 0 100 0 - - -; +#X text 175 234 liveness \, 0-100; +#X floatatom 169 258 4 0 5000 0 - - -; +#X floatatom 204 281 0 0 100 0 - - -; +#X text 217 256 crossover frequency \, Hz.; +#X text 240 283 HF damping \, percent; +#X text 140 341 output level \, dB; +#X text 94 52 tone; +#X text 95 69 bursts; +#X text 131 147 (60 for; +#X text 114 167 middle C); +#X obj 29 307 rev3~ 100 90 3000 20; +#X text 263 4 REV3~ - hard-core \, 2-in \, 4-out reverberator; +#X text 236 56 The creation arguments (level \, liveness \, crossover +frequency \, HF damping) may also be supplied in four inlets as shown. +The "liveness" (actually the internal feedback percentage) should be +100 for infinite reverb \, 90 for longish \, and 80 for short. The +crossover frequency and HF damping work together: at frequencies above +crossover \, the feedback is diminished by the "damping" as a percentage. +So zero HF damping means equal reverb time at all frequencies \, and +100% damping means almost nothing above the crossover frequency gets +through.; +#X text 236 29 (A more expensive \, presumably better \, one than rev2~.) +; +#X text 470 352 modified for Pd version 0.37-1; +#X connect 0 0 25 2; +#X connect 1 0 9 2; +#X connect 2 0 9 0; +#X connect 2 0 25 0; +#X connect 3 0 2 1; +#X connect 4 0 2 1; +#X connect 5 0 2 1; +#X connect 6 0 2 1; +#X connect 7 0 2 0; +#X connect 10 0 2 2; +#X connect 14 0 25 3; +#X connect 16 0 25 4; +#X connect 17 0 25 5; +#X connect 25 0 9 0; +#X connect 25 1 9 1; diff --git a/pd/extra/pique/makefile b/pd/extra/pique/makefile index 8158e7cd..1c1f9326 100644 --- a/pd/extra/pique/makefile +++ b/pd/extra/pique/makefile @@ -35,7 +35,7 @@ SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 SGIINCLUDE = -I../../src .c.pd_irix5: - cc $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + $(CC) $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o rm $*.o @@ -50,7 +50,7 @@ SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ -Ofast=ip32 .c.pd_irix6: - cc $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c + $(CC) $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o rm $*.o @@ -67,7 +67,7 @@ LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \ LINUXINCLUDE = -I../../src .c.pd_linux: - cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + $(CC) $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c ld -export_dynamic -shared -o $*.pd_linux $*.o -lc -lm strip --strip-unneeded $*.pd_linux rm -f $*.o @@ -82,8 +82,8 @@ DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ -Wno-unused -Wno-parentheses -Wno-switch .c.pd_darwin: - cc $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c - cc -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o + $(CC) $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + $(CC) -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o rm -f $*.o # ---------------------------------------------------------- diff --git a/pd/extra/rev3~.pd b/pd/extra/rev3~.pd new file mode 100644 index 00000000..0d8ea472 --- /dev/null +++ b/pd/extra/rev3~.pd @@ -0,0 +1,439 @@ +#N canvas 220 79 810 570 12; +#X obj 520 105 inlet; +#X obj 452 105 inlet; +#X obj 370 335 line~; +#X obj 232 394 *~; +#X obj 301 395 *~; +#X obj 370 284 dbtorms; +#X obj 370 309 pack 0 30; +#X obj 520 211 pack 0 50; +#X obj 232 419 outlet~; +#X obj 301 419 outlet~; +#X obj 520 162 clip 0 100; +#X obj 452 137 f \$1; +#X obj 520 138 f \$2; +#X obj 625 143 f \$3; +#X obj 696 143 f \$4; +#X obj 367 106 loadbang; +#X obj 369 394 *~; +#X obj 437 395 *~; +#X obj 369 419 outlet~; +#X obj 437 419 outlet~; +#X obj 625 167 moses 1; +#X msg 631 193 3000; +#X obj 705 193 clip 0 100; +#X obj 616 218 f; +#X obj 618 105 inlet; +#X obj 696 109 inlet; +#X obj 705 216 f; +#X obj 705 239 * 0.01; +#X obj 705 263 pack 0 50; +#X text 403 10 control inlets:; +#X text 400 29 1: output level \, dB \, 0-100; +#X text 399 79 4: high frequency damping \, 0-100; +#X text 400 62 3: crossover frequency in Hz. (3000 default); +#X text 400 45 2: liveness \, 0-100 \, usually between 85 and 100; +#X obj 616 242 s \$0-lop; +#N canvas 169 94 919 805 doit 0; +#X obj 218 386 *~; +#X obj 341 396 *~; +#X obj 267 389 *~; +#X obj 305 392 *~; +#X obj 28 175 lop~; +#X obj 27 204 -~; +#X obj 27 291 *~; +#X obj 16 319 +~; +#X obj 75 182 lop~; +#X obj 76 214 -~; +#X obj 77 294 *~; +#X obj 67 318 +~; +#X obj 124 187 lop~; +#X obj 124 214 -~; +#X obj 125 297 *~; +#X obj 116 322 +~; +#X obj 176 191 lop~; +#X obj 175 218 -~; +#X obj 175 301 *~; +#X obj 168 326 +~; +#X obj 15 372 *~; +#X obj 169 383 *~; +#X obj 67 376 *~; +#X obj 115 380 *~; +#X obj 207 160 r \$0-lop; +#X obj 183 246 r \$0-damp; +#X obj 183 271 line~; +#X obj 17 14 delread~ \$0-del1 10; +#X obj 117 56 delread~ \$0-del3 13.4567; +#X obj 68 35 delread~ \$0-del2 11.6356; +#X obj 171 77 delread~ \$0-del4 16.7345; +#X obj 524 407 *~; +#X obj 631 409 *~; +#X obj 560 408 *~; +#X obj 595 409 *~; +#X obj 377 399 *~; +#X obj 488 406 *~; +#X obj 414 402 *~; +#X obj 451 405 *~; +#X obj 654 354 line~; +#X obj 708 387 r \$0-fb; +#X obj 218 100 delread~ \$0-del5 20.1862; +#X obj 267 121 delread~ \$0-del6 25.7417; +#X obj 304 142 delread~ \$0-del7 31.4693; +#X obj 341 163 delread~ \$0-del8 38.2944; +#X obj 376 184 delread~ \$0-del9 46.6838; +#X obj 414 205 delread~ \$0-del10 55.4567; +#X obj 488 247 delread~ \$0-del12 76.8243; +#X obj 524 268 delread~ \$0-del13 88.5623; +#X obj 561 289 delread~ \$0-del14 101.278; +#X obj 595 310 delread~ \$0-del15 115.397; +#X obj 632 331 delread~ \$0-del16 130.502; +#X obj 25 346 inlet~; +#X obj 87 346 inlet~; +#X obj 69 440 +~; +#X obj 105 440 -~; +#X obj 141 440 +~; +#X obj 177 440 -~; +#X obj 214 440 +~; +#X obj 250 440 -~; +#X obj 286 440 +~; +#X obj 322 440 -~; +#X obj 359 440 +~; +#X obj 395 440 -~; +#X obj 431 440 +~; +#X obj 467 440 -~; +#X obj 504 440 +~; +#X obj 540 440 -~; +#X obj 576 440 +~; +#X obj 612 440 -~; +#X obj 69 474 +~; +#X obj 177 474 -~; +#X obj 105 474 +~; +#X obj 141 474 -~; +#X obj 214 474 +~; +#X obj 322 474 -~; +#X obj 250 474 +~; +#X obj 286 474 -~; +#X obj 359 474 +~; +#X obj 467 474 -~; +#X obj 395 474 +~; +#X obj 431 474 -~; +#X obj 504 474 +~; +#X obj 612 474 -~; +#X obj 540 474 +~; +#X obj 576 474 -~; +#X obj 69 518 +~; +#X obj 105 518 +~; +#X obj 322 518 -~; +#X obj 286 518 -~; +#X obj 141 518 +~; +#X obj 177 518 +~; +#X obj 214 518 -~; +#X obj 250 518 -~; +#X obj 360 518 +~; +#X obj 396 518 +~; +#X obj 613 518 -~; +#X obj 577 518 -~; +#X obj 432 518 +~; +#X obj 468 518 +~; +#X obj 505 518 -~; +#X obj 541 518 -~; +#X obj 70 575 +~; +#X obj 106 575 +~; +#X obj 469 575 -~; +#X obj 433 575 -~; +#X obj 142 575 +~; +#X obj 178 575 +~; +#X obj 361 575 -~; +#X obj 397 575 -~; +#X obj 215 575 +~; +#X obj 251 575 +~; +#X obj 287 575 +~; +#X obj 323 575 +~; +#X obj 614 575 -~; +#X obj 578 575 -~; +#X obj 506 575 -~; +#X obj 542 575 -~; +#X obj 628 606 outlet~; +#X obj 698 606 outlet~; +#X obj 768 607 outlet~; +#X obj 838 607 outlet~; +#X obj 451 226 delread~ \$0-del11 65.1755; +#X obj 614 629 delwrite~ \$0-del16 130.502; +#X obj 361 776 delwrite~ \$0-del9 46.6838; +#X obj 398 755 delwrite~ \$0-del10 55.4567; +#X obj 434 734 delwrite~ \$0-del11 65.1755; +#X obj 470 713 delwrite~ \$0-del12 76.8243; +#X obj 506 692 delwrite~ \$0-del13 88.5623; +#X obj 542 671 delwrite~ \$0-del14 101.278; +#X obj 579 650 delwrite~ \$0-del15 115.397; +#X obj 323 606 delwrite~ \$0-del8 38.2944; +#X obj 287 628 delwrite~ \$0-del7 31.4693; +#X obj 252 650 delwrite~ \$0-del6 25.7417; +#X obj 215 672 delwrite~ \$0-del5 20.1862; +#X obj 71 761 delwrite~ \$0-del1 10; +#X obj 106 737 delwrite~ \$0-del2 11.6356; +#X obj 141 715 delwrite~ \$0-del3 13.4567; +#X obj 179 693 delwrite~ \$0-del4 16.7345; +#X connect 0 0 58 0; +#X connect 0 0 59 0; +#X connect 1 0 60 1; +#X connect 1 0 61 1; +#X connect 2 0 58 1; +#X connect 2 0 59 1; +#X connect 3 0 60 0; +#X connect 3 0 61 0; +#X connect 4 0 5 0; +#X connect 5 0 6 0; +#X connect 6 0 7 1; +#X connect 7 0 20 0; +#X connect 8 0 9 0; +#X connect 9 0 10 0; +#X connect 10 0 11 1; +#X connect 11 0 22 0; +#X connect 12 0 13 0; +#X connect 13 0 14 0; +#X connect 14 0 15 1; +#X connect 15 0 23 0; +#X connect 16 0 17 0; +#X connect 17 0 18 0; +#X connect 18 0 19 1; +#X connect 19 0 21 0; +#X connect 20 0 54 0; +#X connect 20 0 55 0; +#X connect 21 0 56 1; +#X connect 21 0 57 1; +#X connect 22 0 55 1; +#X connect 22 0 54 1; +#X connect 23 0 56 0; +#X connect 23 0 57 0; +#X connect 24 0 16 1; +#X connect 24 0 12 1; +#X connect 24 0 8 1; +#X connect 24 0 4 1; +#X connect 25 0 26 0; +#X connect 26 0 18 1; +#X connect 26 0 14 1; +#X connect 26 0 10 1; +#X connect 26 0 6 1; +#X connect 27 0 4 0; +#X connect 27 0 5 1; +#X connect 27 0 7 0; +#X connect 28 0 15 0; +#X connect 28 0 12 0; +#X connect 28 0 13 1; +#X connect 29 0 8 0; +#X connect 29 0 9 1; +#X connect 29 0 11 0; +#X connect 30 0 19 0; +#X connect 30 0 17 1; +#X connect 30 0 16 0; +#X connect 31 0 66 0; +#X connect 31 0 67 0; +#X connect 32 0 68 1; +#X connect 32 0 69 1; +#X connect 33 0 66 1; +#X connect 33 0 67 1; +#X connect 34 0 68 0; +#X connect 34 0 69 0; +#X connect 35 0 62 0; +#X connect 35 0 63 0; +#X connect 36 0 64 1; +#X connect 36 0 65 1; +#X connect 37 0 62 1; +#X connect 37 0 63 1; +#X connect 38 0 64 0; +#X connect 38 0 65 0; +#X connect 39 0 2 1; +#X connect 39 0 0 1; +#X connect 39 0 3 1; +#X connect 39 0 1 1; +#X connect 39 0 21 1; +#X connect 39 0 23 1; +#X connect 39 0 22 1; +#X connect 39 0 20 1; +#X connect 39 0 35 1; +#X connect 39 0 38 1; +#X connect 39 0 36 1; +#X connect 39 0 31 1; +#X connect 39 0 33 1; +#X connect 39 0 34 1; +#X connect 39 0 32 1; +#X connect 39 0 37 1; +#X connect 40 0 39 0; +#X connect 41 0 0 0; +#X connect 42 0 2 0; +#X connect 43 0 3 0; +#X connect 44 0 1 0; +#X connect 45 0 35 0; +#X connect 46 0 37 0; +#X connect 47 0 36 0; +#X connect 48 0 31 0; +#X connect 49 0 33 0; +#X connect 50 0 34 0; +#X connect 51 0 32 0; +#X connect 52 0 20 0; +#X connect 53 0 22 0; +#X connect 54 0 70 0; +#X connect 54 0 73 0; +#X connect 55 0 72 0; +#X connect 55 0 71 0; +#X connect 56 0 70 1; +#X connect 56 0 73 1; +#X connect 57 0 72 1; +#X connect 57 0 71 1; +#X connect 58 0 74 0; +#X connect 58 0 77 0; +#X connect 59 0 76 0; +#X connect 59 0 75 0; +#X connect 60 0 74 1; +#X connect 60 0 77 1; +#X connect 61 0 76 1; +#X connect 61 0 75 1; +#X connect 62 0 78 0; +#X connect 62 0 81 0; +#X connect 63 0 80 0; +#X connect 63 0 79 0; +#X connect 64 0 78 1; +#X connect 64 0 81 1; +#X connect 65 0 80 1; +#X connect 65 0 79 1; +#X connect 66 0 82 0; +#X connect 66 0 85 0; +#X connect 67 0 84 0; +#X connect 67 0 83 0; +#X connect 68 0 82 1; +#X connect 68 0 85 1; +#X connect 69 0 84 1; +#X connect 69 0 83 1; +#X connect 70 0 86 0; +#X connect 70 0 92 0; +#X connect 71 0 91 0; +#X connect 71 0 88 0; +#X connect 72 0 87 0; +#X connect 72 0 93 0; +#X connect 73 0 90 0; +#X connect 73 0 89 0; +#X connect 74 0 86 1; +#X connect 74 0 92 1; +#X connect 75 0 91 1; +#X connect 75 0 88 1; +#X connect 76 0 87 1; +#X connect 76 0 93 1; +#X connect 77 0 90 1; +#X connect 77 0 89 1; +#X connect 78 0 94 0; +#X connect 78 0 100 0; +#X connect 79 0 99 0; +#X connect 79 0 96 0; +#X connect 80 0 95 0; +#X connect 80 0 101 0; +#X connect 81 0 98 0; +#X connect 81 0 97 0; +#X connect 82 0 94 1; +#X connect 82 0 100 1; +#X connect 83 0 99 1; +#X connect 83 0 96 1; +#X connect 84 0 95 1; +#X connect 84 0 101 1; +#X connect 85 0 98 1; +#X connect 85 0 97 1; +#X connect 86 0 102 0; +#X connect 86 0 108 0; +#X connect 87 0 103 0; +#X connect 87 0 109 0; +#X connect 88 0 113 0; +#X connect 88 0 114 0; +#X connect 89 0 112 0; +#X connect 89 0 115 0; +#X connect 90 0 106 0; +#X connect 90 0 105 0; +#X connect 91 0 107 0; +#X connect 91 0 104 0; +#X connect 92 0 110 0; +#X connect 92 0 116 0; +#X connect 93 0 111 0; +#X connect 93 0 117 0; +#X connect 94 0 108 1; +#X connect 94 0 102 1; +#X connect 95 0 109 1; +#X connect 95 0 103 1; +#X connect 96 0 114 1; +#X connect 96 0 113 1; +#X connect 97 0 115 1; +#X connect 97 0 112 1; +#X connect 98 0 105 1; +#X connect 98 0 106 1; +#X connect 99 0 104 1; +#X connect 99 0 107 1; +#X connect 100 0 116 1; +#X connect 100 0 110 1; +#X connect 101 0 117 1; +#X connect 101 0 111 1; +#X connect 102 0 135 0; +#X connect 103 0 136 0; +#X connect 104 0 127 0; +#X connect 105 0 126 0; +#X connect 106 0 137 0; +#X connect 107 0 138 0; +#X connect 108 0 124 0; +#X connect 109 0 125 0; +#X connect 110 0 134 0; +#X connect 111 0 133 0; +#X connect 112 0 132 0; +#X connect 113 0 131 0; +#X connect 114 0 121 0; +#X connect 114 0 123 0; +#X connect 115 0 120 0; +#X connect 115 0 130 0; +#X connect 116 0 118 0; +#X connect 116 0 128 0; +#X connect 117 0 119 0; +#X connect 117 0 129 0; +#X connect 122 0 38 0; +#X restore 164 317 pd doit; +#X obj 165 255 inlet~; +#X obj 222 255 inlet~; +#X obj 520 241 s \$0-fb; +#X obj 705 290 s \$0-damp; +#X text 57 490 rev3 - 16-delay reverberator. Like rev2~ but presumably +higher-quality and takes two audio inputs.; +#X obj 520 187 / 400; +#X connect 0 0 12 0; +#X connect 1 0 11 0; +#X connect 2 0 3 1; +#X connect 2 0 4 1; +#X connect 2 0 16 1; +#X connect 2 0 17 1; +#X connect 3 0 8 0; +#X connect 4 0 9 0; +#X connect 5 0 6 0; +#X connect 6 0 2 0; +#X connect 7 0 38 0; +#X connect 10 0 41 0; +#X connect 11 0 5 0; +#X connect 12 0 10 0; +#X connect 13 0 20 0; +#X connect 14 0 22 0; +#X connect 15 0 11 0; +#X connect 15 0 12 0; +#X connect 15 0 13 0; +#X connect 15 0 14 0; +#X connect 16 0 18 0; +#X connect 17 0 19 0; +#X connect 20 0 21 0; +#X connect 20 1 23 0; +#X connect 21 0 23 0; +#X connect 22 0 26 0; +#X connect 23 0 34 0; +#X connect 24 0 23 0; +#X connect 25 0 14 0; +#X connect 26 0 27 0; +#X connect 27 0 28 0; +#X connect 28 0 39 0; +#X connect 35 0 3 0; +#X connect 35 1 4 0; +#X connect 35 2 16 0; +#X connect 35 3 17 0; +#X connect 36 0 35 0; +#X connect 37 0 35 1; +#X connect 41 0 7 0; diff --git a/pd/portaudio_v18/Makefile.in b/pd/portaudio_v18/Makefile.in new file mode 100644 index 00000000..a8e0434f --- /dev/null +++ b/pd/portaudio_v18/Makefile.in @@ -0,0 +1,96 @@ +# +# PortAudio Makefile.in +# +# Dominic Mazzoni +# + +PREFIX = @prefix@ +CC = @CC@ +CFLAGS = @CFLAGS@ -Ipa_common +LIBS = @LIBS@ +AR = @AR@ +RANLIB = @RANLIB@ +INSTALL = @INSTALL@ +SHARED_FLAGS = @SHARED_FLAGS@ +DLL_LIBS = @DLL_LIBS@ + +OTHER_OBJS = @OTHER_OBJS@ + +PALIB = libportaudio.a +PADLL = @PADLL@ +PADLLV = $(PADLL).0.0.18 +PAINC = pa_common/portaudio.h + +COMMON_OBJS = \ + pa_common/pa_convert.o \ + pa_common/pa_lib.o + +TESTS = \ + bin/patest_buffer \ + bin/patest_clip \ + bin/patest_dither \ + bin/patest_hang \ + bin/patest_latency \ + bin/patest_leftright \ + bin/patest_longsine \ + bin/patest_many \ + bin/patest_maxsines \ + bin/patest_multi_sine \ + bin/patest_pink \ + bin/patest_record \ + bin/patest_ringmix \ + bin/patest_saw \ + bin/patest_sine8 \ + bin/patest_sine \ + bin/patest_sine_formats \ + bin/patest_sine_time \ + bin/patest_stop \ + bin/patest_sync \ + bin/patest_toomanysines \ + bin/patest_underflow \ + bin/patest_wire + +OBJS = $(COMMON_OBJS) $(OTHER_OBJS) + +all: lib/$(PALIB) lib/$(PADLLV) tests + +tests: bin/ $(TESTS) + +lib/$(PALIB): lib/ $(OBJS) Makefile $(PAINC) + $(AR) ruv lib/$(PALIB) $(OBJS) + $(RANLIB) lib/$(PALIB) + +lib/$(PADLLV): lib/ $(OBJS) Makefile $(PAINC) + $(CC) $(SHARED_FLAGS) -o lib/$(PADLLV) $(OBJS) $(DLL_LIBS) + +$(TESTS): bin/%: lib/$(PALIB) Makefile $(PAINC) pa_tests/%.c + $(CC) -o $@ $(CFLAGS) pa_tests/$*.c lib/$(PALIB) $(LIBS) + +install: lib/$(PALIB) lib/$(PADLLV) + $(INSTALL) -m 644 lib/$(PADLLV) $(PREFIX)/lib/$(PADLLV) + $(INSTALL) -m 644 lib/$(PALIB) $(PREFIX)/lib/$(PALIB) + cd $(PREFIX)/lib && rm -f $(PADLL) && ln -s $(PADLLV) $(PADLL) + $(INSTALL) -m 644 pa_common/portaudio.h $(PREFIX)/include/portaudio.h + @echo "" + @echo "------------------------------------------------------------" + @echo "PortAudio was successfully installed." + @echo "" + @echo "On some systems (e.g. Linux) you should run 'ldconfig' now" + @echo "to make the shared object available. You may also need to" + @echo "modify your LD_LIBRARY_PATH environment variable to include" + @echo "the directory $(PREFIX)/lib" + @echo "------------------------------------------------------------" + @echo "" + +clean: + rm -f $(OBJS) $(TESTS) lib/$(PALIB) + rm -f config.log config.status + +%.o: %.c Makefile $(PAINC) + $(CC) -c $(CFLAGS) $< -o $@ + +bin: + mkdir bin + +lib: + mkdir lib diff --git a/pd/portaudio_v18/Makefile.linux b/pd/portaudio_v18/Makefile.linux new file mode 100644 index 00000000..a58d57b3 --- /dev/null +++ b/pd/portaudio_v18/Makefile.linux @@ -0,0 +1,59 @@ +# Make PortAudio for Linux +# Updated 2001/08/25 Bill Eldridge bill@rfa.org +# Updated 2001/10/16, philburk@softsynth.com, s/unix_oss/unix_oss/ +# Updated 2002/04/30 Bill Eldridge bill@rfa.org +# Made the libinstall and tests compile a bit cleaner + +# A pretty bare makefile, that figures out all the test files +# and compiles them against the library in the pa_unix_oss directory. + +# Do "make all" and then when happy, "make libinstall" +# (if not happy, "make clean") + +# The ldconfig stuff in libinstall is the wrong way to do it - +# someone tell me the right way, please + + +LIBS = -lm -lpthread + +CDEFINES = -I../pa_common +CFLAGS = -g +LIBINST = /usr/local/lib + +TESTS:= $(wildcard pa_tests/pa*.c pa_tests/debug*.c) +TESTO:= $(wildcard pa_tests/pa*.o pa_tests/debug*.o) + +LIBFILES:= ./pa_common/pa_lib.c ./pa_unix_oss/pa_unix_oss.c ./pa_unix_oss/pa_unix.c + +#all: sharedlib libinstall tests +all: sharedlib libinstall testo testq + +.c.o: + -gcc $(CFLAGS) -c -I./pa_common $< -o $*.o + +.o: + -gcc $*.o -o $* -Lpa_unix_oss -lportaudio $(LIBS) + +#.c.o: +# -gcc -c -I./pa_common $< -o $*.o +# -gcc $*.o -o $* -Lpa_unix_oss $(LIBS) -lportaudio + + +sharedlib: $(LIBFILES:.c=.o) + gcc -shared -o ./pa_unix_oss/libportaudio.so ./pa_common/pa_lib.o ./pa_unix_oss/pa_unix_oss.o ./pa_unix_oss/pa_unix.o + +libinstall: ./pa_unix_oss/libportaudio.so + @cp -f ./pa_unix_oss/libportaudio.so $(LIBINST) + @/sbin/ldconfig + +testo: $(TESTS:.c=.o) + +testq: $(TESTO:.o=) + +clean: + -@rm -f $(TESTS:.c=.o) + -@rm -f $(TESTS:.c=) + -@rm -f $(LIBFILES:.c=.o) + -@rm -f ./pa_unix_oss/libportaudio.so + + diff --git a/pd/portaudio_v18/Makefile.mingw b/pd/portaudio_v18/Makefile.mingw new file mode 100644 index 00000000..2043a161 --- /dev/null +++ b/pd/portaudio_v18/Makefile.mingw @@ -0,0 +1,57 @@ + +# Makefile for PortAudio on mingw (http://mingw.sourceforge.net) + +# Contributed by Bill Eldridge, bill@rfa.org, Radio Free Asia +# Copyright 2002/02/20, GPL + +# Uses a common mingw32 cross-compiler that defaults +# to everything in /usr/local/cross-tools + +# First edit your path with +# export PATH=/usr/local/cross-tools/bin:$PATH + +# Usage: make -f Makefile.mingw all +# or make -f Makefile.mingw sharedlib +# make -f Makefile.mingw tests +# +# Then copy executables & portaudio.dll to your Windows machine +# +# To make work with pa_win_ds, you'll have to substitue +# all the pa_win_wmme files with pa_win_ds files, no biggie. + +CC= i586-mingw32msvc-gcc +DLLTOOL= i586-mingw32msvc-dlltool +DLLWRAP= i586-mingw32msvc-dllwrap + +ARCH= pa_win_wmme + +TESTS:= $(wildcard pa_tests/pa*.c pa_tests/debug*.c) + +.c.o: + -$(CC) -c -I./pa_common $< -o $*.o + -$(CC) $*.o -o $*.exe -L/usr/local/lib -L$(ARCH) -lportaudio.dll -lwinmm + +all: sharedlib tests + +sharedlib: ./pa_common/pa_lib.c + $(CC) -c -I./pa_common pa_common/pa_lib.c -o pa_common/pa_lib.o + $(CC) -c -I./pa_common pa_win_wmme/pa_win_wmme.c -o pa_win_wmme/pa_win_wmme.o + $(CC) -shared -mthreads -o portaudio.dll pa_common/pa_lib.o pa_win_wmme/pa_win_wmme.o -L/usr/local/cross-tools/i586-win32msvc/lib -lwinmm -lm + $(DLLWRAP) --export-all --output-def=libportaudio.def --output-lib=libportaudio.a --dllname=portaudio.dll --drivername=i586-mingw32msvc-gcc pa_common/pa_lib.o pa_win_wmme/pa_win_wmme.o -L/usr/local/cross-tools/i586-win32msvc/lib -lwinmm -lm + $(CC) -shared -Wl,--enable-auto-image-base -o portaudio.dll -Wl,--out-implib=pa_win_wmme/libportaudio.dll.a pa_common/pa_lib.o pa_win_wmme/pa_win_wmme.o -L/usr/local/cross-tools/i586-win32msvc/lib -lwinmm + + +tests: $(TESTS:.c=.o) + +sine: + $(CC) -c -I./pa_common pa_tests/patest_sine.c -o pa_tests/patest_sine.o + $(CC) pa_tests/patest_sine.o -o pa_tests/patest_sine.exe -L/usr/local/lib -lportaudio.dll -lwinmm + +clean: + -rm ./pa_tests/*.exe + -rm ./pa_tests/*.o + +nothing: + $(CC) pa_tests/patest_sine.o -L/usr/lib/w32api -L./pa_win_wmme -lportaudio.dll -lwinmm + + diff --git a/pd/portaudio_v18/Makefile.solaris b/pd/portaudio_v18/Makefile.solaris new file mode 100644 index 00000000..ef3a4185 --- /dev/null +++ b/pd/portaudio_v18/Makefile.solaris @@ -0,0 +1,59 @@ +# Make PortAudio for Linux +# Updated 2001/08/25 Bill Eldridge bill@rfa.org +# Updated 2001/10/16, philburk@softsynth.com, s/unix_oss/unix_oss/ +# Updated 2002/04/30 Bill Eldridge bill@rfa.org +# Made the libinstall and tests compile a bit cleaner + +# A pretty bare makefile, that figures out all the test files +# and compiles them against the library in the pa_unix_oss directory. + +# Do "make all" and then when happy, "make libinstall" +# (if not happy, "make clean") + +# The ldconfig stuff in libinstall is the wrong way to do it - +# someone tell me the right way, please + + +LIBS = -lm -lpthread -lrt + +CDEFINES = -I../pa_common +CFLAGS = -g +LIBINST = /usr/local/lib + +TESTS:= $(wildcard pa_tests/pa*.c pa_tests/debug*.c) +TESTO:= $(wildcard pa_tests/pa*.o pa_tests/debug*.o) + +LIBFILES:= ./pa_common/pa_lib.c ./pa_unix_oss/pa_unix_solaris.c ./pa_unix_oss/pa_unix.c + +#all: sharedlib libinstall tests +all: sharedlib libinstall testo testq + +.c.o: + -gcc $(CFLAGS) -c -I./pa_common $< -o $*.o + +.o: + -gcc $*.o -o $* -Lpa_unix_oss -lportaudio $(LIBS) + +#.c.o: +# -gcc -c -I./pa_common $< -o $*.o +# -gcc $*.o -o $* -Lpa_unix_oss $(LIBS) -lportaudio + + +sharedlib: $(LIBFILES:.c=.o) + gcc -shared -o ./pa_unix_oss/libportaudio.so ./pa_common/pa_lib.o ./pa_unix_oss/pa_unix_solaris.o ./pa_unix_oss/pa_unix.o + +libinstall: ./pa_unix_oss/libportaudio.so + @cp -f ./pa_unix_oss/libportaudio.so $(LIBINST) + @/sbin/ldconfig + +testo: $(TESTS:.c=.o) + +testq: $(TESTO:.o=) + +clean: + -@rm -f $(TESTS:.c=.o) + -@rm -f $(TESTS:.c=) + -@rm -f $(LIBFILES:.c=.o) + -@rm -f ./pa_unix_oss/libportaudio.so + + diff --git a/pd/portaudio_v18/VERSION.txt b/pd/portaudio_v18/VERSION.txt new file mode 100644 index 00000000..350a736a --- /dev/null +++ b/pd/portaudio_v18/VERSION.txt @@ -0,0 +1,2 @@ +Portaudio version 18.1, packaged 03.05.28, downloaded Aug. 1: +-rw------- 1 msp 550130 Aug 1 19:47 portaudio_v18_1.zip diff --git a/pd/portaudio_v18/config.guess b/pd/portaudio_v18/config.guess new file mode 100644 index 00000000..297e5c30 --- /dev/null +++ b/pd/portaudio_v18/config.guess @@ -0,0 +1,1308 @@ +#! /bin/sh +# Attempt to guess a canonical system name. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +# Free Software Foundation, Inc. + +timestamp='2001-10-05' + +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Originally written by Per Bothner <bothner@cygnus.com>. +# Please send patches to <config-patches@gnu.org>. Submit a context +# diff and a properly formatted ChangeLog entry. +# +# This script attempts to guess a canonical system name similar to +# config.sub. If it succeeds, it prints the system name on stdout, and +# exits with 0. Otherwise, it exits with 1. +# +# The plan is that this can be called by configure scripts if you +# don't specify an explicit build system type. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] + +Output the configuration name of the system \`$me' is run on. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to <config-patches@gnu.org>." + +version="\ +GNU config.guess ($timestamp) + +Originally written by Per Bothner. +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit 0 ;; + --version | -v ) + echo "$version" ; exit 0 ;; + --help | --h* | -h ) + echo "$usage"; exit 0 ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + * ) + break ;; + esac +done + +if test $# != 0; then + echo "$me: too many arguments$help" >&2 + exit 1 +fi + + +dummy=dummy-$$ +trap 'rm -f $dummy.c $dummy.o $dummy.rel $dummy; exit 1' 1 2 15 + +# CC_FOR_BUILD -- compiler used by this script. +# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still +# use `HOST_CC' if defined, but it is deprecated. + +set_cc_for_build='case $CC_FOR_BUILD,$HOST_CC,$CC in + ,,) echo "int dummy(){}" > $dummy.c ; + for c in cc gcc c89 ; do + ($c $dummy.c -c -o $dummy.o) >/dev/null 2>&1 ; + if test $? = 0 ; then + CC_FOR_BUILD="$c"; break ; + fi ; + done ; + rm -f $dummy.c $dummy.o $dummy.rel ; + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found ; + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; +esac' + +# This is needed to find uname on a Pyramid OSx when run in the BSD universe. +# (ghazi@noc.rutgers.edu 1994-08-24) +if (test -f /.attbin/uname) >/dev/null 2>&1 ; then + PATH=$PATH:/.attbin ; export PATH +fi + +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown + +# Note: order is significant - the case branches are not exclusive. + +case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in + *:NetBSD:*:*) + # NetBSD (nbsd) targets should (where applicable) match one or + # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, + # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently + # switched to ELF, *-*-netbsd* would select the old + # object file format. This provides both forward + # compatibility and a consistent mechanism for selecting the + # object file format. + # Determine the machine/vendor (is the vendor relevant). + case "${UNAME_MACHINE}" in + amiga) machine=m68k-unknown ;; + arm32) machine=arm-unknown ;; + atari*) machine=m68k-atari ;; + sun3*) machine=m68k-sun ;; + mac68k) machine=m68k-apple ;; + macppc) machine=powerpc-apple ;; + hp3[0-9][05]) machine=m68k-hp ;; + ibmrt|romp-ibm) machine=romp-ibm ;; + sparc*) machine=`uname -p`-unknown ;; + *) machine=${UNAME_MACHINE}-unknown ;; + esac + # The Operating System including object format, if it has switched + # to ELF recently, or will in the future. + case "${UNAME_MACHINE}" in + i386|sparc|amiga|arm*|hp300|mvme68k|vax|atari|luna68k|mac68k|news68k|next68k|pc532|sun3*|x68k) + eval $set_cc_for_build + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep __ELF__ >/dev/null + then + # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). + # Return netbsd for either. FIX? + os=netbsd + else + os=netbsdelf + fi + ;; + *) + os=netbsd + ;; + esac + # The OS release + release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + echo "${machine}-${os}${release}" + exit 0 ;; + amiga:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + arc:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + hp300:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mac68k:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + macppc:OpenBSD:*:*) + echo powerpc-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvme68k:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvme88k:OpenBSD:*:*) + echo m88k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvmeppc:OpenBSD:*:*) + echo powerpc-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + pmax:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + sgi:OpenBSD:*:*) + echo mipseb-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + sun3:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + wgrisc:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + *:OpenBSD:*:*) + echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + alpha:OSF1:*:*) + if test $UNAME_RELEASE = "V4.0"; then + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + fi + # A Vn.n version is a released version. + # A Tn.n version is a released field test version. + # A Xn.n version is an unreleased experimental baselevel. + # 1.2 uses "1.2" for uname -r. + cat <<EOF >$dummy.s + .data +\$Lformat: + .byte 37,100,45,37,120,10,0 # "%d-%x\n" + + .text + .globl main + .align 4 + .ent main +main: + .frame \$30,16,\$26,0 + ldgp \$29,0(\$27) + .prologue 1 + .long 0x47e03d80 # implver \$0 + lda \$2,-1 + .long 0x47e20c21 # amask \$2,\$1 + lda \$16,\$Lformat + mov \$0,\$17 + not \$1,\$18 + jsr \$26,printf + ldgp \$29,0(\$26) + mov 0,\$16 + jsr \$26,exit + .end main +EOF + eval $set_cc_for_build + $CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null + if test "$?" = 0 ; then + case `./$dummy` in + 0-0) + UNAME_MACHINE="alpha" + ;; + 1-0) + UNAME_MACHINE="alphaev5" + ;; + 1-1) + UNAME_MACHINE="alphaev56" + ;; + 1-101) + UNAME_MACHINE="alphapca56" + ;; + 2-303) + UNAME_MACHINE="alphaev6" + ;; + 2-307) + UNAME_MACHINE="alphaev67" + ;; + 2-1307) + UNAME_MACHINE="alphaev68" + ;; + esac + fi + rm -f $dummy.s $dummy + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + exit 0 ;; + Alpha\ *:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # Should we change UNAME_MACHINE based on the output of uname instead + # of the specific Alpha model? + echo alpha-pc-interix + exit 0 ;; + 21064:Windows_NT:50:3) + echo alpha-dec-winnt3.5 + exit 0 ;; + Amiga*:UNIX_System_V:4.0:*) + echo m68k-unknown-sysv4 + exit 0;; + *:[Aa]miga[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-amigaos + exit 0 ;; + *:OS/390:*:*) + echo i370-ibm-openedition + exit 0 ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + echo arm-acorn-riscix${UNAME_RELEASE} + exit 0;; + SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) + echo hppa1.1-hitachi-hiuxmpp + exit 0;; + Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) + # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. + if test "`(/bin/universe) 2>/dev/null`" = att ; then + echo pyramid-pyramid-sysv3 + else + echo pyramid-pyramid-bsd + fi + exit 0 ;; + NILE*:*:*:dcosx) + echo pyramid-pyramid-svr4 + exit 0 ;; + sun4H:SunOS:5.*:*) + echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) + echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + i86pc:SunOS:5.*:*) + echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + sun4*:SunOS:6*:*) + # According to config.sub, this is the proper way to canonicalize + # SunOS6. Hard to guess exactly what SunOS6 will be like, but + # it's likely to be more like Solaris than SunOS4. + echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + sun4*:SunOS:*:*) + case "`/usr/bin/arch -k`" in + Series*|S4*) + UNAME_RELEASE=`uname -v` + ;; + esac + # Japanese Language versions have a version number like `4.1.3-JL'. + echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` + exit 0 ;; + sun3*:SunOS:*:*) + echo m68k-sun-sunos${UNAME_RELEASE} + exit 0 ;; + sun*:*:4.2BSD:*) + UNAME_RELEASE=`(head -1 /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 + case "`/bin/arch`" in + sun3) + echo m68k-sun-sunos${UNAME_RELEASE} + ;; + sun4) + echo sparc-sun-sunos${UNAME_RELEASE} + ;; + esac + exit 0 ;; + aushp:SunOS:*:*) + echo sparc-auspex-sunos${UNAME_RELEASE} + exit 0 ;; + # The situation for MiNT is a little confusing. The machine name + # can be virtually everything (everything which is not + # "atarist" or "atariste" at least should have a processor + # > m68000). The system name ranges from "MiNT" over "FreeMiNT" + # to the lowercase version "mint" (or "freemint"). Finally + # the system name "TOS" denotes a system which is actually not + # MiNT. But MiNT is downward compatible to TOS, so this should + # be no problem. + atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit 0 ;; + atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit 0 ;; + *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit 0 ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + echo m68k-milan-mint${UNAME_RELEASE} + exit 0 ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + echo m68k-hades-mint${UNAME_RELEASE} + exit 0 ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + echo m68k-unknown-mint${UNAME_RELEASE} + exit 0 ;; + powerpc:machten:*:*) + echo powerpc-apple-machten${UNAME_RELEASE} + exit 0 ;; + RISC*:Mach:*:*) + echo mips-dec-mach_bsd4.3 + exit 0 ;; + RISC*:ULTRIX:*:*) + echo mips-dec-ultrix${UNAME_RELEASE} + exit 0 ;; + VAX*:ULTRIX*:*:*) + echo vax-dec-ultrix${UNAME_RELEASE} + exit 0 ;; + 2020:CLIX:*:* | 2430:CLIX:*:*) + echo clipper-intergraph-clix${UNAME_RELEASE} + exit 0 ;; + mips:*:*:UMIPS | mips:*:*:RISCos) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c +#ifdef __cplusplus +#include <stdio.h> /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif + #if defined (host_mips) && defined (MIPSEB) + #if defined (SYSTYPE_SYSV) + printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_SVR4) + printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) + printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); + #endif + #endif + exit (-1); + } +EOF + $CC_FOR_BUILD $dummy.c -o $dummy \ + && ./$dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \ + && rm -f $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy + echo mips-mips-riscos${UNAME_RELEASE} + exit 0 ;; + Motorola:PowerMAX_OS:*:*) + echo powerpc-motorola-powermax + exit 0 ;; + Night_Hawk:Power_UNIX:*:*) + echo powerpc-harris-powerunix + exit 0 ;; + m88k:CX/UX:7*:*) + echo m88k-harris-cxux7 + exit 0 ;; + m88k:*:4*:R4*) + echo m88k-motorola-sysv4 + exit 0 ;; + m88k:*:3*:R3*) + echo m88k-motorola-sysv3 + exit 0 ;; + AViiON:dgux:*:*) + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` + if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + then + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ + [ ${TARGET_BINARY_INTERFACE}x = x ] + then + echo m88k-dg-dgux${UNAME_RELEASE} + else + echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + else + echo i586-dg-dgux${UNAME_RELEASE} + fi + exit 0 ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + echo m88k-dolphin-sysv3 + exit 0 ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + echo m88k-motorola-sysv3 + exit 0 ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + echo m88k-tektronix-sysv3 + exit 0 ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + echo m68k-tektronix-bsd + exit 0 ;; + *:IRIX*:*:*) + echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + exit 0 ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i*86:AIX:*:*) + echo i386-ibm-aix + exit 0 ;; + ia64:AIX:*:*) + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} + exit 0 ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include <sys/systemcfg.h> + + main() + { + if (!__power_pc()) + exit(1); + puts("powerpc-ibm-aix3.2.5"); + exit(0); + } +EOF + $CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm -f $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy + echo rs6000-ibm-aix3.2.5 + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + echo rs6000-ibm-aix3.2.4 + else + echo rs6000-ibm-aix3.2 + fi + exit 0 ;; + *:AIX:*:[45]) + IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | head -1 | awk '{ print $1 }'` + if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then + IBM_ARCH=rs6000 + else + IBM_ARCH=powerpc + fi + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${IBM_ARCH}-ibm-aix${IBM_REV} + exit 0 ;; + *:AIX:*:*) + echo rs6000-ibm-aix + exit 0 ;; + ibmrt:4.4BSD:*|romp-ibm:BSD:*) + echo romp-ibm-bsd4.4 + exit 0 ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and + echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to + exit 0 ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + echo rs6000-bull-bosx + exit 0 ;; + DPX/2?00:B.O.S.:*:*) + echo m68k-bull-sysv3 + exit 0 ;; + 9000/[34]??:4.3bsd:1.*:*) + echo m68k-hp-bsd + exit 0 ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + echo m68k-hp-bsd4.4 + exit 0 ;; + 9000/[34678]??:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + case "${UNAME_MACHINE}" in + 9000/31? ) HP_ARCH=m68000 ;; + 9000/[34]?? ) HP_ARCH=m68k ;; + 9000/[678][0-9][0-9]) + if [ -x /usr/bin/getconf ]; then + sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case "${sc_cpu_version}" in + 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 + 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 + 532) # CPU_PA_RISC2_0 + case "${sc_kernel_bits}" in + 32) HP_ARCH="hppa2.0n" ;; + 64) HP_ARCH="hppa2.0w" ;; + '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 + esac ;; + esac + fi + if [ "${HP_ARCH}" = "" ]; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + + #define _HPUX_SOURCE + #include <stdlib.h> + #include <unistd.h> + + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); + + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + case 32: puts ("hppa2.0n"); break; + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } +EOF + (CCOPTS= $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null) && HP_ARCH=`./$dummy` + if test -z "$HP_ARCH"; then HP_ARCH=hppa; fi + rm -f $dummy.c $dummy + fi ;; + esac + echo ${HP_ARCH}-hp-hpux${HPUX_REV} + exit 0 ;; + ia64:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ia64-hp-hpux${HPUX_REV} + exit 0 ;; + 3050*:HI-UX:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include <unistd.h> + int + main () + { + long cpu = sysconf (_SC_CPU_VERSION); + /* The order matters, because CPU_IS_HP_MC68K erroneously returns + true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct + results, however. */ + if (CPU_IS_PA_RISC (cpu)) + { + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; + case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; + default: puts ("hppa-hitachi-hiuxwe2"); break; + } + } + else if (CPU_IS_HP_MC68K (cpu)) + puts ("m68k-hitachi-hiuxwe2"); + else puts ("unknown-hitachi-hiuxwe2"); + exit (0); + } +EOF + $CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm -f $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy + echo unknown-hitachi-hiuxwe2 + exit 0 ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) + echo hppa1.1-hp-bsd + exit 0 ;; + 9000/8??:4.3bsd:*:*) + echo hppa1.0-hp-bsd + exit 0 ;; + *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) + echo hppa1.0-hp-mpeix + exit 0 ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) + echo hppa1.1-hp-osf + exit 0 ;; + hp8??:OSF1:*:*) + echo hppa1.0-hp-osf + exit 0 ;; + i*86:OSF1:*:*) + if [ -x /usr/sbin/sysversion ] ; then + echo ${UNAME_MACHINE}-unknown-osf1mk + else + echo ${UNAME_MACHINE}-unknown-osf1 + fi + exit 0 ;; + parisc*:Lites*:*:*) + echo hppa1.1-hp-lites + exit 0 ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + echo c1-convex-bsd + exit 0 ;; + C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit 0 ;; + C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) + echo c34-convex-bsd + exit 0 ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + echo c38-convex-bsd + exit 0 ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + echo c4-convex-bsd + exit 0 ;; + CRAY*X-MP:*:*:*) + echo xmp-cray-unicos + exit 0 ;; + CRAY*Y-MP:*:*:*) + echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY*[A-Z]90:*:*:*) + echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ + | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ + -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ + -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY*TS:*:*:*) + echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY*T3D:*:*:*) + echo alpha-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY*T3E:*:*:*) + echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY*SV1:*:*:*) + echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY-2:*:*:*) + echo cray2-cray-unicos + exit 0 ;; + F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) + FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` + echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit 0 ;; + i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) + echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} + exit 0 ;; + sparc*:BSD/OS:*:*) + echo sparc-unknown-bsdi${UNAME_RELEASE} + exit 0 ;; + *:BSD/OS:*:*) + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} + exit 0 ;; + *:FreeBSD:*:*) + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + exit 0 ;; + i*:CYGWIN*:*) + echo ${UNAME_MACHINE}-pc-cygwin + exit 0 ;; + i*:MINGW*:*) + echo ${UNAME_MACHINE}-pc-mingw32 + exit 0 ;; + i*:PW*:*) + echo ${UNAME_MACHINE}-pc-pw32 + exit 0 ;; + i*:Windows_NT*:* | Pentium*:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we + # UNAME_MACHINE based on the output of uname instead of i386? + echo i386-pc-interix + exit 0 ;; + i*:UWIN*:*) + echo ${UNAME_MACHINE}-pc-uwin + exit 0 ;; + p*:CYGWIN*:*) + echo powerpcle-unknown-cygwin + exit 0 ;; + prep*:SunOS:5.*:*) + echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + *:GNU:*:*) + echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + exit 0 ;; + i*86:Minix:*:*) + echo ${UNAME_MACHINE}-pc-minix + exit 0 ;; + arm*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + ia64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux + exit 0 ;; + m68*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + mips:Linux:*:*) + case `sed -n '/^byte/s/^.*: \(.*\) endian/\1/p' < /proc/cpuinfo` in + big) echo mips-unknown-linux-gnu && exit 0 ;; + little) echo mipsel-unknown-linux-gnu && exit 0 ;; + esac + ;; + ppc:Linux:*:*) + echo powerpc-unknown-linux-gnu + exit 0 ;; + ppc64:Linux:*:*) + echo powerpc64-unknown-linux-gnu + exit 0 ;; + alpha:Linux:*:*) + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in + EV5) UNAME_MACHINE=alphaev5 ;; + EV56) UNAME_MACHINE=alphaev56 ;; + PCA56) UNAME_MACHINE=alphapca56 ;; + PCA57) UNAME_MACHINE=alphapca56 ;; + EV6) UNAME_MACHINE=alphaev6 ;; + EV67) UNAME_MACHINE=alphaev67 ;; + EV68*) UNAME_MACHINE=alphaev68 ;; + esac + objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null + if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi + echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} + exit 0 ;; + parisc:Linux:*:* | hppa:Linux:*:*) + # Look for CPU level + case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + PA7*) echo hppa1.1-unknown-linux-gnu ;; + PA8*) echo hppa2.0-unknown-linux-gnu ;; + *) echo hppa-unknown-linux-gnu ;; + esac + exit 0 ;; + parisc64:Linux:*:* | hppa64:Linux:*:*) + echo hppa64-unknown-linux-gnu + exit 0 ;; + s390:Linux:*:* | s390x:Linux:*:*) + echo ${UNAME_MACHINE}-ibm-linux + exit 0 ;; + sh*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + sparc:Linux:*:* | sparc64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + x86_64:Linux:*:*) + echo x86_64-unknown-linux-gnu + exit 0 ;; + i*86:Linux:*:*) + # The BFD linker knows what the default object file format is, so + # first see if it will tell us. cd to the root directory to prevent + # problems with other programs or directories called `ld' in the path. + ld_supported_targets=`cd /; ld --help 2>&1 \ + | sed -ne '/supported targets:/!d + s/[ ][ ]*/ /g + s/.*supported targets: *// + s/ .*// + p'` + case "$ld_supported_targets" in + elf32-i386) + TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" + ;; + a.out-i386-linux) + echo "${UNAME_MACHINE}-pc-linux-gnuaout" + exit 0 ;; + coff-i386) + echo "${UNAME_MACHINE}-pc-linux-gnucoff" + exit 0 ;; + "") + # Either a pre-BFD a.out linker (linux-gnuoldld) or + # one that does not give us useful --help. + echo "${UNAME_MACHINE}-pc-linux-gnuoldld" + exit 0 ;; + esac + # Determine whether the default compiler is a.out or elf + eval $set_cc_for_build + cat >$dummy.c <<EOF +#include <features.h> +#ifdef __cplusplus +#include <stdio.h> /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif +#ifdef __ELF__ +# ifdef __GLIBC__ +# if __GLIBC__ >= 2 + printf ("%s-pc-linux-gnu\n", argv[1]); +# else + printf ("%s-pc-linux-gnulibc1\n", argv[1]); +# endif +# else + printf ("%s-pc-linux-gnulibc1\n", argv[1]); +# endif +#else + printf ("%s-pc-linux-gnuaout\n", argv[1]); +#endif + return 0; +} +EOF + $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy "${UNAME_MACHINE}" && rm -f $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy + test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 + ;; + i*86:DYNIX/ptx:4*:*) + # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. + # earlier versions are messed up and put the nodename in both + # sysname and nodename. + echo i386-sequent-sysv4 + exit 0 ;; + i*86:UNIX_SV:4.2MP:2.*) + # Unixware is an offshoot of SVR4, but it has its own version + # number series starting with 2... + # I am not positive that other SVR4 systems won't match this, + # I just have to hope. -- rms. + # Use sysv4.2uw... so that sysv4* matches it. + echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} + exit 0 ;; + i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) + UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} + else + echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} + fi + exit 0 ;; + i*86:*:5:[78]*) + case `/bin/uname -X | grep "^Machine"` in + *486*) UNAME_MACHINE=i486 ;; + *Pentium) UNAME_MACHINE=i586 ;; + *Pent*|*Celeron) UNAME_MACHINE=i686 ;; + esac + echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + exit 0 ;; + i*86:*:3.2:*) + if test -f /usr/options/cb.name; then + UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name` + echo ${UNAME_MACHINE}-pc-isc$UNAME_REL + elif /bin/uname -X 2>/dev/null >/dev/null ; then + UNAME_REL=`(/bin/uname -X|egrep Release|sed -e 's/.*= //')` + (/bin/uname -X|egrep i80486 >/dev/null) && UNAME_MACHINE=i486 + (/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \ + && UNAME_MACHINE=i586 + (/bin/uname -X|egrep '^Machine.*Pent ?II' >/dev/null) \ + && UNAME_MACHINE=i686 + (/bin/uname -X|egrep '^Machine.*Pentium Pro' >/dev/null) \ + && UNAME_MACHINE=i686 + echo ${UNAME_MACHINE}-pc-sco$UNAME_REL + else + echo ${UNAME_MACHINE}-pc-sysv32 + fi + exit 0 ;; + i*86:*DOS:*:*) + echo ${UNAME_MACHINE}-pc-msdosdjgpp + exit 0 ;; + pc:*:*:*) + # Left here for compatibility: + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i386. + echo i386-pc-msdosdjgpp + exit 0 ;; + Intel:Mach:3*:*) + echo i386-pc-mach3 + exit 0 ;; + paragon:*:*:*) + echo i860-intel-osf1 + exit 0 ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + fi + exit 0 ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + echo m68010-convergent-sysv + exit 0 ;; + M68*:*:R3V[567]*:*) + test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;; + 3[34]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0) + OS_REL='' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && echo i486-ncr-sysv4.3${OS_REL} && exit 0 + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;; + 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && echo i486-ncr-sysv4 && exit 0 ;; + m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) + echo m68k-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + mc68030:UNIX_System_V:4.*:*) + echo m68k-atari-sysv4 + exit 0 ;; + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) + echo i386-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + TSUNAMI:LynxOS:2.*:*) + echo sparc-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + rs6000:LynxOS:2.*:*) + echo rs6000-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) + echo powerpc-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + SM[BE]S:UNIX_SV:*:*) + echo mips-dde-sysv${UNAME_RELEASE} + exit 0 ;; + RM*:ReliantUNIX-*:*:*) + echo mips-sni-sysv4 + exit 0 ;; + RM*:SINIX-*:*:*) + echo mips-sni-sysv4 + exit 0 ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + echo ${UNAME_MACHINE}-sni-sysv4 + else + echo ns32k-sni-sysv + fi + exit 0 ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says <Richard.M.Bartel@ccMail.Census.GOV> + echo i586-unisys-sysv4 + exit 0 ;; + *:UNIX_System_V:4*:FTX*) + # From Gerald Hewes <hewes@openmarket.com>. + # How about differentiating between stratus architectures? -djm + echo hppa1.1-stratus-sysv4 + exit 0 ;; + *:*:*:FTX*) + # From seanf@swdc.stratus.com. + echo i860-stratus-sysv4 + exit 0 ;; + *:VOS:*:*) + # From Paul.Green@stratus.com. + echo hppa1.1-stratus-vos + exit 0 ;; + mc68*:A/UX:*:*) + echo m68k-apple-aux${UNAME_RELEASE} + exit 0 ;; + news*:NEWS-OS:6*:*) + echo mips-sony-newsos6 + exit 0 ;; + R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) + if [ -d /usr/nec ]; then + echo mips-nec-sysv${UNAME_RELEASE} + else + echo mips-unknown-sysv${UNAME_RELEASE} + fi + exit 0 ;; + BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. + echo powerpc-be-beos + exit 0 ;; + BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. + echo powerpc-apple-beos + exit 0 ;; + BePC:BeOS:*:*) # BeOS running on Intel PC compatible. + echo i586-pc-beos + exit 0 ;; + SX-4:SUPER-UX:*:*) + echo sx4-nec-superux${UNAME_RELEASE} + exit 0 ;; + SX-5:SUPER-UX:*:*) + echo sx5-nec-superux${UNAME_RELEASE} + exit 0 ;; + Power*:Rhapsody:*:*) + echo powerpc-apple-rhapsody${UNAME_RELEASE} + exit 0 ;; + *:Rhapsody:*:*) + echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + exit 0 ;; + *:Darwin:*:*) + echo `uname -p`-apple-darwin${UNAME_RELEASE} + exit 0 ;; + *:procnto*:*:* | *:QNX:[0123456789]*:*) + if test "${UNAME_MACHINE}" = "x86pc"; then + UNAME_MACHINE=pc + fi + echo `uname -p`-${UNAME_MACHINE}-nto-qnx + exit 0 ;; + *:QNX:*:4*) + echo i386-pc-qnx + exit 0 ;; + NSR-[KW]:NONSTOP_KERNEL:*:*) + echo nsr-tandem-nsk${UNAME_RELEASE} + exit 0 ;; + *:NonStop-UX:*:*) + echo mips-compaq-nonstopux + exit 0 ;; + BS2000:POSIX*:*:*) + echo bs2000-siemens-sysv + exit 0 ;; + DS/*:UNIX_System_V:*:*) + echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} + exit 0 ;; + *:Plan9:*:*) + # "uname -m" is not consistent, so use $cputype instead. 386 + # is converted to i386 for consistency with other x86 + # operating systems. + if test "$cputype" = "386"; then + UNAME_MACHINE=i386 + else + UNAME_MACHINE="$cputype" + fi + echo ${UNAME_MACHINE}-unknown-plan9 + exit 0 ;; + i*86:OS/2:*:*) + # If we were able to find `uname', then EMX Unix compatibility + # is probably installed. + echo ${UNAME_MACHINE}-pc-os2-emx + exit 0 ;; + *:TOPS-10:*:*) + echo pdp10-unknown-tops10 + exit 0 ;; + *:TENEX:*:*) + echo pdp10-unknown-tenex + exit 0 ;; + KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) + echo pdp10-dec-tops20 + exit 0 ;; + XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) + echo pdp10-xkl-tops20 + exit 0 ;; + *:TOPS-20:*:*) + echo pdp10-unknown-tops20 + exit 0 ;; + *:ITS:*:*) + echo pdp10-unknown-its + exit 0 ;; + i*86:XTS-300:*:STOP) + echo ${UNAME_MACHINE}-unknown-stop + exit 0 ;; + i*86:atheos:*:*) + echo ${UNAME_MACHINE}-unknown-atheos + exit 0 ;; +esac + +#echo '(No uname command or uname output not recognized.)' 1>&2 +#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 + +eval $set_cc_for_build +cat >$dummy.c <<EOF +#ifdef _SEQUENT_ +# include <sys/types.h> +# include <sys/utsname.h> +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include <sys/param.h> + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (__arm) && defined (__acorn) && defined (__unix) + printf ("arm-acorn-riscix"); exit (0); +#endif + +#if defined (hp300) && !defined (hpux) + printf ("m68k-hp-bsd\n"); exit (0); +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); + +#endif + +#if defined (vax) +# if !defined (ultrix) +# include <sys/param.h> +# if defined (BSD) +# if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +# else +# if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# endif +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# else + printf ("vax-dec-ultrix\n"); exit (0); +# endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy && rm -f $dummy.c $dummy && exit 0 +rm -f $dummy.c $dummy + +# Apollos put the system type in the environment. + +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; } + +# Convex versions that predate uname can use getsysinfo(1) + +if [ -x /usr/convex/getsysinfo ] +then + case `getsysinfo -f cpu_type` in + c1*) + echo c1-convex-bsd + exit 0 ;; + c2*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit 0 ;; + c34*) + echo c34-convex-bsd + exit 0 ;; + c38*) + echo c38-convex-bsd + exit 0 ;; + c4*) + echo c4-convex-bsd + exit 0 ;; + esac +fi + +cat >&2 <<EOF +$0: unable to guess system type + +This script, last modified $timestamp, has failed to recognize +the operating system you are using. It is advised that you +download the most up to date version of the config scripts from + + ftp://ftp.gnu.org/pub/gnu/config/ + +If the version you run ($0) is already up to date, please +send the following data and any information you think might be +pertinent to <config-patches@gnu.org> in order to provide the needed +information to handle your system. + +config.guess timestamp = $timestamp + +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null` + +hostinfo = `(hostinfo) 2>/dev/null` +/bin/universe = `(/bin/universe) 2>/dev/null` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` +/bin/arch = `(/bin/arch) 2>/dev/null` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` + +UNAME_MACHINE = ${UNAME_MACHINE} +UNAME_RELEASE = ${UNAME_RELEASE} +UNAME_SYSTEM = ${UNAME_SYSTEM} +UNAME_VERSION = ${UNAME_VERSION} +EOF + +exit 1 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/pd/portaudio_v18/config.sub b/pd/portaudio_v18/config.sub new file mode 100644 index 00000000..791bcded --- /dev/null +++ b/pd/portaudio_v18/config.sub @@ -0,0 +1,1413 @@ +#! /bin/sh +# Configuration validation subroutine script. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +# Free Software Foundation, Inc. + +timestamp='2001-10-05' + +# This file is (in principle) common to ALL GNU software. +# The presence of a machine in this file suggests that SOME GNU software +# can handle that machine. It does not imply ALL GNU software can. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Please send patches to <config-patches@gnu.org>. Submit a context +# diff and a properly formatted ChangeLog entry. +# +# Configuration subroutine to validate and canonicalize a configuration type. +# Supply the specified configuration type as an argument. +# If it is invalid, we print an error message on stderr and exit with code 1. +# Otherwise, we print the canonical config type on stdout and succeed. + +# This file is supposed to be the same for all GNU packages +# and recognize all the CPU types, system types and aliases +# that are meaningful with *any* GNU software. +# Each package is responsible for reporting which valid configurations +# it does not support. The user should be able to distinguish +# a failure to support a valid configuration from a meaningless +# configuration. + +# The goal of this file is to map all the various variations of a given +# machine specification into a single specification in the form: +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or in some cases, the newer four-part form: +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM +# It is wrong to echo any other type of specification. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] CPU-MFR-OPSYS + $0 [OPTION] ALIAS + +Canonicalize a configuration name. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to <config-patches@gnu.org>." + +version="\ +GNU config.sub ($timestamp) + +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit 0 ;; + --version | -v ) + echo "$version" ; exit 0 ;; + --help | --h* | -h ) + echo "$usage"; exit 0 ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" + exit 1 ;; + + *local*) + # First pass through any local machine types. + echo $1 + exit 0;; + + * ) + break ;; + esac +done + +case $# in + 0) echo "$me: missing argument$help" >&2 + exit 1;; + 1) ;; + *) echo "$me: too many arguments$help" >&2 + exit 1;; +esac + +# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). +# Here we must recognize all the valid KERNEL-OS combinations. +maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` +case $maybe_os in + nto-qnx* | linux-gnu* | storm-chaos* | os2-emx* | windows32-*) + os=-$maybe_os + basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` + ;; + *) + basic_machine=`echo $1 | sed 's/-[^-]*$//'` + if [ $basic_machine != $1 ] + then os=`echo $1 | sed 's/.*-/-/'` + else os=; fi + ;; +esac + +### Let's recognize common machines as not being operating systems so +### that things like config.sub decstation-3100 work. We also +### recognize some manufacturers as not being operating systems, so we +### can provide default operating systems below. +case $os in + -sun*os*) + # Prevent following clause from handling this invalid input. + ;; + -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ + -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ + -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ + -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ + -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ + -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ + -apple | -axis) + os= + basic_machine=$1 + ;; + -sim | -cisco | -oki | -wec | -winbond) + os= + basic_machine=$1 + ;; + -scout) + ;; + -wrs) + os=-vxworks + basic_machine=$1 + ;; + -chorusos*) + os=-chorusos + basic_machine=$1 + ;; + -chorusrdb) + os=-chorusrdb + basic_machine=$1 + ;; + -hiux*) + os=-hiuxwe2 + ;; + -sco5) + os=-sco3.2v5 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco4) + os=-sco3.2v4 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2.[4-9]*) + os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2v[4-9]*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco*) + os=-sco3.2v2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -udk*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -isc) + os=-isc2.2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -clix*) + basic_machine=clipper-intergraph + ;; + -isc*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -lynx*) + os=-lynxos + ;; + -ptx*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + ;; + -windowsnt*) + os=`echo $os | sed -e 's/windowsnt/winnt/'` + ;; + -psos*) + os=-psos + ;; + -mint | -mint[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; +esac + +# Decode aliases for certain CPU-COMPANY combinations. +case $basic_machine in + # Recognize the basic CPU types without company name. + # Some are omitted here because they have special meanings below. + 1750a | 580 \ + | a29k \ + | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ + | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \ + | c4x | clipper \ + | d10v | d30v | dsp16xx \ + | fr30 \ + | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | i370 | i860 | i960 | ia64 \ + | m32r | m68000 | m68k | m88k | mcore \ + | mips16 | mips64 | mips64el | mips64orion | mips64orionel \ + | mips64vr4100 | mips64vr4100el | mips64vr4300 \ + | mips64vr4300el | mips64vr5000 | mips64vr5000el \ + | mipsbe | mipseb | mipsel | mipsle | mipstx39 | mipstx39el \ + | mipsisa32 \ + | mn10200 | mn10300 \ + | ns16k | ns32k \ + | openrisc \ + | pdp10 | pdp11 | pj | pjl \ + | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ + | pyramid \ + | s390 | s390x \ + | sh | sh[34] | sh[34]eb | shbe | shle \ + | sparc | sparc64 | sparclet | sparclite | sparcv9 | sparcv9b \ + | stormy16 | strongarm \ + | tahoe | thumb | tic80 | tron \ + | v850 \ + | we32k \ + | x86 | xscale \ + | z8k) + basic_machine=$basic_machine-unknown + ;; + m6811 | m68hc11 | m6812 | m68hc12) + # Motorola 68HC11/12. + basic_machine=$basic_machine-unknown + os=-none + ;; + m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) + ;; + + # We use `pc' rather than `unknown' + # because (1) that's what they normally are, and + # (2) the word "unknown" tends to confuse beginning users. + i*86 | x86_64) + basic_machine=$basic_machine-pc + ;; + # Object if more than one company name word. + *-*-*) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; + # Recognize the basic CPU types with company name. + 580-* \ + | a29k-* \ + | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ + | alphapca5[67]-* | arc-* \ + | arm-* | armbe-* | armle-* | armv*-* \ + | avr-* \ + | bs2000-* \ + | c[123]* | c30-* | [cjt]90-* | c54x-* \ + | clipper-* | cray2-* | cydra-* \ + | d10v-* | d30v-* \ + | elxsi-* \ + | f30[01]-* | f700-* | fr30-* | fx80-* \ + | h8300-* | h8500-* \ + | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ + | i*86-* | i860-* | i960-* | ia64-* \ + | m32r-* \ + | m68000-* | m680[01234]0-* | m68360-* | m683?2-* | m68k-* \ + | m88110-* | m88k-* | mcore-* \ + | mips-* | mips16-* | mips64-* | mips64el-* | mips64orion-* \ + | mips64orionel-* | mips64vr4100-* | mips64vr4100el-* \ + | mips64vr4300-* | mips64vr4300el-* | mipsbe-* | mipseb-* \ + | mipsle-* | mipsel-* | mipstx39-* | mipstx39el-* \ + | none-* | np1-* | ns16k-* | ns32k-* \ + | orion-* \ + | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ + | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ + | pyramid-* \ + | romp-* | rs6000-* \ + | s390-* | s390x-* \ + | sh-* | sh[34]-* | sh[34]eb-* | shbe-* | shle-* \ + | sparc-* | sparc64-* | sparc86x-* | sparclite-* \ + | sparcv9-* | sparcv9b-* | stormy16-* | strongarm-* | sv1-* \ + | t3e-* | tahoe-* | thumb-* | tic30-* | tic54x-* | tic80-* | tron-* \ + | v850-* | vax-* \ + | we32k-* \ + | x86-* | x86_64-* | xmp-* | xps100-* | xscale-* \ + | ymp-* \ + | z8k-*) + ;; + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 386bsd) + basic_machine=i386-unknown + os=-bsd + ;; + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + basic_machine=m68000-att + ;; + 3b*) + basic_machine=we32k-att + ;; + a29khif) + basic_machine=a29k-amd + os=-udi + ;; + adobe68k) + basic_machine=m68010-adobe + os=-scout + ;; + alliant | fx80) + basic_machine=fx80-alliant + ;; + altos | altos3068) + basic_machine=m68k-altos + ;; + am29k) + basic_machine=a29k-none + os=-bsd + ;; + amdahl) + basic_machine=580-amdahl + os=-sysv + ;; + amiga | amiga-*) + basic_machine=m68k-unknown + ;; + amigaos | amigados) + basic_machine=m68k-unknown + os=-amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + os=-sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + os=-sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + os=-bsd + ;; + aux) + basic_machine=m68k-apple + os=-aux + ;; + balance) + basic_machine=ns32k-sequent + os=-dynix + ;; + convex-c1) + basic_machine=c1-convex + os=-bsd + ;; + convex-c2) + basic_machine=c2-convex + os=-bsd + ;; + convex-c32) + basic_machine=c32-convex + os=-bsd + ;; + convex-c34) + basic_machine=c34-convex + os=-bsd + ;; + convex-c38) + basic_machine=c38-convex + os=-bsd + ;; + cray | ymp) + basic_machine=ymp-cray + os=-unicos + ;; + cray2) + basic_machine=cray2-cray + os=-unicos + ;; + [cjt]90) + basic_machine=${basic_machine}-cray + os=-unicos + ;; + crds | unos) + basic_machine=m68k-crds + ;; + cris | cris-* | etrax*) + basic_machine=cris-axis + ;; + da30 | da30-*) + basic_machine=m68k-da30 + ;; + decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) + basic_machine=mips-dec + ;; + delta | 3300 | motorola-3300 | motorola-delta \ + | 3300-motorola | delta-motorola) + basic_machine=m68k-motorola + ;; + delta88) + basic_machine=m88k-motorola + os=-sysv3 + ;; + dpx20 | dpx20-*) + basic_machine=rs6000-bull + os=-bosx + ;; + dpx2* | dpx2*-bull) + basic_machine=m68k-bull + os=-sysv3 + ;; + ebmon29k) + basic_machine=a29k-amd + os=-ebmon + ;; + elxsi) + basic_machine=elxsi-elxsi + os=-bsd + ;; + encore | umax | mmax) + basic_machine=ns32k-encore + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + os=-ose + ;; + fx2800) + basic_machine=i860-alliant + ;; + genix) + basic_machine=ns32k-ns + ;; + gmicro) + basic_machine=tron-gmicro + os=-sysv + ;; + go32) + basic_machine=i386-pc + os=-go32 + ;; + h3050r* | hiux*) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + h8300hms) + basic_machine=h8300-hitachi + os=-hms + ;; + h8300xray) + basic_machine=h8300-hitachi + os=-xray + ;; + h8500hms) + basic_machine=h8500-hitachi + os=-hms + ;; + harris) + basic_machine=m88k-harris + os=-sysv3 + ;; + hp300-*) + basic_machine=m68k-hp + ;; + hp300bsd) + basic_machine=m68k-hp + os=-bsd + ;; + hp300hpux) + basic_machine=m68k-hp + os=-hpux + ;; + hp3k9[0-9][0-9] | hp9[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + basic_machine=m68000-hp + ;; + hp9k3[2-9][0-9]) + basic_machine=m68k-hp + ;; + hp9k6[0-9][0-9] | hp6[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k7[0-79][0-9] | hp7[0-79][0-9]) + basic_machine=hppa1.1-hp + ;; + hp9k78[0-9] | hp78[0-9]) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][13679] | hp8[0-9][13679]) + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hppa-next) + os=-nextstep3 + ;; + hppaosf) + basic_machine=hppa1.1-hp + os=-osf + ;; + hppro) + basic_machine=hppa1.1-hp + os=-proelf + ;; + i370-ibm* | ibm*) + basic_machine=i370-ibm + ;; +# I'm not sure what "Sysv32" means. Should this be sysv3.2? + i*86v32) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv32 + ;; + i*86v4*) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv4 + ;; + i*86v) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv + ;; + i*86sol2) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-solaris2 + ;; + i386mach) + basic_machine=i386-mach + os=-mach + ;; + i386-vsta | vsta) + basic_machine=i386-unknown + os=-vsta + ;; + iris | iris4d) + basic_machine=mips-sgi + case $os in + -irix*) + ;; + *) + os=-irix4 + ;; + esac + ;; + isi68 | isi) + basic_machine=m68k-isi + os=-sysv + ;; + m88k-omron*) + basic_machine=m88k-omron + ;; + magnum | m3230) + basic_machine=mips-mips + os=-sysv + ;; + merlin) + basic_machine=ns32k-utek + os=-sysv + ;; + mingw32) + basic_machine=i386-pc + os=-mingw32 + ;; + miniframe) + basic_machine=m68000-convergent + ;; + *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; + mipsel*-linux*) + basic_machine=mipsel-unknown + os=-linux-gnu + ;; + mips*-linux*) + basic_machine=mips-unknown + os=-linux-gnu + ;; + mips3*-*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` + ;; + mips3*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown + ;; + mmix*) + basic_machine=mmix-knuth + os=-mmixware + ;; + monitor) + basic_machine=m68k-rom68k + os=-coff + ;; + msdos) + basic_machine=i386-pc + os=-msdos + ;; + mvs) + basic_machine=i370-ibm + os=-mvs + ;; + ncr3000) + basic_machine=i486-ncr + os=-sysv4 + ;; + netbsd386) + basic_machine=i386-unknown + os=-netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + os=-linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + os=-newsos + ;; + news1000) + basic_machine=m68030-sony + os=-newsos + ;; + news-3600 | risc-news) + basic_machine=mips-sony + os=-newsos + ;; + necv70) + basic_machine=v70-nec + os=-sysv + ;; + next | m*-next ) + basic_machine=m68k-next + case $os in + -nextstep* ) + ;; + -ns2*) + os=-nextstep2 + ;; + *) + os=-nextstep3 + ;; + esac + ;; + nh3000) + basic_machine=m68k-harris + os=-cxux + ;; + nh[45]000) + basic_machine=m88k-harris + os=-cxux + ;; + nindy960) + basic_machine=i960-intel + os=-nindy + ;; + mon960) + basic_machine=i960-intel + os=-mon960 + ;; + nonstopux) + basic_machine=mips-compaq + os=-nonstopux + ;; + np1) + basic_machine=np1-gould + ;; + nsr-tandem) + basic_machine=nsr-tandem + ;; + op50n-* | op60c-*) + basic_machine=hppa1.1-oki + os=-proelf + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + os=-ose + ;; + os68k) + basic_machine=m68k-none + os=-os68k + ;; + pa-hitachi) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + paragon) + basic_machine=i860-intel + os=-osf + ;; + pbd) + basic_machine=sparc-tti + ;; + pbb) + basic_machine=m68k-tti + ;; + pc532 | pc532-*) + basic_machine=ns32k-pc532 + ;; + pentium | p5 | k5 | k6 | nexgen | viac3) + basic_machine=i586-pc + ;; + pentiumpro | p6 | 6x86 | athlon) + basic_machine=i686-pc + ;; + pentiumii | pentium2) + basic_machine=i686-pc + ;; + pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) + basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumpro-* | p6-* | 6x86-* | athlon-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumii-* | pentium2-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pn) + basic_machine=pn-gould + ;; + power) basic_machine=power-ibm + ;; + ppc) basic_machine=powerpc-unknown + ;; + ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppcle | powerpclittle | ppc-le | powerpc-little) + basic_machine=powerpcle-unknown + ;; + ppcle-* | powerpclittle-*) + basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64) basic_machine=powerpc64-unknown + ;; + ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64le | powerpc64little | ppc64-le | powerpc64-little) + basic_machine=powerpc64le-unknown + ;; + ppc64le-* | powerpc64little-*) + basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ps2) + basic_machine=i386-ibm + ;; + pw32) + basic_machine=i586-unknown + os=-pw32 + ;; + rom68k) + basic_machine=m68k-rom68k + os=-coff + ;; + rm[46]00) + basic_machine=mips-siemens + ;; + rtpc | rtpc-*) + basic_machine=romp-ibm + ;; + sa29200) + basic_machine=a29k-amd + os=-udi + ;; + sequent) + basic_machine=i386-sequent + ;; + sh) + basic_machine=sh-hitachi + os=-hms + ;; + sparclite-wrs | simso-wrs) + basic_machine=sparclite-wrs + os=-vxworks + ;; + sps7) + basic_machine=m68k-bull + os=-sysv2 + ;; + spur) + basic_machine=spur-unknown + ;; + st2000) + basic_machine=m68k-tandem + ;; + stratus) + basic_machine=i860-stratus + os=-sysv4 + ;; + sun2) + basic_machine=m68000-sun + ;; + sun2os3) + basic_machine=m68000-sun + os=-sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + os=-sunos4 + ;; + sun3os3) + basic_machine=m68k-sun + os=-sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + os=-sunos4 + ;; + sun4os3) + basic_machine=sparc-sun + os=-sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + os=-sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + os=-solaris2 + ;; + sun3 | sun3-*) + basic_machine=m68k-sun + ;; + sun4) + basic_machine=sparc-sun + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + ;; + sv1) + basic_machine=sv1-cray + os=-unicos + ;; + symmetry) + basic_machine=i386-sequent + os=-dynix + ;; + t3e) + basic_machine=t3e-cray + os=-unicos + ;; + tic54x | c54x*) + basic_machine=tic54x-unknown + os=-coff + ;; + tx39) + basic_machine=mipstx39-unknown + ;; + tx39el) + basic_machine=mipstx39el-unknown + ;; + tower | tower-32) + basic_machine=m68k-ncr + ;; + udi29k) + basic_machine=a29k-amd + os=-udi + ;; + ultra3) + basic_machine=a29k-nyu + os=-sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + os=-none + ;; + vaxv) + basic_machine=vax-dec + os=-sysv + ;; + vms) + basic_machine=vax-dec + os=-vms + ;; + vpp*|vx|vx-*) + basic_machine=f301-fujitsu + ;; + vxworks960) + basic_machine=i960-wrs + os=-vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + os=-vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + os=-vxworks + ;; + w65*) + basic_machine=w65-wdc + os=-none + ;; + w89k-*) + basic_machine=hppa1.1-winbond + os=-proelf + ;; + windows32) + basic_machine=i386-pc + os=-windows32-msvcrt + ;; + xmp) + basic_machine=xmp-cray + os=-unicos + ;; + xps | xps100) + basic_machine=xps100-honeywell + ;; + z8k-*-coff) + basic_machine=z8k-unknown + os=-sim + ;; + none) + basic_machine=none-none + os=-none + ;; + +# Here we handle the default manufacturer of certain CPU types. It is in +# some cases the only manufacturer, in others, it is the most popular. + w89k) + basic_machine=hppa1.1-winbond + ;; + op50n) + basic_machine=hppa1.1-oki + ;; + op60c) + basic_machine=hppa1.1-oki + ;; + mips) + if [ x$os = x-linux-gnu ]; then + basic_machine=mips-unknown + else + basic_machine=mips-mips + fi + ;; + romp) + basic_machine=romp-ibm + ;; + rs6000) + basic_machine=rs6000-ibm + ;; + vax) + basic_machine=vax-dec + ;; + pdp10) + # there are many clones, so DEC is not a safe bet + basic_machine=pdp10-unknown + ;; + pdp11) + basic_machine=pdp11-dec + ;; + we32k) + basic_machine=we32k-att + ;; + sh3 | sh4 | sh3eb | sh4eb) + basic_machine=sh-unknown + ;; + sparc | sparcv9 | sparcv9b) + basic_machine=sparc-sun + ;; + cydra) + basic_machine=cydra-cydrome + ;; + orion) + basic_machine=orion-highlevel + ;; + orion105) + basic_machine=clipper-highlevel + ;; + mac | mpw | mac-mpw) + basic_machine=m68k-apple + ;; + pmac | pmac-mpw) + basic_machine=powerpc-apple + ;; + c4x*) + basic_machine=c4x-none + os=-coff + ;; + *-unknown) + # Make sure to match an already-canonicalized machine name. + ;; + *) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $basic_machine in + *-digital*) + basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` + ;; + *-commodore*) + basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if [ x"$os" != x"" ] +then +case $os in + # First match some system type aliases + # that might get confused with valid system types. + # -solaris* is a basic system type, with this one exception. + -solaris1 | -solaris1.*) + os=`echo $os | sed -e 's|solaris1|sunos4|'` + ;; + -solaris) + os=-solaris2 + ;; + -svr4*) + os=-sysv4 + ;; + -unixware*) + os=-sysv4.2uw + ;; + -gnu/linux*) + os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` + ;; + # First accept the basic system types. + # The portable systems comes first. + # Each alternative MUST END IN A *, to match a version number. + # -sysv* is not here because it comes later, after sysvr4. + -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ + | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ + | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ + | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ + | -aos* \ + | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ + | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ + | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \ + | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ + | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ + | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ + | -chorusos* | -chorusrdb* \ + | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \ + | -interix* | -uwin* | -rhapsody* | -darwin* | -opened* \ + | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ + | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ + | -os2* | -vos*) + # Remember, each alternative MUST END IN *, to match a version number. + ;; + -qnx*) + case $basic_machine in + x86-* | i*86-*) + ;; + *) + os=-nto$os + ;; + esac + ;; + -nto*) + os=-nto-qnx + ;; + -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ + | -windows* | -osx | -abug | -netware* | -os9* | -beos* \ + | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) + ;; + -mac*) + os=`echo $os | sed -e 's|mac|macos|'` + ;; + -linux*) + os=`echo $os | sed -e 's|linux|linux-gnu|'` + ;; + -sunos5*) + os=`echo $os | sed -e 's|sunos5|solaris2|'` + ;; + -sunos6*) + os=`echo $os | sed -e 's|sunos6|solaris3|'` + ;; + -opened*) + os=-openedition + ;; + -wince*) + os=-wince + ;; + -osfrose*) + os=-osfrose + ;; + -osf*) + os=-osf + ;; + -utek*) + os=-bsd + ;; + -dynix*) + os=-bsd + ;; + -acis*) + os=-aos + ;; + -386bsd) + os=-bsd + ;; + -ctix* | -uts*) + os=-sysv + ;; + -ns2 ) + os=-nextstep2 + ;; + -nsk*) + os=-nsk + ;; + # Preserve the version number of sinix5. + -sinix5.*) + os=`echo $os | sed -e 's|sinix|sysv|'` + ;; + -sinix*) + os=-sysv4 + ;; + -triton*) + os=-sysv3 + ;; + -oss*) + os=-sysv3 + ;; + -svr4) + os=-sysv4 + ;; + -svr3) + os=-sysv3 + ;; + -sysvr4) + os=-sysv4 + ;; + # This must come after -sysvr4. + -sysv*) + ;; + -ose*) + os=-ose + ;; + -es1800*) + os=-ose + ;; + -xenix) + os=-xenix + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + os=-mint + ;; + -none) + ;; + *) + # Get rid of the `-' at the beginning of $os. + os=`echo $os | sed 's/[^-]*-//'` + echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 + exit 1 + ;; +esac +else + +# Here we handle the default operating systems that come with various machines. +# The value should be what the vendor currently ships out the door with their +# machine or put another way, the most popular os provided with the machine. + +# Note that if you're going to try to match "-MANUFACTURER" here (say, +# "-sun"), then you have to tell the case statement up towards the top +# that MANUFACTURER isn't an operating system. Otherwise, code above +# will signal an error saying that MANUFACTURER isn't an operating +# system, and we'll never get to this point. + +case $basic_machine in + *-acorn) + os=-riscix1.2 + ;; + arm*-rebel) + os=-linux + ;; + arm*-semi) + os=-aout + ;; + pdp10-*) + os=-tops20 + ;; + pdp11-*) + os=-none + ;; + *-dec | vax-*) + os=-ultrix4.2 + ;; + m68*-apollo) + os=-domain + ;; + i386-sun) + os=-sunos4.0.2 + ;; + m68000-sun) + os=-sunos3 + # This also exists in the configure program, but was not the + # default. + # os=-sunos4 + ;; + m68*-cisco) + os=-aout + ;; + mips*-cisco) + os=-elf + ;; + mips*-*) + os=-elf + ;; + *-tti) # must be before sparc entry or we get the wrong os. + os=-sysv3 + ;; + sparc-* | *-sun) + os=-sunos4.1.1 + ;; + *-be) + os=-beos + ;; + *-ibm) + os=-aix + ;; + *-wec) + os=-proelf + ;; + *-winbond) + os=-proelf + ;; + *-oki) + os=-proelf + ;; + *-hp) + os=-hpux + ;; + *-hitachi) + os=-hiux + ;; + i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) + os=-sysv + ;; + *-cbm) + os=-amigaos + ;; + *-dg) + os=-dgux + ;; + *-dolphin) + os=-sysv3 + ;; + m68k-ccur) + os=-rtu + ;; + m88k-omron*) + os=-luna + ;; + *-next ) + os=-nextstep + ;; + *-sequent) + os=-ptx + ;; + *-crds) + os=-unos + ;; + *-ns) + os=-genix + ;; + i370-*) + os=-mvs + ;; + *-next) + os=-nextstep3 + ;; + *-gould) + os=-sysv + ;; + *-highlevel) + os=-bsd + ;; + *-encore) + os=-bsd + ;; + *-sgi) + os=-irix + ;; + *-siemens) + os=-sysv4 + ;; + *-masscomp) + os=-rtu + ;; + f30[01]-fujitsu | f700-fujitsu) + os=-uxpv + ;; + *-rom68k) + os=-coff + ;; + *-*bug) + os=-coff + ;; + *-apple) + os=-macos + ;; + *-atari*) + os=-mint + ;; + *) + os=-none + ;; +esac +fi + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +vendor=unknown +case $basic_machine in + *-unknown) + case $os in + -riscix*) + vendor=acorn + ;; + -sunos*) + vendor=sun + ;; + -aix*) + vendor=ibm + ;; + -beos*) + vendor=be + ;; + -hpux*) + vendor=hp + ;; + -mpeix*) + vendor=hp + ;; + -hiux*) + vendor=hitachi + ;; + -unos*) + vendor=crds + ;; + -dgux*) + vendor=dg + ;; + -luna*) + vendor=omron + ;; + -genix*) + vendor=ns + ;; + -mvs* | -opened*) + vendor=ibm + ;; + -ptx*) + vendor=sequent + ;; + -vxsim* | -vxworks*) + vendor=wrs + ;; + -aux*) + vendor=apple + ;; + -hms*) + vendor=hitachi + ;; + -mpw* | -macos*) + vendor=apple + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + vendor=atari + ;; + -vos*) + vendor=stratus + ;; + esac + basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` + ;; +esac + +echo $basic_machine$os +exit 0 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/pd/portaudio_v18/configure b/pd/portaudio_v18/configure new file mode 100644 index 00000000..67ec37b0 --- /dev/null +++ b/pd/portaudio_v18/configure @@ -0,0 +1,2622 @@ +#! /bin/sh +# Guess values for system-dependent variables and create Makefiles. +# Generated by Autoconf 2.52. +# +# Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 +# Free Software Foundation, Inc. +# This configure script is free software; the Free Software Foundation +# gives unlimited permission to copy, distribute and modify it. + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="sed y%*+%pp%;s%[^_$as_cr_alnum]%_%g" + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="sed y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g" + +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: +elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then + set -o posix +fi + +# Name of the executable. +as_me=`echo "$0" |sed 's,.*[\\/],,'` + +if expr a : '\(a\)' >/dev/null 2>&1; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + # We could just check for DJGPP; but this test a) works b) is more generic + # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). + if test -f conf$$.exe; then + # Don't use ln at all; we don't have any links + as_ln_s='cp -p' + else + as_ln_s='ln -s' + fi +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.file + +as_executable_p="test -f" + +# Support unset when possible. +if (FOO=FOO; unset FOO) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + +# NLS nuisances. +$as_unset LANG || test "${LANG+set}" != set || { LANG=C; export LANG; } +$as_unset LC_ALL || test "${LC_ALL+set}" != set || { LC_ALL=C; export LC_ALL; } +$as_unset LC_TIME || test "${LC_TIME+set}" != set || { LC_TIME=C; export LC_TIME; } +$as_unset LC_CTYPE || test "${LC_CTYPE+set}" != set || { LC_CTYPE=C; export LC_CTYPE; } +$as_unset LANGUAGE || test "${LANGUAGE+set}" != set || { LANGUAGE=C; export LANGUAGE; } +$as_unset LC_COLLATE || test "${LC_COLLATE+set}" != set || { LC_COLLATE=C; export LC_COLLATE; } +$as_unset LC_NUMERIC || test "${LC_NUMERIC+set}" != set || { LC_NUMERIC=C; export LC_NUMERIC; } +$as_unset LC_MESSAGES || test "${LC_MESSAGES+set}" != set || { LC_MESSAGES=C; export LC_MESSAGES; } + +# IFS +# We need space, tab and new line, in precisely that order. +as_nl=' +' +IFS=" $as_nl" + +# CDPATH. +$as_unset CDPATH || test "${CDPATH+set}" != set || { CDPATH=:; export CDPATH; } + +# Name of the host. +# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +exec 6>&1 + +# +# Initializations. +# +ac_default_prefix=/usr/local +cross_compiling=no +subdirs= +MFLAGS= MAKEFLAGS= +SHELL=${CONFIG_SHELL-/bin/sh} + +# Maximum number of lines to put in a shell here document. +# This variable seems obsolete. It should probably be removed, and +# only ac_max_sed_lines should be used. +: ${ac_max_here_lines=38} + +ac_unique_file="pa_common/portaudio.h" + +# Initialize some variables set by options. +ac_init_help= +ac_init_version=false +# The variables have the same names as the options, with +# dashes changed to underlines. +cache_file=/dev/null +exec_prefix=NONE +no_create= +no_recursion= +prefix=NONE +program_prefix=NONE +program_suffix=NONE +program_transform_name=s,x,x, +silent= +site= +srcdir= +verbose= +x_includes=NONE +x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +bindir='${exec_prefix}/bin' +sbindir='${exec_prefix}/sbin' +libexecdir='${exec_prefix}/libexec' +datadir='${prefix}/share' +sysconfdir='${prefix}/etc' +sharedstatedir='${prefix}/com' +localstatedir='${prefix}/var' +libdir='${exec_prefix}/lib' +includedir='${prefix}/include' +oldincludedir='/usr/include' +infodir='${prefix}/info' +mandir='${prefix}/man' + +# Identity of this package. +PACKAGE_NAME= +PACKAGE_TARNAME= +PACKAGE_VERSION= +PACKAGE_STRING= +PACKAGE_BUGREPORT= + +ac_prev= +for ac_option +do + # If the previous option needs an argument, assign it. + if test -n "$ac_prev"; then + eval "$ac_prev=\$ac_option" + ac_prev= + continue + fi + + ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` + + # Accept the important Cygnus configure options, so we can diagnose typos. + + case $ac_option in + + -bindir | --bindir | --bindi | --bind | --bin | --bi) + ac_prev=bindir ;; + -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) + bindir=$ac_optarg ;; + + -build | --build | --buil | --bui | --bu) + ac_prev=build_alias ;; + -build=* | --build=* | --buil=* | --bui=* | --bu=*) + build_alias=$ac_optarg ;; + + -cache-file | --cache-file | --cache-fil | --cache-fi \ + | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) + ac_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) + cache_file=$ac_optarg ;; + + --config-cache | -C) + cache_file=config.cache ;; + + -datadir | --datadir | --datadi | --datad | --data | --dat | --da) + ac_prev=datadir ;; + -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \ + | --da=*) + datadir=$ac_optarg ;; + + -disable-* | --disable-*) + ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/-/_/g'` + eval "enable_$ac_feature=no" ;; + + -enable-* | --enable-*) + ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/-/_/g'` + case $ac_option in + *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; + *) ac_optarg=yes ;; + esac + eval "enable_$ac_feature='$ac_optarg'" ;; + + -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ + | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ + | --exec | --exe | --ex) + ac_prev=exec_prefix ;; + -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ + | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ + | --exec=* | --exe=* | --ex=*) + exec_prefix=$ac_optarg ;; + + -gas | --gas | --ga | --g) + # Obsolete; use --with-gas. + with_gas=yes ;; + + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; + + -host | --host | --hos | --ho) + ac_prev=host_alias ;; + -host=* | --host=* | --hos=* | --ho=*) + host_alias=$ac_optarg ;; + + -includedir | --includedir | --includedi | --included | --include \ + | --includ | --inclu | --incl | --inc) + ac_prev=includedir ;; + -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ + | --includ=* | --inclu=* | --incl=* | --inc=*) + includedir=$ac_optarg ;; + + -infodir | --infodir | --infodi | --infod | --info | --inf) + ac_prev=infodir ;; + -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) + infodir=$ac_optarg ;; + + -libdir | --libdir | --libdi | --libd) + ac_prev=libdir ;; + -libdir=* | --libdir=* | --libdi=* | --libd=*) + libdir=$ac_optarg ;; + + -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ + | --libexe | --libex | --libe) + ac_prev=libexecdir ;; + -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ + | --libexe=* | --libex=* | --libe=*) + libexecdir=$ac_optarg ;; + + -localstatedir | --localstatedir | --localstatedi | --localstated \ + | --localstate | --localstat | --localsta | --localst \ + | --locals | --local | --loca | --loc | --lo) + ac_prev=localstatedir ;; + -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ + | --localstate=* | --localstat=* | --localsta=* | --localst=* \ + | --locals=* | --local=* | --loca=* | --loc=* | --lo=*) + localstatedir=$ac_optarg ;; + + -mandir | --mandir | --mandi | --mand | --man | --ma | --m) + ac_prev=mandir ;; + -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) + mandir=$ac_optarg ;; + + -nfp | --nfp | --nf) + # Obsolete; use --without-fp. + with_fp=no ;; + + -no-create | --no-create | --no-creat | --no-crea | --no-cre \ + | --no-cr | --no-c) + no_create=yes ;; + + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) + no_recursion=yes ;; + + -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ + | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ + | --oldin | --oldi | --old | --ol | --o) + ac_prev=oldincludedir ;; + -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ + | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ + | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) + oldincludedir=$ac_optarg ;; + + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ac_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + prefix=$ac_optarg ;; + + -program-prefix | --program-prefix | --program-prefi | --program-pref \ + | --program-pre | --program-pr | --program-p) + ac_prev=program_prefix ;; + -program-prefix=* | --program-prefix=* | --program-prefi=* \ + | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) + program_prefix=$ac_optarg ;; + + -program-suffix | --program-suffix | --program-suffi | --program-suff \ + | --program-suf | --program-su | --program-s) + ac_prev=program_suffix ;; + -program-suffix=* | --program-suffix=* | --program-suffi=* \ + | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) + program_suffix=$ac_optarg ;; + + -program-transform-name | --program-transform-name \ + | --program-transform-nam | --program-transform-na \ + | --program-transform-n | --program-transform- \ + | --program-transform | --program-transfor \ + | --program-transfo | --program-transf \ + | --program-trans | --program-tran \ + | --progr-tra | --program-tr | --program-t) + ac_prev=program_transform_name ;; + -program-transform-name=* | --program-transform-name=* \ + | --program-transform-nam=* | --program-transform-na=* \ + | --program-transform-n=* | --program-transform-=* \ + | --program-transform=* | --program-transfor=* \ + | --program-transfo=* | --program-transf=* \ + | --program-trans=* | --program-tran=* \ + | --progr-tra=* | --program-tr=* | --program-t=*) + program_transform_name=$ac_optarg ;; + + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + silent=yes ;; + + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) + ac_prev=sbindir ;; + -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ + | --sbi=* | --sb=*) + sbindir=$ac_optarg ;; + + -sharedstatedir | --sharedstatedir | --sharedstatedi \ + | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ + | --sharedst | --shareds | --shared | --share | --shar \ + | --sha | --sh) + ac_prev=sharedstatedir ;; + -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ + | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ + | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ + | --sha=* | --sh=*) + sharedstatedir=$ac_optarg ;; + + -site | --site | --sit) + ac_prev=site ;; + -site=* | --site=* | --sit=*) + site=$ac_optarg ;; + + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + ac_prev=srcdir ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + srcdir=$ac_optarg ;; + + -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ + | --syscon | --sysco | --sysc | --sys | --sy) + ac_prev=sysconfdir ;; + -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ + | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) + sysconfdir=$ac_optarg ;; + + -target | --target | --targe | --targ | --tar | --ta | --t) + ac_prev=target_alias ;; + -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) + target_alias=$ac_optarg ;; + + -v | -verbose | --verbose | --verbos | --verbo | --verb) + verbose=yes ;; + + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; + + -with-* | --with-*) + ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } + ac_package=`echo $ac_package| sed 's/-/_/g'` + case $ac_option in + *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; + *) ac_optarg=yes ;; + esac + eval "with_$ac_package='$ac_optarg'" ;; + + -without-* | --without-*) + ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } + ac_package=`echo $ac_package | sed 's/-/_/g'` + eval "with_$ac_package=no" ;; + + --x) + # Obsolete; use --with-x. + with_x=yes ;; + + -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ + | --x-incl | --x-inc | --x-in | --x-i) + ac_prev=x_includes ;; + -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ + | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) + x_includes=$ac_optarg ;; + + -x-libraries | --x-libraries | --x-librarie | --x-librari \ + | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) + ac_prev=x_libraries ;; + -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ + | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) + x_libraries=$ac_optarg ;; + + -*) { echo "$as_me: error: unrecognized option: $ac_option +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; } + ;; + + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid variable name: $ac_envvar" >&2 + { (exit 1); exit 1; }; } + ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` + eval "$ac_envvar='$ac_optarg'" + export $ac_envvar ;; + + *) + # FIXME: should be removed in autoconf 3.0. + echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} + ;; + + esac +done + +if test -n "$ac_prev"; then + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + { echo "$as_me: error: missing argument to $ac_option" >&2 + { (exit 1); exit 1; }; } +fi + +# Be sure to have absolute paths. +for ac_var in exec_prefix prefix +do + eval ac_val=$`echo $ac_var` + case $ac_val in + [\\/$]* | ?:[\\/]* | NONE | '' ) ;; + *) { echo "$as_me: error: expected an absolute path for --$ac_var: $ac_val" >&2 + { (exit 1); exit 1; }; };; + esac +done + +# Be sure to have absolute paths. +for ac_var in bindir sbindir libexecdir datadir sysconfdir sharedstatedir \ + localstatedir libdir includedir oldincludedir infodir mandir +do + eval ac_val=$`echo $ac_var` + case $ac_val in + [\\/$]* | ?:[\\/]* ) ;; + *) { echo "$as_me: error: expected an absolute path for --$ac_var: $ac_val" >&2 + { (exit 1); exit 1; }; };; + esac +done + +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +build=$build_alias +host=$host_alias +target=$target_alias + +# FIXME: should be removed in autoconf 3.0. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used." >&2 + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi + +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null + +# Find the source files, if location was not specified. +if test -z "$srcdir"; then + ac_srcdir_defaulted=yes + # Try the directory containing this script, then its parent. + ac_prog=$0 + ac_confdir=`echo "$ac_prog" | sed 's%[\\/][^\\/][^\\/]*$%%'` + test "x$ac_confdir" = "x$ac_prog" && ac_confdir=. + srcdir=$ac_confdir + if test ! -r $srcdir/$ac_unique_file; then + srcdir=.. + fi +else + ac_srcdir_defaulted=no +fi +if test ! -r $srcdir/$ac_unique_file; then + if test "$ac_srcdir_defaulted" = yes; then + { echo "$as_me: error: cannot find sources in $ac_confdir or .." >&2 + { (exit 1); exit 1; }; } + else + { echo "$as_me: error: cannot find sources in $srcdir" >&2 + { (exit 1); exit 1; }; } + fi +fi +srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'` +ac_env_build_alias_set=${build_alias+set} +ac_env_build_alias_value=$build_alias +ac_cv_env_build_alias_set=${build_alias+set} +ac_cv_env_build_alias_value=$build_alias +ac_env_host_alias_set=${host_alias+set} +ac_env_host_alias_value=$host_alias +ac_cv_env_host_alias_set=${host_alias+set} +ac_cv_env_host_alias_value=$host_alias +ac_env_target_alias_set=${target_alias+set} +ac_env_target_alias_value=$target_alias +ac_cv_env_target_alias_set=${target_alias+set} +ac_cv_env_target_alias_value=$target_alias +ac_env_CC_set=${CC+set} +ac_env_CC_value=$CC +ac_cv_env_CC_set=${CC+set} +ac_cv_env_CC_value=$CC +ac_env_CFLAGS_set=${CFLAGS+set} +ac_env_CFLAGS_value=$CFLAGS +ac_cv_env_CFLAGS_set=${CFLAGS+set} +ac_cv_env_CFLAGS_value=$CFLAGS +ac_env_LDFLAGS_set=${LDFLAGS+set} +ac_env_LDFLAGS_value=$LDFLAGS +ac_cv_env_LDFLAGS_set=${LDFLAGS+set} +ac_cv_env_LDFLAGS_value=$LDFLAGS +ac_env_CPPFLAGS_set=${CPPFLAGS+set} +ac_env_CPPFLAGS_value=$CPPFLAGS +ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set} +ac_cv_env_CPPFLAGS_value=$CPPFLAGS + +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<EOF +\`configure' configures this package to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +EOF + + cat <<EOF +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + [PREFIX] + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --datadir=DIR read-only architecture-independent data [PREFIX/share] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --infodir=DIR info documentation [PREFIX/info] + --mandir=DIR man documentation [PREFIX/man] +EOF + + cat <<\EOF + +System types: + --build=BUILD configure for building on BUILD [guessed] + --host=HOST build programs to run on HOST [BUILD] +EOF +fi + +if test -n "$ac_init_help"; then + + cat <<\EOF + +Some influential environment variables: + CC C compiler command + CFLAGS C compiler flags + LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a + nonstandard directory <lib dir> + CPPFLAGS C/C++ preprocessor flags, e.g. -I<include dir> if you have + headers in a nonstandard directory <include dir> + +Use these variables to override the choices made by `configure' or to help +it to find libraries and programs with nonstandard names/locations. + +EOF +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + ac_popdir=`pwd` + for ac_subdir in : $ac_subdirs_all; do test "x$ac_subdir" = x: && continue + cd $ac_subdir + # A "../" for each directory in /$ac_subdir. + ac_dots=`echo $ac_subdir | + sed 's,^\./,,;s,[^/]$,&/,;s,[^/]*/,../,g'` + + case $srcdir in + .) # No --srcdir option. We are building in place. + ac_sub_srcdir=$srcdir ;; + [\\/]* | ?:[\\/]* ) # Absolute path. + ac_sub_srcdir=$srcdir/$ac_subdir ;; + *) # Relative path. + ac_sub_srcdir=$ac_dots$srcdir/$ac_subdir ;; + esac + + # Check for guested configure; otherwise get Cygnus style configure. + if test -f $ac_sub_srcdir/configure.gnu; then + echo + $SHELL $ac_sub_srcdir/configure.gnu --help=recursive + elif test -f $ac_sub_srcdir/configure; then + echo + $SHELL $ac_sub_srcdir/configure --help=recursive + elif test -f $ac_sub_srcdir/configure.ac || + test -f $ac_sub_srcdir/configure.in; then + echo + $ac_configure --help + else + echo "$as_me: WARNING: no configuration information is in $ac_subdir" >&2 + fi + cd $ac_popdir + done +fi + +test -n "$ac_init_help" && exit 0 +if $ac_init_version; then + cat <<\EOF + +Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 +Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +EOF + exit 0 +fi +exec 5>config.log +cat >&5 <<EOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by $as_me, which was +generated by GNU Autoconf 2.52. Invocation command line was + + $ $0 $@ + +EOF +{ +cat <<_ASUNAME +## ---------- ## +## Platform. ## +## ---------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +hostinfo = `(hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +PATH = $PATH + +_ASUNAME +} >&5 + +cat >&5 <<EOF +## ------------ ## +## Core tests. ## +## ------------ ## + +EOF + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Also quote any args containing shell meta-characters. +ac_configure_args= +ac_sep= +for ac_arg +do + case $ac_arg in + -no-create | --no-create | --no-creat | --no-crea | --no-cre \ + | --no-cr | --no-c) ;; + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;; + *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*) + ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` + ac_configure_args="$ac_configure_args$ac_sep'$ac_arg'" + ac_sep=" " ;; + *) ac_configure_args="$ac_configure_args$ac_sep$ac_arg" + ac_sep=" " ;; + esac + # Get rid of the leading space. +done + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +trap 'exit_status=$? + # Save into config.log some information that might help in debugging. + echo >&5 + echo "## ----------------- ##" >&5 + echo "## Cache variables. ##" >&5 + echo "## ----------------- ##" >&5 + echo >&5 + # The following way of writing the cache mishandles newlines in values, +{ + (set) 2>&1 | + case `(ac_space='"'"' '"'"'; set | grep ac_space) 2>&1` in + *ac_space=\ *) + sed -n \ + "s/'"'"'/'"'"'\\\\'"'"''"'"'/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='"'"'\\2'"'"'/p" + ;; + *) + sed -n \ + "s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" + ;; + esac; +} >&5 + sed "/^$/d" confdefs.h >conftest.log + if test -s conftest.log; then + echo >&5 + echo "## ------------ ##" >&5 + echo "## confdefs.h. ##" >&5 + echo "## ------------ ##" >&5 + echo >&5 + cat conftest.log >&5 + fi + (echo; echo) >&5 + test "$ac_signal" != 0 && + echo "$as_me: caught signal $ac_signal" >&5 + echo "$as_me: exit $exit_status" >&5 + rm -rf conftest* confdefs* core core.* *.core conf$$* $ac_clean_files && + exit $exit_status + ' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -rf conftest* confdefs.h +# AIX cpp loses on an empty file, so make sure it contains at least a newline. +echo >confdefs.h + +# Let the site file select an alternate cache file if it wants to. +# Prefer explicitly selected file to automatically selected ones. +if test -z "$CONFIG_SITE"; then + if test "x$prefix" != xNONE; then + CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site" + else + CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" + fi +fi +for ac_site_file in $CONFIG_SITE; do + if test -r "$ac_site_file"; then + { echo "$as_me:818: loading site script $ac_site_file" >&5 +echo "$as_me: loading site script $ac_site_file" >&6;} + cat "$ac_site_file" >&5 + . "$ac_site_file" + fi +done + +if test -r "$cache_file"; then + # Some versions of bash will fail to source /dev/null (special + # files actually), so we avoid doing that. + if test -f "$cache_file"; then + { echo "$as_me:829: loading cache $cache_file" >&5 +echo "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . $cache_file;; + *) . ./$cache_file;; + esac + fi +else + { echo "$as_me:837: creating cache $cache_file" >&5 +echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file +fi + +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in `(set) 2>&1 | + sed -n 's/^ac_env_\([a-zA-Z_0-9]*\)_set=.*/\1/p'`; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val="\$ac_cv_env_${ac_var}_value" + eval ac_new_val="\$ac_env_${ac_var}_value" + case $ac_old_set,$ac_new_set in + set,) + { echo "$as_me:853: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { echo "$as_me:857: error: \`$ac_var' was not set in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + { echo "$as_me:863: error: \`$ac_var' has changed since the previous run:" >&5 +echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + { echo "$as_me:865: former value: $ac_old_val" >&5 +echo "$as_me: former value: $ac_old_val" >&2;} + { echo "$as_me:867: current value: $ac_new_val" >&5 +echo "$as_me: current value: $ac_new_val" >&2;} + ac_cache_corrupted=: + fi;; + esac + # Pass precious variables to config.status. It doesn't matter if + # we pass some twice (in addition to the command line arguments). + if test "$ac_new_set" = set; then + case $ac_new_val in + *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*) + ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` + ac_configure_args="$ac_configure_args '$ac_arg'" + ;; + *) ac_configure_args="$ac_configure_args $ac_var=$ac_new_val" + ;; + esac + fi +done +if $ac_cache_corrupted; then + { echo "$as_me:886: error: changes in the environment can compromise the build" >&5 +echo "$as_me: error: changes in the environment can compromise the build" >&2;} + { { echo "$as_me:888: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5 +echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;} + { (exit 1); exit 1; }; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in + *c*,-n*) ECHO_N= ECHO_C=' +' ECHO_T=' ' ;; + *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;; + *) ECHO_N= ECHO_C='\c' ECHO_T= ;; +esac +echo "#! $SHELL" >conftest.sh +echo "exit 0" >>conftest.sh +chmod +x conftest.sh +if { (echo "$as_me:908: PATH=\".;.\"; conftest.sh") >&5 + (PATH=".;."; conftest.sh) 2>&5 + ac_status=$? + echo "$as_me:911: \$? = $ac_status" >&5 + (exit $ac_status); }; then + ac_path_separator=';' +else + ac_path_separator=: +fi +PATH_SEPARATOR="$ac_path_separator" +rm -f conftest.sh + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +echo "$as_me:928: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_save_IFS=$IFS; IFS=$ac_path_separator +ac_dummy="$PATH" +for ac_dir in $ac_dummy; do + IFS=$ac_save_IFS + test -z "$ac_dir" && ac_dir=. + $as_executable_p "$ac_dir/$ac_word" || continue +ac_cv_prog_CC="${ac_tool_prefix}gcc" +echo "$as_me:943: found $ac_dir/$ac_word" >&5 +break +done + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + echo "$as_me:951: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6 +else + echo "$as_me:954: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +echo "$as_me:963: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else + ac_save_IFS=$IFS; IFS=$ac_path_separator +ac_dummy="$PATH" +for ac_dir in $ac_dummy; do + IFS=$ac_save_IFS + test -z "$ac_dir" && ac_dir=. + $as_executable_p "$ac_dir/$ac_word" || continue +ac_cv_prog_ac_ct_CC="gcc" +echo "$as_me:978: found $ac_dir/$ac_word" >&5 +break +done + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + echo "$as_me:986: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6 +else + echo "$as_me:989: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + + CC=$ac_ct_CC +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +echo "$as_me:1002: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_save_IFS=$IFS; IFS=$ac_path_separator +ac_dummy="$PATH" +for ac_dir in $ac_dummy; do + IFS=$ac_save_IFS + test -z "$ac_dir" && ac_dir=. + $as_executable_p "$ac_dir/$ac_word" || continue +ac_cv_prog_CC="${ac_tool_prefix}cc" +echo "$as_me:1017: found $ac_dir/$ac_word" >&5 +break +done + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + echo "$as_me:1025: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6 +else + echo "$as_me:1028: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +echo "$as_me:1037: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else + ac_save_IFS=$IFS; IFS=$ac_path_separator +ac_dummy="$PATH" +for ac_dir in $ac_dummy; do + IFS=$ac_save_IFS + test -z "$ac_dir" && ac_dir=. + $as_executable_p "$ac_dir/$ac_word" || continue +ac_cv_prog_ac_ct_CC="cc" +echo "$as_me:1052: found $ac_dir/$ac_word" >&5 +break +done + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + echo "$as_me:1060: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6 +else + echo "$as_me:1063: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + + CC=$ac_ct_CC +else + CC="$ac_cv_prog_CC" +fi + +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +echo "$as_me:1076: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no + ac_save_IFS=$IFS; IFS=$ac_path_separator +ac_dummy="$PATH" +for ac_dir in $ac_dummy; do + IFS=$ac_save_IFS + test -z "$ac_dir" && ac_dir=. + $as_executable_p "$ac_dir/$ac_word" || continue +if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue +fi +ac_cv_prog_CC="cc" +echo "$as_me:1096: found $ac_dir/$ac_word" >&5 +break +done + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + set dummy "$ac_dir/$ac_word" ${1+"$@"} + shift + ac_cv_prog_CC="$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + echo "$as_me:1118: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6 +else + echo "$as_me:1121: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +echo "$as_me:1132: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_save_IFS=$IFS; IFS=$ac_path_separator +ac_dummy="$PATH" +for ac_dir in $ac_dummy; do + IFS=$ac_save_IFS + test -z "$ac_dir" && ac_dir=. + $as_executable_p "$ac_dir/$ac_word" || continue +ac_cv_prog_CC="$ac_tool_prefix$ac_prog" +echo "$as_me:1147: found $ac_dir/$ac_word" >&5 +break +done + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + echo "$as_me:1155: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6 +else + echo "$as_me:1158: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +echo "$as_me:1171: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else + ac_save_IFS=$IFS; IFS=$ac_path_separator +ac_dummy="$PATH" +for ac_dir in $ac_dummy; do + IFS=$ac_save_IFS + test -z "$ac_dir" && ac_dir=. + $as_executable_p "$ac_dir/$ac_word" || continue +ac_cv_prog_ac_ct_CC="$ac_prog" +echo "$as_me:1186: found $ac_dir/$ac_word" >&5 +break +done + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + echo "$as_me:1194: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6 +else + echo "$as_me:1197: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + + test -n "$ac_ct_CC" && break +done + + CC=$ac_ct_CC +fi + +fi + +test -z "$CC" && { { echo "$as_me:1209: error: no acceptable cc found in \$PATH" >&5 +echo "$as_me: error: no acceptable cc found in \$PATH" >&2;} + { (exit 1); exit 1; }; } + +# Provide some information about the compiler. +echo "$as_me:1214:" \ + "checking for C compiler version" >&5 +ac_compiler=`set X $ac_compile; echo $2` +{ (eval echo "$as_me:1217: \"$ac_compiler --version </dev/null >&5\"") >&5 + (eval $ac_compiler --version </dev/null >&5) 2>&5 + ac_status=$? + echo "$as_me:1220: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (eval echo "$as_me:1222: \"$ac_compiler -v </dev/null >&5\"") >&5 + (eval $ac_compiler -v </dev/null >&5) 2>&5 + ac_status=$? + echo "$as_me:1225: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (eval echo "$as_me:1227: \"$ac_compiler -V </dev/null >&5\"") >&5 + (eval $ac_compiler -V </dev/null >&5) 2>&5 + ac_status=$? + echo "$as_me:1230: \$? = $ac_status" >&5 + (exit $ac_status); } + +cat >conftest.$ac_ext <<_ACEOF +#line 1234 "configure" +#include "confdefs.h" + +int +main () +{ + + ; + return 0; +} +_ACEOF +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files a.out a.exe" +# Try to create an executable without -o first, disregard a.out. +# It will help us diagnose broken compilers, and finding out an intuition +# of exeext. +echo "$as_me:1250: checking for C compiler default output" >&5 +echo $ECHO_N "checking for C compiler default output... $ECHO_C" >&6 +ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` +if { (eval echo "$as_me:1253: \"$ac_link_default\"") >&5 + (eval $ac_link_default) 2>&5 + ac_status=$? + echo "$as_me:1256: \$? = $ac_status" >&5 + (exit $ac_status); }; then + # Find the output, starting from the most likely. This scheme is +# not robust to junk in `.', hence go to wildcards (a.*) only as a last +# resort. +for ac_file in `ls a.exe conftest.exe 2>/dev/null; + ls a.out conftest 2>/dev/null; + ls a.* conftest.* 2>/dev/null`; do + case $ac_file in + *.$ac_ext | *.o | *.obj | *.xcoff | *.tds | *.d | *.pdb ) ;; + a.out ) # We found the default executable, but exeext='' is most + # certainly right. + break;; + *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + # FIXME: I believe we export ac_cv_exeext for Libtool --akim. + export ac_cv_exeext + break;; + * ) break;; + esac +done +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +{ { echo "$as_me:1279: error: C compiler cannot create executables" >&5 +echo "$as_me: error: C compiler cannot create executables" >&2;} + { (exit 77); exit 77; }; } +fi + +ac_exeext=$ac_cv_exeext +echo "$as_me:1285: result: $ac_file" >&5 +echo "${ECHO_T}$ac_file" >&6 + +# Check the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +echo "$as_me:1290: checking whether the C compiler works" >&5 +echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6 +# FIXME: These cross compiler hacks should be removed for Autoconf 3.0 +# If not cross compiling, check that we can run a simple program. +if test "$cross_compiling" != yes; then + if { ac_try='./$ac_file' + { (eval echo "$as_me:1296: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:1299: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + cross_compiling=no + else + if test "$cross_compiling" = maybe; then + cross_compiling=yes + else + { { echo "$as_me:1306: error: cannot run C compiled programs. +If you meant to cross compile, use \`--host'." >&5 +echo "$as_me: error: cannot run C compiled programs. +If you meant to cross compile, use \`--host'." >&2;} + { (exit 1); exit 1; }; } + fi + fi +fi +echo "$as_me:1314: result: yes" >&5 +echo "${ECHO_T}yes" >&6 + +rm -f a.out a.exe conftest$ac_cv_exeext +ac_clean_files=$ac_clean_files_save +# Check the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +echo "$as_me:1321: checking whether we are cross compiling" >&5 +echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6 +echo "$as_me:1323: result: $cross_compiling" >&5 +echo "${ECHO_T}$cross_compiling" >&6 + +echo "$as_me:1326: checking for executable suffix" >&5 +echo $ECHO_N "checking for executable suffix... $ECHO_C" >&6 +if { (eval echo "$as_me:1328: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:1331: \$? = $ac_status" >&5 + (exit $ac_status); }; then + # If both `conftest.exe' and `conftest' are `present' (well, observable) +# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will +# work properly (i.e., refer to `conftest.exe'), while it won't with +# `rm'. +for ac_file in `(ls conftest.exe; ls conftest; ls conftest.*) 2>/dev/null`; do + case $ac_file in + *.$ac_ext | *.o | *.obj | *.xcoff | *.tds | *.d | *.pdb ) ;; + *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + export ac_cv_exeext + break;; + * ) break;; + esac +done +else + { { echo "$as_me:1347: error: cannot compute EXEEXT: cannot compile and link" >&5 +echo "$as_me: error: cannot compute EXEEXT: cannot compile and link" >&2;} + { (exit 1); exit 1; }; } +fi + +rm -f conftest$ac_cv_exeext +echo "$as_me:1353: result: $ac_cv_exeext" >&5 +echo "${ECHO_T}$ac_cv_exeext" >&6 + +rm -f conftest.$ac_ext +EXEEXT=$ac_cv_exeext +ac_exeext=$EXEEXT +echo "$as_me:1359: checking for object suffix" >&5 +echo $ECHO_N "checking for object suffix... $ECHO_C" >&6 +if test "${ac_cv_objext+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line 1365 "configure" +#include "confdefs.h" + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.o conftest.obj +if { (eval echo "$as_me:1377: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:1380: \$? = $ac_status" >&5 + (exit $ac_status); }; then + for ac_file in `(ls conftest.o conftest.obj; ls conftest.*) 2>/dev/null`; do + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb ) ;; + *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` + break;; + esac +done +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +{ { echo "$as_me:1392: error: cannot compute OBJEXT: cannot compile" >&5 +echo "$as_me: error: cannot compute OBJEXT: cannot compile" >&2;} + { (exit 1); exit 1; }; } +fi + +rm -f conftest.$ac_cv_objext conftest.$ac_ext +fi +echo "$as_me:1399: result: $ac_cv_objext" >&5 +echo "${ECHO_T}$ac_cv_objext" >&6 +OBJEXT=$ac_cv_objext +ac_objext=$OBJEXT +echo "$as_me:1403: checking whether we are using the GNU C compiler" >&5 +echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6 +if test "${ac_cv_c_compiler_gnu+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line 1409 "configure" +#include "confdefs.h" + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:1424: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:1427: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:1430: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:1433: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_compiler_gnu=yes +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +ac_compiler_gnu=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +echo "$as_me:1445: result: $ac_cv_c_compiler_gnu" >&5 +echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6 +GCC=`test $ac_compiler_gnu = yes && echo yes` +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +CFLAGS="-g" +echo "$as_me:1451: checking whether $CC accepts -g" >&5 +echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6 +if test "${ac_cv_prog_cc_g+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line 1457 "configure" +#include "confdefs.h" + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:1469: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:1472: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:1475: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:1478: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_prog_cc_g=yes +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +ac_cv_prog_cc_g=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:1488: result: $ac_cv_prog_cc_g" >&5 +echo "${ECHO_T}$ac_cv_prog_cc_g" >&6 +if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +# Some people use a C++ compiler to compile C. Since we use `exit', +# in C++ we need to declare it. In case someone uses the same compiler +# for both compiling C and C++ we need to have the C++ compiler decide +# the declaration of exit, since it's the most demanding environment. +cat >conftest.$ac_ext <<_ACEOF +#ifndef __cplusplus + choke me +#endif +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:1515: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:1518: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:1521: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:1524: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + for ac_declaration in \ + ''\ + '#include <stdlib.h>' \ + 'extern "C" void std::exit (int) throw (); using std::exit;' \ + 'extern "C" void std::exit (int); using std::exit;' \ + 'extern "C" void exit (int) throw ();' \ + 'extern "C" void exit (int);' \ + 'void exit (int);' +do + cat >conftest.$ac_ext <<_ACEOF +#line 1536 "configure" +#include "confdefs.h" +#include <stdlib.h> +$ac_declaration +int +main () +{ +exit (42); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:1549: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:1552: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:1555: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:1558: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + : +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +continue +fi +rm -f conftest.$ac_objext conftest.$ac_ext + cat >conftest.$ac_ext <<_ACEOF +#line 1568 "configure" +#include "confdefs.h" +$ac_declaration +int +main () +{ +exit (42); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:1580: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:1583: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:1586: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:1589: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + break +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +fi +rm -f conftest.$ac_objext conftest.$ac_ext +done +rm -f conftest* +if test -n "$ac_declaration"; then + echo '#ifdef __cplusplus' >>confdefs.h + echo $ac_declaration >>confdefs.h + echo '#endif' >>confdefs.h +fi + +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +fi +rm -f conftest.$ac_objext conftest.$ac_ext +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. +set dummy ${ac_tool_prefix}ranlib; ac_word=$2 +echo "$as_me:1619: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_RANLIB+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$RANLIB"; then + ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. +else + ac_save_IFS=$IFS; IFS=$ac_path_separator +ac_dummy="$PATH" +for ac_dir in $ac_dummy; do + IFS=$ac_save_IFS + test -z "$ac_dir" && ac_dir=. + $as_executable_p "$ac_dir/$ac_word" || continue +ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" +echo "$as_me:1634: found $ac_dir/$ac_word" >&5 +break +done + +fi +fi +RANLIB=$ac_cv_prog_RANLIB +if test -n "$RANLIB"; then + echo "$as_me:1642: result: $RANLIB" >&5 +echo "${ECHO_T}$RANLIB" >&6 +else + echo "$as_me:1645: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + +fi +if test -z "$ac_cv_prog_RANLIB"; then + ac_ct_RANLIB=$RANLIB + # Extract the first word of "ranlib", so it can be a program name with args. +set dummy ranlib; ac_word=$2 +echo "$as_me:1654: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_RANLIB"; then + ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. +else + ac_save_IFS=$IFS; IFS=$ac_path_separator +ac_dummy="$PATH" +for ac_dir in $ac_dummy; do + IFS=$ac_save_IFS + test -z "$ac_dir" && ac_dir=. + $as_executable_p "$ac_dir/$ac_word" || continue +ac_cv_prog_ac_ct_RANLIB="ranlib" +echo "$as_me:1669: found $ac_dir/$ac_word" >&5 +break +done + + test -z "$ac_cv_prog_ac_ct_RANLIB" && ac_cv_prog_ac_ct_RANLIB=":" +fi +fi +ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB +if test -n "$ac_ct_RANLIB"; then + echo "$as_me:1678: result: $ac_ct_RANLIB" >&5 +echo "${ECHO_T}$ac_ct_RANLIB" >&6 +else + echo "$as_me:1681: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + + RANLIB=$ac_ct_RANLIB +else + RANLIB="$ac_cv_prog_RANLIB" +fi + +ac_aux_dir= +for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do + if test -f $ac_dir/install-sh; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install-sh -c" + break + elif test -f $ac_dir/install.sh; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install.sh -c" + break + elif test -f $ac_dir/shtool; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/shtool install -c" + break + fi +done +if test -z "$ac_aux_dir"; then + { { echo "$as_me:1707: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&5 +echo "$as_me: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&2;} + { (exit 1); exit 1; }; } +fi +ac_config_guess="$SHELL $ac_aux_dir/config.guess" +ac_config_sub="$SHELL $ac_aux_dir/config.sub" +ac_configure="$SHELL $ac_aux_dir/configure" # This should be Cygnus configure. + +# Find a good install program. We prefer a C program (faster), +# so one script is as good as another. But avoid the broken or +# incompatible versions: +# SysV /etc/install, /usr/sbin/install +# SunOS /usr/etc/install +# IRIX /sbin/install +# AIX /bin/install +# AmigaOS /C/install, which installs bootblocks on floppy discs +# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag +# AFS /usr/afsws/bin/install, which mishandles nonexistent args +# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" +# ./install, which can be erroneously created by make from ./install.sh. +echo "$as_me:1727: checking for a BSD compatible install" >&5 +echo $ECHO_N "checking for a BSD compatible install... $ECHO_C" >&6 +if test -z "$INSTALL"; then +if test "${ac_cv_path_install+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_save_IFS=$IFS; IFS=$ac_path_separator + for ac_dir in $PATH; do + IFS=$ac_save_IFS + # Account for people who put trailing slashes in PATH elements. + case $ac_dir/ in + / | ./ | .// | /cC/* \ + | /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* \ + | /usr/ucb/* ) ;; + *) + # OSF1 and SCO ODT 3.0 have their own names for install. + # Don't use installbsd from OSF since it installs stuff as root + # by default. + for ac_prog in ginstall scoinst install; do + if $as_executable_p "$ac_dir/$ac_prog"; then + if test $ac_prog = install && + grep dspmsg "$ac_dir/$ac_prog" >/dev/null 2>&1; then + # AIX install. It has an incompatible calling convention. + : + elif test $ac_prog = install && + grep pwplus "$ac_dir/$ac_prog" >/dev/null 2>&1; then + # program-specific install script used by HP pwplus--don't use. + : + else + ac_cv_path_install="$ac_dir/$ac_prog -c" + break 2 + fi + fi + done + ;; + esac + done + +fi + if test "${ac_cv_path_install+set}" = set; then + INSTALL=$ac_cv_path_install + else + # As a last resort, use the slow shell script. We don't cache a + # path for INSTALL within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the path is relative. + INSTALL=$ac_install_sh + fi +fi +echo "$as_me:1776: result: $INSTALL" >&5 +echo "${ECHO_T}$INSTALL" >&6 + +# Use test -z because SunOS4 sh mishandles braces in ${var-val}. +# It thinks the first close brace ends the variable substitution. +test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' + +test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' + +test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' + +# Extract the first word of "ar", so it can be a program name with args. +set dummy ar; ac_word=$2 +echo "$as_me:1789: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_path_AR+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + case $AR in + [\\/]* | ?:[\\/]*) + ac_cv_path_AR="$AR" # Let the user override the test with a path. + ;; + *) + ac_save_IFS=$IFS; IFS=$ac_path_separator +ac_dummy="$PATH" +for ac_dir in $ac_dummy; do + IFS=$ac_save_IFS + test -z "$ac_dir" && ac_dir=. + if $as_executable_p "$ac_dir/$ac_word"; then + ac_cv_path_AR="$ac_dir/$ac_word" + echo "$as_me:1806: found $ac_dir/$ac_word" >&5 + break +fi +done + + test -z "$ac_cv_path_AR" && ac_cv_path_AR="no" + ;; +esac +fi +AR=$ac_cv_path_AR + +if test -n "$AR"; then + echo "$as_me:1818: result: $AR" >&5 +echo "${ECHO_T}$AR" >&6 +else + echo "$as_me:1821: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + +if [ $AR = "no" ] ; then + { { echo "$as_me:1826: error: \"Could not find ar - needed to create a library\"" >&5 +echo "$as_me: error: \"Could not find ar - needed to create a library\"" >&2;} + { (exit 1); exit 1; }; }; +fi + +# Make sure we can run config.sub. +$ac_config_sub sun4 >/dev/null 2>&1 || + { { echo "$as_me:1833: error: cannot run $ac_config_sub" >&5 +echo "$as_me: error: cannot run $ac_config_sub" >&2;} + { (exit 1); exit 1; }; } + +echo "$as_me:1837: checking build system type" >&5 +echo $ECHO_N "checking build system type... $ECHO_C" >&6 +if test "${ac_cv_build+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_build_alias=$build_alias +test -z "$ac_cv_build_alias" && + ac_cv_build_alias=`$ac_config_guess` +test -z "$ac_cv_build_alias" && + { { echo "$as_me:1846: error: cannot guess build type; you must specify one" >&5 +echo "$as_me: error: cannot guess build type; you must specify one" >&2;} + { (exit 1); exit 1; }; } +ac_cv_build=`$ac_config_sub $ac_cv_build_alias` || + { { echo "$as_me:1850: error: $ac_config_sub $ac_cv_build_alias failed." >&5 +echo "$as_me: error: $ac_config_sub $ac_cv_build_alias failed." >&2;} + { (exit 1); exit 1; }; } + +fi +echo "$as_me:1855: result: $ac_cv_build" >&5 +echo "${ECHO_T}$ac_cv_build" >&6 +build=$ac_cv_build +build_cpu=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` +build_vendor=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` +build_os=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` + +echo "$as_me:1862: checking host system type" >&5 +echo $ECHO_N "checking host system type... $ECHO_C" >&6 +if test "${ac_cv_host+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_host_alias=$host_alias +test -z "$ac_cv_host_alias" && + ac_cv_host_alias=$ac_cv_build_alias +ac_cv_host=`$ac_config_sub $ac_cv_host_alias` || + { { echo "$as_me:1871: error: $ac_config_sub $ac_cv_host_alias failed" >&5 +echo "$as_me: error: $ac_config_sub $ac_cv_host_alias failed" >&2;} + { (exit 1); exit 1; }; } + +fi +echo "$as_me:1876: result: $ac_cv_host" >&5 +echo "${ECHO_T}$ac_cv_host" >&6 +host=$ac_cv_host +host_cpu=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` +host_vendor=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` +host_os=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` + +case "${host_os}" in + darwin* ) + + OTHER_OBJS="pa_mac_core/pa_mac_core.o"; + LIBS="-framework CoreAudio -lm"; + PADLL="libportaudio.dylib"; + SHARED_FLAGS="-framework CoreAudio -dynamiclib"; + ;; + + mingw* ) + + OTHER_OBJS="pa_win_wmme/pa_win_wmme.o"; + LIBS="-lwinmm -lm"; + PADLL="portaudio.dll"; + SHARED_FLAGS="-shared -mthreads"; + DLL_LIBS="-lwinmm"; + ;; + + cygwin* ) + + OTHER_OBJS="pa_win_wmme/pa_win_wmme.o"; + LIBS="-lwinmm -lm"; + PADLL="portaudio.dll"; + SHARED_FLAGS="-shared -mthreads"; + DLL_LIBS="-lwinmm"; + ;; + + *) + +echo "$as_me:1912: checking for pthread_create in -lpthread" >&5 +echo $ECHO_N "checking for pthread_create in -lpthread... $ECHO_C" >&6 +if test "${ac_cv_lib_pthread_pthread_create+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lpthread $LIBS" +cat >conftest.$ac_ext <<_ACEOF +#line 1920 "configure" +#include "confdefs.h" + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char pthread_create (); +int +main () +{ +pthread_create (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:1939: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:1942: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:1945: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:1948: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_pthread_pthread_create=yes +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +ac_cv_lib_pthread_pthread_create=no +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:1959: result: $ac_cv_lib_pthread_pthread_create" >&5 +echo "${ECHO_T}$ac_cv_lib_pthread_pthread_create" >&6 +if test $ac_cv_lib_pthread_pthread_create = yes; then + cat >>confdefs.h <<EOF +#define HAVE_LIBPTHREAD 1 +EOF + + LIBS="-lpthread $LIBS" + +else + { { echo "$as_me:1969: error: libpthread not found!" >&5 +echo "$as_me: error: libpthread not found!" >&2;} + { (exit 1); exit 1; }; } +fi + + OTHER_OBJS="pa_unix_oss/pa_unix_oss.o pa_unix_oss/pa_unix.o"; + LIBS="-lm -lpthread"; + PADLL="libportaudio.so"; + SHARED_FLAGS="-shared"; +esac + +ac_config_files="$ac_config_files Makefile" +cat >confcache <<\_ACEOF +# This file is a shell script that caches the results of configure +# tests run on this system so they can be shared between configure +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. +# +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. +# +# `ac_cv_env_foo' variables (set or unset) will be overriden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + +# The following way of writing the cache mishandles newlines in values, +# but we know of no workaround that is simple, portable, and efficient. +# So, don't put newlines in cache variables' values. +# Ultrix sh set writes to stderr and can't be redirected directly, +# and sets the high bit in the cache file unless we assign to the vars. +{ + (set) 2>&1 | + case `(ac_space=' '; set | grep ac_space) 2>&1` in + *ac_space=\ *) + # `set' does not quote correctly, so add quotes (double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \). + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n \ + "s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" + ;; + esac; +} | + sed ' + t clear + : clear + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + t end + /^ac_cv_env/!s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + : end' >>confcache +if cmp -s $cache_file confcache; then :; else + if test -w $cache_file; then + test "x$cache_file" != "x/dev/null" && echo "updating cache $cache_file" + cat confcache >$cache_file + else + echo "not updating unwritable cache $cache_file" + fi +fi +rm -f confcache + +test "x$prefix" = xNONE && prefix=$ac_default_prefix +# Let make expand exec_prefix. +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + +# VPATH may cause trouble with some makes, so we remove $(srcdir), +# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=/{ +s/:*\$(srcdir):*/:/; +s/:*\${srcdir}:*/:/; +s/:*@srcdir@:*/:/; +s/^\([^=]*=[ ]*\):*/\1/; +s/:*$//; +s/^[^=]*=[ ]*$//; +}' +fi + +# Transform confdefs.h into DEFS. +# Protect against shell expansion while executing Makefile rules. +# Protect against Makefile macro expansion. +# +# If the first sed substitution is executed (which looks for macros that +# take arguments), then we branch to the quote section. Otherwise, +# look for a macro that doesn't take arguments. +cat >confdef2opt.sed <<\EOF +t clear +: clear +s,^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[ ]*\(.*\),-D\1=\2,g +t quote +s,^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\),-D\1=\2,g +t quote +d +: quote +s,[ `~#$^&*(){}\\|;'"<>?],\\&,g +s,\[,\\&,g +s,\],\\&,g +s,\$,$$,g +p +EOF +# We use echo to avoid assuming a particular line-breaking character. +# The extra dot is to prevent the shell from consuming trailing +# line-breaks from the sub-command output. A line-break within +# single-quotes doesn't work because, if this script is created in a +# platform that uses two characters for line-breaks (e.g., DOS), tr +# would break. +ac_LF_and_DOT=`echo; echo .` +DEFS=`sed -n -f confdef2opt.sed confdefs.h | tr "$ac_LF_and_DOT" ' .'` +rm -f confdef2opt.sed + +: ${CONFIG_STATUS=./config.status} +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files $CONFIG_STATUS" +{ echo "$as_me:2090: creating $CONFIG_STATUS" >&5 +echo "$as_me: creating $CONFIG_STATUS" >&6;} +cat >$CONFIG_STATUS <<_ACEOF +#! $SHELL +# Generated automatically by configure. +# Run this file to recreate the current configuration. +# Compiler output produced by configure, useful for debugging +# configure, is in config.log if it exists. + +debug=false +SHELL=\${CONFIG_SHELL-$SHELL} +ac_cs_invocation="\$0 \$@" + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: +elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then + set -o posix +fi + +# Name of the executable. +as_me=`echo "$0" |sed 's,.*[\\/],,'` + +if expr a : '\(a\)' >/dev/null 2>&1; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + # We could just check for DJGPP; but this test a) works b) is more generic + # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). + if test -f conf$$.exe; then + # Don't use ln at all; we don't have any links + as_ln_s='cp -p' + else + as_ln_s='ln -s' + fi +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.file + +as_executable_p="test -f" + +# Support unset when possible. +if (FOO=FOO; unset FOO) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + +# NLS nuisances. +$as_unset LANG || test "${LANG+set}" != set || { LANG=C; export LANG; } +$as_unset LC_ALL || test "${LC_ALL+set}" != set || { LC_ALL=C; export LC_ALL; } +$as_unset LC_TIME || test "${LC_TIME+set}" != set || { LC_TIME=C; export LC_TIME; } +$as_unset LC_CTYPE || test "${LC_CTYPE+set}" != set || { LC_CTYPE=C; export LC_CTYPE; } +$as_unset LANGUAGE || test "${LANGUAGE+set}" != set || { LANGUAGE=C; export LANGUAGE; } +$as_unset LC_COLLATE || test "${LC_COLLATE+set}" != set || { LC_COLLATE=C; export LC_COLLATE; } +$as_unset LC_NUMERIC || test "${LC_NUMERIC+set}" != set || { LC_NUMERIC=C; export LC_NUMERIC; } +$as_unset LC_MESSAGES || test "${LC_MESSAGES+set}" != set || { LC_MESSAGES=C; export LC_MESSAGES; } + +# IFS +# We need space, tab and new line, in precisely that order. +as_nl=' +' +IFS=" $as_nl" + +# CDPATH. +$as_unset CDPATH || test "${CDPATH+set}" != set || { CDPATH=:; export CDPATH; } + +exec 6>&1 + +_ACEOF + +# Files that config.status was made for. +if test -n "$ac_config_files"; then + echo "config_files=\"$ac_config_files\"" >>$CONFIG_STATUS +fi + +if test -n "$ac_config_headers"; then + echo "config_headers=\"$ac_config_headers\"" >>$CONFIG_STATUS +fi + +if test -n "$ac_config_links"; then + echo "config_links=\"$ac_config_links\"" >>$CONFIG_STATUS +fi + +if test -n "$ac_config_commands"; then + echo "config_commands=\"$ac_config_commands\"" >>$CONFIG_STATUS +fi + +cat >>$CONFIG_STATUS <<\EOF + +ac_cs_usage="\ +\`$as_me' instantiates files from templates according to the +current configuration. + +Usage: $0 [OPTIONS] [FILE]... + + -h, --help print this help, then exit + -V, --version print version number, then exit + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + +Configuration files: +$config_files + +Report bugs to <bug-autoconf@gnu.org>." +EOF + +cat >>$CONFIG_STATUS <<EOF +ac_cs_version="\\ +config.status +configured by $0, generated by GNU Autoconf 2.52, + with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" + +Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 +Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." +srcdir=$srcdir +INSTALL="$INSTALL" +EOF + +cat >>$CONFIG_STATUS <<\EOF +# If no file are specified by the user, then we need to provide default +# value. By we need to know if files were specified by the user. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=*) + ac_option=`expr "x$1" : 'x\([^=]*\)='` + ac_optarg=`expr "x$1" : 'x[^=]*=\(.*\)'` + shift + set dummy "$ac_option" "$ac_optarg" ${1+"$@"} + shift + ;; + -*);; + *) # This is not an option, so the user has probably given explicit + # arguments. + ac_need_defaults=false;; + esac + + case $1 in + # Handling of the options. +EOF +cat >>$CONFIG_STATUS <<EOF + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + echo "running $SHELL $0 " $ac_configure_args " --no-create --no-recursion" + exec $SHELL $0 $ac_configure_args --no-create --no-recursion ;; +EOF +cat >>$CONFIG_STATUS <<\EOF + --version | --vers* | -V ) + echo "$ac_cs_version"; exit 0 ;; + --he | --h) + # Conflict between --help and --header + { { echo "$as_me:2258: error: ambiguous option: $1 +Try \`$0 --help' for more information." >&5 +echo "$as_me: error: ambiguous option: $1 +Try \`$0 --help' for more information." >&2;} + { (exit 1); exit 1; }; };; + --help | --hel | -h ) + echo "$ac_cs_usage"; exit 0 ;; + --debug | --d* | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + shift + CONFIG_FILES="$CONFIG_FILES $1" + ac_need_defaults=false;; + --header | --heade | --head | --hea ) + shift + CONFIG_HEADERS="$CONFIG_HEADERS $1" + ac_need_defaults=false;; + + # This is an error. + -*) { { echo "$as_me:2277: error: unrecognized option: $1 +Try \`$0 --help' for more information." >&5 +echo "$as_me: error: unrecognized option: $1 +Try \`$0 --help' for more information." >&2;} + { (exit 1); exit 1; }; } ;; + + *) ac_config_targets="$ac_config_targets $1" ;; + + esac + shift +done + +exec 5>>config.log +cat >&5 << _ACEOF + +## ----------------------- ## +## Running config.status. ## +## ----------------------- ## + +This file was extended by $as_me 2.52, executed with + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + > $ac_cs_invocation +on `(hostname || uname -n) 2>/dev/null | sed 1q` + +_ACEOF +EOF + +cat >>$CONFIG_STATUS <<\EOF +for ac_config_target in $ac_config_targets +do + case "$ac_config_target" in + # Handling of arguments. + "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;; + *) { { echo "$as_me:2313: error: invalid argument: $ac_config_target" >&5 +echo "$as_me: error: invalid argument: $ac_config_target" >&2;} + { (exit 1); exit 1; }; };; + esac +done + +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files +fi + +# Create a temporary directory, and hook for its removal unless debugging. +$debug || +{ + trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0 + trap '{ (exit 1); exit 1; }' 1 2 13 15 +} + +# Create a (secure) tmp directory for tmp files. +: ${TMPDIR=/tmp} +{ + tmp=`(umask 077 && mktemp -d -q "$TMPDIR/csXXXXXX") 2>/dev/null` && + test -n "$tmp" && test -d "$tmp" +} || +{ + tmp=$TMPDIR/cs$$-$RANDOM + (umask 077 && mkdir $tmp) +} || +{ + echo "$me: cannot create a temporary directory in $TMPDIR" >&2 + { (exit 1); exit 1; } +} + +EOF + +cat >>$CONFIG_STATUS <<EOF + +# +# CONFIG_FILES section. +# + +# No need to generate the scripts if there are no CONFIG_FILES. +# This happens for instance when ./config.status config.h +if test -n "\$CONFIG_FILES"; then + # Protect against being on the right side of a sed subst in config.status. + sed 's/,@/@@/; s/@,/@@/; s/,;t t\$/@;t t/; /@;t t\$/s/[\\\\&,]/\\\\&/g; + s/@@/,@/; s/@@/@,/; s/@;t t\$/,;t t/' >\$tmp/subs.sed <<\\CEOF +s,@SHELL@,$SHELL,;t t +s,@exec_prefix@,$exec_prefix,;t t +s,@prefix@,$prefix,;t t +s,@program_transform_name@,$program_transform_name,;t t +s,@bindir@,$bindir,;t t +s,@sbindir@,$sbindir,;t t +s,@libexecdir@,$libexecdir,;t t +s,@datadir@,$datadir,;t t +s,@sysconfdir@,$sysconfdir,;t t +s,@sharedstatedir@,$sharedstatedir,;t t +s,@localstatedir@,$localstatedir,;t t +s,@libdir@,$libdir,;t t +s,@includedir@,$includedir,;t t +s,@oldincludedir@,$oldincludedir,;t t +s,@infodir@,$infodir,;t t +s,@mandir@,$mandir,;t t +s,@PACKAGE_NAME@,$PACKAGE_NAME,;t t +s,@PACKAGE_TARNAME@,$PACKAGE_TARNAME,;t t +s,@PACKAGE_VERSION@,$PACKAGE_VERSION,;t t +s,@PACKAGE_STRING@,$PACKAGE_STRING,;t t +s,@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,;t t +s,@build_alias@,$build_alias,;t t +s,@host_alias@,$host_alias,;t t +s,@target_alias@,$target_alias,;t t +s,@ECHO_C@,$ECHO_C,;t t +s,@ECHO_N@,$ECHO_N,;t t +s,@ECHO_T@,$ECHO_T,;t t +s,@PATH_SEPARATOR@,$PATH_SEPARATOR,;t t +s,@DEFS@,$DEFS,;t t +s,@LIBS@,$LIBS,;t t +s,@CC@,$CC,;t t +s,@CFLAGS@,$CFLAGS,;t t +s,@LDFLAGS@,$LDFLAGS,;t t +s,@CPPFLAGS@,$CPPFLAGS,;t t +s,@ac_ct_CC@,$ac_ct_CC,;t t +s,@EXEEXT@,$EXEEXT,;t t +s,@OBJEXT@,$OBJEXT,;t t +s,@RANLIB@,$RANLIB,;t t +s,@ac_ct_RANLIB@,$ac_ct_RANLIB,;t t +s,@INSTALL_PROGRAM@,$INSTALL_PROGRAM,;t t +s,@INSTALL_SCRIPT@,$INSTALL_SCRIPT,;t t +s,@INSTALL_DATA@,$INSTALL_DATA,;t t +s,@AR@,$AR,;t t +s,@OTHER_OBJS@,$OTHER_OBJS,;t t +s,@PADLL@,$PADLL,;t t +s,@SHARED_FLAGS@,$SHARED_FLAGS,;t t +s,@DLL_LIBS@,$DLL_LIBS,;t t +s,@build@,$build,;t t +s,@build_cpu@,$build_cpu,;t t +s,@build_vendor@,$build_vendor,;t t +s,@build_os@,$build_os,;t t +s,@host@,$host,;t t +s,@host_cpu@,$host_cpu,;t t +s,@host_vendor@,$host_vendor,;t t +s,@host_os@,$host_os,;t t +CEOF + +EOF + + cat >>$CONFIG_STATUS <<\EOF + # Split the substitutions into bite-sized pieces for seds with + # small command number limits, like on Digital OSF/1 and HP-UX. + ac_max_sed_lines=48 + ac_sed_frag=1 # Number of current file. + ac_beg=1 # First line for current file. + ac_end=$ac_max_sed_lines # Line after last line for current file. + ac_more_lines=: + ac_sed_cmds= + while $ac_more_lines; do + if test $ac_beg -gt 1; then + sed "1,${ac_beg}d; ${ac_end}q" $tmp/subs.sed >$tmp/subs.frag + else + sed "${ac_end}q" $tmp/subs.sed >$tmp/subs.frag + fi + if test ! -s $tmp/subs.frag; then + ac_more_lines=false + else + # The purpose of the label and of the branching condition is to + # speed up the sed processing (if there are no `@' at all, there + # is no need to browse any of the substitutions). + # These are the two extra sed commands mentioned above. + (echo ':t + /@[a-zA-Z_][a-zA-Z_0-9]*@/!b' && cat $tmp/subs.frag) >$tmp/subs-$ac_sed_frag.sed + if test -z "$ac_sed_cmds"; then + ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed" + else + ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed" + fi + ac_sed_frag=`expr $ac_sed_frag + 1` + ac_beg=$ac_end + ac_end=`expr $ac_end + $ac_max_sed_lines` + fi + done + if test -z "$ac_sed_cmds"; then + ac_sed_cmds=cat + fi +fi # test -n "$CONFIG_FILES" + +EOF +cat >>$CONFIG_STATUS <<\EOF +for ac_file in : $CONFIG_FILES; do test "x$ac_file" = x: && continue + # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". + case $ac_file in + - | *:- | *:-:* ) # input from stdin + cat >$tmp/stdin + ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` + ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; + *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` + ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; + * ) ac_file_in=$ac_file.in ;; + esac + + # Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories. + ac_dir=`$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| \ + . : '\(.\)' 2>/dev/null || +echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } + /^X\(\/\/\)[^/].*/{ s//\1/; q; } + /^X\(\/\/\)$/{ s//\1/; q; } + /^X\(\/\).*/{ s//\1/; q; } + s/.*/./; q'` + if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then + { case "$ac_dir" in + [\\/]* | ?:[\\/]* ) as_incr_dir=;; + *) as_incr_dir=.;; +esac +as_dummy="$ac_dir" +for as_mkdir_dir in `IFS='/\\'; set X $as_dummy; shift; echo "$@"`; do + case $as_mkdir_dir in + # Skip DOS drivespec + ?:) as_incr_dir=$as_mkdir_dir ;; + *) + as_incr_dir=$as_incr_dir/$as_mkdir_dir + test -d "$as_incr_dir" || mkdir "$as_incr_dir" + ;; + esac +done; } + + ac_dir_suffix="/`echo $ac_dir|sed 's,^\./,,'`" + # A "../" for each directory in $ac_dir_suffix. + ac_dots=`echo "$ac_dir_suffix" | sed 's,/[^/]*,../,g'` + else + ac_dir_suffix= ac_dots= + fi + + case $srcdir in + .) ac_srcdir=. + if test -z "$ac_dots"; then + ac_top_srcdir=. + else + ac_top_srcdir=`echo $ac_dots | sed 's,/$,,'` + fi ;; + [\\/]* | ?:[\\/]* ) + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir ;; + *) # Relative path. + ac_srcdir=$ac_dots$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_dots$srcdir ;; + esac + + case $INSTALL in + [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; + *) ac_INSTALL=$ac_dots$INSTALL ;; + esac + + if test x"$ac_file" != x-; then + { echo "$as_me:2532: creating $ac_file" >&5 +echo "$as_me: creating $ac_file" >&6;} + rm -f "$ac_file" + fi + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated automatically by config.status. */ + configure_input="Generated automatically from `echo $ac_file_in | + sed 's,.*/,,'` by configure." + + # First look for the input files in the build tree, otherwise in the + # src tree. + ac_file_inputs=`IFS=: + for f in $ac_file_in; do + case $f in + -) echo $tmp/stdin ;; + [\\/$]*) + # Absolute (can't be DOS-style, as IFS=:) + test -f "$f" || { { echo "$as_me:2550: error: cannot find input file: $f" >&5 +echo "$as_me: error: cannot find input file: $f" >&2;} + { (exit 1); exit 1; }; } + echo $f;; + *) # Relative + if test -f "$f"; then + # Build tree + echo $f + elif test -f "$srcdir/$f"; then + # Source tree + echo $srcdir/$f + else + # /dev/null tree + { { echo "$as_me:2563: error: cannot find input file: $f" >&5 +echo "$as_me: error: cannot find input file: $f" >&2;} + { (exit 1); exit 1; }; } + fi;; + esac + done` || { (exit 1); exit 1; } +EOF +cat >>$CONFIG_STATUS <<EOF + sed "$ac_vpsub +$extrasub +EOF +cat >>$CONFIG_STATUS <<\EOF +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s,@configure_input@,$configure_input,;t t +s,@srcdir@,$ac_srcdir,;t t +s,@top_srcdir@,$ac_top_srcdir,;t t +s,@INSTALL@,$ac_INSTALL,;t t +" $ac_file_inputs | (eval "$ac_sed_cmds") >$tmp/out + rm -f $tmp/stdin + if test x"$ac_file" != x-; then + mv $tmp/out $ac_file + else + cat $tmp/out + rm -f $tmp/out + fi + +done +EOF + +cat >>$CONFIG_STATUS <<\EOF + +{ (exit 0); exit 0; } +EOF +chmod +x $CONFIG_STATUS +ac_clean_files=$ac_clean_files_save + +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + exec 5>/dev/null + $SHELL $CONFIG_STATUS || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || { (exit 1); exit 1; } +fi + +echo "" +echo "Finished configure." + +echo "" +echo "Type 'make' to build PortAudio and examples." diff --git a/pd/portaudio_v18/configure.in b/pd/portaudio_v18/configure.in new file mode 100644 index 00000000..d3a9946c --- /dev/null +++ b/pd/portaudio_v18/configure.in @@ -0,0 +1,81 @@ +dnl +dnl PortAudio configure.in script +dnl +dnl Dominic Mazzoni +dnl + +dnl Require autoconf >= 2.13 +AC_PREREQ(2.13) + +dnl Init autoconf and make sure configure is being called +dnl from the right directory +AC_INIT([pa_common/portaudio.h]) + +dnl Checks for programs +AC_PROG_CC +AC_PROG_RANLIB +AC_PROG_INSTALL +AC_PATH_PROG(AR, ar, no) +if [[ $AR = "no" ]] ; then + AC_MSG_ERROR("Could not find ar - needed to create a library"); +fi + +dnl Extra variables we want to substitute +AC_SUBST(OTHER_OBJS) +AC_SUBST(PADLL) +AC_SUBST(SHARED_FLAGS) +AC_SUBST(DLL_LIBS) + +dnl Determine the host operating system / platform +AC_CANONICAL_HOST + +case "${host_os}" in + darwin* ) + dnl Mac OS X configuration + + OTHER_OBJS="pa_mac_core/pa_mac_core.o"; + LIBS="-framework CoreAudio -lm"; + PADLL="libportaudio.dylib"; + SHARED_FLAGS="-framework CoreAudio -dynamiclib"; + ;; + + mingw* ) + dnl MingW configuration + + OTHER_OBJS="pa_win_wmme/pa_win_wmme.o"; + LIBS="-lwinmm -lm"; + PADLL="portaudio.dll"; + SHARED_FLAGS="-shared -mthreads"; + DLL_LIBS="-lwinmm"; + ;; + + cygwin* ) + dnl Cygwin configuration + + OTHER_OBJS="pa_win_wmme/pa_win_wmme.o"; + LIBS="-lwinmm -lm"; + PADLL="portaudio.dll"; + SHARED_FLAGS="-shared -mthreads"; + DLL_LIBS="-lwinmm"; + ;; + + *) + dnl Unix OSS configuration + + AC_CHECK_LIB(pthread, pthread_create, + , + AC_MSG_ERROR([libpthread not found!])) + + OTHER_OBJS="pa_unix_oss/pa_unix_oss.o pa_unix_oss/pa_unix.o"; + LIBS="-lm -lpthread"; + PADLL="libportaudio.so"; + SHARED_FLAGS="-shared"; +esac + +AC_OUTPUT([Makefile]) + +echo "" +echo "Finished configure." + +echo "" +echo "Type 'make' to build PortAudio and examples." diff --git a/pd/portaudio_v18/docs/index.html b/pd/portaudio_v18/docs/index.html new file mode 100644 index 00000000..bd94eaa7 --- /dev/null +++ b/pd/portaudio_v18/docs/index.html @@ -0,0 +1,78 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.79 [en] (Windows NT 5.0; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="PortAudio Docs, a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Docs</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Documentation</h1></center> +</td> +</tr> +</table></center> + +<p>Copyright 2000 Phil Burk and Ross Bencina +<br> +<hr WIDTH="100%"> +<h2> +V18</h2> + +<h3> +<a href="portaudio_h.txt">API Reference for V18</a></h3> + +<blockquote>The Application Programmer Interface is documented in "portaudio.h".</blockquote> + +<h3> +<a href="pa_tutorial.html">Tutorial</a></h3> + +<blockquote>Describes how to write audio programs using the PortAudio API.</blockquote> + +<h3> +<a href="pa_impl_guide.html">Implementation Guide</a></h3> + +<blockquote>Describes how to write an implementation of PortAudio for a +new computer platform.</blockquote> + +<h3> +<a href="portaudio_icmc2001.pdf">Paper Presented at ICMC2001</a> (PDF)</h3> + +<blockquote>Describes the PortAudio API and discusses implementation issues. +Written July 2001.</blockquote> + +<hr WIDTH="100%"> +<h2> +V19 - improved API</h2> + +<h3> +<a href="proposals/index.html">Proposed V19 Changes</a></h3> + +<blockquote>Describes API changes being considered by the developer community. +Feedback welcome.</blockquote> + +<h3> +<a href="v19-doxydocs/">API Reference for V19</a></h3> + +<blockquote>Reference documents for the Application Programmer Interface +for V19 generated by doxygen.</blockquote> + +<hr WIDTH="100%"> +<h2> +Miscellaneous</h2> + +<h3> +<a href="latency.html">Improving Latency</a></h3> + +<blockquote>How to tune your computer to achieve the lowest possible audio +delay.</blockquote> +<a href="http://www.portaudio.com/">Return to PortAudio Home Page</a> +</body> +</html> diff --git a/pd/portaudio_v18/docs/latency.html b/pd/portaudio_v18/docs/latency.html new file mode 100644 index 00000000..87f1d122 --- /dev/null +++ b/pd/portaudio_v18/docs/latency.html @@ -0,0 +1,192 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.79 [en] (Windows NT 5.0; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Internal docs. How a stream is started or stopped."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Implementation - Start/Stop</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +<a href="http://www.portaudio.com">PortAudio</a> Latency</h1></center> +</td> +</tr> +</table></center> + +<p>This page discusses the issues of audio latency for <a href="http://www.portaudio.com">PortAudio</a> +. It offers suggestions on how to lower latency to improve the responsiveness +of applications. +<blockquote><b><a href="#what">What is Latency?</a></b> +<br><b><a href="#portaudio">PortAudio and Latency</a></b> +<br><b><a href="#macintosh">Macintosh</a></b> +<br><b><a href="#unix">Unix</a></b> +<br><b><a href="#windows">WIndows</a></b></blockquote> +By Phil Burk, Copyright 2002 Phil Burk and Ross Bencina +<h2> +<a NAME="what"></a>What is Latency?</h2> +Latency is basically longest time that you have to wait before you obtain +a desired result. For digital audio output it is the time between making +a sound in software and finally hearing it. +<p>Consider the example of pressing a key on the ASCII keyboard to play +a note. There are several stages in this process which each contribute +their own latency. First the operating system must respond to the keypress. +Then the audio signal generated must work its way through the PortAudio +buffers. Then it must work its way through the audio card hardware. Then +it must go through the audio amplifier which is very quick and then travel +through the air. Sound travels at abous one foot per millisecond through +air so placing speakers across the room can add 5-20 msec of delay. +<p>The reverse process occurs when recording or responding to audio input. +If you are processing audio, for example if you implement a software guitar +fuzz box, then you have both the audio input and audio output latencies +added together. +<p>The audio buffers are used to prevent glitches in the audio stream. +The user software writes audio into the output buffers. That audio is read +by the low level audio driver or by DMA and sent to the DAC. If the computer +gets busy doing something like reading the disk or redrawing the screen, +then it may not have time to fill the audio buffer. The audio hardware +then runs out of audio data, which causes a glitch. By using a large enough +buffer we can ensure that there is always enough audio data for the audio +hardware to play. But if the buffer is too large then the latency is high +and the system feels sluggish. If you play notes on the keyboard then the +"instrument" will feel unresponsive. So you want the buffers to be as small +as possible without glitching. +<h2> +<a NAME="portaudio"></a>PortAudio and Latency</h2> +The only delay that PortAudio can control is the total length of its buffers. +The Pa_OpenStream() call takes two parameters: numBuffers and framesPerBuffer. +The latency is also affected by the sample rate which we will call framesPerSecond. +A frame is a set of samples that occur simultaneously. For a stereo stream, +a frame is two samples. +<p>The latency in milliseconds due to this buffering is: +<blockquote><tt>latency_msec = 1000 * numBuffers * framesPerBuffer / framesPerSecond</tt></blockquote> +This is not the total latency, as we have seen, but it is the part we can +control. +<p>If you call Pa_OpenStream() with numBuffers equal to zero, then PortAudio +will select a conservative number that will prevent audio glitches. If +you still get glitches, then you can pass a larger value for numBuffers +until the glitching stops. if you try to pass a numBuffers value that is +too small, then PortAudio will use its own idea of the minimum value. +<p>PortAudio decides on the minimum number of buffers in a conservative +way based on the frameRate, operating system and other variables. You can +query the value that PortAudio will use by calling: +<blockquote><tt>int Pa_GetMinNumBuffers( int framesPerBuffer, double sampleRate +);</tt></blockquote> +On some systems you can override the PortAudio minimum if you know your +system can handle a lower value. You do this by setting an environment +variable called PA_MIN_LATENCY_MSEC which is read by PortAudio when it +starts up. This is supported on the PortAudio implementations for Windows +MME, Windows DirectSound, and Unix OSS. +<h2> +<a NAME="macintosh"></a>Macintosh</h2> +The best thing you can do to improve latency on Mac OS 8 and 9 is to turn +off Virtual Memory. PortAudio V18 will detect that Virtual Memory is turned +off and use a very low latency. +<p>For Mac OS X the latency is very low because Apple Core Audio is so +well written. You can set the PA_MIN_LATENCY_MSEC variable using: +<blockquote><tt>setenv PA_MIN_LATENCY_MSEC 4</tt></blockquote> + +<h2> +<a NAME="unix"></a>Unix</h2> +PortAudio under Unix currently uses a backgroud thread that reads and writes +to OSS. This gives you decent but not great latency. But if you raise the +priority of the background thread to a very priority then you can get under +10 milliseconds latency. In order to raise your priority you must run the +PortAudio program as root! You must also set PA_MIN_LATENCY_MSEC using +the appropriate command for your shell. +<h2> +<a NAME="windows"></a>Windows</h2> +Latency under Windows is a complex issue because of all the alternative +operating system versions and device drivers. I have seen latency range +from 8 milliseconds to 400 milliseconds. The worst case is when using Windows +NT. Windows 98 is a little better, and Windows XP can be quite good if +properly tuned. +<p>The underlying audio API also makes a lot of difference. If the audio +device has its own DirectSound driver then DirectSound can often provide +better latency than WMME. But if a real DirectSound driver is not available +for your device then it is emulated using WMME and the latency can be very +high. That's where I saw the 400 millisecond latency. The ASIO implementation +is generally very good and will give the lowest latency if available. +<p>You can set the PA_MIN_LATENCY_MSEC variable to 50, for example, by +entering in MS-DOS: +<blockquote><tt>set PA_MIN_LATENCY_MSEC=50</tt></blockquote> +If you enter this in a DOS window then you must run the PortAudio program +from that same window for the variable to have an effect. You can add that +line to your C:\AUTOEXEC.BAT file and reboot if you want it to affect any +PortAudio based program. +<p>For Windows XP, you can set environment variables as follows: +<ol> +<li> +Select "Control Panel" from the "Start Menu".</li> + +<li> +Launch the "System" Control Panel</li> + +<li> +Click on the "Advanced" tab.</li> + +<li> +Click on the "Environment Variables" button.</li> + +<li> +Click "New" button under User Variables.</li> + +<li> +Enter PA_MIN_LATENCY_MSEC for the name and some optimistic number for the +value.</li> + +<li> +Click OK, OK, OK.</li> +</ol> + +<h3> +Improving Latency on Windows</h3> +There are several steps you can take to improve latency under windows. +<ol> +<li> +Avoid reading or writng to disk when doing audio.</li> + +<li> +Turn off all automated background tasks such as email clients, virus scanners, +backup programs, FTP servers, web servers, etc. when doing audio.</li> + +<li> +Disconnect from the network to prevent network traffic from interrupting +your CPU.</li> +</ol> +<b>Important: </b>Windows XP users can also tune the OS to favor background +tasks, such as audio, over foreground tasks, such as word processing. I +lowered my latency from 40 to 10 milliseconds using this simple technique. +<ol> +<li> +Select "Control Panel" from the "Start Menu".</li> + +<li> +Launch the "System" Control Panel</li> + +<li> +Click on the "Advanced" tab.</li> + +<li> +Click on the "Settings" button in the Performance area.</li> + +<li> +Click on the "Advanced" tab.</li> + +<li> +Select "Background services" in the Processor Scheduling area.</li> + +<li> +Click OK, OK.</li> +</ol> +Please let us know if you have others sugestions for lowering latency. +<br> +<br> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_drivermodel.c.txt b/pd/portaudio_v18/docs/pa_drivermodel.c.txt new file mode 100644 index 00000000..956f664c --- /dev/null +++ b/pd/portaudio_v18/docs/pa_drivermodel.c.txt @@ -0,0 +1,488 @@ +/* + This file contains the host-neutral code for implementing multiple driver model + support in PortAudio. + + It has not been compiled, but it is supplied only for example purposes at this stage. + + TODO: use of CHECK_DRIVER_MODEL is bogus in some instances since some + of those functions don't return a PaError + + +*/ + +#include "pa_drivermodel.h.txt" + + +#ifndef PA_MULTIDRIVER +/* single driver support, most functions will stay in the implementation files */ + +PaDriverModelID Pa_CountDriverModels() +{ + return 1; +} + +/* +Perhaps all drivers should define this with this signature +const PaDriverModelInfo* Pa_GetDriverModelInfo( PaDriverModelID driverModelID ) +{ +} +*/ + +PaDeviceID Pa_DriverModelDefaultInputDeviceID( PaDriverModelID driverModelID ) +{ + return Pa_GetDefaultInputDeviceID(); +} + + +PaDeviceID Pa_DriverModelDefaultOutputDeviceID( PaDriverModelID driverModelID ) +{ + return Pa_GetDefaultInputDeviceID(); +} + +/* +Perhaps all drivers should define with this signature +int Pa_DriverModelMinNumBuffers( PaDriverModelID driverModelID, int framesPerBuffer, double sampleRate ) +{ + +} +*/ + +int Pa_DriverModelCountDevices( PaDriverModelID driverModelID ) +{ + return Pa_CountDevices(); +} + +PaDeviceID Pa_DriverModelGetDeviceID(PaDriverModelID driverModelID, int perDriverModelIndex ) +{ + return perDriverModelIndex; +} + + +#else +/* multidriver support */ + + +typedef PaError (*PaInitializeFunPtr)( PaDriverModelImplementation** ); + +/* + the initializers array is a static table of function pointers + to all the available driverModels on the current platform. + + the order of pointers in the array is important. the first + pointer is always considered to be the "default" driver model. +*/ + +static PaInitializeFunPtr driverModelInitializers[] = { +#ifdef WINDOWS + PaWin32WMME_MultiDriverInitialize, + PaWin32DS_MultiDriverInitialize, + PaASIO_MultiDriverInitialize +#endif +#ifdef MAC + PaMacSM_MultiDriverInitialize, + PaMacCA_MultiDriverInitialize, + PaASIO_MultiDriverInitialize +#endif +/* other platforms here */ + (PaInitializeFunPtr*)0 /* NULL terminate the list */ +}; + + +/* + the driverModels array is a dynamically created table of + currently available driverModels. +*/ +static PaDriverModelImplementation* driverModels = 0; +static int numDriverModels = 0; + + +#define PA_CHECK_INITIALIZED\ + if( driverModels == 0 ) + return paLibraryNotInitialised + +#define PA_CHECK_DRIVER_MODEL_ID( id ) + if( id < 0 || id >= numDriverModels ) + return paBadDriverModelID; + + +/* + ConvertPublicDeviceIdToImplementationDeviceId converts deviceId + from a public device id, to a device id for a particular + PortAudio implementation. On return impl will either point + to a valid implementation or will be NULL. +*/ +static void ConvertPublicDeviceIDToImplementationDeviceID( + PaDriverModelImplementation *impl, PaDeviceID deviceID ) +{ + int i, count; + + impl = NULL; + + for( i=0; i < numDriverModels; ++i ){ + count = driverModels[i]->countDevices(); + if( deviceID < count ){ + impl = driverModels[i]; + return NULL; + }else{ + deviceID -= count; + } + } +} + +static PaDeviceID ConvertImplementationDeviceIDToPublicDeviceID( + PaDriverModelID driverModelID, PaDeviceID deviceID ) +{ + int i; + + for( i=0; i < driverModelID; ++i ) + deviceID += driverModels[i]->countDevices(); +} + + +PaError Pa_Initialize( void ) +{ + PaError result = paNoError; + int i, initializerCount; + PaDriverModelImplementation *impl; + + if( driverModels != 0 ) + return paAlreadyInitialized; + + /* count the number of driverModels */ + initializerCount=0; + while( driverModelInitializers[initializerCount] != 0 ){ + ++initializerCount; + } + + driverModels = malloc( sizeof(PaDriverModelImplementation*) * initializerCount ); + if( driverModels == NULL ) + return paInsufficientMemory; + + numDriverModels = 0; + for( i=0; i<initializerCount; ++i ){ + result = (*driverModelInitializers[i])( &impl ); + if( result == paNoError ){ + driverModels[numDriverModels] = impl; + ++numDriverModels; + }else{ + // TODO: terminate the drivers which have already been initialized. + } + } + + return result; +} + + + +PaError Pa_Terminate( void ) +{ + int i; + + PA_CHECK_INITIALIZED; + + /* + rather than require each implementation to do it separately we could + keep track of all open streams and close them here + */ + + for( i=0; i<numDriverModels; ++i ) + driverModels[i]->terminate( driverModels[i] ); +} + + +long Pa_GetHostError( void ) +{ + PA_CHECK_INITIALIZED; + + under construction. depends on error text proposal. +} + + +const char *Pa_GetErrorText( PaError errnum ) +{ + PA_CHECK_INITIALIZED; + + under construction. may need to call driver model specific code + depending on how the error text proposal pans out. +} + + + +int Pa_CountDevices() +{ + int i, result; + + PA_CHECK_INITIALIZED; + + result = 0; + for( i=0; i < numDriverModels; ++i ) + result += driverModels[i]->countDevices(); + + return result; +} + + +PaDeviceID Pa_GetDefaultInputDeviceID( void ) +{ + PA_CHECK_INITIALIZED; + + return driverModels[0]->getDefaultInputDeviceID(); +} + +PaDeviceID Pa_GetDefaultOutputDeviceID( void ) +{ + PA_CHECK_INITIALIZED; + + return driverModels[0]->getDefaultInputDeviceID(); +} + + +const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceID deviceID ) +{ + PaDriverModelImplementation *impl; + + PA_CHECK_INITIALIZED; + + ConvertPublicDeviceIDToImplementationDeviceID( impl, deviceID ); + if( impl == NULL ) + return paInvalidDeviceID; + + return impl->getDeviceInfo( deviceID ); +} + +/* NEW MULTIPLE DRIVER MODEL FUNCTIONS ---------------------------------- */ + +PaDriverModelID Pa_CountDriverModels() +{ + PA_CHECK_INITIALIZED; + + return numDriverModels; +} + + +const PaDriverModelInfo* Pa_GetDriverModelInfo( PaDriverModelID driverModelID ) +{ + PA_CHECK_INITIALIZED; + PA_CHECK_DRIVER_MODEL_ID( driverModelID ); + + return driverModels[ driverModelID ]->getDriverModelInfo(); +} + + +PaDeviceID Pa_DriverModelDefaultInputDeviceID( PaDriverModelID driverModelID ) +{ + PA_CHECK_INITIALIZED; + PA_CHECK_DRIVER_MODEL_ID( driverModelID ); + + return ConvertImplementationDeviceIDToPublicDeviceID( driverModelID, + driverModels[ driverModelID ]->getDefaultInputDeviceID(); +} + + +PaDeviceID Pa_DriverModelDefaultOutputDeviceID( PaDriverModelID driverModelID ) +{ + PA_CHECK_INITIALIZED; + PA_CHECK_DRIVER_MODEL_ID( driverModelID ); + + return ConvertImplementationDeviceIDToPublicDeviceID( driverModelID, + driverModels[ driverModelID ]->getDefaultOutputDeviceID(); +} + + +int Pa_DriverModelMinNumBuffers( PaDriverModelID driverModelID, int framesPerBuffer, double sampleRate ) +{ + PA_CHECK_INITIALIZED; + PA_CHECK_DRIVER_MODEL_ID( driverModelID ); + + return driverModels[ driverModelID ]->getMinNumBuffers( int framesPerBuffer, double sampleRate ); +} + + +int Pa_DriverModelCountDevices( PaDriverModelID driverModelID ) +{ + PA_CHECK_INITIALIZED; + PA_CHECK_DRIVER_MODEL_ID( driverModelID ); + + return driverModels[ driverModelID ]->coundDevices(); +} + +PaDeviceID Pa_DriverModelGetDeviceID(PaDriverModelID driverModelID, int perDriverModelIndex ) +{ + PA_CHECK_INITIALIZED; + PA_CHECK_DRIVER_MODEL_ID( driverModelID ); + + return ConvertImplementationDeviceIDToPublicDeviceID( driverModelID, perDriverModelIndex ); +} + +/* END NEW MULTIPLE DRIVER MODEL FUNCTIONS ------------------------------ */ + + +PaError Pa_OpenStream( PortAudioStream** stream, + PaDeviceID inputDevice, + int numInputChannels, + PaSampleFormat inputSampleFormat, + void *inputDriverInfo, + PaDeviceID outputDevice, + int numOutputChannels, + PaSampleFormat outputSampleFormat, + void *outputDriverInfo, + double sampleRate, + unsigned long framesPerBuffer, + unsigned long numberOfBuffers, + PaStreamFlags streamFlags, + PortAudioCallback *callback, + void *userData ) +{ + PaError result; + PaDriverModelImplementation *inputImpl, *outputImpl, impl; + + PA_CHECK_INITIALIZED; + + if( inputDevice != paNoDevice ){ + ConvertPublicDeviceIDToImplementationDeviceID( inputImpl, inputDevice ); + if( inputImpl == NULL ) + return paInvalidDeviceID; + else + impl = inputImpl; + } + + if( outputDevice != paNoDevice ){ + ConvertPublicDeviceIDToImplementationDeviceID( outputImpl, outputDevice ); + if( outputImpl == NULL ) + return paInvalidDeviceID; + else + impl = outputImpl; + } + + if( inputDevice != paNoDevice && outputDevice != paNoDevice ){ + if( inputImpl != outputImpl ) + return paDevicesMustBelongToTheSameDriverModel; + } + + + result = impl->openStream( stream, inputDevice, numInputChannels, inputSampleFormat, inputDriverInfo, + outputDevice, numOutputChannels, outputSampleFormat, outputDriverInfo, + sampleRate, framesPerBuffer, numberOfBuffers, streamFlags, callback, userData ); + + + if( result == paNoError ) + ((PaStreamImplementation*)stream)->magic = PA_STREAM_MAGIC; + + return result; +} + + +PaError Pa_OpenDefaultStream( PortAudioStream** stream, + int numInputChannels, + int numOutputChannels, + PaSampleFormat sampleFormat, + double sampleRate, + unsigned long framesPerBuffer, + unsigned long numberOfBuffers, + PortAudioCallback *callback, + void *userData ) +{ + PaError result; + int inputDevice = driverModels[0]->getDefaultInputDeviceID; + int outputDevice = driverModels[0]->getDefaultOutputDeviceID; + + result = driverModels[0]->openStream( stream, inputDevice, numInputChannels, sampleFormat, 0, + outputDevice, numOutputChannels, sampleFormat, 0, + sampleRate, framesPerBuffer, numberOfBuffers, + streamFlags, callback, userData ); + + if( result == paNoError ) + ((PaStreamImplementation*)stream)->magic = PA_STREAM_MAGIC; + + return result; +} + + +PaError Pa_CloseStream( PortAudioStream* stream ) +{ + PA_CHECK_INITIALIZED; + + PaError result = ((PaStreamImplementation*)stream)->close(); + + if( result == PaNoError ) + ((PaStreamImplementation*)stream)->magic = 0; /* clear magic number */ + + return result; +} + + +PaError Pa_StartStream( PortAudioStream *stream ); +{ + PA_CHECK_INITIALIZED; + + return ((PaStreamImplementation*)stream)->start(); +} + + +PaError Pa_StopStream( PortAudioStream *stream ); +{ + PA_CHECK_INITIALIZED; + + return ((PaStreamImplementation*)stream)->stop(); +} + + +PaError Pa_AbortStream( PortAudioStream *stream ); +{ + PA_CHECK_INITIALIZED; + + return ((PaStreamImplementation*)stream)->abort(); +} + + +PaError Pa_StreamActive( PortAudioStream *stream ) +{ + PA_CHECK_INITIALIZED; + + return ((PaStreamImplementation*)stream)->active(); +} + +PaTimestamp Pa_StreamTime( PortAudioStream *stream ) +{ + PA_CHECK_INITIALIZED; + + return ((PaStreamImplementation*)stream)->time(); +} + + +double Pa_StreamCPULoad( PortAudioStream* stream ) +{ + PA_CHECK_INITIALIZED; + + return ((PaStreamImplementation*)stream)->cpuLoad(); +} + + + +int Pa_GetMinNumBuffers( PaDeviceID deviceID, int framesPerBuffer, double sampleRate ) +{ + PaDriverModelImplementation *impl; + PA_CHECK_INITIALIZED; + + ConvertPublicDeviceIDToImplementationDeviceID( impl, deviceID ); + if( impl == NULL ) + return paInvalidDeviceID; + + return impl->getMinNumBuffers( framesPerBuffer, sampleRate ); +} + + +void Pa_Sleep( long msec ) +{ + same as existing implementaion +} + + +PaError Pa_GetSampleSize( PaSampleFormat format ) +{ + same as existing implementation +} + +#endif /* PA_MULTIDRIVER */ + + diff --git a/pd/portaudio_v18/docs/pa_drivermodel.h.txt b/pd/portaudio_v18/docs/pa_drivermodel.h.txt new file mode 100644 index 00000000..f3f2ca2a --- /dev/null +++ b/pd/portaudio_v18/docs/pa_drivermodel.h.txt @@ -0,0 +1,143 @@ +#ifndef PA_MULTIDRIVERMODEL_H +#define PA_MULTIDRIVERMODEL_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/* + This file contains the host-neutral code for implementing multiple driver model + support in PortAudio. + + It has not been compiled, but it is supplied only for example purposes at this stage. +*/ + + +#include "portaudio.h" + + +#define PA_MULTIDRIVER // for multidriver support + + + +TODO: declare function pointer types for the following function pointers + +/* + Each driver model implementation needs to implement an initialize function + which is added to the driverModelInitializers array in pa_multidrivermodel.c + + the initializer function needs to return a pointer to a + PaDriverModelImplementation structure, or NULL if initiliazation failed. TODO: need error code instead + + the function pointer members of this structure point to funtions + which operate in exactly the same way as the corresponding functions + in the PortAudio API. +*/ + +struct{ + fptr terminate; /* takes the PaDriverModelImplementation* returned by initialize */ + fptr getDriverModelInfo; + fptr getHostError; + fptr getHostErrorText; + fptr countDevices; + fptr getDefaultInputDeviceID; + fptr getDefaultOutputDeviceID; + fptr getDeviceInfo; + fptr openStream; + fptr getMinNumBuffers; +} PaDriverModelImplementation; + +/* + whenever an implementaion's openstream method is called it should return a + PortAudioStream* whose first segment is actually the following structure. + + the functions pointer members of this structure point to funcitons + which operate in exactly the same way as the corresponding functions + in the PortAudio API. +*/ +struct{ + unsigned long magic; + fptr close; + fptr start; + fptr stop; + fptr abort; + fptr active; + fptr time; + fptr cpuLoad; +} PaStreamImplementation; + +/* + Implementations should set magic to PA_STREAM_MAGIC when opening + a stream _and_ clear it to zero when closing a stream. + All functions which operate on streams should check the validity + of magic. +*/ + +#define PA_STREAM_MAGIC 0x12345678 + +#define PA_CHECK_STREAM( stream )\ + if( ((PaStreamImplementation*)stream)->magic != PA_STREAM_MAGIC )\ + return paBadStreamPtr; + + +/* + PA_API allows the same implementation to be used for single + driver model and multi-driver model operation. If + PA_MULTIDRIVER not defined, PA_API will declare api + functions as global, otherwise they will be static, and include + the drivermodel code. + + Usage would be something like: + + int PA_API(CountDevices)(); + + The PA_MULTIDRIVER_SUPPORT macro declares the initialization and + termination functions required by the multidriver support. it also + allocates and deallocates the PaDriverModelImplementation structure. + + TODO: add macros for initializing PaStreamImplementation PortAudioStream + these would be PA_INITIALIZE_STREAM and PA_TERMINATE_STREAM + they would assign and clear the magic number and assign the + interface functions if neceassary. +*/ + +#ifdef PA_MULTIDRIVER + +#define PA_API( model, name ) static Pa ## model ## _ ## name + +#define PA_MULTIDRIVER_SUPPORT( model )\ +PaError Pa_ ## model ## _MultiDriverTerminate( PaStreamImplementation *impl )\ +{\ + free( impl );\ + return Pa ## model ## _Terminate();\ +}\ +PaError Pa ## model ## _MultiDriverInitialize( PaStreamImplementation** impl )\ +{\ + PaError result = Pa ## model ## _Initialize();\ +\ + if( result == paNoError ){\ + *impl = malloc( sizeof( PaDriverModelImplementation ) );\ + if( impl == NULL ){\ + // TODO: call terminate, return an error + }else{\ + (*impl)->terminate = Pa ## model ## _MultiDriverTerminate();\ + (*impl)->getDriverModelInfo = Pa ## model ## _GetDriverModelInfo();\ + (*impl)->getHostError = Pa ## model ## _GetHostError();\ + // TODO: assign the rest of the interface functions + }\ + }\ + return result;\ +} + +#else /* !PA_MULTIDRIVER */ + +#define PA_API( model, name ) Pa_ ## name + +#define PA_MULTIDRIVER_SUPPORT + +#endif /* PA_MULTIDRIVER */ + + + +#endif /* PA_MULTIDRIVERMODEL_H */ diff --git a/pd/portaudio_v18/docs/pa_impl_guide.html b/pd/portaudio_v18/docs/pa_impl_guide.html new file mode 100644 index 00000000..50abc304 --- /dev/null +++ b/pd/portaudio_v18/docs/pa_impl_guide.html @@ -0,0 +1,197 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.79 [en] (Windows NT 5.0; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Internal docs. How a stream is started or stopped."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Implementation - Start/Stop</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +<a href="http://www.portaudio.com">PortAudio</a> Implementation Guide</h1></center> +</td> +</tr> +</table></center> + +<p>This document describes how to implement the PortAudio API on a new +computer platform. Implementing PortAudio on a new platform, makes it possible +to port many existing audio applications to that platform. +<p>By Phil Burk +<br>Copyright 2000 Phil Burk and Ross Bencina +<p>Note that the license says: <b>"Any person wishing to distribute modifications +to the Software is requested to send the modifications to the original +developer so that they can be incorporated into the canonical version."</b>. +So when you have finished a new implementation, please send it back to +us at "<a href="http://www.portaudio.com">http://www.portaudio.com</a>" +so that we can make it available for other users. Thank you! +<h2> +Download the Latest PortAudio Implementation</h2> +Always start with the latest implementation available at "<a href="http://www.portaudio.com">http://www.portaudio.com</a>". +Look for the nightly snapshot under the CVS section. +<h2> +Select an Existing Implementation as a Basis</h2> +The fastest way to get started is to take an existing implementation and +translate it for your new platform. Choose an implementation whose architecture +is as close as possible to your target. +<ul> +<li> +DirectSound Implementation - pa_win_ds - Uses a timer callback for the +background "thread". Polls a circular buffer and writes blocks of data +to keep it full.</li> + +<li> +Windows MME - pa_win_wmme - Spawns an actual Win32 thread. Writes blocks +of data to the HW device and waits for events that signal buffer completion.</li> + +<li> +Linux OSS - pa_linux - Spawns a real thread that writes to the "/dev/dsp" +stream using blocking I/O calls.</li> +</ul> +When you write a new implementation, you will be using some code that is +in common with all implementations. This code is in the folder "pa_common". +It provides various functions such as parameter checking, error code to +text conversion, sample format conversion, clipping and dithering, etc. +<p>The code that you write will go into a separate folder called "pa_{os}_{api}". +For example, code specific to the DirectSound interface for Windows goes +in "pa_win_ds". +<h2> +Read Docs and Code</h2> +Famialiarize yourself with the system by reading the documentation provided. +here is a suggested order: +<ol> +<li> +User Programming <a href="pa_tutorial.html">Tutorial</a></li> + +<li> +Header file "pa_common/portaudio.h" which defines API.</li> + +<li> +Header file "pa_common/pa_host.h" for host dependant code. This definces +the routine you will need to provide.</li> + +<li> +Shared code in "pa_common/pa_lib.c".</li> + +<li> +Docs on Implementation of <a href="pa_impl_startstop.html">Start/Stop</a> +code.</li> +</ol> + +<h2> +Implement Output to Default Device</h2> +Now we are ready to crank some code. For instant gratification, let's try +to play a sine wave. +<ol> +<li> +Link the test program "pa_tests/patest_sine.c" with the file "pa_lib.c" +and the implementation specific file you are creating.</li> + +<li> +For now, just stub out the device query code and the audio input code.</li> + +<li> +Modify PaHost_OpenStream() to open your default target device and get everything +setup.</li> + +<li> +Modify PaHost_StartOutput() to start playing audio.</li> + +<li> +Modify PaHost_StopOutput() to stop audio.</li> + +<li> +Modify PaHost_CloseStream() to clean up. Free all memory that you allocated +in PaHost_OpenStream().</li> + +<li> +Keep cranking until you can play a sine wave using "patest_sine.c".</li> + +<li> +Once that works, try "patest_pink.c", "patest_clip.c", "patest_sine8.c".</li> + +<li> +To test your Open and Close code, try "patest_many.c".</li> + +<li> +Now test to make sure that the three modes of stopping are properly supported +by running "patest_stop.c".</li> + +<li> +Test your implementation of time stamping with "patest_sync.c".</li> +</ol> + +<h2> +Implement Device Queries</h2> +Now that output is working, lets implement the code for querying what devices +are available to the user. Run "pa_tests/pa_devs.c". It should print all +of the devices available and their characteristics. +<h2> +Implement Input</h2> +Implement audio input and test it with: +<ol> +<li> +patest_record.c - record in half duplex, play back as recorded.</li> + +<li> +patest_wire.c - full duplex, copies input to output. Note that some HW +may not support full duplex.</li> + +<li> +patest_fuzz.c - plug in your guitar and get a feel for why latency is an +important issue in computer music.</li> + +<li> +paqa_devs.c - try to open every device and use it with every possible format</li> +</ol> + +<h2> +Debugging Tools</h2> +You generally cannot use printf() calls to debug real-time processes because +they disturb the timing. Also calling printf() from your background thread +or interrupt could crash the machine. So PA includes a tool for capturing +events and storing the information while it is running. It then prints +the events when Pa_Terminate() is called. +<ol> +<li> +To enable trace mode, change TRACE_REALTIME_EVENTS in "pa_common/pa_trace.h" +from a (0) to a (1).</li> + +<li> +Link with "pa_common/pa_trace.c".</li> + +<li> +Add trace messages to your code by calling:</li> + +<br><tt> void AddTraceMessage( char *msg, int data );</tt> +<br><tt>for example</tt> +<br><tt> AddTraceMessage("Pa_TimeSlice: past_NumCallbacks ", +past->past_NumCallbacks );</tt> +<li> +Run your program. You will get a dump of events at the end.</li> + +<li> +You can leave the trace messages in your code. They will turn to NOOPs +when you change TRACE_REALTIME_EVENTS back to (0).</li> +</ol> + +<h2> +Delivery</h2> +Please send your new code along with notes on the implementation back to +us at "<a href="http://www.portaudio.com">http://www.portaudio.com</a>". +We will review the implementation and post it with your name. If you had +to make any modifications to the code in "pa_common" or "pa_tests" <b>please</b> +send us those modifications and your notes. We will try to merge your changes +so that the "pa_common" code works with <b>all</b> implementations. +<p>If you have suggestions for how to make future implementations easier, +please let us know. +<br>THANKS! +<br> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_impl_startstop.html b/pd/portaudio_v18/docs/pa_impl_startstop.html new file mode 100644 index 00000000..0f2d0ce5 --- /dev/null +++ b/pd/portaudio_v18/docs/pa_impl_startstop.html @@ -0,0 +1,190 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.75 [en]C-gatewaynet (Win98; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Internal docs. How a stream is started or stopped."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Implementation - Start/Stop</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Implementation</h1></center> +</td> +</tr> +</table></center> + +<h2> +Starting and Stopping Streams</h2> +PortAudio is generally executed in two "threads". The foreground thread +is the application thread. The background "thread" may be implemented as +an actual thread, an interrupt handler, or a callback from a timer thread. +<p>There are three ways that PortAudio can stop a stream. In each case +we look at the sequence of events and the messages sent between the two +threads. The following variables are contained in the internalPortAudioStream. +<blockquote><tt>int past_IsActive; +/* Background is still playing. */</tt> +<br><tt>int past_StopSoon; /* Stop +when last buffer done. */</tt> +<br><tt>int past_StopNow; /* +Stop IMMEDIATELY. */</tt></blockquote> + +<h3> +Pa_AbortStream()</h3> +This function causes the background thread to terminate as soon as possible +and audio I/O to stop abruptly. +<br> +<table BORDER COLS=2 WIDTH="60%" > +<tr> +<td><b>Foreground Thread</b></td> + +<td><b>Background Thread</b></td> +</tr> + +<tr> +<td>sets <tt>StopNow</tt></td> + +<td></td> +</tr> + +<tr> +<td></td> + +<td>sees <tt>StopNow</tt>, </td> +</tr> + +<tr> +<td></td> + +<td>clears IsActive, stops thread</td> +</tr> + +<tr> +<td>waits for thread to exit</td> + +<td></td> +</tr> + +<tr> +<td>turns off audio I/O</td> + +<td></td> +</tr> +</table> + +<h3> +Pa_StopStream()</h3> +This function stops the user callback function from being called and then +waits for all audio data written to the output buffer to be played. In +a system with very low latency, you may not hear any difference between +<br> +<table BORDER COLS=2 WIDTH="60%" > +<tr> +<td><b>Foreground Thread</b></td> + +<td><b>Background Thread</b></td> +</tr> + +<tr> +<td>sets StopSoon</td> + +<td></td> +</tr> + +<tr> +<td></td> + +<td>stops calling user callback</td> +</tr> + +<tr> +<td></td> + +<td>continues until output buffer empty</td> +</tr> + +<tr> +<td></td> + +<td>clears IsActive, stops thread</td> +</tr> + +<tr> +<td>waits for thread to exit</td> + +<td></td> +</tr> + +<tr> +<td>turns off audio I/O</td> + +<td></td> +</tr> +</table> + +<h3> +User callback returns one.</h3> +If the user callback returns one then the user callback function will no +longer be called. Audio output will continue until all audio data written +to the output buffer has been played. Then the audio I/O is stopped, the +background thread terminates, and the stream becomes inactive. +<br> +<table BORDER COLS=2 WIDTH="60%" > +<tr> +<td><b>Foreground Thread</b></td> + +<td><b>Background Thread</b></td> +</tr> + +<tr> +<td></td> + +<td>callback returns 1</td> +</tr> + +<tr> +<td></td> + +<td>sets StopSoon</td> +</tr> + +<tr> +<td></td> + +<td>stops calling user callback</td> +</tr> + +<tr> +<td></td> + +<td>continues until output buffer empty</td> +</tr> + +<tr> +<td></td> + +<td>clears IsActive, stops thread</td> +</tr> + +<tr> +<td>waits for thread to exit</td> + +<td></td> +</tr> + +<tr> +<td>turns off audio I/O</td> + +<td></td> +</tr> +</table> + +<br> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_tut_asio.html b/pd/portaudio_v18/docs/pa_tut_asio.html new file mode 100644 index 00000000..a7fa7d3a --- /dev/null +++ b/pd/portaudio_v18/docs/pa_tut_asio.html @@ -0,0 +1,108 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.79 [en] (Windows NT 5.0; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Tutorial for PortAudio, a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Tutorial</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Tutorial</h1></center> +</td> +</tr> +</table></center> + +<h2> +<font size=+2><a href="http://www.portaudio.com/">home</a> | +<a href="pa_tutorial.html">contents</a> +| <a href="pa_tut_over.html">previous</a> | <a href="pa_tut_callback.html">next</a></font></h2> + +<h2> +Compiling for ASIO (Windows or Macintosh)</h2> + +<blockquote>ASIO is a low latency audio API from Steinberg. To compile +an ASIO application, you must first <a href="http://www.steinberg.net/en/ps/support/3rdparty/">download +the ASIO SDK</a> from Steinberg. You also need to obtain ASIO drivers from +the manufacturer of your audio hardware. +<p>Note: I am using '/' as a file separator below. On Macintosh replace +'/' with ':'. On Windows, replace '/' with '\'. +<p>You may try compiling the "pa_tests/patest_saw.c" file first because +it is the simplest. +<p>Several files are common to all PortAudio implementations. Add the following +source files to your project: +<blockquote>pa_common/pa_lib.c +<br>pa_common/portaudio.h +<br>pa_common/pa_host.h</blockquote> +To use ASIO with the PortAudio library add the following: +<blockquote> +<pre>pa_asio/pa_asio.cpp</pre> +</blockquote> +</blockquote> + +<h3> +Macintosh Specific</h3> + +<blockquote>Note: there is a bug in the <b>Macintosh</b> ASIO code. Mac +users should read the file "pa_asio:readme_asio_sdk_patch.txt" for information +on how to fix the bug. +<p>Add these files from the ASIO SDK downloaded from Steinberg:</blockquote> + +<blockquote> +<blockquote><tt>host/asiodrivers.cpp</tt> +<br><tt>host/mac/asioshlib.cpp</tt> +<br><tt>host/mac/codefragements.cpp</tt></blockquote> +The ASIO drivers should be in a folder called "ASIO Drivers" beneath your +application.</blockquote> + +<h3> +Windows Specific</h3> + +<blockquote>Add these files from the ASIO SDK downloaded from Steinberg:</blockquote> + +<blockquote> +<blockquote><tt>host/asiodrivers.cpp</tt> +<br><tt>host/asiolist.cpp</tt> +<br><tt>common/asio.cpp</tt></blockquote> +</blockquote> + +<blockquote>Add these directories to the path for include files:</blockquote> + +<blockquote> +<blockquote><tt>host</tt> +<br><tt>host/pc</tt> +<br><tt>common</tt></blockquote> +</blockquote> + +<blockquote>and link with the system library "<b>winmm.lib</b>". For MS +Visual C++: +<ul> +<li> +select "Settings..." from the "Project" menu,</li> + +<li> +select the project name in the tree on the left,</li> + +<li> +choose "All Configurations" in the popup menu above the tree,</li> + +<li> +select the "Link" tab,</li> + +<li> +enter "winmm.lib", without quotes, as the first item in the "Object/library +modules:" field.</li> +</ul> +</blockquote> +<font size=+2><a href="http://www.portaudio.com/">home</a> | +<a href="pa_tutorial.html">contents</a> +| <a href="pa_tut_over.html">previous</a> | <a href="pa_tut_callback.html">next</a></font> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_tut_callback.html b/pd/portaudio_v18/docs/pa_tut_callback.html new file mode 100644 index 00000000..f5ccaf0f --- /dev/null +++ b/pd/portaudio_v18/docs/pa_tut_callback.html @@ -0,0 +1,91 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.77 [en]C-gatewaynet (Win98; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Tutorial for PortAudio, a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Tutorial</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Tutorial</h1></center> +</td> +</tr> +</table></center> + +<h2> +Writing a Callback Function</h2> + +<blockquote>To write a program using PortAudio, you must include the "portaudio.h" +include file. You may wish to read "<a href="portaudio_h.txt">portaudio.h</a>" +because it contains a complete description of the PortAudio functions and +constants. +<blockquote> +<pre>#include "portaudio.h"</pre> +</blockquote> +The next task is to write your custom callback function. It is a function +that is called by the PortAudio engine whenever it has captured audio data, +or when it needs more audio data for output. +<p>Your callback function is often called by an interrupt, or low level +process so you should not do any complex system activities like allocating +memory, or reading or writing files, or printf(). Just crunch numbers and +generate audio signals. What is safe or not safe will vary from platform +to platform. On the Macintosh, for example, you can only call "interrupt +safe" routines. Also do not call any PortAudio functions in the callback +except for Pa_StreamTime() and Pa_GetCPULoad(). +<p>Your callback function must return an int and accept the exact parameters +specified in this typedef: +<blockquote> +<pre>typedef int (PortAudioCallback)( + void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData );</pre> +</blockquote> +Here is an example callback function from the test file "patests/patest_saw.c". +It calculates a simple left and right sawtooth signal and writes it to +the output buffer. Notice that in this example, the signals are of <tt>float</tt> +data type. The signals must be between -1.0 and +1.0. You can also use +16 bit integers or other formats which are specified during setup. You +can pass a pointer to your data structure through PortAudio which will +appear as <tt>userData</tt>. +<blockquote> +<pre>int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + unsigned int i; +/* Cast data passed through stream to our structure type. */ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + + for( i=0; i<framesPerBuffer; i++ ) + { + /* Stereo channels are interleaved. */ + *out++ = data->left_phase; /* left */ + *out++ = data->right_phase; /* right */ + + /* Generate simple sawtooth phaser that ranges between -1.0 and 1.0. */ + data->left_phase += 0.01f; + /* When signal reaches top, drop back down. */ + if( data->left_phase >= 1.0f ) data->left_phase -= 2.0f; + + /* higher pitch so we can distinguish left and right. */ + data->right_phase += 0.03f; + if( data->right_phase >= 1.0f ) data->right_phase -= 2.0f; + } + return 0; +}</pre> +</blockquote> +</blockquote> +<font size=+2><a href="http://www.portaudio.com/">home</a> | +<a href="pa_tutorial.html">contents</a> +| <a href="pa_tut_over.html">previous</a> | <a href="pa_tut_init.html">next</a></font> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_tut_devs.html b/pd/portaudio_v18/docs/pa_tut_devs.html new file mode 100644 index 00000000..1756992c --- /dev/null +++ b/pd/portaudio_v18/docs/pa_tut_devs.html @@ -0,0 +1,65 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.75 [en]C-gatewaynet (Win98; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Tutorial for PortAudio, a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Tutorial</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Tutorial</h1></center> +</td> +</tr> +</table></center> + +<h2> +Querying for Available Devices</h2> + +<blockquote>There are often several different audio devices available in +a computer with different capabilities. They can differ in the sample rates +supported, bit widths, etc. PortAudio provides a simple way to query for +the available devices, and then pass the selected device to Pa_OpenStream(). +For an example, see the file "pa_tests/pa_devs.c". +<p>To determine the number of devices: +<blockquote> +<pre>numDevices = Pa_CountDevices();</pre> +</blockquote> +You can then query each device in turn by calling Pa_GetDeviceInfo() with +an index. +<blockquote> +<pre>for( i=0; i<numDevices; i++ ) { + pdi = Pa_GetDeviceInfo( i );</pre> +</blockquote> +It will return a pointer to a <tt>PaDeviceInfo</tt> structure which is +defined as: +<blockquote> +<pre>typedef struct{ + int structVersion; + const char *name; + int maxInputChannels; + int maxOutputChannels; +/* Number of discrete rates, or -1 if range supported. */ + int numSampleRates; +/* Array of supported sample rates, or {min,max} if range supported. */ + const double *sampleRates; + PaSampleFormat nativeSampleFormat; +}PaDeviceInfo;</pre> +</blockquote> +If the device supports a continuous range of sample rates, then numSampleRates +will equal -1, and the sampleRates array will have two values, the minimum +and maximum rate. +<p>The device information is allocated by Pa_Initialize() and freed by +Pa_Terminate() so you do not have to free() the structure returned by Pa_GetDeviceInfo().</blockquote> +<font size=+2><a href="http://www.portaudio.com/">home</a> | +<a href="pa_tutorial.html">contents</a> +| <a href="pa_tut_util.html">previous</a> | <a href="pa_tut_rw.html">next</a></font> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_tut_explore.html b/pd/portaudio_v18/docs/pa_tut_explore.html new file mode 100644 index 00000000..91c08a5b --- /dev/null +++ b/pd/portaudio_v18/docs/pa_tut_explore.html @@ -0,0 +1,42 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.73 [en]C-gatewaynet (Win98; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Tutorial for PortAudio, a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Tutorial</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Tutorial</h1></center> +</td> +</tr> +</table></center> + +<h2> +Exploring PortAudio</h2> + +<blockquote>Now that you have a good idea of how PortAudio works, you can +try out the test programs. +<ul> +<li> +For an example of playing a sine wave, see "pa_tests/patest_sine.c".</li> + +<li> +For an example of recording and playing back a sound, see "pa_tests/patest_record.c".</li> +</ul> +I also encourage you to examine the source for the PortAudio libraries. +If you have suggestions on ways to improve them, please let us know. if +you want to implement PortAudio on a new platform, please let us know as +well so we can coordinate people's efforts.</blockquote> +<font size=+2><a href="http://www.portaudio.com/">home</a> | <a href="pa_tutorial.html">contents</a> +| <a href="pa_tut_rw.html">previous</a> | next</font> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_tut_init.html b/pd/portaudio_v18/docs/pa_tut_init.html new file mode 100644 index 00000000..91bfa8d9 --- /dev/null +++ b/pd/portaudio_v18/docs/pa_tut_init.html @@ -0,0 +1,43 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.73 [en]C-gatewaynet (Win98; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Tutorial for PortAudio, a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Tutorial</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Tutorial</h1></center> +</td> +</tr> +</table></center> + +<h2> +Initializing PortAudio</h2> + +<blockquote>Before making any other calls to PortAudio, you must call <tt>Pa_Initialize</tt>(). +This will trigger a scan of available devices which can be queried later. +Like most PA functions, it will return a result of type <tt>paError</tt>. +If the result is not <tt>paNoError</tt>, then an error has occurred. +<blockquote> +<pre>err = Pa_Initialize(); +if( err != paNoError ) goto error;</pre> +</blockquote> +You can get a text message that explains the error message by passing it +to +<blockquote> +<pre>printf( "PortAudio error: %s\n", Pa_GetErrorText( err ) );</pre> +</blockquote> +</blockquote> +<font size=+2><a href="http://www.portaudio.com/">home</a> | <a href="pa_tutorial.html">contents</a> +| <a href="pa_tut_callback.html">previous</a> | <a href="pa_tut_open.html">next</a></font> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_tut_mac.html b/pd/portaudio_v18/docs/pa_tut_mac.html new file mode 100644 index 00000000..bf3dafd1 --- /dev/null +++ b/pd/portaudio_v18/docs/pa_tut_mac.html @@ -0,0 +1,41 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.77 [en]C-gatewaynet (Win98; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Tutorial for PortAudio, a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Tutorial</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Tutorial</h1></center> +</td> +</tr> +</table></center> + +<h2> +Compiling for Macintosh</h2> + +<blockquote>To compile a Macintosh application with the PortAudio library, +add the following source files to your project: +<blockquote> +<pre>pa_mac:pa_mac.c +pa_common:pa_lib.c +pa_common:portaudio.h +pa_common:pa_host.h</pre> +</blockquote> +Also add the Apple <b>SoundLib</b> to your project. +<p>You may try compiling the "pa_tests:patest_saw.c" file first because +it is the simplest.</blockquote> +<font size=+2><a href="http://www.portaudio.com/">home</a> | +<a href="pa_tutorial.html">contents</a> +| <a href="pa_tut_over.html">previous</a> | <a href="pa_tut_callback.html">next</a></font> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_tut_mac_osx.html b/pd/portaudio_v18/docs/pa_tut_mac_osx.html new file mode 100644 index 00000000..44b13883 --- /dev/null +++ b/pd/portaudio_v18/docs/pa_tut_mac_osx.html @@ -0,0 +1,84 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.79 [en] (Windows NT 5.0; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Tutorial for PortAudio, a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Tutorial</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Tutorial</h1></center> +</td> +</tr> +</table></center> + +<h2> +<font size=+2><a href="http://www.portaudio.com/">home</a> | +<a href="pa_tutorial.html">contents</a> +| <a href="pa_tut_over.html">previous</a> | <a href="pa_tut_callback.html">next</a></font></h2> + +<h2> +Compiling for Macintosh OS X</h2> + +<blockquote>To compile a Macintosh OS X CoreAudio application with the +PortAudio library you will use the following source files: +<blockquote>pa_mac_core/pa_mac_core.c<br> +pa_common/pa_lib.c<br> +pa_common/portaudio.h<br> +pa_common/pa_host.h<br> +pa_common/pa_convert.c<br> +pablio/ringbuffer.c<br> +pablio/ringbuffer.h</blockquote> +</blockquote> + +<h3> +Using Apple Project Builder</h3> + +<blockquote>Create a new ProjectBuilder project. You can use a "Tool" project +to run the PortAudio examples. +<p>Add the source files from above to your Project. +<p>Add both the Apple CoreAudio.framework and the AudioToolbox.framework +to your project by selecting "Add FrameWorks..." from the Project menu. +<p>Compile and run the "pa_tests:patest_saw.c" file first because it is +the simplest.</blockquote> + +<h3> +Or Using Metrowerks CodeWarrior 8</h3> + +<blockquote>by James Vanlommel</blockquote> + +<blockquote>Create a new CodeWarrior project using Mac OS C++ Stationery. +<br>Then choose Mac OS X Mach-O > Standard Console > C++ Console Mach-O. +<p>In the project window, Clear the HelloWorld.cpp file and add the source +files from above to your Project. +<p>Add a test file of your choosing, like +<br> patests /patest_sine8.c +<br> +<br>Add the frameworks to the Frameworks tab using Project > Add Files... +<br> CoreAudio +<br> AudioToolbox +<p>(The System framework should already be a part of the project.) +<p>Open the current target's settings, and in Language Settings > C/C++ +Language, uncheck (disable) the "ANSI Strict" setting. (Do this for both +Debug and Release projects, if necessary.) +<p>Edit pa_mac_core.c: +<br> On line 1546, cast the PaHost_AllocateFastMemory() result +to a (char *) or you will get a compile error. +<br> +<br>Compile and run. (may need to run from a terminal window) +<p>I've successfully built patest_sine8.c this way using the CVS .tar version +of portaudio (date: 2003-04-27). I get 17 warnings during compilation, +all of which deal with unused variables or arguments.</blockquote> +<font size=+2><a href="http://www.portaudio.com/">home</a> | +<a href="pa_tutorial.html">contents</a> +| <a href="pa_tut_over.html">previous</a> | <a href="pa_tut_callback.html">next</a></font> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_tut_open.html b/pd/portaudio_v18/docs/pa_tut_open.html new file mode 100644 index 00000000..12772811 --- /dev/null +++ b/pd/portaudio_v18/docs/pa_tut_open.html @@ -0,0 +1,56 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.79 [en] (Windows NT 5.0; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Tutorial for PortAudio, a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Tutorial</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Tutorial</h1></center> +</td> +</tr> +</table></center> + +<h2> +Opening a Stream using Defaults</h2> + +<blockquote>The next step is to open a stream which is similar to opening +a file. You can specify whether you want audio input and/or output, how +many channels, the data format, sample rate, etc. +<p>First declare a variable to receive the stream pointer: +<blockquote> +<pre>PortAudioStream *stream;</pre> +</blockquote> +There are two calls for opening streams, <tt>Pa_OpenStream</tt>() and <tt>Pa_OpenDefaultStream</tt>(). +P<tt>a_OpenStream()</tt> takes extra parameters which give you more +control. You can normally just use <tt>Pa_OpenDefaultStream</tt>() which +just calls <tt>Pa_OpenStream()</tt> <tt>with</tt> some reasonable default +values. Let's open a stream for stereo output, using floating point +data, at 44100 Hz. +<blockquote> +<pre>err = Pa_OpenDefaultStream( + &stream, /* passes back stream pointer */ + 0, /* no input channels */ + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + 44100, /* sample rate */ + 256, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + patestCallback, /* specify our custom callback */ + &data ); /* pass our data through to callback */</pre> +</blockquote> +If you want to use 16 bit integer data, pass <tt>paInt16</tt> instead of +<tt>paFloat32</tt>.</blockquote> +<font size=+2><a href="http://www.portaudio.com/">home</a> | <a href="pa_tutorial.html">contents</a> +| <a href="pa_tut_init.html">previous</a> | <a href="pa_tut_run.html">next</a></font> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_tut_oss.html b/pd/portaudio_v18/docs/pa_tut_oss.html new file mode 100644 index 00000000..1bb76f25 --- /dev/null +++ b/pd/portaudio_v18/docs/pa_tut_oss.html @@ -0,0 +1,46 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.77 [en]C-gatewaynet (Win98; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Tutorial for PortAudio, a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Tutorial</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Tutorial</h1></center> +</td> +</tr> +</table></center> + +<h2> +Compiling for Unix OSS</h2> + +<blockquote>[Skip this page if you are not using Unix and OSS] +<p>We currently support the <a href="http://www.opensound.com/">OSS</a> +audio drivers for Linux, Solaris, and FreeBSD. We hope to someday support +the newer ALSA drivers. +<ol> +<li> +cd to pa_unix_oss directory</li> + +<li> +Edit the Makefile and uncomment one of the tests. You may try compiling +the "patest_sine.c" file first because it is very simple.</li> + +<li> +gmake run</li> +</ol> +</blockquote> +<font size=+2><a href="http://www.portaudio.com/">home</a> | +<a href="pa_tutorial.html">contents</a> +| <a href="pa_tut_pc.html">previous</a> | <a href="pa_tut_callback.html">next</a></font> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_tut_over.html b/pd/portaudio_v18/docs/pa_tut_over.html new file mode 100644 index 00000000..baa99205 --- /dev/null +++ b/pd/portaudio_v18/docs/pa_tut_over.html @@ -0,0 +1,92 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.79 [en] (Windows NT 5.0; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Tutorial for PortAudio, a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Tutorial</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Tutorial</h1></center> +</td> +</tr> +</table></center> + +<h2> +Overview of PortAudio</h2> + +<blockquote>PortAudio is a library that provides streaming audio input +and output. It is a cross-platform API (Application Programming Interface) +that works on Windows, Macintosh, Unix running OSS, SGI, BeOS, and perhaps +other platforms by the time you read this. This means that you can write +a simple 'C' program to process or generate an audio signal, and that program +can run on several different types of computer just by recompiling the +source code. +<p>Here are the steps to writing a PortAudio application: +<ol> +<li> +Write a callback function that will be called by PortAudio when audio processing +is needed.</li> + +<li> +Initialize the PA library and open a stream for audio I/O.</li> + +<li> +Start the stream. Your callback function will be now be called repeatedly +by PA in the background.</li> + +<li> +In your callback you can read audio data from the inputBuffer and/or write +data to the outputBuffer.</li> + +<li> +Stop the stream by returning 1 from your callback, or by calling a stop +function.</li> + +<li> +Close the stream and terminate the library.</li> +</ol> +</blockquote> + +<blockquote>There is also <a href="pa_tut_rw.html">another interface</a> +provided that allows you to generate audio in the foreground. You then +simply write data to the stream and the tool will not return until it is +ready to accept more data. This interface is simpler to use but is usually +not preferred for large applications because it requires that you launch +a thread to perform the synthesis. Launching a thread may be difficult +on non-multi-tasking systems such as the Macintosh prior to MacOS X. +<p>Let's continue by building a simple application that will play a sawtooth +wave. +<p>Please select the page for the specific implementation you would like +to use: +<ul> +<li> +<a href="pa_tut_pc.html">Windows (WMME or DirectSound)</a></li> + +<li> +<a href="pa_tut_mac.html">Macintosh SoundManager for OS 7,8,9</a></li> + +<li> +<a href="pa_tut_mac_osx.html">Macintosh CoreAudio for OS X</a></li> + +<li> +<a href="pa_tut_asio.html">ASIO on Windows or Macintosh</a></li> + +<li> +<a href="pa_tut_oss.html">Unix OSS</a></li> +</ul> +or continue with the <a href="pa_tut_callback.html">next page of the programming +tutorial</a>.</blockquote> +<font size=+2><a href="http://www.portaudio.com/">home</a> | +<a href="pa_tutorial.html">contents</a> +| <a href="pa_tutorial.html">previous</a></font> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_tut_pc.html b/pd/portaudio_v18/docs/pa_tut_pc.html new file mode 100644 index 00000000..f7a70101 --- /dev/null +++ b/pd/portaudio_v18/docs/pa_tut_pc.html @@ -0,0 +1,114 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.79 [en] (Windows NT 5.0; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Tutorial for PortAudio, a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Tutorial</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Tutorial</h1></center> +</td> +</tr> +</table></center> + +<h2> +Compiling for Windows (WMME or DirectSound)</h2> + +<blockquote>To compile PortAudio for Windows, you can choose between three +options: +<ul> +<li> +DirectSound API.</li> + +<li> +Windows MultiMedia Extensions API (aka WMME or WAVE).</li> + +<li> +<a href="pa_tut_asio.html">Steinberg's ASIO API</a></li> +</ul> +Some advantages of using DirectSound are that DirectSound may have lower +latency than WMME, and supports effects processing plugins. But one disadvantage +is that DirectSound is not installed on all PCs, and is not well supported +under Windows NT. <b>So WMME is the best choice for most projects.</b><b></b> +<p><b>Note: </b>If you are compiling one of the PortAudio test programs +with Visual C++, then create a new Project of type "Win32 Console Application". +<h3> +All</h3> +For any Windows implementation, add the following source files to your +project: +<blockquote> +<pre><b>pa_common\pa_lib.c +pa_common\portaudio.h +pa_common\pa_host.h</b></pre> +</blockquote> +Link with the system library "<b>winmm.lib</b>". For Visual C++: +<ol> +<li> +select "Settings..." from the "Project" menu,</li> + +<li> +select the project name in the tree on the left,</li> + +<li> +choose "All Configurations" in the popup menu above the tree,</li> + +<li> +select the "Link" tab,</li> + +<li> +enter "winmm.lib", without quotes, as the first item in the "Object/library +modules:" field.</li> +</ol> + +<h3> +WMME</h3> +To use the WMME implementation, add the following source files to your +project: +<blockquote><b><tt>pa_win_wmme/pa_win_wmme.c</tt></b></blockquote> + +<h3> +DirectSound</h3> +If you want to use the DirectSound implementation of PortAudio then you +must have a recent copy of the free +<a href="http://www.microsoft.com/directx/download.asp">DirectX</a> +SDK for Developers from Microsoft installed on your computer. To compile +an application add the following source files to your project: +<blockquote> +<pre><b>pa_win_ds\dsound_wrapper.c +pa_win_ds\pa_dsound.c</b></pre> +</blockquote> +Link with both system libraries "<b>dsound.lib</b>" and "<b>winmm.lib</b>" +using the procedure described above for "winmm.lib". +<br> +<table BORDER > +<tr> +<td><b>Borland</b> users cannot link with the "dsound.lib" from Microsoft +directly. Emmanuel offered this advice: +<p>One can use implib from Borland to generate a new .lib file which is +compatible with Borland C++. +<p>Use: "implib dsound.dll dsound.lib" and include dsound.lib into your +project. +<p>I still had a problem executing the patest_record example. The thread +ended with an error like 'Floating point overflow at...'. This problem +was caused due to a fault in the compiler. Now I'm using Borland 5.02 (instead +of 5.01). Everything seems to be working fine at the moment.</td> +</tr> +</table> +</blockquote> + +<blockquote>You might try compiling the "pa_tests\patest_saw.c" file first +because it is the simplest.</blockquote> +<font size=+2><a href="http://www.portaudio.com/">home</a> | +<a href="pa_tutorial.html">contents</a> +| <a href="pa_tut_over.html">previous</a> | <a href="pa_tut_callback.html">next</a></font> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_tut_run.html b/pd/portaudio_v18/docs/pa_tut_run.html new file mode 100644 index 00000000..5c70d089 --- /dev/null +++ b/pd/portaudio_v18/docs/pa_tut_run.html @@ -0,0 +1,56 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.73 [en]C-gatewaynet (Win98; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Tutorial for PortAudio, a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Tutorial</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Tutorial</h1></center> +</td> +</tr> +</table></center> + +<h2> +Starting and Stopping a Stream</h2> + +<blockquote>The stream will not start running until you call Pa_StartStream(). +Then it will start calling your callback function to perform the audio +processing. +<blockquote> +<pre>err = Pa_StartStream( stream ); +if( err != paNoError ) goto error;</pre> +</blockquote> +At this point, audio is being generated. You can communicate to your callback +routine through the data structure you passed in on the open call, or through +global variables, or using other interprocess communication techniques. +Please be aware that your callback function may be called at interrupt +time when your foreground process is least expecting it. So avoid sharing +complex data structures that are easily corrupted like double linked lists. +<p>In many of the tests we simply sleep for a few seconds so we can hear +the sound. This is easy to do with Pa_Sleep() which will sleep for some +number of milliseconds. Do not rely on this function for accurate scheduling. +it is mostly for writing examples. +<blockquote> +<pre>/* Sleep for several seconds. */ +Pa_Sleep(NUM_SECONDS*1000);</pre> +</blockquote> +When you are through, you can stop the stream from the foreground. +<blockquote> +<pre>err = Pa_StopStream( stream ); +if( err != paNoError ) goto error;</pre> +</blockquote> +You can also stop the stream by returning 1 from your custom callback function.</blockquote> +<font size=+2><a href="http://www.portaudio.com/">home</a> | <a href="pa_tutorial.html">contents</a> +| <a href="pa_tut_open.html">previous</a> | <a href="pa_tut_term.html">next</a></font> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_tut_rw.html b/pd/portaudio_v18/docs/pa_tut_rw.html new file mode 100644 index 00000000..93c7b8bb --- /dev/null +++ b/pd/portaudio_v18/docs/pa_tut_rw.html @@ -0,0 +1,79 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.77 [en]C-gatewaynet (Win98; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Tutorial for PortAudio, a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Tutorial</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Tutorial</h1></center> +</td> +</tr> +</table></center> + +<h2> +Blocking Read/Write Functions</h2> + +<blockquote>[Note: These functions are not part of the official PortAudio +API. They are simply built on top of PortAudio as an extra utility. Also +note that they are under evaluation and their definition may change.] +<p>There are two fundamentally different ways to design an audio API. One +is to use callback functions the way we have already shown. The callback +function operates under an interrupt or background thread This leaves the +foreground application free to do other things while the audio just runs +in the background. But this can sometimes be awkward. +<p>So we have provided an alternative technique that lets a program generate +audio in the foreground and then just write it to the audio stream as if +it was a file. If there is not enough room in the audio buffer for more +data, then the write function will just block until more room is available. +This can make it very easy to write an audio example. To use this tool, +you must add the files "pablio/pablio.c" and "pablio/ringbuffer.c" to your +project. You must also: +<blockquote> +<pre>#include "pablio.h"</pre> +</blockquote> +Here is a short excerpt of a program that opens a stream for input and +output. It then reads a block of samples from input, and writes them to +output, in a loop. The complete example can be found in "pablio/test_rw.c". +<blockquote> +<pre> #define SAMPLES_PER_FRAME (2) + #define FRAMES_PER_BLOCK (1024) + SAMPLE samples[SAMPLES_PER_FRAME * FRAMES_PER_BLOCK]; + PaError err; + PABLIO_Stream *aStream; + +/* Open simplified blocking I/O layer on top of PortAudio. */ + err = OpenAudioStream( &rwbl, SAMPLE_RATE, paFloat32, + (PABLIO_READ_WRITE | PABLIO_STEREO) ); + if( err != paNoError ) goto error; + +/* Process samples in the foreground. */ + for( i=0; i<(NUM_SECONDS * SAMPLE_RATE); i++ ) + { + /* Read one block of data into sample array from audio input. */ + ReadAudioStream( aStream, samples, FRAMES_PER_BLOCK ); + /* + ** At this point you could process the data in samples array, + ** and write the result back to the same samples array. + */ + /* Write that same frame of data to output. */ + WriteAudioStream( aStream, samples, FRAMES_PER_BLOCK ); + } + + CloseAudioStream( aStream );</pre> +</blockquote> +</blockquote> +<font size=+2><a href="http://www.portaudio.com/">home</a> | +<a href="pa_tutorial.html">contents</a> +| <a href="pa_tut_devs.html">previous</a> | <a href="pa_tut_explore.html">next</a></font> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_tut_term.html b/pd/portaudio_v18/docs/pa_tut_term.html new file mode 100644 index 00000000..1c72209f --- /dev/null +++ b/pd/portaudio_v18/docs/pa_tut_term.html @@ -0,0 +1,47 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.73 [en]C-gatewaynet (Win98; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Tutorial for PortAudio, a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Tutorial</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Tutorial</h1></center> +</td> +</tr> +</table></center> + +<h2> +Terminating PortAudio</h2> + +<blockquote>You can start and stop a stream as many times as you like. +But when you are done using it, you should close it by calling:</blockquote> + +<blockquote> +<blockquote> +<pre>err = Pa_CloseStream( stream ); +if( err != paNoError ) goto error;</pre> +</blockquote> +Then when you are done using PortAudio, you should terminate the whole +system by calling: +<blockquote> +<pre>Pa_Terminate();</pre> +</blockquote> +That's basically it. You can now write an audio program in 'C' that will +run on multiple platforms, for example PCs and Macintosh. +<p>In the rest of the tutorial we will look at some additional utility +functions, and a different way of using PortAudio that does not require +the use of a callback function.</blockquote> +<font size=+2><a href="http://www.portaudio.com/">home</a> | <a href="pa_tutorial.html">contents</a> +| <a href="pa_tut_run.html">previous</a> | <a href="pa_tut_util.html">next</a></font> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_tut_util.html b/pd/portaudio_v18/docs/pa_tut_util.html new file mode 100644 index 00000000..f4b54750 --- /dev/null +++ b/pd/portaudio_v18/docs/pa_tut_util.html @@ -0,0 +1,55 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.75 [en]C-gatewaynet (Win98; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Tutorial for PortAudio, a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Tutorial</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Tutorial</h1></center> +</td> +</tr> +</table></center> + +<h2> +Utility Functions</h2> + +<blockquote>Here are several more functions that are not critical, but +may be handy when using PortAudio. +<p>Pa_StreamActive() returns one when the stream in playing audio, zero +when not playing, or a negative error number if the stream is invalid. +The stream is active between calls to Pa_StartStream() and Pa_StopStream(), +but may also become inactive if the callback returns a non-zero value. +In the latter case, the stream is considered inactive after the last buffer +has finished playing. +<blockquote> +<pre>PaError Pa_StreamActive( PortAudioStream *stream );</pre> +</blockquote> +Pa_StreamTime() returns the number of samples that have been generated. +PaTimeStamp is a double precision number which is a convenient way to pass +big numbers around even though we only need integers. +<blockquote> +<pre>PaTimestamp Pa_StreamTime( PortAudioStream *stream );</pre> +</blockquote> +The "CPU Load" is a fraction of total CPU time consumed by the stream's +audio processing. A value of 0.5 would imply that PortAudio and the sound +generating callback was consuming roughly 50% of the available CPU time. +This function may be called from the callback function or the application. +<blockquote> +<pre>double Pa_GetCPULoad( PortAudioStream* stream );</pre> +</blockquote> +</blockquote> +<font size=+2><a href="http://www.portaudio.com/">home</a> | +<a href="pa_tutorial.html">contents</a> | <a href="pa_tut_term.html">previous</a> +| <a href="pa_tut_devs.html">next</a></font> +</body> +</html> diff --git a/pd/portaudio_v18/docs/pa_tutorial.html b/pd/portaudio_v18/docs/pa_tutorial.html new file mode 100644 index 00000000..1371c44f --- /dev/null +++ b/pd/portaudio_v18/docs/pa_tutorial.html @@ -0,0 +1,46 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.79 [en] (Windows NT 5.0; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="Tutorial for PortAudio, a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Tutorial</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio Tutorial</h1></center> +</td> +</tr> +</table></center> + +<p>Copyright 2000 Phil Burk and Ross Bencina +<h2> +Table of Contents</h2> + +<blockquote><a href="pa_tut_over.html">Overview of PortAudio</a> +<br><a href="pa_tut_mac.html">Compiling for Macintosh OS 7,8,9</a> +<br><a href="pa_tut_mac_osx.html">Compiling for Macintosh OS X</a> +<br><a href="pa_tut_pc.html">Compiling for Windows (DirectSound and WMME)</a> +<br><a href="pa_tut_asio.html">Compiling for ASIO on Windows or Mac OS +8,9</a> +<br><a href="pa_tut_oss.html">Compiling for Unix OSS</a> +<br><a href="pa_tut_callback.html">Writing a Callback Function</a> +<br><a href="pa_tut_init.html">Initializing PortAudio</a> +<br><a href="pa_tut_open.html">Opening a Stream using Defaults</a> +<br><a href="pa_tut_run.html">Starting and Stopping a Stream</a> +<br><a href="pa_tut_term.html">Cleaning Up</a> +<br><a href="pa_tut_util.html">Utilities</a> +<br><a href="pa_tut_devs.html">Querying for Devices</a> +<br><a href="pa_tut_rw.html">Blocking Read/Write Functions</a> +<br><a href="pa_tut_explore.html">Exploring the PortAudio Package</a></blockquote> +<font size=+2><a href="http://www.portaudio.com/">home</a> | contents | +previous | <a href="pa_tut_over.html">next</a></font> +</body> +</html> diff --git a/pd/portaudio_v18/docs/portaudio_h.txt b/pd/portaudio_v18/docs/portaudio_h.txt new file mode 100644 index 00000000..6d60086f --- /dev/null +++ b/pd/portaudio_v18/docs/portaudio_h.txt @@ -0,0 +1,425 @@ +#ifndef PORT_AUDIO_H +#define PORT_AUDIO_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * PortAudio Portable Real-Time Audio Library + * PortAudio API Header File + * Latest version available at: http://www.audiomulch.com/portaudio/ + * + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +typedef int PaError; +typedef enum { + paNoError = 0, + + paHostError = -10000, + paInvalidChannelCount, + paInvalidSampleRate, + paInvalidDeviceId, + paInvalidFlag, + paSampleFormatNotSupported, + paBadIODeviceCombination, + paInsufficientMemory, + paBufferTooBig, + paBufferTooSmall, + paNullCallback, + paBadStreamPtr, + paTimedOut, + paInternalError +} PaErrorNum; + +/* + Pa_Initialize() is the library initialisation function - call this before + using the library. +*/ + +PaError Pa_Initialize( void ); + +/* + Pa_Terminate() is the library termination function - call this after + using the library. +*/ + +PaError Pa_Terminate( void ); + +/* + Return host specific error. + This can be called after receiving a paHostError. +*/ +long Pa_GetHostError( void ); + +/* + Translate the error number into a human readable message. +*/ +const char *Pa_GetErrorText( PaError errnum ); + +/* + Sample formats + + These are formats used to pass sound data between the callback and the + stream. Each device has a "native" format which may be used when optimum + efficiency or control over conversion is required. + + Formats marked "always available" are supported (emulated) by all devices. + + The floating point representation uses +1.0 and -1.0 as the respective + maximum and minimum. + +*/ + +typedef unsigned long PaSampleFormat; +#define paFloat32 ((PaSampleFormat) (1<<0)) /*always available*/ +#define paInt16 ((PaSampleFormat) (1<<1)) /*always available*/ +#define paInt32 ((PaSampleFormat) (1<<2)) /*always available*/ +#define paInt24 ((PaSampleFormat) (1<<3)) +#define paPackedInt24 ((PaSampleFormat) (1<<4)) +#define paInt8 ((PaSampleFormat) (1<<5)) +#define paUInt8 ((PaSampleFormat) (1<<6)) /* unsigned 8 bit, 128 is "ground" */ +#define paCustomFormat ((PaSampleFormat) (1<<16)) + +/* + Device enumeration mechanism. + + Device ids range from 0 to Pa_CountDevices()-1. + + Devices may support input, output or both. Device 0 is always the "default" + device and should support at least stereo in and out if that is available + on the taget platform _even_ if this involves kludging an input/output + device on platforms that usually separate input from output. Other platform + specific devices are specified by positive device ids. +*/ + +typedef int PaDeviceID; +#define paNoDevice -1 + +typedef struct{ + int structVersion; + const char *name; + int maxInputChannels; + int maxOutputChannels; +/* Number of discrete rates, or -1 if range supported. */ + int numSampleRates; +/* Array of supported sample rates, or {min,max} if range supported. */ + const double *sampleRates; + PaSampleFormat nativeSampleFormats; +} PaDeviceInfo; + + +int Pa_CountDevices(); +/* + Pa_GetDefaultInputDeviceID(), Pa_GetDefaultOutputDeviceID() + + Return the default device ID or paNoDevice if there is no devices. + The result can be passed to Pa_OpenStream(). + + On the PC, the user can specify a default device by + setting an environment variable. For example, to use device #1. + + set PA_RECOMMENDED_OUTPUT_DEVICE=1 + + The user should first determine the available device ID by using + the supplied application "pa_devs". +*/ +PaDeviceID Pa_GetDefaultInputDeviceID( void ); +PaDeviceID Pa_GetDefaultOutputDeviceID( void ); + +/* + PaTimestamp is used to represent a continuous sample clock with arbitrary + start time useful for syncronisation. The type is used in the outTime + argument to the callback function and the result of Pa_StreamTime() +*/ + +typedef double PaTimestamp; + +/* + Pa_GetDeviceInfo() returns a pointer to an immutable PaDeviceInfo structure + referring to the device specified by id. + If id is out of range the function returns NULL. + + The returned structure is owned by the PortAudio implementation and must + not be manipulated or freed. The pointer is guaranteed to be valid until + between calls to Pa_Initialize() and Pa_Terminate(). +*/ + +const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceID devID ); + +/* + PortAudioCallback is implemented by clients of the portable audio api. + + inputBuffer and outputBuffer are arrays of interleaved samples, + the format, packing and number of channels used by the buffers are + determined by parameters to Pa_OpenStream() (see below). + + framesPerBuffer is the number of sample frames to be processed by the callback. + + outTime is the time in samples when the buffer(s) processed by + this callback will begin being played at the audio output. + See also Pa_StreamTime() + + userData is the value of a user supplied pointer passed to Pa_OpenStream() + intended for storing synthesis data etc. + + return value: + The callback can return a nonzero value to stop the stream. This may be + useful in applications such as soundfile players where a specific duration + of output is required. However, it is not necessary to utilise this mechanism + as StopStream() will also terminate the stream. A callback returning a + nonzero value must fill the entire outputBuffer. + + NOTE: None of the other stream functions may be called from within the + callback function except for Pa_GetCPULoad(). + +*/ + +typedef int (PortAudioCallback)( + void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ); + + +/* + Stream flags + + These flags may be supplied (ored together) in the streamFlags argument to + the Pa_OpenStream() function. + + [ suggestions? ] +*/ + +#define paNoFlag (0) +#define paClipOff (1<<0) /* disable defult clipping of out of range samples */ +#define paDitherOff (1<<1) /* disable default dithering */ +#define paPlatformSpecificFlags (0x00010000) +typedef unsigned long PaStreamFlags; + +/* + A single PortAudioStream provides multiple channels of real-time + input and output audio streaming to a client application. + Pointers to PortAudioStream objects are passed between PortAudio functions. +*/ + +typedef void PortAudioStream; +#define PaStream PortAudioStream + +/* + Pa_OpenStream() opens a stream for either input, output or both. + + stream is the address of a PortAudioStream pointer which will receive + a pointer to the newly opened stream. + + inputDevice is the id of the device used for input (see PaDeviceID above.) + inputDevice may be paNoDevice to indicate that an input device is not required. + + numInputChannels is the number of channels of sound to be delivered to the + callback. It can range from 1 to the value of maxInputChannels in the + device input record for the device specified in the inputDevice parameter. + If inputDevice is paNoDevice numInputChannels is ignored. + + inputSampleFormat is the format of inputBuffer provided to the callback + function. inputSampleFormat may be any of the formats described by the + PaSampleFormat enumeration (see above). PortAudio guarantees support for + the sound devices native formats (nativeSampleFormats in the device info + record) and additionally 16 and 32 bit integer and 32 bit floating point + formats. Support for other formats is implementation defined. + + inputDriverInfo is a pointer to an optional driver specific data structure + containing additional information for device setup or stream processing. + inputDriverInfo is never required for correct operation. If not used + inputDriverInfo should be NULL. + + outputDevice is the id of the device used for output (see PaDeviceID above.) + outputDevice may be paNoDevice to indicate that an output device is not required. + + numOutputChannels is the number of channels of sound to be supplied by the + callback. See the definition of numInputChannels above for more details. + + outputSampleFormat is the sample format of the outputBuffer filled by the + callback function. See the definition of inputSampleFormat above for more + details. + + outputDriverInfo is a pointer to an optional driver specific data structure + containing additional information for device setup or stream processing. + outputDriverInfo is never required for correct operation. If not used + outputDriverInfo should be NULL. + + sampleRate is the desired sampleRate for input and output + + framesPerBuffer is the length in sample frames of all internal sample buffers + used for communication with platform specific audio routines. Wherever + possible this corresponds to the framesPerBuffer parameter passed to the + callback function. + + numberOfBuffers is the number of buffers used for multibuffered + communication with the platform specific audio routines. This parameter is + provided only as a guide - and does not imply that an implementation must + use multibuffered i/o when reliable double buffering is available (such as + SndPlayDoubleBuffer() on the Macintosh.) + + streamFlags may contain a combination of flags ORed together. + These flags modify the behavior of the + streaming process. Some flags may only be relevant to certain buffer formats. + + callback is a pointer to a client supplied function that is responsible + for processing and filling input and output buffers (see above for details.) + + userData is a client supplied pointer which is passed to the callback + function. It could for example, contain a pointer to instance data necessary + for processing the audio buffers. + + return value: + Apon success Pa_OpenStream() returns PaNoError and places a pointer to a + valid PortAudioStream in the stream argument. The stream is inactive (stopped). + If a call to Pa_OpenStream() fails a nonzero error code is returned (see + PAError above) and the value of stream is invalid. + +*/ + +PaError Pa_OpenStream( PortAudioStream** stream, + PaDeviceID inputDevice, + int numInputChannels, + PaSampleFormat inputSampleFormat, + void *inputDriverInfo, + PaDeviceID outputDevice, + int numOutputChannels, + PaSampleFormat outputSampleFormat, + void *outputDriverInfo, + double sampleRate, + unsigned long framesPerBuffer, + unsigned long numberOfBuffers, + PaStreamFlags streamFlags, + PortAudioCallback *callback, + void *userData ); + + +/* + Pa_OpenDefaultStream() is a simplified version of Pa_OpenStream() that + opens the default input and/or ouput devices. Most parameters have + identical meaning to their Pa_OpenStream() counterparts, with the following + exceptions: + + If either numInputChannels or numOutputChannels is 0 the respective device + is not opened (same as passing paNoDevice in the device arguments to Pa_OpenStream() ) + + sampleFormat applies to both the input and output buffers. +*/ + +PaError Pa_OpenDefaultStream( PortAudioStream** stream, + int numInputChannels, + int numOutputChannels, + PaSampleFormat sampleFormat, + double sampleRate, + unsigned long framesPerBuffer, + unsigned long numberOfBuffers, + PortAudioCallback *callback, + void *userData ); + +/* + Pa_CloseStream() closes an audio stream, flushing any pending buffers. +*/ + +PaError Pa_CloseStream( PortAudioStream* ); + +/* + Pa_StartStream() and Pa_StopStream() begin and terminate audio processing. + Pa_StopStream() waits until all pending audio buffers have been played. + Pa_AbortStream() stops playing immediately without waiting for pending + buffers to complete. +*/ + +PaError Pa_StartStream( PortAudioStream *stream ); + +PaError Pa_StopStream( PortAudioStream *stream ); + +PaError Pa_AbortStream( PortAudioStream *stream ); + +/* + Pa_StreamActive() returns one when the stream is playing audio, + zero when not playing, or a negative error number if the + stream is invalid. + The stream is active between calls to Pa_StartStream() and Pa_StopStream(), + but may also become inactive if the callback returns a non-zero value. + In the latter case, the stream is considered inactive after the last + buffer has finished playing. +*/ + +PaError Pa_StreamActive( PortAudioStream *stream ); + +/* + Pa_StreamTime() returns the current output time for the stream in samples. + This time may be used as a time reference (for example syncronising audio to + MIDI). +*/ + +PaTimestamp Pa_StreamTime( PortAudioStream *stream ); + +/* + The "CPU Load" is a fraction of total CPU time consumed by the + stream's audio processing. + A value of 0.5 would imply that PortAudio and the sound generating + callback was consuming roughly 50% of the available CPU time. + This function may be called from the callback function or the application. +*/ +double Pa_GetCPULoad( PortAudioStream* stream ); + +/* + Use Pa_GetMinNumBuffers() to determine minimum number of buffers required for + the current host based on minimum latency. + On the PC, for the DirectSound implementation, latency can be optionally set + by user by setting an environment variable. + For example, to set latency to 200 msec, put: + + set PA_MIN_LATENCY_MSEC=200 + + in the AUTOEXEC.BAT file and reboot. + If the environment variable is not set, then the latency will be determined + based on the OS. Windows NT has higher latency than Win95. +*/ + +int Pa_GetMinNumBuffers( int framesPerBuffer, double sampleRate ); + +/* + Sleep for at least 'msec' milliseconds. + You may sleep longer than the requested time so don't rely + on this for accurate musical timing. +*/ +void Pa_Sleep( long msec ); + +/* + Return size in bytes of a single sample in a given PaSampleFormat + or paSampleFormatNotSupported. +*/ +PaError Pa_GetSampleSize( PaSampleFormat format ); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* PORT_AUDIO_H */ diff --git a/pd/portaudio_v18/docs/portaudio_icmc2001.pdf b/pd/portaudio_v18/docs/portaudio_icmc2001.pdf Binary files differnew file mode 100644 index 00000000..747016e1 --- /dev/null +++ b/pd/portaudio_v18/docs/portaudio_icmc2001.pdf diff --git a/pd/portaudio_v18/docs/proposals.html b/pd/portaudio_v18/docs/proposals.html Binary files differnew file mode 100644 index 00000000..88dd2d07 --- /dev/null +++ b/pd/portaudio_v18/docs/proposals.html diff --git a/pd/portaudio_v18/docs/releases.html b/pd/portaudio_v18/docs/releases.html new file mode 100644 index 00000000..aec80a1c --- /dev/null +++ b/pd/portaudio_v18/docs/releases.html @@ -0,0 +1,339 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.79 [en] (Windows NT 5.0; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="PortAudio is a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio Release Notes</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio - Release Notes</h1></center> +</td> +</tr> +</table></center> + +<p>Link to <a href="http://www.portaudio.com">PortAudio Home Page</a> +<h2> +<b>V18 - 5/6/02</b></h2> + +<blockquote>All source code and documentation now under <a href="http://www.portaudio.com/usingcvs.html">CVS</a>. +<p>Ran most of the code through <a href="http://astyle.sourceforge.net/">AStyle</a> +to cleanup ragged indentation caused by using different editors. Used this +command: +<br><tt> astyle --style=ansi -c -o --convert-tabs --indent-preprocessor +*.c</tt></blockquote> + +<blockquote>Added "pa_common/pa_convert.c" for Mac OS X. Start of new conversion +utilities. +<p><b>ASIO</b> +<ul> +<li> +New Pa_ASIO_Adaptor_Init function to init Callback adpatation variables,</li> + +<li> +Cleanup of Pa_ASIO_Callback_Input</li> + +<li> +Break apart device loading to debug random failure in Pa_ASIO_QueryDeviceInfo</li> + +<li> +Deallocate all resources in PaHost_Term for cases where Pa_CloseStream +is not called properly</li> + +<li> +New Pa_ASIO_loadDriver that calls CoInitialize on each thread on Windows. +Allows use by multiple threads.</li> + +<li> +Correct error code management in PaHost_Term, removed various compiler +warning</li> + +<li> +Add Mac includes for <Devices.h> and <Timer.h></li> + +<li> +Pa_ASIO_QueryDeviceInfo bug correction, memory allocation checking, better +error handling</li> +</ul> +<b>Mac OS X</b> +<ul> +<li> +Major cleanup and improvements.</li> + +<li> +Fixed device queries for numChannels and sampleRates,</li> + +<li> +Audio input works if using same CoreAudio device (some HW devices make +separate CoreAudio devices).</li> + +<li> +Added paInt16, paInt8, format using new "pa_common/pa_convert.c" file.</li> + +<li> +Return error if opened in mono mode cuz not supported.</li> + +<li> +Check for getenv("PA_MIN_LATEWNCY_MSEC") to set latency externally.</li> + +<li> +Use getrusage() instead of gettimeofday() for CPU Load calculation.</li> +</ul> +<b>Windows MME</b> +<ul> +<li> +Fixed bug that caused TIMEOUT in Pa_StopStream(). Added check for past_StopSoon() +in Pa_TimeSlice(). Thanks Julien Maillard.</li> + +<li> +Detect Win XP versus NT, use lower latency.</li> + +<li> +Fix DBUG typo;</li> + +<li> +removed init of CurrentCount which was not compiling on Borland</li> + +<li> +general cleanup, factored streamData alloc and cpu usage initialization</li> + +<li> +stopped counting WAVE_MAPPER when there were no audio cards plugged in</li> +</ul> +<b>Windows DirectSound</b> +<ul> +<li> +Detect Win XP and Win 2K properly when determining latency.</li> +</ul> +<b>Unix OSS</b> +<ul> +<li> +Use high real-time priority if app is running with root priveledges. Lowers +latency.</li> + +<li> +Added watch dog thread that prevents real-time thread from hogging CPU +and hanging the computer.</li> + +<li> +Check error return from read() and write().</li> + +<li> +Check CPU endianness instead of assuming Little Endian.</li> +</ul> +</blockquote> + +<h2> +<b>V17 - 10/15/01</b></h2> + +<blockquote><b>Unix OSS</b> +<ul> +<li> +Set num channels back to two after device query for ALSA. This fixed a +bug in V16 that sometimes caused a failure when querying for the sample +rates. Thanks Stweart Greenhill.</li> +</ul> +</blockquote> + +<blockquote> +<h4> +<b>Macintosh Sound Manager</b></h4> + +<ul> +<li> +Use NewSndCallBackUPP() for CARBON compatibility.</li> +</ul> +</blockquote> + +<h2> +<b>V16 - 9/27/01</b></h2> + +<blockquote><b>Added Alpha implementations for ASIO, SGI, and BeOS!</b> +<br> +<li> +CPULoad is now calculated based on the time spent to generate a known number +of frames. This is more accurate than a simple percentage of real-time. +Implemented in pa_unix_oss, pa_win_wmme and pa_win_ds.</li> + +<li> +Fix dither and shift for recording PaUInt8 format data.</li> + +<li> +Added "patest_maxsines.c" which tests <tt>Pa_GetCPULoad().</tt></li> +</blockquote> + +<blockquote> +<h4> +Windows WMME</h4> + +<ul> +<li> +sDevicePtrs now allocated using <tt>GlobalAlloc()</tt>. This prevents a +crash in Pa_Terminate() on Win2000. Thanks Mike Berry for finding this. +Thanks Mike Berry.</li> + +<li> +Pass process instead of thread to <tt>SetPriorityClass</tt>(). This fixes +a bug that caused the priority to not be increased. Thanks to Alberto di +Bene for spotting this.</li> +</ul> + +<h4> +Windows DirectSound</h4> + +<ul> +<li> +Casts for compiling with __MWERKS__ CodeWarrior.</li> +</ul> + +<h4> +UNIX OSS</h4> + +<ul> +<li> +Derived from Linux OSS implementation.</li> + +<li> +Numerous patches from Heiko Purnhagen, Stephen Brandon, etc.</li> + +<li> +Improved query mechanism which often bailed out unnecessarily.</li> + +<li> +Removed sNumDevices and potential related bugs,</li> + +<li> +Use <tt>getenv("PA_MIN_LATENCY_MSEC")</tt> in code to set desired latency. +User can set by entering:</li> + +<br> <tt>export PA_MIN_LATENCY_MSEC=40</tt></ul> + +<h4> +Macintosh Sound Manager</h4> + +<ul> +<li> +Pass unused event to WaitNextEvent instead of NULL to prevent Mac OSX crash. +Thanks Dominic Mazzoni.</li> + +<li> +Use requested number of input channels.</li> + +<br> </ul> +</blockquote> + +<h2> +<b>V15 - 5/29/01</b></h2> + +<blockquote> +<ul> +<li> +<b>New Linux OSS Beta</b></li> +</ul> + +<h4> +Windows WMME</h4> + +<ul> +<li> + sDevicePtrs now allocated based on sizeof(pointer). Was allocating +too much space.</li> + +<li> + Check for excessive numbers of channels. Some drivers reported bogus +numbers.</li> + +<li> +Apply Mike Berry's changes for CodeWarrior on PC including condition including +of memory.h, and explicit typecasting on memory allocation.</li> +</ul> + +<h4> +Macintosh Sound Manager</h4> + +<ul> +<li> +ScanInputDevices was setting sDefaultOutputDeviceID instead of sDefaultInputDeviceID.</li> + +<li> +Device Scan was crashing for anything other than siBadSoundInDevice, but +some Macs may return other errors! Caused failure to init on some G4s under +OS9.</li> + +<li> +Fix TIMEOUT in record mode.</li> + +<li> +Change CARBON_COMPATIBLE to TARGET_API_MAC_CARBON</li> +</ul> +</blockquote> + +<h2> +<b>V14 - 2/6/01</b></h2> + +<blockquote> +<ul> +<li> +Added implementation for Windows MultiMedia Extensions (WMME) by Ross and +Phil</li> + +<li> +Changed Pa_StopStream() so that it waits for the buffers to drain.</li> + +<li> +Added Pa_AbortStream() that stops immediately without waiting.</li> + +<li> +Added new test: patest_stop.c to test above two mods.</li> + +<li> +Fixed Pa_StreamTime() so that it returns current play position instead +of the write position. Added "patest_sync.c" to demo audio/video sync.</li> + +<li> +Improved stability of Macintosh implementation. Added timeouts to prevent +hangs.</li> + +<li> +Added Pa_GetSampleSize( PaSampleFormat format );</li> + +<li> +Changes some "int"s to "long"s so that PA works properly on Macintosh which +often compiles using 16 bit ints.</li> + +<li> +Added Implementation Guide</li> +</ul> +</blockquote> + +<h2> +<b>V12 - 1/9/01</b></h2> + +<blockquote> +<ul> +<li> +Mac now scans for and queries all devices. But it does not yet support +selecting any other than the default device.</li> + +<li> +Blocking I/O calls renamed to separate them from the PortAudio API.</li> + +<li> +Cleaned up indentation problems with tabs versus spaces.</li> + +<li> +Now attempts to correct bogus sample rate info returned from DirectSound +device queries.</li> +</ul> +</blockquote> + +</body> +</html> diff --git a/pd/portaudio_v18/fixdir.bat b/pd/portaudio_v18/fixdir.bat new file mode 100644 index 00000000..92d6c747 --- /dev/null +++ b/pd/portaudio_v18/fixdir.bat @@ -0,0 +1,19 @@ +rem Use Astyle to fix style in 'C' files +cd %1% + +fixlines -p *.c +fixlines -p *.cpp +fixlines -p *.cc + +astyle --style=ansi -c -o --convert-tabs --indent-preprocessor *.c +astyle --style=ansi -c -o --convert-tabs --indent-preprocessor *.cpp +astyle --style=ansi -c -o --convert-tabs --indent-preprocessor *.cc +del *.orig +@rem convert line terminators to Unix style LFs +fixlines -u *.c +fixlines -u *.cpp +fixlines -u *.cc +fixlines -u *.h +del *.bak + +cd ..\ diff --git a/pd/portaudio_v18/fixfile.bat b/pd/portaudio_v18/fixfile.bat new file mode 100644 index 00000000..48f6fbc2 --- /dev/null +++ b/pd/portaudio_v18/fixfile.bat @@ -0,0 +1,7 @@ +rem Use Astyle to fix style in a file +fixlines -p %1% +astyle --style=ansi -c -o --convert-tabs --indent-preprocessor %1% +del %1%.orig +@rem convert line terminators to Unix style LFs +fixlines -u %1% +del %1%.bak diff --git a/pd/portaudio_v18/index.html b/pd/portaudio_v18/index.html new file mode 100644 index 00000000..ff6cfeec --- /dev/null +++ b/pd/portaudio_v18/index.html @@ -0,0 +1,89 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.79 [en] (Windows NT 5.0; U) [Netscape]"> + <meta name="Author" content="Phil Burk"> + <meta name="Description" content="PortAudio is a cross platform, open-source, audio I/O library.It provides a very simple API for recording and/or playing sound using a simple callback function."> + <meta name="KeyWords" content="audio, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,"> + <title>PortAudio - Cross-Platform Audio API</title> +</head> +<body> + +<center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" > +<tr> +<td> +<center> +<h1> +PortAudio - Portable Audio Library</h1></center> +</td> +</tr> +</table></center> + +<p>Last updated 5/6/02. +<p>PortAudio is a cross platform, <a href="#License">open-source</a>, audio +I/O library proposed by <b>Ross Bencina</b> to the <a href="http://shoko.calarts.edu/~glmrboy/musicdsp/music-dsp.html">music-dsp</a> +mailing list. It lets you write simple audio programs in 'C' that will +compile and run on <b>Windows, Macintosh, Unix, BeOS</b>. PortAudio is +intended to promote the exchange of audio synthesis software between developers +on different platforms. +<p>For complete information on PortAudio and to download the latest releases, +please visit "<b><font size=+2><a href="http://www.portaudio.com">http://www.portaudio.com</a></font></b>". +<br> +<br> +<center> +<h2> +<b><a href="docs/index.html">Click here for Documentation</a></b></h2></center> + +<h2> +<b><font size=+2></font></b></h2> + +<h2> +<b><font size=+2>Contacts and E-Mail List</font></b></h2> + +<ul> +<li> +If you are using or implementing PortAudio then please join the <b><font size=+1><a href="http://techweb.rfa.org/mailman/listinfo/portaudio">PortAudio +mail list</a></font><font size=+2> </font></b>generously administered by +<b>Bill +Eldridge</b>.</li> + +<li> +If you find bugs in one of these implementations, or have suggestions, +please e-mail them to <a href="mailto:philburk@softsynth.com">Phil Burk</a>.</li> + +<li> +If you make improvements to the library, please send them to us so we can +incorporate the improvements.</li> +</ul> + +<h2> +<a NAME="License"></a>License</h2> +PortAudio Portable Real-Time Audio Library +<br>Copyright (c) 1999-2000 Ross Bencina and Phil Burk +<p>Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: +<ul> +<li> +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software.</li> + +<li> +Any person wishing to distribute modifications to the Software is requested +to send the modifications to the original developer so that they can be +incorporated into the canonical version.</li> +</ul> +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND ON INFRINGEMENT. +<br>IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT +OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR +THE USE OR OTHER DEALINGS IN THE SOFTWARE. +<br> +</body> +</html> diff --git a/pd/portaudio_v18/install-sh b/pd/portaudio_v18/install-sh new file mode 100644 index 00000000..e9de2384 --- /dev/null +++ b/pd/portaudio_v18/install-sh @@ -0,0 +1,251 @@ +#!/bin/sh +# +# install - install a program, script, or datafile +# This comes from X11R5 (mit/util/scripts/install.sh). +# +# Copyright 1991 by the Massachusetts Institute of Technology +# +# Permission to use, copy, modify, distribute, and sell this software and its +# documentation for any purpose is hereby granted without fee, provided that +# the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of M.I.T. not be used in advertising or +# publicity pertaining to distribution of the software without specific, +# written prior permission. M.I.T. makes no representations about the +# suitability of this software for any purpose. It is provided "as is" +# without express or implied warranty. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# `make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. It can only install one file at a time, a restriction +# shared with many OS's install programs. + + +# set DOITPROG to echo to test this script + +# Don't use :- since 4.3BSD and earlier shells don't like it. +doit="${DOITPROG-}" + + +# put in absolute paths if you don't have them in your path; or use env. vars. + +mvprog="${MVPROG-mv}" +cpprog="${CPPROG-cp}" +chmodprog="${CHMODPROG-chmod}" +chownprog="${CHOWNPROG-chown}" +chgrpprog="${CHGRPPROG-chgrp}" +stripprog="${STRIPPROG-strip}" +rmprog="${RMPROG-rm}" +mkdirprog="${MKDIRPROG-mkdir}" + +transformbasename="" +transform_arg="" +instcmd="$mvprog" +chmodcmd="$chmodprog 0755" +chowncmd="" +chgrpcmd="" +stripcmd="" +rmcmd="$rmprog -f" +mvcmd="$mvprog" +src="" +dst="" +dir_arg="" + +while [ x"$1" != x ]; do + case $1 in + -c) instcmd="$cpprog" + shift + continue;; + + -d) dir_arg=true + shift + continue;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + -s) stripcmd="$stripprog" + shift + continue;; + + -t=*) transformarg=`echo $1 | sed 's/-t=//'` + shift + continue;; + + -b=*) transformbasename=`echo $1 | sed 's/-b=//'` + shift + continue;; + + *) if [ x"$src" = x ] + then + src=$1 + else + # this colon is to work around a 386BSD /bin/sh bug + : + dst=$1 + fi + shift + continue;; + esac +done + +if [ x"$src" = x ] +then + echo "install: no input file specified" + exit 1 +else + true +fi + +if [ x"$dir_arg" != x ]; then + dst=$src + src="" + + if [ -d $dst ]; then + instcmd=: + chmodcmd="" + else + instcmd=mkdir + fi +else + +# Waiting for this to be detected by the "$instcmd $src $dsttmp" command +# might cause directories to be created, which would be especially bad +# if $src (and thus $dsttmp) contains '*'. + + if [ -f $src -o -d $src ] + then + true + else + echo "install: $src does not exist" + exit 1 + fi + + if [ x"$dst" = x ] + then + echo "install: no destination specified" + exit 1 + else + true + fi + +# If destination is a directory, append the input filename; if your system +# does not like double slashes in filenames, you may need to add some logic + + if [ -d $dst ] + then + dst="$dst"/`basename $src` + else + true + fi +fi + +## this sed command emulates the dirname command +dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + +# Make sure that the destination directory exists. +# this part is taken from Noah Friedman's mkinstalldirs script + +# Skip lots of stat calls in the usual case. +if [ ! -d "$dstdir" ]; then +defaultIFS=' +' +IFS="${IFS-${defaultIFS}}" + +oIFS="${IFS}" +# Some sh's can't handle IFS=/ for some reason. +IFS='%' +set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` +IFS="${oIFS}" + +pathcomp='' + +while [ $# -ne 0 ] ; do + pathcomp="${pathcomp}${1}" + shift + + if [ ! -d "${pathcomp}" ] ; + then + $mkdirprog "${pathcomp}" + else + true + fi + + pathcomp="${pathcomp}/" +done +fi + +if [ x"$dir_arg" != x ] +then + $doit $instcmd $dst && + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi +else + +# If we're going to rename the final executable, determine the name now. + + if [ x"$transformarg" = x ] + then + dstfile=`basename $dst` + else + dstfile=`basename $dst $transformbasename | + sed $transformarg`$transformbasename + fi + +# don't allow the sed command to completely eliminate the filename + + if [ x"$dstfile" = x ] + then + dstfile=`basename $dst` + else + true + fi + +# Make a temp file name in the proper directory. + + dsttmp=$dstdir/#inst.$$# + +# Move or copy the file name to the temp name + + $doit $instcmd $src $dsttmp && + + trap "rm -f ${dsttmp}" 0 && + +# and set any options; do chmod last to preserve setuid bits + +# If any of these fail, we abort the whole thing. If we want to +# ignore errors from any of these, just make sure not to ignore +# errors from the above "$doit $instcmd $src $dsttmp" command. + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && + +# Now rename the file to the real destination. + + $doit $rmcmd -f $dstdir/$dstfile && + $doit $mvcmd $dsttmp $dstdir/$dstfile + +fi && + + +exit 0 diff --git a/pd/portaudio_v18/pa_asio/Callback_adaptation_.pdf b/pd/portaudio_v18/pa_asio/Callback_adaptation_.pdf Binary files differnew file mode 100644 index 00000000..b1014959 --- /dev/null +++ b/pd/portaudio_v18/pa_asio/Callback_adaptation_.pdf diff --git a/pd/portaudio_v18/pa_asio/Pa_ASIO.pdf b/pd/portaudio_v18/pa_asio/Pa_ASIO.pdf Binary files differnew file mode 100644 index 00000000..1b5d668f --- /dev/null +++ b/pd/portaudio_v18/pa_asio/Pa_ASIO.pdf diff --git a/pd/portaudio_v18/pa_asio/pa_asio.cpp b/pd/portaudio_v18/pa_asio/pa_asio.cpp new file mode 100644 index 00000000..cec01134 --- /dev/null +++ b/pd/portaudio_v18/pa_asio/pa_asio.cpp @@ -0,0 +1,3084 @@ +/* + * $Id: pa_asio.cpp,v 1.7.4.5 2003/06/30 16:27:10 stephane Exp $ + * Portable Audio I/O Library for ASIO Drivers + * + * Author: Stephane Letz + * Based on the Open Source API proposed by Ross Bencina + * Copyright (c) 2000-2001 Stephane Letz, Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* Modification History + + 08-03-01 First version : Stephane Letz + 08-06-01 Tweaks for PC, use C++, buffer allocation, Float32 to Int32 conversion : Phil Burk + 08-20-01 More conversion, PA_StreamTime, Pa_GetHostError : Stephane Letz + 08-21-01 PaUInt8 bug correction, implementation of ASIOSTFloat32LSB and ASIOSTFloat32MSB native formats : Stephane Letz + 08-24-01 MAX_INT32_FP hack, another Uint8 fix : Stephane and Phil + 08-27-01 Implementation of hostBufferSize < userBufferSize case, better management of the ouput buffer when + the stream is stopped : Stephane Letz + 08-28-01 Check the stream pointer for null in bufferSwitchTimeInfo, correct bug in bufferSwitchTimeInfo when + the stream is stopped : Stephane Letz + 10-12-01 Correct the PaHost_CalcNumHostBuffers function: computes FramesPerHostBuffer to be the lowest that + respect requested FramesPerUserBuffer and userBuffersPerHostBuffer : Stephane Letz + 10-26-01 Management of hostBufferSize and userBufferSize of any size : Stephane Letz + 10-27-01 Improve calculus of hostBufferSize to be multiple or divisor of userBufferSize if possible : Stephane and Phil + 10-29-01 Change MAX_INT32_FP to (2147483520.0f) to prevent roundup to 0x80000000 : Phil Burk + 10-31-01 Clear the ouput buffer and user buffers in PaHost_StartOutput, correct bug in GetFirstMultiple : Stephane Letz + 11-06-01 Rename functions : Stephane Letz + 11-08-01 New Pa_ASIO_Adaptor_Init function to init Callback adpatation variables, cleanup of Pa_ASIO_Callback_Input: Stephane Letz + 11-29-01 Break apart device loading to debug random failure in Pa_ASIO_QueryDeviceInfo ; Phil Burk + 01-03-02 Desallocate all resources in PaHost_Term for cases where Pa_CloseStream is not called properly : Stephane Letz + 02-01-02 Cleanup, test of multiple-stream opening : Stephane Letz + 19-02-02 New Pa_ASIO_loadDriver that calls CoInitialize on each thread on Windows : Stephane Letz + 09-04-02 Correct error code management in PaHost_Term, removes various compiler warning : Stephane Letz + 12-04-02 Add Mac includes for <Devices.h> and <Timer.h> : Phil Burk + 13-04-02 Removes another compiler warning : Stephane Letz + 30-04-02 Pa_ASIO_QueryDeviceInfo bug correction, memory allocation checking, better error handling : D Viens, P Burk, S Letz + 01-12-02 Fix Pa_GetDefaultInputDeviceID and Pa_GetDefaultOuputDeviceID result when no driver are available : S Letz + 05-12-02 More debug messages : S Letz + 01-23-03 Increased max channels to 128. Fixed comparison of (OutputChannels > kMaxInputChannels) : P Burk + 02-17-03 Better termination handling : PaHost_CloseStream is called in PaHost_term is the the stream was not explicitely closed by the application : S Letz + 04-02-03 More robust ASIO driver buffer size initialization : some buggy drivers (like the Hoontech DSP24) give incorrect [min, preferred, max] values + They should work with the preferred size value, thus if Pa_ASIO_CreateBuffers fails with the hostBufferSize computed in PaHost_CalcNumHostBuffers, + we try again with the preferred size. Fix an old (never detected?) bug in the buffer adapdation code : S Letz + 30-06-03 The audio callback was not protected against reentrancy : some drivers (like the Hoontech DSP24) seems to cause this behaviour + that corrupted the buffer adapdation state and finally caused crashes. The reentrancy state is now checked in bufferSwitchTimeInfo : S Letz + + TO DO : + + - Check Pa_StopSteam and Pa_AbortStream + - Optimization for Input only or Ouput only (really necessary ??) +*/ + + +#include <stdio.h> +#include <assert.h> +#include <string.h> + +#include "portaudio.h" +#include "pa_host.h" +#include "pa_trace.h" + +#include "asiosys.h" +#include "asio.h" +#include "asiodrivers.h" + + +#if MAC +#include <Devices.h> +#include <Timer.h> +#include <Math64.h> +#else +#include <math.h> +#include <windows.h> +#include <mmsystem.h> +#endif + +enum { + // number of input and outputs supported by the host application + // you can change these to higher or lower values + kMaxInputChannels = 128, + kMaxOutputChannels = 128 +}; + +/* ASIO specific device information. */ +typedef struct internalPortAudioDevice +{ + PaDeviceInfo pad_Info; +} internalPortAudioDevice; + + +/* ASIO driver internal data storage */ +typedef struct PaHostSoundControl +{ + // ASIOInit() + ASIODriverInfo pahsc_driverInfo; + + // ASIOGetChannels() + int32 pahsc_NumInputChannels; + int32 pahsc_NumOutputChannels; + + // ASIOGetBufferSize() - sizes in frames per buffer + int32 pahsc_minSize; + int32 pahsc_maxSize; + int32 pahsc_preferredSize; + int32 pahsc_granularity; + + // ASIOGetSampleRate() + ASIOSampleRate pahsc_sampleRate; + + // ASIOOutputReady() + bool pahsc_postOutput; + + // ASIOGetLatencies () + int32 pahsc_inputLatency; + int32 pahsc_outputLatency; + + // ASIOCreateBuffers () + ASIOBufferInfo bufferInfos[kMaxInputChannels + kMaxOutputChannels]; // buffer info's + + // ASIOGetChannelInfo() + ASIOChannelInfo pahsc_channelInfos[kMaxInputChannels + kMaxOutputChannels]; // channel info's + // The above two arrays share the same indexing, as the data in them are linked together + + // Information from ASIOGetSamplePosition() + // data is converted to double floats for easier use, however 64 bit integer can be used, too + double nanoSeconds; + double samples; + double tcSamples; // time code samples + + // bufferSwitchTimeInfo() + ASIOTime tInfo; // time info state + unsigned long sysRefTime; // system reference time, when bufferSwitch() was called + + // Signal the end of processing in this example + bool stopped; + + ASIOCallbacks pahsc_asioCallbacks; + + + int32 pahsc_userInputBufferFrameOffset; // Position in Input user buffer + int32 pahsc_userOutputBufferFrameOffset; // Position in Output user buffer + int32 pahsc_hostOutputBufferFrameOffset; // Position in Output ASIO buffer + + int32 past_FramesPerHostBuffer; // Number of frames in ASIO buffer + + int32 pahsc_InputBufferOffset; // Number of null frames for input buffer alignement + int32 pahsc_OutputBufferOffset; // Number of null frames for ouput buffer alignement + +#if MAC + UInt64 pahsc_EntryCount; + UInt64 pahsc_LastExitCount; +#elif WINDOWS + LARGE_INTEGER pahsc_EntryCount; + LARGE_INTEGER pahsc_LastExitCount; +#endif + + PaTimestamp pahsc_NumFramesDone; + + internalPortAudioStream *past; + + int32 reenterCount; // Counter of audio callback reentrancy + int32 reenterError; // Counter of audio callback reentrancy detection + +} PaHostSoundControl; + + +//---------------------------------------------------------- +#define PRINT(x) { printf x; fflush(stdout); } +#define ERR_RPT(x) PRINT(x) + +#define DBUG(x) /* PRINT(x) */ +#define DBUGX(x) /* PRINT(x) */ + +/* We are trying to be compatible with CARBON but this has not been thoroughly tested. */ +#define CARBON_COMPATIBLE (0) +#define PA_MAX_DEVICE_INFO (32) + +#define MIN_INT8 (-0x80) +#define MAX_INT8 (0x7F) + +#define MIN_INT8_FP ((float)-0x80) +#define MAX_INT8_FP ((float)0x7F) + +#define MIN_INT16_FP ((float)-0x8000) +#define MAX_INT16_FP ((float)0x7FFF) + +#define MIN_INT16 (-0x8000) +#define MAX_INT16 (0x7FFF) + +#define MAX_INT32_FP (2147483520.0f) /* 0x0x7FFFFF80 - seems safe */ + +/************************************************************************************/ +/****************** Data ************************************************************/ +/************************************************************************************/ +static int sNumDevices = 0; +static internalPortAudioDevice sDevices[PA_MAX_DEVICE_INFO] = { 0 }; +static int32 sPaHostError = 0; +static int sDefaultOutputDeviceID = 0; +static int sDefaultInputDeviceID = 0; + +PaHostSoundControl asioDriverInfo = {0}; + +#ifdef MAC +static bool swap = true; +#elif WINDOWS +static bool swap = false; +#endif + +// Prototypes +static void bufferSwitch(long index, ASIOBool processNow); +static ASIOTime *bufferSwitchTimeInfo(ASIOTime *timeInfo, long index, ASIOBool processNow); +static void sampleRateChanged(ASIOSampleRate sRate); +static long asioMessages(long selector, long value, void* message, double* opt); +static void Pa_StartUsageCalculation( internalPortAudioStream *past ); +static void Pa_EndUsageCalculation( internalPortAudioStream *past ); + +static void Pa_ASIO_Convert_Inter_Input( + ASIOBufferInfo* nativeBuffer, + void* inputBuffer, + long NumInputChannels, + long NumOuputChannels, + long framePerBuffer, + long hostFrameOffset, + long userFrameOffset, + ASIOSampleType nativeFormat, + PaSampleFormat paFormat, + PaStreamFlags flags, + long index); + +static void Pa_ASIO_Convert_Inter_Output( + ASIOBufferInfo* nativeBuffer, + void* outputBuffer, + long NumInputChannels, + long NumOuputChannels, + long framePerBuffer, + long hostFrameOffset, + long userFrameOffset, + ASIOSampleType nativeFormat, + PaSampleFormat paFormat, + PaStreamFlags flags, + long index); + +static void Pa_ASIO_Clear_Output(ASIOBufferInfo* nativeBuffer, + ASIOSampleType nativeFormat, + long NumInputChannels, + long NumOuputChannels, + long index, + long hostFrameOffset, + long frames); + +static void Pa_ASIO_Callback_Input(long index); +static void Pa_ASIO_Callback_Output(long index, long framePerBuffer); +static void Pa_ASIO_Callback_End(); +static void Pa_ASIO_Clear_User_Buffers(); + +// Some external references +extern AsioDrivers* asioDrivers ; +bool loadAsioDriver(char *name); +unsigned long get_sys_reference_time(); + + +/************************************************************************************/ +/****************** Macro ************************************************************/ +/************************************************************************************/ + +#define SwapLong(v) ((((v)>>24)&0xFF)|(((v)>>8)&0xFF00)|(((v)&0xFF00)<<8)|(((v)&0xFF)<<24)) ; +#define SwapShort(v) ((((v)>>8)&0xFF)|(((v)&0xFF)<<8)) ; + +#define ClipShort(v) (((v)<MIN_INT16)?MIN_INT16:(((v)>MAX_INT16)?MAX_INT16:(v))) +#define ClipChar(v) (((v)<MIN_INT8)?MIN_INT8:(((v)>MAX_INT8)?MAX_INT8:(v))) +#define ClipFloat(v) (((v)<-1.0f)?-1.0f:(((v)>1.0f)?1.0f:(v))) + +#ifndef min +#define min(a,b) ((a)<(b)?(a):(b)) +#endif + +#ifndef max +#define max(a,b) ((a)>=(b)?(a):(b)) +#endif + + +static bool Pa_ASIO_loadAsioDriver(char *name) +{ + #ifdef WINDOWS + CoInitialize(0); + #endif + return loadAsioDriver(name); +} + + + +// Utilities for alignement buffer size computation +static int PGCD (int a, int b) {return (b == 0) ? a : PGCD (b,a%b);} +static int PPCM (int a, int b) {return (a*b) / PGCD (a,b);} + +// Takes the size of host buffer and user buffer : returns the number of frames needed for buffer adaptation +static int Pa_ASIO_CalcFrameShift (int M, int N) +{ + int res = 0; + for (int i = M; i < PPCM (M,N) ; i+=M) { res = max (res, i%N); } + return res; +} + +// We have the following relation : +// Pa_ASIO_CalcFrameShift (M,N) + M = Pa_ASIO_CalcFrameShift (N,M) + N + +/* ASIO sample type to PortAudio sample type conversion */ +static PaSampleFormat Pa_ASIO_Convert_SampleFormat(ASIOSampleType type) +{ + switch (type) { + + case ASIOSTInt16MSB: + case ASIOSTInt16LSB: + case ASIOSTInt32MSB16: + case ASIOSTInt32LSB16: + return paInt16; + + case ASIOSTFloat32MSB: + case ASIOSTFloat32LSB: + case ASIOSTFloat64MSB: + case ASIOSTFloat64LSB: + return paFloat32; + + case ASIOSTInt32MSB: + case ASIOSTInt32LSB: + case ASIOSTInt32MSB18: + case ASIOSTInt32MSB20: + case ASIOSTInt32MSB24: + case ASIOSTInt32LSB18: + case ASIOSTInt32LSB20: + case ASIOSTInt32LSB24: + return paInt32; + + case ASIOSTInt24MSB: + case ASIOSTInt24LSB: + return paInt24; + + default: + return paCustomFormat; + } +} + + + +//-------------------------------------------------------------------------------------------------------------------- +static void PaHost_CalcBufferOffset(internalPortAudioStream *past) +{ + if (asioDriverInfo.past_FramesPerHostBuffer > past->past_FramesPerUserBuffer){ + // Computes the MINIMUM value of null frames shift for the output buffer alignement + asioDriverInfo.pahsc_OutputBufferOffset = Pa_ASIO_CalcFrameShift (asioDriverInfo.past_FramesPerHostBuffer,past->past_FramesPerUserBuffer); + asioDriverInfo.pahsc_InputBufferOffset = 0; + DBUG(("PaHost_CalcBufferOffset : Minimum BufferOffset for Output = %d\n", asioDriverInfo.pahsc_OutputBufferOffset)); + }else{ + + //Computes the MINIMUM value of null frames shift for the input buffer alignement + asioDriverInfo.pahsc_InputBufferOffset = Pa_ASIO_CalcFrameShift (asioDriverInfo.past_FramesPerHostBuffer,past->past_FramesPerUserBuffer); + asioDriverInfo.pahsc_OutputBufferOffset = 0; + DBUG(("PaHost_CalcBufferOffset : Minimum BufferOffset for Input = %d\n", asioDriverInfo.pahsc_InputBufferOffset)); + } +} + +//-------------------------------------------------------------------------------------------------------------------- +/* Allocate ASIO buffers, initialise channels */ +static ASIOError Pa_ASIO_CreateBuffers (PaHostSoundControl *asioDriverInfo, long InputChannels, + long OutputChannels, long framesPerBuffer) +{ + ASIOError err; + int i; + + ASIOBufferInfo *info = asioDriverInfo->bufferInfos; + + // Check parameters + if ((InputChannels > kMaxInputChannels) || (OutputChannels > kMaxOutputChannels)) return ASE_InvalidParameter; + + for(i = 0; i < InputChannels; i++, info++){ + info->isInput = ASIOTrue; + info->channelNum = i; + info->buffers[0] = info->buffers[1] = 0; + } + + for(i = 0; i < OutputChannels; i++, info++){ + info->isInput = ASIOFalse; + info->channelNum = i; + info->buffers[0] = info->buffers[1] = 0; + } + + // Set up the asioCallback structure and create the ASIO data buffer + asioDriverInfo->pahsc_asioCallbacks.bufferSwitch = &bufferSwitch; + asioDriverInfo->pahsc_asioCallbacks.sampleRateDidChange = &sampleRateChanged; + asioDriverInfo->pahsc_asioCallbacks.asioMessage = &asioMessages; + asioDriverInfo->pahsc_asioCallbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfo; + + DBUG(("Pa_ASIO_CreateBuffers : ASIOCreateBuffers with inputChannels = %ld \n", InputChannels)); + DBUG(("Pa_ASIO_CreateBuffers : ASIOCreateBuffers with OutputChannels = %ld \n", OutputChannels)); + DBUG(("Pa_ASIO_CreateBuffers : ASIOCreateBuffers with size = %ld \n", framesPerBuffer)); + + err = ASIOCreateBuffers( asioDriverInfo->bufferInfos, InputChannels+OutputChannels, + framesPerBuffer, &asioDriverInfo->pahsc_asioCallbacks); + if (err != ASE_OK) return err; + + // Initialise buffers + for (i = 0; i < InputChannels + OutputChannels; i++) + { + asioDriverInfo->pahsc_channelInfos[i].channel = asioDriverInfo->bufferInfos[i].channelNum; + asioDriverInfo->pahsc_channelInfos[i].isInput = asioDriverInfo->bufferInfos[i].isInput; + err = ASIOGetChannelInfo(&asioDriverInfo->pahsc_channelInfos[i]); + if (err != ASE_OK) break; + } + + err = ASIOGetLatencies(&asioDriverInfo->pahsc_inputLatency, &asioDriverInfo->pahsc_outputLatency); + + DBUG(("Pa_ASIO_CreateBuffers : InputLatency = %ld latency = %ld msec \n", + asioDriverInfo->pahsc_inputLatency, + (long)((asioDriverInfo->pahsc_inputLatency*1000)/ asioDriverInfo->past->past_SampleRate))); + DBUG(("Pa_ASIO_CreateBuffers : OuputLatency = %ld latency = %ld msec \n", + asioDriverInfo->pahsc_outputLatency, + (long)((asioDriverInfo->pahsc_outputLatency*1000)/ asioDriverInfo->past->past_SampleRate))); + + return err; +} + + +/* + Query ASIO driver info : + + First we get all available ASIO drivers located in the ASIO folder, + then try to load each one. For each loaded driver, get all needed informations. +*/ +static PaError Pa_ASIO_QueryDeviceInfo( internalPortAudioDevice * ipad ) +{ + +#define NUM_STANDARDSAMPLINGRATES 3 /* 11.025, 22.05, 44.1 */ +#define NUM_CUSTOMSAMPLINGRATES 9 /* must be the same number of elements as in the array below */ +#define MAX_NUMSAMPLINGRATES (NUM_STANDARDSAMPLINGRATES+NUM_CUSTOMSAMPLINGRATES) + + ASIOSampleRate possibleSampleRates[] + = {8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0, 44100.0, 48000.0, 88200.0, 96000.0}; + + ASIOChannelInfo channelInfos; + long InputChannels,OutputChannels; + double *sampleRates; + char* names[PA_MAX_DEVICE_INFO] ; + PaDeviceInfo *dev; + int i; + int numDrivers; + ASIOError asioError; + + /* Allocate names */ + for (i = 0 ; i < PA_MAX_DEVICE_INFO ; i++) { + names[i] = (char*)PaHost_AllocateFastMemory(32); + /* check memory */ + if(!names[i]) return paInsufficientMemory; + } + + /* MUST BE CHECKED : to force fragments loading on Mac */ + Pa_ASIO_loadAsioDriver("dummy"); + + /* Get names of all available ASIO drivers */ + asioDrivers->getDriverNames(names,PA_MAX_DEVICE_INFO); + + /* Check all available ASIO drivers */ +#if MAC + numDrivers = asioDrivers->getNumFragments(); +#elif WINDOWS + numDrivers = asioDrivers->asioGetNumDev(); +#endif + + DBUG(("PaASIO_QueryDeviceInfo: number of installed drivers = %d\n", numDrivers )); + + for (int driver = 0 ; driver < numDrivers ; driver++) + { + + #if WINDOWS + asioDriverInfo.pahsc_driverInfo.asioVersion = 2; // FIXME - is this right? PLB + asioDriverInfo.pahsc_driverInfo.sysRef = GetDesktopWindow(); // FIXME - is this right? PLB + #endif + + DBUG(("---------------------------------------\n")); + + DBUG(("PaASIO_QueryDeviceInfo: Driver name = %s\n", names[driver])); + + /* If the driver can be loaded : */ + if ( !Pa_ASIO_loadAsioDriver(names[driver]) ){ + DBUG(("PaASIO_QueryDeviceInfo could not loadAsioDriver %s\n", names[driver])); + } else { + + DBUG(("PaASIO_QueryDeviceInfo: loadAsioDriver OK\n")); + + if((asioError = ASIOInit(&asioDriverInfo.pahsc_driverInfo)) != ASE_OK){ + + DBUG(("PaASIO_QueryDeviceInfo: ASIOInit returned %d for %s\n", asioError, names[driver])); + + }else { + + DBUG(("PaASIO_QueryDeviceInfo: ASIOInit OK \n")); + + if(ASIOGetChannels(&InputChannels, &OutputChannels) != ASE_OK){ + + DBUG(("PaASIO_QueryDeviceInfo could not ASIOGetChannels for %s\n", names[driver])); + + }else { + + DBUG(("PaASIO_QueryDeviceInfo: ASIOGetChannels OK \n")); + + /* Gets the name */ + dev = &(ipad[sNumDevices].pad_Info); + dev->name = names[driver]; + names[driver] = 0; + + /* Gets Input and Output channels number */ + dev->maxInputChannels = InputChannels; + dev->maxOutputChannels = OutputChannels; + + DBUG(("PaASIO_QueryDeviceInfo: InputChannels = %d\n", InputChannels )); + DBUG(("PaASIO_QueryDeviceInfo: OutputChannels = %d\n", OutputChannels )); + + /* Make room in case device supports all rates. */ + sampleRates = (double*)PaHost_AllocateFastMemory(MAX_NUMSAMPLINGRATES * sizeof(double)); + /* check memory */ + if (!sampleRates) { + ASIOExit(); + return paInsufficientMemory; + } + dev->sampleRates = sampleRates; + dev->numSampleRates = 0; + + /* Loop through the possible sampling rates and check each to see if the device supports it. */ + for (int index = 0; index < MAX_NUMSAMPLINGRATES; index++) { + if (ASIOCanSampleRate(possibleSampleRates[index]) != ASE_NoClock) { + DBUG(("PaASIO_QueryDeviceInfo: possible sample rate = %d\n", (long)possibleSampleRates[index])); + dev->numSampleRates += 1; + *sampleRates = possibleSampleRates[index]; + sampleRates++; + } + } + + /* We assume that all channels have the same SampleType, so check the first */ + channelInfos.channel = 0; + channelInfos.isInput = 1; + + if ((asioError = ASIOGetChannelInfo(&channelInfos)) == ASE_NotPresent) { + DBUG(("PaASIO_QueryDeviceInfo: ASIOGetChannelInfo returned %d \n",asioError)); + } + + dev->nativeSampleFormats = Pa_ASIO_Convert_SampleFormat(channelInfos.type); + + /* unload the driver */ + if ((asioError = ASIOExit()) != ASE_OK) { + DBUG(("PaASIO_QueryDeviceInfo: ASIOExit returned %d \n",asioError)); + } + + sNumDevices++; + } + + } + } + } + + /* free only unused names */ + for (i = 0 ; i < PA_MAX_DEVICE_INFO ; i++) if (names[i]) PaHost_FreeFastMemory(names[i],32); + + return paNoError; +} + +//---------------------------------------------------------------------------------- +// TAKEN FROM THE ASIO SDK: +void sampleRateChanged(ASIOSampleRate sRate) +{ + // do whatever you need to do if the sample rate changed + // usually this only happens during external sync. + // Audio processing is not stopped by the driver, actual sample rate + // might not have even changed, maybe only the sample rate status of an + // AES/EBU or S/PDIF digital input at the audio device. + // You might have to update time/sample related conversion routines, etc. +} + +//---------------------------------------------------------------------------------- +// TAKEN FROM THE ASIO SDK: +long asioMessages(long selector, long value, void* message, double* opt) +{ + // currently the parameters "value", "message" and "opt" are not used. + long ret = 0; + switch(selector) + { + case kAsioSelectorSupported: + if(value == kAsioResetRequest + || value == kAsioEngineVersion + || value == kAsioResyncRequest + || value == kAsioLatenciesChanged + // the following three were added for ASIO 2.0, you don't necessarily have to support them + || value == kAsioSupportsTimeInfo + || value == kAsioSupportsTimeCode + || value == kAsioSupportsInputMonitor) + ret = 1L; + break; + + case kAsioBufferSizeChange: + //printf("kAsioBufferSizeChange \n"); + break; + + case kAsioResetRequest: + // defer the task and perform the reset of the driver during the next "safe" situation + // You cannot reset the driver right now, as this code is called from the driver. + // Reset the driver is done by completely destruct is. I.e. ASIOStop(), ASIODisposeBuffers(), Destruction + // Afterwards you initialize the driver again. + asioDriverInfo.stopped; // In this sample the processing will just stop + ret = 1L; + break; + case kAsioResyncRequest: + // This informs the application, that the driver encountered some non fatal data loss. + // It is used for synchronization purposes of different media. + // Added mainly to work around the Win16Mutex problems in Windows 95/98 with the + // Windows Multimedia system, which could loose data because the Mutex was hold too long + // by another thread. + // However a driver can issue it in other situations, too. + ret = 1L; + break; + case kAsioLatenciesChanged: + // This will inform the host application that the drivers were latencies changed. + // Beware, it this does not mean that the buffer sizes have changed! + // You might need to update internal delay data. + ret = 1L; + //printf("kAsioLatenciesChanged \n"); + break; + case kAsioEngineVersion: + // return the supported ASIO version of the host application + // If a host applications does not implement this selector, ASIO 1.0 is assumed + // by the driver + ret = 2L; + break; + case kAsioSupportsTimeInfo: + // informs the driver wether the asioCallbacks.bufferSwitchTimeInfo() callback + // is supported. + // For compatibility with ASIO 1.0 drivers the host application should always support + // the "old" bufferSwitch method, too. + ret = 1; + break; + case kAsioSupportsTimeCode: + // informs the driver wether application is interested in time code info. + // If an application does not need to know about time code, the driver has less work + // to do. + ret = 0; + break; + } + return ret; +} + + +//---------------------------------------------------------------------------------- +// conversion from 64 bit ASIOSample/ASIOTimeStamp to double float +#if NATIVE_INT64 + #define ASIO64toDouble(a) (a) +#else + const double twoRaisedTo32 = 4294967296.; + #define ASIO64toDouble(a) ((a).lo + (a).hi * twoRaisedTo32) +#endif + + +static ASIOTime *bufferSwitchTimeInfo(ASIOTime *timeInfo, long index, ASIOBool processNow) +{ + // the actual processing callback. + // Beware that this is normally in a seperate thread, hence be sure that you take care + // about thread synchronization. This is omitted here for simplicity. + + // store the timeInfo for later use + asioDriverInfo.tInfo = *timeInfo; + + // get the time stamp of the buffer, not necessary if no + // synchronization to other media is required + + if (timeInfo->timeInfo.flags & kSystemTimeValid) + asioDriverInfo.nanoSeconds = ASIO64toDouble(timeInfo->timeInfo.systemTime); + else + asioDriverInfo.nanoSeconds = 0; + + if (timeInfo->timeInfo.flags & kSamplePositionValid) + asioDriverInfo.samples = ASIO64toDouble(timeInfo->timeInfo.samplePosition); + else + asioDriverInfo.samples = 0; + + if (timeInfo->timeCode.flags & kTcValid) + asioDriverInfo.tcSamples = ASIO64toDouble(timeInfo->timeCode.timeCodeSamples); + else + asioDriverInfo.tcSamples = 0; + + // get the system reference time + asioDriverInfo.sysRefTime = get_sys_reference_time(); + +#if 0 + // a few debug messages for the Windows device driver developer + // tells you the time when driver got its interrupt and the delay until the app receives + // the event notification. + static double last_samples = 0; + char tmp[128]; + sprintf (tmp, "diff: %d / %d ms / %d ms / %d samples \n", asioDriverInfo.sysRefTime - (long)(asioDriverInfo.nanoSeconds / 1000000.0), asioDriverInfo.sysRefTime, (long)(asioDriverInfo.nanoSeconds / 1000000.0), (long)(asioDriverInfo.samples - last_samples)); + OutputDebugString (tmp); + last_samples = asioDriverInfo.samples; +#endif + + // To avoid the callback accessing a desallocated stream + if (asioDriverInfo.past == NULL) return 0L; + + // Keep sample position + asioDriverInfo.pahsc_NumFramesDone = timeInfo->timeInfo.samplePosition.lo; + + // Reentrancy control + if( ++asioDriverInfo.reenterCount) { + asioDriverInfo.reenterError++; + DBUG(("bufferSwitchTimeInfo : reentrancy detection = %d\n", asioDriverInfo.reenterError)); + return 0L; + } + + do { + + /* Has a user callback returned '1' to indicate finished at the last ASIO callback? */ + if( asioDriverInfo.past->past_StopSoon ) { + + Pa_ASIO_Clear_Output(asioDriverInfo.bufferInfos, + asioDriverInfo.pahsc_channelInfos[0].type, + asioDriverInfo.pahsc_NumInputChannels , + asioDriverInfo.pahsc_NumOutputChannels, + index, + 0, + asioDriverInfo.past_FramesPerHostBuffer); + + asioDriverInfo.past->past_IsActive = 0; + + // Finally if the driver supports the ASIOOutputReady() optimization, do it here, all data are in place + if (asioDriverInfo.pahsc_postOutput) ASIOOutputReady(); + + }else { + + /* CPU usage */ + Pa_StartUsageCalculation(asioDriverInfo.past); + + Pa_ASIO_Callback_Input(index); + + // Finally if the driver supports the ASIOOutputReady() optimization, do it here, all data are in place + if (asioDriverInfo.pahsc_postOutput) ASIOOutputReady(); + + Pa_ASIO_Callback_End(); + + /* CPU usage */ + Pa_EndUsageCalculation(asioDriverInfo.past); + } + + } while(asioDriverInfo.reenterCount--); + + return 0L; +} + + +//---------------------------------------------------------------------------------- +void bufferSwitch(long index, ASIOBool processNow) +{ + // the actual processing callback. + // Beware that this is normally in a seperate thread, hence be sure that you take care + // about thread synchronization. This is omitted here for simplicity. + + // as this is a "back door" into the bufferSwitchTimeInfo a timeInfo needs to be created + // though it will only set the timeInfo.samplePosition and timeInfo.systemTime fields and the according flags + + ASIOTime timeInfo; + memset (&timeInfo, 0, sizeof (timeInfo)); + + // get the time stamp of the buffer, not necessary if no + // synchronization to other media is required + if(ASIOGetSamplePosition(&timeInfo.timeInfo.samplePosition, &timeInfo.timeInfo.systemTime) == ASE_OK) + timeInfo.timeInfo.flags = kSystemTimeValid | kSamplePositionValid; + + // Call the real callback + bufferSwitchTimeInfo (&timeInfo, index, processNow); +} + +//---------------------------------------------------------------------------------- +unsigned long get_sys_reference_time() +{ + // get the system reference time + #if WINDOWS + return timeGetTime(); + #elif MAC + static const double twoRaisedTo32 = 4294967296.; + UnsignedWide ys; + Microseconds(&ys); + double r = ((double)ys.hi * twoRaisedTo32 + (double)ys.lo); + return (unsigned long)(r / 1000.); + #endif +} + + +/************************************************************* +** Calculate 2 LSB dither signal with a triangular distribution. +** Ranged properly for adding to a 32 bit integer prior to >>15. +*/ +#define DITHER_BITS (15) +#define DITHER_SCALE (1.0f / ((1<<DITHER_BITS)-1)) +inline static long Pa_TriangularDither( void ) +{ + static unsigned long previous = 0; + static unsigned long randSeed1 = 22222; + static unsigned long randSeed2 = 5555555; + long current, highPass; +/* Generate two random numbers. */ + randSeed1 = (randSeed1 * 196314165) + 907633515; + randSeed2 = (randSeed2 * 196314165) + 907633515; +/* Generate triangular distribution about 0. */ + current = (((long)randSeed1)>>(32-DITHER_BITS)) + (((long)randSeed2)>>(32-DITHER_BITS)); + /* High pass filter to reduce audibility. */ + highPass = current - previous; + previous = current; + return highPass; +} + +// TO BE COMPLETED WITH ALL SUPPORTED PA SAMPLE TYPES + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Input_Int16_Float32 (ASIOBufferInfo* nativeBuffer, float *inBufPtr, int framePerBuffer, int NumInputChannels, int index, int hostFrameOffset,int userFrameOffset, bool swap) +{ + long temp; + int i,j; + + for( j=0; j<NumInputChannels; j++ ) { + short *asioBufPtr = &((short*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + float *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapShort(temp); + *userBufPtr = (1.0f / MAX_INT16_FP) * temp; + userBufPtr += NumInputChannels; + } + } + +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Input_Int32_Float32 (ASIOBufferInfo* nativeBuffer, float *inBufPtr, int framePerBuffer, int NumInputChannels, int index, int hostFrameOffset,int userFrameOffset,bool swap) +{ + long temp; + int i,j; + + for( j=0; j<NumInputChannels; j++ ) { + long *asioBufPtr = &((long*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + float *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapLong(temp); + *userBufPtr = (1.0f / MAX_INT32_FP) * temp; + userBufPtr += NumInputChannels; + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +// MUST BE TESTED +static void Input_Float32_Float32 (ASIOBufferInfo* nativeBuffer, float *inBufPtr, int framePerBuffer, int NumInputChannels, int index, int hostFrameOffset,int userFrameOffset,bool swap) +{ + unsigned long temp; + int i,j; + + for( j=0; j<NumInputChannels; j++ ) { + unsigned long *asioBufPtr = &((unsigned long*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + float *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapLong(temp); + *userBufPtr = (float)temp; + userBufPtr += NumInputChannels; + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Input_Int16_Int32 (ASIOBufferInfo* nativeBuffer, long *inBufPtr, int framePerBuffer, int NumInputChannels, int index, int hostFrameOffset,int userFrameOffset,bool swap) +{ + long temp; + int i,j; + + for( j=0; j<NumInputChannels; j++ ) { + short *asioBufPtr = &((short*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + long *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapShort(temp); + *userBufPtr = temp<<16; + userBufPtr += NumInputChannels; + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Input_Int32_Int32 (ASIOBufferInfo* nativeBuffer, long *inBufPtr, int framePerBuffer, int NumInputChannels, int index, int hostFrameOffset,int userFrameOffset,bool swap) +{ + long temp; + int i,j; + + for( j=0; j<NumInputChannels; j++ ) { + long *asioBufPtr = &((long*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + long *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapLong(temp); + *userBufPtr = temp; + userBufPtr += NumInputChannels; + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +// MUST BE TESTED +static void Input_Float32_Int32 (ASIOBufferInfo* nativeBuffer, long *inBufPtr, int framePerBuffer, int NumInputChannels, int index, int hostFrameOffset,int userFrameOffset,bool swap) +{ + unsigned long temp; + int i,j; + + for( j=0; j<NumInputChannels; j++ ) { + unsigned long *asioBufPtr = &((unsigned long*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + long *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapLong(temp); + *userBufPtr = (long)((float)temp * MAX_INT32_FP); // Is temp a value between -1.0 and 1.0 ?? + userBufPtr += NumInputChannels; + } + } +} + + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Input_Int16_Int16 (ASIOBufferInfo* nativeBuffer, short *inBufPtr, int framePerBuffer, int NumInputChannels, int index, int hostFrameOffset,int userFrameOffset,bool swap) +{ + long temp; + int i,j; + + for( j=0; j<NumInputChannels; j++ ) { + short *asioBufPtr = &((short*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + short *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapShort(temp); + *userBufPtr = (short)temp; + userBufPtr += NumInputChannels; + } + } +} + + //------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Input_Int32_Int16 (ASIOBufferInfo* nativeBuffer, short *inBufPtr, int framePerBuffer, int NumInputChannels, int index, int hostFrameOffset, int userFrameOffset,uint32 flags,bool swap) +{ + long temp; + int i,j; + + if( flags & paDitherOff ) + { + for( j=0; j<NumInputChannels; j++ ) { + long *asioBufPtr = &((long*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + short *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapLong(temp); + *userBufPtr = (short)(temp>>16); + userBufPtr += NumInputChannels; + } + } + } + else + { + for( j=0; j<NumInputChannels; j++ ) { + long *asioBufPtr = &((long*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + short *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapLong(temp); + temp = (temp >> 1) + Pa_TriangularDither(); + temp = temp >> 15; + temp = (short) ClipShort(temp); + *userBufPtr = (short)temp; + userBufPtr += NumInputChannels; + } + } + + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +// MUST BE TESTED +static void Input_Float32_Int16 (ASIOBufferInfo* nativeBuffer, short *inBufPtr, int framePerBuffer, int NumInputChannels, int index, int hostFrameOffset,int userFrameOffset,uint32 flags,bool swap) +{ + unsigned long temp; + int i,j; + + if( flags & paDitherOff ) + { + for( j=0; j<NumInputChannels; j++ ) { + unsigned long *asioBufPtr = &((unsigned long*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + short *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapLong(temp); + *userBufPtr = (short)((float)temp * MAX_INT16_FP); // Is temp a value between -1.0 and 1.0 ?? + userBufPtr += NumInputChannels; + } + } + } + else + { + for( j=0; j<NumInputChannels; j++ ) { + unsigned long *asioBufPtr = &((unsigned long*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + short *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + float dither = Pa_TriangularDither()*DITHER_SCALE; + temp = asioBufPtr[i]; + if (swap) temp = SwapLong(temp); + temp = (short)(((float)temp * MAX_INT16_FP) + dither); + temp = ClipShort(temp); + *userBufPtr = (short)temp; + userBufPtr += NumInputChannels; + } + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Input_Int16_Int8 (ASIOBufferInfo* nativeBuffer, char *inBufPtr, int framePerBuffer, int NumInputChannels, int index, int hostFrameOffset,int userFrameOffset, uint32 flags,bool swap) +{ + long temp; + int i,j; + + if( flags & paDitherOff ) + { + for( j=0; j<NumInputChannels; j++ ) { + short *asioBufPtr = &((short*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + char *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapShort(temp); + *userBufPtr = (char)(temp>>8); + userBufPtr += NumInputChannels; + } + } + } + else + { + for( j=0; j<NumInputChannels; j++ ) { + short *asioBufPtr = &((short*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + char *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapShort(temp); + temp += Pa_TriangularDither() >> 8; + temp = ClipShort(temp); + *userBufPtr = (char)(temp>>8); + userBufPtr += NumInputChannels; + } + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Input_Int32_Int8 (ASIOBufferInfo* nativeBuffer, char *inBufPtr, int framePerBuffer, int NumInputChannels, int index, int hostFrameOffset, int userFrameOffset, uint32 flags,bool swap) +{ + long temp; + int i,j; + + if( flags & paDitherOff ) + { + for( j=0; j<NumInputChannels; j++ ) { + long *asioBufPtr = &((long*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + char *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapLong(temp); + *userBufPtr = (char)(temp>>24); + userBufPtr += NumInputChannels; + } + } + } + else + { + for( j=0; j<NumInputChannels; j++ ) { + long *asioBufPtr = &((long*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + char *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapLong(temp); + temp = temp>>16; // Shift to get a 16 bit value, then use the 16 bits to 8 bits code (MUST BE CHECHED) + temp += Pa_TriangularDither() >> 8; + temp = ClipShort(temp); + *userBufPtr = (char)(temp >> 8); + userBufPtr += NumInputChannels; + } + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +// MUST BE TESTED + +static void Input_Float32_Int8 (ASIOBufferInfo* nativeBuffer, char *inBufPtr, int framePerBuffer, int NumInputChannels, int index, int hostFrameOffset,int userFrameOffset, uint32 flags,bool swap) +{ + unsigned long temp; + int i,j; + + if( flags & paDitherOff ) + { + for( j=0; j<NumInputChannels; j++ ) { + unsigned long *asioBufPtr = &((unsigned long*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + char *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapLong(temp); + *userBufPtr = (char)((float)temp*MAX_INT8_FP); // Is temp a value between -1.0 and 1.0 ?? + userBufPtr += NumInputChannels; + } + } + } + else + { + for( j=0; j<NumInputChannels; j++ ) { + unsigned long *asioBufPtr = &((unsigned long*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + char *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + float dither = Pa_TriangularDither()*DITHER_SCALE; + temp = asioBufPtr[i]; + if (swap) temp = SwapLong(temp); + temp = (char)(((float)temp * MAX_INT8_FP) + dither); + temp = ClipChar(temp); + *userBufPtr = (char)temp; + userBufPtr += NumInputChannels; + } + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Input_Int16_IntU8 (ASIOBufferInfo* nativeBuffer, unsigned char *inBufPtr, int framePerBuffer, int NumInputChannels, int index, int hostFrameOffset,int userFrameOffset, uint32 flags,bool swap) +{ + long temp; + int i,j; + + if( flags & paDitherOff ) + { + for( j=0; j<NumInputChannels; j++ ) { + short *asioBufPtr = &((short*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + unsigned char *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapShort(temp); + *userBufPtr = (unsigned char)((temp>>8) + 0x80); + userBufPtr += NumInputChannels; + } + } + } + else + { + for( j=0; j<NumInputChannels; j++ ) { + short *asioBufPtr = &((short*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + unsigned char *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapShort(temp); + temp += Pa_TriangularDither() >> 8; + temp = ClipShort(temp); + *userBufPtr = (unsigned char)((temp>>8) + 0x80); + userBufPtr += NumInputChannels; + } + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Input_Int32_IntU8 (ASIOBufferInfo* nativeBuffer, unsigned char *inBufPtr, int framePerBuffer, int NumInputChannels, int index, int hostFrameOffset, int userFrameOffset,uint32 flags,bool swap) +{ + long temp; + int i,j; + + if( flags & paDitherOff ) + { + for( j=0; j<NumInputChannels; j++ ) { + long *asioBufPtr = &((long*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + unsigned char *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapLong(temp); + *userBufPtr = (unsigned char)((temp>>24) + 0x80); + userBufPtr += NumInputChannels; + } + } + } + else + { + for( j=0; j<NumInputChannels; j++ ) { + long *asioBufPtr = &((long*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + unsigned char *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapLong(temp); + temp = temp>>16; // Shift to get a 16 bit value, then use the 16 bits to 8 bits code (MUST BE CHECHED) + temp += Pa_TriangularDither() >> 8; + temp = ClipShort(temp); + *userBufPtr = (unsigned char)((temp>>8) + 0x80); + userBufPtr += NumInputChannels; + } + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +// MUST BE TESTED + +static void Input_Float32_IntU8 (ASIOBufferInfo* nativeBuffer, unsigned char *inBufPtr, int framePerBuffer, int NumInputChannels, int index, int hostFrameOffset,int userFrameOffset, uint32 flags,bool swap) +{ + unsigned long temp; + int i,j; + + if( flags & paDitherOff ) + { + for( j=0; j<NumInputChannels; j++ ) { + unsigned long *asioBufPtr = &((unsigned long*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + unsigned char *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + temp = asioBufPtr[i]; + if (swap) temp = SwapLong(temp); + *userBufPtr = (unsigned char)(((float)temp*MAX_INT8_FP) + 0x80); + userBufPtr += NumInputChannels; + } + } + } + else + { + for( j=0; j<NumInputChannels; j++ ) { + unsigned long *asioBufPtr = &((unsigned long*)nativeBuffer[j].buffers[index])[hostFrameOffset]; + unsigned char *userBufPtr = &inBufPtr[j+(userFrameOffset*NumInputChannels)]; + for (i= 0; i < framePerBuffer; i++) + { + float dither = Pa_TriangularDither()*DITHER_SCALE; + temp = asioBufPtr[i]; + if (swap) temp = SwapLong(temp); + temp = (char)(((float)temp * MAX_INT8_FP) + dither); + temp = ClipChar(temp); + *userBufPtr = (unsigned char)(temp + 0x80); + userBufPtr += NumInputChannels; + } + } + } +} + + +// OUPUT +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Output_Float32_Int16 (ASIOBufferInfo* nativeBuffer, float *outBufPtr, int framePerBuffer, int NumInputChannels, int NumOuputChannels, int index, int hostFrameOffset, int userFrameOffset,uint32 flags, bool swap) +{ + long temp; + int i,j; + + if( flags & paDitherOff ) + { + if( flags & paClipOff ) /* NOTHING */ + { + for( j=0; j<NumOuputChannels; j++ ) { + short *asioBufPtr = &((short*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + float *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + + for (i= 0; i < framePerBuffer; i++) + { + temp = (short) (*userBufPtr * MAX_INT16_FP); + if (swap) temp = SwapShort(temp); + asioBufPtr[i] = (short)temp; + userBufPtr += NumOuputChannels; + } + } + } + else /* CLIP */ + { + for( j=0; j<NumOuputChannels; j++ ) { + short *asioBufPtr = &((short*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + float *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + + for (i= 0; i < framePerBuffer; i++) + { + temp = (long) (*userBufPtr * MAX_INT16_FP); + temp = ClipShort(temp); + if (swap) temp = SwapShort(temp); + asioBufPtr[i] = (short)temp; + userBufPtr += NumOuputChannels; + } + } + } + } + else + { + /* If you dither then you have to clip because dithering could push the signal out of range! */ + for( j=0; j<NumOuputChannels; j++ ) { + short *asioBufPtr = &((short*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + float *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + + for (i= 0; i < framePerBuffer; i++) + { + float dither = Pa_TriangularDither()*DITHER_SCALE; + temp = (long) ((*userBufPtr * MAX_INT16_FP) + dither); + temp = ClipShort(temp); + if (swap) temp = SwapShort(temp); + asioBufPtr[i] = (short)temp; + userBufPtr += NumOuputChannels; + } + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Output_Float32_Int32 (ASIOBufferInfo* nativeBuffer, float *outBufPtr, int framePerBuffer, int NumInputChannels, int NumOuputChannels, int index, int hostFrameOffset, int userFrameOffset,uint32 flags,bool swap) +{ + long temp; + int i,j; + + if( flags & paClipOff ) + { + for (j= 0; j < NumOuputChannels; j++) + { + long *asioBufPtr = &((long*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + float *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + for( i=0; i<framePerBuffer; i++ ) + { + temp = (long) (*userBufPtr * MAX_INT32_FP); + if (swap) temp = SwapLong(temp); + asioBufPtr[i] = temp; + userBufPtr += NumOuputChannels; + } + } + } + else // CLIP * + { + for (j= 0; j < NumOuputChannels; j++) + { + long *asioBufPtr = &((long*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + float *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + for( i=0; i<framePerBuffer; i++ ) + { + float temp1 = *userBufPtr; + temp1 = ClipFloat(temp1); + temp = (long) (temp1*MAX_INT32_FP); + if (swap) temp = SwapLong(temp); + asioBufPtr[i] = temp; + userBufPtr += NumOuputChannels; + } + } + } + +} + + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +// MUST BE TESTED + + static void Output_Float32_Float32 (ASIOBufferInfo* nativeBuffer, float *outBufPtr, int framePerBuffer, int NumInputChannels, int NumOuputChannels, int index, int hostFrameOffset, int userFrameOffset,uint32 flags,bool swap) +{ + long temp; + int i,j; + + if( flags & paClipOff ) + { + for (j= 0; j < NumOuputChannels; j++) + { + float *asioBufPtr = &((float*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + float *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + for( i=0; i<framePerBuffer; i++ ) + { + temp = (long) *userBufPtr; + if (swap) temp = SwapLong(temp); + asioBufPtr[i] = (float)temp; + userBufPtr += NumOuputChannels; + } + } + + } + else /* CLIP */ + { + for (j= 0; j < NumOuputChannels; j++) + { + float *asioBufPtr = &((float*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + float *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + for( i=0; i<framePerBuffer; i++ ) + { + float temp1 = *userBufPtr; + temp1 = ClipFloat(temp1); // Is is necessary?? + temp = (long) temp1; + if (swap) temp = SwapLong(temp); + asioBufPtr[i] = (float)temp; + userBufPtr += NumOuputChannels; + } + } + } + +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Output_Int32_Int16(ASIOBufferInfo* nativeBuffer, long *outBufPtr, int framePerBuffer, int NumInputChannels, int NumOuputChannels, int index, int hostFrameOffset,int userFrameOffset,uint32 flags,bool swap) +{ + long temp; + int i,j; + + if( flags & paDitherOff ) + { + for (j= 0; j < NumOuputChannels; j++) + { + short *asioBufPtr = &((short*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + long *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + for( i=0; i<framePerBuffer; i++ ) + { + temp = (short) ((*userBufPtr) >> 16); + if (swap) temp = SwapShort(temp); + asioBufPtr[i] = (short)temp; + userBufPtr += NumOuputChannels; + } + } + } + else + { + for (j= 0; j < NumOuputChannels; j++) + { + short *asioBufPtr = &((short*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + long *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + for( i=0; i<framePerBuffer; i++ ) + { + temp = (*userBufPtr >> 1) + Pa_TriangularDither(); + temp = temp >> 15; + temp = (short) ClipShort(temp); + if (swap) temp = SwapShort(temp); + asioBufPtr[i] = (short)temp; + userBufPtr += NumOuputChannels; + } + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Output_Int32_Int32(ASIOBufferInfo* nativeBuffer, long *outBufPtr, int framePerBuffer, int NumInputChannels, int NumOuputChannels, int index, int hostFrameOffset,int userFrameOffset,uint32 flags,bool swap) +{ + long temp; + int i,j; + + for (j= 0; j < NumOuputChannels; j++) + { + long *asioBufPtr = &((long*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + long *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + for( i=0; i<framePerBuffer; i++ ) + { + temp = *userBufPtr; + if (swap) temp = SwapLong(temp); + asioBufPtr[i] = temp; + userBufPtr += NumOuputChannels; + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +// MUST BE CHECKED + +static void Output_Int32_Float32(ASIOBufferInfo* nativeBuffer, long *outBufPtr, int framePerBuffer, int NumInputChannels, int NumOuputChannels, int index, int hostFrameOffset,int userFrameOffset,uint32 flags,bool swap) +{ + long temp; + int i,j; + + for (j= 0; j < NumOuputChannels; j++) + { + float *asioBufPtr = &((float*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + long *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + for( i=0; i<framePerBuffer; i++ ) + { + temp = *userBufPtr; + if (swap) temp = SwapLong(temp); + asioBufPtr[i] = ((float)temp) * (1.0f / MAX_INT32_FP); + userBufPtr += NumOuputChannels; + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Output_Int16_Int16(ASIOBufferInfo* nativeBuffer, short *outBufPtr, int framePerBuffer, int NumInputChannels, int NumOuputChannels, int index, int hostFrameOffset, int userFrameOffset,bool swap) +{ + long temp; + int i,j; + + for (j= 0; j < NumOuputChannels; j++) + { + short *asioBufPtr = &((short*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + short *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + for( i=0; i<framePerBuffer; i++ ) + { + temp = *userBufPtr; + if (swap) temp = SwapShort(temp); + asioBufPtr[i] = (short)temp; + userBufPtr += NumOuputChannels; + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Output_Int16_Int32(ASIOBufferInfo* nativeBuffer, short *outBufPtr, int framePerBuffer, int NumInputChannels, int NumOuputChannels, int index, int hostFrameOffset,int userFrameOffset, bool swap) +{ + long temp; + int i,j; + + for (j= 0; j < NumOuputChannels; j++) + { + long *asioBufPtr = &((long*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + short *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + for( i=0; i<framePerBuffer; i++ ) + { + temp = (*userBufPtr)<<16; + if (swap) temp = SwapLong(temp); + asioBufPtr[i] = temp; + userBufPtr += NumOuputChannels; + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +// MUST BE CHECKED +static void Output_Int16_Float32(ASIOBufferInfo* nativeBuffer, short *outBufPtr, int framePerBuffer, int NumInputChannels, int NumOuputChannels, int index, int hostFrameOffset,int userFrameOffset, bool swap) +{ + long temp; + int i,j; + + for (j= 0; j < NumOuputChannels; j++) + { + float *asioBufPtr = &((float*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + short *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + for( i=0; i<framePerBuffer; i++ ) + { + temp = *userBufPtr; + asioBufPtr[i] = ((float)temp) * (1.0f / MAX_INT16_FP); + userBufPtr += NumOuputChannels; + } + } +} +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Output_Int8_Int16(ASIOBufferInfo* nativeBuffer, char *outBufPtr, int framePerBuffer, int NumInputChannels, int NumOuputChannels, int index, int hostFrameOffset,int userFrameOffset, bool swap) +{ + long temp; + int i,j; + + for (j= 0; j < NumOuputChannels; j++) + { + short *asioBufPtr = &((short*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + char *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + for( i=0; i<framePerBuffer; i++ ) + { + temp = (short)(*userBufPtr)<<8; + if (swap) temp = SwapShort(temp); + asioBufPtr[i] = (short)temp; + userBufPtr += NumOuputChannels; + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Output_Int8_Int32(ASIOBufferInfo* nativeBuffer, char *outBufPtr, int framePerBuffer, int NumInputChannels, int NumOuputChannels, int index, int hostFrameOffset,int userFrameOffset, bool swap) +{ + long temp; + int i,j; + + for (j= 0; j < NumOuputChannels; j++) + { + long *asioBufPtr = &((long*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + char *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + for( i=0; i<framePerBuffer; i++ ) + { + temp = (short)(*userBufPtr)<<24; + if (swap) temp = SwapLong(temp); + asioBufPtr[i] = temp; + userBufPtr += NumOuputChannels; + } + } +} + + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +// MUST BE CHECKED +static void Output_Int8_Float32(ASIOBufferInfo* nativeBuffer, char *outBufPtr, int framePerBuffer, int NumInputChannels, int NumOuputChannels, int index, int hostFrameOffset,int userFrameOffset, bool swap) +{ + long temp; + int i,j; + + for (j= 0; j < NumOuputChannels; j++) + { + long *asioBufPtr = &((long*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + char *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + for( i=0; i<framePerBuffer; i++ ) + { + temp = *userBufPtr; + asioBufPtr[i] = (long)(((float)temp) * (1.0f / MAX_INT8_FP)); + userBufPtr += NumOuputChannels; + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Output_IntU8_Int16(ASIOBufferInfo* nativeBuffer, unsigned char *outBufPtr, int framePerBuffer, int NumInputChannels, int NumOuputChannels, int index, int hostFrameOffset,int userFrameOffset, bool swap) +{ + long temp; + int i,j; + + for (j= 0; j < NumOuputChannels; j++) + { + short *asioBufPtr = &((short*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + unsigned char *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + for( i=0; i<framePerBuffer; i++ ) + { + temp = ((short)((*userBufPtr) - 0x80)) << 8; + if (swap) temp = SwapShort(temp); + asioBufPtr[i] = (short)temp; + userBufPtr += NumOuputChannels; + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Output_IntU8_Int32(ASIOBufferInfo* nativeBuffer, unsigned char *outBufPtr, int framePerBuffer, int NumInputChannels, int NumOuputChannels, int index, int hostFrameOffset,int userFrameOffset, bool swap) +{ + long temp; + int i,j; + + for (j= 0; j < NumOuputChannels; j++) + { + long *asioBufPtr = &((long*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + unsigned char *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + for( i=0; i<framePerBuffer; i++ ) + { + temp = ((short)((*userBufPtr) - 0x80)) << 24; + if (swap) temp = SwapLong(temp); + asioBufPtr[i] = temp; + userBufPtr += NumOuputChannels; + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +// MUST BE CHECKED + +static void Output_IntU8_Float32(ASIOBufferInfo* nativeBuffer, unsigned char *outBufPtr, int framePerBuffer, int NumInputChannels, int NumOuputChannels, int index, int hostFrameOffset,int userFrameOffset, bool swap) +{ + long temp; + int i,j; + + for (j= 0; j < NumOuputChannels; j++) + { + float *asioBufPtr = &((float*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + unsigned char *userBufPtr = &outBufPtr[j+(userFrameOffset*NumOuputChannels)]; + for( i=0; i<framePerBuffer; i++ ) + { + temp = ((short)((*userBufPtr) - 0x80)) << 24; + asioBufPtr[i] = ((float)temp) * (1.0f / MAX_INT32_FP); + userBufPtr += NumOuputChannels; + } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Pa_ASIO_Clear_Output_16 (ASIOBufferInfo* nativeBuffer, long frames, long NumInputChannels, long NumOuputChannels, long index, long hostFrameOffset) +{ + int i,j; + + for( j=0; j<NumOuputChannels; j++ ) { + short *asioBufPtr = &((short*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + for (i= 0; i < frames; i++) {asioBufPtr[i] = 0; } + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Pa_ASIO_Clear_Output_32 (ASIOBufferInfo* nativeBuffer, long frames, long NumInputChannels, long NumOuputChannels, long index, long hostFrameOffset) +{ + int i,j; + + for( j=0; j<NumOuputChannels; j++ ) { + long *asioBufPtr = &((long*)nativeBuffer[j+NumInputChannels].buffers[index])[hostFrameOffset]; + for (i= 0; i < frames; i++) {asioBufPtr[i] = 0; } + } +} + + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Pa_ASIO_Adaptor_Init() +{ + if (asioDriverInfo.past->past_FramesPerUserBuffer <= asioDriverInfo.past_FramesPerHostBuffer) { + asioDriverInfo.pahsc_hostOutputBufferFrameOffset = asioDriverInfo.pahsc_OutputBufferOffset; + asioDriverInfo.pahsc_userInputBufferFrameOffset = 0; // empty + asioDriverInfo.pahsc_userOutputBufferFrameOffset = asioDriverInfo.past->past_FramesPerUserBuffer; // empty + DBUG(("Pa_ASIO_Adaptor_Init : shift output\n")); + DBUG(("Pa_ASIO_Adaptor_Init : userInputBufferFrameOffset %d\n",asioDriverInfo.pahsc_userInputBufferFrameOffset)); + DBUG(("Pa_ASIO_Adaptor_Init : userOutputBufferFrameOffset %d\n",asioDriverInfo.pahsc_userOutputBufferFrameOffset)); + DBUG(("Pa_ASIO_Adaptor_Init : hostOutputBufferFrameOffset %d\n",asioDriverInfo.pahsc_hostOutputBufferFrameOffset)); + + }else { + asioDriverInfo.pahsc_hostOutputBufferFrameOffset = 0; // empty + asioDriverInfo.pahsc_userInputBufferFrameOffset = asioDriverInfo.pahsc_InputBufferOffset; + asioDriverInfo.pahsc_userOutputBufferFrameOffset = asioDriverInfo.past->past_FramesPerUserBuffer; // empty + DBUG(("Pa_ASIO_Adaptor_Init : shift input\n")); + DBUG(("Pa_ASIO_Adaptor_Init : userInputBufferFrameOffset %d\n",asioDriverInfo.pahsc_userInputBufferFrameOffset)); + DBUG(("Pa_ASIO_Adaptor_Init : userOutputBufferFrameOffset %d\n",asioDriverInfo.pahsc_userOutputBufferFrameOffset)); + DBUG(("Pa_ASIO_Adaptor_Init : hostOutputBufferFrameOffset %d\n",asioDriverInfo.pahsc_hostOutputBufferFrameOffset)); + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +// FIXME : optimization for Input only or output only modes (really necessary ??) +static void Pa_ASIO_Callback_Input(long index) +{ + internalPortAudioStream *past = asioDriverInfo.past; + long framesInputHostBuffer = asioDriverInfo.past_FramesPerHostBuffer; // number of frames available into the host input buffer + long framesInputUserBuffer; // number of frames needed to complete the user input buffer + long framesOutputHostBuffer; // number of frames needed to complete the host output buffer + long framesOuputUserBuffer; // number of frames available into the user output buffer + long userResult; + long tmp; + + /* Fill host ASIO output with remaining frames in user output */ + framesOutputHostBuffer = asioDriverInfo.past_FramesPerHostBuffer - asioDriverInfo.pahsc_hostOutputBufferFrameOffset; + framesOuputUserBuffer = asioDriverInfo.past->past_FramesPerUserBuffer - asioDriverInfo.pahsc_userOutputBufferFrameOffset; + tmp = min(framesOutputHostBuffer, framesOuputUserBuffer); + framesOutputHostBuffer -= tmp; + Pa_ASIO_Callback_Output(index,tmp); + + /* Available frames in hostInputBuffer */ + while (framesInputHostBuffer > 0) { + + /* Number of frames needed to complete an user input buffer */ + framesInputUserBuffer = asioDriverInfo.past->past_FramesPerUserBuffer - asioDriverInfo.pahsc_userInputBufferFrameOffset; + + if (framesInputHostBuffer >= framesInputUserBuffer) { + + /* Convert ASIO input to user input */ + Pa_ASIO_Convert_Inter_Input (asioDriverInfo.bufferInfos, + past->past_InputBuffer, + asioDriverInfo.pahsc_NumInputChannels , + asioDriverInfo.pahsc_NumOutputChannels, + framesInputUserBuffer, + asioDriverInfo.past_FramesPerHostBuffer - framesInputHostBuffer, + asioDriverInfo.pahsc_userInputBufferFrameOffset, + asioDriverInfo.pahsc_channelInfos[0].type, + past->past_InputSampleFormat, + past->past_Flags, + index); + + /* Call PortAudio callback */ + userResult = asioDriverInfo.past->past_Callback(past->past_InputBuffer, past->past_OutputBuffer, + past->past_FramesPerUserBuffer,past->past_FrameCount,past->past_UserData ); + + /* User callback has asked us to stop in the middle of the host buffer */ + if( userResult != 0) { + + /* Put 0 in the end of the output buffer */ + Pa_ASIO_Clear_Output(asioDriverInfo.bufferInfos, + asioDriverInfo.pahsc_channelInfos[0].type, + asioDriverInfo.pahsc_NumInputChannels , + asioDriverInfo.pahsc_NumOutputChannels, + index, + asioDriverInfo.pahsc_hostOutputBufferFrameOffset, + asioDriverInfo.past_FramesPerHostBuffer - asioDriverInfo.pahsc_hostOutputBufferFrameOffset); + + past->past_StopSoon = 1; + return; + } + + + /* Full user ouput buffer : write offset */ + asioDriverInfo.pahsc_userOutputBufferFrameOffset = 0; + + /* Empty user input buffer : read offset */ + asioDriverInfo.pahsc_userInputBufferFrameOffset = 0; + + /* Fill host ASIO output */ + tmp = min (past->past_FramesPerUserBuffer,framesOutputHostBuffer); + Pa_ASIO_Callback_Output(index,tmp); + + framesOutputHostBuffer -= tmp; + framesInputHostBuffer -= framesInputUserBuffer; + + }else { + + /* Convert ASIO input to user input */ + Pa_ASIO_Convert_Inter_Input (asioDriverInfo.bufferInfos, + past->past_InputBuffer, + asioDriverInfo.pahsc_NumInputChannels , + asioDriverInfo.pahsc_NumOutputChannels, + framesInputHostBuffer, + asioDriverInfo.past_FramesPerHostBuffer - framesInputHostBuffer, + asioDriverInfo.pahsc_userInputBufferFrameOffset, + asioDriverInfo.pahsc_channelInfos[0].type, + past->past_InputSampleFormat, + past->past_Flags, + index); + + /* Update pahsc_userInputBufferFrameOffset */ + asioDriverInfo.pahsc_userInputBufferFrameOffset += framesInputHostBuffer; + + /* Update framesInputHostBuffer */ + framesInputHostBuffer = 0; + } + } + +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Pa_ASIO_Callback_Output(long index, long framePerBuffer) +{ + internalPortAudioStream *past = asioDriverInfo.past; + + if (framePerBuffer > 0) { + + /* Convert user output to ASIO ouput */ + Pa_ASIO_Convert_Inter_Output (asioDriverInfo.bufferInfos, + past->past_OutputBuffer, + asioDriverInfo.pahsc_NumInputChannels, + asioDriverInfo.pahsc_NumOutputChannels, + framePerBuffer, + asioDriverInfo.pahsc_hostOutputBufferFrameOffset, + asioDriverInfo.pahsc_userOutputBufferFrameOffset, + asioDriverInfo.pahsc_channelInfos[0].type, + past->past_InputSampleFormat, + past->past_Flags, + index); + + /* Update hostOuputFrameOffset */ + asioDriverInfo.pahsc_hostOutputBufferFrameOffset += framePerBuffer; + + /* Update userOutputFrameOffset */ + asioDriverInfo.pahsc_userOutputBufferFrameOffset += framePerBuffer; + } +} +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Pa_ASIO_Callback_End() + { + /* Empty ASIO ouput : write offset */ + asioDriverInfo.pahsc_hostOutputBufferFrameOffset = 0; + } + +//------------------------------------------------------------------------------------------------------------------------------------------------------- +static void Pa_ASIO_Clear_User_Buffers() +{ + if( asioDriverInfo.past->past_InputBuffer != NULL ) + { + memset( asioDriverInfo.past->past_InputBuffer, 0, asioDriverInfo.past->past_InputBufferSize ); + } + if( asioDriverInfo.past->past_OutputBuffer != NULL ) + { + memset( asioDriverInfo.past->past_OutputBuffer, 0, asioDriverInfo.past->past_OutputBufferSize ); + } +} + +//------------------------------------------------------------------------------------------------------------------------------------------------------- + static void Pa_ASIO_Clear_Output(ASIOBufferInfo* nativeBuffer, + ASIOSampleType nativeFormat, + long NumInputChannels, + long NumOuputChannels, + long index, + long hostFrameOffset, + long frames) +{ + + switch (nativeFormat) { + + case ASIOSTInt16MSB: + case ASIOSTInt16LSB: + case ASIOSTInt32MSB16: + case ASIOSTInt32LSB16: + Pa_ASIO_Clear_Output_16(nativeBuffer, frames, NumInputChannels, NumOuputChannels, index, hostFrameOffset); + break; + + case ASIOSTFloat64MSB: + case ASIOSTFloat64LSB: + break; + + case ASIOSTFloat32MSB: + case ASIOSTFloat32LSB: + case ASIOSTInt32MSB: + case ASIOSTInt32LSB: + case ASIOSTInt32MSB18: + case ASIOSTInt32MSB20: + case ASIOSTInt32MSB24: + case ASIOSTInt32LSB18: + case ASIOSTInt32LSB20: + case ASIOSTInt32LSB24: + Pa_ASIO_Clear_Output_32(nativeBuffer, frames, NumInputChannels, NumOuputChannels, index, hostFrameOffset); + break; + + case ASIOSTInt24MSB: + case ASIOSTInt24LSB: + break; + + default: + break; + } +} + + +//--------------------------------------------------------------------------------------- +static void Pa_ASIO_Convert_Inter_Input( + ASIOBufferInfo* nativeBuffer, + void* inputBuffer, + long NumInputChannels, + long NumOuputChannels, + long framePerBuffer, + long hostFrameOffset, + long userFrameOffset, + ASIOSampleType nativeFormat, + PaSampleFormat paFormat, + PaStreamFlags flags, + long index) +{ + + if((NumInputChannels > 0) && (nativeBuffer != NULL)) + { + /* Convert from native format to PA format. */ + switch(paFormat) + { + case paFloat32: + { + float *inBufPtr = (float *) inputBuffer; + + switch (nativeFormat) { + case ASIOSTInt16LSB: + Input_Int16_Float32(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset, userFrameOffset, swap); + break; + case ASIOSTInt16MSB: + Input_Int16_Float32(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset, userFrameOffset,!swap); + break; + case ASIOSTInt32LSB: + Input_Int32_Float32(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset, userFrameOffset,swap); + break; + case ASIOSTInt32MSB: + Input_Int32_Float32(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset, userFrameOffset,!swap); + break; + case ASIOSTFloat32LSB: // IEEE 754 32 bit float, as found on Intel x86 architecture + Input_Float32_Float32(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset, userFrameOffset,swap); + break; + case ASIOSTFloat32MSB: // IEEE 754 32 bit float, as found on Intel x86 architecture + Input_Float32_Float32(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset, userFrameOffset,!swap); + break; + + case ASIOSTInt24LSB: // used for 20 bits as well + case ASIOSTInt24MSB: // used for 20 bits as well + + case ASIOSTFloat64LSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + case ASIOSTFloat64MSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + + // these are used for 32 bit data buffer, with different alignment of the data inside + // 32 bit PCI bus systems can more easily used with these + + case ASIOSTInt32LSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32LSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32LSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32LSB24: // 32 bit data with 24 bit alignment + + + case ASIOSTInt32MSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32MSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32MSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32MSB24: // 32 bit data with 24 bit alignment + DBUG(("Not yet implemented : please report the problem\n")); + break; + } + + break; + } + + case paInt32: + { + long *inBufPtr = (long *)inputBuffer; + + switch (nativeFormat) { + case ASIOSTInt16LSB: + Input_Int16_Int32(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, swap); + break; + case ASIOSTInt16MSB: + Input_Int16_Int32(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, !swap); + break; + case ASIOSTInt32LSB: + Input_Int32_Int32(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, swap); + break; + case ASIOSTInt32MSB: + Input_Int32_Int32(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, !swap); + break; + case ASIOSTFloat32LSB: // IEEE 754 32 bit float, as found on Intel x86 architecture + Input_Float32_Int32(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, swap); + break; + case ASIOSTFloat32MSB: // IEEE 754 32 bit float, as found on Intel x86 architecture + Input_Float32_Int32(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, !swap); + break; + + case ASIOSTInt24LSB: // used for 20 bits as well + case ASIOSTInt24MSB: // used for 20 bits as well + + case ASIOSTFloat64LSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + case ASIOSTFloat64MSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + + // these are used for 32 bit data buffer, with different alignment of the data inside + // 32 bit PCI bus systems can more easily used with these + + case ASIOSTInt32LSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32LSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32LSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32LSB24: // 32 bit data with 24 bit alignment + + + case ASIOSTInt32MSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32MSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32MSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32MSB24: // 32 bit data with 24 bit alignment + DBUG(("Not yet implemented : please report the problem\n")); + break; + + } + break; + } + + case paInt16: + { + short *inBufPtr = (short *) inputBuffer; + + switch (nativeFormat) { + case ASIOSTInt16LSB: + Input_Int16_Int16(nativeBuffer, inBufPtr, framePerBuffer , NumInputChannels, index , hostFrameOffset,userFrameOffset, swap); + break; + case ASIOSTInt16MSB: + Input_Int16_Int16(nativeBuffer, inBufPtr, framePerBuffer , NumInputChannels, index , hostFrameOffset,userFrameOffset, !swap); + break; + case ASIOSTInt32LSB: + Input_Int32_Int16(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, flags,swap); + break; + case ASIOSTInt32MSB: + Input_Int32_Int16(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, flags,!swap); + break; + case ASIOSTFloat32LSB: // IEEE 754 32 bit float, as found on Intel x86 architecture + Input_Float32_Int16(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, flags,swap); + break; + case ASIOSTFloat32MSB: // IEEE 754 32 bit float, as found on Intel x86 architecture + Input_Float32_Int16(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, flags,!swap); + break; + + case ASIOSTInt24LSB: // used for 20 bits as well + case ASIOSTInt24MSB: // used for 20 bits as well + + case ASIOSTFloat64LSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + case ASIOSTFloat64MSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + + // these are used for 32 bit data buffer, with different alignment of the data inside + // 32 bit PCI bus systems can more easily used with these + + case ASIOSTInt32LSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32LSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32LSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32LSB24: // 32 bit data with 24 bit alignment + + + case ASIOSTInt32MSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32MSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32MSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32MSB24: // 32 bit data with 24 bit alignment + DBUG(("Not yet implemented : please report the problem\n")); + break; + + } + break; + } + + case paInt8: + { + /* Convert 16 bit data to 8 bit chars */ + + char *inBufPtr = (char *) inputBuffer; + + switch (nativeFormat) { + case ASIOSTInt16LSB: + Input_Int16_Int8(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset,flags,swap); + break; + case ASIOSTInt16MSB: + Input_Int16_Int8(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, flags,!swap); + break; + case ASIOSTInt32LSB: + Input_Int32_Int8(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, flags,swap); + break; + case ASIOSTInt32MSB: + Input_Int32_Int8(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, flags,!swap); + break; + case ASIOSTFloat32LSB: // IEEE 754 32 bit float, as found on Intel x86 architecture + Input_Float32_Int8(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, flags,swap); + break; + case ASIOSTFloat32MSB: // IEEE 754 32 bit float, as found on Intel x86 architecture + Input_Float32_Int8(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, flags,!swap); + break; + + case ASIOSTInt24LSB: // used for 20 bits as well + case ASIOSTInt24MSB: // used for 20 bits as well + + case ASIOSTFloat64LSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + case ASIOSTFloat64MSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + + // these are used for 32 bit data buffer, with different alignment of the data inside + // 32 bit PCI bus systems can more easily used with these + + case ASIOSTInt32LSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32LSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32LSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32LSB24: // 32 bit data with 24 bit alignment + + + case ASIOSTInt32MSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32MSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32MSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32MSB24: // 32 bit data with 24 bit alignment + DBUG(("Not yet implemented : please report the problem\n")); + break; + } + break; + } + + case paUInt8: + { + /* Convert 16 bit data to 8 bit unsigned chars */ + + unsigned char *inBufPtr = (unsigned char *)inputBuffer; + + switch (nativeFormat) { + case ASIOSTInt16LSB: + Input_Int16_IntU8(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, flags,swap); + break; + case ASIOSTInt16MSB: + Input_Int16_IntU8(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, flags,!swap); + break; + case ASIOSTInt32LSB: + Input_Int32_IntU8(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset,flags,swap); + break; + case ASIOSTInt32MSB: + Input_Int32_IntU8(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset, flags,!swap); + break; + case ASIOSTFloat32LSB: // IEEE 754 32 bit float, as found on Intel x86 architecture + Input_Float32_IntU8(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset,flags,swap); + break; + case ASIOSTFloat32MSB: // IEEE 754 32 bit float, as found on Intel x86 architecture + Input_Float32_IntU8(nativeBuffer, inBufPtr, framePerBuffer, NumInputChannels, index, hostFrameOffset,userFrameOffset,flags,!swap); + break; + + case ASIOSTInt24LSB: // used for 20 bits as well + case ASIOSTInt24MSB: // used for 20 bits as well + + case ASIOSTFloat64LSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + case ASIOSTFloat64MSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + + // these are used for 32 bit data buffer, with different alignment of the data inside + // 32 bit PCI bus systems can more easily used with these + + case ASIOSTInt32LSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32LSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32LSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32LSB24: // 32 bit data with 24 bit alignment + + + case ASIOSTInt32MSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32MSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32MSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32MSB24: // 32 bit data with 24 bit alignment + DBUG(("Not yet implemented : please report the problem\n")); + break; + + } + break; + } + + default: + break; + } + } +} + + +//--------------------------------------------------------------------------------------- +static void Pa_ASIO_Convert_Inter_Output(ASIOBufferInfo* nativeBuffer, + void* outputBuffer, + long NumInputChannels, + long NumOuputChannels, + long framePerBuffer, + long hostFrameOffset, + long userFrameOffset, + ASIOSampleType nativeFormat, + PaSampleFormat paFormat, + PaStreamFlags flags, + long index) +{ + + if((NumOuputChannels > 0) && (nativeBuffer != NULL)) + { + /* Convert from PA format to native format */ + + switch(paFormat) + { + case paFloat32: + { + float *outBufPtr = (float *) outputBuffer; + + switch (nativeFormat) { + case ASIOSTInt16LSB: + Output_Float32_Int16(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset, userFrameOffset, flags, swap); + break; + case ASIOSTInt16MSB: + Output_Float32_Int16(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset, userFrameOffset, flags,!swap); + break; + case ASIOSTInt32LSB: + Output_Float32_Int32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset, userFrameOffset, flags,swap); + break; + case ASIOSTInt32MSB: + Output_Float32_Int32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, flags,!swap); + break; + case ASIOSTFloat32LSB: + Output_Float32_Float32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset,flags,swap); + break; + case ASIOSTFloat32MSB: + Output_Float32_Float32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, flags,!swap); + break; + + case ASIOSTInt24LSB: // used for 20 bits as well + case ASIOSTInt24MSB: // used for 20 bits as well + + case ASIOSTFloat64LSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + case ASIOSTFloat64MSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + + // these are used for 32 bit data buffer, with different alignment of the data inside + // 32 bit PCI bus systems can more easily used with these + + case ASIOSTInt32LSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32LSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32LSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32LSB24: // 32 bit data with 24 bit alignment + + + case ASIOSTInt32MSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32MSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32MSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32MSB24: // 32 bit data with 24 bit alignment + DBUG(("Not yet implemented : please report the problem\n")); + break; + } + break; + } + + case paInt32: + { + long *outBufPtr = (long *) outputBuffer; + + switch (nativeFormat) { + case ASIOSTInt16LSB: + Output_Int32_Int16(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, flags,swap); + break; + case ASIOSTInt16MSB: + Output_Int32_Int16(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, flags,!swap); + break; + case ASIOSTInt32LSB: + Output_Int32_Int32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, flags,swap); + break; + case ASIOSTInt32MSB: + Output_Int32_Int32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, flags,!swap); + break; + case ASIOSTFloat32LSB: + Output_Int32_Float32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, flags,swap); + break; + case ASIOSTFloat32MSB: + Output_Int32_Float32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, flags,!swap); + break; + + case ASIOSTInt24LSB: // used for 20 bits as well + case ASIOSTInt24MSB: // used for 20 bits as well + + case ASIOSTFloat64LSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + case ASIOSTFloat64MSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + + // these are used for 32 bit data buffer, with different alignment of the data inside + // 32 bit PCI bus systems can more easily used with these + + case ASIOSTInt32LSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32LSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32LSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32LSB24: // 32 bit data with 24 bit alignment + + + case ASIOSTInt32MSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32MSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32MSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32MSB24: // 32 bit data with 24 bit alignment + DBUG(("Not yet implemented : please report the problem\n")); + break; + } + break; + } + + case paInt16: + { + short *outBufPtr = (short *) outputBuffer; + + switch (nativeFormat) { + case ASIOSTInt16LSB: + Output_Int16_Int16(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, swap); + break; + case ASIOSTInt16MSB: + Output_Int16_Int16(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, !swap); + break; + case ASIOSTInt32LSB: + Output_Int16_Int32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, swap); + break; + case ASIOSTInt32MSB: + Output_Int16_Int32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, !swap); + break; + case ASIOSTFloat32LSB: + Output_Int16_Float32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, swap); + break; + case ASIOSTFloat32MSB: + Output_Int16_Float32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, !swap); + break; + + case ASIOSTInt24LSB: // used for 20 bits as well + case ASIOSTInt24MSB: // used for 20 bits as well + + case ASIOSTFloat64LSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + case ASIOSTFloat64MSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + + // these are used for 32 bit data buffer, with different alignment of the data inside + // 32 bit PCI bus systems can more easily used with these + + case ASIOSTInt32LSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32LSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32LSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32LSB24: // 32 bit data with 24 bit alignment + + + case ASIOSTInt32MSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32MSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32MSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32MSB24: // 32 bit data with 24 bit alignment + DBUG(("Not yet implemented : please report the problem\n")); + break; + + } + break; + } + + + case paInt8: + { + char *outBufPtr = (char *) outputBuffer; + + switch (nativeFormat) { + case ASIOSTInt16LSB: + Output_Int8_Int16(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, swap); + break; + case ASIOSTInt16MSB: + Output_Int8_Int16(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, !swap); + break; + case ASIOSTInt32LSB: + Output_Int8_Int32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, swap); + break; + case ASIOSTInt32MSB: + Output_Int8_Int32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, !swap); + break; + case ASIOSTFloat32LSB: + Output_Int8_Float32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, swap); + break; + case ASIOSTFloat32MSB: + Output_Int8_Float32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, !swap); + break; + + case ASIOSTInt24LSB: // used for 20 bits as well + case ASIOSTInt24MSB: // used for 20 bits as well + + case ASIOSTFloat64LSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + case ASIOSTFloat64MSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + + // these are used for 32 bit data buffer, with different alignment of the data inside + // 32 bit PCI bus systems can more easily used with these + + case ASIOSTInt32LSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32LSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32LSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32LSB24: // 32 bit data with 24 bit alignment + + + case ASIOSTInt32MSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32MSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32MSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32MSB24: // 32 bit data with 24 bit alignment + DBUG(("Not yet implemented : please report the problem\n")); + break; + } + break; + } + + case paUInt8: + { + unsigned char *outBufPtr = (unsigned char *) outputBuffer; + + switch (nativeFormat) { + case ASIOSTInt16LSB: + Output_IntU8_Int16(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, swap); + break; + case ASIOSTInt16MSB: + Output_IntU8_Int16(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, !swap); + break; + case ASIOSTInt32LSB: + Output_IntU8_Int32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, swap); + break; + case ASIOSTInt32MSB: + Output_IntU8_Int32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, !swap); + break; + case ASIOSTFloat32LSB: + Output_IntU8_Float32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, swap); + break; + case ASIOSTFloat32MSB: + Output_IntU8_Float32(nativeBuffer, outBufPtr, framePerBuffer, NumInputChannels, NumOuputChannels, index, hostFrameOffset,userFrameOffset, !swap); + break; + + case ASIOSTInt24LSB: // used for 20 bits as well + case ASIOSTInt24MSB: // used for 20 bits as well + + case ASIOSTFloat64LSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + case ASIOSTFloat64MSB: // IEEE 754 64 bit double float, as found on Intel x86 architecture + + // these are used for 32 bit data buffer, with different alignment of the data inside + // 32 bit PCI bus systems can more easily used with these + + case ASIOSTInt32LSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32LSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32LSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32LSB24: // 32 bit data with 24 bit alignment + + + case ASIOSTInt32MSB16: // 32 bit data with 16 bit alignment + case ASIOSTInt32MSB18: // 32 bit data with 18 bit alignment + case ASIOSTInt32MSB20: // 32 bit data with 20 bit alignment + case ASIOSTInt32MSB24: // 32 bit data with 24 bit alignment + DBUG(("Not yet implemented : please report the problem\n")); + break; + } + break; + } + + default: + break; + } + } + +} + + + +/* Load a ASIO driver corresponding to the required device */ +static PaError Pa_ASIO_loadDevice (long device) +{ + PaDeviceInfo * dev = &(sDevices[device].pad_Info); + + if (!Pa_ASIO_loadAsioDriver((char *) dev->name)) return paHostError; + if (ASIOInit(&asioDriverInfo.pahsc_driverInfo) != ASE_OK) return paHostError; + if (ASIOGetChannels(&asioDriverInfo.pahsc_NumInputChannels, &asioDriverInfo.pahsc_NumOutputChannels) != ASE_OK) return paHostError; + if (ASIOGetBufferSize(&asioDriverInfo.pahsc_minSize, &asioDriverInfo.pahsc_maxSize, &asioDriverInfo.pahsc_preferredSize, &asioDriverInfo.pahsc_granularity) != ASE_OK) return paHostError; + + if(ASIOOutputReady() == ASE_OK) + asioDriverInfo.pahsc_postOutput = true; + else + asioDriverInfo.pahsc_postOutput = false; + + return paNoError; +} + +//--------------------------------------------------- +static int GetHighestBitPosition (unsigned long n) +{ + int pos = -1; + while( n != 0 ) + { + pos++; + n = n >> 1; + } + return pos; +} + +//------------------------------------------------------------------------------------------ +static int GetFirstMultiple(long min, long val ){ return ((min + val - 1) / val) * val; } + +//------------------------------------------------------------------------------------------ +static int GetFirstPossibleDivisor(long max, long val ) +{ + for (int i = 2; i < 20; i++) {if (((val%i) == 0) && ((val/i) <= max)) return (val/i); } + return val; +} + +//------------------------------------------------------------------------ +static int IsPowerOfTwo( unsigned long n ) { return ((n & (n-1)) == 0); } + +/******************************************************************* +* Determine size of native ASIO audio buffer size +* Input parameters : FramesPerUserBuffer, NumUserBuffers +* Output values : FramesPerHostBuffer, OutputBufferOffset or InputtBufferOffset +*/ + +static PaError PaHost_CalcNumHostBuffers( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + long requestedBufferSize; + long firstMultiple, firstDivisor; + + // Compute requestedBufferSize + if( past->past_NumUserBuffers < 1 ){ + requestedBufferSize = past->past_FramesPerUserBuffer; + }else{ + requestedBufferSize = past->past_NumUserBuffers * past->past_FramesPerUserBuffer; + } + + // Adjust FramesPerHostBuffer using requestedBufferSize, ASIO minSize and maxSize, + if (requestedBufferSize < asioDriverInfo.pahsc_minSize){ + + firstMultiple = GetFirstMultiple(asioDriverInfo.pahsc_minSize, requestedBufferSize); + + if (firstMultiple <= asioDriverInfo.pahsc_maxSize) + asioDriverInfo.past_FramesPerHostBuffer = firstMultiple; + else + asioDriverInfo.past_FramesPerHostBuffer = asioDriverInfo.pahsc_minSize; + + }else if (requestedBufferSize > asioDriverInfo.pahsc_maxSize){ + + firstDivisor = GetFirstPossibleDivisor(asioDriverInfo.pahsc_maxSize, requestedBufferSize); + + if ((firstDivisor >= asioDriverInfo.pahsc_minSize) && (firstDivisor <= asioDriverInfo.pahsc_maxSize)) + asioDriverInfo.past_FramesPerHostBuffer = firstDivisor; + else + asioDriverInfo.past_FramesPerHostBuffer = asioDriverInfo.pahsc_maxSize; + }else{ + asioDriverInfo.past_FramesPerHostBuffer = requestedBufferSize; + } + + // If ASIO buffer size needs to be a power of two + if( asioDriverInfo.pahsc_granularity < 0 ){ + // Needs to be a power of two. + + if( !IsPowerOfTwo( asioDriverInfo.past_FramesPerHostBuffer ) ) + { + int highestBit = GetHighestBitPosition(asioDriverInfo.past_FramesPerHostBuffer); + asioDriverInfo.past_FramesPerHostBuffer = 1 << (highestBit + 1); + } + } + + DBUG(("----------------------------------\n")); + DBUG(("PaHost_CalcNumHostBuffers : minSize = %ld \n",asioDriverInfo.pahsc_minSize)); + DBUG(("PaHost_CalcNumHostBuffers : preferredSize = %ld \n",asioDriverInfo.pahsc_preferredSize)); + DBUG(("PaHost_CalcNumHostBuffers : maxSize = %ld \n",asioDriverInfo.pahsc_maxSize)); + DBUG(("PaHost_CalcNumHostBuffers : granularity = %ld \n",asioDriverInfo.pahsc_granularity)); + DBUG(("PaHost_CalcNumHostBuffers : User buffer size = %d\n", asioDriverInfo.past->past_FramesPerUserBuffer )); + DBUG(("PaHost_CalcNumHostBuffers : ASIO buffer size = %d\n", asioDriverInfo.past_FramesPerHostBuffer )); + + return paNoError; +} + + +/***********************************************************************/ +int Pa_CountDevices() +{ + PaError err ; + + if( sNumDevices <= 0 ) + { + /* Force loading of ASIO drivers */ + err = Pa_ASIO_QueryDeviceInfo(sDevices); + if( err != paNoError ) goto error; + } + + return sNumDevices; + +error: + PaHost_Term(); + DBUG(("Pa_CountDevices: returns %d\n", err )); + return err; +} + +/***********************************************************************/ +PaError PaHost_Init( void ) +{ + /* Have we already initialized the device info? */ + PaError err = (PaError) Pa_CountDevices(); + return ( err < 0 ) ? err : paNoError; +} + +/***********************************************************************/ +PaError PaHost_Term( void ) +{ + int i; + PaDeviceInfo *dev; + double *rates; + PaError result = paNoError; + + if (sNumDevices > 0) { + + /* Free allocated sample rate arrays and names*/ + for( i=0; i<sNumDevices; i++ ){ + dev = &sDevices[i].pad_Info; + rates = (double *) dev->sampleRates; + if ((rates != NULL)) PaHost_FreeFastMemory(rates, MAX_NUMSAMPLINGRATES * sizeof(double)); + dev->sampleRates = NULL; + if(dev->name != NULL) PaHost_FreeFastMemory((void *) dev->name, 32); + dev->name = NULL; + } + + sNumDevices = 0; + + /* If the stream has been closed with PaHost_CloseStream, asioDriverInfo.past == null, otherwise close it now */ + if(asioDriverInfo.past != NULL) Pa_CloseStream(asioDriverInfo.past); + + /* remove the loaded ASIO driver */ + asioDrivers->removeCurrentDriver(); + } + + return result; +} + +/***********************************************************************/ +PaError PaHost_OpenStream( internalPortAudioStream *past ) +{ + PaError result = paNoError; + ASIOError err; + int32 device; + + /* Check if a stream already runs */ + if (asioDriverInfo.past != NULL) return paHostError; + + /* Check the device number */ + if ((past->past_InputDeviceID != paNoDevice) + &&(past->past_OutputDeviceID != paNoDevice) + &&(past->past_InputDeviceID != past->past_OutputDeviceID)) + { + return paInvalidDeviceId; + } + + /* Allocation */ + memset(&asioDriverInfo, 0, sizeof(PaHostSoundControl)); + past->past_DeviceData = (void*) &asioDriverInfo; + + /* Reentrancy counter initialisation */ + asioDriverInfo.reenterCount = -1; + asioDriverInfo.reenterError = 0; + + /* FIXME */ + asioDriverInfo.past = past; + + /* load the ASIO device */ + device = (past->past_InputDeviceID < 0) ? past->past_OutputDeviceID : past->past_InputDeviceID; + result = Pa_ASIO_loadDevice(device); + if (result != paNoError) goto error; + + /* Check ASIO parameters and input parameters */ + if ((past->past_NumInputChannels > asioDriverInfo.pahsc_NumInputChannels) + || (past->past_NumOutputChannels > asioDriverInfo.pahsc_NumOutputChannels)) { + result = paInvalidChannelCount; + goto error; + } + + /* Set sample rate */ + if (ASIOSetSampleRate(past->past_SampleRate) != ASE_OK) { + result = paInvalidSampleRate; + goto error; + } + + /* if OK calc buffer size */ + result = PaHost_CalcNumHostBuffers( past ); + if (result != paNoError) goto error; + + + /* + Allocating input and output buffers number for the real past_NumInputChannels and past_NumOutputChannels + optimize the data transfer. + */ + + asioDriverInfo.pahsc_NumInputChannels = past->past_NumInputChannels; + asioDriverInfo.pahsc_NumOutputChannels = past->past_NumOutputChannels; + + /* Allocate ASIO buffers and callback*/ + err = Pa_ASIO_CreateBuffers(&asioDriverInfo, + asioDriverInfo.pahsc_NumInputChannels, + asioDriverInfo.pahsc_NumOutputChannels, + asioDriverInfo.past_FramesPerHostBuffer); + + + /* + Some buggy drivers (like the Hoontech DSP24) give incorrect [min, preferred, max] values + They should work with the preferred size value, thus if Pa_ASIO_CreateBuffers fails with + the hostBufferSize computed in PaHost_CalcNumHostBuffers, we try again with the preferred size. + */ + + if (err != ASE_OK) { + + DBUG(("PaHost_OpenStream : Pa_ASIO_CreateBuffers failed with the requested framesPerBuffer = %ld \n", asioDriverInfo.past_FramesPerHostBuffer)); + + err = Pa_ASIO_CreateBuffers(&asioDriverInfo, + asioDriverInfo.pahsc_NumInputChannels, + asioDriverInfo.pahsc_NumOutputChannels, + asioDriverInfo.pahsc_preferredSize); + + if (err == ASE_OK) { + // Adjust FramesPerHostBuffer to take the preferredSize instead of the value computed in PaHost_CalcNumHostBuffers + asioDriverInfo.past_FramesPerHostBuffer = asioDriverInfo.pahsc_preferredSize; + DBUG(("PaHost_OpenStream : Adjust FramesPerHostBuffer to take the preferredSize instead of the value computed in PaHost_CalcNumHostBuffers\n")); + } else { + DBUG(("PaHost_OpenStream : Pa_ASIO_CreateBuffers failed with the preferred framesPerBuffer = %ld \n", asioDriverInfo.pahsc_preferredSize)); + } + } + + /* Compute buffer adapdation offset */ + PaHost_CalcBufferOffset(past); + + if (err == ASE_OK) + return paNoError; + else if (err == ASE_NoMemory) + result = paInsufficientMemory; + else if (err == ASE_InvalidParameter) + result = paInvalidChannelCount; + else if (err == ASE_InvalidMode) + result = paBufferTooBig; + else + result = paHostError; + +error: + ASIOExit(); + return result; + +} + +/***********************************************************************/ +PaError PaHost_CloseStream( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc; + PaError result = paNoError; + + if( past == NULL ) return paBadStreamPtr; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return paNoError; + + #if PA_TRACE_START_STOP + AddTraceMessage( "PaHost_CloseStream: pahsc_HWaveOut ", (int) pahsc->pahsc_HWaveOut ); + #endif + + /* Free data and device for output. */ + past->past_DeviceData = NULL; + asioDriverInfo.past = NULL; + + /* Dispose */ + if(ASIODisposeBuffers() != ASE_OK) result = paHostError; + if(ASIOExit() != ASE_OK) result = paHostError; + + return result; +} + +/***********************************************************************/ +PaError PaHost_StartOutput( internalPortAudioStream *past ) +{ + /* Clear the index 0 host output buffer */ + Pa_ASIO_Clear_Output(asioDriverInfo.bufferInfos, + asioDriverInfo.pahsc_channelInfos[0].type, + asioDriverInfo.pahsc_NumInputChannels, + asioDriverInfo.pahsc_NumOutputChannels, + 0, + 0, + asioDriverInfo.past_FramesPerHostBuffer); + + /* Clear the index 1 host output buffer */ + Pa_ASIO_Clear_Output(asioDriverInfo.bufferInfos, + asioDriverInfo.pahsc_channelInfos[0].type, + asioDriverInfo.pahsc_NumInputChannels, + asioDriverInfo.pahsc_NumOutputChannels, + 1, + 0, + asioDriverInfo.past_FramesPerHostBuffer); + + Pa_ASIO_Clear_User_Buffers(); + + Pa_ASIO_Adaptor_Init(); + + return paNoError; +} + +/***********************************************************************/ +PaError PaHost_StopOutput( internalPortAudioStream *past, int abort ) +{ + /* Nothing to do ?? */ + return paNoError; +} + +/***********************************************************************/ +PaError PaHost_StartInput( internalPortAudioStream *past ) +{ + /* Nothing to do ?? */ + return paNoError; +} + +/***********************************************************************/ +PaError PaHost_StopInput( internalPortAudioStream *past, int abort ) +{ + /* Nothing to do */ + return paNoError; +} + +/***********************************************************************/ +PaError PaHost_StartEngine( internalPortAudioStream *past ) +{ + // TO DO : count of samples + past->past_IsActive = 1; + return (ASIOStart() == ASE_OK) ? paNoError : paHostError; +} + +/***********************************************************************/ +PaError PaHost_StopEngine( internalPortAudioStream *past, int abort ) +{ + // TO DO : count of samples + past->past_IsActive = 0; + return (ASIOStop() == ASE_OK) ? paNoError : paHostError; +} + +/***********************************************************************/ +// TO BE CHECKED +PaError PaHost_StreamActive( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc; + if( past == NULL ) return paBadStreamPtr; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return paInternalError; + return (PaError) past->past_IsActive; +} + +/*************************************************************************/ +PaTimestamp Pa_StreamTime( PortAudioStream *stream ) +{ + PaHostSoundControl *pahsc; + internalPortAudioStream *past = (internalPortAudioStream *) stream; + if( past == NULL ) return paBadStreamPtr; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + return pahsc->pahsc_NumFramesDone; +} + +/************************************************************************* + * Allocate memory that can be accessed in real-time. + * This may need to be held in physical memory so that it is not + * paged to virtual memory. + * This call MUST be balanced with a call to PaHost_FreeFastMemory(). + */ +void *PaHost_AllocateFastMemory( long numBytes ) +{ + #if MAC + void *addr = NewPtrClear( numBytes ); + if( (addr == NULL) || (MemError () != 0) ) return NULL; + + #if (CARBON_COMPATIBLE == 0) + if( HoldMemory( addr, numBytes ) != noErr ) + { + DisposePtr( (Ptr) addr ); + return NULL; + } + #endif + return addr; + #elif WINDOWS + void *addr = malloc( numBytes ); /* FIXME - do we need physical memory? */ + if( addr != NULL ) memset( addr, 0, numBytes ); + return addr; + #endif +} + +/************************************************************************* + * Free memory that could be accessed in real-time. + * This call MUST be balanced with a call to PaHost_AllocateFastMemory(). + */ +void PaHost_FreeFastMemory( void *addr, long numBytes ) +{ + #if MAC + if( addr == NULL ) return; + #if CARBON_COMPATIBLE + (void) numBytes; + #else + UnholdMemory( addr, numBytes ); + #endif + DisposePtr( (Ptr) addr ); + #elif WINDOWS + if( addr != NULL ) free( addr ); + #endif +} + + +/*************************************************************************/ +void Pa_Sleep( long msec ) +{ + #if MAC + int32 sleepTime, endTime; + /* Convert to ticks. Round up so we sleep a MINIMUM of msec time. */ + sleepTime = ((msec * 60) + 999) / 1000; + if( sleepTime < 1 ) sleepTime = 1; + endTime = TickCount() + sleepTime; + do{ + DBUGX(("Sleep for %d ticks.\n", sleepTime )); + WaitNextEvent( 0, NULL, sleepTime, NULL ); /* Use this just to sleep without getting events. */ + sleepTime = endTime - TickCount(); + } while( sleepTime > 0 ); + #elif WINDOWS + Sleep( msec ); + #endif +} + +/*************************************************************************/ +const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceID id ) +{ + if( (id < 0) || ( id >= Pa_CountDevices()) ) return NULL; + return &sDevices[id].pad_Info; +} + +/*************************************************************************/ +PaDeviceID Pa_GetDefaultInputDeviceID( void ) +{ + return (sNumDevices > 0) ? sDefaultInputDeviceID : paNoDevice; +} + +/*************************************************************************/ +PaDeviceID Pa_GetDefaultOutputDeviceID( void ) +{ + return (sNumDevices > 0) ? sDefaultOutputDeviceID : paNoDevice; +} + +/*************************************************************************/ +int Pa_GetMinNumBuffers( int framesPerUserBuffer, double sampleRate ) +{ + // TO BE IMPLEMENTED : using the ASIOGetLatency call?? + return 2; +} + +/*************************************************************************/ +int32 Pa_GetHostError( void ) +{ + int32 err = sPaHostError; + sPaHostError = 0; + return err; +} + + +#ifdef MAC + +/**************************************************************************/ +static void Pa_StartUsageCalculation( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + UnsignedWide widePad; + if( pahsc == NULL ) return; +/* Query system timer for usage analysis and to prevent overuse of CPU. */ + Microseconds( &widePad ); + pahsc->pahsc_EntryCount = UnsignedWideToUInt64( widePad ); +} +/**************************************************************************/ +static void Pa_EndUsageCalculation( internalPortAudioStream *past ) +{ + UnsignedWide widePad; + UInt64 CurrentCount; + long InsideCount; + long TotalCount; + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return; +/* Measure CPU utilization during this callback. Note that this calculation +** assumes that we had the processor the whole time. +*/ +#define LOWPASS_COEFFICIENT_0 (0.9) +#define LOWPASS_COEFFICIENT_1 (0.99999 - LOWPASS_COEFFICIENT_0) + Microseconds( &widePad ); + CurrentCount = UnsignedWideToUInt64( widePad ); + if( past->past_IfLastExitValid ) + { + InsideCount = (long) U64Subtract(CurrentCount, pahsc->pahsc_EntryCount); + TotalCount = (long) U64Subtract(CurrentCount, pahsc->pahsc_LastExitCount); +/* Low pass filter the result because sometimes we get called several times in a row. +* That can cause the TotalCount to be very low which can cause the usage to appear +* unnaturally high. So we must filter numerator and denominator separately!!! +*/ + past->past_AverageInsideCount = (( LOWPASS_COEFFICIENT_0 * past->past_AverageInsideCount) + + (LOWPASS_COEFFICIENT_1 * InsideCount)); + past->past_AverageTotalCount = (( LOWPASS_COEFFICIENT_0 * past->past_AverageTotalCount) + + (LOWPASS_COEFFICIENT_1 * TotalCount)); + past->past_Usage = past->past_AverageInsideCount / past->past_AverageTotalCount; + } + pahsc->pahsc_LastExitCount = CurrentCount; + past->past_IfLastExitValid = 1; +} + +#elif WINDOWS + +/********************************* BEGIN CPU UTILIZATION MEASUREMENT ****/ +static void Pa_StartUsageCalculation( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return; +/* Query system timer for usage analysis and to prevent overuse of CPU. */ + QueryPerformanceCounter( &pahsc->pahsc_EntryCount ); +} + +static void Pa_EndUsageCalculation( internalPortAudioStream *past ) +{ + LARGE_INTEGER CurrentCount = { 0, 0 }; + LONGLONG InsideCount; + LONGLONG TotalCount; +/* +** Measure CPU utilization during this callback. Note that this calculation +** assumes that we had the processor the whole time. +*/ +#define LOWPASS_COEFFICIENT_0 (0.9) +#define LOWPASS_COEFFICIENT_1 (0.99999 - LOWPASS_COEFFICIENT_0) + + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return; + + if( QueryPerformanceCounter( &CurrentCount ) ) + { + if( past->past_IfLastExitValid ) + { + InsideCount = CurrentCount.QuadPart - pahsc->pahsc_EntryCount.QuadPart; + TotalCount = CurrentCount.QuadPart - pahsc->pahsc_LastExitCount.QuadPart; +/* Low pass filter the result because sometimes we get called several times in a row. + * That can cause the TotalCount to be very low which can cause the usage to appear + * unnaturally high. So we must filter numerator and denominator separately!!! + */ + past->past_AverageInsideCount = (( LOWPASS_COEFFICIENT_0 * past->past_AverageInsideCount) + + (LOWPASS_COEFFICIENT_1 * InsideCount)); + past->past_AverageTotalCount = (( LOWPASS_COEFFICIENT_0 * past->past_AverageTotalCount) + + (LOWPASS_COEFFICIENT_1 * TotalCount)); + past->past_Usage = past->past_AverageInsideCount / past->past_AverageTotalCount; + } + pahsc->pahsc_LastExitCount = CurrentCount; + past->past_IfLastExitValid = 1; + } +} + +#endif + + + + diff --git a/pd/portaudio_v18/pa_asio/readme_asio_sdk_patch.txt b/pd/portaudio_v18/pa_asio/readme_asio_sdk_patch.txt new file mode 100644 index 00000000..c0fdca7f --- /dev/null +++ b/pd/portaudio_v18/pa_asio/readme_asio_sdk_patch.txt @@ -0,0 +1,25 @@ +There is a bug in the ASIO SDK that causes the Macintosh version to often fail during initialization. Here is a patch that you can apply. + +In codefragments.cpp replace getFrontProcessDirectory function with +the following one (GetFrontProcess replaced by GetCurrentProcess) + + +bool CodeFragments::getFrontProcessDirectory(void *specs) +{ + FSSpec *fss = (FSSpec *)specs; + ProcessInfoRec pif; + ProcessSerialNumber psn; + + memset(&psn,0,(long)sizeof(ProcessSerialNumber)); + // if(GetFrontProcess(&psn) == noErr) // wrong !!! + if(GetCurrentProcess(&psn) == noErr) // correct !!! + { + pif.processName = 0; + pif.processAppSpec = fss; + pif.processInfoLength = sizeof(ProcessInfoRec); + if(GetProcessInformation(&psn, &pif) == noErr) + return true; + } + return false; +} + diff --git a/pd/portaudio_v18/pa_beos/PlaybackNode.cc b/pd/portaudio_v18/pa_beos/PlaybackNode.cc new file mode 100644 index 00000000..a93b8412 --- /dev/null +++ b/pd/portaudio_v18/pa_beos/PlaybackNode.cc @@ -0,0 +1,538 @@ +/* + * $Id: PlaybackNode.cc,v 1.1.1.1 2002/01/22 00:52:07 phil Exp $ + * PortAudio Portable Real-Time Audio Library + * Latest Version at: http://www.portaudio.com + * BeOS Media Kit Implementation by Joshua Haberman + * + * Copyright (c) 2001 Joshua Haberman <joshua@haberman.com> + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * --- + * + * Significant portions of this file are based on sample code from Be. The + * Be Sample Code Licence follows: + * + * Copyright 1991-1999, Be Incorporated. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdio.h> + +#include <be/media/BufferGroup.h> +#include <be/media/Buffer.h> +#include <be/media/TimeSource.h> + +#include "PlaybackNode.h" + +#define PRINT(x) { printf x; fflush(stdout); } + +#ifdef DEBUG +#define DBUG(x) PRINT(x) +#else +#define DBUG(x) +#endif + + +PaPlaybackNode::PaPlaybackNode(uint32 channels, float frame_rate, uint32 frames_per_buffer, + PortAudioCallback* callback, void *user_data) : + BMediaNode("PortAudio input node"), + BBufferProducer(B_MEDIA_RAW_AUDIO), + BMediaEventLooper(), + mAborted(false), + mRunning(false), + mBufferGroup(NULL), + mDownstreamLatency(0), + mStartTime(0), + mCallback(callback), + mUserData(user_data), + mFramesPerBuffer(frames_per_buffer) +{ + DBUG(("Constructor called.\n")); + + mPreferredFormat.type = B_MEDIA_RAW_AUDIO; + mPreferredFormat.u.raw_audio.channel_count = channels; + mPreferredFormat.u.raw_audio.frame_rate = frame_rate; + mPreferredFormat.u.raw_audio.byte_order = + (B_HOST_IS_BENDIAN) ? B_MEDIA_BIG_ENDIAN : B_MEDIA_LITTLE_ENDIAN; + mPreferredFormat.u.raw_audio.buffer_size = + media_raw_audio_format::wildcard.buffer_size; + + mOutput.destination = media_destination::null; + mOutput.format = mPreferredFormat; + + /* The amount of time it takes for this node to produce a buffer when + * asked. Essentially, it is how long the user's callback takes to run. + * We set this to be the length of the sound data each buffer of the + * requested size can hold. */ + //mInternalLatency = (bigtime_t)(1000000 * frames_per_buffer / frame_rate); + + /* ACK! it seems that the mixer (at least on my machine) demands that IT + * specify the buffer size, so for now I'll just make a generic guess here */ + mInternalLatency = 1000000 / 20; +} + + + +PaPlaybackNode::~PaPlaybackNode() +{ + DBUG(("Destructor called.\n")); + Quit(); /* Stop the BMediaEventLooper thread */ +} + + +/************************* + * + * Local methods + * + */ + +bool PaPlaybackNode::IsRunning() +{ + return mRunning; +} + + +PaTimestamp PaPlaybackNode::GetStreamTime() +{ + BTimeSource *timeSource = TimeSource(); + PaTimestamp time = (timeSource->Now() - mStartTime) * + mPreferredFormat.u.raw_audio.frame_rate / 1000000; + return time; +} + + +void PaPlaybackNode::SetSampleFormat(PaSampleFormat inFormat, + PaSampleFormat outFormat) +{ + uint32 beOutFormat; + + switch(outFormat) + { + case paFloat32: + beOutFormat = media_raw_audio_format::B_AUDIO_FLOAT; + mOutputSampleWidth = 4; + break; + + case paInt16: + beOutFormat = media_raw_audio_format::B_AUDIO_SHORT; + mOutputSampleWidth = 2; + break; + + case paInt32: + beOutFormat = media_raw_audio_format::B_AUDIO_INT; + mOutputSampleWidth = 4; + break; + + case paInt8: + beOutFormat = media_raw_audio_format::B_AUDIO_CHAR; + mOutputSampleWidth = 1; + break; + + case paUInt8: + beOutFormat = media_raw_audio_format::B_AUDIO_UCHAR; + mOutputSampleWidth = 1; + break; + + case paInt24: + case paPackedInt24: + case paCustomFormat: + DBUG(("Unsupported output format: %x\n", outFormat)); + break; + + default: + DBUG(("Unknown output format: %x\n", outFormat)); + } + + mPreferredFormat.u.raw_audio.format = beOutFormat; + mFramesPerBuffer * mPreferredFormat.u.raw_audio.channel_count * mOutputSampleWidth; +} + +BBuffer *PaPlaybackNode::FillNextBuffer(bigtime_t time) +{ + /* Get a buffer from the buffer group */ + BBuffer *buf = mBufferGroup->RequestBuffer( + mOutput.format.u.raw_audio.buffer_size, BufferDuration()); + unsigned long frames = mOutput.format.u.raw_audio.buffer_size / + mOutputSampleWidth / mOutput.format.u.raw_audio.channel_count; + bigtime_t start_time; + int ret; + + if( !buf ) + { + DBUG(("Unable to allocate a buffer\n")); + return NULL; + } + + start_time = mStartTime + + (bigtime_t)((double)mSamplesSent / + (double)mOutput.format.u.raw_audio.frame_rate / + (double)mOutput.format.u.raw_audio.channel_count * + 1000000.0); + + /* Now call the user callback to get the data */ + ret = mCallback(NULL, /* Input buffer */ + buf->Data(), /* Output buffer */ + frames, /* Frames per buffer */ + mSamplesSent / mOutput.format.u.raw_audio.channel_count, /* timestamp */ + mUserData); + + if( ret ) + mAborted = true; + + media_header *hdr = buf->Header(); + + hdr->type = B_MEDIA_RAW_AUDIO; + hdr->size_used = mOutput.format.u.raw_audio.buffer_size; + hdr->time_source = TimeSource()->ID(); + hdr->start_time = start_time; + + return buf; +} + + + + +/************************* + * + * BMediaNode methods + * + */ + +BMediaAddOn *PaPlaybackNode::AddOn( int32 * ) const +{ + DBUG(("AddOn() called.\n")); + return NULL; /* we don't provide service to outside applications */ +} + + +status_t PaPlaybackNode::HandleMessage( int32 message, const void *data, + size_t size ) +{ + DBUG(("HandleMessage() called.\n")); + return B_ERROR; /* we don't define any custom messages */ +} + + + + +/************************* + * + * BMediaEventLooper methods + * + */ + +void PaPlaybackNode::NodeRegistered() +{ + DBUG(("NodeRegistered() called.\n")); + + /* Start the BMediaEventLooper thread */ + SetPriority(B_REAL_TIME_PRIORITY); + Run(); + + /* set up as much information about our output as we can */ + mOutput.source.port = ControlPort(); + mOutput.source.id = 0; + mOutput.node = Node(); + ::strcpy(mOutput.name, "PortAudio Playback"); +} + + +void PaPlaybackNode::HandleEvent( const media_timed_event *event, + bigtime_t lateness, bool realTimeEvent ) +{ + // DBUG(("HandleEvent() called.\n")); + status_t err; + + switch(event->type) + { + case BTimedEventQueue::B_START: + DBUG((" Handling a B_START event\n")); + if( RunState() != B_STARTED ) + { + mStartTime = event->event_time + EventLatency(); + mSamplesSent = 0; + mAborted = false; + mRunning = true; + media_timed_event firstEvent( mStartTime, + BTimedEventQueue::B_HANDLE_BUFFER ); + EventQueue()->AddEvent( firstEvent ); + } + break; + + case BTimedEventQueue::B_STOP: + DBUG((" Handling a B_STOP event\n")); + mRunning = false; + EventQueue()->FlushEvents( 0, BTimedEventQueue::B_ALWAYS, true, + BTimedEventQueue::B_HANDLE_BUFFER ); + break; + + case BTimedEventQueue::B_HANDLE_BUFFER: + //DBUG((" Handling a B_HANDLE_BUFFER event\n")); + + /* make sure we're started and connected */ + if( RunState() != BMediaEventLooper::B_STARTED || + mOutput.destination == media_destination::null ) + break; + + BBuffer *buffer = FillNextBuffer(event->event_time); + + /* make sure we weren't aborted while this routine was running. + * this can happen in one of two ways: either the callback returned + * nonzero (in which case mAborted is set in FillNextBuffer() ) or + * the client called AbortStream */ + if( mAborted ) + { + if( buffer ) + buffer->Recycle(); + Stop(0, true); + break; + } + + if( buffer ) + { + err = SendBuffer(buffer, mOutput.destination); + if( err != B_OK ) + buffer->Recycle(); + } + + mSamplesSent += mOutput.format.u.raw_audio.buffer_size / mOutputSampleWidth; + + /* Now schedule the next buffer event, so we can send another + * buffer when this one runs out. We calculate when it should + * happen by calculating when the data we just sent will finish + * playing. + * + * NOTE, however, that the event will actually get generated + * earlier than we specify, to account for the latency it will + * take to produce the buffer. It uses the latency value we + * specified in SetEventLatency() to determine just how early + * to generate it. */ + + /* totalPerformanceTime includes the time represented by the buffer + * we just sent */ + bigtime_t totalPerformanceTime = (bigtime_t)((double)mSamplesSent / + (double)mOutput.format.u.raw_audio.channel_count / + (double)mOutput.format.u.raw_audio.frame_rate * 1000000.0); + + bigtime_t nextEventTime = mStartTime + totalPerformanceTime; + + media_timed_event nextBufferEvent(nextEventTime, + BTimedEventQueue::B_HANDLE_BUFFER); + EventQueue()->AddEvent(nextBufferEvent); + + break; + + } +} + + + + +/************************* + * + * BBufferProducer methods + * + */ + +status_t PaPlaybackNode::FormatSuggestionRequested( media_type type, + int32 /*quality*/, media_format* format ) +{ + /* the caller wants to know this node's preferred format and provides + * a suggestion, asking if we support it */ + DBUG(("FormatSuggestionRequested() called.\n")); + + if(!format) + return B_BAD_VALUE; + + *format = mPreferredFormat; + + /* we only support raw audio (a wildcard is okay too) */ + if ( type == B_MEDIA_UNKNOWN_TYPE || type == B_MEDIA_RAW_AUDIO ) + return B_OK; + else + return B_MEDIA_BAD_FORMAT; +} + + +status_t PaPlaybackNode::FormatProposal( const media_source& output, + media_format* format ) +{ + /* This is similar to FormatSuggestionRequested(), but it is actually part + * of the negotiation process. We're given the opportunity to specify any + * properties that are wildcards (ie. properties that the other node doesn't + * care one way or another about) */ + DBUG(("FormatProposal() called.\n")); + + /* Make sure this proposal really applies to our output */ + if( output != mOutput.source ) + return B_MEDIA_BAD_SOURCE; + + /* We return two things: whether we support the proposed format, and our own + * preferred format */ + *format = mPreferredFormat; + + if( format->type == B_MEDIA_UNKNOWN_TYPE || format->type == B_MEDIA_RAW_AUDIO ) + return B_OK; + else + return B_MEDIA_BAD_FORMAT; +} + + +status_t PaPlaybackNode::FormatChangeRequested( const media_source& source, + const media_destination& destination, media_format* io_format, int32* ) +{ + /* we refuse to change formats, supporting only 1 */ + DBUG(("FormatChangeRequested() called.\n")); + + return B_ERROR; +} + + +status_t PaPlaybackNode::GetNextOutput( int32* cookie, media_output* out_output ) +{ + /* this is where we allow other to enumerate our outputs -- the cookie is + * an integer we can use to keep track of where we are in enumeration. */ + DBUG(("GetNextOutput() called.\n")); + + if( *cookie == 0 ) + { + *out_output = mOutput; + *cookie = 1; + return B_OK; + } + + return B_BAD_INDEX; +} + + +status_t PaPlaybackNode::DisposeOutputCookie( int32 cookie ) +{ + DBUG(("DisposeOutputCookie() called.\n")); + return B_OK; +} + + +void PaPlaybackNode::LateNoticeReceived( const media_source& what, + bigtime_t how_much, bigtime_t performance_time ) +{ + /* This function is called as notification that a buffer we sent wasn't + * received by the time we stamped it with -- it got there late. Basically, + * it means we underestimated our own latency, so we should increase it */ + DBUG(("LateNoticeReceived() called.\n")); + + if( what != mOutput.source ) + return; + + if( RunMode() == B_INCREASE_LATENCY ) + { + mInternalLatency += how_much; + SetEventLatency( mDownstreamLatency + mInternalLatency ); + DBUG(("Increasing latency to %Ld\n", mDownstreamLatency + mInternalLatency)); + } + else + DBUG(("I don't know what to do with this notice!")); +} + + +void PaPlaybackNode::EnableOutput( const media_source& what, bool enabled, + int32* ) +{ + DBUG(("EnableOutput() called.\n")); + /* stub -- we don't support this yet */ +} + + +status_t PaPlaybackNode::PrepareToConnect( const media_source& what, + const media_destination& where, media_format* format, + media_source* out_source, char* out_name ) +{ + /* the final stage of format negotiations. here we _must_ make specific any + * remaining wildcards */ + DBUG(("PrepareToConnect() called.\n")); + + /* make sure this really refers to our source */ + if( what != mOutput.source ) + return B_MEDIA_BAD_SOURCE; + + /* make sure we're not already connected */ + if( mOutput.destination != media_destination::null ) + return B_MEDIA_ALREADY_CONNECTED; + + if( format->type != B_MEDIA_RAW_AUDIO ) + return B_MEDIA_BAD_FORMAT; + + if( format->u.raw_audio.format != mPreferredFormat.u.raw_audio.format ) + return B_MEDIA_BAD_FORMAT; + + if( format->u.raw_audio.buffer_size == + media_raw_audio_format::wildcard.buffer_size ) + { + DBUG(("We were left to decide buffer size: choosing 2048")); + format->u.raw_audio.buffer_size = 2048; + } + else + DBUG(("Using consumer specified buffer size of %lu.\n", + format->u.raw_audio.buffer_size)); + + /* Reserve the connection, return the information */ + mOutput.destination = where; + mOutput.format = *format; + *out_source = mOutput.source; + strncpy( out_name, mOutput.name, B_MEDIA_NAME_LENGTH ); + + return B_OK; +} + + +void PaPlaybackNode::Connect(status_t error, const media_source& source, + const media_destination& destination, const media_format& format, char* io_name) +{ + DBUG(("Connect() called.\n")); + diff --git a/pd/portaudio_v18/pa_beos/PlaybackNode.h b/pd/portaudio_v18/pa_beos/PlaybackNode.h new file mode 100644 index 00000000..c9582056 --- /dev/null +++ b/pd/portaudio_v18/pa_beos/PlaybackNode.h @@ -0,0 +1,108 @@ +/* + * $Id: PlaybackNode.h,v 1.1.1.1 2002/01/22 00:52:08 phil Exp $ + * PortAudio Portable Real-Time Audio Library + * Latest Version at: http://www.portaudio.com + * BeOS Media Kit Implementation by Joshua Haberman + * + * Copyright (c) 2001 Joshua Haberman <joshua@haberman.com> + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#include <be/media/MediaRoster.h> +#include <be/media/MediaEventLooper.h> +#include <be/media/BufferProducer.h> + +#include "portaudio.h" + +class PaPlaybackNode : + public BBufferProducer, + public BMediaEventLooper +{ + +public: + PaPlaybackNode( uint32 channels, float frame_rate, uint32 frames_per_buffer, + PortAudioCallback *callback, void *user_data ); + ~PaPlaybackNode(); + + + /* Local methods ******************************************/ + + BBuffer *FillNextBuffer(bigtime_t time); + void SetSampleFormat(PaSampleFormat inFormat, PaSampleFormat outFormat); + bool IsRunning(); + PaTimestamp GetStreamTime(); + + /* BMediaNode methods *************************************/ + + BMediaAddOn* AddOn( int32 * ) const; + status_t HandleMessage( int32 message, const void *data, size_t size ); + + /* BMediaEventLooper methods ******************************/ + + void HandleEvent( const media_timed_event *event, bigtime_t lateness, + bool realTimeEvent ); + void NodeRegistered(); + + /* BBufferProducer methods ********************************/ + + status_t FormatSuggestionRequested( media_type type, int32 quality, + media_format* format ); + status_t FormatProposal( const media_source& output, media_format* format ); + status_t FormatChangeRequested( const media_source& source, + const media_destination& destination, media_format* io_format, int32* ); + + status_t GetNextOutput( int32* cookie, media_output* out_output ); + status_t DisposeOutputCookie( int32 cookie ); + + void LateNoticeReceived( const media_source& what, bigtime_t how_much, + bigtime_t performance_time ); + void EnableOutput( const media_source& what, bool enabled, int32* _deprecated_ ); + + status_t PrepareToConnect( const media_source& what, + const media_destination& where, media_format* format, + media_source* out_source, char* out_name ); + void Connect(status_t error, const media_source& source, + const media_destination& destination, const media_format& format, + char* io_name); + void Disconnect(const media_source& what, const media_destination& where); + + status_t SetBufferGroup(const media_source& for_source, BBufferGroup* newGroup); + + bool mAborted; + +private: + media_output mOutput; + media_format mPreferredFormat; + uint32 mOutputSampleWidth, mFramesPerBuffer; + BBufferGroup *mBufferGroup; + bigtime_t mDownstreamLatency, mInternalLatency, mStartTime; + uint64 mSamplesSent; + PortAudioCallback *mCallback; + void *mUserData; + bool mRunning; + +}; + diff --git a/pd/portaudio_v18/pa_beos/pa_beos_mk.cc b/pd/portaudio_v18/pa_beos/pa_beos_mk.cc new file mode 100644 index 00000000..ff35cdc3 --- /dev/null +++ b/pd/portaudio_v18/pa_beos/pa_beos_mk.cc @@ -0,0 +1,441 @@ +/* + * $Id: pa_beos_mk.cc,v 1.1.1.1 2002/01/22 00:52:09 phil Exp $ + * PortAudio Portable Real-Time Audio Library + * Latest Version at: http://www.portaudio.com + * BeOS Media Kit Implementation by Joshua Haberman + * + * Copyright (c) 2001 Joshua Haberman <joshua@haberman.com> + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#include <be/app/Application.h> +#include <be/kernel/OS.h> +#include <be/media/RealtimeAlloc.h> +#include <be/media/MediaRoster.h> +#include <be/media/TimeSource.h> + +#include <stdio.h> +#include <string.h> + +#include "portaudio.h" +#include "pa_host.h" + +#include "PlaybackNode.h" + +#define PRINT(x) { printf x; fflush(stdout); } + +#ifdef DEBUG +#define DBUG(x) PRINT(x) +#else +#define DBUG(x) +#endif + +typedef struct PaHostSoundControl +{ + /* These members are common to all modes of operation */ + media_node pahsc_TimeSource; /* the sound card's DAC. */ + media_format pahsc_Format; + + /* These methods are specific to playing mode */ + media_node pahsc_OutputNode; /* output to the mixer */ + media_node pahsc_InputNode; /* reads data from user callback -- PA specific */ + + media_input pahsc_MixerInput; /* input jack on the soundcard's mixer. */ + media_output pahsc_PaOutput; /* output jack from the PA node */ + + PaPlaybackNode *pahsc_InputNodeInstance; + +} +PaHostSoundControl; + +/*************************************************************************/ +PaDeviceID Pa_GetDefaultOutputDeviceID( void ) +{ + /* stub */ + return 0; +} + +/*************************************************************************/ +PaDeviceID Pa_GetDefaultInputDeviceID( void ) +{ + /* stub */ + return 0; +} + +/*************************************************************************/ +const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceID id ) +{ + /* stub */ + return NULL; +} + +/*************************************************************************/ +int Pa_CountDevices() +{ + /* stub */ + return 1; +} + +/*************************************************************************/ +PaError PaHost_Init( void ) +{ + /* we have to create this in order to use BMediaRoster. I hope it doesn't + * cause problems */ + be_app = new BApplication("application/x-vnd.portaudio-app"); + + return paNoError; +} + +PaError PaHost_Term( void ) +{ + delete be_app; + return paNoError; +} + +/*************************************************************************/ +PaError PaHost_StreamActive( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc = (PaHostSoundControl *)past->past_DeviceData; + DBUG(("IsRunning returning: %s\n", + pahsc->pahsc_InputNodeInstance->IsRunning() ? "true" : "false")); + + return (PaError)pahsc->pahsc_InputNodeInstance->IsRunning(); +} + +PaError PaHost_StartOutput( internalPortAudioStream *past ) +{ + return paNoError; +} + +/*************************************************************************/ +PaError PaHost_StartInput( internalPortAudioStream *past ) +{ + return paNoError; +} + +/*************************************************************************/ +PaError PaHost_StopInput( internalPortAudioStream *past, int abort ) +{ + return paNoError; +} + +/*************************************************************************/ +PaError PaHost_StopOutput( internalPortAudioStream *past, int abort ) +{ + return paNoError; +} + + +/*************************************************************************/ +PaError PaHost_StartEngine( internalPortAudioStream *past ) +{ + bigtime_t very_soon, start_latency; + status_t err; + BMediaRoster *roster = BMediaRoster::Roster(&err); + PaHostSoundControl *pahsc = (PaHostSoundControl *)past->past_DeviceData; + + /* for some reason, err indicates an error (though nothing it wrong) + * when the DBUG macro in pa_lib.c is enabled. It's reproducably + * linked. Weird. */ + if( !roster /* || err != B_OK */ ) + { + DBUG(("No media server! err=%d, roster=%x\n", err, roster)); + return paHostError; + } + + /* tell the node when to start -- since there aren't any other nodes + * starting that we have to wait for, just tell it to start now + */ + + BTimeSource *timeSource = roster->MakeTimeSourceFor(pahsc->pahsc_TimeSource); + very_soon = timeSource->PerformanceTimeFor( BTimeSource::RealTime() ); + timeSource->Release(); + + /* Add the latency of starting the network of nodes */ + err = roster->GetStartLatencyFor( pahsc->pahsc_TimeSource, &start_latency ); + very_soon += start_latency; + + err = roster->StartNode( pahsc->pahsc_InputNode, very_soon ); + /* No need to start the mixer -- it's always running */ + + return paNoError; +} + + +/*************************************************************************/ +PaError PaHost_StopEngine( internalPortAudioStream *past, int abort ) +{ + PaHostSoundControl *pahsc = (PaHostSoundControl *)past->past_DeviceData; + BMediaRoster *roster = BMediaRoster::Roster(); + + if( !roster ) + { + DBUG(("No media roster!\n")); + return paHostError; + } + + if( !pahsc ) + return paHostError; + + /* this crashes, and I don't know why yet */ + // if( abort ) + // pahsc->pahsc_InputNodeInstance->mAborted = true; + + roster->StopNode(pahsc->pahsc_InputNode, 0, /* immediate = */ true); + + return paNoError; +} + + +/*************************************************************************/ +PaError PaHost_OpenStream( internalPortAudioStream *past ) +{ + status_t err; + BMediaRoster *roster = BMediaRoster::Roster(&err); + PaHostSoundControl *pahsc; + + /* Allocate and initialize host data. */ + pahsc = (PaHostSoundControl *) PaHost_AllocateFastMemory(sizeof(PaHostSoundControl)); + if( pahsc == NULL ) + { + goto error; + } + memset( pahsc, 0, sizeof(PaHostSoundControl) ); + past->past_DeviceData = (void *) pahsc; + + if( !roster /* || err != B_OK */ ) + { + /* no media server! */ + DBUG(("No media server.\n")); + goto error; + } + + if ( past->past_NumInputChannels > 0 && past->past_NumOutputChannels > 0 ) + { + /* filter -- not implemented yet */ + goto error; + } + else if ( past->past_NumInputChannels > 0 ) + { + /* recorder -- not implemented yet */ + goto error; + } + else + { + /* player ****************************************************************/ + + status_t err; + int32 num; + + /* First we need to create the three components (like components in a stereo + * system). The mixer component is our interface to the sound card, data + * we write there will get played. The BePA_InputNode component is the node + * which represents communication with the PA client (it is what calls the + * client's callbacks). The time source component is the sound card's DAC, + * which allows us to slave the other components to it instead of the system + * clock. */ + err = roster->GetAudioMixer( &pahsc->pahsc_OutputNode ); + if( err != B_OK ) + { + DBUG(("Couldn't get default mixer.\n")); + goto error; + } + + err = roster->GetTimeSource( &pahsc->pahsc_TimeSource ); + if( err != B_OK ) + { + DBUG(("Couldn't get time source.\n")); + goto error; + } + + pahsc->pahsc_InputNodeInstance = new PaPlaybackNode(2, 44100, + past->past_FramesPerUserBuffer, past->past_Callback, past->past_UserData ); + pahsc->pahsc_InputNodeInstance->SetSampleFormat(0, + past->past_OutputSampleFormat); + err = roster->RegisterNode( pahsc->pahsc_InputNodeInstance ); + if( err != B_OK ) + { + DBUG(("Unable to register node.\n")); + goto error; + } + + roster->GetNodeFor( pahsc->pahsc_InputNodeInstance->Node().node, + &pahsc->pahsc_InputNode ); + if( err != B_OK ) + { + DBUG(("Unable to get input node.\n")); + goto error; + } + + /* Now we have three components (nodes) sitting next to each other. The + * next step is to look at them and find their inputs and outputs so we can + * wire them together. */ + err = roster->GetFreeInputsFor( pahsc->pahsc_OutputNode, + &pahsc->pahsc_MixerInput, 1, &num, B_MEDIA_RAW_AUDIO ); + if( err != B_OK || num < 1 ) + { + DBUG(("Couldn't get the mixer input.\n")); + goto error; + } + + err = roster->GetFreeOutputsFor( pahsc->pahsc_InputNode, + &pahsc->pahsc_PaOutput, 1, &num, B_MEDIA_RAW_AUDIO ); + if( err != B_OK || num < 1 ) + { + DBUG(("Couldn't get PortAudio output.\n")); + goto error; + } + + + /* We've found the input and output -- the final step is to run a wire + * between them so they are connected. */ + + /* try to make the mixer input adapt to what PA sends it */ + pahsc->pahsc_Format = pahsc->pahsc_PaOutput.format; + roster->Connect( pahsc->pahsc_PaOutput.source, + pahsc->pahsc_MixerInput.destination, &pahsc->pahsc_Format, + &pahsc->pahsc_PaOutput, &pahsc->pahsc_MixerInput ); + + + /* Actually, there's one final step -- tell them all to sync to the + * sound card's DAC */ + roster->SetTimeSourceFor( pahsc->pahsc_InputNode.node, + pahsc->pahsc_TimeSource.node ); + roster->SetTimeSourceFor( pahsc->pahsc_OutputNode.node, + pahsc->pahsc_TimeSource.node ); + + } + + return paNoError; + +error: + PaHost_CloseStream( past ); + return paHostError; +} + +/*************************************************************************/ +PaError PaHost_CloseStream( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc = (PaHostSoundControl *)past->past_DeviceData; + status_t err; + BMediaRoster *roster = BMediaRoster::Roster(&err); + + if( !roster ) + { + DBUG(("Couldn't get media roster\n")); + return paHostError; + } + + if( !pahsc ) + return paHostError; + + /* Disconnect all the connections we made when opening the stream */ + + roster->Disconnect(pahsc->pahsc_InputNode.node, pahsc->pahsc_PaOutput.source, + pahsc->pahsc_OutputNode.node, pahsc->pahsc_MixerInput.destination); + + DBUG(("Calling ReleaseNode()")); + roster->ReleaseNode(pahsc->pahsc_InputNode); + + /* deleting the node shouldn't be necessary -- it is reference counted, and will + * delete itself when its references drop to zero. the call to ReleaseNode() + * above should decrease its reference count */ + pahsc->pahsc_InputNodeInstance = NULL; + + return paNoError; +} + +/*************************************************************************/ +PaTimestamp Pa_StreamTime( PortAudioStream *stream ) +{ + internalPortAudioStream *past = (internalPortAudioStream *) stream; + PaHostSoundControl *pahsc = (PaHostSoundControl *)past->past_DeviceData; + + return pahsc->pahsc_InputNodeInstance->GetStreamTime(); +} + +/*************************************************************************/ +void Pa_Sleep( long msec ) +{ + /* snooze() takes microseconds */ + snooze( msec * 1000 ); +} + +/************************************************************************* + * Allocate memory that can be accessed in real-time. + * This may need to be held in physical memory so that it is not + * paged to virtual memory. + * This call MUST be balanced with a call to PaHost_FreeFastMemory(). + * Memory will be set to zero. + */ +void *PaHost_AllocateFastMemory( long numBytes ) +{ + /* BeOS supports non-pagable memory through pools -- a pool is an area + * of physical memory that is locked. It would be best to pre-allocate + * that pool and then hand out memory from it, but we don't know in + * advance how much we'll need. So for now, we'll allocate a pool + * for every request we get, storing a pointer to the pool at the + * beginning of the allocated memory */ + rtm_pool *pool; + void *addr; + long size = numBytes + sizeof(rtm_pool *); + static int counter = 0; + char pool_name[100]; + + /* Every pool needs a unique name. */ + sprintf(pool_name, "PaPoolNumber%d", counter++); + + if( rtm_create_pool( &pool, size, pool_name ) != B_OK ) + return 0; + + addr = rtm_alloc( pool, size ); + if( addr == NULL ) + return 0; + + memset( addr, 0, numBytes ); + *((rtm_pool **)addr) = pool; // store the pointer to the pool + addr = (rtm_pool **)addr + 1; // and return the next location in memory + + return addr; +} + +/************************************************************************* + * Free memory that could be accessed in real-time. + * This call MUST be balanced with a call to PaHost_AllocateFastMemory(). + */ +void PaHost_FreeFastMemory( void *addr, long numBytes ) +{ + rtm_pool *pool; + + if( addr == NULL ) + return; + + addr = (rtm_pool **)addr - 1; + pool = *((rtm_pool **)addr); + + rtm_free( addr ); + rtm_delete_pool( pool ); +} diff --git a/pd/portaudio_v18/pa_dll_switch/PaDllEntry.h b/pd/portaudio_v18/pa_dll_switch/PaDllEntry.h new file mode 100644 index 00000000..e070054b --- /dev/null +++ b/pd/portaudio_v18/pa_dll_switch/PaDllEntry.h @@ -0,0 +1,184 @@ + +/* + * PortAudio Portable Real-Time Audio Library + * PortAudio DLL Header File + * Latest version available at: http://www.audiomulch.com/portaudio/ + * + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +// changed by zplane.developement in order to generate a DLL + +#ifndef __PADLLENTRY_HEADER_INCLUDED__ + +#define __PADLLENTRY_HEADER_INCLUDED__ + +typedef int PaError; +typedef enum { + paNoError = 0, + + paHostError = -10000, + paInvalidChannelCount, + paInvalidSampleRate, + paInvalidDeviceId, + paInvalidFlag, + paSampleFormatNotSupported, + paBadIODeviceCombination, + paInsufficientMemory, + paBufferTooBig, + paBufferTooSmall, + paNullCallback, + paBadStreamPtr, + paTimedOut, + paInternalError +} PaErrorNum; + +typedef unsigned long PaSampleFormat; +#define paFloat32 ((PaSampleFormat) (1<<0)) /*always available*/ +#define paInt16 ((PaSampleFormat) (1<<1)) /*always available*/ +#define paInt32 ((PaSampleFormat) (1<<2)) /*always available*/ +#define paInt24 ((PaSampleFormat) (1<<3)) +#define paPackedInt24 ((PaSampleFormat) (1<<4)) +#define paInt8 ((PaSampleFormat) (1<<5)) +#define paUInt8 ((PaSampleFormat) (1<<6)) /* unsigned 8 bit, 128 is "ground" */ +#define paCustomFormat ((PaSampleFormat) (1<<16)) + + +typedef int PaDeviceID; +#define paNoDevice -1 + +typedef struct +{ + int structVersion; + const char *name; + int maxInputChannels; + int maxOutputChannels; + /* Number of discrete rates, or -1 if range supported. */ + int numSampleRates; + /* Array of supported sample rates, or {min,max} if range supported. */ + const double *sampleRates; + PaSampleFormat nativeSampleFormats; +} +PaDeviceInfo; + + +typedef double PaTimestamp; + + +typedef int (PortAudioCallback)( + void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ); + + +#define paNoFlag (0) +#define paClipOff (1<<0) /* disable default clipping of out of range samples */ +#define paDitherOff (1<<1) /* disable default dithering */ +#define paPlatformSpecificFlags (0x00010000) +typedef unsigned long PaStreamFlags; + +typedef void PortAudioStream; +#define PaStream PortAudioStream + +extern PaError (__cdecl* Pa_Initialize)( void ); + + + +extern PaError (__cdecl* Pa_Terminate)( void ); + + +extern long (__cdecl* Pa_GetHostError)( void ); + + +extern const char* (__cdecl* Pa_GetErrorText)( PaError ); + + + +extern int (__cdecl* Pa_CountDevices)(void); + +extern PaDeviceID (__cdecl* Pa_GetDefaultInputDeviceID)( void ); + +extern PaDeviceID (__cdecl* Pa_GetDefaultOutputDeviceID)( void ); + + +extern const PaDeviceInfo* (__cdecl* Pa_GetDeviceInfo)( PaDeviceID); + + + +extern PaError (__cdecl* Pa_OpenStream)( + PortAudioStream ** , + PaDeviceID , + int , + PaSampleFormat , + void *, + PaDeviceID , + int , + PaSampleFormat , + void *, + double , + unsigned long , + unsigned long , + unsigned long , + PortAudioCallback *, + void * ); + + + +extern PaError (__cdecl* Pa_OpenDefaultStream)( PortAudioStream** stream, + int numInputChannels, + int numOutputChannels, + PaSampleFormat sampleFormat, + double sampleRate, + unsigned long framesPerBuffer, + unsigned long numberOfBuffers, + PortAudioCallback *callback, + void *userData ); + + +extern PaError (__cdecl* Pa_CloseStream)( PortAudioStream* ); + + +extern PaError (__cdecl* Pa_StartStream)( PortAudioStream *stream ); + +extern PaError (__cdecl* Pa_StopStream)( PortAudioStream *stream ); + +extern PaError (__cdecl* Pa_AbortStream)( PortAudioStream *stream ); + +extern PaError (__cdecl* Pa_StreamActive)( PortAudioStream *stream ); + +extern PaTimestamp (__cdecl* Pa_StreamTime)( PortAudioStream *stream ); + +extern double (__cdecl* Pa_GetCPULoad)( PortAudioStream* stream ); + +extern int (__cdecl* Pa_GetMinNumBuffers)( int framesPerBuffer, double sampleRate ); + +extern void (__cdecl* Pa_Sleep)( long msec ); + +extern PaError (__cdecl* Pa_GetSampleSize)( PaSampleFormat format ); + +#endif // __PADLLENTRY_HEADER_INCLUDED__ + diff --git a/pd/portaudio_v18/pa_dll_switch/letter_from_tim_010817.txt b/pd/portaudio_v18/pa_dll_switch/letter_from_tim_010817.txt Binary files differnew file mode 100644 index 00000000..a535cd1d --- /dev/null +++ b/pd/portaudio_v18/pa_dll_switch/letter_from_tim_010817.txt diff --git a/pd/portaudio_v18/pa_dll_switch/loadPA_DLL.cpp b/pd/portaudio_v18/pa_dll_switch/loadPA_DLL.cpp new file mode 100644 index 00000000..043eda87 --- /dev/null +++ b/pd/portaudio_v18/pa_dll_switch/loadPA_DLL.cpp @@ -0,0 +1,203 @@ +////////////////////////////////////////////////////////////////////////// + + +HINSTANCE pPaDll; + +/* + the function pointers to the PortAudio DLLs +*/ + +PaError (__cdecl* Pa_Initialize)( void ); + + + +PaError (__cdecl* Pa_Terminate)( void ); + + +long (__cdecl* Pa_GetHostError)( void ); + + +const char* (__cdecl* Pa_GetErrorText)( PaError ); + + +int (__cdecl* Pa_CountDevices)(void); + +PaDeviceID (__cdecl* Pa_GetDefaultInputDeviceID)( void ); + +PaDeviceID (__cdecl* Pa_GetDefaultOutputDeviceID)( void ); + + +const PaDeviceInfo* (__cdecl* Pa_GetDeviceInfo)( PaDeviceID); + + + +PaError (__cdecl* Pa_OpenStream)( + PortAudioStream ** , + PaDeviceID , + int , + PaSampleFormat , + void *, + PaDeviceID , + int , + PaSampleFormat , + void *, + double , + unsigned long , + unsigned long , + unsigned long , + PortAudioCallback *, + void * ); + + + +PaError (__cdecl* Pa_OpenDefaultStream)( PortAudioStream** stream, + int numInputChannels, + int numOutputChannels, + PaSampleFormat sampleFormat, + double sampleRate, + unsigned long framesPerBuffer, + unsigned long numberOfBuffers, + PortAudioCallback *callback, + void *userData ); + + +PaError (__cdecl* Pa_CloseStream)( PortAudioStream* ); + + +PaError (__cdecl* Pa_StartStream)( PortAudioStream *stream ); + +PaError (__cdecl* Pa_StopStream)( PortAudioStream *stream ); + +PaError (__cdecl* Pa_AbortStream)( PortAudioStream *stream ); + +PaError (__cdecl* Pa_StreamActive)( PortAudioStream *stream ); + +PaTimestamp (__cdecl* Pa_StreamTime)( PortAudioStream *stream ); + +double (__cdecl* Pa_GetCPULoad)( PortAudioStream* stream ); + +int (__cdecl* Pa_GetMinNumBuffers)( int framesPerBuffer, double sampleRate ); + +void (__cdecl* Pa_Sleep)( long msec ); + +PaError (__cdecl* Pa_GetSampleSize)( PaSampleFormat format ); + + +////////////////////////////////////////////////////////////////////////// + +... + +ZERROR AudioEngine::DirectXSupport(ZBOOL bSupDX) +{ + if (bSupDX) + if (CheckForDirectXSupport()) + bSupportDirectX = _TRUE; + else + return _NO_SOUND; + else + bSupportDirectX = _FALSE; + return _NO_ERROR; +} + + + +ZBOOL AudioEngine::CheckForDirectXSupport() +{ + HMODULE pTestDXLib; + FARPROC pFunctionality; + + pTestDXLib=LoadLibrary("DSOUND"); + if (pTestDXLib!=NULL) // check if there is a DirectSound + { + pFunctionality = GetProcAddress(pTestDXLib, (char*) 7); + if (pFunctionality!=NULL) + { + FreeLibrary(pTestDXLib); + return _TRUE; + } + else + { + FreeLibrary(pTestDXLib); + return _FALSE; + } + } + else + return _FALSE; +} + + +ZERROR AudioEngine::LoadPALib() +{ +#ifdef _DEBUG + if (bSupportDirectX) + pPaDll = LoadLibrary("PA_DXD"); + else + pPaDll = LoadLibrary("PA_MMED"); +#else + if (bSupportDirectX) + pPaDll = LoadLibrary("PA_DX"); + else + pPaDll = LoadLibrary("PA_MME"); +#endif + if (pPaDll!=NULL) + { + + Pa_Initialize = (int (__cdecl*)(void))GetProcAddress(pPaDll,"Pa_Initialize"); + Pa_Terminate = (int (__cdecl*)(void))GetProcAddress(pPaDll,"Pa_Terminate"); + Pa_GetHostError = (long (__cdecl* )( void )) GetProcAddress(pPaDll,"Pa_GetHostError"); + Pa_GetErrorText = (const char* (__cdecl* )( PaError )) GetProcAddress(pPaDll,"Pa_GetErrorText"); + Pa_CountDevices = (int (__cdecl*)(void))GetProcAddress(pPaDll,"Pa_CountDevices"); + Pa_GetDefaultInputDeviceID = (int (__cdecl*)(void))GetProcAddress(pPaDll,"Pa_GetDefaultInputDeviceID"); + Pa_GetDefaultOutputDeviceID = (int (__cdecl*)(void))GetProcAddress(pPaDll,"Pa_GetDefaultOutputDeviceID"); + Pa_GetDeviceInfo = (const PaDeviceInfo* (__cdecl* )( PaDeviceID)) GetProcAddress(pPaDll,"Pa_GetDeviceInfo"); + Pa_OpenStream = ( PaError (__cdecl* )( + PortAudioStream ** , + PaDeviceID , + int , + PaSampleFormat , + void *, + PaDeviceID , + int , + PaSampleFormat , + void *, + double , + unsigned long , + unsigned long , + unsigned long , + PortAudioCallback *, + void * )) GetProcAddress(pPaDll,"Pa_OpenStream"); + + Pa_OpenDefaultStream = (PaError (__cdecl* )( PortAudioStream** , + int , + int , + PaSampleFormat , + double , + unsigned long , + unsigned long , + PortAudioCallback *, + void * )) GetProcAddress(pPaDll,"Pa_OpenDefaultStream"); + Pa_CloseStream = (PaError (__cdecl* )( PortAudioStream* )) GetProcAddress(pPaDll,"Pa_CloseStream"); + Pa_StartStream = (PaError (__cdecl* )( PortAudioStream* )) GetProcAddress(pPaDll,"Pa_StartStream"); + Pa_StopStream = (PaError (__cdecl* )( PortAudioStream* ))GetProcAddress(pPaDll,"Pa_StopStream"); + Pa_AbortStream = (PaError (__cdecl* )( PortAudioStream* )) GetProcAddress(pPaDll,"Pa_AbortStream"); + Pa_StreamActive = (PaError (__cdecl* )( PortAudioStream* )) GetProcAddress(pPaDll,"Pa_StreamActive"); + Pa_StreamTime = (PaTimestamp (__cdecl* )( PortAudioStream *))GetProcAddress(pPaDll,"Pa_StreamTime"); + Pa_GetCPULoad = (double (__cdecl* )( PortAudioStream* ))GetProcAddress(pPaDll,"Pa_GetCPULoad"); + Pa_GetMinNumBuffers = (int (__cdecl* )( int , double )) GetProcAddress(pPaDll,"Pa_GetMinNumBuffers"); + Pa_Sleep = (void (__cdecl* )( long )) GetProcAddress(pPaDll,"Pa_Sleep"); + Pa_GetSampleSize = (PaError (__cdecl* )( PaSampleFormat )) GetProcAddress(pPaDll,"Pa_GetSampleSize"); + + return _NO_ERROR; + } + else + return _DLL_NOT_FOUND; +} + +ZERROR AudioEngine::UnLoadPALib() +{ + if (pPaDll!=NULL) + FreeLibrary(pPaDll); + return _NO_ERROR; +} + +... diff --git a/pd/portaudio_v18/pa_dll_switch/pa_lib.c b/pd/portaudio_v18/pa_dll_switch/pa_lib.c new file mode 100644 index 00000000..86601592 --- /dev/null +++ b/pd/portaudio_v18/pa_dll_switch/pa_lib.c @@ -0,0 +1,827 @@ +/* + * Portable Audio I/O Library + * Host Independant Layer + * + * Based on the Open Source API proposed by Ross Bencina + * Copyright (c) 1999-2000 Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +/* Modification History: + PLB20010422 - apply Mike Berry's changes for CodeWarrior on PC +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> + +/* PLB20010422 - "memory.h" doesn't work on CodeWarrior for PC. Thanks Mike Berry for the mod. */ +#ifdef _WIN32 +#ifndef __MWERKS__ +#include <memory.h> +#endif /* __MWERKS__ */ +#else /* !_WIN32 */ +#include <memory.h> +#endif /* _WIN32 */ + +#include "portaudio.h" +#include "pa_host.h" +#include "pa_trace.h" + +/* The reason we might NOT want to validate the rate before opening the stream + * is because many DirectSound drivers lie about the rates they actually support. + */ +#define PA_VALIDATE_RATE (0) /* If true validate sample rate against driver info. */ + +/* +O- maybe not allocate past_InputBuffer and past_OutputBuffer if not needed for conversion +*/ + +#ifndef FALSE + #define FALSE (0) + #define TRUE (!FALSE) +#endif + +#define PRINT(x) { printf x; fflush(stdout); } +#define ERR_RPT(x) PRINT(x) +#define DBUG(x) /* PRINT(x) */ +#define DBUGX(x) /* PRINT(x) */ + +static int gInitCount = 0; /* Count number of times Pa_Initialize() called to allow nesting and overlapping. */ + +static PaError Pa_KillStream( PortAudioStream *stream, int abort ); + +/***********************************************************************/ +int PaHost_FindClosestTableEntry( double allowableError, const double *rateTable, int numRates, double frameRate ) +{ + double err, minErr = allowableError; + int i, bestFit = -1; + + for( i=0; i<numRates; i++ ) + { + err = fabs( frameRate - rateTable[i] ); + if( err < minErr ) + { + minErr = err; + bestFit = i; + } + } + return bestFit; +} + +/************************************************************************** +** Make sure sample rate is legal and also convert to enumeration for driver. +*/ +PaError PaHost_ValidateSampleRate( PaDeviceID id, double requestedFrameRate, + double *closestFrameRatePtr ) +{ + long bestRateIndex; + const PaDeviceInfo *pdi; + pdi = Pa_GetDeviceInfo( id ); + if( pdi == NULL ) return paInvalidDeviceId; + + if( pdi->numSampleRates == -1 ) + { + /* Is it out of range? */ + if( (requestedFrameRate < pdi->sampleRates[0]) || + (requestedFrameRate > pdi->sampleRates[1]) ) + { + return paInvalidSampleRate; + } + + *closestFrameRatePtr = requestedFrameRate; + } + else + { + bestRateIndex = PaHost_FindClosestTableEntry( 1.0, pdi->sampleRates, pdi->numSampleRates, requestedFrameRate ); + if( bestRateIndex < 0 ) return paInvalidSampleRate; + *closestFrameRatePtr = pdi->sampleRates[bestRateIndex]; + } + return paNoError; +} + +/*************************************************************************/ +DLL_API PaError Pa_OpenStream( + PortAudioStream** streamPtrPtr, + PaDeviceID inputDeviceID, + int numInputChannels, + PaSampleFormat inputSampleFormat, + void *inputDriverInfo, + PaDeviceID outputDeviceID, + int numOutputChannels, + PaSampleFormat outputSampleFormat, + void *outputDriverInfo, + double sampleRate, + unsigned long framesPerBuffer, + unsigned long numberOfBuffers, + unsigned long streamFlags, + PortAudioCallback *callback, + void *userData ) +{ + internalPortAudioStream *past = NULL; + PaError result = paNoError; + int bitsPerInputSample; + int bitsPerOutputSample; + /* Print passed parameters. */ + DBUG(("Pa_OpenStream( %p, %d, %d, %d, %p, /* input */ \n", + streamPtrPtr, inputDeviceID, numInputChannels, + inputSampleFormat, inputDriverInfo )); + DBUG((" %d, %d, %d, %p, /* output */\n", + outputDeviceID, numOutputChannels, + outputSampleFormat, outputDriverInfo )); + DBUG((" %g, %d, %d, 0x%x, , %p )\n", + sampleRate, framesPerBuffer, numberOfBuffers, + streamFlags, userData )); + + /* Check for parameter errors. */ + if( (streamFlags & ~(paClipOff | paDitherOff)) != 0 ) return paInvalidFlag; + if( streamPtrPtr == NULL ) return paBadStreamPtr; + if( inputDriverInfo != NULL ) return paHostError; /* REVIEW */ + if( outputDriverInfo != NULL ) return paHostError; /* REVIEW */ + if( (inputDeviceID < 0) && ( outputDeviceID < 0) ) return paInvalidDeviceId; + if( (outputDeviceID >= Pa_CountDevices()) || (inputDeviceID >= Pa_CountDevices()) ) return paInvalidDeviceId; + if( (numInputChannels <= 0) && ( numOutputChannels <= 0) ) return paInvalidChannelCount; + +#if SUPPORT_AUDIO_CAPTURE + if( inputDeviceID >= 0 ) + { + PaError size = Pa_GetSampleSize( inputSampleFormat ); + if( size < 0 ) return size; + bitsPerInputSample = 8 * size; + if( (numInputChannels <= 0) ) return paInvalidChannelCount; + } +#else + if( inputDeviceID >= 0 ) + { + return paInvalidChannelCount; + } +#endif /* SUPPORT_AUDIO_CAPTURE */ + else + { + if( numInputChannels > 0 ) return paInvalidChannelCount; + bitsPerInputSample = 0; + } + + if( outputDeviceID >= 0 ) + { + PaError size = Pa_GetSampleSize( outputSampleFormat ); + if( size < 0 ) return size; + bitsPerOutputSample = 8 * size; + if( (numOutputChannels <= 0) ) return paInvalidChannelCount; + } + else + { + if( numOutputChannels > 0 ) return paInvalidChannelCount; + bitsPerOutputSample = 0; + } + + if( callback == NULL ) return paNullCallback; + + /* Allocate and clear stream structure. */ + past = (internalPortAudioStream *) PaHost_AllocateFastMemory( sizeof(internalPortAudioStream) ); + if( past == NULL ) return paInsufficientMemory; + memset( past, 0, sizeof(internalPortAudioStream) ); + AddTraceMessage("Pa_OpenStream: past", (long) past ); + + past->past_Magic = PA_MAGIC; /* Set ID to catch bugs. */ + past->past_FramesPerUserBuffer = framesPerBuffer; + past->past_NumUserBuffers = numberOfBuffers; /* NOTE - PaHost_OpenStream() NMUST CHECK FOR ZERO! */ + past->past_Callback = callback; + past->past_UserData = userData; + past->past_OutputSampleFormat = outputSampleFormat; + past->past_InputSampleFormat = inputSampleFormat; + past->past_OutputDeviceID = outputDeviceID; + past->past_InputDeviceID = inputDeviceID; + past->past_NumInputChannels = numInputChannels; + past->past_NumOutputChannels = numOutputChannels; + past->past_Flags = streamFlags; + + /* Check for absurd sample rates. */ + if( (sampleRate < 1000.0) || (sampleRate > 200000.0) ) + { + result = paInvalidSampleRate; + goto cleanup; + } + + /* Allocate buffers that may be used for format conversion from user to native buffers. */ + if( numInputChannels > 0 ) + { + +#if PA_VALIDATE_RATE + result = PaHost_ValidateSampleRate( inputDeviceID, sampleRate, &past->past_SampleRate ); + if( result < 0 ) + { + goto cleanup; + } +#else + past->past_SampleRate = sampleRate; +#endif + /* Allocate single Input buffer. */ + past->past_InputBufferSize = framesPerBuffer * numInputChannels * ((bitsPerInputSample+7) / 8); + past->past_InputBuffer = PaHost_AllocateFastMemory(past->past_InputBufferSize); + if( past->past_InputBuffer == NULL ) + { + result = paInsufficientMemory; + goto cleanup; + } + } + else + { + past->past_InputBuffer = NULL; + } + + /* Allocate single Output buffer. */ + if( numOutputChannels > 0 ) + { +#if PA_VALIDATE_RATE + result = PaHost_ValidateSampleRate( outputDeviceID, sampleRate, &past->past_SampleRate ); + if( result < 0 ) + { + goto cleanup; + } +#else + past->past_SampleRate = sampleRate; +#endif + past->past_OutputBufferSize = framesPerBuffer * numOutputChannels * ((bitsPerOutputSample+7) / 8); + past->past_OutputBuffer = PaHost_AllocateFastMemory(past->past_OutputBufferSize); + if( past->past_OutputBuffer == NULL ) + { + result = paInsufficientMemory; + goto cleanup; + } + } + else + { + past->past_OutputBuffer = NULL; + } + + result = PaHost_OpenStream( past ); + if( result < 0 ) goto cleanup; + + *streamPtrPtr = (void *) past; + + return result; + +cleanup: + if( past != NULL ) Pa_CloseStream( past ); + *streamPtrPtr = NULL; + return result; +} + + +/*************************************************************************/ +DLL_API PaError Pa_OpenDefaultStream( PortAudioStream** stream, + int numInputChannels, + int numOutputChannels, + PaSampleFormat sampleFormat, + double sampleRate, + unsigned long framesPerBuffer, + unsigned long numberOfBuffers, + PortAudioCallback *callback, + void *userData ) +{ + return Pa_OpenStream( + stream, + ((numInputChannels > 0) ? Pa_GetDefaultInputDeviceID() : paNoDevice), + numInputChannels, sampleFormat, NULL, + ((numOutputChannels > 0) ? Pa_GetDefaultOutputDeviceID() : paNoDevice), + numOutputChannels, sampleFormat, NULL, + sampleRate, framesPerBuffer, numberOfBuffers, paNoFlag, callback, userData ); +} + +/*************************************************************************/ +DLL_API PaError Pa_CloseStream( PortAudioStream* stream) +{ + PaError result; + internalPortAudioStream *past; + + DBUG(("Pa_CloseStream()\n")); + if( stream == NULL ) return paBadStreamPtr; + past = (internalPortAudioStream *) stream; + + Pa_AbortStream( past ); + result = PaHost_CloseStream( past ); + + if( past->past_InputBuffer ) PaHost_FreeFastMemory( past->past_InputBuffer, past->past_InputBufferSize ); + if( past->past_OutputBuffer ) PaHost_FreeFastMemory( past->past_OutputBuffer, past->past_OutputBufferSize ); + PaHost_FreeFastMemory( past, sizeof(internalPortAudioStream) ); + + return result; +} + +/*************************************************************************/ +DLL_API PaError Pa_StartStream( PortAudioStream *stream ) +{ + PaError result = paHostError; + internalPortAudioStream *past; + + if( stream == NULL ) return paBadStreamPtr; + past = (internalPortAudioStream *) stream; + + past->past_FrameCount = 0.0; + + if( past->past_NumInputChannels > 0 ) + { + result = PaHost_StartInput( past ); + DBUG(("Pa_StartStream: PaHost_StartInput returned = 0x%X.\n", result)); + if( result < 0 ) goto error; + } + + if( past->past_NumOutputChannels > 0 ) + { + result = PaHost_StartOutput( past ); + DBUG(("Pa_StartStream: PaHost_StartOutput returned = 0x%X.\n", result)); + if( result < 0 ) goto error; + } + + result = PaHost_StartEngine( past ); + DBUG(("Pa_StartStream: PaHost_StartEngine returned = 0x%X.\n", result)); + if( result < 0 ) goto error; + + return paNoError; + +error: + return result; +} + +/*************************************************************************/ +DLL_API PaError Pa_StopStream( PortAudioStream *stream ) +{ + return Pa_KillStream( stream, 0 ); +} + +/*************************************************************************/ +DLL_API PaError Pa_AbortStream( PortAudioStream *stream ) +{ + return Pa_KillStream( stream, 1 ); +} + +/*************************************************************************/ +static PaError Pa_KillStream( PortAudioStream *stream, int abort ) +{ + PaError result = paNoError; + internalPortAudioStream *past; + + DBUG(("Pa_StopStream().\n")); + if( stream == NULL ) return paBadStreamPtr; + past = (internalPortAudioStream *) stream; + + if( (past->past_NumInputChannels > 0) || (past->past_NumOutputChannels > 0) ) + { + result = PaHost_StopEngine( past, abort ); + DBUG(("Pa_StopStream: PaHost_StopEngine returned = 0x%X.\n", result)); + if( result < 0 ) goto error; + } + + if( past->past_NumInputChannels > 0 ) + { + result = PaHost_StopInput( past, abort ); + DBUG(("Pa_StopStream: PaHost_StopInput returned = 0x%X.\n", result)); + if( result != paNoError ) goto error; + } + + if( past->past_NumOutputChannels > 0 ) + { + result = PaHost_StopOutput( past, abort ); + DBUG(("Pa_StopStream: PaHost_StopOutput returned = 0x%X.\n", result)); + if( result != paNoError ) goto error; + } + +error: + past->past_Usage = 0; + past->past_IfLastExitValid = 0; + + return result; +} + +/*************************************************************************/ +DLL_API PaError Pa_StreamActive( PortAudioStream *stream ) +{ + internalPortAudioStream *past; + if( stream == NULL ) return paBadStreamPtr; + past = (internalPortAudioStream *) stream; + return PaHost_StreamActive( past ); +} + +/*************************************************************************/ +DLL_API const char *Pa_GetErrorText( PaError errnum ) +{ + const char *msg; + + switch(errnum) + { + case paNoError: msg = "Success"; break; + case paHostError: msg = "Host error."; break; + case paInvalidChannelCount: msg = "Invalid number of channels."; break; + case paInvalidSampleRate: msg = "Invalid sample rate."; break; + case paInvalidDeviceId: msg = "Invalid device ID."; break; + case paInvalidFlag: msg = "Invalid flag."; break; + case paSampleFormatNotSupported: msg = "Sample format not supported"; break; + case paBadIODeviceCombination: msg = "Illegal combination of I/O devices."; break; + case paInsufficientMemory: msg = "Insufficient memory."; break; + case paBufferTooBig: msg = "Buffer too big."; break; + case paBufferTooSmall: msg = "Buffer too small."; break; + case paNullCallback: msg = "No callback routine specified."; break; + case paBadStreamPtr: msg = "Invalid stream pointer."; break; + case paTimedOut : msg = "Wait Timed Out."; break; + case paInternalError: msg = "Internal PortAudio Error."; break; + default: msg = "Illegal error number."; break; + } + return msg; +} + +/* + Get CPU Load as a fraction of total CPU time. + A value of 0.5 would imply that PortAudio and the sound generating + callback was consuming roughly 50% of the available CPU time. + The amount may vary depending on CPU load. + This function may be called from the callback function. +*/ +DLL_API double Pa_GetCPULoad( PortAudioStream* stream) +{ + internalPortAudioStream *past; + if( stream == NULL ) return (double) paBadStreamPtr; + past = (internalPortAudioStream *) stream; + return past->past_Usage; +} + +/************************************************************* +** Calculate 2 LSB dither signal with a triangular distribution. +** Ranged properly for adding to a 32 bit integer prior to >>15. +*/ +#define DITHER_BITS (15) +#define DITHER_SCALE (1.0f / ((1<<DITHER_BITS)-1)) +static long Pa_TriangularDither( void ) +{ + static unsigned long previous = 0; + static unsigned long randSeed1 = 22222; + static unsigned long randSeed2 = 5555555; + long current, highPass; + /* Generate two random numbers. */ + randSeed1 = (randSeed1 * 196314165) + 907633515; + randSeed2 = (randSeed2 * 196314165) + 907633515; + /* Generate triangular distribution about 0. */ + current = (((long)randSeed1)>>(32-DITHER_BITS)) + (((long)randSeed2)>>(32-DITHER_BITS)); + /* High pass filter to reduce audibility. */ + highPass = current - previous; + previous = current; + return highPass; +} + +/************************************************************************* +** Called by host code. +** Convert input from Int16, call user code, then convert output +** to Int16 format for native use. +** Assumes host native format is paInt16. +** Returns result from user callback. +*/ +long Pa_CallConvertInt16( internalPortAudioStream *past, + short *nativeInputBuffer, + short *nativeOutputBuffer ) +{ + long temp; + long bytesEmpty = 0; + long bytesFilled = 0; + int userResult; + unsigned int i; + void *inputBuffer = NULL; + void *outputBuffer = NULL; + +#if SUPPORT_AUDIO_CAPTURE + /* Get native data from DirectSound. */ + if( (past->past_NumInputChannels > 0) && (nativeInputBuffer != NULL) ) + { + /* Convert from native format to PA format. */ + unsigned int samplesPerBuffer = past->past_FramesPerUserBuffer * past->past_NumInputChannels; + switch(past->past_InputSampleFormat) + { + + case paFloat32: + { + float *inBufPtr = (float *) past->past_InputBuffer; + inputBuffer = past->past_InputBuffer; + for( i=0; i<samplesPerBuffer; i++ ) + { + inBufPtr[i] = nativeInputBuffer[i] * (1.0f / 32767.0f); + } + break; + } + + case paInt32: + { + /* Convert 16 bit data to 32 bit integers */ + int *inBufPtr = (int *) past->past_InputBuffer; + inputBuffer = past->past_InputBuffer; + for( i=0; i<samplesPerBuffer; i++ ) + { + inBufPtr[i] = nativeInputBuffer[i] << 16; + } + break; + } + + case paInt16: + { + /* Already in correct format so don't copy. */ + inputBuffer = nativeInputBuffer; + break; + } + + case paInt8: + { + /* Convert 16 bit data to 8 bit chars */ + char *inBufPtr = (char *) past->past_InputBuffer; + inputBuffer = past->past_InputBuffer; + if( past->past_Flags & paDitherOff ) + { + for( i=0; i<samplesPerBuffer; i++ ) + { + inBufPtr[i] = (char)(nativeInputBuffer[i] >> 8); + } + } + else + { + for( i=0; i<samplesPerBuffer; i++ ) + { + temp = nativeInputBuffer[i]; + temp += Pa_TriangularDither() >> 7; + temp = ((temp < -0x8000) ? -0x8000 : ((temp > 0x7FFF) ? 0x7FFF : temp)); + inBufPtr[i] = (char)(temp >> 8); + } + } + break; + } + + case paUInt8: + { + /* Convert 16 bit data to 8 bit unsigned chars */ + unsigned char *inBufPtr = (unsigned char *) past->past_InputBuffer; + inputBuffer = past->past_InputBuffer; + if( past->past_Flags & paDitherOff ) + { + for( i=0; i<samplesPerBuffer; i++ ) + { + inBufPtr[i] = ((unsigned char)(nativeInputBuffer[i] >> 8)) + 0x80; + } + } + else + { + /* If you dither then you have to clip because dithering could push the signal out of range! */ + for( i=0; i<samplesPerBuffer; i++ ) + { + temp = nativeInputBuffer[i]; + temp += Pa_TriangularDither() >> 7; + temp = ((temp < -0x8000) ? -0x8000 : ((temp > 0x7FFF) ? 0x7FFF : temp)); + inBufPtr[i] = (unsigned char)(temp + 0x80); + } + } + break; + } + + default: + break; + } + } +#endif /* SUPPORT_AUDIO_CAPTURE */ + + /* Are we doing output time? */ + if( (past->past_NumOutputChannels > 0) && (nativeOutputBuffer != NULL) ) + { + /* May already be in native format so just write directly to native buffer. */ + outputBuffer = (past->past_OutputSampleFormat == paInt16) ? + nativeOutputBuffer : past->past_OutputBuffer; + } + /* + AddTraceMessage("Pa_CallConvertInt16: inputBuffer = ", (int) inputBuffer ); + AddTraceMessage("Pa_CallConvertInt16: outputBuffer = ", (int) outputBuffer ); + */ + /* Call user callback routine. */ + userResult = past->past_Callback( + inputBuffer, + outputBuffer, + past->past_FramesPerUserBuffer, + past->past_FrameCount, + past->past_UserData ); + + past->past_FrameCount += (PaTimestamp) past->past_FramesPerUserBuffer; + + /* Convert to native format if necessary. */ + if( outputBuffer != NULL ) + { + unsigned int samplesPerBuffer = past->past_FramesPerUserBuffer * past->past_NumOutputChannels; + switch(past->past_OutputSampleFormat) + { + case paFloat32: + { + float *outBufPtr = (float *) past->past_OutputBuffer; + if( past->past_Flags & paDitherOff ) + { + if( past->past_Flags & paClipOff ) /* NOTHING */ + { + for( i=0; i<samplesPerBuffer; i++ ) + { + *nativeOutputBuffer++ = (short) (outBufPtr[i] * (32767.0f)); + } + } + else /* CLIP */ + { + for( i=0; i<samplesPerBuffer; i++ ) + { + temp = (long)(outBufPtr[i] * 32767.0f); + *nativeOutputBuffer++ = (short)((temp < -0x8000) ? -0x8000 : ((temp > 0x7FFF) ? 0x7FFF : temp)); + } + } + } + else + { + /* If you dither then you have to clip because dithering could push the signal out of range! */ + for( i=0; i<samplesPerBuffer; i++ ) + { + float dither = Pa_TriangularDither()*DITHER_SCALE; + float dithered = (outBufPtr[i] * (32767.0f)) + dither; + temp = (long) (dithered); + *nativeOutputBuffer++ = (short)((temp < -0x8000) ? -0x8000 : ((temp > 0x7FFF) ? 0x7FFF : temp)); + } + } + break; + } + + case paInt32: + { + int *outBufPtr = (int *) past->past_OutputBuffer; + if( past->past_Flags & paDitherOff ) + { + for( i=0; i<samplesPerBuffer; i++ ) + { + *nativeOutputBuffer++ = (short) (outBufPtr[i] >> 16 ); + } + } + else + { + for( i=0; i<samplesPerBuffer; i++ ) + { + /* Shift one bit down before dithering so that we have room for overflow from add. */ + temp = (outBufPtr[i] >> 1) + Pa_TriangularDither(); + temp = temp >> 15; + *nativeOutputBuffer++ = (short)((temp < -0x8000) ? -0x8000 : ((temp > 0x7FFF) ? 0x7FFF : temp)); + } + } + break; + } + + case paInt8: + { + char *outBufPtr = (char *) past->past_OutputBuffer; + for( i=0; i<samplesPerBuffer; i++ ) + { + *nativeOutputBuffer++ = ((short)outBufPtr[i]) << 8; + } + break; + } + + case paUInt8: + { + unsigned char *outBufPtr = (unsigned char *) past->past_OutputBuffer; + for( i=0; i<samplesPerBuffer; i++ ) + { + *nativeOutputBuffer++ = ((short)(outBufPtr[i] - 0x80)) << 8; + } + break; + } + + default: + break; + } + + } + + return userResult; +} + +/************************************************************************* +** Called by host code. +** Convert input from Float32, call user code, then convert output +** to Float32 format for native use. +** Assumes host native format is Float32. +** Returns result from user callback. +** FIXME - Unimplemented for formats other than paFloat32!!!! +*/ +long Pa_CallConvertFloat32( internalPortAudioStream *past, + float *nativeInputBuffer, + float *nativeOutputBuffer ) +{ + long bytesEmpty = 0; + long bytesFilled = 0; + int userResult; + void *inputBuffer = NULL; + void *outputBuffer = NULL; + + /* Get native data from DirectSound. */ + if( (past->past_NumInputChannels > 0) && (nativeInputBuffer != NULL) ) + { + inputBuffer = nativeInputBuffer; // FIXME + } + + /* Are we doing output time? */ + if( (past->past_NumOutputChannels > 0) && (nativeOutputBuffer != NULL) ) + { + /* May already be in native format so just write directly to native buffer. */ + outputBuffer = (past->past_OutputSampleFormat == paFloat32) ? + nativeOutputBuffer : past->past_OutputBuffer; + } + /* + AddTraceMessage("Pa_CallConvertInt16: inputBuffer = ", (int) inputBuffer ); + AddTraceMessage("Pa_CallConvertInt16: outputBuffer = ", (int) outputBuffer ); + */ + /* Call user callback routine. */ + userResult = past->past_Callback( + inputBuffer, + outputBuffer, + past->past_FramesPerUserBuffer, + past->past_FrameCount, + past->past_UserData ); + + past->past_FrameCount += (PaTimestamp) past->past_FramesPerUserBuffer; + + /* Convert to native format if necessary. */ // FIXME + return userResult; +} + +/*************************************************************************/ +DLL_API PaError Pa_Initialize( void ) +{ + if( gInitCount++ > 0 ) return paNoError; + ResetTraceMessages(); + return PaHost_Init(); +} + +DLL_API PaError Pa_Terminate( void ) +{ + PaError result = paNoError; + + if( gInitCount == 0 ) return paNoError; + else if( --gInitCount == 0 ) + { + result = PaHost_Term(); + DumpTraceMessages(); + } + return result; +} + +/*************************************************************************/ +DLL_API PaError Pa_GetSampleSize( PaSampleFormat format ) +{ + int size; + switch(format ) + { + + case paUInt8: + case paInt8: + size = 1; + break; + + case paInt16: + size = 2; + break; + + case paPackedInt24: + size = 3; + break; + + case paFloat32: + case paInt32: + case paInt24: + size = 4; + break; + + default: + size = paSampleFormatNotSupported; + break; + } + return (PaError) size; +} + + diff --git a/pd/portaudio_v18/pa_dll_switch/portaudio.h b/pd/portaudio_v18/pa_dll_switch/portaudio.h new file mode 100644 index 00000000..9632521e --- /dev/null +++ b/pd/portaudio_v18/pa_dll_switch/portaudio.h @@ -0,0 +1,439 @@ +#ifndef PORT_AUDIO_H +#define PORT_AUDIO_H + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/* + * PortAudio Portable Real-Time Audio Library + * PortAudio API Header File + * Latest version available at: http://www.audiomulch.com/portaudio/ + * + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +// added by zplane.developement in order to generate a DLL + +#if defined(PA_MME_EXPORTS) || defined(PA_DX_EXPORTS) +#define DLL_API __declspec( dllexport ) +#elif defined(_LIB) || defined(_STATIC_LINK) || defined(_STATIC_APP) +#define DLL_API +#else +#define DLL_API __declspec(dllexport) +#endif + + +typedef int PaError; +typedef enum { + paNoError = 0, + + paHostError = -10000, + paInvalidChannelCount, + paInvalidSampleRate, + paInvalidDeviceId, + paInvalidFlag, + paSampleFormatNotSupported, + paBadIODeviceCombination, + paInsufficientMemory, + paBufferTooBig, + paBufferTooSmall, + paNullCallback, + paBadStreamPtr, + paTimedOut, + paInternalError +} PaErrorNum; + +/* + Pa_Initialize() is the library initialisation function - call this before + using the library. +*/ + +DLL_API PaError Pa_Initialize( void ); + +/* + Pa_Terminate() is the library termination function - call this after + using the library. +*/ + +DLL_API PaError Pa_Terminate( void ); + +/* + Return host specific error. + This can be called after receiving a paHostError. +*/ +DLL_API long Pa_GetHostError( void ); + +/* + Translate the error number into a human readable message. +*/ +DLL_API const char *Pa_GetErrorText( PaError errnum ); + +/* + Sample formats + + These are formats used to pass sound data between the callback and the + stream. Each device has a "native" format which may be used when optimum + efficiency or control over conversion is required. + + Formats marked "always available" are supported (emulated) by all devices. + + The floating point representation uses +1.0 and -1.0 as the respective + maximum and minimum. + +*/ + +typedef unsigned long PaSampleFormat; +#define paFloat32 ((PaSampleFormat) (1<<0)) /*always available*/ +#define paInt16 ((PaSampleFormat) (1<<1)) /*always available*/ +#define paInt32 ((PaSampleFormat) (1<<2)) /*always available*/ +#define paInt24 ((PaSampleFormat) (1<<3)) +#define paPackedInt24 ((PaSampleFormat) (1<<4)) +#define paInt8 ((PaSampleFormat) (1<<5)) +#define paUInt8 ((PaSampleFormat) (1<<6)) /* unsigned 8 bit, 128 is "ground" */ +#define paCustomFormat ((PaSampleFormat) (1<<16)) + +/* + Device enumeration mechanism. + + Device ids range from 0 to Pa_CountDevices()-1. + + Devices may support input, output or both. Device 0 is always the "default" + device and should support at least stereo in and out if that is available + on the taget platform _even_ if this involves kludging an input/output + device on platforms that usually separate input from output. Other platform + specific devices are specified by positive device ids. +*/ + +typedef int PaDeviceID; +#define paNoDevice -1 + +typedef struct +{ + int structVersion; + const char *name; + int maxInputChannels; + int maxOutputChannels; + /* Number of discrete rates, or -1 if range supported. */ + int numSampleRates; + /* Array of supported sample rates, or {min,max} if range supported. */ + const double *sampleRates; + PaSampleFormat nativeSampleFormats; +} +PaDeviceInfo; + + +DLL_API int Pa_CountDevices(); +/* + Pa_GetDefaultInputDeviceID(), Pa_GetDefaultOutputDeviceID() + + Return the default device ID or paNoDevice if there is no devices. + The result can be passed to Pa_OpenStream(). + + On the PC, the user can specify a default device by + setting an environment variable. For example, to use device #1. + + set PA_RECOMMENDED_OUTPUT_DEVICE=1 + + The user should first determine the available device ID by using + the supplied application "pa_devs". +*/ +DLL_API PaDeviceID Pa_GetDefaultInputDeviceID( void ); +DLL_API PaDeviceID Pa_GetDefaultOutputDeviceID( void ); + +/* + PaTimestamp is used to represent a continuous sample clock with arbitrary + start time useful for syncronisation. The type is used in the outTime + argument to the callback function and the result of Pa_StreamTime() +*/ + +typedef double PaTimestamp; + +/* + Pa_GetDeviceInfo() returns a pointer to an immutable PaDeviceInfo structure + referring to the device specified by id. + If id is out of range the function returns NULL. + + The returned structure is owned by the PortAudio implementation and must + not be manipulated or freed. The pointer is guaranteed to be valid until + between calls to Pa_Initialize() and Pa_Terminate(). +*/ + +DLL_API const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceID id ); + +/* + PortAudioCallback is implemented by clients of the portable audio api. + + inputBuffer and outputBuffer are arrays of interleaved samples, + the format, packing and number of channels used by the buffers are + determined by parameters to Pa_OpenStream() (see below). + + framesPerBuffer is the number of sample frames to be processed by the callback. + + outTime is the time in samples when the buffer(s) processed by + this callback will begin being played at the audio output. + See also Pa_StreamTime() + + userData is the value of a user supplied pointer passed to Pa_OpenStream() + intended for storing synthesis data etc. + + return value: + The callback can return a nonzero value to stop the stream. This may be + useful in applications such as soundfile players where a specific duration + of output is required. However, it is not necessary to utilise this mechanism + as StopStream() will also terminate the stream. A callback returning a + nonzero value must fill the entire outputBuffer. + + NOTE: None of the other stream functions may be called from within the + callback function except for Pa_GetCPULoad(). + +*/ + +typedef int (PortAudioCallback)( + void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ); + + +/* + Stream flags + + These flags may be supplied (ored together) in the streamFlags argument to + the Pa_OpenStream() function. + + [ suggestions? ] +*/ + +#define paNoFlag (0) +#define paClipOff (1<<0) /* disable defult clipping of out of range samples */ +#define paDitherOff (1<<1) /* disable default dithering */ +#define paPlatformSpecificFlags (0x00010000) +typedef unsigned long PaStreamFlags; + +/* + A single PortAudioStream provides multiple channels of real-time + input and output audio streaming to a client application. + Pointers to PortAudioStream objects are passed between PortAudio functions. +*/ + +typedef void PortAudioStream; +#define PaStream PortAudioStream + +/* + Pa_OpenStream() opens a stream for either input, output or both. + + stream is the address of a PortAudioStream pointer which will receive + a pointer to the newly opened stream. + + inputDevice is the id of the device used for input (see PaDeviceID above.) + inputDevice may be paNoDevice to indicate that an input device is not required. + + numInputChannels is the number of channels of sound to be delivered to the + callback. It can range from 1 to the value of maxInputChannels in the + device input record for the device specified in the inputDevice parameter. + If inputDevice is paNoDevice numInputChannels is ignored. + + inputSampleFormat is the format of inputBuffer provided to the callback + function. inputSampleFormat may be any of the formats described by the + PaSampleFormat enumeration (see above). PortAudio guarantees support for + the sound devices native formats (nativeSampleFormats in the device info + record) and additionally 16 and 32 bit integer and 32 bit floating point + formats. Support for other formats is implementation defined. + + inputDriverInfo is a pointer to an optional driver specific data structure + containing additional information for device setup or stream processing. + inputDriverInfo is never required for correct operation. If not used + inputDriverInfo should be NULL. + + outputDevice is the id of the device used for output (see PaDeviceID above.) + outputDevice may be paNoDevice to indicate that an output device is not required. + + numOutputChannels is the number of channels of sound to be supplied by the + callback. See the definition of numInputChannels above for more details. + + outputSampleFormat is the sample format of the outputBuffer filled by the + callback function. See the definition of inputSampleFormat above for more + details. + + outputDriverInfo is a pointer to an optional driver specific data structure + containing additional information for device setup or stream processing. + outputDriverInfo is never required for correct operation. If not used + outputDriverInfo should be NULL. + + sampleRate is the desired sampleRate for input and output + + framesPerBuffer is the length in sample frames of all internal sample buffers + used for communication with platform specific audio routines. Wherever + possible this corresponds to the framesPerBuffer parameter passed to the + callback function. + + numberOfBuffers is the number of buffers used for multibuffered + communication with the platform specific audio routines. This parameter is + provided only as a guide - and does not imply that an implementation must + use multibuffered i/o when reliable double buffering is available (such as + SndPlayDoubleBuffer() on the Macintosh.) + + streamFlags may contain a combination of flags ORed together. + These flags modify the behavior of the + streaming process. Some flags may only be relevant to certain buffer formats. + + callback is a pointer to a client supplied function that is responsible + for processing and filling input and output buffers (see above for details.) + + userData is a client supplied pointer which is passed to the callback + function. It could for example, contain a pointer to instance data necessary + for processing the audio buffers. + + return value: + Apon success Pa_OpenStream() returns PaNoError and places a pointer to a + valid PortAudioStream in the stream argument. The stream is inactive (stopped). + If a call to Pa_OpenStream() fails a nonzero error code is returned (see + PAError above) and the value of stream is invalid. + +*/ + +DLL_API PaError Pa_OpenStream( PortAudioStream** stream, + PaDeviceID inputDevice, + int numInputChannels, + PaSampleFormat inputSampleFormat, + void *inputDriverInfo, + PaDeviceID outputDevice, + int numOutputChannels, + PaSampleFormat outputSampleFormat, + void *outputDriverInfo, + double sampleRate, + unsigned long framesPerBuffer, + unsigned long numberOfBuffers, + PaStreamFlags streamFlags, + PortAudioCallback *callback, + void *userData ); + + +/* + Pa_OpenDefaultStream() is a simplified version of Pa_OpenStream() that + opens the default input and/or ouput devices. Most parameters have + identical meaning to their Pa_OpenStream() counterparts, with the following + exceptions: + + If either numInputChannels or numOutputChannels is 0 the respective device + is not opened (same as passing paNoDevice in the device arguments to Pa_OpenStream() ) + + sampleFormat applies to both the input and output buffers. +*/ + +DLL_API PaError Pa_OpenDefaultStream( PortAudioStream** stream, + int numInputChannels, + int numOutputChannels, + PaSampleFormat sampleFormat, + double sampleRate, + unsigned long framesPerBuffer, + unsigned long numberOfBuffers, + PortAudioCallback *callback, + void *userData ); + +/* + Pa_CloseStream() closes an audio stream, flushing any pending buffers. +*/ + +DLL_API PaError Pa_CloseStream( PortAudioStream* ); + +/* + Pa_StartStream() and Pa_StopStream() begin and terminate audio processing. + When Pa_StopStream() returns, all pending audio buffers have been played. + Pa_AbortStream() stops playing immediately without waiting for pending + buffers to complete. +*/ + +DLL_API PaError Pa_StartStream( PortAudioStream *stream ); + +DLL_API PaError Pa_StopStream( PortAudioStream *stream ); + +DLL_API PaError Pa_AbortStream( PortAudioStream *stream ); + +/* + Pa_StreamActive() returns one when the stream is playing audio, + zero when not playing, or a negative error number if the + stream is invalid. + The stream is active between calls to Pa_StartStream() and Pa_StopStream(), + but may also become inactive if the callback returns a non-zero value. + In the latter case, the stream is considered inactive after the last + buffer has finished playing. +*/ + +DLL_API PaError Pa_StreamActive( PortAudioStream *stream ); + +/* + Pa_StreamTime() returns the current output time for the stream in samples. + This time may be used as a time reference (for example syncronising audio to + MIDI). +*/ + +DLL_API PaTimestamp Pa_StreamTime( PortAudioStream *stream ); + +/* + The "CPU Load" is a fraction of total CPU time consumed by the + stream's audio processing. + A value of 0.5 would imply that PortAudio and the sound generating + callback was consuming roughly 50% of the available CPU time. + This function may be called from the callback function or the application. +*/ +DLL_API double Pa_GetCPULoad( PortAudioStream* stream ); + +/* + Use Pa_GetMinNumBuffers() to determine minimum number of buffers required for + the current host based on minimum latency. + On the PC, for the DirectSound implementation, latency can be optionally set + by user by setting an environment variable. + For example, to set latency to 200 msec, put: + + set PA_MIN_LATENCY_MSEC=200 + + in the AUTOEXEC.BAT file and reboot. + If the environment variable is not set, then the latency will be determined + based on the OS. Windows NT has higher latency than Win95. +*/ + +DLL_API int Pa_GetMinNumBuffers( int framesPerBuffer, double sampleRate ); + +/* + Sleep for at least 'msec' milliseconds. + You may sleep longer than the requested time so don't rely + on this for accurate musical timing. +*/ +DLL_API void Pa_Sleep( long msec ); + +/* + Return size in bytes of a single sample in a given PaSampleFormat + or paSampleFormatNotSupported. +*/ +DLL_API PaError Pa_GetSampleSize( PaSampleFormat format ); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* PORT_AUDIO_H */ diff --git a/pd/portaudio_v18/pa_mac/pa_mac.c b/pd/portaudio_v18/pa_mac/pa_mac.c new file mode 100644 index 00000000..118ea510 --- /dev/null +++ b/pd/portaudio_v18/pa_mac/pa_mac.c @@ -0,0 +1,1687 @@ +/* + * $Id: pa_mac.c,v 1.4.4.2 2002/10/15 03:14:08 dmazzoni Exp $ + * Portable Audio I/O Library for Macintosh + * + * Based on the Open Source API proposed by Ross Bencina + * Copyright (c) 1999-2000 Phil Burk + * + * Special thanks to Chris Rolfe for his many helpful suggestions, bug fixes, + * and code contributions. + * Thanks also to Tue Haste Andersen, Alberto Ricci, Nico Wald, + * Roelf Toxopeus and Tom Erbe for testing the code and making + * numerous suggestions. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +/* Modification History + PLB20010415 - ScanInputDevices was setting sDefaultOutputDeviceID instead of sDefaultInputDeviceID + PLB20010415 - Device Scan was crashing for anything other than siBadSoundInDevice, but some Macs may return other errors! + PLB20010420 - Fix TIMEOUT in record mode. + PLB20010420 - Change CARBON_COMPATIBLE to TARGET_API_MAC_CARBON + PLB20010907 - Pass unused event to WaitNextEvent to prevent Mac OSX crash. Thanks Dominic Mazzoni. + PLB20010908 - Use requested number of input channels. Thanks Dominic Mazzoni. + PLB20011009 - Use NewSndCallBackUPP() for CARBON + PLB20020417 - I used to call Pa_GetMinNumBuffers() which doesn't take into account the + variable minFramesPerHostBuffer. Now I call PaMac_GetMinNumBuffers() which will + give lower latency when virtual memory is turned off. + Thanks Kristoffer Jensen and Georgios Marentakis for spotting this bug. + PLB20020423 - Use new method to calculate CPU load similar to other ports. Based on num frames calculated. + Fixed Pa_StreamTime(). Now estimates how many frames have played based on MicroSecond timer. + Added PA_MAX_USAGE_ALLOWED to prevent Mac from hanging when CPU load approaches 100%. + PLB20020424 - Fixed return value in Pa_StreamTime + PLB20020612 - Fix allocation error on Mac 8600 by casting *nameH as uchar* so that we get a proper Str255 length. +*/ + +/* +COMPATIBILITY +This Macintosh implementation is designed for use with Mac OS 7, 8 and +9 on PowerMacs, and OS X if compiled with CARBON + +OUTPUT +A circular array of CmpSoundHeaders is used as a queue. For low latency situations +there will only be two small buffers used. For higher latency, more and larger buffers +may be used. +To play the sound we use SndDoCommand() with bufferCmd. Each buffer is followed +by a callbackCmd which informs us when the buffer has been processsed. + +INPUT +The SndInput Manager SPBRecord call is used for sound input. If only +input is used, then the PA user callback is called from the Input completion proc. +For full-duplex, or output only operation, the PA callback is called from the +HostBuffer output completion proc. In that case, input sound is passed to the +callback by a simple FIFO. + +TODO: +O- Add support for native sample data formats other than int16. +O- Review buffer sizing. Should it be based on result of siDeviceBufferInfo query? +O- Determine default devices somehow. +*/ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <memory.h> +#include <math.h> + +/* Mac specific includes */ +#include "OSUtils.h" +#include <MacTypes.h> +#include <Math64.h> +#include <Errors.h> +#include <Sound.h> +#include <SoundInput.h> +#include <SoundComponents.h> +#include <Devices.h> +#include <DateTimeUtils.h> +#include <Timer.h> +#include <Gestalt.h> + +#include "portaudio.h" +#include "pa_host.h" +#include "pa_trace.h" + +#ifndef FALSE + #define FALSE (0) + #define TRUE (!FALSE) +#endif + +/* #define TARGET_API_MAC_CARBON (1) */ + +/* + * Define maximum CPU load that will be allowed. User callback will + * be skipped if load exceeds this limit. This is to prevent the Mac + * from hanging when the CPU is hogged by the sound thread. + * On my PowerBook G3, the mac hung when I used 94% of CPU ( usage = 0.94 ). + */ +#define PA_MAX_USAGE_ALLOWED (0.92) + +/* Debugging output macros. */ +#define PRINT(x) { printf x; fflush(stdout); } +#define ERR_RPT(x) PRINT(x) +#define DBUG(x) /* PRINT(x) */ +#define DBUGX(x) /* PRINT(x) */ + +#define MAC_PHYSICAL_FRAMES_PER_BUFFER (512) /* Minimum number of stereo frames per SoundManager double buffer. */ +#define MAC_VIRTUAL_FRAMES_PER_BUFFER (4096) /* Need this many when using Virtual Memory for recording. */ +#define PA_MIN_NUM_HOST_BUFFERS (2) +#define PA_MAX_NUM_HOST_BUFFERS (16) /* Do not exceed!! */ +#define PA_MAX_DEVICE_INFO (32) + +/* Conversions for 16.16 fixed point code. */ +#define DoubleToUnsignedFixed(x) ((UnsignedFixed) ((x) * 65536.0)) +#define UnsignedFixedToDouble(fx) (((double)(fx)) * (1.0/(1<<16))) + +/************************************************************************************/ +/****************** Structures ******************************************************/ +/************************************************************************************/ +/* Use for passing buffers from input callback to output callback for processing. */ +typedef struct MultiBuffer +{ + char *buffers[PA_MAX_NUM_HOST_BUFFERS]; + int numBuffers; + int nextWrite; + int nextRead; +} +MultiBuffer; + +/* Define structure to contain all Macintosh specific data. */ +typedef struct PaHostSoundControl +{ + UInt64 pahsc_EntryCount; + double pahsc_InverseMicrosPerHostBuffer; /* 1/Microseconds of real-time audio per user buffer. */ + + /* Use char instead of Boolean for atomic operation. */ + volatile char pahsc_IsRecording; /* Recording in progress. Set by foreground. Cleared by background. */ + volatile char pahsc_StopRecording; /* Signal sent to background. */ + volatile char pahsc_IfInsideCallback; + /* Input */ + SPB pahsc_InputParams; + SICompletionUPP pahsc_InputCompletionProc; + MultiBuffer pahsc_InputMultiBuffer; + int32 pahsc_BytesPerInputHostBuffer; + int32 pahsc_InputRefNum; + /* Output */ + CmpSoundHeader pahsc_SoundHeaders[PA_MAX_NUM_HOST_BUFFERS]; + int32 pahsc_BytesPerOutputHostBuffer; + SndChannelPtr pahsc_Channel; + SndCallBackUPP pahsc_OutputCompletionProc; + int32 pahsc_NumOutsQueued; + int32 pahsc_NumOutsPlayed; + PaTimestamp pahsc_NumFramesDone; + UInt64 pahsc_WhenFramesDoneIncremented; + /* Init Time -------------- */ + int32 pahsc_NumHostBuffers; + int32 pahsc_FramesPerHostBuffer; + int32 pahsc_UserBuffersPerHostBuffer; + int32 pahsc_MinFramesPerHostBuffer; /* Can vary depending on virtual memory usage. */ +} +PaHostSoundControl; + +/* Mac specific device information. */ +typedef struct internalPortAudioDevice +{ + long pad_DeviceRefNum; + long pad_DeviceBufferSize; + Component pad_Identifier; + PaDeviceInfo pad_Info; +} +internalPortAudioDevice; + +/************************************************************************************/ +/****************** Data ************************************************************/ +/************************************************************************************/ +static int sNumDevices = 0; +static internalPortAudioDevice sDevices[PA_MAX_DEVICE_INFO] = { 0 }; +static int32 sPaHostError = 0; +static int sDefaultOutputDeviceID; +static int sDefaultInputDeviceID; + +/************************************************************************************/ +/****************** Prototypes ******************************************************/ +/************************************************************************************/ +static PaError PaMac_TimeSlice( internalPortAudioStream *past, int16 *macOutputBufPtr ); +static PaError PaMac_CallUserLoop( internalPortAudioStream *past, int16 *outPtr ); +static PaError PaMac_RecordNext( internalPortAudioStream *past ); +static void PaMac_StartLoadCalculation( internalPortAudioStream *past ); +static int PaMac_GetMinNumBuffers( int minFramesPerHostBuffer, int framesPerBuffer, double sampleRate ); +static double *PaMac_GetSampleRatesFromHandle ( int numRates, Handle h ); +static PaError PaMac_ScanInputDevices( void ); +static PaError PaMac_ScanOutputDevices( void ); +static PaError PaMac_QueryOutputDeviceInfo( Component identifier, internalPortAudioDevice *ipad ); +static PaError PaMac_QueryInputDeviceInfo( Str255 deviceName, internalPortAudioDevice *ipad ); +static void PaMac_InitSoundHeader( internalPortAudioStream *past, CmpSoundHeader *sndHeader ); +static void PaMac_EndLoadCalculation( internalPortAudioStream *past ); +static void PaMac_PlayNext ( internalPortAudioStream *past, int index ); +static long PaMac_FillNextOutputBuffer( internalPortAudioStream *past, int index ); +static pascal void PaMac_InputCompletionProc(SPBPtr recParams); +static pascal void PaMac_OutputCompletionProc (SndChannelPtr theChannel, SndCommand * theCmd); +static PaError PaMac_BackgroundManager( internalPortAudioStream *past, int index ); +long PaHost_GetTotalBufferFrames( internalPortAudioStream *past ); +static int Mac_IsVirtualMemoryOn( void ); +static void PToCString(unsigned char* inString, char* outString); +static void CToPString(char *inString, unsigned char* outString); +char *MultiBuffer_GetNextWriteBuffer( MultiBuffer *mbuf ); +char *MultiBuffer_GetNextReadBuffer( MultiBuffer *mbuf ); +int MultiBuffer_GetNextReadIndex( MultiBuffer *mbuf ); +int MultiBuffer_GetNextWriteIndex( MultiBuffer *mbuf ); +int MultiBuffer_IsWriteable( MultiBuffer *mbuf ); +int MultiBuffer_IsReadable( MultiBuffer *mbuf ); +void MultiBuffer_AdvanceReadIndex( MultiBuffer *mbuf ); +void MultiBuffer_AdvanceWriteIndex( MultiBuffer *mbuf ); + +/************************************************************************* +** Simple FIFO index control for multiple buffers. +** Read and Write indices range from 0 to 2N-1. +** This allows us to distinguish between full and empty. +*/ +char *MultiBuffer_GetNextWriteBuffer( MultiBuffer *mbuf ) +{ + return mbuf->buffers[mbuf->nextWrite % mbuf->numBuffers]; +} +char *MultiBuffer_GetNextReadBuffer( MultiBuffer *mbuf ) +{ + return mbuf->buffers[mbuf->nextRead % mbuf->numBuffers]; +} +int MultiBuffer_GetNextReadIndex( MultiBuffer *mbuf ) +{ + return mbuf->nextRead % mbuf->numBuffers; +} +int MultiBuffer_GetNextWriteIndex( MultiBuffer *mbuf ) +{ + return mbuf->nextWrite % mbuf->numBuffers; +} + +int MultiBuffer_IsWriteable( MultiBuffer *mbuf ) +{ + int bufsFull = mbuf->nextWrite - mbuf->nextRead; + if( bufsFull < 0 ) bufsFull += (2 * mbuf->numBuffers); + return (bufsFull < mbuf->numBuffers); +} +int MultiBuffer_IsReadable( MultiBuffer *mbuf ) +{ + int bufsFull = mbuf->nextWrite - mbuf->nextRead; + if( bufsFull < 0 ) bufsFull += (2 * mbuf->numBuffers); + return (bufsFull > 0); +} +void MultiBuffer_AdvanceReadIndex( MultiBuffer *mbuf ) +{ + int temp = mbuf->nextRead + 1; + mbuf->nextRead = (temp >= (2 * mbuf->numBuffers)) ? 0 : temp; +} +void MultiBuffer_AdvanceWriteIndex( MultiBuffer *mbuf ) +{ + int temp = mbuf->nextWrite + 1; + mbuf->nextWrite = (temp >= (2 * mbuf->numBuffers)) ? 0 : temp; +} + +/************************************************************************* +** String Utility by Chris Rolfe +*/ +static void PToCString(unsigned char* inString, char* outString) +{ + long i; + for(i=0; i<inString[0]; i++) /* convert Pascal to C string */ + outString[i] = inString[i+1]; + outString[i]=0; +} + +/************************************************************************* +** String Utility by Dominic Mazzoni +*/ +static void CToPString(char* inString, unsigned char* outString) +{ + long len = strlen(inString); + long i; + + if (len > 255) + len = 255; + + /* Length is stored in first char of Pascal string */ + outString[0] = (unsigned char)len; + for(i=0; i<len; i++) + outString[i+1] = inString[i]; +} + +/*************************************************************************/ +PaError PaHost_Term( void ) +{ + int i; + PaDeviceInfo *dev; + double *rates; + /* Free any allocated sample rate arrays. */ + for( i=0; i<sNumDevices; i++ ) + { + dev = &sDevices[i].pad_Info; + rates = (double *) dev->sampleRates; + if( (rates != NULL) ) free( rates ); /* MEM_011 */ + dev->sampleRates = NULL; + if( dev->name != NULL ) free( (void *) dev->name ); /* MEM_010 */ + dev->name = NULL; + } + sNumDevices = 0; + return paNoError; +} + +/************************************************************************* + PaHost_Init() is the library initialization function - call this before + using the library. +*/ +PaError PaHost_Init( void ) +{ + PaError err; + NumVersionVariant version; + + version.parts = SndSoundManagerVersion(); + DBUG(("SndSoundManagerVersion = 0x%x\n", version.whole)); + + /* Have we already initialized the device info? */ + err = (PaError) Pa_CountDevices(); + if( err < 0 ) return err; + else return paNoError; +} + +/************************************************************************* + PaMac_ScanOutputDevices() queries the properties of all output devices. +*/ +static PaError PaMac_ScanOutputDevices( void ) +{ + PaError err; + Component identifier=0; + ComponentDescription criteria = { kSoundOutputDeviceType, 0, 0, 0, 0 }; + long numComponents, i; + + /* Search the system linked list for output components */ + numComponents = CountComponents (&criteria); + identifier = 0; + sDefaultOutputDeviceID = sNumDevices; /* FIXME - query somehow */ + for (i = 0; i < numComponents; i++) + { + /* passing nil returns first matching component. */ + identifier = FindNextComponent( identifier, &criteria); + sDevices[sNumDevices].pad_Identifier = identifier; + + /* Set up for default OUTPUT devices. */ + err = PaMac_QueryOutputDeviceInfo( identifier, &sDevices[sNumDevices] ); + if( err < 0 ) return err; + else sNumDevices++; + + } + + return paNoError; +} + +/************************************************************************* + PaMac_ScanInputDevices() queries the properties of all input devices. +*/ +static PaError PaMac_ScanInputDevices( void ) +{ + Str255 deviceName; + int count; + Handle iconHandle; + PaError err; + OSErr oserr; + count = 1; + sDefaultInputDeviceID = sNumDevices; /* FIXME - query somehow */ /* PLB20010415 - was setting sDefaultOutputDeviceID */ + while(true) + { + /* Thanks Chris Rolfe and Alberto Ricci for this trick. */ + oserr = SPBGetIndexedDevice(count++, deviceName, &iconHandle); + DBUG(("PaMac_ScanInputDevices: SPBGetIndexedDevice returned %d\n", oserr )); +#if 1 + /* PLB20010415 - was giving error for anything other than siBadSoundInDevice, but some Macs may return other errors! */ + if(oserr != noErr) break; /* Some type of error is expected when count > devices */ +#else + if(oserr == siBadSoundInDevice) + { /* it's expected when count > devices */ + oserr = noErr; + break; + } + if(oserr != noErr) + { + ERR_RPT(("ERROR: SPBGetIndexedDevice(%d,,) returned %d\n", count-1, oserr )); + sPaHostError = oserr; + return paHostError; + } +#endif + DisposeHandle(iconHandle); /* Don't need the icon */ + + err = PaMac_QueryInputDeviceInfo( deviceName, &sDevices[sNumDevices] ); + DBUG(("PaMac_ScanInputDevices: PaMac_QueryInputDeviceInfo returned %d\n", err )); + if( err < 0 ) return err; + else if( err == 1 ) sNumDevices++; + } + + return paNoError; +} + +/* Sample rate info returned by using siSampleRateAvailable selector in SPBGetDeviceInfo() */ +/* Thanks to Chris Rolfe for help with this query. */ +#pragma options align=mac68k +typedef struct +{ + int16 numRates; + UnsignedFixed (**rates)[]; /* Handle created by SPBGetDeviceInfo */ +} +SRateInfo; +#pragma options align=reset + +/************************************************************************* +** PaMac_QueryOutputDeviceInfo() +** Query information about a named output device. +** Clears contents of ipad and writes info based on queries. +** Return one if OK, +** zero if device cannot be used, +** or negative error. +*/ +static PaError PaMac_QueryOutputDeviceInfo( Component identifier, internalPortAudioDevice *ipad ) +{ + int len; + OSErr err; + PaDeviceInfo *dev = &ipad->pad_Info; + SRateInfo srinfo = {0}; + int numRates; + ComponentDescription tempD; + Handle nameH=nil, infoH=nil, iconH=nil; + + memset( ipad, 0, sizeof(internalPortAudioDevice) ); + + dev->structVersion = 1; + dev->maxInputChannels = 0; + dev->maxOutputChannels = 2; + dev->nativeSampleFormats = paInt16; /* FIXME - query to see if 24 or 32 bit data can be handled. */ + + /* Get sample rates supported. */ + err = GetSoundOutputInfo(identifier, siSampleRateAvailable, (Ptr) &srinfo); + if(err != noErr) + { + ERR_RPT(("Error in PaMac_QueryOutputDeviceInfo: GetSoundOutputInfo siSampleRateAvailable returned %d\n", err )); + goto error; + } + numRates = srinfo.numRates; + DBUG(("PaMac_QueryOutputDeviceInfo: srinfo.numRates = %d\n", srinfo.numRates )); + if( numRates == 0 ) + { + dev->numSampleRates = -1; + numRates = 2; + } + else + { + dev->numSampleRates = numRates; + } + dev->sampleRates = PaMac_GetSampleRatesFromHandle( numRates, (Handle) srinfo.rates ); + if(dev->sampleRates == NULL) + { + DBUG(("PaMac_QueryOutputDeviceInfo: PaMac_GetSampleRatesFromHandle alloc failed.\n")); + return paInsufficientMemory; + } + + /* SPBGetDeviceInfo created the handle, but it's OUR job to release it. */ + DisposeHandle((Handle) srinfo.rates); + + /* Device name */ + /* we pass an existing handle for the component name; + we don't care about the info (type, subtype, etc.) or icon, so set them to nil */ + DBUG(("PaMac_QueryOutputDeviceInfo: get component name.\n")); + infoH = nil; + iconH = nil; + nameH = NewHandle(0); + if(nameH == nil) return paInsufficientMemory; + err = GetComponentInfo(identifier, &tempD, nameH, infoH, iconH); + if (err) + { + ERR_RPT(("Error in PaMac_QueryOutputDeviceInfo: GetComponentInfo returned %d\n", err )); + goto error; + } + /* Cast as uchar* so that we get a proper pascal string length. */ + len = ((unsigned char *)(*nameH))[0] + 1; /* PLB20020612 - fix allocation error on Mac 8600 */ + DBUG(("PaMac_QueryOutputDeviceInfo: new len = %d\n", len )); + + dev->name = (char *) malloc(len); /* MEM_010 */ + if( dev->name == NULL ) + { + DisposeHandle(nameH); + return paInsufficientMemory; + } + else + { + PToCString((unsigned char *)(*nameH), (char *) dev->name); + DisposeHandle(nameH); + } + + DBUG(("PaMac_QueryOutputDeviceInfo: dev->name = %s\n", dev->name )); + return paNoError; + +error: + sPaHostError = err; + return paHostError; + +} + +/************************************************************************* +** PaMac_QueryInputDeviceInfo() +** Query information about a named input device. +** Clears contents of ipad and writes info based on queries. +** Return one if OK, +** zero if device cannot be used, +** or negative error. +*/ +static PaError PaMac_QueryInputDeviceInfo( Str255 deviceName, internalPortAudioDevice *ipad ) +{ + PaError result = paNoError; + int len; + OSErr err; + long mRefNum = 0; + long tempL; + int16 tempS; + Fixed tempF; + PaDeviceInfo *dev = &ipad->pad_Info; + SRateInfo srinfo = {0}; + int numRates; + + memset( ipad, 0, sizeof(internalPortAudioDevice) ); + dev->maxOutputChannels = 0; + + /* Open device based on name. If device is in use, it may not be able to open in write mode. */ + err = SPBOpenDevice( deviceName, siWritePermission, &mRefNum); + if (err) + { + /* If device is in use, it may not be able to open in write mode so try read mode. */ + err = SPBOpenDevice( deviceName, siReadPermission, &mRefNum); + if (err) + { + ERR_RPT(("Error in PaMac_QueryInputDeviceInfo: SPBOpenDevice returned %d\n", err )); + sPaHostError = err; + return paHostError; + } + } + + /* Define macros for printing out device info. */ +#define PrintDeviceInfo(selector,var) \ + err = SPBGetDeviceInfo(mRefNum, selector, (Ptr) &var); \ + if (err) { \ + DBUG(("query %s failed\n", #selector )); \ + }\ + else { \ + DBUG(("query %s = 0x%x\n", #selector, var )); \ + } + + PrintDeviceInfo( siContinuous, tempS ); + PrintDeviceInfo( siAsync, tempS ); + PrintDeviceInfo( siNumberChannels, tempS ); + PrintDeviceInfo( siSampleSize, tempS ); + PrintDeviceInfo( siSampleRate, tempF ); + PrintDeviceInfo( siChannelAvailable, tempS ); + PrintDeviceInfo( siActiveChannels, tempL ); + PrintDeviceInfo( siDeviceBufferInfo, tempL ); + + err = SPBGetDeviceInfo(mRefNum, siActiveChannels, (Ptr) &tempL); + if (err == 0) DBUG(("%s = 0x%x\n", "siActiveChannels", tempL )); + /* Can we use this device? */ + err = SPBGetDeviceInfo(mRefNum, siAsync, (Ptr) &tempS); + if (err) + { + ERR_RPT(("Error in PaMac_QueryInputDeviceInfo: SPBGetDeviceInfo siAsync returned %d\n", err )); + goto error; + } + if( tempS == 0 ) goto useless; /* Does not support async recording so forget about it. */ + + err = SPBGetDeviceInfo(mRefNum, siChannelAvailable, (Ptr) &tempS); + if (err) + { + ERR_RPT(("Error in PaMac_QueryInputDeviceInfo: SPBGetDeviceInfo siChannelAvailable returned %d\n", err )); + goto error; + } + dev->maxInputChannels = tempS; + + /* Get sample rates supported. */ + err = SPBGetDeviceInfo(mRefNum, siSampleRateAvailable, (Ptr) &srinfo); + if (err) + { + ERR_RPT(("Error in PaMac_QueryInputDeviceInfo: SPBGetDeviceInfo siSampleRateAvailable returned %d\n", err )); + goto error; + } + + numRates = srinfo.numRates; + DBUG(("numRates = 0x%x\n", numRates )); + if( numRates == 0 ) + { + dev->numSampleRates = -1; + numRates = 2; + } + else + { + dev->numSampleRates = numRates; + } + dev->sampleRates = PaMac_GetSampleRatesFromHandle( numRates, (Handle) srinfo.rates ); + /* SPBGetDeviceInfo created the handle, but it's OUR job to release it. */ + DisposeHandle((Handle) srinfo.rates); + + /* Get size of device buffer. */ + err = SPBGetDeviceInfo(mRefNum, siDeviceBufferInfo, (Ptr) &tempL); + if (err) + { + ERR_RPT(("Error in PaMac_QueryInputDeviceInfo: SPBGetDeviceInfo siDeviceBufferInfo returned %d\n", err )); + goto error; + } + ipad->pad_DeviceBufferSize = tempL; + DBUG(("siDeviceBufferInfo = %d\n", tempL )); + + /* Set format based on sample size. */ + err = SPBGetDeviceInfo(mRefNum, siSampleSize, (Ptr) &tempS); + if (err) + { + ERR_RPT(("Error in PaMac_QueryInputDeviceInfo: SPBGetDeviceInfo siSampleSize returned %d\n", err )); + goto error; + } + switch( tempS ) + { + case 0x0020: + dev->nativeSampleFormats = paInt32; /* FIXME - warning, code probably won't support this! */ + break; + case 0x0010: + default: /* FIXME - What about other formats? */ + dev->nativeSampleFormats = paInt16; + break; + } + DBUG(("nativeSampleFormats = %d\n", dev->nativeSampleFormats )); + + /* Device name */ + len = deviceName[0] + 1; /* Get length of Pascal string */ + dev->name = (char *) malloc(len); /* MEM_010 */ + if( dev->name == NULL ) + { + result = paInsufficientMemory; + goto cleanup; + } + PToCString(deviceName, (char *) dev->name); + DBUG(("deviceName = %s\n", dev->name )); + result = (PaError) 1; + /* All done so close up device. */ +cleanup: + if( mRefNum ) SPBCloseDevice(mRefNum); + return result; + +error: + if( mRefNum ) SPBCloseDevice(mRefNum); + sPaHostError = err; + return paHostError; + +useless: + if( mRefNum ) SPBCloseDevice(mRefNum); + return (PaError) 0; +} + +/************************************************************************* +** Allocate a double array and fill it with listed sample rates. +*/ +static double * PaMac_GetSampleRatesFromHandle ( int numRates, Handle h ) +{ + OSErr err = noErr; + SInt8 hState; + int i; + UnsignedFixed *fixedRates; + double *rates = (double *) malloc( numRates * sizeof(double) ); /* MEM_011 */ + if( rates == NULL ) return NULL; + /* Save and restore handle state as suggested by TechNote at: + http://developer.apple.com/technotes/tn/tn1122.html + */ + hState = HGetState (h); + if (!(err = MemError ())) + { + HLock (h); + if (!(err = MemError ( ))) + { + fixedRates = (UInt32 *) *h; + for( i=0; i<numRates; i++ ) + { + rates[i] = UnsignedFixedToDouble(fixedRates[i]); + } + + HSetState (h,hState); + err = MemError ( ); + } + } + if( err ) + { + free( rates ); + ERR_RPT(("Error in PaMac_GetSampleRatesFromHandle = %d\n", err )); + } + return rates; +} + +/*************************************************************************/ +int Pa_CountDevices() +{ + PaError err; + DBUG(("Pa_CountDevices()\n")); + /* If no devices, go find some. */ + if( sNumDevices <= 0 ) + { + err = PaMac_ScanOutputDevices(); + if( err != paNoError ) goto error; + err = PaMac_ScanInputDevices(); + if( err != paNoError ) goto error; + } + return sNumDevices; + +error: + PaHost_Term(); + DBUG(("Pa_CountDevices: returns %d\n", err )); + return err; + +} + +/*************************************************************************/ +const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceID id ) +{ + if( (id < 0) || ( id >= Pa_CountDevices()) ) return NULL; + return &sDevices[id].pad_Info; +} +/*************************************************************************/ +PaDeviceID Pa_GetDefaultInputDeviceID( void ) +{ + return sDefaultInputDeviceID; +} + +/*************************************************************************/ +PaDeviceID Pa_GetDefaultOutputDeviceID( void ) +{ + return sDefaultOutputDeviceID; +} + +/********************************* BEGIN CPU UTILIZATION MEASUREMENT ****/ +static void PaMac_StartLoadCalculation( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + UnsignedWide widePad; + if( pahsc == NULL ) return; + /* Query system timer for usage analysis and to prevent overuse of CPU. */ + Microseconds( &widePad ); + pahsc->pahsc_EntryCount = UnsignedWideToUInt64( widePad ); +} + +/****************************************************************************** +** Measure fractional CPU load based on real-time it took to calculate +** buffers worth of output. +*/ +/**************************************************************************/ +static void PaMac_EndLoadCalculation( internalPortAudioStream *past ) +{ + UnsignedWide widePad; + UInt64 currentCount; + long usecsElapsed; + double newUsage; + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return; + + /* Measure CPU utilization during this callback. Note that this calculation + ** assumes that we had the processor the whole time. + */ +#define LOWPASS_COEFFICIENT_0 (0.95) +#define LOWPASS_COEFFICIENT_1 (0.99999 - LOWPASS_COEFFICIENT_0) + Microseconds( &widePad ); + currentCount = UnsignedWideToUInt64( widePad ); + + usecsElapsed = (long) U64Subtract(currentCount, pahsc->pahsc_EntryCount); + + /* Use inverse because it is faster than the divide. */ + newUsage = usecsElapsed * pahsc->pahsc_InverseMicrosPerHostBuffer; + + past->past_Usage = (LOWPASS_COEFFICIENT_0 * past->past_Usage) + + (LOWPASS_COEFFICIENT_1 * newUsage); + +} + +/*********************************************************************** +** Called by Pa_StartStream() +*/ +PaError PaHost_StartInput( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + pahsc->pahsc_IsRecording = 0; + pahsc->pahsc_StopRecording = 0; + pahsc->pahsc_InputMultiBuffer.nextWrite = 0; + pahsc->pahsc_InputMultiBuffer.nextRead = 0; + return PaMac_RecordNext( past ); +} + +/*********************************************************************** +** Called by Pa_StopStream(). +** May be called during error recovery or cleanup code +** so protect against NULL pointers. +*/ +PaError PaHost_StopInput( internalPortAudioStream *past, int abort ) +{ + int32 timeOutMsec; + PaError result = paNoError; + OSErr err = 0; + long mRefNum; + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return paNoError; + + (void) abort; + + mRefNum = pahsc->pahsc_InputRefNum; + + DBUG(("PaHost_StopInput: mRefNum = %d\n", mRefNum )); + if( mRefNum ) + { + DBUG(("PaHost_StopInput: pahsc_IsRecording = %d\n", pahsc->pahsc_IsRecording )); + if( pahsc->pahsc_IsRecording ) + { + /* PLB20010420 - Fix TIMEOUT in record mode. */ + pahsc->pahsc_StopRecording = 1; /* Request that we stop recording. */ + err = SPBStopRecording(mRefNum); + DBUG(("PaHost_StopInput: then pahsc_IsRecording = %d\n", pahsc->pahsc_IsRecording )); + + /* Calculate timeOut longer than longest time it could take to play one buffer. */ + timeOutMsec = (int32) ((1500.0 * pahsc->pahsc_FramesPerHostBuffer) / past->past_SampleRate); + /* Keep querying sound channel until it is no longer busy playing. */ + while( !err && pahsc->pahsc_IsRecording && (timeOutMsec > 0)) + { + Pa_Sleep(20); + timeOutMsec -= 20; + } + if( timeOutMsec <= 0 ) + { + ERR_RPT(("PaHost_StopInput: timed out!\n")); + return paTimedOut; + } + } + } + if( err ) + { + sPaHostError = err; + result = paHostError; + } + + DBUG(("PaHost_StopInput: finished.\n", mRefNum )); + return result; +} + +/***********************************************************************/ +static void PaMac_InitSoundHeader( internalPortAudioStream *past, CmpSoundHeader *sndHeader ) +{ + sndHeader->numChannels = past->past_NumOutputChannels; + sndHeader->sampleRate = DoubleToUnsignedFixed(past->past_SampleRate); + sndHeader->loopStart = 0; + sndHeader->loopEnd = 0; + sndHeader->encode = cmpSH; + sndHeader->baseFrequency = kMiddleC; + sndHeader->markerChunk = nil; + sndHeader->futureUse2 = nil; + sndHeader->stateVars = nil; + sndHeader->leftOverSamples = nil; + sndHeader->compressionID = 0; + sndHeader->packetSize = 0; + sndHeader->snthID = 0; + sndHeader->sampleSize = 8 * sizeof(int16); // FIXME - might be 24 or 32 bits some day; + sndHeader->sampleArea[0] = 0; + sndHeader->format = kSoundNotCompressed; +} + +static void SetFramesDone( PaHostSoundControl *pahsc, PaTimestamp framesDone ) +{ + UnsignedWide now; + Microseconds( &now ); + pahsc->pahsc_NumFramesDone = framesDone; + pahsc->pahsc_WhenFramesDoneIncremented = UnsignedWideToUInt64( now ); +} + +/***********************************************************************/ +PaError PaHost_StartOutput( internalPortAudioStream *past ) +{ + SndCommand pauseCommand; + SndCommand resumeCommand; + int i; + OSErr error; + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return paInternalError; + if( pahsc->pahsc_Channel == NULL ) return paInternalError; + + past->past_StopSoon = 0; + past->past_IsActive = 1; + pahsc->pahsc_NumOutsQueued = 0; + pahsc->pahsc_NumOutsPlayed = 0; + + SetFramesDone( pahsc, 0.0 ); + + /* Pause channel so it does not do back ground processing while we are still filling the queue. */ + pauseCommand.cmd = pauseCmd; + pauseCommand.param1 = pauseCommand.param2 = 0; + error = SndDoCommand (pahsc->pahsc_Channel, &pauseCommand, true); + if (noErr != error) goto exit; + + /* Queue all of the buffers so we start off full. */ + for (i = 0; i<pahsc->pahsc_NumHostBuffers; i++) + { + PaMac_PlayNext( past, i ); + } + + /* Resume channel now that the queue is full. */ + resumeCommand.cmd = resumeCmd; + resumeCommand.param1 = resumeCommand.param2 = 0; + error = SndDoImmediate( pahsc->pahsc_Channel, &resumeCommand ); + if (noErr != error) goto exit; + + return paNoError; +exit: + past->past_IsActive = 0; + sPaHostError = error; + ERR_RPT(("Error in PaHost_StartOutput: SndDoCommand returned %d\n", error )); + return paHostError; +} + +/*******************************************************************/ +long PaHost_GetTotalBufferFrames( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + return (long) (pahsc->pahsc_NumHostBuffers * pahsc->pahsc_FramesPerHostBuffer); +} + +/*********************************************************************** +** Called by Pa_StopStream(). +** May be called during error recovery or cleanup code +** so protect against NULL pointers. +*/ +PaError PaHost_StopOutput( internalPortAudioStream *past, int abort ) +{ + int32 timeOutMsec; + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return paNoError; + if( pahsc->pahsc_Channel == NULL ) return paNoError; + + DBUG(("PaHost_StopOutput()\n")); + if( past->past_IsActive == 0 ) return paNoError; + + /* Set flags for callback function to see. */ + if( abort ) past->past_StopNow = 1; + past->past_StopSoon = 1; + /* Calculate timeOut longer than longest time it could take to play all buffers. */ + timeOutMsec = (int32) ((1500.0 * PaHost_GetTotalBufferFrames( past )) / past->past_SampleRate); + /* Keep querying sound channel until it is no longer busy playing. */ + while( past->past_IsActive && (timeOutMsec > 0)) + { + Pa_Sleep(20); + timeOutMsec -= 20; + } + if( timeOutMsec <= 0 ) + { + ERR_RPT(("PaHost_StopOutput: timed out!\n")); + return paTimedOut; + } + else return paNoError; +} + +/***********************************************************************/ +PaError PaHost_StartEngine( internalPortAudioStream *past ) +{ + (void) past; /* Prevent unused variable warnings. */ + return paNoError; +} + +/***********************************************************************/ +PaError PaHost_StopEngine( internalPortAudioStream *past, int abort ) +{ + (void) past; /* Prevent unused variable warnings. */ + (void) abort; /* Prevent unused variable warnings. */ + return paNoError; +} +/***********************************************************************/ +PaError PaHost_StreamActive( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + return (PaError) ( past->past_IsActive + pahsc->pahsc_IsRecording ); +} +int Mac_IsVirtualMemoryOn( void ) +{ + long attr; + OSErr result = Gestalt( gestaltVMAttr, &attr ); + DBUG(("gestaltVMAttr : 0x%x\n", attr )); + return ((attr >> gestaltVMHasPagingControl ) & 1); +} + +/******************************************************************* +* Determine number of host Buffers +* and how many User Buffers we can put into each host buffer. +*/ +static void PaHost_CalcNumHostBuffers( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + int32 minNumBuffers; + int32 minFramesPerHostBuffer; + int32 minTotalFrames; + int32 userBuffersPerHostBuffer; + int32 framesPerHostBuffer; + int32 numHostBuffers; + + minFramesPerHostBuffer = pahsc->pahsc_MinFramesPerHostBuffer; + minFramesPerHostBuffer = (minFramesPerHostBuffer + 7) & ~7; + DBUG(("PaHost_CalcNumHostBuffers: minFramesPerHostBuffer = %d\n", minFramesPerHostBuffer )); + + /* Determine number of user buffers based on minimum latency. */ + /* PLB20020417 I used to call Pa_GetMinNumBuffers() which doesn't take into account the + ** variable minFramesPerHostBuffer. Now I call PaMac_GetMinNumBuffers() which will + ** gove lower latency when virtual memory is turned off. */ + /* minNumBuffers = Pa_GetMinNumBuffers( past->past_FramesPerUserBuffer, past->past_SampleRate ); WRONG */ + minNumBuffers = PaMac_GetMinNumBuffers( minFramesPerHostBuffer, past->past_FramesPerUserBuffer, past->past_SampleRate ); + + past->past_NumUserBuffers = ( minNumBuffers > past->past_NumUserBuffers ) ? minNumBuffers : past->past_NumUserBuffers; + DBUG(("PaHost_CalcNumHostBuffers: min past_NumUserBuffers = %d\n", past->past_NumUserBuffers )); + minTotalFrames = past->past_NumUserBuffers * past->past_FramesPerUserBuffer; + + /* We cannot make the buffers too small because they may not get serviced quickly enough. */ + if( (int32) past->past_FramesPerUserBuffer < minFramesPerHostBuffer ) + { + userBuffersPerHostBuffer = + (minFramesPerHostBuffer + past->past_FramesPerUserBuffer - 1) / + past->past_FramesPerUserBuffer; + } + else + { + userBuffersPerHostBuffer = 1; + } + framesPerHostBuffer = past->past_FramesPerUserBuffer * userBuffersPerHostBuffer; + + /* Calculate number of host buffers needed. Round up to cover minTotalFrames. */ + numHostBuffers = (minTotalFrames + framesPerHostBuffer - 1) / framesPerHostBuffer; + /* Make sure we have enough host buffers. */ + if( numHostBuffers < PA_MIN_NUM_HOST_BUFFERS) + { + numHostBuffers = PA_MIN_NUM_HOST_BUFFERS; + } + else + { + /* If we have too many host buffers, try to put more user buffers in a host buffer. */ + while(numHostBuffers > PA_MAX_NUM_HOST_BUFFERS) + { + userBuffersPerHostBuffer += 1; + framesPerHostBuffer = past->past_FramesPerUserBuffer * userBuffersPerHostBuffer; + numHostBuffers = (minTotalFrames + framesPerHostBuffer - 1) / framesPerHostBuffer; + } + } + + pahsc->pahsc_UserBuffersPerHostBuffer = userBuffersPerHostBuffer; + pahsc->pahsc_FramesPerHostBuffer = framesPerHostBuffer; + pahsc->pahsc_NumHostBuffers = numHostBuffers; + DBUG(("PaHost_CalcNumHostBuffers: pahsc_UserBuffersPerHostBuffer = %d\n", pahsc->pahsc_UserBuffersPerHostBuffer )); + DBUG(("PaHost_CalcNumHostBuffers: pahsc_NumHostBuffers = %d\n", pahsc->pahsc_NumHostBuffers )); + DBUG(("PaHost_CalcNumHostBuffers: pahsc_FramesPerHostBuffer = %d\n", pahsc->pahsc_FramesPerHostBuffer )); + DBUG(("PaHost_CalcNumHostBuffers: past_NumUserBuffers = %d\n", past->past_NumUserBuffers )); +} + +/*******************************************************************/ +PaError PaHost_OpenStream( internalPortAudioStream *past ) +{ + OSErr err; + PaError result = paHostError; + PaHostSoundControl *pahsc; + int i; + /* Allocate and initialize host data. */ + pahsc = (PaHostSoundControl *) PaHost_AllocateFastMemory(sizeof(PaHostSoundControl)); + if( pahsc == NULL ) + { + return paInsufficientMemory; + } + past->past_DeviceData = (void *) pahsc; + + /* If recording, and virtual memory is turned on, then use bigger buffers to prevent glitches. */ + if( (past->past_NumInputChannels > 0) && Mac_IsVirtualMemoryOn() ) + { + pahsc->pahsc_MinFramesPerHostBuffer = MAC_VIRTUAL_FRAMES_PER_BUFFER; + } + else + { + pahsc->pahsc_MinFramesPerHostBuffer = MAC_PHYSICAL_FRAMES_PER_BUFFER; + } + + PaHost_CalcNumHostBuffers( past ); + + /* Setup constants for CPU load measurement. */ + pahsc->pahsc_InverseMicrosPerHostBuffer = past->past_SampleRate / (1000000.0 * pahsc->pahsc_FramesPerHostBuffer); + + /* ------------------ OUTPUT */ + if( past->past_NumOutputChannels > 0 ) + { + /* Create sound channel to which we can send commands. */ + pahsc->pahsc_Channel = 0L; + err = SndNewChannel(&pahsc->pahsc_Channel, sampledSynth, 0, nil); /* FIXME - use kUseOptionalOutputDevice if not default. */ + if(err != 0) + { + ERR_RPT(("Error in PaHost_OpenStream: SndNewChannel returned 0x%x\n", err )); + goto error; + } + + /* Install our callback function pointer straight into the sound channel structure */ + /* Use new CARBON name for callback procedure. */ +#if TARGET_API_MAC_CARBON + pahsc->pahsc_OutputCompletionProc = NewSndCallBackUPP(PaMac_OutputCompletionProc); +#else + pahsc->pahsc_OutputCompletionProc = NewSndCallBackProc(PaMac_OutputCompletionProc); +#endif + + pahsc->pahsc_Channel->callBack = pahsc->pahsc_OutputCompletionProc; + + pahsc->pahsc_BytesPerOutputHostBuffer = pahsc->pahsc_FramesPerHostBuffer * past->past_NumOutputChannels * sizeof(int16); + for (i = 0; i<pahsc->pahsc_NumHostBuffers; i++) + { + char *buf = (char *)PaHost_AllocateFastMemory(pahsc->pahsc_BytesPerOutputHostBuffer); + if (buf == NULL) + { + ERR_RPT(("Error in PaHost_OpenStream: could not allocate output buffer. Size = \n", pahsc->pahsc_BytesPerOutputHostBuffer )); + goto memerror; + } + + PaMac_InitSoundHeader( past, &pahsc->pahsc_SoundHeaders[i] ); + pahsc->pahsc_SoundHeaders[i].samplePtr = buf; + pahsc->pahsc_SoundHeaders[i].numFrames = (unsigned long) pahsc->pahsc_FramesPerHostBuffer; + + } + } +#ifdef SUPPORT_AUDIO_CAPTURE + /* ------------------ INPUT */ + /* Use double buffer scheme that matches output. */ + if( past->past_NumInputChannels > 0 ) + { + int16 tempS; + long tempL; + Fixed tempF; + long mRefNum; + Str255 namePString; +#if TARGET_API_MAC_CARBON + pahsc->pahsc_InputCompletionProc = NewSICompletionUPP((SICompletionProcPtr)PaMac_InputCompletionProc); +#else + pahsc->pahsc_InputCompletionProc = NewSICompletionProc((ProcPtr)PaMac_InputCompletionProc); +#endif + pahsc->pahsc_BytesPerInputHostBuffer = pahsc->pahsc_FramesPerHostBuffer * past->past_NumInputChannels * sizeof(int16); + for (i = 0; i<pahsc->pahsc_NumHostBuffers; i++) + { + char *buf = (char *) PaHost_AllocateFastMemory(pahsc->pahsc_BytesPerInputHostBuffer); + if ( buf == NULL ) + { + ERR_RPT(("PaHost_OpenStream: could not allocate input buffer. Size = \n", pahsc->pahsc_BytesPerInputHostBuffer )); + goto memerror; + } + pahsc->pahsc_InputMultiBuffer.buffers[i] = buf; + } + pahsc->pahsc_InputMultiBuffer.numBuffers = pahsc->pahsc_NumHostBuffers; + + // err = SPBOpenDevice( (const unsigned char *) &noname, siWritePermission, &mRefNum); + CToPString((char *)sDevices[past->past_InputDeviceID].pad_Info.name, namePString); + err = SPBOpenDevice(namePString, siWritePermission, &mRefNum); + + if (err) goto error; + pahsc->pahsc_InputRefNum = mRefNum; + DBUG(("PaHost_OpenStream: mRefNum = %d\n", mRefNum )); + + /* Set input device characteristics. */ + tempS = 1; + err = SPBSetDeviceInfo(mRefNum, siContinuous, (Ptr) &tempS); + if (err) + { + ERR_RPT(("Error in PaHost_OpenStream: SPBSetDeviceInfo siContinuous returned %d\n", err )); + goto error; + } + + tempL = 0x03; + err = SPBSetDeviceInfo(mRefNum, siActiveChannels, (Ptr) &tempL); + if (err) + { + DBUG(("PaHost_OpenStream: setting siActiveChannels returned 0x%x. Error ignored.\n", err )); + } + + /* PLB20010908 - Use requested number of input channels. Thanks Dominic Mazzoni. */ + tempS = past->past_NumInputChannels; + err = SPBSetDeviceInfo(mRefNum, siNumberChannels, (Ptr) &tempS); + if (err) + { + ERR_RPT(("Error in PaHost_OpenStream: SPBSetDeviceInfo siNumberChannels returned %d\n", err )); + goto error; + } + + tempF = ((unsigned long)past->past_SampleRate) << 16; + err = SPBSetDeviceInfo(mRefNum, siSampleRate, (Ptr) &tempF); + if (err) + { + ERR_RPT(("Error in PaHost_OpenStream: SPBSetDeviceInfo siSampleRate returned %d\n", err )); + goto error; + } + + /* Setup record-parameter block */ + pahsc->pahsc_InputParams.inRefNum = mRefNum; + pahsc->pahsc_InputParams.milliseconds = 0; // not used + pahsc->pahsc_InputParams.completionRoutine = pahsc->pahsc_InputCompletionProc; + pahsc->pahsc_InputParams.interruptRoutine = 0; + pahsc->pahsc_InputParams.userLong = (long) past; + pahsc->pahsc_InputParams.unused1 = 0; + } +#endif /* SUPPORT_AUDIO_CAPTURE */ + DBUG(("PaHost_OpenStream: complete.\n")); + return paNoError; + +error: + PaHost_CloseStream( past ); + ERR_RPT(("PaHost_OpenStream: sPaHostError = 0x%x.\n", err )); + sPaHostError = err; + return paHostError; + +memerror: + PaHost_CloseStream( past ); + return paInsufficientMemory; +} + +/*********************************************************************** +** Called by Pa_CloseStream(). +** May be called during error recovery or cleanup code +** so protect against NULL pointers. +*/ +PaError PaHost_CloseStream( internalPortAudioStream *past ) +{ + PaError result = paNoError; + OSErr err = 0; + int i; + PaHostSoundControl *pahsc; + + DBUG(("PaHost_CloseStream( 0x%x )\n", past )); + + if( past == NULL ) return paBadStreamPtr; + + pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return paNoError; + + if( past->past_NumOutputChannels > 0 ) + { + /* TRUE means flush now instead of waiting for quietCmd to be processed. */ + if( pahsc->pahsc_Channel != NULL ) SndDisposeChannel(pahsc->pahsc_Channel, TRUE); + { + for (i = 0; i<pahsc->pahsc_NumHostBuffers; i++) + { + Ptr p = (Ptr) pahsc->pahsc_SoundHeaders[i].samplePtr; + if( p != NULL ) PaHost_FreeFastMemory( p, pahsc->pahsc_BytesPerOutputHostBuffer ); + } + } + } + + if( past->past_NumInputChannels > 0 ) + { + if( pahsc->pahsc_InputRefNum ) + { + err = SPBCloseDevice(pahsc->pahsc_InputRefNum); + pahsc->pahsc_InputRefNum = 0; + if( err ) + { + sPaHostError = err; + result = paHostError; + } + } + { + for (i = 0; i<pahsc->pahsc_InputMultiBuffer.numBuffers; i++) + { + Ptr p = (Ptr) pahsc->pahsc_InputMultiBuffer.buffers[i]; + if( p != NULL ) PaHost_FreeFastMemory( p, pahsc->pahsc_BytesPerInputHostBuffer ); + } + } + } + + past->past_DeviceData = NULL; + PaHost_FreeFastMemory( pahsc, sizeof(PaHostSoundControl) ); + + DBUG(("PaHost_CloseStream: complete.\n", past )); + return result; +} +/*************************************************************************/ +int Pa_GetMinNumBuffers( int framesPerUserBuffer, double sampleRate ) +{ +/* We use the MAC_VIRTUAL_FRAMES_PER_BUFFER because we might be recording. +** This routine doesn't have enough information to determine the best value +** and is being depracated. */ + return PaMac_GetMinNumBuffers( MAC_VIRTUAL_FRAMES_PER_BUFFER, framesPerUserBuffer, sampleRate ); +} +/*************************************************************************/ +static int PaMac_GetMinNumBuffers( int minFramesPerHostBuffer, int framesPerUserBuffer, double sampleRate ) +{ + int minUserPerHost = ( minFramesPerHostBuffer + framesPerUserBuffer - 1) / framesPerUserBuffer; + int numBufs = PA_MIN_NUM_HOST_BUFFERS * minUserPerHost; + if( numBufs < PA_MIN_NUM_HOST_BUFFERS ) numBufs = PA_MIN_NUM_HOST_BUFFERS; + (void) sampleRate; + return numBufs; +} + +/*************************************************************************/ +void Pa_Sleep( int32 msec ) +{ + EventRecord event; + int32 sleepTime, endTime; + /* Convert to ticks. Round up so we sleep a MINIMUM of msec time. */ + sleepTime = ((msec * 60) + 999) / 1000; + if( sleepTime < 1 ) sleepTime = 1; + endTime = TickCount() + sleepTime; + do + { + DBUGX(("Sleep for %d ticks.\n", sleepTime )); + /* Use WaitNextEvent() to sleep without getting events. */ + /* PLB20010907 - Pass unused event to WaitNextEvent instead of NULL to prevent + * Mac OSX crash. Thanks Dominic Mazzoni. */ + WaitNextEvent( 0, &event, sleepTime, NULL ); + sleepTime = endTime - TickCount(); + } + while( sleepTime > 0 ); +} +/*************************************************************************/ +int32 Pa_GetHostError( void ) +{ + int32 err = sPaHostError; + sPaHostError = 0; + return err; +} + +/************************************************************************* + * Allocate memory that can be accessed in real-time. + * This may need to be held in physical memory so that it is not + * paged to virtual memory. + * This call MUST be balanced with a call to PaHost_FreeFastMemory(). + */ +void *PaHost_AllocateFastMemory( long numBytes ) +{ + void *addr = NewPtrClear( numBytes ); + if( (addr == NULL) || (MemError () != 0) ) return NULL; + +#if (TARGET_API_MAC_CARBON == 0) + if( HoldMemory( addr, numBytes ) != noErr ) + { + DisposePtr( (Ptr) addr ); + return NULL; + } +#endif + return addr; +} + +/************************************************************************* + * Free memory that could be accessed in real-time. + * This call MUST be balanced with a call to PaHost_AllocateFastMemory(). + */ +void PaHost_FreeFastMemory( void *addr, long numBytes ) +{ + if( addr == NULL ) return; +#if TARGET_API_MAC_CARBON + (void) numBytes; +#else + UnholdMemory( addr, numBytes ); +#endif + DisposePtr( (Ptr) addr ); +} + +/*************************************************************************/ +PaTimestamp Pa_StreamTime( PortAudioStream *stream ) +{ + PaTimestamp framesDone1; + PaTimestamp framesDone2; + UInt64 whenIncremented; + UnsignedWide now; + UInt64 now64; + long microsElapsed; + long framesElapsed; + + PaHostSoundControl *pahsc; + internalPortAudioStream *past = (internalPortAudioStream *) stream; + if( past == NULL ) return paBadStreamPtr; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + +/* Capture information from audio thread. + * We have to be careful that we don't get interrupted in the middle. + * So we grab the pahsc_NumFramesDone twice and make sure it didn't change. + */ + do + { + framesDone1 = pahsc->pahsc_NumFramesDone; + whenIncremented = pahsc->pahsc_WhenFramesDoneIncremented; + framesDone2 = pahsc->pahsc_NumFramesDone; + } while( framesDone1 != framesDone2 ); + + /* Calculate how many microseconds have elapsed and convert to frames. */ + Microseconds( &now ); + now64 = UnsignedWideToUInt64( now ); + microsElapsed = U64Subtract( now64, whenIncremented ); + framesElapsed = microsElapsed * past->past_SampleRate * 0.000001; + + return framesDone1 + framesElapsed; +} + +/************************************************************************** +** Callback for Input, SPBRecord() +*/ +int gRecordCounter = 0; +int gPlayCounter = 0; +pascal void PaMac_InputCompletionProc(SPBPtr recParams) +{ + PaError result = paNoError; + int finished = 1; + internalPortAudioStream *past; + PaHostSoundControl *pahsc; + + gRecordCounter += 1; /* debug hack to see if engine running */ + + /* Get our PA data from Mac structure. */ + past = (internalPortAudioStream *) recParams->userLong; + if( past == NULL ) return; + + if( past->past_Magic != PA_MAGIC ) + { + AddTraceMessage("PaMac_InputCompletionProc: bad MAGIC, past", (long) past ); + AddTraceMessage("PaMac_InputCompletionProc: bad MAGIC, magic", (long) past->past_Magic ); + goto error; + } + pahsc = (PaHostSoundControl *) past->past_DeviceData; + past->past_NumCallbacks += 1; + + /* Have we been asked to stop recording? */ + if( (recParams->error == abortErr) || pahsc->pahsc_StopRecording ) goto error; + + /* If there are no output channels, then we need to call the user callback function from here. + * Otherwise we will call the user code during the output completion routine. + */ + if(past->past_NumOutputChannels == 0) + { + SetFramesDone( pahsc, + pahsc->pahsc_NumFramesDone + pahsc->pahsc_FramesPerHostBuffer ); + result = PaMac_CallUserLoop( past, NULL ); + } + + /* Did user code ask us to stop? If not, issue another recording request. */ + if( (result == paNoError) && (pahsc->pahsc_StopRecording == 0) ) + { + result = PaMac_RecordNext( past ); + if( result != paNoError ) pahsc->pahsc_IsRecording = 0; + } + else goto error; + + return; + +error: + pahsc->pahsc_IsRecording = 0; + pahsc->pahsc_StopRecording = 0; + return; +} + +/*********************************************************************** +** Called by either input or output completion proc. +** Grabs input data if any present, and calls PA conversion code, +** that in turn calls user code. +*/ +static PaError PaMac_CallUserLoop( internalPortAudioStream *past, int16 *outPtr ) +{ + PaError result = paNoError; + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + int16 *inPtr = NULL; + int i; + + + /* Advance read index for sound input FIFO here, independantly of record/write process. */ + if(past->past_NumInputChannels > 0) + { + if( MultiBuffer_IsReadable( &pahsc->pahsc_InputMultiBuffer ) ) + { + inPtr = (int16 *) MultiBuffer_GetNextReadBuffer( &pahsc->pahsc_InputMultiBuffer ); + MultiBuffer_AdvanceReadIndex( &pahsc->pahsc_InputMultiBuffer ); + } + } + + /* Call user code enough times to fill buffer. */ + if( (inPtr != NULL) || (outPtr != NULL) ) + { + PaMac_StartLoadCalculation( past ); /* CPU usage */ + +#ifdef PA_MAX_USAGE_ALLOWED + /* If CPU usage exceeds limit, skip user callback to prevent hanging CPU. */ + if( past->past_Usage > PA_MAX_USAGE_ALLOWED ) + { + past->past_FrameCount += (PaTimestamp) pahsc->pahsc_FramesPerHostBuffer; + } + else +#endif + { + + for( i=0; i<pahsc->pahsc_UserBuffersPerHostBuffer; i++ ) + { + result = (PaError) Pa_CallConvertInt16( past, inPtr, outPtr ); + if( result != 0) + { + /* Recording might be in another process, so tell it to stop with a flag. */ + pahsc->pahsc_StopRecording = pahsc->pahsc_IsRecording; + break; + } + /* Advance sample pointers. */ + if(inPtr != NULL) inPtr += past->past_FramesPerUserBuffer * past->past_NumInputChannels; + if(outPtr != NULL) outPtr += past->past_FramesPerUserBuffer * past->past_NumOutputChannels; + } + } + + PaMac_EndLoadCalculation( past ); + } + return result; +} + +/*********************************************************************** +** Setup next recording buffer in FIFO and issue recording request to Snd Input Manager. +*/ +static PaError PaMac_RecordNext( internalPortAudioStream *past ) +{ + PaError result = paNoError; + OSErr err; + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + /* Get pointer to next buffer to record into. */ + pahsc->pahsc_InputParams.bufferPtr = MultiBuffer_GetNextWriteBuffer( &pahsc->pahsc_InputMultiBuffer ); + + /* Advance write index if there is room. Otherwise keep writing same buffer. */ + if( MultiBuffer_IsWriteable( &pahsc->pahsc_InputMultiBuffer ) ) + { + MultiBuffer_AdvanceWriteIndex( &pahsc->pahsc_InputMultiBuffer ); + } + + AddTraceMessage("PaMac_RecordNext: bufferPtr", (long) pahsc->pahsc_InputParams.bufferPtr ); + AddTraceMessage("PaMac_RecordNext: nextWrite", pahsc->pahsc_InputMultiBuffer.nextWrite ); + + /* Setup parameters and issue an asynchronous recording request. */ + pahsc->pahsc_InputParams.bufferLength = pahsc->pahsc_BytesPerInputHostBuffer; + pahsc->pahsc_InputParams.count = pahsc->pahsc_BytesPerInputHostBuffer; + err = SPBRecord(&pahsc->pahsc_InputParams, true); + if( err ) + { + AddTraceMessage("PaMac_RecordNext: SPBRecord error ", err ); + sPaHostError = err; + result = paHostError; + } + else + { + pahsc->pahsc_IsRecording = 1; + } + return result; +} + +/************************************************************************** +** Callback for Output Playback() +** Return negative error, 0 to continue, 1 to stop. +*/ +long PaMac_FillNextOutputBuffer( internalPortAudioStream *past, int index ) +{ + PaHostSoundControl *pahsc; + long result = 0; + int finished = 1; + char *outPtr; + + gPlayCounter += 1; /* debug hack */ + + past->past_NumCallbacks += 1; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return -1; + /* Are we nested?! */ + if( pahsc->pahsc_IfInsideCallback ) return 0; + pahsc->pahsc_IfInsideCallback = 1; + /* Get pointer to buffer to fill. */ + outPtr = pahsc->pahsc_SoundHeaders[index].samplePtr; + /* Combine with any sound input, and call user callback. */ + result = PaMac_CallUserLoop( past, (int16 *) outPtr ); + + pahsc->pahsc_IfInsideCallback = 0; + return result; +} + +/************************************************************************************* +** Called by SoundManager when ready for another buffer. +*/ +static pascal void PaMac_OutputCompletionProc (SndChannelPtr theChannel, SndCommand * theCallBackCmd) +{ + internalPortAudioStream *past; + PaHostSoundControl *pahsc; + (void) theChannel; + (void) theCallBackCmd; + + /* Get our data from Mac structure. */ + past = (internalPortAudioStream *) theCallBackCmd->param2; + if( past == NULL ) return; + + pahsc = (PaHostSoundControl *) past->past_DeviceData; + pahsc->pahsc_NumOutsPlayed += 1; + + SetFramesDone( pahsc, + pahsc->pahsc_NumFramesDone + pahsc->pahsc_FramesPerHostBuffer ); + + PaMac_BackgroundManager( past, theCallBackCmd->param1 ); +} + +/*******************************************************************/ +static PaError PaMac_BackgroundManager( internalPortAudioStream *past, int index ) +{ + PaError result = paNoError; + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + /* Has someone asked us to abort by calling Pa_AbortStream()? */ + if( past->past_StopNow ) + { + SndCommand command; + /* Clear the queue of any pending commands. */ + command.cmd = flushCmd; + command.param1 = command.param2 = 0; + SndDoImmediate( pahsc->pahsc_Channel, &command ); + /* Then stop currently playing buffer, if any. */ + command.cmd = quietCmd; + SndDoImmediate( pahsc->pahsc_Channel, &command ); + past->past_IsActive = 0; + } + /* Has someone asked us to stop by calling Pa_StopStream() + * OR has a user callback returned '1' to indicate finished. + */ + else if( past->past_StopSoon ) + { + if( (pahsc->pahsc_NumOutsQueued - pahsc->pahsc_NumOutsPlayed) <= 0 ) + { + past->past_IsActive = 0; /* We're finally done. */ + } + } + else + { + PaMac_PlayNext( past, index ); + } + return result; +} + +/************************************************************************************* +** Fill next buffer with sound and queue it for playback. +*/ +static void PaMac_PlayNext ( internalPortAudioStream *past, int index ) +{ + OSErr error; + long result; + SndCommand playCmd; + SndCommand callbackCmd; + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + + /* If this was the last buffer, or abort requested, then just be done. */ + if ( past->past_StopSoon ) goto done; + + /* Load buffer with sound. */ + result = PaMac_FillNextOutputBuffer ( past, index ); + if( result > 0 ) past->past_StopSoon = 1; /* Stop generating audio but wait until buffers play. */ + else if( result < 0 ) goto done; + + /* Play the next buffer. */ + playCmd.cmd = bufferCmd; + playCmd.param1 = 0; + playCmd.param2 = (long) &pahsc->pahsc_SoundHeaders[ index ]; + error = SndDoCommand (pahsc->pahsc_Channel, &playCmd, true ); + if( error != noErr ) goto gotError; + + /* Ask for a callback when it is done. */ + callbackCmd.cmd = callBackCmd; + callbackCmd.param1 = index; + callbackCmd.param2 = (long)past; + error = SndDoCommand (pahsc->pahsc_Channel, &callbackCmd, true ); + if( error != noErr ) goto gotError; + pahsc->pahsc_NumOutsQueued += 1; + + return; + +gotError: + sPaHostError = error; +done: + return; +} diff --git a/pd/portaudio_v18/pa_mac_core/pa_mac_core.c b/pd/portaudio_v18/pa_mac_core/pa_mac_core.c index 5bf24cb6..e0a31374 100644 --- a/pd/portaudio_v18/pa_mac_core/pa_mac_core.c +++ b/pd/portaudio_v18/pa_mac_core/pa_mac_core.c @@ -1,5 +1,5 @@ /* - * $Id: pa_mac_core.c,v 1.8.4.8 2003/03/07 01:34:18 philburk Exp $ + * $Id: pa_mac_core.c,v 1.8.4.12 2003/04/16 19:06:01 philburk Exp $ * pa_mac_core.c * Implementation of PortAudio for Mac OS X Core Audio * @@ -97,6 +97,17 @@ See code related to "streamInterleavingBuffer". 03.06.2003 - Phil Burk and Ryan Francesconi - fixed numChannels query for MOTU828. Handle fact that MOTU828 gives you 8 channels even when you ask for 2! + 04.06.2003 - Phil Burk - Combine Dominic Mazzoni's technique of using Configuration to query maxChannels + with old technique of scanning for mormat. + Increase channel scan by 1 to handle mono USB microphones. + Do not merge or split channels in AudioConverter to handle 2+2 channels + of Quattro which has a format of 2 channels. + 04.07.2003 - Phil Burk - use AudioGetCurrentHostTime instead of getrusage() which can lock threads. + 04.10.2003 - Phil Burk - fixed pointer bug with input deinterleaving loop. + Detect and ignore NULL inputData and outputData in CodeAudio callback. + Overlap creation and deletion of AudioConverters to prevent thread death when device rate changes. + 04.16.2003 - Phil Burk - Fixed input channel scrambling when numChannels != 2^N. Caused by alignment + error when filling RingBuffer with 2^N zero bytes. */ #include <CoreServices/CoreServices.h> @@ -107,12 +118,16 @@ #include <AudioUnit/AudioUnit.h> #include <AudioToolbox/DefaultAudioOutput.h> #include <AudioToolbox/AudioConverter.h> +#include <CoreAudio/HostTime.h> #include "portaudio.h" #include "pa_host.h" #include "pa_trace.h" #include "ringbuffer.h" +/************************************************* Configuration ********/ +#define PA_ENABLE_LOAD_MEASUREMENT (1) + /************************************************* Constants ********/ #define SET_DEVICE_BUFFER_SIZE (1) @@ -173,8 +188,8 @@ typedef struct PaHostSoundControl char *ringBufferData; Boolean formatListenerCalled; /* For measuring CPU utilization. */ - struct rusage entryRusage; - double inverseMicrosPerHostBuffer; /* 1/Microseconds of real-time audio per user buffer. */ + UInt64 entryTime; + double inverseHostTicksPerBuffer; /* 1/Ticks of real-time audio per user buffer. */ } PaHostSoundControl; /************************************************************** @@ -289,15 +304,7 @@ static void Pa_StartUsageCalculation( internalPortAudioStream *past ) PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; if( pahsc == NULL ) return; /* Query user CPU timer for usage analysis and to prevent overuse of CPU. */ - getrusage( RUSAGE_SELF, &pahsc->entryRusage ); -} - -static long SubtractTime_AminusB( struct timeval *timeA, struct timeval *timeB ) -{ - long secs = timeA->tv_sec - timeB->tv_sec; - long usecs = secs * 1000000; - usecs += (timeA->tv_usec - timeB->tv_usec); - return usecs; + pahsc->entryTime = AudioGetCurrentHostTime(); } /****************************************************************************** @@ -306,9 +313,9 @@ static long SubtractTime_AminusB( struct timeval *timeA, struct timeval *timeB ) */ static void Pa_EndUsageCalculation( internalPortAudioStream *past ) { - struct rusage currentRusage; - long usecsElapsed; - double newUsage; + UInt64 exitTime; + UInt64 ticksElapsed; + double newUsage; #define LOWPASS_COEFFICIENT_0 (0.95) #define LOWPASS_COEFFICIENT_1 (0.99999 - LOWPASS_COEFFICIENT_0) @@ -316,16 +323,15 @@ static void Pa_EndUsageCalculation( internalPortAudioStream *past ) PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; if( pahsc == NULL ) return; - if( getrusage( RUSAGE_SELF, ¤tRusage ) == 0 ) - { - usecsElapsed = SubtractTime_AminusB( ¤tRusage.ru_utime, &pahsc->entryRusage.ru_utime ); - - /* Use inverse because it is faster than the divide. */ - newUsage = usecsElapsed * pahsc->inverseMicrosPerHostBuffer; + exitTime = AudioGetCurrentHostTime(); + + ticksElapsed = exitTime - pahsc->entryTime; - past->past_Usage = (LOWPASS_COEFFICIENT_0 * past->past_Usage) + + /* Use inverse because it is faster than the divide. */ + newUsage = ticksElapsed * pahsc->inverseHostTicksPerBuffer; + /* Low pass filter result. */ + past->past_Usage = (LOWPASS_COEFFICIENT_0 * past->past_Usage) + (LOWPASS_COEFFICIENT_1 * newUsage); - } } /****************************************** END CPU UTILIZATION *******/ @@ -523,10 +529,61 @@ static int PaOSX_ScanDevices( Boolean isInput ) } /************************************************************************* -** Determine the maximum number of channels a device will support. +** Determine the maximum number of channels based on the configuration. ** @return maxChannels or negative error. */ -static int PaOSX_GetMaxChannels( AudioDeviceID devID, Boolean isInput ) +static int PaOSX_GetMaxChannels_Config( AudioDeviceID devID, Boolean isInput ) +{ + OSStatus err; + UInt32 outSize; + Boolean outWritable; + AudioBufferList *list; + int numChannels; + int i; + + // Determine maximum number of channels supported. + // dmazzoni: new method + + outSize = 0; + err = AudioDeviceGetPropertyInfo(devID, 0, isInput, + kAudioDevicePropertyStreamConfiguration, + &outSize, &outWritable); + if ( err != noErr ) + { + PRINT_ERR("PaOSX_GetMaxChannels_Config: Could not get stream configuration info", err); + sSavedHostError = err; + return paHostError; + } + + list = (AudioBufferList *)PaHost_AllocateFastMemory( outSize ); + err = AudioDeviceGetProperty(devID, 0, isInput, + kAudioDevicePropertyStreamConfiguration, + &outSize, list); + if ( err != noErr ) + { + PRINT_ERR("PaOSX_GetMaxChannels_Config: Could not get stream configuration", err); + sSavedHostError = err; + return paHostError; + } + + numChannels = 0; + for( i=0; i<list->mNumberBuffers; i++ ) + { + int bufChannels = list->mBuffers[i].mNumberChannels; + DBUG(("PaOSX_GetMaxChannels_Config: buffer %d has %d channels.\n", i, bufChannels )); + numChannels += bufChannels; + } + + PaHost_FreeFastMemory( list, outSize ); + + return numChannels; +} + +/************************************************************************* +** Determine the maximum number of channels a device will support based on scanning the format. +** @return maxChannels or negative error. +*/ +static int PaOSX_GetMaxChannels_Format( AudioDeviceID devID, Boolean isInput ) { OSStatus err; UInt32 outSize; @@ -540,13 +597,14 @@ static int PaOSX_GetMaxChannels( AudioDeviceID devID, Boolean isInput ) // For example, some 8 channel devices return 2 when given 256 as input. gotMax = false; maxChannels = 0; + numChannels = 0; while( !gotMax ) { memset( &formatDesc, 0, sizeof(formatDesc)); - numChannels = maxChannels + 2; - DBUG(("PaOSX_GetMaxChannels: try numChannels = %d = %d + 2\n", - numChannels, maxChannels )); + numChannels = numChannels + 1; + DBUG(("PaOSX_GetMaxChannels: try numChannels = %d = %d + 1\n", + numChannels, numChannels )); formatDesc.mChannelsPerFrame = numChannels; outSize = sizeof(formatDesc); @@ -557,7 +615,10 @@ static int PaOSX_GetMaxChannels( AudioDeviceID devID, Boolean isInput ) err, formatDesc.mChannelsPerFrame )); if( err != noErr ) { - gotMax = true; + if (numChannels > (maxChannels + 4)) // Try several possibilities above current max + { + gotMax = true; + } } else { @@ -568,7 +629,10 @@ static int PaOSX_GetMaxChannels( AudioDeviceID devID, Boolean isInput ) } else if(formatDesc.mChannelsPerFrame < numChannels) { - gotMax = true; + if (numChannels > (maxChannels + 4)) // Try several possibilities above current max + { + gotMax = true; + } } else { @@ -579,6 +643,24 @@ static int PaOSX_GetMaxChannels( AudioDeviceID devID, Boolean isInput ) return maxChannels; } + + +/************************************************************************* +** Determine the maximum number of channels a device will support. +** It is not clear at this point which the better technique so +** we do both and use the biggest result. +** +** @return maxChannels or negative error. +*/ +static int PaOSX_GetMaxChannels( AudioDeviceID devID, Boolean isInput ) +{ + int maxChannelsFormat; + int maxChannelsConfig; + maxChannelsFormat = PaOSX_GetMaxChannels_Format( devID, isInput ); + maxChannelsConfig = PaOSX_GetMaxChannels_Config( devID, isInput ); + return (maxChannelsFormat > maxChannelsConfig) ? maxChannelsFormat : maxChannelsConfig; +} + /************************************************************************* ** Try to fill in the device info for this device. ** Return 1 if a good device that PA can use. @@ -733,12 +815,22 @@ static OSStatus PaOSX_LoadAndProcess( internalPortAudioStream *past, inputBuffer = pahsc->input.converterBuffer; } + /* Measure CPU load. */ +#if PA_ENABLE_LOAD_MEASUREMENT + Pa_StartUsageCalculation( past ); +#endif + /* Fill part of audio converter buffer by converting input to user format, * calling user callback, then converting output to native format. */ if( PaConvert_Process( past, inputBuffer, outputBuffer )) { past->past_StopSoon = 1; } + +#if PA_ENABLE_LOAD_MEASUREMENT + Pa_EndUsageCalculation( past ); +#endif + } return err; } @@ -777,11 +869,11 @@ static OSStatus PaOSX_WriteInputRingBuffer( internalPortAudioStream *past, char *inputNativeBufferfPtr = NULL; PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; - /* Do we need to interleave the buffers first? */ + /* Do we need to deinterleave the buffers first? */ if( past->past_NumInputChannels != inInputData->mBuffers[0].mNumberChannels ) { - - numFramesInInputBuffer = inInputData->mBuffers[0].mDataByteSize / (sizeof(float) * inInputData->mBuffers[0].mNumberChannels); + numFramesInInputBuffer = inInputData->mBuffers[0].mDataByteSize / + (sizeof(float) * inInputData->mBuffers[0].mNumberChannels); numBytes = numFramesInInputBuffer * sizeof(float) * past->past_NumInputChannels; @@ -813,11 +905,14 @@ static OSStatus PaOSX_WriteInputRingBuffer( internalPortAudioStream *past, for( j=0; j<numChannelsUsedInThisBuffer; j++ ) { int k; + float *dest = &pahsc->input.streamInterleavingBuffer[ currentInterleavedChannelIndex ]; + float *src = &((float *)inInputData->mBuffers[i].mData)[ j ]; /* Move one channel from CoreAudio buffer to interleaved buffer. */ for( k=0; k<numFramesInInputBuffer; k++ ) { - pahsc->input.streamInterleavingBuffer[ k*numInterleavedChannels + currentInterleavedChannelIndex ] = - ((float *)inInputData->mBuffers[i].mData)[ k*numBufChannels + j ]; + *dest = *src; + src += numBufChannels; + dest += numInterleavedChannels; } currentInterleavedChannelIndex++; } @@ -830,7 +925,7 @@ static OSStatus PaOSX_WriteInputRingBuffer( internalPortAudioStream *past, else { inputNativeBufferfPtr = (char*)inInputData->mBuffers[0].mData; - numBytes += inInputData->mBuffers[0].mDataByteSize; + numBytes = inInputData->mBuffers[0].mDataByteSize; } writeRoom = RingBuffer_GetWriteAvailable( &pahsc->ringBuffer ); @@ -838,7 +933,7 @@ static OSStatus PaOSX_WriteInputRingBuffer( internalPortAudioStream *past, if( numBytes <= writeRoom ) { RingBuffer_Write( &pahsc->ringBuffer, inputNativeBufferfPtr, numBytes ); - DBUGBACK(("PaOSX_WriteInputRingBuffer: wrote %ld bytes to FIFO.\n", inInputData->mBuffers[0].mDataByteSize)); + DBUGBACK(("PaOSX_WriteInputRingBuffer: wrote %ld bytes to FIFO.\n", numBytes)); } // FIXME else drop samples on floor, remember overflow??? return noErr; @@ -854,6 +949,12 @@ static OSStatus PaOSX_HandleInput( internalPortAudioStream *past, OSStatus err = noErr; PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( inInputData == NULL ) + { + DBUG(("PaOSX_HandleInput: inInputData == NULL\n")); + return noErr; + } + if( inInputData->mNumberBuffers > 0 ) { /* Write to FIFO here if we are only using this callback. */ @@ -894,9 +995,16 @@ static OSStatus PaOSX_HandleOutput( internalPortAudioStream *past, Boolean deinterleavingNeeded; int numFramesInOutputBuffer; + if( outOutputData == NULL ) + { + DBUG(("PaOSX_HandleOutput: outOutputData == NULL\n")); + return noErr; + } + deinterleavingNeeded = past->past_NumOutputChannels != outOutputData->mBuffers[0].mNumberChannels; - numFramesInOutputBuffer = outOutputData->mBuffers[0].mDataByteSize / (sizeof(float) * outOutputData->mBuffers[0].mNumberChannels); + numFramesInOutputBuffer = outOutputData->mBuffers[0].mDataByteSize / + (sizeof(float) * outOutputData->mBuffers[0].mNumberChannels); if( pahsc->mode != PA_MODE_INPUT_ONLY ) { @@ -931,7 +1039,7 @@ static OSStatus PaOSX_HandleOutput( internalPortAudioStream *past, outputNativeBufferfPtr = (void*)outOutputData->mBuffers[0].mData; } - /* Pull code from PA user through converter. */ + /* Pull data from PA user through converter. */ err = AudioConverterFillBuffer( pahsc->output.converter, PaOSX_OutputConverterCallbackProc, @@ -962,11 +1070,14 @@ static OSStatus PaOSX_HandleOutput( internalPortAudioStream *past, for( j=0; j<numChannelsUsedInThisBuffer; j++ ) { int k; + float *dest = &((float *)outOutputData->mBuffers[i].mData)[ j ]; + float *src = &pahsc->output.streamInterleavingBuffer[ currentInterleavedChannelIndex ]; /* Move one channel from interleaved buffer to CoreAudio buffer. */ for( k=0; k<numFramesInOutputBuffer; k++ ) { - ((float *)outOutputData->mBuffers[i].mData)[ k*numBufChannels + j ] = - pahsc->output.streamInterleavingBuffer[ k*numInterleavedChannels + currentInterleavedChannelIndex ]; + *dest = *src; + dest += numBufChannels; + src += numInterleavedChannels; } currentInterleavedChannelIndex++; } @@ -999,7 +1110,7 @@ static OSStatus PaOSX_CoreAudioInputCallback (AudioDeviceID inDevice, const Aud pahsc = (PaHostSoundControl *) past->past_DeviceData; /* If there is a FIFO for input then write to it. */ - if( pahsc->ringBufferData != NULL ) + if( (pahsc->ringBufferData != NULL) && (inInputData != NULL) ) { err = PaOSX_WriteInputRingBuffer( past, inInputData ); if( err != noErr ) goto error; @@ -1051,8 +1162,6 @@ static OSStatus PaOSX_CoreAudioIOCallback (AudioDeviceID inDevice, const AudioT past->past_FrameCount = inInputTime->mSampleTime; } - /* Measure CPU load. */ - Pa_StartUsageCalculation( past ); past->past_NumCallbacks += 1; /* Process full input buffer. */ @@ -1062,8 +1171,6 @@ static OSStatus PaOSX_CoreAudioIOCallback (AudioDeviceID inDevice, const AudioT /* Fill up empty output buffers. */ err = PaOSX_HandleOutput( past, outOutputData ); if( err != 0 ) goto error; - - Pa_EndUsageCalculation( past ); } if( err != 0 ) DBUG(("PaOSX_CoreAudioIOCallback: returns %ld.\n", err )); @@ -1198,7 +1305,7 @@ static void PaOSX_FixVolumeScalars( AudioDeviceID devID, Boolean isInput, kAudioDevicePropertyMute, &dataSize, &uidata32 ); if( err == noErr ) { - DBUG(("uidata32 for channel %d = %ld\n", iChannel, uidata32)); + DBUG(("mute for channel %d = %ld\n", iChannel, uidata32)); if( uidata32 == 1 ) // muted? { dataSize = sizeof( uidata32 ); @@ -1304,24 +1411,16 @@ static OSStatus PAOSX_DevicePropertyListener (AudioDeviceID inDevice, UInt32 dataSize; OSStatus err = noErr; AudioStreamBasicDescription userStreamFormat, hardwareStreamFormat; - Boolean updateInverseMicros; - Boolean updateConverter; + PaHostInOut *hostInOut; + AudioStreamBasicDescription *destFormatPtr, *srcFormatPtr; past = (internalPortAudioStream *) inClientData; pahsc = (PaHostSoundControl *) past->past_DeviceData; DBUG(("PAOSX_DevicePropertyListener: called with propertyID = 0x%0X\n", (unsigned int) inPropertyID )); - updateInverseMicros = (inDevice == pahsc->primaryDeviceID) && - ((inPropertyID == kAudioDevicePropertyStreamFormat) || - (inPropertyID == kAudioDevicePropertyBufferFrameSize)); - - updateConverter = (inPropertyID == kAudioDevicePropertyStreamFormat); - - // Sample rate needed for both. - if( updateConverter || updateInverseMicros ) + if(inPropertyID == kAudioDevicePropertyStreamFormat) { - /* Get target device format */ dataSize = sizeof(hardwareStreamFormat); err = AudioDeviceGetProperty(inDevice, 0, isInput, @@ -1332,12 +1431,7 @@ static OSStatus PAOSX_DevicePropertyListener (AudioDeviceID inDevice, sSavedHostError = err; goto error; } - } - - if( updateConverter ) - { - DBUG(("PAOSX_DevicePropertyListener: HW rate = %f\n", hardwareStreamFormat.mSampleRate )); - DBUG(("PAOSX_DevicePropertyListener: user rate = %f\n", past->past_SampleRate )); + DBUG(("PAOSX_DevicePropertyListener: HW mChannelsPerFrame = %d\n", (int)hardwareStreamFormat.mChannelsPerFrame )); /* Set source user format. */ @@ -1349,69 +1443,48 @@ static OSStatus PAOSX_DevicePropertyListener (AudioDeviceID inDevice, userStreamFormat.mBytesPerFrame = userStreamFormat.mChannelsPerFrame * sizeof(float); userStreamFormat.mBytesPerPacket = userStreamFormat.mBytesPerFrame * userStreamFormat.mFramesPerPacket; - /* Don't use AudioConverter for merging channels. */ - if( hardwareStreamFormat.mChannelsPerFrame > userStreamFormat.mChannelsPerFrame ) - { - hardwareStreamFormat.mChannelsPerFrame = userStreamFormat.mChannelsPerFrame; - hardwareStreamFormat.mBytesPerFrame = userStreamFormat.mBytesPerFrame; - hardwareStreamFormat.mBytesPerPacket = userStreamFormat.mBytesPerPacket; - } - + /* Don't use AudioConverter for merging or splitting channels. */ + hardwareStreamFormat.mChannelsPerFrame = userStreamFormat.mChannelsPerFrame; + hardwareStreamFormat.mBytesPerFrame = userStreamFormat.mBytesPerFrame; + hardwareStreamFormat.mBytesPerPacket = userStreamFormat.mBytesPerPacket; + if( isInput ) { - if( pahsc->input.converter != NULL ) - { - verify_noerr(AudioConverterDispose (pahsc->input.converter)); - } - - // Convert from hardware format to user format. - err = AudioConverterNew ( - &hardwareStreamFormat, - &userStreamFormat, - &pahsc->input.converter ); - if( err != noErr ) - { - PRINT_ERR("Could not create input format converter", err); - sSavedHostError = err; - goto error; - } + hostInOut = &pahsc->input; + srcFormatPtr = &hardwareStreamFormat; + destFormatPtr = &userStreamFormat; } else { - if( pahsc->output.converter != NULL ) - { - verify_noerr(AudioConverterDispose (pahsc->output.converter)); - } - - // Convert from user format to hardware format. - err = AudioConverterNew ( - &userStreamFormat, - &hardwareStreamFormat, - &pahsc->output.converter ); - if( err != noErr ) - { - PRINT_ERR("Could not create output format converter", err); - sSavedHostError = err; - goto error; - } + hostInOut = &pahsc->output; + srcFormatPtr = &userStreamFormat; + destFormatPtr = &hardwareStreamFormat; } - } - - if( updateInverseMicros ) - { - // Update coefficient used to calculate CPU Load based on sampleRate and bufferSize. - UInt32 ioBufferSize; - dataSize = sizeof(ioBufferSize); - err = AudioDeviceGetProperty( inDevice, 0, isInput, - kAudioDevicePropertyBufferFrameSize, &dataSize, - &ioBufferSize); - if( err == noErr ) + DBUG(("PAOSX_DevicePropertyListener: source rate = %f\n", srcFormatPtr->mSampleRate )); + DBUG(("PAOSX_DevicePropertyListener: dest rate = %f\n", destFormatPtr->mSampleRate )); + + // Don't delete old converter until we create new one so we don't pull + // the rug out from under other audio threads. + AudioConverterRef oldConverter = hostInOut->converter; + + // Make converter to change sample rate. + err = AudioConverterNew ( + srcFormatPtr, + destFormatPtr, + &hostInOut->converter ); + if( err != noErr ) { - pahsc->inverseMicrosPerHostBuffer = hardwareStreamFormat.mSampleRate / - (1000000.0 * ioBufferSize); + PRINT_ERR("Could not create format converter", err); + sSavedHostError = err; + goto error; + } + + if( oldConverter != NULL ) + { + verify_noerr( AudioConverterDispose( oldConverter ) ); } } - + error: pahsc->formatListenerCalled = true; return err; @@ -1430,6 +1503,7 @@ static PaError PaOSX_CreateInputRingBuffer( internalPortAudioStream *past ) UInt32 framesPerHostBuffer; UInt32 bytesForDevice; UInt32 bytesForUser; + UInt32 bytesPerFrame; AudioStreamBasicDescription formatDesc; dataSize = sizeof(formatDesc); @@ -1437,7 +1511,7 @@ static PaError PaOSX_CreateInputRingBuffer( internalPortAudioStream *past ) kAudioDevicePropertyStreamFormat, &dataSize, &formatDesc); if( err != noErr ) { - PRINT_ERR("PaOSX_CreateInputRingBuffer: Could not get I/O buffer size.\n", err); + PRINT_ERR("PaOSX_CreateInputRingBuffer: Could not get input format.\n", err); sSavedHostError = err; return paHostError; } @@ -1452,15 +1526,15 @@ static PaError PaOSX_CreateInputRingBuffer( internalPortAudioStream *past ) &framesPerHostBuffer); if( err != noErr ) { - PRINT_ERR("PaOSX_CreateInputRingBuffer: Could not get I/O buffer size.\n", err); + PRINT_ERR("PaOSX_CreateInputRingBuffer: Could not get input buffer size.\n", err); sSavedHostError = err; return paHostError; } - bytesForDevice = framesPerHostBuffer * formatDesc.mChannelsPerFrame * sizeof(Float32) * 2; + bytesPerFrame = past->past_NumInputChannels * sizeof(Float32); - bytesForUser = past->past_FramesPerUserBuffer * past->past_NumInputChannels * - sizeof(Float32) * 3 * sampleRateRatio; + bytesForDevice = framesPerHostBuffer * bytesPerFrame * 2; + bytesForUser = past->past_FramesPerUserBuffer * bytesPerFrame * 3 * sampleRateRatio; // Ring buffer should be large enough to consume audio input from device, // and to deliver a complete user buffer. @@ -1475,8 +1549,13 @@ static PaError PaOSX_CreateInputRingBuffer( internalPortAudioStream *past ) return paInsufficientMemory; } RingBuffer_Init( &pahsc->ringBuffer, numBytes, pahsc->ringBufferData ); - // make it look full at beginning - RingBuffer_AdvanceWriteIndex( &pahsc->ringBuffer, numBytes ); + // Make it look almost full at beginning. We must advance by an integral number of frames + // so that the channels don't get scrambled when numChannels is not a power of 2. + { + int numZeroFrames = numBytes / bytesPerFrame; + int numZeroBytes = numZeroFrames * bytesPerFrame; + RingBuffer_AdvanceWriteIndex( &pahsc->ringBuffer, numZeroBytes ); + } return paNoError; } @@ -1750,7 +1829,7 @@ PaError PaHost_OpenStream( internalPortAudioStream *past ) DBUG(("outputDeviceID = %ld\n", pahsc->output.audioDeviceID )); DBUG(("inputDeviceID = %ld\n", pahsc->input.audioDeviceID )); DBUG(("primaryDeviceID = %ld\n", pahsc->primaryDeviceID )); - + /* ------------------ OUTPUT */ if( useOutput ) { @@ -1764,6 +1843,14 @@ PaError PaHost_OpenStream( internalPortAudioStream *past ) result = PaOSX_OpenInputDevice( past ); if( result < 0 ) goto error; } + +#if PA_ENABLE_LOAD_MEASUREMENT + pahsc->inverseHostTicksPerBuffer = past->past_SampleRate / + (AudioGetHostClockFrequency() * past->past_FramesPerUserBuffer); + DBUG(("inverseHostTicksPerBuffer based on buffer size of %d frames.\n", past->past_FramesPerUserBuffer )); +#else + PRINT(("WARNING - Pa_GetCPULoad() mesaurement disabled in pa_mac_core.c.\n")); +#endif return result; diff --git a/pd/portaudio_v18/pa_sgi/Makefile b/pd/portaudio_v18/pa_sgi/Makefile new file mode 100644 index 00000000..0cecda2d --- /dev/null +++ b/pd/portaudio_v18/pa_sgi/Makefile @@ -0,0 +1,63 @@ +# Makefile for pa_sgi. PortAudio for Silicon Graphics IRIX 6.2-6.5. +# Pieter suurmond, march 15, 2003. (pa-V18-patch). +# Tested under IRIX 6.5 with both GCC and MIPS compilers. +# Based on SGI-specific sproc()-method to spawn children, not on POSIX-threads. + +# Choose compiler in combination with options: + +CC = cc +CFLAGS = -O2 + +# Possible options with MIPSpro compiler are: -32, -o32, -n32, -64, +# -mips1, -mips2, -mips3, -mips4, etc. Use -g, -g2, -g3 for debugging. +# For GCC, use -Wall. And use for example -O2 or -O3 for better optimization: + +#CC = gcc +#CFLAGS = -O2 -Wall + +# Instead of "-lpthread", as with linux, just the audio- and math-library for SGI: + +LIBS = -laudio -lm + +# So sourcefiles can find included headerfiles in pa_common: +CDEFINES = -I../pa_common + +PASRC = ../pa_common/pa_lib.c pa_sgi.c +PAINC = ../pa_common/portaudio.h + +# Tests performed on SGI Indy with R5000 @ 180MHz running IRIX 6.5: +# Used GCC compiler version 3.0.4. and MIPS. + +TESTC = $(PASRC) ../pa_tests/patest_record.c ## OK GCC march 2003 (MIPS sees errors in patest_record.c, refuses compilation). +#TESTC = $(PASRC) ../pa_tests/patest_latency.c ## OK GCC march 2003. (MIPS doesn't like //) +#TESTC = $(PASRC) ../pa_tests/patest_longsine.c ## OK GCC march 2003. +#TESTC = $(PASRC) ../pa_tests/patest_wire.c ## OK GCC Click free now. march 2003. +#TESTC = $(PASRC) ../pa_tests/pa_fuzz.c ## OK GCC march 2003. + +#TESTC = $(PASRC) ../pa_tests/pa_devs.c # Never knew my Indy had 16 input- and output-channels! +#TESTC = $(PASRC) ../pa_tests/patest_saw.c ## - Pa_sleep doesn't work anymore?! +#TESTC = $(PASRC) ../pa_tests/patest_sine.c # - Pa_sleep doesn't work anymore?! +#TESTC = $(PASRC) ../pa_tests/patest_many.c ## - Pa_sleep doesn't work anymore?! +#TESTC = $(PASRC) ../pa_tests/patest_sine_time.c ## Silence for 2 seconds doesn't work, sine sounds ok. + +#TESTC = $(PASRC) ../pa_tests/patest_sine8.c ## Silence for 2 seconds doesn't work, sine sounds ok. +#TESTC = $(PASRC) ../pa_tests/patest_leftright.c # OK GCC and MIPS-CC march 2003. +#TESTC = $(PASRC) ../pa_tests/patest_pink.c ## OK GCC march 2003 +#TESTC = $(PASRC) ../pa_tests/patest_clip.c # +#TESTC = $(PASRC) ../pa_tests/patest_stop.c # MIPS doesn't like patest_stop.c Worked before but now + # error AL_BAD_QSIZE on IRIX 6.5 (with GCC). +#TESTC = $(PASRC) ../pa_tests/patest_dither.c # +#TESTC = $(PASRC) ../pa_tests/patest_sync.c # I don't hear the 6th beep, not really in sync @500ms lat. +#TESTC = $(PASRC) ../pa_tests/paqa_devs.c # A lot of error messages but no coredump. +#TESTC = $(PASRC) ../pa_tests/paqa_errs.c # Segmentation fault (core dumped)! + +TESTH = $(PAINC) + +all: patest + +patest: $(TESTC) $(TESTH) Makefile + $(CC) $(CFLAGS) $(TESTC) $(CDEFINES) $(LIBS) -o patest + +run: patest + ./patest + diff --git a/pd/portaudio_v18/pa_sgi/pa_sgi.c b/pd/portaudio_v18/pa_sgi/pa_sgi.c new file mode 100644 index 00000000..fa2978b5 --- /dev/null +++ b/pd/portaudio_v18/pa_sgi/pa_sgi.c @@ -0,0 +1,1069 @@ +/* + * $Id: pa_sgi.c,v 1.2.4.2 2003/03/13 00:56:47 pieter Exp $ + * PortAudio Portable Real-Time Audio Library. Copyright (c) 1999-2001 Phil Burk. + * Latest Version at: http://www.portaudio.com + * + * Silicon Graphics (SGI) IRIX implementation by Pieter Suurmond. + * This implementation uses sproc()-spawning, not the POSIX-threads. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * +MODIFICATIONS: + 8/12/2001 - Pieter Suurmond - took the v15 pa_linux_oss.c file and started to adapt for IRIX 6.2. + 8/17/2001 - v15, first unstable alpha release for IRIX, sent to Phil & Ross. + 9/23/2001 - Many fixes and changes: POLLIN for input, not POLLOUT! + 7/04/2002 - Implemented multiple user buffers per host buffer to allow clients that + request smaller buffersizes. + 3/13/2003 - Fixed clicks in full-duplex (wire) mode. Fixed some uninitialised vars, got rid of + all GCC-warnings (-Wall). Tested with MIPS compiler and GCC 3.0.4. on IRIX 6.5 (AL v7). +TODO: + - Dynamically switch to 32 bit float as native format when appropriate (let SGI do the conversion), + and maybe also the other natively supported formats? (might increase performance) + - Implement fancy callback block adapter as described in the PDF by Stephane Letz in the ASIO dir. + +REFERENCES: + - IRIX 6.2 man pages regarding SGI AL library. + - IRIS Digital Media Programming Guide (online books and man-pages come + with IRIX 6.2 and may not be publically available on the internet). +*/ + +#include <stdio.h> /* Standard libraries. */ +#include <stdlib.h> + +#include "../pa_common/portaudio.h" /* (Makefile fails to find in subdirs, -I doesn't work?). */ +#include "../pa_common/pa_host.h" +#include "../pa_common/pa_trace.h" + +#include <errno.h> /* Needed for int oserror(void);. */ +#include <sys/time.h> +#include <sys/types.h> +#include <sys/prctl.h> +#include <sys/schedctl.h> /* For schedctl(NDPRI, NDPHIMIN). */ +#include <fcntl.h> /* fcntl.h needed. */ +#include <unistd.h> /* For streams, ioctl(), etc. */ +#include <ulocks.h> +#include <poll.h> +#include <dmedia/audio.h> /* System specific (IRIX 6.2-6.5). */ + +/*----------------- MACROS --------------------*/ +#define PRINT(x) { printf x; fflush(stdout); } +#define ERR_RPT(x) PRINT(x) +#define DBUG(x) /* PRINT(x) */ +#define DBUGX(x) /* PRINT(x) */ + +#define MAX_CHARS_DEVNAME (16) +#define MAX_SAMPLE_RATES (8) /* Known from SGI AL there are 7. */ + /* Constants used in 'Pa_GetMinNumBuffers()' below: */ +#define MIN_LATENCY_MSEC (200) /* Used if 'getenv("PA_MIN_LATENCY_MSEC")' fails. */ +#define PA_LATENCY_ENV_NAME ("PA_MIN_LATENCY_MSEC") /* Same names as in file pa_unix.h. */ + +/*------------------------------- IRIX AL specific device info: --------------------------------------*/ +typedef struct internalPortAudioDevice +{ + PaDeviceID pad_DeviceID; /* THIS "ID" IS NEW HERE. */ + long pad_ALdevice; /* SGI-number! */ + double pad_SampleRates[MAX_SAMPLE_RATES]; /* For pointing to from pad_Info */ + char pad_DeviceName[MAX_CHARS_DEVNAME+1]; /* +1 for \0, one more than OSS. */ + PaDeviceInfo pad_Info; /* pad_Info (v15) contains: */ + struct internalPortAudioDevice* pad_Next; /* Singly linked list (NULL=end). */ +} internalPortAudioDevice; + +/*----------------- Structure containing all SGI IRIX specific data: ---------------------------------------*/ +typedef struct PaHostSoundControl +{ + ALconfig pahsc_ALconfigIN, /* IRIX-audio-library-datatype. Configuration */ + pahsc_ALconfigOUT; /* stucts separate for input and output ports. */ + ALport pahsc_ALportIN, /* IRIX-audio-library-datatype. ALports can only be */ + pahsc_ALportOUT; /* unidirectional, so we sometimes need 2 of them. */ + int pahsc_threadPID; /* Sproc()-result, written by PaHost_StartEngine(). */ + + unsigned int pahsc_UserBuffersPerHostBuffer, + pahsc_SamplesPerInputHostBuffer, /* Channels per frame are accounted for. */ + pahsc_SamplesPerOutputHostBuffer, + pahsc_BytesPerInputHostBuffer, /* Size per sample are accounted for. */ + pahsc_BytesPerOutputHostBuffer; + short *pahsc_InputHostBuffer, /* Allocated here, in this file, if necessary. */ + *pahsc_OutputHostBuffer; + + struct itimerval pahsc_EntryTime, /* For measuring CPU utilization (same as linux). */ + pahsc_LastExitTime; + long pahsc_InsideCountSum, + pahsc_TotalCountSum; +} PaHostSoundControl; + +/*-------------------------------------------------------- Shared Data -------------------------------*/ +static internalPortAudioDevice* sDeviceList = NULL; /* FIXME - put Mutex around this shared data. */ +static int sPaHostError = 0; /* Maybe more than one process writing errs!? */ +usema_t *SendSema, /* These variables are shared between the */ + *RcvSema; /* audio handling process and main process. */ +/*--------------------------*/ +long Pa_GetHostError(void) +{ + return (long)sPaHostError; +} + +/*----------------------------- BEGIN CPU UTILIZATION MEASUREMENT -----------------*/ +/* (copied from source pa_linux_oss/pa_linux_oss.c) */ +static void Pa_StartUsageCalculation( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return; + /* Query system timer for usage analysis and to prevent overuse of CPU. */ + getitimer( ITIMER_REAL, &pahsc->pahsc_EntryTime ); +} + +static long SubtractTime_AminusB( struct itimerval *timeA, struct itimerval *timeB ) +{ + long secs = timeA->it_value.tv_sec - timeB->it_value.tv_sec; + long usecs = secs * 1000000; + usecs += (timeA->it_value.tv_usec - timeB->it_value.tv_usec); + return usecs; +} + +static void Pa_EndUsageCalculation( internalPortAudioStream *past ) +{ + struct itimerval currentTime; + long insideCount; + long totalCount; /* Measure CPU utilization during this callback. */ + +#define LOWPASS_COEFFICIENT_0 (0.95) +#define LOWPASS_COEFFICIENT_1 (0.99999 - LOWPASS_COEFFICIENT_0) + + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if (pahsc == NULL) + return; + if (getitimer( ITIMER_REAL, ¤tTime ) == 0 ) + { + if (past->past_IfLastExitValid) + { + insideCount = SubtractTime_AminusB( &pahsc->pahsc_EntryTime, ¤tTime ); + pahsc->pahsc_InsideCountSum += insideCount; + totalCount = SubtractTime_AminusB( &pahsc->pahsc_LastExitTime, ¤tTime ); + pahsc->pahsc_TotalCountSum += totalCount; + /* DBUG(("insideCount = %d, totalCount = %d\n", insideCount, totalCount )); */ + /* Low pass filter the result because sometimes we get called several times in a row. */ + /* That can cause the TotalCount to be very low which can cause the usage to appear */ + /* unnaturally high. So we must filter numerator and denominator separately!!! */ + if (pahsc->pahsc_InsideCountSum > 0) + { + past->past_AverageInsideCount = ((LOWPASS_COEFFICIENT_0 * past->past_AverageInsideCount) + + (LOWPASS_COEFFICIENT_1 * pahsc->pahsc_InsideCountSum)); + past->past_AverageTotalCount = ((LOWPASS_COEFFICIENT_0 * past->past_AverageTotalCount) + + (LOWPASS_COEFFICIENT_1 * pahsc->pahsc_TotalCountSum)); + past->past_Usage = past->past_AverageInsideCount / past->past_AverageTotalCount; + pahsc->pahsc_InsideCountSum = 0; + pahsc->pahsc_TotalCountSum = 0; + } + } + past->past_IfLastExitValid = 1; + } + pahsc->pahsc_LastExitTime.it_value.tv_sec = 100; + pahsc->pahsc_LastExitTime.it_value.tv_usec = 0; + setitimer( ITIMER_REAL, &pahsc->pahsc_LastExitTime, NULL ); + past->past_IfLastExitValid = 1; +} /*----------- END OF CPU UTILIZATION CODE (from pa_linux_oss/pa_linux_oss.c v15)--------------------*/ + + +/*--------------------------------------------------------------------------------------*/ +PaError translateSGIerror(void) /* Calls oserror(), may be used after an SGI AL-library */ +{ /* call to report via ERR_RPT(), yields a PaError-num. */ + const char* a = "SGI AL "; /* (Not absolutely sure errno came from THIS thread! */ + switch(oserror()) /* Read IRIX man-pages about the _SGI_MP_SOURCE macro.) */ + { + case AL_BAD_OUT_OF_MEM: + ERR_RPT(("%sout of memory.\n", a)); + return paInsufficientMemory; /* Known PaError. */ + case AL_BAD_CONFIG: + ERR_RPT(("%sconfiguration invalid or NULL.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_CHANNELS: + ERR_RPT(("%schannels not 1,2 or 4.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_NO_PORTS: + ERR_RPT(("%sout of audio ports.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_DEVICE: + ERR_RPT(("%swrong device number.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_DEVICE_ACCESS: + ERR_RPT(("%swrong device access.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_DIRECTION: + ERR_RPT(("%sinvalid direction.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_SAMPFMT: + ERR_RPT(("%sdoesn't accept sampleformat.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_FLOATMAX: + ERR_RPT(("%smax float value is zero.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_WIDTH: + ERR_RPT(("%sunsupported samplewidth.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_QSIZE: + ERR_RPT(("%sinvalid queue size.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_PVBUFFER: + ERR_RPT(("%sPVbuffer null.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_BUFFERLENGTH_NEG: + ERR_RPT(("%snegative bufferlength.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_BUFFERLENGTH_ODD: + ERR_RPT(("%sodd bufferlength.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_PARAM: + ERR_RPT(("%sparameter not valid for device.\n", a)); + return paHostError; /* Generic PaError. */ + default: + ERR_RPT(("%sunknown error.\n", a)); + return paHostError; /* Generic PaError. */ + } +} + +/*------------------------------------------------------------------------------------------*/ +/* Tries to set various rates and formats and fill in the device info structure. */ +static PaError Pa_sgiQueryDevice(long ALdev, /* (AL_DEFAULT_DEVICE) */ + PaDeviceID id, /* (DefaultI|ODeviceID()) */ + char* name, /* (for example "SGI AL") */ + internalPortAudioDevice* pad) /* Result written to pad. */ +{ + long min, max; /* To catch hardware characteristics. */ + ALseterrorhandler(0); /* 0 = turn off the default error handler. */ + /*--------------------------------------------------------------------------------------*/ + pad->pad_ALdevice = ALdev; /* Set the AL device number. */ + pad->pad_DeviceID = id; /* Set the PA device number. */ + if (strlen(name) > MAX_CHARS_DEVNAME) /* MAX_CHARS defined above. */ + { + ERR_RPT(("Pa_QueryDevice(): name too long (%s).\n", name)); + return paHostError; + } + strcpy(pad->pad_DeviceName, name); /* Write name-string. */ + pad->pad_Info.name = pad->pad_DeviceName; /* Set pointer,..hmmm. */ + /*--------------------------------- natively supported sample formats: -----------------*/ + pad->pad_Info.nativeSampleFormats = paInt16; /* Later also include paFloat32 | ..| etc. */ + /* Then also choose other CallConvertXX()! */ + /*--------------------------------- number of available i/o channels: ------------------*/ + if (ALgetminmax(ALdev, AL_INPUT_COUNT, &min, &max)) + return translateSGIerror(); + pad->pad_Info.maxInputChannels = max; + DBUG(("Pa_QueryDevice: maxInputChannels = %d\n", pad->pad_Info.maxInputChannels)) + if (ALgetminmax(ALdev, AL_OUTPUT_COUNT, &min, &max)) + return translateSGIerror(); + pad->pad_Info.maxOutputChannels = max; + DBUG(("Pa_QueryDevice: maxOutputChannels = %d\n", pad->pad_Info.maxOutputChannels)) + /*--------------------------------- supported samplerates: ----------------------*/ + pad->pad_Info.numSampleRates = 7; + pad->pad_Info.sampleRates = pad->pad_SampleRates; + pad->pad_SampleRates[0] = (double)AL_RATE_8000; /* long -> double. */ + pad->pad_SampleRates[1] = (double)AL_RATE_11025; + pad->pad_SampleRates[2] = (double)AL_RATE_16000; + pad->pad_SampleRates[3] = (double)AL_RATE_22050; + pad->pad_SampleRates[4] = (double)AL_RATE_32000; + pad->pad_SampleRates[5] = (double)AL_RATE_44100; + pad->pad_SampleRates[6] = (double)AL_RATE_48000; + if (ALgetminmax(ALdev, AL_INPUT_RATE, &min, &max)) /* Ask INPUT rate-max. */ + return translateSGIerror(); /* double -> long. */ + if (max != (long)(0.5 + pad->pad_SampleRates[6])) /* FP-compare not recommndd. */ + goto weird; + if (ALgetminmax(ALdev, AL_OUTPUT_RATE, &min, &max)) /* Ask OUTPUT rate-max. */ + return translateSGIerror(); + if (max != (long)(0.5 + pad->pad_SampleRates[6])) + { +weird: ERR_RPT(("Pa_sgiQueryDevice() did not confirm max samplerate (%ld)\n",max)); + return paHostError; /* Or make it a warning and just carry on... */ + } + /*-------------------------------------------------------------------------------*/ + return paNoError; +} + + +/*--------------------------------------------------------------------------------*/ +int Pa_CountDevices() /* Name of this function suggests it only counts and */ +{ /* is NOT destructive, it however resets whole PA ! */ + int numDevices = 0; /* Let 's not do that here. */ + internalPortAudioDevice* currentDevice = sDeviceList; /* COPY GLOBAL VAR. */ +#if 0 /* Remains from linux_oss v15: Pa_Initialize(), on */ + if (!currentDevice) /* its turn, calls PaHost_Init() via file pa_lib.c. */ + Pa_Initialize(); /* Isn't that a bit too 'rude'? Don't be too */ +#endif /* friendly to clients that forgot to initialize PA. */ + while (currentDevice) /* Slower but more elegant than the sNumDevices-way: */ + { + numDevices++; + currentDevice = currentDevice->pad_Next; + } + return numDevices; +} + +/*-------------------------------------------------------------------------------*/ +static internalPortAudioDevice *Pa_GetInternalDevice(PaDeviceID id) +{ + int numDevices = 0; + internalPortAudioDevice *res = (internalPortAudioDevice*)NULL; + internalPortAudioDevice *pad = sDeviceList; /* COPY GLOBAL VAR. */ + while (pad) /* pad may be NULL, that's ok, return 0. */ + { /* (Added ->pad_DeviceID field to the pad-struct, Pieter, 2001.) */ + if (pad->pad_DeviceID == id) /* This the device we were looking for? */ + res = pad; /* But keep on(!) counting so we don't */ + numDevices++; /* have to call Pa_CountDevices() later. */ + pad = pad->pad_Next; /* Advance to the next device or NULL. */ + } /* No assumptions about order of ID's in */ + if (!res) /* the list. */ + ERR_RPT(("Pa_GetInternalDevice() could not find specified ID (%d).\n",id)); + if ((id < 0) || (id >= numDevices)) + { + ERR_RPT(("Pa_GetInternalDevice() supplied with an illegal ID (%d).\n",id)); +#if 1 /* Be strict, even when found, */ + res = (internalPortAudioDevice*)NULL; /* do not accept illegal ID's. */ +#endif + } + return res; +} + +/*----------------------------------------------------------------------*/ +const PaDeviceInfo* Pa_GetDeviceInfo(PaDeviceID id) +{ + PaDeviceInfo* res = (PaDeviceInfo*)NULL; + internalPortAudioDevice* pad = Pa_GetInternalDevice(id); /* Call. */ + if (pad) + res = &pad->pad_Info; /* Not finding the specified ID is not */ + if (!res) /* the same as &pad->pad_Info == NULL. */ + ERR_RPT(("Pa_GetDeviceInfo() could not find it (ID=%d).\n", id)); + return res; /* So (maybe) a second/third ERR_RPT(). */ +} + +/*------------------------------------------------*/ +PaDeviceID Pa_GetDefaultInputDeviceID(void) +{ + return 0; /* 0 is the default device ID. */ +} +/*------------------------------------------------*/ +PaDeviceID Pa_GetDefaultOutputDeviceID(void) +{ + return 0; +} + +/*-------------------------------------------------------------------------------------------------*/ +/* Build linked a list with all the available audio devices on this SGI machine (only 1 for now). */ +PaError PaHost_Init(void) /* Called by Pa_Initialize() from pa_lib.c. */ +{ + internalPortAudioDevice* pad; + PaError r = paNoError; + int audioLibFileID; /* To test for the presence of audio. */ + + if (sDeviceList) /* Allow re-init, only warn, no error. */ + { + ERR_RPT(("Warning: PaHost_Init() did not really re-init PA.\n")); + return r; + } + /*------------- ADD THE SGI DEFAULT DEVICE TO THE LIST: ---------------------------------------*/ + audioLibFileID = open("/dev/hdsp/hdsp0master", O_RDONLY); /* Try to open Indigo style audio */ + if (audioLibFileID < 0) /* IO port. On failure, machine */ + { /* has no audio ability. */ + ERR_RPT(("PaHost_Init(): This machine has no (Indigo-style) audio abilities.\n")); + return paHostError; + } + close(audioLibFileID); /* Allocate fast mem to hold device info. */ + pad = PaHost_AllocateFastMemory(sizeof(internalPortAudioDevice)); + if (pad == NULL) + return paInsufficientMemory; + memset(pad, 0, sizeof(internalPortAudioDevice)); /* "pad->pad_Next = NULL" is more elegant. */ + r = Pa_sgiQueryDevice(AL_DEFAULT_DEVICE, /* Set AL device num (AL_DEFAULT_DEVICE). */ + Pa_GetDefaultOutputDeviceID(),/* Set PA device num (or InputDeviceID()). */ + "AL default", /* A suitable name. */ + pad); /* Write args and queried info into pad. */ + if (r != paNoError) + { + ERR_RPT(("Pa_QueryDevice for '%s' returned: %d\n", pad->pad_DeviceName, r)); + PaHost_FreeFastMemory(pad, sizeof(internalPortAudioDevice)); /* sDeviceList still NULL ! */ + } + else + sDeviceList = pad; /* First element in linked list. pad->pad_Next already NULL. */ + /*------------- QUERY AND ADD MORE POSSIBLE SGI DEVICES TO THE LINKED LIST: -------------------*/ + /*---------------------------------------------------------------------------------------------*/ + return r; +} + +/*--------------------------------------------------------------------------------------------*/ +#define MIN(a,b) ((a)<(b)?(a):(b)) /* MIN()-function is used below. */ +#define kPollSEMA 0 /* To index the pollfd-array, reads nicer than just */ +#define kPollOUT 1 /* numbers. */ +#define kPollIN 2 +void Pa_SgiAudioProcess(void *v) /* This function is sproc-ed by PaHost_StartEngine() */ +{ /* as a separate thread. (Argument must be void*). */ + short evtLoop; /* Reset by parent indirectly, or at local errors. */ + PaError result; + struct pollfd PollFD[3]; /* To catch kPollSEMA-, kPollOUT- and kPollIN-events. */ + internalPortAudioStream *past = (internalPortAudioStream*)v; /* Copy void-ptr-argument. */ + PaHostSoundControl *pahsc; + short n, inputEvent, outputEvent, ioEvent, semaEvent = 0; + short *inBuffer, *outBuffer; /* Only 16 bit for now, may change... */ + unsigned int samplesPerInputUserBuffer, samplesPerOutputUserBuffer; + + DBUG(("Entering sproc-thread.\n")); + if (!past) + { + sPaHostError = paInternalError; /* Or paBadStreamPtr ? */ + ERR_RPT(("argument NULL!\n")); + goto noPast; + } + pahsc = (PaHostSoundControl*)past->past_DeviceData; + if (!pahsc) + { + sPaHostError = paInternalError; /* The only way is to signal error to shared area?! */ + ERR_RPT(("past_DeviceData NULL!\n")); + goto noPahsc; /* Sproc-ed threads MAY NOT RETURN paInternalError. */ + } + /*----------------------------- open AL-ports here, after sproc(): -----------------------*/ + if (past->past_NumInputChannels > 0) /* Open input port. */ + { + pahsc->pahsc_ALportIN = ALopenport("PA sgi in", "r", pahsc->pahsc_ALconfigIN); + if (!pahsc->pahsc_ALportIN) + { + ERR_RPT(("Failed to open AL input port.\n")); + sPaHostError = paInternalError; + goto skip; + } + DBUG(("Opened %d input channel(s).\n", past->past_NumInputChannels)); + samplesPerInputUserBuffer = pahsc->pahsc_SamplesPerInputHostBuffer / + pahsc->pahsc_UserBuffersPerHostBuffer; + } + else + samplesPerInputUserBuffer = 0; /* Added 2003. */ + if (past->past_NumOutputChannels > 0) /* Open output port. */ + { + pahsc->pahsc_ALportOUT = ALopenport("PA sgi out", "w", pahsc->pahsc_ALconfigOUT); + if (!pahsc->pahsc_ALportOUT) + { + ERR_RPT(("Failed to open AL output port.\n")); + sPaHostError = paInternalError; /* Assume pahsc_ALconfigs are the */ + goto skip; /* same for IN and OUT in case */ + } /* both ports are opened (bidir). */ + DBUG(("Opened %d output channel(s).\n", past->past_NumOutputChannels)); + samplesPerOutputUserBuffer = pahsc->pahsc_SamplesPerOutputHostBuffer / + pahsc->pahsc_UserBuffersPerHostBuffer; + DBUG(("samplesPerOutputUserBuffer = %d\n", samplesPerOutputUserBuffer)); + } + else + samplesPerOutputUserBuffer = 0; /* Added 2003. */ + /*-----------------------------------------------------------------------*/ + past->past_IsActive = 1; /* Wasn't this already done by the calling parent?! */ + PollFD[kPollIN].fd = ALgetfd(pahsc->pahsc_ALportIN); /* ALgetfd returns -1 on failures */ + PollFD[kPollIN].events = POLLIN; /* such as ALport not there. */ + PollFD[kPollOUT].fd = ALgetfd(pahsc->pahsc_ALportOUT); + PollFD[kPollOUT].events = POLLOUT; /* .events = POLLOUT is OK. */ + schedctl(NDPRI, NDPHIMIN); /* Sets non-degrading priority for this process. */ + PollFD[kPollSEMA].fd = usopenpollsema(SendSema, 0777); /* To communicate with parent. */ + PollFD[kPollSEMA].events = POLLIN; /* .events = POLLIN is OK. */ + uspsema(SendSema); /* Blocks until ... MUST be here, this uspsema(). */ + evtLoop = ((past->past_StopNow | past->past_StopSoon) == 0); + while (evtLoop) + { + /*----------------------------- SET FILLPOINTS AND WAIT UNTIL SOMETHING HAPPENS: ---------*/ + if (pahsc->pahsc_InputHostBuffer) /* Then pahsc_ALportIN should also be there. */ + { + /* For input port, fill point is number of locations in the sample queue that must be */ + /* filled in order to trigger a return from select(). (or poll()) */ + /* Notice IRIX docs mention number of samples as argument, not number of sampleframes.*/ + if (ALsetfillpoint(pahsc->pahsc_ALportIN, pahsc->pahsc_SamplesPerInputHostBuffer)) + { /* Multiple amount as transferred per time. */ + ERR_RPT(("ALsetfillpoint() for ALportIN failed.\n")); + sPaHostError = paInternalError; /* (Using exit(-1) would be a bit rude.) */ + goto skip; + } + } + /* 'else' added march 2003: set only one of both fillpoints: input or output. When */ + /* setting both fillpoints (as in earlier version) clicks occur at full duplex-mode. */ + else if (pahsc->pahsc_OutputHostBuffer) /* Then pahsc_ALportOUT should also be there. */ + { + /* For output port, fill point is number of locations that must be free in order to */ + /* wake up from select(). (or poll()) */ + if (ALsetfillpoint(pahsc->pahsc_ALportOUT, pahsc->pahsc_SamplesPerOutputHostBuffer)) + { + ERR_RPT(("ALsetfillpoint() for ALportOUT failed.\n")); + sPaHostError = paInternalError; + goto skip; + } + } /* poll() with timeout=-1 makes it block until a requested */ + poll(PollFD, 3, -1); /* event occurs or until call is interrupted. If fd-value in */ + /* array <0, events is ignored and revents is set to 0. */ + /*---------------------------- MESSAGE-EVENT FROM PARENT THREAD: -------------------------*/ + semaEvent = PollFD[kPollSEMA].revents & POLLIN; + if (semaEvent) + { + if (past->past_StopSoon) + evtLoop = 0; + if (past->past_StopNow) + goto skip; + } + /*------------------------------------- FILLED-EVENT FROM INPUT BUFFER: --------------------------*/ + inputEvent = PollFD[kPollIN].revents & POLLIN; + if (inputEvent) /* Don't need to check (pahsc->pahsc_InputHostBuffer): */ + { /* if buffer was not there, ALport not there, no events! */ + if (ALreadsamps(pahsc->pahsc_ALportIN, (void*)pahsc->pahsc_InputHostBuffer, + pahsc->pahsc_SamplesPerInputHostBuffer)) + { /* Here again: number of samples instead of number of frames. */ + ERR_RPT(("ALreadsamps() failed.\n")); + sPaHostError = paInternalError; + goto skip; + } + } + outputEvent = PollFD[kPollOUT].revents & POLLOUT; + ioEvent = (inputEvent | outputEvent); /* Binary or is ok. */ + /*------------------------------------- USER-CALLBACK-ROUTINE: -----------------------------------*/ + if (ioEvent) /* Always true? Or can some other system-event awaken the */ + { /* poll? Sure it wasn't just a "sema"- (i.e. user)-event? */ + Pa_StartUsageCalculation(past); /* Convert 16 bit native data to */ + /* user data and call user routine. */ + inBuffer = pahsc->pahsc_InputHostBuffer; /* Short pointers for now, care! */ + outBuffer = pahsc->pahsc_OutputHostBuffer; + n = pahsc->pahsc_UserBuffersPerHostBuffer; /* 'n' may never start at NULL ! */ + do { + result = Pa_CallConvertInt16(past, inBuffer, outBuffer); + if (result) /* This is apparently NOT an error! Just letting the userCallBack stop us. */ + { DBUG(("Pa_CallConvertInt16() returned %d, stopping...\n", result)); goto skip; } + inBuffer += samplesPerInputUserBuffer; /* Num channels is accounted for. */ + outBuffer += samplesPerOutputUserBuffer; + } while (--n); + Pa_EndUsageCalculation(past); + } + /*------------------------------------ FREE-EVENT FROM OUTPUT BUFFER: ---------------------------*/ + if (pahsc->pahsc_OutputHostBuffer && ioEvent) /* Don't wait for outputEvent solely (that may cause clicks). */ + { /* Just assume it's time to write, outputEvent may not yet be there. */ + if (ALwritesamps(pahsc->pahsc_ALportOUT, (void*)pahsc->pahsc_OutputHostBuffer, + pahsc->pahsc_SamplesPerOutputHostBuffer)) + { + ERR_RPT(("ALwritesamps() failed.\n")); /* Better use SEMAS for messaging back to parent! */ + sPaHostError = paInternalError; + goto skip; + } + } + } +skip: + /*------------------------------- close AL-ports ----------------------------*/ + if (pahsc->pahsc_ALportIN) + { + if (ALcloseport(pahsc->pahsc_ALportIN)) + translateSGIerror(); /* Translates SGI AL-code to PA-code and ERR_RPTs string. */ + else /* But go on anyway... to release other stuff... */ + pahsc->pahsc_ALportIN = (ALport)0; + } + if (pahsc->pahsc_ALportOUT) + { + if (ALcloseport(pahsc->pahsc_ALportOUT)) + translateSGIerror(); + else + pahsc->pahsc_ALportOUT = (ALport)0; + } +noPahsc: + past->past_IsActive = 0; + if (semaEvent) + { + uspsema(SendSema); /* StopEngine() was still waiting for this acknowledgement. */ + usvsema(RcvSema); /* (semaEvent initialized with 0.) */ + } +noPast: + DBUG(("Leaving sproc-thread.\n")); +} + + +/*--------------------------------------------------------------------------------------*/ +PaError PaHost_OpenStream(internalPortAudioStream *past) +{ + PaError result = paNoError; + PaHostSoundControl *pahsc; + unsigned int minNumBuffers; + internalPortAudioDevice *padIN, *padOUT; /* For looking up native AL-numbers. */ + long pvbuf[8], sr, alq; /* To get/set hardware configs. */ + + DBUG(("PaHost_OpenStream() called.\n")); /* Alloc FASTMEM and init host data. */ + if (!past) + { + ERR_RPT(("Streampointer NULL!\n")); + result = paBadStreamPtr; goto done; + } + pahsc = (PaHostSoundControl*)PaHost_AllocateFastMemory(sizeof(PaHostSoundControl)); + if (pahsc == NULL) + { + ERR_RPT(("FAST Memory allocation failed.\n")); /* Pass trough some ERR_RPT-exit- */ + result = paInsufficientMemory; goto done; /* code (nothing will be freed). */ + } + memset(pahsc, 0, sizeof(PaHostSoundControl)); + pahsc->pahsc_threadPID = -1; /* Should pahsc_threadPID be inited to */ + past->past_DeviceData = (void*)pahsc; /* -1 instead of 0 ?? */ + /*------------------------------------------ Manipulate hardware if necessary and allowed: --*/ + ALseterrorhandler(0); /* 0 = turn off the default error handler. */ + pvbuf[0] = AL_INPUT_RATE; + pvbuf[2] = AL_INPUT_COUNT; + pvbuf[4] = AL_OUTPUT_RATE; /* TO FIX: rates may be logically, not always in Hz! */ + pvbuf[6] = AL_OUTPUT_COUNT; + sr = (long)(past->past_SampleRate + 0.5); /* Common for both input and output :-) */ + /*-----------------------------------------------------------------------------*/ + /* OVERWRITE 'past_NumUserBuffers'-field in the struct supplied by the caller. */ + /* This field may be set to zero by a client application to ask for minimum */ + /* latency. It is used below, to set both input- and output-AL-queuesizes. */ + minNumBuffers = Pa_GetMinNumBuffers(past->past_FramesPerUserBuffer, + past->past_SampleRate); /* Take biggest. */ + past->past_NumUserBuffers = (minNumBuffers > past->past_NumUserBuffers) ? + minNumBuffers : past->past_NumUserBuffers; + DBUG(("past->past_NumUserBuffers=%d\n", past->past_NumUserBuffers)); + /*----------------------------------------------------------------------------------*/ + pahsc->pahsc_UserBuffersPerHostBuffer = past->past_NumUserBuffers >> 1; + DBUG(("pahsc_UserBuffersPerHostBuffer=%d\n",pahsc->pahsc_UserBuffersPerHostBuffer)); + /* 1 is minimum because Pa_GetMinNumBuffers() returns >= 2. + Callback will be called 'pahsc_UserBuffersPerHostBuffer' times (with 'past_FramesPerUserBuffer') + per host transfer. */ + /*---------------------------------------------------- SET INPUT CONFIGURATION: ---------------------*/ + if (past->past_NumInputChannels > 0) /* We need to lookup the corre- */ + { /* sponding native AL-number(s). */ + /*--------------------------------------------------- Allocate native buffers: --------------*/ + pahsc->pahsc_SamplesPerInputHostBuffer = pahsc->pahsc_UserBuffersPerHostBuffer * + past->past_FramesPerUserBuffer * /* Needed by the */ + past->past_NumInputChannels; /* audio-thread. */ + DBUG(("pahsc_SamplesPerInputHostBuffer=%d\n", pahsc->pahsc_SamplesPerInputHostBuffer)); + pahsc->pahsc_BytesPerInputHostBuffer = pahsc->pahsc_SamplesPerInputHostBuffer * sizeof(short); + pahsc->pahsc_InputHostBuffer = (short*)PaHost_AllocateFastMemory(pahsc->pahsc_BytesPerInputHostBuffer); + if (!pahsc->pahsc_InputHostBuffer) + { + ERR_RPT(("Fast memory allocation failed (in).\n")); + result = paInsufficientMemory; + goto done; + } + padIN = Pa_GetInternalDevice(past->past_InputDeviceID); + if (!padIN) + { + ERR_RPT(("Pa_GetInternalDevice() for input failed.\n")); + result = paHostError; + goto done; + } + if (ALgetparams(padIN->pad_ALdevice, &pvbuf[0], 4)) /* Although input and output will both be on */ + goto sgiError; /* the same AL-device, the AL-library might */ + if (pvbuf[1] != sr) /* contain more than AL_DEFAULT_DEVICE in */ + { /* Rate different from current harware-rate? the future. Therefore 2 seperate queries. */ + if (pvbuf[3] > 0) /* Means, there's other clients using AL-input-ports */ + { + ERR_RPT(("Sorry, not allowed to switch input-hardware to %ld Hz because \ +another process is currently using input at %ld Hz.\n", sr, pvbuf[1])); + result = paHostError; + goto done; + } + pvbuf[1] = sr; /* Then set input-rate. */ + if (ALsetparams(padIN->pad_ALdevice, &pvbuf[0], 2)) + goto sgiError; /* WHETHER THIS SAMPLERATE WAS REALLY PRESENT IN OUR ARRAY OF RATES, */ + } /* IS NOT CHECKED, AT LEAST NOT BY ME, WITHIN THIS FILE! Does PA do? */ + pahsc->pahsc_ALconfigIN = ALnewconfig(); /* Released at PaHost_CloseStream(). */ + if (pahsc->pahsc_ALconfigIN == (ALconfig)0) + goto sgiError; + if (ALsetsampfmt(pahsc->pahsc_ALconfigIN, AL_SAMPFMT_TWOSCOMP))/* Choose paInt16 as native i/o-format. */ + goto sgiError; + if (ALsetwidth (pahsc->pahsc_ALconfigIN, AL_SAMPLE_16)) /* Only meaningful when sample format for */ + goto sgiError; /* config is set to two's complement format. */ + /************************ Future versions might (dynamically) switch to 32-bit floats? ******* + if (ALsetsampfmt(pahsc_ALconfigIN, AL_SAMPFMT_FLOAT)) (Then also call another CallConvert-func.) + goto sgiError; + if (ALsetfloatmax (pahsc_ALconfigIN, 1.0)) Only meaningful when sample format for config + goto sgiError; is set to AL_SAMPFMT_FLOAT or AL_SAMPFMT_DOUBLE. */ + /*--------- Set internal AL queuesize (in samples, not in frames!) -------------------------------*/ + alq = (long)past->past_NumUserBuffers * past->past_FramesPerUserBuffer * past->past_NumInputChannels; + DBUG(("AL input queuesize = %ld samples.\n", alq)); + if (ALsetqueuesize(pahsc->pahsc_ALconfigIN, alq)) + goto sgiError; + if (ALsetchannels (pahsc->pahsc_ALconfigIN, (long)(past->past_NumInputChannels))) + goto sgiError; /* Returns 0 on success, -1 on failure. */ + } + else + pahsc->pahsc_InputHostBuffer = (short*)NULL; /* Added 2003! Is checked in callback-routine. */ + /*---------------------------------------------------- SET OUTPUT CONFIGURATION: ------------------------*/ + if (past->past_NumOutputChannels > 0) /* CARE: padOUT/IN may NOT be NULL if Channels <= 0! */ + { /* We use padOUT/IN later on, or at least 1 of both. */ + pahsc->pahsc_SamplesPerOutputHostBuffer = pahsc->pahsc_UserBuffersPerHostBuffer * + past->past_FramesPerUserBuffer * /* Needed by the */ + past->past_NumOutputChannels; /* audio-thread. */ + DBUG(("pahsc_SamplesPerOutputHostBuffer=%d\n", pahsc->pahsc_SamplesPerOutputHostBuffer)); + pahsc->pahsc_BytesPerOutputHostBuffer = pahsc->pahsc_SamplesPerOutputHostBuffer * sizeof(short); + pahsc->pahsc_OutputHostBuffer = (short*)PaHost_AllocateFastMemory(pahsc->pahsc_BytesPerOutputHostBuffer); + if (!pahsc->pahsc_OutputHostBuffer) + { + ERR_RPT(("Fast memory allocation failed (out).\n")); + result = paInsufficientMemory; + goto done; + } + padOUT = Pa_GetInternalDevice(past->past_OutputDeviceID); + if (!padOUT) + { + ERR_RPT(("Pa_GetInternalDevice() for output failed.\n")); + result = paHostError; + goto done; + } + if (ALgetparams(padOUT->pad_ALdevice,&pvbuf[4], 4)) + goto sgiError; + if (pvbuf[5] != sr) + { /* Output needed and rate different from current harware-rate. */ + if (pvbuf[7] > 0) /* Means, there's other clients using AL-output-ports */ + { + ERR_RPT(("Sorry, not allowed to switch output-hardware to %ld Hz because \ +another process is currently using output at %ld Hz.\n", sr, pvbuf[5])); + result = paHostError; + goto done; /* Will free again the inputbuffer */ + } /* that was just created above. */ + pvbuf[5] = sr; /* Then set output-rate. */ + if (ALsetparams(padOUT->pad_ALdevice, &pvbuf[4], 2)) + goto sgiError; + } + pahsc->pahsc_ALconfigOUT = ALnewconfig(); /* Released at PaHost_CloseStream(). */ + if (pahsc->pahsc_ALconfigOUT == (ALconfig)0) + goto sgiError; + if (ALsetsampfmt(pahsc->pahsc_ALconfigOUT, AL_SAMPFMT_TWOSCOMP)) /* Choose paInt16 as native i/o-format. */ + goto sgiError; + if (ALsetwidth (pahsc->pahsc_ALconfigOUT, AL_SAMPLE_16)) /* Only meaningful when sample format for */ + goto sgiError; /* config is set to two's complement format. */ + /** Future versions might (dynamically) switch to 32-bit floats. **/ + alq = (long)past->past_NumUserBuffers * past->past_FramesPerUserBuffer * past->past_NumOutputChannels; + DBUG(("AL output queuesize = %ld samples.\n", alq)); + if (ALsetqueuesize(pahsc->pahsc_ALconfigOUT, alq)) + goto sgiError; + if (ALsetchannels (pahsc->pahsc_ALconfigOUT, (long)(past->past_NumOutputChannels))) + goto sgiError; + } + else + pahsc->pahsc_OutputHostBuffer = (short*)NULL; + /*----------------------------------------------- TEST DEVICE ID's: --------------------*/ + if ((past->past_OutputDeviceID != past->past_InputDeviceID) && /* Who SETS these devive-numbers? */ + (past->past_NumOutputChannels > 0) && (past->past_NumInputChannels > 0)) + { + ERR_RPT(("Cannot setup bidirectional stream between different devices.\n")); + result = paHostError; + goto done; + } + goto done; /* (no errors occured) */ +sgiError: + result = translateSGIerror(); /* Translates SGI AL-code to PA-code and ERR_RPTs string. */ +done: + if (result != paNoError) + PaHost_CloseStream(past); /* Frees memory (only if really allocated!). */ + return result; +} + +/*-----------------------------------------------------*/ +PaError PaHost_StartOutput(internalPortAudioStream *past) +{ + return paNoError; /* Hmm, not implemented yet? */ +} +PaError PaHost_StartInput(internalPortAudioStream *past) +{ + return paNoError; +} + +/*------------------------------------------------------------------------------*/ +PaError PaHost_StartEngine(internalPortAudioStream *past) +{ + PaHostSoundControl *pahsc; + usptr_t *arena; + if (!past) /* Test argument. */ + { + ERR_RPT(("PaHost_StartEngine(NULL)!\n")); + return paBadStreamPtr; + } + pahsc = (PaHostSoundControl*)past->past_DeviceData; + if (!pahsc) + { + ERR_RPT(("PaHost_StartEngine(arg): arg->past_DeviceData = NULL!\n")); + return paHostError; + } + past->past_StopSoon = 0; /* Assume SGI ALport is already opened! */ + past->past_StopNow = 0; /* Why don't we check pahsc for NULL? */ + past->past_IsActive = 1; + + /* Although the pthread_create() function, as well as <pthread.h>, may be */ + /* available in IRIX, use sproc() on SGI to create audio-background-thread. */ + /* (Linux/oss uses pthread_create() instead of __clone() because: */ + /* - pthread_create also works for other UNIX systems like Solaris, */ + /* - Java HotSpot VM crashes in pthread_setcanceltype() using __clone().) */ + + usconfig(CONF_ARENATYPE, US_SHAREDONLY); /* (From SGI-AL-examples, file */ + arena = usinit(tmpnam(0)); /* motifexample.c, function */ + SendSema = usnewpollsema(arena, 0); /* InitializeAudioProcess().) */ + RcvSema = usnewsema(arena, 1); /* 1= common mutual exclusion semaphore, where 1 and only 1 process + will be permitted through a semaphore at a time. Values > 1 + imply that up to val resources may be simultaneously used, but requests + for more than val resources cause the calling process to block until a + resource comes free (by a process holding a resource performing a + usvsema(). IS THIS usnewsema() TOO PLATFORM SPECIFIC? */ + prctl(PR_SETEXITSIG, 0); /* No not (void*)9, but 0, which doesn't kill the parent! */ + /* PR_SETEXITSIG controls whether all members of a share group will be + signaled if any one of them leaves the share group (either via exit() + or exec()). If 2nd arg, interpreted as an int is 0, then normal IRIX + process termination rules apply, namely that the parent is sent a + SIGCLD upon death of child, but no indication of death of parent is + given. If the second argument is a valid signal number then if any + member of a share group leaves the share group, a signal is + sent to ALL surviving members of the share group. */ + /* SPAWN AUDIO-CHILD: */ + pahsc->pahsc_threadPID = sproc(Pa_SgiAudioProcess, /* Returns process ID of */ + PR_SALL, /* new process, or -1. */ + (void*)past); /* Pass past as optional */ /* IS THIS SAFE, will past never */ + if (pahsc->pahsc_threadPID == -1) /* third void-ptr-arg. */ /* be moved around in memory???? */ + { + ERR_RPT(("PaHost_StartEngine() failed to spawn audio-thread.\n")); + sPaHostError = oserror(); /* Pass native error-number to shared area. */ + return paHostError; /* But return the generic error-number. */ + } + return paNoError; /* Hmmm, errno may come from other threads in same group! */ +} /* ("man sproc" in IRIX6.2 to read about _SGI_MP_SOURCE.) */ + +/*------------------------------------------------------------------------------*/ +PaError PaHost_StopEngine(internalPortAudioStream *past, int abort) +{ + PaError result = paNoError; + PaHostSoundControl *pahsc; + + DBUG(("PaHost_StopEngine() called.\n")); + if (!past) + return paBadStreamPtr; + pahsc = (PaHostSoundControl*)past->past_DeviceData; + /* Prevent from doing this twice!! */ + if ((!pahsc) || /* Some tests call this CLOSE twice!! */ + (!past->past_IsActive) || + past->past_StopSoon || past->past_StopNow) + return result; /* paNoError (already stopped, no err?). */ + past->past_StopSoon = 1; /* Tell background thread to stop generating */ + if (abort) /* more and to let current data play out. If */ + past->past_StopNow = 1; /* aborting, tell backgrnd thread to stop NOW! */ + /*---- USE SEMAPHORE LOCK TO COMMUNICATE: -----*/ + usvsema(SendSema); /* Increments count associated with SendSema. */ + /* Wait for the response. */ + uspsema(RcvSema); /* Decrements count of previously allocated */ + /* semaphore specified by RcvSema. */ + while (past->past_IsActive) /* REALLY WAIT. */ + { + /* DBUG(("wait 1 ms for audio-thread to stop.\n")); */ + Pa_Sleep(1); + } + +#if 0 /* We don't need to KILL(), just COMMUNICATE and be patient... */ + if (pahsc->pahsc_threadPID != -1) /* Did we really init it to -1 somewhere? */ + { + DBUG(("PaHost_StopEngine() is about to kill(SIGKILL) audio-thread.\n")); + if (kill(pahsc->pahsc_threadPID, SIGKILL)) /* Or SIGTERM or SIGQUIT(core) */ + { /* Returns -1 in case of error. */ + result = paHostError; + sPaHostError = oserror(); /* Hmmm, other threads may also write here! */ + ERR_RPT(("PaHost_StopEngine() failed to kill audio-thread.\n")); + } + else + pahsc->pahsc_threadPID = -1; /* Notify that we've killed this thread. */ + } +#endif + past->past_IsActive = 0; /* Even when kill() failed and pahsc_threadPID still there??? */ + return result; +} + +/*---------------------------------------------------------------*/ +PaError PaHost_StopOutput(internalPortAudioStream *past, int abort) +{ + return paNoError; /* Not implemented yet? */ +} +PaError PaHost_StopInput(internalPortAudioStream *past, int abort ) +{ + return paNoError; +} + +/*******************************************************************/ +PaError PaHost_CloseStream(internalPortAudioStream *past) +{ + PaHostSoundControl *pahsc; + PaError result = paNoError; + + DBUG(("PaHost_CloseStream() called.\n")); + if (!past) + return paBadStreamPtr; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + if (!pahsc) /* If pahsc not NULL, past_DeviceData will be freed, and set to NULL. */ + return result; /* This test prevents from freeing NULL-pointers. */ + + if (pahsc->pahsc_ALconfigIN) + { /* Release configuration structs, only if allocated. */ + ALfreeconfig(pahsc->pahsc_ALconfigIN); + pahsc->pahsc_ALconfigIN = NULL; + } + if (pahsc->pahsc_ALconfigOUT) + { + ALfreeconfig(pahsc->pahsc_ALconfigOUT); /* (Al-ports were already closed by audioProcess). */ + pahsc->pahsc_ALconfigOUT = NULL; + } + if (pahsc->pahsc_InputHostBuffer) + { + PaHost_FreeFastMemory(pahsc->pahsc_InputHostBuffer, pahsc->pahsc_BytesPerInputHostBuffer); + pahsc->pahsc_InputHostBuffer = NULL; + } + if (pahsc->pahsc_OutputHostBuffer) + { + PaHost_FreeFastMemory(pahsc->pahsc_OutputHostBuffer, pahsc->pahsc_BytesPerOutputHostBuffer); + pahsc->pahsc_OutputHostBuffer = NULL; + } + PaHost_FreeFastMemory(pahsc, sizeof(PaHostSoundControl)); + past->past_DeviceData = NULL; /* PaHost_OpenStream() allocated FAST MEM. */ + return result; +} + + +/*------------------------------------------------------------------------*/ +/* Determine minimum number of buffers required for (SGI) host based on */ +/* minimum latency. Latency can be optionally set by user by setting an */ +/* environment variable. For example, to set my latency to 200 msec, I've */ +/* put this line in my '.cshrc' file: setenv PA_MIN_LATENCY_MSEC 200 */ +/* It always calls the 'PRINT' macro. */ +/* The minimum number that is returned is 2. */ +/* This number is directly proportional to the AL-queue sizes to set up. */ +/* It is one more than the number of user buffers per host buffer - in */ +/* case minimum is returned, or, twice the user buffers per host buffer. */ +/*------------------------------------------------------------------------*/ +int Pa_GetMinNumBuffers(int framesPerUserBuffer, double framesPerSecond) +{ + int minBuffers, minLatencyMsec; + char *minLatencyText; + double actualLatency; + + minLatencyText = getenv(PA_LATENCY_ENV_NAME); /* Defined at top of file. */ + if (minLatencyText) + { + minLatencyMsec = atoi(minLatencyText); + if (minLatencyMsec < 10) + { /* 10 is the minimum. */ + minLatencyMsec = 10; + PRINT (("Environment variable 'PA_MIN_LATENCY_MSEC' below minimum of %d milliseconds.\n", + minLatencyMsec)); + } + else if (minLatencyMsec > 4000) + { /* 4000 is the maximum. */ + minLatencyMsec = 4000; + PRINT (("Environment variable 'PA_MIN_LATENCY_MSEC' above maximum of %d milliseconds.\n", + minLatencyMsec)); + } + else + PRINT (("Using environment variable 'PA_MIN_LATENCY_MSEC' (set to %d milliseconds).\n", + minLatencyMsec)); + } + else + { + minLatencyMsec = MIN_LATENCY_MSEC; /* Defined at top of this file. */ + PRINT (("Environment variable 'PA_MIN_LATENCY_MSEC' not found.\nUsing default of %d milliseconds\n", + minLatencyMsec)); + } + minBuffers = (int)((minLatencyMsec * framesPerSecond) / + (1000.0 * framesPerUserBuffer)); + if (minBuffers < 2) + minBuffers = 2; + actualLatency = 1000.0 * minBuffers * framesPerUserBuffer / framesPerSecond; + PRINT (("Actual AL latency set to %.2f milliseconds\n", actualLatency)); + return minBuffers; +} + +/*---------------------------------------------------------------------*/ +PaError PaHost_Term(void) /* Frees all of the linked audio-devices. */ +{ /* Called by Pa_Terminate() from pa_lib.c. */ + internalPortAudioDevice *pad = sDeviceList, + *nxt; + while (pad) + { + DBUG(("PaHost_Term: freeing %s\n", pad->pad_DeviceName)); + nxt = pad->pad_Next; + PaHost_FreeFastMemory(pad, sizeof(internalPortAudioDevice)); + pad = nxt; /* PaHost_Init allocated this fast mem.*/ + } + sDeviceList = (internalPortAudioDevice*)NULL; + return 0; +} + +/***********************************************************************/ +void Pa_Sleep( long msec ) /* Sleep requested number of milliseconds. */ +{ +#if 0 + struct timeval timeout; + timeout.tv_sec = msec / 1000; + timeout.tv_usec = (msec % 1000) * 1000; + select(0, NULL, NULL, NULL, &timeout); +#else + long usecs = msec * 1000; + usleep( usecs ); +#endif +} + +/*---------------------------------------------------------------------------------------*/ +/* Allocate memory that can be accessed in real-time. This may need to be held in physi- */ +/* cal memory so that it is not paged to virtual memory. This call MUST be balanced with */ +/* a call to PaHost_FreeFastMemory(). */ +void *PaHost_AllocateFastMemory(long numBytes) +{ + void *addr = malloc(numBytes); /* mpin() reads into memory all pages over the given */ + if (addr) /* range and locks the pages into memory. A counter */ + { /* is incremented each time the page is locked. The */ + if (mpin(addr, numBytes)) /* superuser can lock as many pages as it wishes, */ + { /* others are limited to the configurable PLOCK_MA. */ + ERR_RPT(("PaHost_AllocateFastMemory() failed to mpin() memory.\n")); +#if 1 + free(addr); /* You MAY cut out these 2 lines to be less strict, */ + addr = NULL; /* you then only get the warning but PA goes on... */ +#endif /* Only problem then may be corresponding munpin() */ + } /* call at PaHost_FreeFastMemory(), below. */ + memset(addr, 0, numBytes); /* Locks established with mlock are not inherited by */ + } /* a child process after a fork. Furthermore, IRIX- */ + return addr; /* man-pages warn against mixing both mpin and mlock */ +} /* in 1 piece of code, so stick to mpin()/munpin() ! */ + + +/*---------------------------------------------------------------------------------------*/ +/* Free memory that could be accessed in real-time. This call MUST be balanced with a */ +/* call to PaHost_AllocateFastMemory(). */ +void PaHost_FreeFastMemory(void *addr, long numBytes) +{ + if (addr) + { + if (munpin(addr, numBytes)) /* Will munpin() fail when it was never mpinned? */ + ERR_RPT(("WARNING: PaHost_FreeFastMemory() failed to munpin() memory.\n")); + free(addr); /* But go on, try to release it, just warn... */ + } +} + +/*----------------------------------------------------------*/ +PaError PaHost_StreamActive( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc; + if (past == NULL) + return paBadStreamPtr; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + if (pahsc == NULL) + return paInternalError; + return (PaError)(past->past_IsActive != 0); +} + +/*-------------------------------------------------------------------*/ +PaTimestamp Pa_StreamTime( PortAudioStream *stream ) +{ + internalPortAudioStream *past = (internalPortAudioStream *) stream; +/* FIXME - return actual frames played, not frames generated. +** Need to query the output device somehow. +*/ + return past->past_FrameCount; +} diff --git a/pd/portaudio_v18/pa_sgi/pthread-Makefile b/pd/portaudio_v18/pa_sgi/pthread-Makefile new file mode 100644 index 00000000..527677a8 --- /dev/null +++ b/pd/portaudio_v18/pa_sgi/pthread-Makefile @@ -0,0 +1,52 @@ +# Make PortAudio for Silicon Graphics IRIX (6.2) +# Pieter suurmond, september 22, 2001. (v15 pa_sgi sub-version #0.18) + +# pthread, math (as with linux) and SGI audio library: +# SGI-books say -lpthread should be the last on the line. +LIBS = -lm -laudio -lpthread + +CDEFINES = -I../pa_common + +# Possible CFLAGS with MIPSpro compiler are: -32, -o32, -n32, -64, +# -mips1, -mips2, -mips3, -mips4, etc. Use -g, -g2, -g3 for debugging. +# And use for example -O2 or -O3 for better optimization: +CFLAGS = -O2 +PASRC = ../pa_common/pa_lib.c pa_sgi.c +PAINC = ../pa_common/portaudio.h + +# Tests that work (SGI Indy with R5000 @ 180MHz running IRIX 6.2). +#TESTC = $(PASRC) ../pa_tests/patest_record.c # OK +#TESTC = $(PASRC) ../pa_tests/patest_many.c # OK +#TESTC = $(PASRC) ../pa_tests/patest_latency.c # OK +#TESTC = $(PASRC) ../pa_tests/patest_longsine.c # OK but needs more than 4 buffers to do without glitches. +TESTC = $(PASRC) ../pa_tests/patest_saw.c # Seems OK (does it gracefully exit?). +#TESTC = $(PASRC) ../pa_tests/patest_wire.c # OK +#TESTC = $(PASRC) ../pa_tests/pa_devs.c # OK +#TESTC = $(PASRC) ../pa_tests/patest_sine.c # OK +#TESTC = $(PASRC) ../pa_tests/patest_sine_time.c # OK +#TESTC = $(PASRC) ../pa_tests/patest_sine8.c # OK +#TESTC = $(PASRC) ../pa_tests/patest_leftright.c # OK +#TESTC = $(PASRC) ../pa_tests/patest_pink.c # OK +#TESTC = $(PASRC) ../pa_tests/patest_clip.c # OK +#TESTC = $(PASRC) ../pa_tests/patest_stop.c # OK +#TESTC = $(PASRC) ../pa_tests/patest_dither.c # OK +#TESTC = $(PASRC) ../pa_tests/patest_sync.c # BEEPS and delta's, no crashes anymore. + +# Tests that do not yet work. +#TESTC = $(PASRC) ../pa_tests/paqa_devs.c # Heavy crash with core-dump after PaHost_OpenStream: opening 1 output channel(s) on AL default +#TESTC = $(PASRC) ../pa_tests/paqa_errs.c # Heavy crash with core-dump after PaHost_OpenStream: opening 2 output channel(s) on AL default +#TESTC = $(PASRC) ../pa_tests/pa_fuzz.c # THIS FUZZ CRASHED MY WHOLE IRIX SYSTEM after "ENTER"! :-( + # PROCESS IN ITSELF RUNS OK, WITH LARGER BUFFSIZES THOUGH. + # OH MAYBE IT WAS BECAUSE DEBUGGING WAS ON??? + # ANYWAY, I'M NOT GONNA RUN THAT AGAIN... WAY TOO DANGEROUS! +TESTH = $(PAINC) + +all: patest + +# "cc" for the MIPSpro compiler, may be changed to "gcc": +patest: $(TESTC) $(TESTH) Makefile + cc $(CFLAGS) $(TESTC) $(CDEFINES) $(LIBS) -o patest + +run: patest + ./patest + diff --git a/pd/portaudio_v18/pa_sgi/pthread-pa_sgi.c b/pd/portaudio_v18/pa_sgi/pthread-pa_sgi.c new file mode 100644 index 00000000..e9ab273c --- /dev/null +++ b/pd/portaudio_v18/pa_sgi/pthread-pa_sgi.c @@ -0,0 +1,908 @@ +/* + * PortAudio Portable Real-Time Audio Library + * Latest Version at: http://www.portaudio.com + * SGI IRIX implementation by Pieter Suurmond, september 22, 2001 (#0.18). + * + * Copyright (c) 1999-2001 Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +/* +Modfication History: + 8/12/2001 - Pieter Suurmond - took the v15 pa_linux_oss.c file and started to adapt for IRIX 6.2. + 8/17/2001 - alpha release with IRIX sproc()-method, may sometimes let IRIX6.2 crash at closing audiostream. + 9/22/2001 - #0.18 pthread starts to work a bit: + BUT UNDER IRIX6.2, I DON'T GET IT TO WORK REALLY CORRECTLY, + this POSIX-attempt, + DON'T USE THIS FILE FOR RELIABLE OPERATION, IT IS HERE JUST + FOR DOCUMENTATION/ARCHIVE... OR FOR ANYONE WHO WANTS TO FIX...... +TODO: + - Test under IRIX 6.5. + - Dynamically switch to 32 bit float as native format when appropriate (let SGI do the conversion), + and maybe also the other natively supported formats? (might increase performance) + - Not sure whether CPU UTILIZATION MEASUREMENT (from OSS/linux) really works. Changed nothing yet, + seems ok, but I've not yet tested it thoroughly. (maybe utilization-code may be made _unix_common_ then?) + - The minimal number of buffers setting... I do not yet fully understand it.. I now just take *4. +REFERENCES: + - IRIX 6.2 man pages regarding SGI AL library. + - IRIS Digital MediaProgramming Guide (online books as well as man-pages come with IRIX 6.2 and + may not be publically available on the internet). +*/ + +#include <stdio.h> /* Standard libraries. */ +#include <stdlib.h> + +#include "../pa_common/portaudio.h" /* Portaudio headers. */ +#include "../pa_common/pa_host.h" +#include "../pa_common/pa_trace.h" + +/* +#include <malloc.h> +#include <memory.h> +#include <sys/prctl.h> Not needed +#include <sys/types.h> +#include <sys/schedctl.h> +#include <signal.h> +#include <sys/ioctl.h> Needed? +#include <sys/time.h> +#include <sched.h> sched_param struct and related functions + used in setting thread priorities. +#include <limits.h> Some POSIX constants such as _POSIX_THREAD_THREADS_MAX +*/ + +#include <pthread.h> /* Pthreads are supported by IRIX 6.2 after */ + /* patches 1361, 1367, and 1429 are applied. */ + +#include <fcntl.h> /* fcntl.h needed for "O_RDONLY". */ +#include <unistd.h> /* For usleep() and constants used when calling sysconf() */ + /* to query POSIX limits (see the sysconf(3) ref. page. */ + +#include <dmedia/audio.h> /* SGI-specific audio library. */ + + +/*--------------------------------------------*/ +#define PRINT(x) { printf x; fflush(stdout); } +#define ERR_RPT(x) PRINT(x) +#define DBUG(x) PRINT(x) +#define DBUGX(x) /* PRINT(x) */ + +#define MAX_CHARS_DEVNAME (16) /* Was 32 in OSS (20 for AL but "in"/"out" is concat. */ +#define MAX_SAMPLE_RATES (8) /* Known from SGI AL there are 7 (was 10 in OSS v15). */ + +typedef struct internalPortAudioDevice /* IRIX specific device info: */ +{ + PaDeviceID /* NEW: */ pad_DeviceID; /* THIS "ID" IS NEW HERE (Pieter)! */ + long pad_ALdevice; /* SGI-number! */ + double pad_SampleRates[MAX_SAMPLE_RATES]; /* for pointing to from pad_Info */ + char pad_DeviceName[MAX_CHARS_DEVNAME+1]; /* +1 for \0, one more than OSS. */ + PaDeviceInfo pad_Info; /* pad_Info (v15) contains: */ + /* int structVersion; */ + /* const char* name; */ + /* int maxInputChannels, maxOutputChannels; */ + /* int numSampleRates; Num rates, or -1 if range supprtd. */ + /* const double* sampleRates; Array of supported sample rates, */ + /* PaSampleFormat nativeSampleFormats; or {min,max} if range supported. */ + struct internalPortAudioDevice* pad_Next; /* Singly linked list, (NULL=end). */ +} internalPortAudioDevice; + +typedef struct PaHostSoundControl /* Structure to contain all SGI IRIX specific data. */ +{ + ALport pahsc_ALportIN, /* IRIX-audio-library-datatype. ALports can only be */ + pahsc_ALportOUT; /* unidirectional, so we sometimes need 2 of them. */ + pthread_t pahsc_ThreadPID; + short *pahsc_NativeInputBuffer, /* Allocated here, in this file, if necessary. */ + *pahsc_NativeOutputBuffer; + unsigned int pahsc_BytesPerInputBuffer, /* Native buffer sizes in bytes, really needed here */ + pahsc_BytesPerOutputBuffer; /* to free FAST memory, if buffs were alloctd FAST. */ + unsigned int pahsc_SamplesPerInputBuffer, /* These amounts are needed again and again in the */ + pahsc_SamplesPerOutputBuffer; /* audio-thread (don't need to be kept globally). */ + struct itimerval pahsc_EntryTime, /* For measuring CPU utilization (same as linux). */ + pahsc_LastExitTime; + long pahsc_InsideCountSum, + pahsc_TotalCountSum; +} PaHostSoundControl; + +/*----------------------------- Shared Data ------------------------------------------------------*/ +static internalPortAudioDevice* sDeviceList = NULL; /* FIXME - put Mutex around this shared data. */ +static int sPaHostError = 0; /* Maybe more than one process writing errs!? */ + +long Pa_GetHostError(void) +{ + return (long)sPaHostError; +} + +/*----------------------------- BEGIN CPU UTILIZATION MEASUREMENT -----------------*/ +/* (copied from source pa_linux_oss/pa_linux_oss.c) */ +static void Pa_StartUsageCalculation( internalPortAudioStream *past ) +{ + struct itimerval itimer; + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return; +/* Query system timer for usage analysis and to prevent overuse of CPU. */ + getitimer( ITIMER_REAL, &pahsc->pahsc_EntryTime ); +} + +static long SubtractTime_AminusB( struct itimerval *timeA, struct itimerval *timeB ) +{ + long secs = timeA->it_value.tv_sec - timeB->it_value.tv_sec; + long usecs = secs * 1000000; + usecs += (timeA->it_value.tv_usec - timeB->it_value.tv_usec); + return usecs; +} + +static void Pa_EndUsageCalculation( internalPortAudioStream *past ) +{ + struct itimerval currentTime; + long insideCount; + long totalCount; /* Measure CPU utilization during this callback. */ + +#define LOWPASS_COEFFICIENT_0 (0.95) +#define LOWPASS_COEFFICIENT_1 (0.99999 - LOWPASS_COEFFICIENT_0) + + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if (pahsc == NULL) + return; + if (getitimer( ITIMER_REAL, ¤tTime ) == 0 ) + { + if (past->past_IfLastExitValid) + { + insideCount = SubtractTime_AminusB( &pahsc->pahsc_EntryTime, ¤tTime ); + pahsc->pahsc_InsideCountSum += insideCount; + totalCount = SubtractTime_AminusB( &pahsc->pahsc_LastExitTime, ¤tTime ); + pahsc->pahsc_TotalCountSum += totalCount; + /* DBUG(("insideCount = %d, totalCount = %d\n", insideCount, totalCount )); */ + /* Low pass filter the result because sometimes we get called several times in a row. */ + /* That can cause the TotalCount to be very low which can cause the usage to appear */ + /* unnaturally high. So we must filter numerator and denominator separately!!! */ + if (pahsc->pahsc_InsideCountSum > 0) + { + past->past_AverageInsideCount = ((LOWPASS_COEFFICIENT_0 * past->past_AverageInsideCount) + + (LOWPASS_COEFFICIENT_1 * pahsc->pahsc_InsideCountSum)); + past->past_AverageTotalCount = ((LOWPASS_COEFFICIENT_0 * past->past_AverageTotalCount) + + (LOWPASS_COEFFICIENT_1 * pahsc->pahsc_TotalCountSum)); + past->past_Usage = past->past_AverageInsideCount / past->past_AverageTotalCount; + pahsc->pahsc_InsideCountSum = 0; + pahsc->pahsc_TotalCountSum = 0; + } + } + past->past_IfLastExitValid = 1; + } + pahsc->pahsc_LastExitTime.it_value.tv_sec = 100; + pahsc->pahsc_LastExitTime.it_value.tv_usec = 0; + setitimer( ITIMER_REAL, &pahsc->pahsc_LastExitTime, NULL ); + past->past_IfLastExitValid = 1; +} /*----------- END OF CPU UTILIZATION CODE (from pa_linux_oss/pa_linux_oss.c v15)--------------------*/ + + +/*--------------------------------------------------------------------------------------*/ +PaError translateSGIerror(void) /* Calls oserror(), may be used after an SGI AL-library */ +{ /* call to report via ERR_RPT(), yields a PaError-num. */ + const char* a = "SGI AL "; /* (Not absolutely sure errno came from THIS thread! */ + switch(oserror()) /* Read IRIX man-pages about the _SGI_MP_SOURCE macro.) */ + { + case AL_BAD_OUT_OF_MEM: + ERR_RPT(("%sout of memory.\n", a)); + return paInsufficientMemory; /* Known PaError. */ + case AL_BAD_CONFIG: + ERR_RPT(("%sconfiguration invalid or NULL.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_CHANNELS: + ERR_RPT(("%schannels not 1,2 or 4.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_NO_PORTS: + ERR_RPT(("%sout of audio ports.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_DEVICE: + ERR_RPT(("%swrong device number.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_DEVICE_ACCESS: + ERR_RPT(("%swrong device access.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_DIRECTION: + ERR_RPT(("%sinvalid direction.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_SAMPFMT: + ERR_RPT(("%sdoesn't accept sampleformat.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_FLOATMAX: + ERR_RPT(("%smax float value is zero.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_WIDTH: + ERR_RPT(("%sunsupported samplewidth.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_QSIZE: + ERR_RPT(("%sinvalid queue size.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_PVBUFFER: + ERR_RPT(("%sPVbuffer null.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_BUFFERLENGTH_NEG: + ERR_RPT(("%snegative bufferlength.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_BUFFERLENGTH_ODD: + ERR_RPT(("%sodd bufferlength.\n", a)); + return paHostError; /* Generic PaError. */ + case AL_BAD_PARAM: + ERR_RPT(("%sparameter not valid for device.\n", a)); + return paHostError; /* Generic PaError. */ + default: + ERR_RPT(("%sunknown error.\n", a)); + return paHostError; /* Generic PaError. */ + } +} + +/*------------------------------------------------------------------------------------------*/ +/* Tries to set various rates and formats and fill in the device info structure. */ +static PaError Pa_sgiQueryDevice(long ALdev, /* (AL_DEFAULT_DEVICE) */ + PaDeviceID id, /* (DefaultI|ODeviceID()) */ + char* name, /* (for example "SGI AL") */ + internalPortAudioDevice* pad) /* Result written to pad. */ +{ + int format; + long min, max; /* To catch hardware characteristics. */ + ALseterrorhandler(0); /* 0 = turn off the default error handler. */ + /*--------------------------------------------------------------------------------------*/ + pad->pad_ALdevice = ALdev; /* Set the AL device number. */ + pad->pad_DeviceID = id; /* Set the PA device number. */ + if (strlen(name) > MAX_CHARS_DEVNAME) /* MAX_CHARS defined above. */ + { + ERR_RPT(("Pa_QueryDevice(): name too long (%s).\n", name)); + return paHostError; + } + strcpy(pad->pad_DeviceName, name); /* Write name-string. */ + pad->pad_Info.name = pad->pad_DeviceName; /* Set pointer,..hmmm. */ + /*--------------------------------- natively supported sample formats: -----------------*/ + pad->pad_Info.nativeSampleFormats = paInt16; /* Later also include paFloat32 | ..| etc. */ + /* Then also choose other CallConvertXX()! */ + /*--------------------------------- number of available i/o channels: ------------------*/ + if (ALgetminmax(ALdev, AL_INPUT_COUNT, &min, &max)) + return translateSGIerror(); + pad->pad_Info.maxInputChannels = max; + DBUG(("Pa_QueryDevice: maxInputChannels = %d\n", pad->pad_Info.maxInputChannels)) + if (ALgetminmax(ALdev, AL_OUTPUT_COUNT, &min, &max)) + return translateSGIerror(); + pad->pad_Info.maxOutputChannels = max; + DBUG(("Pa_QueryDevice: maxOutputChannels = %d\n", pad->pad_Info.maxOutputChannels)) + /*--------------------------------- supported samplerates: ----------------------*/ + pad->pad_Info.numSampleRates = 7; + pad->pad_Info.sampleRates = pad->pad_SampleRates; + pad->pad_SampleRates[0] = (double)AL_RATE_8000; /* long -> double. */ + pad->pad_SampleRates[1] = (double)AL_RATE_11025; + pad->pad_SampleRates[2] = (double)AL_RATE_16000; + pad->pad_SampleRates[3] = (double)AL_RATE_22050; + pad->pad_SampleRates[4] = (double)AL_RATE_32000; + pad->pad_SampleRates[5] = (double)AL_RATE_44100; + pad->pad_SampleRates[6] = (double)AL_RATE_48000; + if (ALgetminmax(ALdev, AL_INPUT_RATE, &min, &max)) /* Ask INPUT rate-max. */ + return translateSGIerror(); /* double -> long. */ + if (max != (long)(0.5 + pad->pad_SampleRates[6])) /* FP-compare not recommndd. */ + goto weird; + if (ALgetminmax(ALdev, AL_OUTPUT_RATE, &min, &max)) /* Ask OUTPUT rate-max. */ + return translateSGIerror(); + if (max != (long)(0.5 + pad->pad_SampleRates[6])) + { +weird: ERR_RPT(("Pa_sgiQueryDevice() did not confirm max samplerate (%ld)\n",max)); + return paHostError; /* Or make it a warning and just carry on... */ + } + /*-------------------------------------------------------------------------------*/ + return paNoError; +} + + +/*--------------------------------------------------------------------------------*/ +int Pa_CountDevices() /* Name of this function suggests it only counts and */ +{ /* is NOT destructive, it however resets whole PA ! */ + int numDevices = 0; /* Let 's not do that here. */ + internalPortAudioDevice* currentDevice = sDeviceList; /* COPY GLOBAL VAR. */ +#if 0 /* Remains from linux_oss v15: Pa_Initialize(), on */ + if (!currentDevice) /* its turn, calls PaHost_Init() via file pa_lib.c. */ + Pa_Initialize(); /* Isn't that a bit too 'rude'? Don't be too */ +#endif /* friendly to clients that forgot to initialize PA. */ + while (currentDevice) /* Slower but more elegant than the sNumDevices-way: */ + { + numDevices++; + currentDevice = currentDevice->pad_Next; + } + return numDevices; +} + +/*-------------------------------------------------------------------------------*/ +static internalPortAudioDevice *Pa_GetInternalDevice(PaDeviceID id) +{ + int numDevices = 0; + internalPortAudioDevice *res = (internalPortAudioDevice*)NULL; + internalPortAudioDevice *pad = sDeviceList; /* COPY GLOBAL VAR. */ + while (pad) /* pad may be NULL, that's ok, return 0. */ + { /* (Added ->pad_DeviceID field to the pad-struct, Pieter, 2001.) */ + if (pad->pad_DeviceID == id) /* This the device we were looking for? */ + res = pad; /* But keep on(!) counting so we don't */ + numDevices++; /* have to call Pa_CountDevices() later. */ + pad = pad->pad_Next; /* Advance to the next device or NULL. */ + } /* No assumptions about order of ID's in */ + if (!res) /* the list. */ + ERR_RPT(("Pa_GetInternalDevice() could not find specified ID (%d).\n",id)); + if ((id < 0) || (id >= numDevices)) + { + ERR_RPT(("Pa_GetInternalDevice() supplied with an illegal ID (%d).\n",id)); +#if 1 /* Be strict, even when found, */ + res = (internalPortAudioDevice*)NULL; /* do not accept illegal ID's. */ +#endif + } + return res; +} + +/*----------------------------------------------------------------------*/ +const PaDeviceInfo* Pa_GetDeviceInfo(PaDeviceID id) +{ + PaDeviceInfo* res = (PaDeviceInfo*)NULL; + internalPortAudioDevice* pad = Pa_GetInternalDevice(id); /* Call. */ + if (pad) + res = &pad->pad_Info; /* Not finding the specified ID is not */ + if (!res) /* the same as &pad->pad_Info == NULL. */ + ERR_RPT(("Pa_GetDeviceInfo() could not find it (ID=%d).\n", id)); + return res; /* So (maybe) a second/third ERR_RPT(). */ +} + +/*------------------------------------------------*/ +PaDeviceID Pa_GetDefaultInputDeviceID(void) +{ + return 0; /* 0 is the default device ID. */ +} +/*------------------------------------------------*/ +PaDeviceID Pa_GetDefaultOutputDeviceID(void) +{ + return 0; +} + +/*-------------------------------------------------------------------------------------------------*/ +/* Build linked a list with all the available audio devices on this SGI machine (only 1 for now). */ +PaError PaHost_Init(void) /* Called by Pa_Initialize() from pa_lib.c. */ +{ + internalPortAudioDevice* pad; + PaError r = paNoError; + int audioLibFileID; /* To test for the presence of audio. */ + + if (sDeviceList) /* Allow re-init, only warn, no error. */ + { + ERR_RPT(("Warning: PaHost_Init() did not really re-init PA.\n")); + return r; + } + /*------------- ADD THE SGI DEFAULT DEVICE TO THE LIST: ---------------------------------------*/ + audioLibFileID = open("/dev/hdsp/hdsp0master", O_RDONLY); /* Try to open Indigo style audio */ + if (audioLibFileID < 0) /* IO port. On failure, machine */ + { /* has no audio ability. */ + ERR_RPT(("PaHost_Init(): This machine has no (Indigo-style) audio abilities.\n")); + return paHostError; + } + close(audioLibFileID); /* Allocate fast mem to hold device info. */ + pad = PaHost_AllocateFastMemory(sizeof(internalPortAudioDevice)); + if (pad == NULL) + return paInsufficientMemory; + memset(pad, 0, sizeof(internalPortAudioDevice)); /* "pad->pad_Next = NULL" is more elegant. */ + r = Pa_sgiQueryDevice(AL_DEFAULT_DEVICE, /* Set AL device num (AL_DEFAULT_DEVICE). */ + Pa_GetDefaultOutputDeviceID(),/* Set PA device num (or InputDeviceID()). */ + "AL default", /* A suitable name. */ + pad); /* Write args and queried info into pad. */ + if (r != paNoError) + { + ERR_RPT(("Pa_QueryDevice for '%s' returned: %d\n", pad->pad_DeviceName, r)); + PaHost_FreeFastMemory(pad, sizeof(internalPortAudioDevice)); /* sDeviceList still NULL ! */ + } + else + sDeviceList = pad; /* First element in linked list. pad->pad_Next already NULL. */ + /*------------- QUERY AND ADD MORE POSSIBLE SGI DEVICES TO THE LINKED LIST: -------------------*/ + /*---------------------------------------------------------------------------------------------*/ + return r; +} + +/*---------------------------------------------------------------------------------------------------*/ +static PaError Pa_SgiAudioProcess(internalPortAudioStream *past) /* Spawned by PaHost_StartEngine(). */ +{ + PaError result = paNoError; + PaHostSoundControl *pahsc; + + if (!past) + return paBadStreamPtr; + pahsc = (PaHostSoundControl*)past->past_DeviceData; + if (!pahsc) + return paInternalError; + past->past_IsActive = 1; /* Wasn't this already done by the calling parent?! */ + DBUG(("entering thread.\n")); + + while (!past->past_StopSoon) /* OR-ing StopSoon and StopNow here gives problems! */ + { + /*---------------------------------------- INPUT: ------------------------------------*/ + if (pahsc->pahsc_NativeInputBuffer) /* Then pahsc_ALportIN should also be there! */ + { + while (ALgetfilled(pahsc->pahsc_ALportIN) < pahsc->pahsc_SamplesPerInputBuffer) + { + /* Trying sginap(1); and usleep(); here... things get blocked under IRIX6.2. */ + if (past->past_StopNow) /* Don't let ALreadsamps() block */ + goto done; + } + if (ALreadsamps(pahsc->pahsc_ALportIN, (void*)pahsc->pahsc_NativeInputBuffer, + pahsc->pahsc_SamplesPerInputBuffer)) /* Number of samples instead */ + { /* of number of frames. */ + ERR_RPT(("ALreadsamps() failed.\n")); + result = paInternalError; + goto done; + } + } + /*---------------------------------------------------- USER CALLBACK ROUTINE: ----------*/ + /* DBUG(("Calling Pa_CallConvertInt16()...\n")); */ + Pa_StartUsageCalculation(past); /* Convert 16 bit native data to */ + result = Pa_CallConvertInt16(past, /* user data and call user routine. */ + pahsc->pahsc_NativeInputBuffer, pahsc->pahsc_NativeOutputBuffer); + Pa_EndUsageCalculation(past); + if (result) + { + DBUG(("Pa_CallConvertInt16() returned %d, stopping...\n", result)); + goto done; /* This is apparently NOT an error! */ + } /* Just letting the userCallBack stop us. */ + /*---------------------------------------- OUTPUT: ------------------------------------*/ + if (pahsc->pahsc_NativeOutputBuffer) /* Then pahsc_ALportOUT should also be there! */ + { + while (ALgetfillable(pahsc->pahsc_ALportOUT) < pahsc->pahsc_SamplesPerOutputBuffer) + { + /* Trying sginap(1); and usleep(); here... things get blocked under IRIX6.2. */ + if (past->past_StopNow) /* Don't let ALwritesamps() block */ + goto done; + } + if (ALwritesamps(pahsc->pahsc_ALportOUT, (void*)pahsc->pahsc_NativeOutputBuffer, + pahsc->pahsc_SamplesPerOutputBuffer)) + { + ERR_RPT(("ALwritesamps() failed.\n")); + result = paInternalError; + goto done; + } + } + /*-------------------------------------------------------------------------------------*/ + } +done: + /* pahsc->pahsc_ThreadPID = -1; Hu? doesn't help!! (added by Pieter) */ + past->past_IsActive = 0; + DBUG(("leaving thread.\n")); + return result; +} + + +/*--------------------------------------------------------------------------------------*/ +PaError PaHost_OpenStream(internalPortAudioStream *past) +{ + PaError result = paNoError; + PaHostSoundControl *pahsc; + unsigned int minNumBuffers; + internalPortAudioDevice *padIN, *padOUT; /* For looking up native AL-numbers. */ + ALconfig sgiALconfig = NULL; /* IRIX-datatype. */ + long pvbuf[8]; /* To get/set hardware configs. */ + long sr, ALqsize; + DBUG(("PaHost_OpenStream() called.\n")); /* Alloc FASTMEM and init host data. */ + if (!past) + { + ERR_RPT(("Streampointer NULL!\n")); + result = paBadStreamPtr; goto done; + } + pahsc = (PaHostSoundControl*)PaHost_AllocateFastMemory(sizeof(PaHostSoundControl)); + if (pahsc == NULL) + { + ERR_RPT(("FAST Memory allocation failed.\n")); /* Pass trough some ERR_RPT-exit- */ + result = paInsufficientMemory; goto done; /* code (nothing will be freed). */ + } + memset(pahsc, 0, sizeof(PaHostSoundControl)); +/* pahsc->pahsc_threadPID = -1; Should pahsc_threadPID be inited to */ + past->past_DeviceData = (void*)pahsc; /* -1 instead of 0 ?? */ + /*--------------------------------------------------- Allocate native buffers: --------*/ + pahsc->pahsc_SamplesPerInputBuffer = past->past_FramesPerUserBuffer * /* Needed by the */ + past->past_NumInputChannels; /* audio-thread. */ + pahsc->pahsc_BytesPerInputBuffer = pahsc->pahsc_SamplesPerInputBuffer * sizeof(short); + if (past->past_NumInputChannels > 0) /* Assumes short = 16 bits! */ + { + pahsc->pahsc_NativeInputBuffer = (short*)PaHost_AllocateFastMemory(pahsc->pahsc_BytesPerInputBuffer); + if( pahsc->pahsc_NativeInputBuffer == NULL ) + { + ERR_RPT(("Fast memory allocation for input-buffer failed.\n")); + result = paInsufficientMemory; goto done; + } + } + pahsc->pahsc_SamplesPerOutputBuffer = past->past_FramesPerUserBuffer * /* Needed by the */ + past->past_NumOutputChannels; /* audio-thread. */ + pahsc->pahsc_BytesPerOutputBuffer = pahsc->pahsc_SamplesPerOutputBuffer * sizeof(short); + if (past->past_NumOutputChannels > 0) /* Assumes short = 16 bits! */ + { + pahsc->pahsc_NativeOutputBuffer = (short*)PaHost_AllocateFastMemory(pahsc->pahsc_BytesPerOutputBuffer); + if (pahsc->pahsc_NativeOutputBuffer == NULL) + { + ERR_RPT(("Fast memory allocation for output-buffer failed.\n")); + result = paInsufficientMemory; goto done; + } + } + /*------------------------------------------ Manipulate hardware if necessary and allowed: --*/ + ALseterrorhandler(0); /* 0 = turn off the default error handler. */ + pvbuf[0] = AL_INPUT_RATE; + pvbuf[2] = AL_INPUT_COUNT; + pvbuf[4] = AL_OUTPUT_RATE; /* TO FIX: rates may be logically, not always in Hz! */ + pvbuf[6] = AL_OUTPUT_COUNT; + sr = (long)(past->past_SampleRate + 0.5); /* Common for input and output :-) */ + if (past->past_NumInputChannels > 0) /* We need to lookup the corre- */ + { /* sponding native AL-number(s). */ + padIN = Pa_GetInternalDevice(past->past_InputDeviceID); + if (!padIN) + { + ERR_RPT(("Pa_GetInternalDevice() for input failed.\n")); + result = paHostError; goto done; + } + if (ALgetparams(padIN->pad_ALdevice, &pvbuf[0], 4)) /* Although input and output will both be on */ + goto sgiError; /* the same AL-device, the AL-library might */ + if (pvbuf[1] != sr) /* contain more than AL_DEFAULT_DEVICE in */ + { /* Rate different from current harware-rate? the future. Therefore 2 seperate queries. */ + if (pvbuf[3] > 0) /* Means, there's other clients using AL-input-ports */ + { + ERR_RPT(("Sorry, not allowed to switch input-hardware to %ld Hz because \ +another process is currently using input at %ld kHz.\n", sr, pvbuf[1])); + result = paHostError; goto done; + } + pvbuf[1] = sr; /* Then set input-rate. */ + if (ALsetparams(padIN->pad_ALdevice, &pvbuf[0], 2)) + goto sgiError; /* WHETHER THIS SAMPLERATE WAS REALLY PRESENT IN OUR ARRAY OF RATES, */ + } /* IS NOT CHECKED, AT LEAST NOT BY ME, WITHIN THIS FILE! Does PA do? */ + } + if (past->past_NumOutputChannels > 0) /* CARE: padOUT/IN may NOT be NULL if Channels <= 0! */ + { /* We use padOUT/IN later on, or at least 1 of both. */ + padOUT = Pa_GetInternalDevice(past->past_OutputDeviceID); + if (!padOUT) + { + ERR_RPT(("Pa_GetInternalDevice() for output failed.\n")); + result = paHostError; goto done; + } + if (ALgetparams(padOUT->pad_ALdevice,&pvbuf[4], 4)) + goto sgiError; + if ((past->past_NumOutputChannels > 0) && (pvbuf[5] != sr)) + { /* Output needed and rate different from current harware-rate. */ + if (pvbuf[7] > 0) /* Means, there's other clients using AL-output-ports */ + { + ERR_RPT(("Sorry, not allowed to switch output-hardware to %ld Hz because \ +another process is currently using output at %ld kHz.\n", sr, pvbuf[5])); + result = paHostError; goto done; /* Will free again the inputbuffer */ + } /* that was just created above. */ + pvbuf[5] = sr; /* Then set output-rate. */ + if (ALsetparams(padOUT->pad_ALdevice, &pvbuf[4], 2)) + goto sgiError; + } + } + /*------------------------------------------ Construct an audio-port-configuration ----------*/ + sgiALconfig = ALnewconfig(); /* Change the SGI-AL-default-settings. */ + if (sgiALconfig == (ALconfig)0) /* sgiALconfig is released here after use! */ + goto sgiError; /* See that sgiALconfig is NOT released! */ + if (ALsetsampfmt(sgiALconfig, AL_SAMPFMT_TWOSCOMP)) /* Choose paInt16 as native i/o-format. */ + goto sgiError; + if (ALsetwidth (sgiALconfig, AL_SAMPLE_16)) /* Only meaningful when sample format for */ + goto sgiError; /* config is set to two's complement format. */ + /************************ Future versions might (dynamically) switch to 32-bit floats? ******* + if (ALsetsampfmt(sgiALconfig, AL_SAMPFMT_FLOAT)) (Then also call another CallConvert-func.) + goto sgiError; + if (ALsetfloatmax (sgiALconfig, 1.0)) Only meaningful when sample format for config + goto sgiError; is set to AL_SAMPFMT_FLOAT or AL_SAMPFMT_DOUBLE. */ + /*---------- ?? --------------------*/ + /* DBUG(("PaHost_OpenStream: pahsc_MinFramesPerHostBuffer = %d\n", pahsc->pahsc_MinFramesPerHostBuffer )); */ + minNumBuffers = Pa_GetMinNumBuffers(past->past_FramesPerUserBuffer, past->past_SampleRate); + past->past_NumUserBuffers = (minNumBuffers > past->past_NumUserBuffers) ? + minNumBuffers : past->past_NumUserBuffers; + /*------------------------------------------------ Set internal AL queuesize (in samples) ----*/ + if (pahsc->pahsc_SamplesPerInputBuffer >= pahsc->pahsc_SamplesPerOutputBuffer) + ALqsize = (long)pahsc->pahsc_SamplesPerInputBuffer; + else /* Take the largest of the two amounts. */ + ALqsize = (long)pahsc->pahsc_SamplesPerOutputBuffer; + ALqsize *= 4; /* 4 times as large as amount per transfer! */ + if (ALsetqueuesize(sgiALconfig, ALqsize)) /* Or should we use past_NumUserBuffers here? */ + goto sgiError; /* Using 2 times may give glitches... */ + /* Have to work on ALsetqueuesize() above. */ + + /* Do ALsetchannels() later, apart per input and/or output. */ + /*----------------------------------------------- OPEN 1 OR 2 AL-DEVICES: --------------------*/ + if (past->past_OutputDeviceID == past->past_InputDeviceID) /* Who SETS these devive-numbers? */ + { + if ((past->past_NumOutputChannels > 0) && (past->past_NumInputChannels > 0)) + { + DBUG(("PaHost_OpenStream: opening both input and output channels.\n")); + /*------------------------- open output port: ----------------------------------*/ + if (ALsetchannels (sgiALconfig, (long)(past->past_NumOutputChannels))) + goto sgiError; /* Returns 0 on success, -1 on failure. */ + pahsc->pahsc_ALportOUT = ALopenport("PA sgi out", "w", sgiALconfig); + if (pahsc->pahsc_ALportOUT == (ALport)0) + goto sgiError; + /*------------------------- open input port: -----------------------------------*/ + if (ALsetchannels (sgiALconfig, (long)(past->past_NumInputChannels))) + goto sgiError; /* Returns 0 on success, -1 on failure. */ + pahsc->pahsc_ALportIN = ALopenport("PA sgi in", "r", sgiALconfig); + if (pahsc->pahsc_ALportIN == (ALport)0) + goto sgiError; /* For some reason the "patest_wire.c"-test crashes! */ + } /* Probably due to too small buffersizes?.... */ + else + { + ERR_RPT(("Cannot setup bidirectional stream between different devices.\n")); + result = paHostError; + goto done; + } + } + else /* (OutputDeviceID != InputDeviceID) */ + { + if (past->past_NumOutputChannels > 0) /* WRITE-ONLY: */ + { + /*------------------------- open output port: ----------------------------------*/ + DBUG(("PaHost_OpenStream: opening %d output channel(s) on %s.\n", + past->past_NumOutputChannels, padOUT->pad_DeviceName)); + if (ALsetchannels (sgiALconfig, (long)(past->past_NumOutputChannels))) + goto sgiError; /* Returns 0 on success, -1 on failure. */ + pahsc->pahsc_ALportOUT = ALopenport("PA sgi out", "w", sgiALconfig); + if (pahsc->pahsc_ALportOUT == (ALport)0) + goto sgiError; + } + if (past->past_NumInputChannels > 0) /* READ-ONLY: */ + { + /*------------------------- open input port: -----------------------------------*/ + DBUG(("PaHost_OpenStream: opening %d input channel(s) on %s.\n", + past->past_NumInputChannels, padIN->pad_DeviceName)); + if (ALsetchannels (sgiALconfig, (long)(past->past_NumInputChannels))) + goto sgiError; /* Returns 0 on success, -1 on failure. */ + pahsc->pahsc_ALportIN = ALopenport("PA sgi in", "r", sgiALconfig); + if (pahsc->pahsc_ALportIN == (ALport)0) + goto sgiError; + } + } + DBUG(("PaHost_OpenStream() succeeded.\n")); + goto done; /* (no errors occured) */ +sgiError: + result = translateSGIerror(); /* Translates SGI AL-code to PA-code and ERR_RPTs string. */ +done: + if (sgiALconfig) + ALfreeconfig(sgiALconfig); /* We don't need that struct anymore. */ + if (result != paNoError) + PaHost_CloseStream(past); /* Frees memory (only if really allocated!). */ + return result; +} + +/*-----------------------------------------------------*/ +PaError PaHost_StartOutput(internalPortAudioStream *past) +{ + return paNoError; /* Hmm, not implemented yet? */ +} +PaError PaHost_StartInput(internalPortAudioStream *past) +{ + return paNoError; +} + +/*------------------------------------------------------------------------------*/ +PaError PaHost_StartEngine(internalPortAudioStream *past) +{ + PaHostSoundControl *pahsc; + int hres; + PaError result = paNoError; + + if (!past) /* Test argument. */ + { + ERR_RPT(("PaHost_StartEngine(NULL)!\n")); + return paBadStreamPtr; + } + pahsc = (PaHostSoundControl*)past->past_DeviceData; + if (!pahsc) + { + ERR_RPT(("PaHost_StartEngine(arg): arg->past_DeviceData == NULL!\n")); + return paHostError; + } + past->past_StopSoon = 0; /* Assume SGI ALport is already opened! */ + past->past_StopNow = 0; + past->past_IsActive = 1; + DBUG(("PaHost_StartEngine() called.\n")); + /* Use pthread_create() instead of __clone() because: */ + /* - pthread_create also works for other UNIX systems like Solaris, */ + /* - Java HotSpot VM crashes in pthread_setcanceltype() when using __clone(). */ + hres = pthread_create(&(pahsc->pahsc_ThreadPID), /* SPAWN AUDIO-CHILD. */ + NULL, /* pthread_attr_t * attr */ + (void*)Pa_SgiAudioProcess, + past); + if (hres) + { + result = paHostError; + sPaHostError = hres; + ERR_RPT(("PaHost_StartEngine() failed to spawn audio-thread.\n")); + } + return result; +} + +/*------------------------------------------------------------------------------*/ +PaError PaHost_StopEngine(internalPortAudioStream *past, int abort) +{ + int hres; + PaError result = paNoError; + PaHostSoundControl *pahsc; + + DBUG(("PaHost_StopEngine() called.\n")); + if (!past) + return paBadStreamPtr; + pahsc = (PaHostSoundControl*)past->past_DeviceData; + if (pahsc == NULL) + return result; /* paNoError (already stopped, no err?). */ + past->past_StopSoon = 1; /* Tell background thread to stop generating */ + if (abort) /* more and to let current data play out. If */ + past->past_StopNow = 1; /* aborting, tell backgrnd thread to stop NOW! */ + if (pahsc->pahsc_ThreadPID != -1) /* Join thread to recover memory resources. */ + { + DBUG(("pthread_join() called.\n")); + hres = pthread_join(pahsc->pahsc_ThreadPID, NULL); + if (hres) + { + result = paHostError; + sPaHostError = hres; + ERR_RPT(("PaHost_StopEngine() failed pthread_join().\n")); + } + pahsc->pahsc_ThreadPID = -1; + } + past->past_IsActive = 0; + return result; +} + +/*---------------------------------------------------------------*/ +PaError PaHost_StopOutput(internalPortAudioStream *past, int abort) +{ + return paNoError; /* Not implemented yet? */ +} +PaError PaHost_StopInput(internalPortAudioStream *past, int abort ) +{ + return paNoError; +} + +/*******************************************************************/ +PaError PaHost_CloseStream(internalPortAudioStream *past) +{ + PaHostSoundControl *pahsc; + PaError result = paNoError; + + DBUG(("PaHost_CloseStream() called.\n")); + if (past == NULL) + return paBadStreamPtr; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + if (pahsc == NULL) /* If pahsc not NULL, past_DeviceData will be freed, and set to NULL. */ + return result; /* This test prevents from freeing NULL-pointers. */ + + if (pahsc->pahsc_ALportIN) + { + if (ALcloseport(pahsc->pahsc_ALportIN)) + result = translateSGIerror(); /* Translates SGI AL-code to PA-code and ERR_RPTs string. */ + else /* But go on anyway... to release other stuff... */ + pahsc->pahsc_ALportIN = (ALport)0; + } + if (pahsc->pahsc_ALportOUT) + { + if (ALcloseport(pahsc->pahsc_ALportOUT)) + result = translateSGIerror(); + else + pahsc->pahsc_ALportOUT = (ALport)0; + } + if (pahsc->pahsc_NativeInputBuffer) + { + PaHost_FreeFastMemory(pahsc->pahsc_NativeInputBuffer, pahsc->pahsc_BytesPerInputBuffer); + pahsc->pahsc_NativeInputBuffer = NULL; + } + if (pahsc->pahsc_NativeOutputBuffer) + { + PaHost_FreeFastMemory(pahsc->pahsc_NativeOutputBuffer, pahsc->pahsc_BytesPerOutputBuffer); + pahsc->pahsc_NativeOutputBuffer = NULL; + } + PaHost_FreeFastMemory(pahsc, sizeof(PaHostSoundControl)); + past->past_DeviceData = NULL; /* PaHost_OpenStream() allocated FAST. */ + return result; +} + +/************************************************************************* +** Determine minimum number of buffers required for this host based +** on minimum latency. Latency can be optionally set by user by setting +** an environment variable. For example, to set latency to 200 msec, put: +** set PA_MIN_LATENCY_MSEC=200 +** in the AUTOEXEC.BAT file and reboot. +** If the environment variable is not set, then the latency will be +** determined based on the OS. Windows NT has higher latency than Win95. +*/ +#define PA_LATENCY_ENV_NAME ("PA_MIN_LATENCY_MSEC") + +int Pa_GetMinNumBuffers( int framesPerBuffer, double sampleRate ) +{ + return 2; +} +/* Hmmm, the note above isn't appropriate for SGI I'm afraid... */ +/* Do we HAVE to do it this way under IRIX???.... */ +/*--------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------*/ +PaError PaHost_Term(void) /* Frees all of the linked audio-devices. */ +{ /* Called by Pa_Terminate() from pa_lib.c. */ + internalPortAudioDevice *pad = sDeviceList, + *nxt; + while (pad) + { + DBUG(("PaHost_Term: freeing %s\n", pad->pad_DeviceName)); + nxt = pad->pad_Next; + PaHost_FreeFastMemory(pad, sizeof(internalPortAudioDevice)); + pad = nxt; /* PaHost_Init allocated this FAST MEM.*/ + } + sDeviceList = (internalPortAudioDevice*)NULL; + return 0; /* Got rid of sNumDevices=0; */ +} + +/***********************************************************************/ +void Pa_Sleep( long msec ) /* Sleep requested number of milliseconds. */ +{ +#if 0 + struct timeval timeout; + timeout.tv_sec = msec / 1000; + timeout.tv_usec = (msec % 1000) * 1000; + select(0, NULL, NULL, NULL, &timeout); +#else + long usecs = msec * 1000; + usleep( usecs ); +#endif +} + +/*---------------------------------------------------------------------------------------*/ +/* Allocate memory that can be accessed in real-time. This may need to be held in physi- */ +/* cal memory so that it is not paged to virtual memory. This call MUST be balanced with */ +/* a call to PaHost_FreeFastMemory(). */ +void *PaHost_AllocateFastMemory(long numBytes) +{ + void *addr = malloc(numBytes); + if (addr) + memset(addr, 0, numBytes); + return addr; +} + +/*---------------------------------------------------------------------------------------*/ +/* Free memory that could be accessed in real-time. This call MUST be balanced with a */ +/* call to PaHost_AllocateFastMemory(). */ +void PaHost_FreeFastMemory(void *addr, long numBytes) +{ + if (addr) + free(addr); +} + +/*----------------------------------------------------------*/ +PaError PaHost_StreamActive (internalPortAudioStream *past) +{ + PaHostSoundControl *pahsc; + if (past == NULL) + return paBadStreamPtr; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + if (pahsc == NULL) + return paInternalError; + return (PaError)(past->past_IsActive != 0); +} + +/*-------------------------------------------------------------------*/ +PaTimestamp Pa_StreamTime( PortAudioStream *stream ) +{ + internalPortAudioStream *past = (internalPortAudioStream *) stream; +/* FIXME - return actual frames played, not frames generated. +** Need to query the output device somehow. +*/ + return past->past_FrameCount; +} diff --git a/pd/portaudio_v18/pa_tests/debug_convert.c b/pd/portaudio_v18/pa_tests/debug_convert.c new file mode 100644 index 00000000..11d25d9a --- /dev/null +++ b/pd/portaudio_v18/pa_tests/debug_convert.c @@ -0,0 +1,131 @@ +/* + * $Id: debug_convert.c,v 1.1 2002/03/21 00:44:35 philburk Exp $ + * Convert tagged values. + * + * Author: Phil Burk <philburk@softsynth.com> + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +#define OUTPUT_DEVICE (Pa_GetDefaultOutputDeviceID()) +//#define OUTPUT_DEVICE (11) +#define NUM_SECONDS (8) +#define SLEEP_DUR (800) +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (256) + +#define NUM_BUFFERS (0) + +typedef struct +{ + unsigned int framesToGo; +} +paTestData; +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + short *out = (short*)outputBuffer; + int i; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + if( data->framesToGo < framesPerBuffer ) finished = 1; + + for( i=0; i<framesPerBuffer; i++ ) + { + *out++ = 0x0000 + i; /* left */ + *out++ = 0x1000 + i; /* right */ + } + return finished; +} +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int i; + int totalSamps; + printf("PortAudio Test: output debug values\n" ); + data.framesToGo = totalSamps = NUM_SECONDS * SAMPLE_RATE; /* Play for a few seconds. */ + printf("totalSamps = %d\n", totalSamps ); + err = Pa_Initialize(); + if( err != paNoError ) goto error; + printf("PortAudio Test: output device = %d\n", OUTPUT_DEVICE ); + + err = Pa_OpenStream( + &stream, + paNoDevice, + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + OUTPUT_DEVICE, + 2, /* stereo output */ + paInt16, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, + NUM_BUFFERS, /* number of buffers, if zero then use default minimum */ + paClipOff|paDitherOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + printf("Is callback being called?\n"); + for( i=0; i<((NUM_SECONDS+1)*1000); i+=SLEEP_DUR ) + { + printf("data.framesToGo = %d\n", data.framesToGo ); fflush(stdout); + Pa_Sleep( SLEEP_DUR ); + } + /* Stop sound until ENTER hit. */ + printf("Call Pa_StopStream()\n"); + err = Pa_StopStream( stream ); + if( err != paNoError ) goto error; + Pa_Terminate(); + printf("Test finished.\n"); + return err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/debug_dither_calc.c b/pd/portaudio_v18/pa_tests/debug_dither_calc.c new file mode 100644 index 00000000..793c3990 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/debug_dither_calc.c @@ -0,0 +1,55 @@ +/* + * $Id: debug_dither_calc.c,v 1.1 2002/03/21 00:44:35 philburk Exp $ + * Test Dither calculations. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +#include "pa_host.h" + +/*******************************************************************/ +int main(void); +int main(void) +{ + long max,min; + int i; + + for( i=0; i<10000; i++ ) + { + long dither = PaConvert_TriangularDither(); + // printf("dither = 0x%08X\n", dither ); + if( dither < min ) min = dither; + else if( dither > max ) max = dither; + } + printf("min = 0x%08X = %d, max = 0x%08X = %d\n", min, min, max, max ); +} diff --git a/pd/portaudio_v18/pa_tests/debug_dual.c b/pd/portaudio_v18/pa_tests/debug_dual.c new file mode 100644 index 00000000..bdb3c413 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/debug_dual.c @@ -0,0 +1,183 @@ +/* + * $Id: debug_dual.c,v 1.1.1.1 2002/01/22 00:52:27 phil Exp $ + * debug_dual.c + * Try to open TWO streams on separate cards. + * Play a sine sweep using the Portable Audio api for several seconds. + * Hacked test for debugging PA. + * + * Author: Phil Burk <philburk@softsynth.com> + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +#define DEV_ID_1 (13) +#define DEV_ID_2 (15) +#define NUM_SECONDS (8) +#define SLEEP_DUR (800) +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (256) +#if 0 +#define MIN_LATENCY_MSEC (200) +#define NUM_BUFFERS ((MIN_LATENCY_MSEC * SAMPLE_RATE) / (FRAMES_PER_BUFFER * 1000)) +#else +#define NUM_BUFFERS (0) +#endif +#define MIN_FREQ (100.0f) +#define MAX_FREQ (4000.0f) +#define FREQ_SCALAR (1.00002f) +#define CalcPhaseIncrement(freq) (freq/SAMPLE_RATE) +#ifndef M_PI +#define M_PI (3.14159265) +#endif +#define TABLE_SIZE (400) +typedef struct +{ + float sine[TABLE_SIZE + 1]; // add one for guard point for interpolation + float phase_increment; + float left_phase; + float right_phase; +} +paTestData; +/* Convert phase between and 1.0 to sine value + * using linear interpolation. + */ +float LookupSine( paTestData *data, float phase ); +float LookupSine( paTestData *data, float phase ) +{ + float fIndex = phase*TABLE_SIZE; + int index = (int) fIndex; + float fract = fIndex - index; + float lo = data->sine[index]; + float hi = data->sine[index+1]; + float val = lo + fract*(hi-lo); + return val; +} +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + unsigned long i; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + + for( i=0; i<framesPerBuffer; i++ ) + { + *out++ = LookupSine(data, data->left_phase); /* left */ + *out++ = LookupSine(data, data->right_phase); /* right */ + data->left_phase += data->phase_increment; + if( data->left_phase >= 1.0f ) data->left_phase -= 1.0f; + data->right_phase += (data->phase_increment * 1.5f); /* fifth above */ + if( data->right_phase >= 1.0f ) data->right_phase -= 1.0f; + /* sweep frequency then start over. */ + data->phase_increment *= FREQ_SCALAR; + if( data->phase_increment > CalcPhaseIncrement(MAX_FREQ) ) data->phase_increment = CalcPhaseIncrement(MIN_FREQ); + } + return 0; +} + +PaError TestStart( PortAudioStream **streamPtr, PaDeviceID devID, + paTestData *data ); +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream1, *stream2; + PaError err; + paTestData DATA1, DATA2; + printf("PortAudio Test: DUAL sine sweep. ask for %d buffers\n", NUM_BUFFERS ); + err = Pa_Initialize(); + if( err != paNoError ) goto error; + err = TestStart( &stream1, DEV_ID_1, &DATA1 ); + if( err != paNoError ) goto error; + err = TestStart( &stream2, DEV_ID_2, &DATA2 ); + if( err != paNoError ) goto error; + printf("Hit ENTER\n"); + getchar(); + err = Pa_StopStream( stream1 ); + if( err != paNoError ) goto error; + err = Pa_StopStream( stream2 ); + if( err != paNoError ) goto error; + Pa_Terminate(); + printf("Test finished.\n"); + return err; +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 err; +} +PaError TestStart( PortAudioStream **streamPtr, PaDeviceID devID, paTestData *data ) +{ + PortAudioStream *stream; + PaError err; + int i; + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + data->sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. ); + } + data->sine[TABLE_SIZE] = data->sine[0]; // set guard point + data->left_phase = data->right_phase = 0.0; + data->phase_increment = CalcPhaseIncrement(MIN_FREQ); + printf("PortAudio Test: output device = %d\n", devID ); + err = Pa_OpenStream( + &stream, + paNoDevice, + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + devID, + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, + NUM_BUFFERS, /* number of buffers, if zero then use default minimum */ + paClipOff|paDitherOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + data ); + if( err != paNoError ) goto error; + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + *streamPtr = stream; + return 0; +error: + return err; +} diff --git a/pd/portaudio_v18/pa_tests/debug_multi_in.c b/pd/portaudio_v18/pa_tests/debug_multi_in.c new file mode 100644 index 00000000..9e376ce1 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/debug_multi_in.c @@ -0,0 +1,187 @@ +/* + * $Id: debug_multi_in.c,v 1.1.1.1.4.3 2003/04/16 19:07:56 philburk Exp $ + * debug_multi_in.c + * Pass output from each of multiple channels + * to a stereo output using the Portable Audio api. + * Hacked test for debugging PA. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include <string.h> +#include "portaudio.h" +//#define INPUT_DEVICE_NAME ("EWS88 MT Interleaved Rec") +#define OUTPUT_DEVICE (Pa_GetDefaultOutputDeviceID()) +//#define OUTPUT_DEVICE (18) +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (256) +#define MIN_LATENCY_MSEC (400) +#define MAX_INPUT_CHANNELS (9999) +#define NUM_BUFFERS ((MIN_LATENCY_MSEC * SAMPLE_RATE) / (FRAMES_PER_BUFFER * 1000)) +#ifndef M_PI +#define M_PI (3.14159265) +#endif +typedef struct +{ + int liveChannel; + int numChannels; +} +paTestData; +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + float *in = (float*)inputBuffer; + int i; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + if( in == NULL ) return 0; + for( i=0; i<(int)framesPerBuffer; i++ ) + { + /* Copy one channel of input to stereo output. */ + *out++ = in[data->liveChannel]; + *out++ = in[data->liveChannel]; + in += data->numChannels; + } + return 0; +} +/*******************************************************************/ +int PaFindDeviceByName( const char *name ) +{ + int i; + int numDevices; + const PaDeviceInfo *pdi; + int len = strlen( name ); + PaDeviceID result = paNoDevice; + numDevices = Pa_CountDevices(); + for( i=0; i<numDevices; i++ ) + { + pdi = Pa_GetDeviceInfo( i ); + if( strncmp( name, pdi->name, len ) == 0 ) + { + result = i; + break; + } + } + return result; +} +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int i; + PaDeviceID inputDevice; + const PaDeviceInfo *pdi; + printf("PortAudio Test: input signal from each channel. %d buffers\n", NUM_BUFFERS ); + data.liveChannel = 0; + err = Pa_Initialize(); + if( err != paNoError ) goto error; +#ifdef INPUT_DEVICE_NAME + printf("Try to use device: %s\n", INPUT_DEVICE_NAME ); + inputDevice = PaFindDeviceByName(INPUT_DEVICE_NAME); + if( inputDevice == paNoDevice ) + { + printf("Could not find %s. Using default instead.\n", INPUT_DEVICE_NAME ); + inputDevice = Pa_GetDefaultInputDeviceID(); + } +#else + printf("Using default input device.\n"); + inputDevice = Pa_GetDefaultInputDeviceID(); +#endif + pdi = Pa_GetDeviceInfo( inputDevice ); + if( pdi == NULL ) + { + printf("Could not get device info!\n"); + goto error; + } + printf("Input Device name is %s\n", pdi->name ); + printf("Input Device has %d channels.\n", pdi->maxInputChannels); + if( pdi->maxInputChannels <= MAX_INPUT_CHANNELS ) + { + data.numChannels = pdi->maxInputChannels; + } + else + { + data.numChannels = MAX_INPUT_CHANNELS; + printf("Only use %d channels.\n", MAX_INPUT_CHANNELS ); + } + err = Pa_OpenStream( + &stream, + inputDevice, + data.numChannels, + paFloat32, /* 32 bit floating point input */ + NULL, + OUTPUT_DEVICE, + 2, + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + NUM_BUFFERS, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + data.liveChannel = 0; + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + for( i=0; i<data.numChannels; i++ ) + { + data.liveChannel = i; + printf("Channel %d being sent to output. Hit ENTER for next channel.", i ); + fflush(stdout); + getchar(); + } + err = Pa_StopStream( stream ); + if( err != paNoError ) goto error; + + err = Pa_CloseStream( stream ); + Pa_Terminate(); + printf("Test finished.\n"); + return err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/debug_multi_out.c b/pd/portaudio_v18/pa_tests/debug_multi_out.c new file mode 100644 index 00000000..7568d1d5 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/debug_multi_out.c @@ -0,0 +1,139 @@ +/* + * $Id: debug_multi_out.c,v 1.3.4.1 2003/04/07 20:00:57 philburk Exp $ + * debug_multi_out.c + * Output different numbers on each channels for step debugging, + * using the Portable Audio api. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" + +#define OUTPUT_DEVICE (Pa_GetDefaultOutputDeviceID()) +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (256) +#define FREQ_INCR (300.0 / SAMPLE_RATE) +#define MAX_CHANNELS (64) + +#ifndef M_PI +#define M_PI (3.14159265) +#endif + +typedef struct +{ + int numChannels; +} +paTestData; + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + int frameIndex, channelIndex; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + for( frameIndex=0; frameIndex<(int)framesPerBuffer; frameIndex++ ) + { + for( channelIndex=0; channelIndex<data->numChannels; channelIndex++ ) + { + /* Output sine wave on every channel. */ + *out++ = (float) ((channelIndex + 1) * 0.1); + } + } + + return 0; +} +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + const PaDeviceInfo *pdi; + paTestData data = {0}; + printf("PortAudio Test: output channel number on each channel.\n" ); + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + + pdi = Pa_GetDeviceInfo( OUTPUT_DEVICE ); + data.numChannels = pdi->maxOutputChannels; + if( data.numChannels > MAX_CHANNELS ) data.numChannels = MAX_CHANNELS; + printf("Number of Channels = %d\n", data.numChannels ); + + err = Pa_OpenStream( + &stream, + paNoDevice, /* default input device */ + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + OUTPUT_DEVICE, + data.numChannels, + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + + printf("Hit ENTER to stop sound.\n"); + fflush(stdout); + getchar(); + + err = Pa_StopStream( stream ); + if( err != paNoError ) goto error; + + Pa_CloseStream( stream ); + Pa_Terminate(); + printf("Test finished.\n"); + return err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/debug_record.c b/pd/portaudio_v18/pa_tests/debug_record.c new file mode 100644 index 00000000..f9359254 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/debug_record.c @@ -0,0 +1,338 @@ +/* + * $Id: debug_record.c,v 1.3.4.3 2003/03/06 06:09:20 philburk Exp $ + * patest_record.c + * Record input into an array. + * Save array to a file. + * Playback recorded data. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <stdlib.h> +#include "portaudio.h" + +#define SAMPLE_RATE (44100) +#define NUM_SECONDS (6) +#define NUM_CHANNELS (2) +#define FRAMES_PER_BUFFER (64) +/* #define DITHER_FLAG (paDitherOff) */ +#define DITHER_FLAG (0) + +/* Select sample format. */ +#if 1 +#define PA_SAMPLE_TYPE paFloat32 +typedef float SAMPLE; +#define SAMPLE_SILENCE (0.0f) + +#elif 0 +#define PA_SAMPLE_TYPE paInt32 +typedef long SAMPLE; +#define SAMPLE_SILENCE (0) + +#elif 0 +#define PA_SAMPLE_TYPE paInt16 +typedef short SAMPLE; +#define SAMPLE_SILENCE (0) + +#elif 0 +#define PA_SAMPLE_TYPE paInt8 +typedef char SAMPLE; +#define SAMPLE_SILENCE (0) + +#else +#define PA_SAMPLE_TYPE paUInt8 +typedef unsigned char SAMPLE; +#define SAMPLE_SILENCE (128) + +#endif + +typedef struct +{ + int frameIndex; /* Index into sample array. */ + int maxFrameIndex; + SAMPLE *recordedSamples; +} +paTestData; +/* This routine will be called by the PortAudio engine when audio is needed. +** It may be called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int recordCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + SAMPLE *rptr = (SAMPLE*)inputBuffer; + SAMPLE *wptr = &data->recordedSamples[data->frameIndex * NUM_CHANNELS]; + long framesToCalc; + long i; + int finished; + unsigned long framesLeft = data->maxFrameIndex - data->frameIndex; + + (void) outputBuffer; /* Prevent unused variable warnings. */ + (void) outTime; + + if( framesLeft < framesPerBuffer ) + { + framesToCalc = framesLeft; + finished = 1; + } + else + { + framesToCalc = framesPerBuffer; + finished = 0; + } + if( inputBuffer == NULL ) + { + for( i=0; i<framesToCalc; i++ ) + { + *wptr++ = SAMPLE_SILENCE; /* left */ + if( NUM_CHANNELS == 2 ) *wptr++ = SAMPLE_SILENCE; /* right */ + } + } + else + { + for( i=0; i<framesToCalc; i++ ) + { + *wptr++ = *rptr++; /* left */ + if( NUM_CHANNELS == 2 ) *wptr++ = *rptr++; /* right */ + } + } + data->frameIndex += framesToCalc; + return finished; +} + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may be called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int playCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + SAMPLE *rptr = &data->recordedSamples[data->frameIndex * NUM_CHANNELS]; + SAMPLE *wptr = (SAMPLE*)outputBuffer; + unsigned int i; + int finished; + unsigned int framesLeft = data->maxFrameIndex - data->frameIndex; + (void) inputBuffer; /* Prevent unused variable warnings. */ + (void) outTime; + + if( framesLeft < framesPerBuffer ) + { + /* final buffer... */ + for( i=0; i<framesLeft; i++ ) + { + *wptr++ = *rptr++; /* left */ + if( NUM_CHANNELS == 2 ) *wptr++ = *rptr++; /* right */ + } + for( ; i<framesPerBuffer; i++ ) + { + *wptr++ = 0; /* left */ + if( NUM_CHANNELS == 2 ) *wptr++ = 0; /* right */ + } + data->frameIndex += framesLeft; + finished = 1; + } + else + { + for( i=0; i<framesPerBuffer; i++ ) + { + *wptr++ = *rptr++; /* left */ + if( NUM_CHANNELS == 2 ) *wptr++ = *rptr++; /* right */ + } + data->frameIndex += framesPerBuffer; + finished = 0; + } + return finished; +} + +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int i; + int totalFrames; + int numSamples; + int numBytes; + SAMPLE max, average, val; + + printf("debug_record.c, sampleRate = %d, numChannels = %d\n", + SAMPLE_RATE, NUM_CHANNELS ); + fflush(stdout); + + data.maxFrameIndex = totalFrames = NUM_SECONDS * SAMPLE_RATE; /* Record for a few seconds. */ + data.frameIndex = 0; + numSamples = totalFrames * NUM_CHANNELS; + + numBytes = numSamples * sizeof(SAMPLE); + data.recordedSamples = (SAMPLE *) malloc( numBytes ); + if( data.recordedSamples == NULL ) + { + printf("Could not allocate record array.\n"); + exit(1); + } + for( i=0; i<numSamples; i++ ) data.recordedSamples[i] = 0; + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + + /* Record some audio. -------------------------------------------- */ + err = Pa_OpenStream( + &stream, + Pa_GetDefaultInputDeviceID(), + NUM_CHANNELS, /* stereo input */ + PA_SAMPLE_TYPE, + NULL, + paNoDevice, + 0, + PA_SAMPLE_TYPE, + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + 0, //paDitherOff, /* flags */ + recordCallback, + &data ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + printf("Start recording!!\n"); fflush(stdout); + + while( Pa_StreamActive( stream ) ) + { + Pa_Sleep(1000); + printf("index = %d\n", data.frameIndex ); fflush(stdout); + } + printf("Stop recording!!\n"); fflush(stdout); + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + + /* Measure maximum peak amplitude. */ + max = 0; + average = 0; + for( i=0; i<numSamples; i++ ) + { + val = data.recordedSamples[i]; + if( val < 0 ) val = -val; /* ABS */ + if( val > max ) + { + max = val; + } + average += val; + } + + average = average / numSamples; + + if( PA_SAMPLE_TYPE == paFloat32 ) + { + printf("sample max amplitude = %f\n", (double) max ); + printf("sample average = %f\n", (double) average ); + } + else + { + printf("sample max amplitude = %d\n", (int) max ); + printf("sample average = %d\n", (int) average ); + } + + /* Write recorded data to a file. */ +#if 0 + { + FILE *fid; + fid = fopen("recorded.raw", "wb"); + if( fid == NULL ) + { + printf("Could not open file."); + } + else + { + fwrite( data.recordedSamples, NUM_CHANNELS * sizeof(SAMPLE), totalFrames, fid ); + fclose( fid ); + printf("Wrote data to 'recorded.raw'\n"); + } + } +#endif + + /* Playback recorded data. -------------------------------------------- */ + data.frameIndex = 0; + printf("Begin playback.\n"); fflush(stdout); + err = Pa_OpenStream( + &stream, + paNoDevice, + 0, /* NO input */ + PA_SAMPLE_TYPE, + NULL, + Pa_GetDefaultOutputDeviceID(), + NUM_CHANNELS, /* stereo output */ + PA_SAMPLE_TYPE, + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + playCallback, + &data ); + if( err != paNoError ) goto error; + + if( stream ) + { + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + printf("Start playback!!\n"); fflush(stdout); + + while( Pa_StreamActive( stream ) ) + { + Pa_Sleep(1000); + printf("index = %d\n", data.frameIndex ); fflush(stdout); + } + + printf("Stop playback!!\n"); fflush(stdout); + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + printf("Done.\n"); fflush(stdout); + } + free( data.recordedSamples ); + + 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 ) ); + return -1; +} diff --git a/pd/portaudio_v18/pa_tests/debug_record_reuse.c b/pd/portaudio_v18/pa_tests/debug_record_reuse.c new file mode 100644 index 00000000..e0670009 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/debug_record_reuse.c @@ -0,0 +1,351 @@ +/* + * $Id: debug_record_reuse.c,v 1.1 2002/05/02 20:16:29 philburk Exp $ + * debug_record_reuse.c + * Record input into an array. + * Save array to a file. + * Based on patest_record.c but with various ugly debug hacks thrown in. + * Loop twice and reuse same streams. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <stdlib.h> +#include <memory.h> +#include "portaudio.h" +#define SAMPLE_RATE (22050) +#define NUM_SECONDS (4) +#define SLEEP_DUR_MSEC (200) +#define FRAMES_PER_BUFFER (256) +#define NUM_REC_BUFS (0) + +#if 1 +#define PA_SAMPLE_TYPE paFloat32 +typedef float SAMPLE; +#else +#define PA_SAMPLE_TYPE paInt16 +typedef short SAMPLE; +#endif + +typedef struct +{ + long frameIndex; /* Index into sample array. */ + long maxFrameIndex; + long samplesPerFrame; + long numSamples; + PortAudioStream *outputStream; + PortAudioStream *inputStream; + SAMPLE *recordedSamples; +} +paTestData; + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may be called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int recordCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + SAMPLE *rptr = (SAMPLE*)inputBuffer; + SAMPLE *wptr = &data->recordedSamples[data->frameIndex * data->samplesPerFrame]; + long framesToCalc; + unsigned long i; + int finished; + unsigned long framesLeft = data->maxFrameIndex - data->frameIndex; + + (void) outputBuffer; /* Prevent unused variable warnings. */ + (void) outTime; + + if( framesLeft < framesPerBuffer ) + { + framesToCalc = framesLeft; + finished = 1; + } + else + { + framesToCalc = framesPerBuffer; + finished = 0; + } + if( inputBuffer == NULL ) + { + for( i=0; i<framesToCalc; i++ ) + { + *wptr++ = 0; /* left */ + *wptr++ = 0; /* right */ + } + } + else + { + for( i=0; i<framesToCalc; i++ ) + { + *wptr++ = *rptr++; /* left */ + *wptr++ = *rptr++; /* right */ + } + } + data->frameIndex += framesToCalc; + return finished; +} + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may be called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int playCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + SAMPLE *rptr = &data->recordedSamples[data->frameIndex * data->samplesPerFrame]; + SAMPLE *wptr = (SAMPLE*)outputBuffer; + unsigned long i; + int finished; + unsigned int framesLeft = data->maxFrameIndex - data->frameIndex; + if( outputBuffer == NULL ) return 0; + (void) inputBuffer; /* Prevent unused variable warnings. */ + (void) outTime; + + if( framesLeft < framesPerBuffer ) + { + /* final buffer... */ + for( i=0; i<framesLeft; i++ ) + { + *wptr++ = *rptr++; /* left */ + *wptr++ = *rptr++; /* right */ + } + for( ; i<framesPerBuffer; i++ ) + { + *wptr++ = 0; /* left */ + *wptr++ = 0; /* right */ + } + data->frameIndex += framesLeft; + finished = 1; + } + else + { + for( i=0; i<framesPerBuffer; i++ ) + { + *wptr++ = *rptr++; /* left */ + *wptr++ = *rptr++; /* right */ + } + data->frameIndex += framesPerBuffer; + finished = 0; + } + return finished; +} + +/****************************************************************/ +PaError TestRecording( paTestData *dataPtr ) +{ + PaError err; + int i; + int lastIndex = 0; + +/* Open input stream if not already open. */ + if( dataPtr->inputStream == NULL ) + { + /* Record some audio. */ + err = Pa_OpenStream( + &dataPtr->inputStream, + Pa_GetDefaultInputDeviceID(), + dataPtr->samplesPerFrame, /* stereo input */ + PA_SAMPLE_TYPE, + NULL, + paNoDevice, + 0, + PA_SAMPLE_TYPE, + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + NUM_REC_BUFS, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + recordCallback, + dataPtr ); + if( err != paNoError ) goto error; + } + + dataPtr->frameIndex = 0; + + err = Pa_StartStream( dataPtr->inputStream ); + if( err != paNoError ) goto error; + + printf("Now recording!\n"); fflush(stdout); + for( i=0; i<(NUM_SECONDS*1000/SLEEP_DUR_MSEC); i++ ) + { + int frameIndex, delta; + Pa_Sleep(SLEEP_DUR_MSEC); + + frameIndex = dataPtr->frameIndex; + if( Pa_StreamActive( dataPtr->inputStream ) <= 0) + { + printf("Stream inactive!\n"); + break; + } + if( dataPtr->maxFrameIndex <= frameIndex ) + { + printf("Buffer recording complete.\n"); + break; + } + + delta = frameIndex - lastIndex; + lastIndex = frameIndex; + printf("index = %d, delta = %d\n", frameIndex, delta ); fflush(stdout); + } + + err = Pa_StopStream( dataPtr->inputStream ); + if( err != paNoError ) goto error; + + printf("Done.\n"); fflush(stdout); + +error: + return err; +} + +/****************************************************************/ +PaError TestPlayback( paTestData *dataPtr ) +{ + PaError err; + int i; + int lastIndex = 0; + + /* Playback recorded data. */ + dataPtr->frameIndex = 0; + printf("Begin playback.\n"); fflush(stdout); + +/* Open output stream if not already open. */ + if( dataPtr->outputStream == NULL ) + { + err = Pa_OpenStream( + &dataPtr->outputStream, + paNoDevice, + 0, /* NO input */ + PA_SAMPLE_TYPE, + NULL, + Pa_GetDefaultOutputDeviceID(), + dataPtr->samplesPerFrame, /* stereo output */ + PA_SAMPLE_TYPE, + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + playCallback, + dataPtr ); + if( err != paNoError ) goto error; + } + + err = Pa_StartStream( dataPtr->outputStream ); + if( err != paNoError ) goto error; + + printf("Waiting for playback to finish.\n"); fflush(stdout); + for( i=0; i<(NUM_SECONDS*1000/SLEEP_DUR_MSEC); i++ ) + { + int frameIndex, delta; + Pa_Sleep(SLEEP_DUR_MSEC); + frameIndex = dataPtr->frameIndex; + delta = frameIndex - lastIndex; + lastIndex = frameIndex; + printf("index = %d, delta = %d\n", frameIndex, delta ); fflush(stdout); + } + + err = Pa_StopStream( dataPtr->outputStream ); + if( err != paNoError ) goto error; + +error: + return err; +} +/*******************************************************************/ +int main(void); +int main(void) +{ + PaError err; + paTestData data = { 0 }; + long totalFrames; + long numBytes; + long i; + printf("patest_record.c\n"); fflush(stdout); + +/* Set up test data structure and sample array. */ + data.frameIndex = 0; + data.samplesPerFrame = 2; + data.maxFrameIndex = totalFrames = NUM_SECONDS*SAMPLE_RATE; + + printf("totalFrames = %d\n", totalFrames ); fflush(stdout); + data.numSamples = totalFrames * data.samplesPerFrame; + + numBytes = data.numSamples * sizeof(SAMPLE); + data.recordedSamples = (SAMPLE *) malloc( numBytes ); + if( data.recordedSamples == NULL ) + { + printf("Could not allocate record array.\n"); + exit(1); + } + for( i=0; i<data.numSamples; i++ ) data.recordedSamples[i] = 0; + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + +/* Record and playback multiple times. */ + for( i=0; i<2; i++ ) + { + err = TestRecording( &data ); + if( err != paNoError ) goto error; + + err = TestPlayback( &data ); + if( err != paNoError ) goto error; + } + +/* Clean up. */ + err = Pa_CloseStream( data.inputStream ); + if( err != paNoError ) goto error; + + err = Pa_CloseStream( data.outputStream ); + if( err != paNoError ) goto error; + + if( err != paNoError ) goto error; + + free( data.recordedSamples ); + Pa_Terminate(); + + printf("Test complete.\n"); fflush(stdout); + 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 ) ); + if( err == paHostError ) + { + fprintf( stderr, "Host Error number: %d\n", Pa_GetHostError() ); + } + return -1; +} diff --git a/pd/portaudio_v18/pa_tests/debug_sine.c b/pd/portaudio_v18/pa_tests/debug_sine.c new file mode 100644 index 00000000..c6e4bbbf --- /dev/null +++ b/pd/portaudio_v18/pa_tests/debug_sine.c @@ -0,0 +1,201 @@ +/* + * $Id: debug_sine.c,v 1.2.4.2 2003/03/06 06:09:20 philburk Exp $ + * debug_sine.c + * Play a sine sweep using the Portable Audio api for several seconds. + * Hacked test for debugging PA. + * + * Author: Phil Burk <philburk@softsynth.com> + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +#define OUTPUT_DEVICE (Pa_GetDefaultOutputDeviceID()) +//#define OUTPUT_DEVICE (11) +#define NUM_SECONDS (8) +#define SLEEP_DUR (800) +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (256) + +#define MSEC_PER_BUFFER (1000 * FRAMES_PER_BUFFER / SAMPLE_RATE) + +#if 0 +#define MIN_LATENCY_MSEC (200) +#define NUM_BUFFERS ((MIN_LATENCY_MSEC * SAMPLE_RATE) / (FRAMES_PER_BUFFER * 1000)) +#else +#define NUM_BUFFERS (0) +#endif + +#define MIN_FREQ (100.0f) +#define MAX_FREQ (4000.0f) +#define FREQ_SCALAR (1.00002f) +#define CalcPhaseIncrement(freq) (freq/SAMPLE_RATE) +#ifndef M_PI +#define M_PI (3.14159265) +#endif +#define TABLE_SIZE (400) +typedef struct +{ + float sine[TABLE_SIZE + 1]; // add one for guard point for interpolation + float phase_increment; + float left_phase; + float right_phase; + unsigned int framesToGo; +} +paTestData; +/* Convert phase between and 1.0 to sine value + * using linear interpolation. + */ +float LookupSine( paTestData *data, float phase ); +float LookupSine( paTestData *data, float phase ) +{ + float fIndex = phase*TABLE_SIZE; + int index = (int) fIndex; + float fract = fIndex - index; + float lo = data->sine[index]; + float hi = data->sine[index+1]; + float val = lo + fract*(hi-lo); + return val; +} +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + int framesToCalc; + int i; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + if( data->framesToGo < framesPerBuffer ) + { + framesToCalc = data->framesToGo; + data->framesToGo = 0; + finished = 1; + } + else + { + framesToCalc = framesPerBuffer; + data->framesToGo -= framesPerBuffer; + } + + for( i=0; i<framesToCalc; i++ ) + { + *out++ = LookupSine(data, data->left_phase); /* left */ + *out++ = LookupSine(data, data->right_phase); /* right */ + data->left_phase += data->phase_increment; + if( data->left_phase >= 1.0f ) data->left_phase -= 1.0f; + data->right_phase += (data->phase_increment * 1.5f); /* fifth above */ + if( data->right_phase >= 1.0f ) data->right_phase -= 1.0f; + /* sweep frequency then start over. */ + data->phase_increment *= FREQ_SCALAR; + if( data->phase_increment > CalcPhaseIncrement(MAX_FREQ) ) data->phase_increment = CalcPhaseIncrement(MIN_FREQ); + } + /* zero remainder of final buffer */ + for( ; i<(int)framesPerBuffer; i++ ) + { + *out++ = 0; /* left */ + *out++ = 0; /* right */ + } + // Pa_Sleep( 3 * MSEC_PER_BUFFER / 4 ); + // Pa_Sleep( MSEC_PER_BUFFER / 3 ); + + return finished; +} +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int i; + int totalSamps; + printf("PortAudio Test: output sine sweep. ask for %d buffers\n", NUM_BUFFERS ); + printf("MSEC_PER_BUFFER = %d\n", MSEC_PER_BUFFER ); + + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. ); + } + data.sine[TABLE_SIZE] = data.sine[0]; // set guard point + data.left_phase = data.right_phase = 0.0; + data.phase_increment = CalcPhaseIncrement(MIN_FREQ); + data.framesToGo = totalSamps = NUM_SECONDS * SAMPLE_RATE; /* Play for a few seconds. */ + printf("totalSamps = %d\n", totalSamps ); + err = Pa_Initialize(); + if( err != paNoError ) goto error; + printf("PortAudio Test: output device = %d\n", OUTPUT_DEVICE ); + err = Pa_OpenStream( + &stream, + paNoDevice, + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + OUTPUT_DEVICE, + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, + NUM_BUFFERS, /* number of buffers, if zero then use default minimum */ + paClipOff|paDitherOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + printf("Is callback being called?\n"); + for( i=0; i<((NUM_SECONDS+1)*1000); i+=SLEEP_DUR ) + { + printf("data.framesToGo = %d\n", data.framesToGo ); fflush(stdout); + Pa_Sleep( SLEEP_DUR ); + } + /* Stop sound until ENTER hit. */ + printf("Call Pa_StopStream()\n"); + err = Pa_StopStream( stream ); + if( err != paNoError ) goto error; + Pa_Terminate(); + printf("Test finished.\n"); + return err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/debug_sine_amp.c b/pd/portaudio_v18/pa_tests/debug_sine_amp.c new file mode 100644 index 00000000..3eeca007 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/debug_sine_amp.c @@ -0,0 +1,157 @@ +/* + * $Id: debug_sine_amp.c,v 1.1 2002/03/21 00:44:35 philburk Exp $ + * Play a different sine wave on each channels, + * using the Portable Audio api. + * Allos amplitude to be set interactively. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" + +#define OUTPUT_DEVICE (Pa_GetDefaultOutputDeviceID()) +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (256) +#define FREQ_INCR (300.0 / SAMPLE_RATE) +#define MAX_CHANNELS (64) + +#ifndef M_PI +#define M_PI (3.14159265) +#endif + +typedef struct +{ + int numChannels; + double phases[MAX_CHANNELS]; + float amplitude; +} +paTestData; + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + int frameIndex, channelIndex; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + for( frameIndex=0; frameIndex<(int)framesPerBuffer; frameIndex++ ) + { + for( channelIndex=0; channelIndex<data->numChannels; channelIndex++ ) + { + /* Output sine wave on every channel. */ + *out++ = (float) ( data->amplitude * sin(data->phases[channelIndex]) ); + + /* Play each channel at a higher frequency. */ + data->phases[channelIndex] += FREQ_INCR * (4 + channelIndex); + if( data->phases[channelIndex] >= (2.0 * M_PI) ) data->phases[channelIndex] -= (2.0 * M_PI); + } + } + + return 0; +} +/*******************************************************************/ +int main(void); +int main(void) +{ + char pad[256]; + PortAudioStream *stream; + PaError err; + const PaDeviceInfo *pdi; + paTestData data = {0}; + printf("PortAudio Test: output sine wave on each channel.\n" ); + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + + pdi = Pa_GetDeviceInfo( OUTPUT_DEVICE ); + data.numChannels = pdi->maxOutputChannels; + if( data.numChannels > MAX_CHANNELS ) data.numChannels = MAX_CHANNELS; + printf("Number of Channels = %d\n", data.numChannels ); + data.amplitude = 1.0; + + err = Pa_OpenStream( + &stream, + paNoDevice, /* default input device */ + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + OUTPUT_DEVICE, + data.numChannels, + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + + do + { + printf("Current amplitude = %f\n", data.amplitude ); + printf("Enter new amplitude or 'q' to quit.\n"); + fflush(stdout); + gets( pad ); + if( pad[0] != 'q' ) + { + // I tried to use atof but it seems to be broken on Mac OS X 10.1 + float amp; + sscanf( pad, "%f", & ); + data.amplitude = amp; + } + } while( pad[0] != 'q' ); + + err = Pa_StopStream( stream ); + if( err != paNoError ) goto error; + + Pa_CloseStream( stream ); + Pa_Terminate(); + printf("Test finished.\n"); + return err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/debug_sine_formats.c b/pd/portaudio_v18/pa_tests/debug_sine_formats.c new file mode 100644 index 00000000..c331dde3 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/debug_sine_formats.c @@ -0,0 +1,202 @@ +/* + * $Id: debug_sine_formats.c,v 1.1 2002/03/21 00:44:35 philburk Exp $ + * patest_sine_formats.c + * Play a sine wave using the Portable Audio api for several seconds. + * Test various data formats. + * + * Author: Phil Burk + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.audiomulch.com/portaudio/ + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" + +#define NUM_SECONDS (10) +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (256) + +#define LEFT_FREQ (SAMPLE_RATE/512.0) /* So we hit 1.0 */ +#define RIGHT_FREQ (500.0) + +#define AMPLITUDE (1.0) + +/* Select ONE format for testing. */ +#define TEST_UINT8 (1) +#define TEST_INT8 (0) +#define TEST_INT16 (0) +#define TEST_FLOAT32 (0) + +#if TEST_UINT8 +#define TEST_FORMAT paUInt8 +typedef unsigned char SAMPLE_t; +#define SAMPLE_ZERO (0x80) +#define DOUBLE_TO_SAMPLE(x) (SAMPLE_ZERO + (SAMPLE_t)(127.0 * (x))) +#define FORMAT_NAME "Unsigned 8 Bit" + +#elif TEST_INT8 +#define TEST_FORMAT paInt8 +typedef char SAMPLE_t; +#define SAMPLE_ZERO (0) +#define DOUBLE_TO_SAMPLE(x) (SAMPLE_ZERO + (SAMPLE_t)(127.0 * (x))) +#define FORMAT_NAME "Signed 8 Bit" + +#elif TEST_INT16 +#define TEST_FORMAT paInt16 +typedef short SAMPLE_t; +#define SAMPLE_ZERO (0) +#define DOUBLE_TO_SAMPLE(x) (SAMPLE_ZERO + (SAMPLE_t)(32767 * (x))) +#define FORMAT_NAME "Signed 16 Bit" + +#elif TEST_FLOAT32 +#define TEST_FORMAT paFloat32 +typedef float SAMPLE_t; +#define SAMPLE_ZERO (0.0) +#define DOUBLE_TO_SAMPLE(x) ((SAMPLE_t)(x)) +#define FORMAT_NAME "Float 32 Bit" +#endif + +#ifndef M_PI +#define M_PI (3.14159265) +#endif + + +typedef struct +{ + double left_phase; + double right_phase; + unsigned int framesToGo; +} +paTestData; +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + SAMPLE_t *out = (SAMPLE_t *)outputBuffer; + SAMPLE_t sample; + int i; + int framesToCalc; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + if( data->framesToGo < framesPerBuffer ) + { + framesToCalc = data->framesToGo; + data->framesToGo = 0; + finished = 1; + } + else + { + framesToCalc = framesPerBuffer; + data->framesToGo -= framesPerBuffer; + } + + for( i=0; i<framesToCalc; i++ ) + { + data->left_phase += (LEFT_FREQ / SAMPLE_RATE); + if( data->left_phase > 1.0) data->left_phase -= 1.0; + sample = DOUBLE_TO_SAMPLE( AMPLITUDE * sin( (data->left_phase * M_PI * 2. ))); /**/ + *out++ = sample; +/* *out++ = sample; /**/ +/* *out++ = 0; /**/ + + data->right_phase += (RIGHT_FREQ / SAMPLE_RATE); + if( data->right_phase > 1.0) data->right_phase -= 1.0; + *out++ = DOUBLE_TO_SAMPLE( AMPLITUDE * sin( (data->right_phase * M_PI * 2. ))); /**/ +/* *out++ = 0; /* */ + } + /* zero remainder of final buffer */ + for( ; i<(int)framesPerBuffer; i++ ) + { + *out++ = SAMPLE_ZERO; /* left */ + *out++ = SAMPLE_ZERO; /* right */ + } + return finished; +} +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int totalSamps; + + printf("PortAudio Test: output " FORMAT_NAME "\n"); + + + data.left_phase = data.right_phase = 0.0; + data.framesToGo = totalSamps = NUM_SECONDS * SAMPLE_RATE; /* Play for a few seconds. */ + err = Pa_Initialize(); + if( err != paNoError ) goto error; + + err = Pa_OpenStream( + &stream, + paNoDevice,/* default input device */ + 0, /* no input */ + TEST_FORMAT, + NULL, + Pa_GetDefaultOutputDeviceID(), /* default output device */ + 2, /* stereo output */ + TEST_FORMAT, + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + + printf("Waiting %d seconds for sound to finish.\n", NUM_SECONDS ); + while( Pa_StreamActive( stream ) ) Pa_Sleep(10); + + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + Pa_Terminate(); + + printf("PortAudio Test Finished: " FORMAT_NAME "\n"); + + return err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/debug_sine_getchar.c b/pd/portaudio_v18/pa_tests/debug_sine_getchar.c new file mode 100644 index 00000000..54c0cba5 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/debug_sine_getchar.c @@ -0,0 +1,140 @@ +/* + * $Id: debug_sine_getchar.c,v 1.1.2.2 2003/04/10 23:09:40 philburk Exp $ + * + * Play a sine wave using the Portable Audio api until ENTER hit. + * + * Authors: + * Ross Bencina <rossb@audiomulch.com> + * Phil Burk <philburk@softsynth.com> + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.audiomulch.com/portaudio/ + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" + +#define SAMPLE_RATE (48000) +#define AMPLITUDE (0.3) +#define FRAMES_PER_BUFFER (64) +#define OUTPUT_DEVICE Pa_GetDefaultOutputDeviceID() +//#define OUTPUT_DEVICE (2) + +#ifndef M_PI +#define M_PI (3.14159265) +#endif + +#define TABLE_SIZE (200) +typedef struct +{ + float sine[TABLE_SIZE]; + int left_phase; + int right_phase; +} +paTestData; + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + unsigned long i; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + for( i=0; i<framesPerBuffer; i++ ) + { + *out++ = data->sine[data->left_phase]; /* left */ + *out++ = data->sine[data->right_phase]; /* right */ + data->left_phase += 1; + if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE; + data->right_phase += 3; /* higher pitch so we can distinguish left and right. */ + if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE; + } + return finished; +} + +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int i; + printf("PortAudio Test: output sine wave. SR = %d, BufSize = %d, devID = %d\n", + SAMPLE_RATE, FRAMES_PER_BUFFER, OUTPUT_DEVICE); + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + data.sine[i] = (float) (AMPLITUDE * sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. )); + } + data.left_phase = data.right_phase = 0; + err = Pa_Initialize(); + if( err != paNoError ) goto error; + err = Pa_OpenStream( + &stream, + paNoDevice,/* default input device */ + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + OUTPUT_DEVICE, + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + printf("Press ENTER to stop.\n" ); fflush(stdout); + getchar(); + + 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 err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/debug_srate.c b/pd/portaudio_v18/pa_tests/debug_srate.c new file mode 100644 index 00000000..ae42611b --- /dev/null +++ b/pd/portaudio_v18/pa_tests/debug_srate.c @@ -0,0 +1,265 @@ +/* + * $Id: debug_srate.c,v 1.1 2002/05/02 20:16:29 philburk Exp $ + * debug_record_reuse.c + * Record input into an array. + * Save array to a file. + * Based on patest_record.c but with various ugly debug hacks thrown in. + * Loop twice and reuse same streams. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <stdlib.h> +#include <memory.h> +#include "portaudio.h" + +#define EWS88MT_12_REC (1) +#define EWS88MT_12_PLAY (10) +#define SBLIVE_REC (2) +#define SBLIVE_PLAY (11) + +#if 0 +#define INPUT_DEVICE_ID Pa_GetDefaultInputDeviceID() +#define OUTPUT_DEVICE_ID Pa_GetDefaultOutputDeviceID() +#else +#define INPUT_DEVICE_ID (EWS88MT_12_REC) +#define OUTPUT_DEVICE_ID (SBLIVE_PLAY) +#endif + +#define INPUT_SAMPLE_RATE (22050.0) +#define OUTPUT_SAMPLE_RATE (22050.0) +#define NUM_SECONDS (4) +#define SLEEP_DUR_MSEC (1000) +#define FRAMES_PER_BUFFER (64) +#define NUM_REC_BUFS (0) +#define SAMPLES_PER_FRAME (2) + +#define PA_SAMPLE_TYPE paInt16 +typedef short SAMPLE; + +typedef struct +{ + long frameIndex; /* Index into sample array. */ +} +paTestData; + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may be called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int recordCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData *) userData; + (void) outputBuffer; /* Prevent unused variable warnings. */ + (void) outTime; + + if( inputBuffer != NULL ) + { + data->frameIndex += framesPerBuffer; + } + return 0; +} + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may be called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int playCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData *) userData; + (void) inputBuffer; /* Prevent unused variable warnings. */ + (void) outTime; + + if( outputBuffer != NULL ) + { + data->frameIndex += framesPerBuffer; + } + return 0; +} + +/****************************************************************/ +PaError MeasureStreamRate( PortAudioStream *stream, paTestData *dataPtr, double *ratePtr ) +{ + PaError err; + int i; + int totalFrames = 0; + int totalMSec = 0; + + dataPtr->frameIndex = 0; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + + for( i=0; i<(NUM_SECONDS*1000/SLEEP_DUR_MSEC); i++ ) + { + int delta, endIndex; + + int startIndex = dataPtr->frameIndex; + Pa_Sleep(SLEEP_DUR_MSEC); + endIndex = dataPtr->frameIndex; + + delta = endIndex - startIndex; + totalFrames += delta; + totalMSec += SLEEP_DUR_MSEC; + + printf("index = %d, delta = %d\n", endIndex, delta ); fflush(stdout); + } + + err = Pa_StopStream( stream ); + if( err != paNoError ) goto error; + + *ratePtr = (totalFrames * 1000.0) / totalMSec; + +error: + return err; +} + +void ReportRate( double measuredRate, double expectedRate ) +{ + double error; + + error = (measuredRate - expectedRate) / expectedRate; + error = (error < 0 ) ? -error : error; + + printf("Measured rate = %6.1f, expected rate = %6.1f\n", + measuredRate, expectedRate ); + if( error > 0.1 ) + { + printf("ERROR: unexpected rate! --------------------- ERROR!\n"); + } + else + { + printf("SUCCESS: rate within tolerance!\n"); + } +} + +/*******************************************************************/ +int main(void); +int main(void) +{ + PaError err; + paTestData data = { 0 }; + long i; + double rate; + const PaDeviceInfo *pdi; + + PortAudioStream *outputStream; + PortAudioStream *inputStream; + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + + + pdi = Pa_GetDeviceInfo( INPUT_DEVICE_ID ); + printf("Input device = %s\n", pdi->name ); + pdi = Pa_GetDeviceInfo( OUTPUT_DEVICE_ID ); + printf("Output device = %s\n", pdi->name ); + +/* Open input stream. */ + err = Pa_OpenStream( + &inputStream, + INPUT_DEVICE_ID, + SAMPLES_PER_FRAME, /* stereo input */ + PA_SAMPLE_TYPE, + NULL, + paNoDevice, + 0, + PA_SAMPLE_TYPE, + NULL, + INPUT_SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + NUM_REC_BUFS, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + recordCallback, + &data ); + if( err != paNoError ) goto error; + + err = Pa_OpenStream( + &outputStream, + paNoDevice, + 0, /* NO input */ + PA_SAMPLE_TYPE, + NULL, + OUTPUT_DEVICE_ID, + SAMPLES_PER_FRAME, /* stereo output */ + PA_SAMPLE_TYPE, + NULL, + OUTPUT_SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + playCallback, + &data ); + if( err != paNoError ) goto error; + +/* Record and playback multiple times. */ + for( i=0; i<2; i++ ) + { + printf("Measuring INPUT ------------------------- \n"); + err = MeasureStreamRate( inputStream, &data, &rate ); + if( err != paNoError ) goto error; + ReportRate( rate, INPUT_SAMPLE_RATE ); + + printf("Measuring OUTPUT ------------------------- \n"); + err = MeasureStreamRate( outputStream, &data, &rate ); + if( err != paNoError ) goto error; + ReportRate( rate, OUTPUT_SAMPLE_RATE ); + } + +/* Clean up. */ + err = Pa_CloseStream( inputStream ); + if( err != paNoError ) goto error; + + err = Pa_CloseStream( outputStream ); + if( err != paNoError ) goto error; + + if( err != paNoError ) goto error; + + Pa_Terminate(); + + printf("Test complete.\n"); fflush(stdout); + 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 ) ); + if( err == paHostError ) + { + fprintf( stderr, "Host Error number: %d\n", Pa_GetHostError() ); + } + return -1; +} diff --git a/pd/portaudio_v18/pa_tests/debug_test1.c b/pd/portaudio_v18/pa_tests/debug_test1.c new file mode 100644 index 00000000..187d0f5c --- /dev/null +++ b/pd/portaudio_v18/pa_tests/debug_test1.c @@ -0,0 +1,114 @@ +/* + * $Id: debug_test1.c,v 1.1.1.1 2002/01/22 00:52:30 phil Exp $ + patest1.c + Ring modulate the audio input with a 441hz sine wave for 20 seconds + using the Portable Audio api + Author: Ross Bencina <rossb@audiomulch.com> + Modifications: + April 5th, 2001 - PLB - Check for NULL inputBuffer. +*/ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +#ifndef M_PI +#define M_PI (3.14159265) +#endif +typedef struct +{ + float sine[100]; + int phase; + int sampsToGo; +} +patest1data; +static int patest1Callback( void *inputBuffer, void *outputBuffer, + unsigned long bufferFrames, + PaTimestamp outTime, void *userData ) +{ + patest1data *data = (patest1data*)userData; + float *in = (float*)inputBuffer; + float *out = (float*)outputBuffer; + int framesToCalc = bufferFrames; + unsigned long i; + int finished = 0; + if(inputBuffer == NULL) return 0; + if( data->sampsToGo < bufferFrames ) + { + finished = 1; + } + for( i=0; i<bufferFrames; i++ ) + { + *out++ = *in++; + *out++ = *in++; + if( data->phase >= 100 ) + data->phase = 0; + } + data->sampsToGo -= bufferFrames; + /* zero remainder of final buffer if not already done */ + for( ; i<bufferFrames; i++ ) + { + *out++ = 0; /* left */ + *out++ = 0; /* right */ + } + return finished; +} +int main(int argc, char* argv[]); +int main(int argc, char* argv[]) +{ + PaStream *stream; + PaError err; + patest1data data; + int i; + int inputDevice = Pa_GetDefaultInputDeviceID(); + int outputDevice = Pa_GetDefaultOutputDeviceID(); + /* initialise sinusoidal wavetable */ + for( i=0; i<100; i++ ) + data.sine[i] = sin( ((double)i/100.) * M_PI * 2. ); + data.phase = 0; + data.sampsToGo = 44100 * 4; // 20 seconds + /* initialise portaudio subsytem */ + Pa_Initialize(); + err = Pa_OpenStream( + &stream, + inputDevice, + 2, /* stereo input */ + paFloat32, /* 32 bit floating point input */ + NULL, + outputDevice, + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + NULL, + 44100., + // 22050, /* half second buffers */ + // 4, /* four buffers */ + 512, /* half second buffers */ + 0, /* four buffers */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patest1Callback, + &data ); + if( err == paNoError ) + { + err = Pa_StartStream( stream ); + // printf( "Press any key to end.\n" ); + // getc( stdin ); //wait for input before exiting + // Pa_AbortStream( stream ); + + printf( "Waiting for stream to complete...\n" ); + + while( Pa_StreamActive( stream ) ) + Pa_Sleep(1000); /* sleep until playback has finished */ + + err = Pa_CloseStream( stream ); + } + else + { + fprintf( stderr, "An error occured while opening the portaudio stream\n" ); + if( err == paHostError ) + fprintf( stderr, "Host error number: %d\n", Pa_GetHostError() ); + else + fprintf( stderr, "Error number: %d\n", err ); + } + Pa_Terminate(); + printf( "bye\n" ); + + return 0; +} diff --git a/pd/portaudio_v18/pa_tests/pa_devs.c b/pd/portaudio_v18/pa_tests/pa_devs.c new file mode 100644 index 00000000..66302395 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/pa_devs.c @@ -0,0 +1,99 @@ +/* + * $Id: pa_devs.c,v 1.1.1.1.4.1 2003/02/11 21:41:32 philburk Exp $ + * pa_devs.c + * List available devices. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" + +/*******************************************************************/ +int main(void); +int main(void) +{ + int i,j; + int numDevices; + const PaDeviceInfo *pdi; + PaError err; + Pa_Initialize(); + numDevices = Pa_CountDevices(); + if( numDevices < 0 ) + { + printf("ERROR: Pa_CountDevices returned 0x%x\n", numDevices ); + err = numDevices; + goto error; + } + printf("Number of devices = %d\n", numDevices ); + for( i=0; i<numDevices; i++ ) + { + pdi = Pa_GetDeviceInfo( i ); + printf("---------------------------------------------- #%d", i ); + if( i == Pa_GetDefaultInputDeviceID() ) printf(" DefaultInput"); + if( i == Pa_GetDefaultOutputDeviceID() ) printf(" DefaultOutput"); + printf("\nName = %s\n", pdi->name ); + printf("Max Inputs = %d", pdi->maxInputChannels ); + printf(", Max Outputs = %d\n", pdi->maxOutputChannels ); + if( pdi->numSampleRates == -1 ) + { + printf("Sample Rate Range = %f to %f\n", pdi->sampleRates[0], pdi->sampleRates[1] ); + } + else + { + printf("Sample Rates ="); + for( j=0; j<pdi->numSampleRates; j++ ) + { + printf(" %8.2f,", pdi->sampleRates[j] ); + } + printf("\n"); + } + printf("Native Sample Formats = "); + if( pdi->nativeSampleFormats & paInt8 ) printf("paInt8, "); + if( pdi->nativeSampleFormats & paUInt8 ) printf("paUInt8, "); + if( pdi->nativeSampleFormats & paInt16 ) printf("paInt16, "); + if( pdi->nativeSampleFormats & paInt32 ) printf("paInt32, "); + if( pdi->nativeSampleFormats & paFloat32 ) printf("paFloat32, "); + if( pdi->nativeSampleFormats & paInt24 ) printf("paInt24, "); + if( pdi->nativeSampleFormats & paPackedInt24 ) printf("paPackedInt24, "); + printf("\n"); + } + Pa_Terminate(); + + printf("----------------------------------------------\n"); + 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 ) ); + return err; +} diff --git a/pd/portaudio_v18/pa_tests/pa_fuzz.c b/pd/portaudio_v18/pa_tests/pa_fuzz.c new file mode 100644 index 00000000..3f0cdb56 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/pa_fuzz.c @@ -0,0 +1,156 @@ +/* + * $Id: pa_fuzz.c,v 1.1.1.1.4.1 2003/02/11 21:41:32 philburk Exp $ + * pa_fuzz.c + * Distort input like a fuzz boz. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +/* +** Note that many of the older ISA sound cards on PCs do NOT support +** full duplex audio (simultaneous record and playback). +** And some only support full duplex at lower sample rates. +*/ +#define SAMPLE_RATE (44100) +#define PA_SAMPLE_TYPE paFloat32 +#define FRAMES_PER_BUFFER (64) + +typedef float SAMPLE; + +float CubicAmplifier( float input ); +static int fuzzCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ); + +/* Non-linear amplifier with soft distortion curve. */ +float CubicAmplifier( float input ) +{ + float output, temp; + if( input < 0.0 ) + { + temp = input + 1.0f; + output = (temp * temp * temp) - 1.0f; + } + else + { + temp = input - 1.0f; + output = (temp * temp * temp) + 1.0f; + } + + return output; +} +#define FUZZ(x) CubicAmplifier(CubicAmplifier(CubicAmplifier(CubicAmplifier(x)))) + +static int gNumNoInputs = 0; +/* This routine will be called by the PortAudio engine when audio is needed. +** It may be called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int fuzzCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + SAMPLE *out = (SAMPLE*)outputBuffer; + SAMPLE *in = (SAMPLE*)inputBuffer; + unsigned int i; + (void) outTime; /* Prevent unused variable warnings. */ + (void) userData; + + if( inputBuffer == NULL ) + { + for( i=0; i<framesPerBuffer; i++ ) + { + *out++ = 0; /* left - silent */ + *out++ = 0; /* right - silent */ + } + gNumNoInputs += 1; + } + else + { + for( i=0; i<framesPerBuffer; i++ ) + { + *out++ = FUZZ(*in++); /* left - distorted */ + *out++ = *in++; /* right - clean */ + } + } + return 0; +} + +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + + err = Pa_OpenStream( + &stream, + Pa_GetDefaultInputDeviceID(), /* default output device */ + 2, /* stereo input */ + PA_SAMPLE_TYPE, + NULL, + Pa_GetDefaultOutputDeviceID(), /* default output device */ + 2, /* stereo output */ + PA_SAMPLE_TYPE, + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, + 0, /* number of buffers, if zero then use default minimum */ + 0, // paClipOff, /* we won't output out of range samples so don't bother clipping them */ + fuzzCallback, + NULL ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + + printf("Hit ENTER to stop program.\n"); + fflush(stdout); + getchar(); + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + + printf("Finished. gNumNoInputs = %d\n", gNumNoInputs ); + 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 ) ); + return -1; +} diff --git a/pd/portaudio_v18/pa_tests/pa_minlat.c b/pd/portaudio_v18/pa_tests/pa_minlat.c new file mode 100644 index 00000000..7256cc00 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/pa_minlat.c @@ -0,0 +1,172 @@ +/* + * $Id: pa_minlat.c,v 1.4 2002/04/30 18:19:00 philburk Exp $ + * paminlat.c + * Experiment with different numbers of buffers to determine the + * minimum latency for a computer. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include "portaudio.h" + +#ifndef M_PI +#define M_PI (3.14159265) +#endif +#define TWOPI (M_PI * 2.0) + +#define DEFAULT_BUFFER_SIZE (64) + +typedef struct +{ + double left_phase; + double right_phase; +} +paTestData; + +/* Very simple synthesis routine to generate two sine waves. */ +static int paminlatCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + unsigned int i; + double left_phaseInc = 0.02; + double right_phaseInc = 0.06; + + double left_phase = data->left_phase; + double right_phase = data->right_phase; + + for( i=0; i<framesPerBuffer; i++ ) + { + left_phase += left_phaseInc; + if( left_phase > TWOPI ) left_phase -= TWOPI; + *out++ = (float) sin( left_phase ); + + right_phase += right_phaseInc; + if( right_phase > TWOPI ) right_phase -= TWOPI; + *out++ = (float) sin( right_phase ); + } + + data->left_phase = left_phase; + data->right_phase = right_phase; + return 0; +} +void main( int argc, char **argv ); +void main( int argc, char **argv ) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int go; + int numBuffers = 0; + int minBuffers = 0; + int framesPerBuffer; + double sampleRate = 44100.0; + char str[256]; + printf("paminlat - Determine minimum latency for your computer.\n"); + printf(" usage: paminlat {framesPerBuffer}\n"); + printf(" for example: paminlat 256\n"); + printf("Adjust your stereo until you hear a smooth tone in each speaker.\n"); + printf("Then try to find the smallest number of buffers that still sounds smooth.\n"); + printf("Note that the sound will stop momentarily when you change the number of buffers.\n"); + /* Get bufferSize from command line. */ + framesPerBuffer = ( argc > 1 ) ? atol( argv[1] ) : DEFAULT_BUFFER_SIZE; + printf("Frames per buffer = %d\n", framesPerBuffer ); + + data.left_phase = data.right_phase = 0.0; + err = Pa_Initialize(); + if( err != paNoError ) goto error; + /* Ask PortAudio for the recommended minimum number of buffers. */ + numBuffers = minBuffers = Pa_GetMinNumBuffers( framesPerBuffer, sampleRate ); + printf("NumBuffers set to %d based on a call to Pa_GetMinNumBuffers()\n", numBuffers ); + /* Try different numBuffers in a loop. */ + go = 1; + while( go ) + { + + printf("Latency = framesPerBuffer * numBuffers = %d * %d = %d frames = %d msecs.\n", + framesPerBuffer, numBuffers, framesPerBuffer*numBuffers, + (int)((1000 * framesPerBuffer * numBuffers) / sampleRate) ); + err = Pa_OpenStream( + &stream, + paNoDevice, + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + Pa_GetDefaultOutputDeviceID(), /* default output device */ + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + NULL, + sampleRate, + framesPerBuffer, + numBuffers, /* number of buffers */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + paminlatCallback, + &data ); + if( err != paNoError ) goto error; + if( stream == NULL ) goto error; + /* Start audio. */ + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + /* Ask user for a new number of buffers. */ + printf("\nMove windows around to see if the sound glitches.\n"); + printf("NumBuffers currently %d, enter new number, or 'q' to quit: ", numBuffers ); + gets( str ); + if( str[0] == 'q' ) go = 0; + else + { + numBuffers = atol( str ); + if( numBuffers < minBuffers ) + { + printf( "numBuffers below minimum of %d! Set to minimum!!!\n", minBuffers ); + numBuffers = minBuffers; + } + } + /* Stop sound until ENTER hit. */ + err = Pa_StopStream( stream ); + if( err != paNoError ) goto error; + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + } + printf("A good setting for latency would be somewhat higher than\n"); + printf("the minimum latency that worked.\n"); + printf("PortAudio: Test finished.\n"); + Pa_Terminate(); + return; +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 ) ); +} diff --git a/pd/portaudio_v18/pa_tests/paqa_devs.c b/pd/portaudio_v18/pa_tests/paqa_devs.c new file mode 100644 index 00000000..92eb6c7a --- /dev/null +++ b/pd/portaudio_v18/pa_tests/paqa_devs.c @@ -0,0 +1,322 @@ +/* + * $Id: paqa_devs.c,v 1.1.1.1.4.1 2003/02/11 21:41:32 philburk Exp $ + * paqa_devs.c + * Self Testing Quality Assurance app for PortAudio + * Try to open each device and run through all the + * possible configurations. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +#include "pa_trace.h" +/****************************************** Definitions ***********/ +#define MODE_INPUT (0) +#define MODE_OUTPUT (1) +typedef struct PaQaData +{ + unsigned long framesLeft; + int numChannels; + int bytesPerSample; + int mode; + short sawPhase; + PaSampleFormat format; +} PaQaData; + +/****************************************** Prototypes ***********/ +static void TestDevices( int mode ); +static void TestFormats( int mode, PaDeviceID deviceID, double sampleRate, + int numChannels ); +static int TestAdvance( int mode, PaDeviceID deviceID, double sampleRate, + int numChannels, PaSampleFormat format ); +static int QaCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ); + +/****************************************** Globals ***********/ +static int gNumPassed = 0; +static int gNumFailed = 0; + +/****************************************** Macros ***********/ +/* Print ERROR if it fails. Tally success or failure. */ +/* Odd do-while wrapper seems to be needed for some compilers. */ +#define EXPECT(_exp) \ + do \ + { \ + if ((_exp)) {\ + /* printf("SUCCESS for %s\n", #_exp ); */ \ + gNumPassed++; \ + } \ + else { \ + printf("ERROR - 0x%x - %s for %s\n", result, \ + ((result == 0) ? "-" : Pa_GetErrorText(result)), \ + #_exp ); \ + gNumFailed++; \ + goto error; \ + } \ + } while(0) +/*******************************************************************/ +/* This routine will be called by the PortAudio engine when audio is needed. +** It may be called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int QaCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + unsigned long i; + short phase; + PaQaData *data = (PaQaData *) userData; + (void) inputBuffer; + (void) outTime; + + /* Play simple sawtooth wave. */ + if( data->mode == MODE_OUTPUT ) + { + phase = data->sawPhase; + switch( data->format ) + { + case paFloat32: + { + float *out = (float *) outputBuffer; + for( i=0; i<framesPerBuffer; i++ ) + { + phase += 0x123; + *out++ = (float) (phase * (1.0 / 32768.0)); + if( data->numChannels == 2 ) + { + *out++ = (float) (phase * (1.0 / 32768.0)); + } + } + } + break; + + case paInt32: + { + int *out = (int *) outputBuffer; + for( i=0; i<framesPerBuffer; i++ ) + { + phase += 0x123; + *out++ = ((int) phase ) << 16; + if( data->numChannels == 2 ) + { + *out++ = ((int) phase ) << 16; + } + } + } + break; + case paInt16: + { + short *out = (short *) outputBuffer; + for( i=0; i<framesPerBuffer; i++ ) + { + phase += 0x123; + *out++ = phase; + if( data->numChannels == 2 ) + { + *out++ = phase; + } + } + } + break; + + default: + { + unsigned char *out = (unsigned char *) outputBuffer; + unsigned long numBytes = framesPerBuffer * data->numChannels * data->bytesPerSample; + for( i=0; i<numBytes; i++ ) + { + *out++ = 0; + } + } + break; + } + data->sawPhase = phase; + } + /* Are we through yet? */ + if( data->framesLeft > framesPerBuffer ) + { + AddTraceMessage("QaCallback: running. framesLeft", data->framesLeft ); + data->framesLeft -= framesPerBuffer; + return 0; + } + else + { + AddTraceMessage("QaCallback: DONE! framesLeft", data->framesLeft ); + data->framesLeft = 0; + return 1; + } +} +/*******************************************************************/ +int main(void); +int main(void) +{ + PaError result; + EXPECT( ((result=Pa_Initialize()) == 0) ); + printf("Test OUTPUT ---------------\n"); + TestDevices( MODE_OUTPUT ); + printf("Test INPUT ---------------\n"); + TestDevices( MODE_INPUT ); +error: + Pa_Terminate(); + printf("QA Report: %d passed, %d failed.\n", gNumPassed, gNumFailed ); +} +/******************************************************************* +* Try each output device, through its full range of capabilities. */ +static void TestDevices( int mode ) +{ + int id,jc,kr; + int maxChannels; + const PaDeviceInfo *pdi; + int numDevices = Pa_CountDevices(); + /* Iterate through all devices. */ + for( id=0; id<numDevices; id++ ) + { + pdi = Pa_GetDeviceInfo( id ); + /* Try 1 to maxChannels on each device. */ + maxChannels = ( mode == MODE_INPUT ) ? pdi->maxInputChannels : pdi->maxOutputChannels; + for( jc=1; jc<=maxChannels; jc++ ) + { + printf("Name = %s\n", pdi->name ); + /* Try each legal sample rate. */ + if( pdi->numSampleRates == -1 ) + { + double low, high; + low = pdi->sampleRates[0]; + high = pdi->sampleRates[1]; + if( low < 8000.0 ) low = 8000.0; + TestFormats( mode, id, low, jc ); +#define TESTSR(sr) {if(((sr)>=low) && ((sr)<=high)) TestFormats( mode, id, (sr), jc ); } + + TESTSR(11025.0); + TESTSR(22050.0); + TESTSR(34567.0); + TESTSR(44100.0); + TestFormats( mode, id, high, jc ); + } + else + { + for( kr=0; kr<pdi->numSampleRates; kr++ ) + { + TestFormats( mode, id, pdi->sampleRates[kr], jc ); + } + } + } + } +} +/*******************************************************************/ +static void TestFormats( int mode, PaDeviceID deviceID, double sampleRate, + int numChannels ) +{ + TestAdvance( mode, deviceID, sampleRate, numChannels, paFloat32 ); /* */ + TestAdvance( mode, deviceID, sampleRate, numChannels, paInt16 ); /* */ + TestAdvance( mode, deviceID, sampleRate, numChannels, paInt32 ); /* */ +} +/*******************************************************************/ +static int TestAdvance( int mode, PaDeviceID deviceID, double sampleRate, + int numChannels, PaSampleFormat format ) +{ + PortAudioStream *stream = NULL; + PaError result; + PaQaData myData; +#define FRAMES_PER_BUFFER (64) + printf("------ TestAdvance: %s, device = %d, rate = %g, numChannels = %d, format = %d -------\n", + ( mode == MODE_INPUT ) ? "INPUT" : "OUTPUT", + deviceID, sampleRate, numChannels, format); + fflush(stdout); + /* Setup data for synthesis thread. */ + myData.framesLeft = (unsigned long) (sampleRate * 100); /* 100 seconds */ + myData.numChannels = numChannels; + myData.mode = mode; + myData.format = format; + switch( format ) + { + case paFloat32: + case paInt32: + case paInt24: + myData.bytesPerSample = 4; + break; + case paPackedInt24: + myData.bytesPerSample = 3; + break; + default: + myData.bytesPerSample = 2; + break; + } + EXPECT( ((result = Pa_OpenStream( + &stream, + ( mode == MODE_INPUT ) ? deviceID : paNoDevice, + ( mode == MODE_INPUT ) ? numChannels : 0, + format, + NULL, + ( mode == MODE_OUTPUT ) ? deviceID : paNoDevice, + ( mode == MODE_OUTPUT ) ? numChannels : 0, + format, + NULL, + sampleRate, + FRAMES_PER_BUFFER, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + QaCallback, + &myData ) + ) == 0) ); + if( stream ) + { + PaTimestamp oldStamp, newStamp; + unsigned long oldFrames; + int minDelay = ( mode == MODE_INPUT ) ? 1000 : 400; + int minNumBuffers = Pa_GetMinNumBuffers( FRAMES_PER_BUFFER, sampleRate ); + int msec = (int) ((minNumBuffers * 3 * 1000.0 * FRAMES_PER_BUFFER) / sampleRate); + if( msec < minDelay ) msec = minDelay; + printf("msec = %d\n", msec); /**/ + EXPECT( ((result=Pa_StartStream( stream )) == 0) ); + /* Check to make sure PortAudio is advancing timeStamp. */ + result = paNoError; + oldStamp = Pa_StreamTime(stream); + fflush(stdout); + Pa_Sleep(msec); + newStamp = Pa_StreamTime(stream); + printf("oldStamp = %g,newStamp = %g\n", oldStamp, newStamp ); /**/ + EXPECT( (oldStamp < newStamp) ); + /* Check to make sure callback is decrementing framesLeft. */ + oldFrames = myData.framesLeft; + Pa_Sleep(msec); + printf("oldFrames = %d, myData.framesLeft = %d\n", oldFrames, myData.framesLeft ); /**/ + EXPECT( (oldFrames > myData.framesLeft) ); + EXPECT( ((result=Pa_CloseStream( stream )) == 0) ); + stream = NULL; + } +error: + if( stream != NULL ) Pa_CloseStream( stream ); + fflush(stdout); + return result; +} diff --git a/pd/portaudio_v18/pa_tests/paqa_errs.c b/pd/portaudio_v18/pa_tests/paqa_errs.c new file mode 100644 index 00000000..a26779cc --- /dev/null +++ b/pd/portaudio_v18/pa_tests/paqa_errs.c @@ -0,0 +1,330 @@ +/* + * $Id: paqa_errs.c,v 1.2.4.1 2003/02/11 21:41:32 philburk Exp $ + * paqa_devs.c + * Self Testing Quality Assurance app for PortAudio + * Do lots of bad things to test error reporting. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +/****************************************** Definitions ***********/ +#define MODE_INPUT (0) +#define MODE_OUTPUT (1) +#define FRAMES_PER_BUFFER (64) +#define SAMPLE_RATE (44100.0) +#define NUM_BUFFERS (0) +typedef struct PaQaData +{ + unsigned long framesLeft; + int numChannels; + int bytesPerSample; + int mode; +} +PaQaData; +/****************************************** Prototypes ***********/ +static void TestDevices( int mode ); +static void TestFormats( int mode, PaDeviceID deviceID, double sampleRate, + int numChannels ); +static int TestBadOpens( void ); +static int TestBadActions( void ); +static int QaCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ); +/****************************************** Globals ***********/ +static int gNumPassed = 0; +static int gNumFailed = 0; +/****************************************** Macros ***********/ +/* Print ERROR if it fails. Tally success or failure. */ +/* Odd do-while wrapper seems to be needed for some compilers. */ +#define EXPECT( msg, _exp) \ + do \ + { \ + if ((_exp)) {\ + gNumPassed++; \ + } \ + else { \ + printf("\nERROR %s\n - 0x%x - %s for %s\n", (msg), result, Pa_GetErrorText(result), #_exp ); \ + gNumFailed++; \ + goto error; \ + } \ + } while(0) +#define HOPEFOR( msg, _exp) \ + do \ + { \ + if ((_exp)) {\ + gNumPassed++; \ + } \ + else { \ + printf("\nERROR %s\n - 0x%x - %s for %s\n", (msg), result, Pa_GetErrorText(result), #_exp ); \ + gNumFailed++; \ + } \ + } while(0) +/*******************************************************************/ +/* This routine will be called by the PortAudio engine when audio is needed. +** It may be called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int QaCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + unsigned long i; + unsigned char *out = (unsigned char *) outputBuffer; + PaQaData *data = (PaQaData *) userData; + (void) inputBuffer; /* Prevent "unused variable" warnings. */ + (void) outTime; + + /* Zero out buffer so we don't hear terrible noise. */ + if( data->mode == MODE_OUTPUT ) + { + unsigned long numBytes = framesPerBuffer * data->numChannels * data->bytesPerSample; + for( i=0; i<numBytes; i++ ) + { + *out++ = 0; + } + } + /* Are we through yet? */ + if( data->framesLeft > framesPerBuffer ) + { + data->framesLeft -= framesPerBuffer; + return 0; + } + else + { + data->framesLeft = 0; + return 1; + } +} +/*******************************************************************/ +int main(void); +int main(void) +{ + PaError result; + EXPECT( "init", ((result=Pa_Initialize()) == 0) ); + TestBadActions(); + TestBadOpens(); +error: + Pa_Terminate(); + printf("QA Report: %d passed, %d failed.\n", gNumPassed, gNumFailed ); + return 0; +} +/*******************************************************************/ +static int TestBadOpens( void ) +{ + PortAudioStream *stream = NULL; + PaError result; + PaQaData myData; + /* Setup data for synthesis thread. */ + myData.framesLeft = (unsigned long) (SAMPLE_RATE * 100); /* 100 seconds */ + myData.numChannels = 1; + myData.mode = MODE_OUTPUT; + HOPEFOR( "No devices specified.",( + (result = Pa_OpenStream( + &stream, + paNoDevice, 0, paFloat32, NULL, + paNoDevice, 0, paFloat32, NULL, + SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS, + paClipOff, + QaCallback, + &myData ) + ) == paInvalidDeviceId) ); + HOPEFOR( "Out of range input device specified.",( + (result = Pa_OpenStream( + &stream, + Pa_CountDevices(), 0, paFloat32, NULL, + paNoDevice, 0, paFloat32, NULL, + SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS, + paClipOff, + QaCallback, + &myData ) + ) == paInvalidDeviceId) ); + + HOPEFOR( "Out of range output device specified.",( + (result = Pa_OpenStream( + &stream, + paNoDevice, 0, paFloat32, NULL, + Pa_CountDevices(), 0, paFloat32, NULL, + SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS, + paClipOff, + QaCallback, + &myData ) + ) == paInvalidDeviceId) ); + HOPEFOR( "Zero input channels.",( + (result = Pa_OpenStream( + &stream, + Pa_GetDefaultInputDeviceID(), 0, paFloat32, NULL, + paNoDevice, 0, paFloat32, NULL, + SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS, + paClipOff, + QaCallback, + &myData ) + ) == paInvalidChannelCount) ); + HOPEFOR( "Zero output channels.",( + (result = Pa_OpenStream( + &stream, + paNoDevice, 0, paFloat32, NULL, + Pa_GetDefaultOutputDeviceID(), 0, paFloat32, NULL, + SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS, + paClipOff, + QaCallback, + &myData ) + ) == paInvalidChannelCount) ); + HOPEFOR( "Nonzero input channels but no device.",( + (result = Pa_OpenStream( + &stream, + Pa_GetDefaultInputDeviceID(), 2, paFloat32, NULL, + paNoDevice, 2, paFloat32, NULL, + SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS, + paClipOff, + QaCallback, + &myData ) + ) == paInvalidChannelCount) ); + + HOPEFOR( "Nonzero output channels but no device.",( + (result = Pa_OpenStream( + &stream, + paNoDevice, 2, paFloat32, NULL, + Pa_GetDefaultOutputDeviceID(), 2, paFloat32, NULL, + SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS, + paClipOff, + QaCallback, + &myData ) + ) == paInvalidChannelCount) ); + HOPEFOR( "NULL stream pointer.",( + (result = Pa_OpenStream( + NULL, + paNoDevice, 0, paFloat32, NULL, + Pa_GetDefaultOutputDeviceID(), 2, paFloat32, NULL, + SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS, + paClipOff, + QaCallback, + &myData ) + ) == paBadStreamPtr) ); + HOPEFOR( "Low sample rate.",( + (result = Pa_OpenStream( + &stream, + paNoDevice, 0, paFloat32, NULL, + Pa_GetDefaultOutputDeviceID(), 2, paFloat32, NULL, + 1.0, FRAMES_PER_BUFFER, NUM_BUFFERS, + paClipOff, + QaCallback, + &myData ) + ) == paInvalidSampleRate) ); + HOPEFOR( "High sample rate.",( + (result = Pa_OpenStream( + &stream, + paNoDevice, 0, paFloat32, NULL, + Pa_GetDefaultOutputDeviceID(), 2, paFloat32, NULL, + 10000000.0, FRAMES_PER_BUFFER, NUM_BUFFERS, + paClipOff, + QaCallback, + &myData ) + ) == paInvalidSampleRate) ); + HOPEFOR( "NULL callback.",( + (result = Pa_OpenStream( + &stream, + paNoDevice, 0, paFloat32, NULL, + Pa_GetDefaultOutputDeviceID(), 2, paFloat32, NULL, + SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS, + paClipOff, + NULL, + &myData ) + ) == paNullCallback) ); + HOPEFOR( "Bad flag.",( + (result = Pa_OpenStream( + &stream, + paNoDevice, 0, paFloat32, NULL, + Pa_GetDefaultOutputDeviceID(), 2, paFloat32, NULL, + SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS, + (1<<3), + QaCallback, + &myData ) + ) == paInvalidFlag) ); + +#if 1 /* FIXME - this is legal for some implementations. */ + HOPEFOR( "Use input device as output device.",( + (result = Pa_OpenStream( + &stream, + paNoDevice, 0, paFloat32, NULL, + Pa_GetDefaultInputDeviceID(), 2, paFloat32, NULL, + SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS, + paClipOff, + QaCallback, + &myData ) + ) == paInvalidDeviceId) ); + + HOPEFOR( "Use output device as input device.",( + (result = Pa_OpenStream( + &stream, + Pa_GetDefaultOutputDeviceID(), 2, paFloat32, NULL, + paNoDevice, 0, paFloat32, NULL, + SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS, + paClipOff, + QaCallback, + &myData ) + ) == paInvalidDeviceId) ); +#endif + + if( stream != NULL ) Pa_CloseStream( stream ); + return result; +} +/*******************************************************************/ +static int TestBadActions( void ) +{ + PortAudioStream *stream = NULL; + PaError result; + PaQaData myData; + /* Setup data for synthesis thread. */ + myData.framesLeft = (unsigned long) (SAMPLE_RATE * 100); /* 100 seconds */ + myData.numChannels = 1; + myData.mode = MODE_OUTPUT; + /* Default output. */ + EXPECT( "TestBadActions", ((result = Pa_OpenStream( + &stream, + paNoDevice, 0, paFloat32, NULL, + Pa_GetDefaultOutputDeviceID(), 2, paFloat32, NULL, + SAMPLE_RATE, FRAMES_PER_BUFFER, NUM_BUFFERS, + paClipOff, + QaCallback, + &myData ) + ) == 0) ); + HOPEFOR( "start", ((result = Pa_StartStream( NULL )) == paBadStreamPtr) ); + HOPEFOR( "stop", ((result = Pa_StopStream( NULL )) == paBadStreamPtr) ); + HOPEFOR( "active?", ((result = Pa_StreamActive( NULL )) == paBadStreamPtr) ); + HOPEFOR( "close", ((result = Pa_CloseStream( NULL )) == paBadStreamPtr) ); + HOPEFOR( "time?", ((result = (PaError)Pa_StreamTime( NULL )) != 0) ); + HOPEFOR( "CPULoad?", ((result = (PaError)Pa_GetCPULoad( NULL )) != 0) ); +error: + if( stream != NULL ) Pa_CloseStream( stream ); + return result; +} diff --git a/pd/portaudio_v18/pa_tests/patest1.c b/pd/portaudio_v18/pa_tests/patest1.c new file mode 100644 index 00000000..8ac45ad1 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest1.c @@ -0,0 +1,114 @@ +/* + $Id: patest1.c,v 1.1.1.1 2002/01/22 00:52:33 phil Exp $ + patest1.c + Ring modulate the audio input with a sine wave for 20 seconds + using the Portable Audio api + Author: Ross Bencina <rossb@audiomulch.com> + Modifications: + April 5th, 2001 - PLB - Check for NULL inputBuffer. +*/ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +#ifndef M_PI +#define M_PI (3.14159265) +#endif +typedef struct +{ + float sine[100]; + int phase; + int sampsToGo; +} +patest1data; +static int patest1Callback( void *inputBuffer, void *outputBuffer, + unsigned long bufferFrames, + PaTimestamp outTime, void *userData ) +{ + patest1data *data = (patest1data*)userData; + float *in = (float*)inputBuffer; + float *out = (float*)outputBuffer; + int framesToCalc = bufferFrames; + unsigned long i; + int finished = 0; + /* Check to see if any input data is available. */ + if(inputBuffer == NULL) return 0; + if( data->sampsToGo < bufferFrames ) + { + framesToCalc = data->sampsToGo; + finished = 1; + } + for( i=0; i<framesToCalc; i++ ) + { + *out++ = *in++ * data->sine[data->phase]; /* left */ + *out++ = *in++ * data->sine[data->phase++]; /* right */ + if( data->phase >= 100 ) + data->phase = 0; + } + data->sampsToGo -= framesToCalc; + /* zero remainder of final buffer if not already done */ + for( ; i<bufferFrames; i++ ) + { + *out++ = 0; /* left */ + *out++ = 0; /* right */ + } + return finished; +} +int main(int argc, char* argv[]); +int main(int argc, char* argv[]) +{ + PaStream *stream; + PaError err; + patest1data data; + int i; + int inputDevice = Pa_GetDefaultInputDeviceID(); + int outputDevice = Pa_GetDefaultOutputDeviceID(); + /* initialise sinusoidal wavetable */ + for( i=0; i<100; i++ ) + data.sine[i] = sin( ((double)i/100.) * M_PI * 2. ); + data.phase = 0; + data.sampsToGo = 44100 * 20; // 20 seconds + /* initialise portaudio subsytem */ + Pa_Initialize(); + err = Pa_OpenStream( + &stream, + inputDevice, + 2, /* stereo input */ + paFloat32, /* 32 bit floating point input */ + NULL, + outputDevice, + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + NULL, + 44100., + 512, /* small buffers */ + 0, /* let PA determine number of buffers */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patest1Callback, + &data ); + if( err == paNoError ) + { + err = Pa_StartStream( stream ); + printf( "Press any key to end.\n" ); + getc( stdin ); //wait for input before exiting + Pa_AbortStream( stream ); + + printf( "Waiting for stream to complete...\n" ); + + while( Pa_StreamActive( stream ) ) + Pa_Sleep(1000); /* sleep until playback has finished */ + + err = Pa_CloseStream( stream ); + } + else + { + fprintf( stderr, "An error occured while opening the portaudio stream\n" ); + if( err == paHostError ) + fprintf( stderr, "Host error number: %d\n", Pa_GetHostError() ); + else + fprintf( stderr, "Error number: %d\n", err ); + } + Pa_Terminate(); + printf( "bye\n" ); + + return 0; +} diff --git a/pd/portaudio_v18/pa_tests/patest_buffer.c b/pd/portaudio_v18/pa_tests/patest_buffer.c new file mode 100644 index 00000000..8d61f4f7 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_buffer.c @@ -0,0 +1,180 @@ +/* + * $Id: patest_buffer.c,v 1.1.1.1.4.1 2003/02/11 21:41:32 philburk Exp $ + * patest_buffer.c + * Test opening streams with different buffer sizes. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include "portaudio.h" +#define NUM_SECONDS (1) +#define SAMPLE_RATE (44100) +#ifndef M_PI +#define M_PI (3.14159265) +#endif +#define TABLE_SIZE (200) + +#define BUFFER_TABLE 9 +long buffer_table[] = {200,256,500,512,600, 723, 1000, 1024, 2345}; + +typedef struct +{ + short sine[TABLE_SIZE]; + int left_phase; + int right_phase; + unsigned int sampsToGo; +} +paTestData; +PaError TestOnce( int buffersize ); + +static int paSineCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ); +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int paSineCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + short *out = (short*)outputBuffer; + unsigned int i; + int finished = 0; + (void) inputBuffer; /* Prevent "unused variable" warnings. */ + (void) outTime; + + if( data->sampsToGo < framesPerBuffer ) + { + for( i=0; i<data->sampsToGo; i++ ) + { + *out++ = data->sine[data->left_phase]; /* left */ + *out++ = data->sine[data->right_phase]; /* right */ + data->left_phase += 1; + if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE; + data->right_phase += 3; /* higher pitch so we can distinguish left and right. */ + if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE; + } + /* zero remainder of final buffer */ + for( ; i<framesPerBuffer; i++ ) + { + *out++ = 0; /* left */ + *out++ = 0; /* right */ + } + + finished = 1; + } + else + { + for( i=0; i<framesPerBuffer; i++ ) + { + *out++ = data->sine[data->left_phase]; /* left */ + *out++ = data->sine[data->right_phase]; /* right */ + data->left_phase += 1; + if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE; + data->right_phase += 3; /* higher pitch so we can distinguish left and right. */ + if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE; + } + data->sampsToGo -= framesPerBuffer; + } + return finished; +} +/*******************************************************************/ +int main(void); +int main(void) +{ + int i; + PaError err; + printf("Test opening streams with different buffer sizes\n\n"); + + for (i = 0 ; i < BUFFER_TABLE; i++) + { + printf("Buffer size %d\n", buffer_table[i]); + err = TestOnce(buffer_table[i]); + if( err < 0 ) return 0; + + } +} + + +PaError TestOnce( int buffersize ) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int i; + int totalSamps; + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + data.sine[i] = (short) (30000.0 * sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. )); + } + data.left_phase = data.right_phase = 0; + data.sampsToGo = totalSamps = NUM_SECONDS * SAMPLE_RATE; /* Play for a few seconds. */ + err = Pa_Initialize(); + if( err != paNoError ) goto error; + err = Pa_OpenStream( + &stream, + paNoDevice,/* default input device */ + 0, /* no input */ + paInt16, /* sample format */ + NULL, + Pa_GetDefaultOutputDeviceID(), /* default output device */ + 2, /* stereo output */ + paInt16, /* sample format */ + NULL, + SAMPLE_RATE, + buffersize, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + paSineCallback, + &data ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + printf("Waiting for sound to finish.\n"); + fflush(stdout); + Pa_Sleep(1000); + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + Pa_Terminate(); + return paNoError; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_clip.c b/pd/portaudio_v18/pa_tests/patest_clip.c new file mode 100644 index 00000000..3fb30d40 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_clip.c @@ -0,0 +1,156 @@ +/* + * $Id: patest_clip.c,v 1.1.1.1 2002/01/22 00:52:34 phil Exp $ + * patest_clip.c + * Play a sine wave using the Portable Audio api for several seconds + * at an amplitude that would require clipping. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +#define NUM_SECONDS (4) +#define SAMPLE_RATE (44100) +#ifndef M_PI +#define M_PI (3.14159265) +#endif +#define TABLE_SIZE (200) +typedef struct paTestData +{ + float sine[TABLE_SIZE]; + float amplitude; + int left_phase; + int right_phase; +} +paTestData; +PaError PlaySine( paTestData *data, unsigned long flags, float amplitude ); +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int sineCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + float amplitude = data->amplitude; + unsigned int i; + (void) inputBuffer; /* Prevent "unused variable" warnings. */ + (void) outTime; + + for( i=0; i<framesPerBuffer; i++ ) + { + *out++ = amplitude * data->sine[data->left_phase]; /* left */ + *out++ = amplitude * data->sine[data->right_phase]; /* right */ + data->left_phase += 1; + if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE; + data->right_phase += 3; /* higher pitch so we can distinguish left and right. */ + if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE; + } + return 0; +} +/*******************************************************************/ +int main(void); +int main(void) +{ + PaError err; + paTestData DATA; + int i; + printf("PortAudio Test: output sine wave with and without clipping.\n"); + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + DATA.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. ); + } + printf("\nHalf amplitude. Should sound like sine wave.\n"); fflush(stdout); + err = PlaySine( &DATA, paClipOff | paDitherOff, 0.5f ); + if( err < 0 ) goto error; + printf("\nFull amplitude. Should sound like sine wave.\n"); fflush(stdout); + err = PlaySine( &DATA, paClipOff | paDitherOff, 0.999f ); + if( err < 0 ) goto error; + printf("\nOver range with clipping and dithering turned OFF. Should sound very nasty.\n"); + fflush(stdout); + err = PlaySine( &DATA, paClipOff | paDitherOff, 1.1f ); + if( err < 0 ) goto error; + printf("\nOver range with clipping and dithering turned ON. Should sound smoother than previous.\n"); + fflush(stdout); + err = PlaySine( &DATA, paNoFlag, 1.1f ); + if( err < 0 ) goto error; + printf("\nOver range with paClipOff but dithering ON.\n" + "That forces clipping ON so it should sound the same as previous.\n"); + fflush(stdout); + err = PlaySine( &DATA, paClipOff, 1.1f ); + if( err < 0 ) goto error; + return 0; +error: + 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 1; +} +/*****************************************************************************/ +PaError PlaySine( paTestData *data, unsigned long flags, float amplitude ) +{ + PortAudioStream *stream; + PaError err; + data->left_phase = data->right_phase = 0; + data->amplitude = amplitude; + err = Pa_Initialize(); + if( err != paNoError ) goto error; + err = Pa_OpenStream( + &stream, + paNoDevice,/* default input device */ + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + Pa_GetDefaultOutputDeviceID(), /* default output device */ + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + 1024, + 0, /* number of buffers, if zero then use default minimum */ + flags, /* we won't output out of range samples so don't bother clipping them */ + sineCallback, + data ); + if( err != paNoError ) goto error; + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + Pa_Sleep( NUM_SECONDS * 1000 ); + printf("CPULoad = %8.6f\n", Pa_GetCPULoad( stream ) ); + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + Pa_Terminate(); + return paNoError; +error: + return err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_dither.c b/pd/portaudio_v18/pa_tests/patest_dither.c new file mode 100644 index 00000000..c58b9cea --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_dither.c @@ -0,0 +1,152 @@ +/* + * $Id: patest_dither.c,v 1.2 2002/03/21 00:58:45 philburk Exp $ + * patest_dither.c + * Attempt to hear difference between dithered and non-dithered signal. + * This only has an effect if the native format is 16 bit. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +#define NUM_SECONDS (4) +#define SAMPLE_RATE (44100) +#ifndef M_PI +#define M_PI (3.14159265) +#endif +#define TABLE_SIZE (200) +typedef struct paTestData +{ + float sine[TABLE_SIZE]; + float amplitude; + int left_phase; + int right_phase; +} +paTestData; +PaError PlaySine( paTestData *data, PaStreamFlags flags, float amplitude ); +static int sineCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ); +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int sineCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + float amplitude = data->amplitude; + unsigned int i; + (void) outTime; + (void) inputBuffer; + for( i=0; i<framesPerBuffer; i++ ) + { + *out++ = amplitude * data->sine[data->left_phase]; /* left */ + *out++ = amplitude * data->sine[data->right_phase]; /* right */ + data->left_phase += 1; + if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE; + data->right_phase += 3; /* higher pitch so we can distinguish left and right. */ + if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE; + } + return 0; +} +/*******************************************************************/ +int main(void); +int main(void) +{ + PaError err; + paTestData DATA; + int i; + float amplitude = 32.0 / (1<<15); + printf("PortAudio Test: output EXTREMELY QUIET sine wave with and without dithering.\n"); + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + DATA.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. ); + } + printf("\nNo treatment..\n"); fflush(stdout); + err = PlaySine( &DATA, paClipOff | paDitherOff, amplitude ); + if( err < 0 ) goto error; + printf("\nClip.\n"); + fflush(stdout); + err = PlaySine( &DATA, paDitherOff, amplitude ); + if( err < 0 ) goto error; + printf("\nClip and Dither.\n"); + fflush(stdout); + err = PlaySine( &DATA, paNoFlag, amplitude ); + if( err < 0 ) goto error; + return 0; +error: + 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 -1; +} +/*****************************************************************************/ +PaError PlaySine( paTestData *data, PaStreamFlags flags, float amplitude ) +{ + PortAudioStream *stream; + PaError err; + data->left_phase = data->right_phase = 0; + data->amplitude = amplitude; + err = Pa_Initialize(); + if( err != paNoError ) goto error; + err = Pa_OpenStream( + &stream, + paNoDevice,/* default input device */ + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + Pa_GetDefaultOutputDeviceID(), /* default output device */ + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + 1024, + 0, /* number of buffers, if zero then use default minimum */ + flags, /* we won't output out of range samples so don't bother clipping them */ + sineCallback, + (void *)data ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + Pa_Sleep( NUM_SECONDS * 1000 ); + printf("CPULoad = %8.6f\n", Pa_GetCPULoad( stream ) ); + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + Pa_Terminate(); + return paNoError; +error: + return err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_hang.c b/pd/portaudio_v18/pa_tests/patest_hang.c new file mode 100644 index 00000000..d1d67199 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_hang.c @@ -0,0 +1,153 @@ +/* + * $Id: patest_hang.c,v 1.1.4.1 2003/02/11 21:41:32 philburk Exp $ + * Play a sine then hang audio callback to test watchdog. + * + * Authors: + * Ross Bencina <rossb@audiomulch.com> + * Phil Burk <philburk@softsynth.com> + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.audiomulch.com/portaudio/ + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" + + +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (1024) +#ifndef M_PI +#define M_PI (3.14159265) +#endif +#define TWOPI (M_PI * 2.0) + +typedef struct paTestData +{ + int sleepFor; + double phase; +} +paTestData; + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + unsigned long i; + int finished = 0; + double phaseInc = 0.02; + double phase = data->phase; + + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + for( i=0; i<framesPerBuffer; i++ ) + { + phase += phaseInc; + if( phase > TWOPI ) phase -= TWOPI; + /* This is not a very efficient way to calc sines. */ + *out++ = (float) sin( phase ); /* mono */ + } + + if( data->sleepFor > 0 ) + { + Pa_Sleep( data->sleepFor ); + } + + data->phase = phase; + return finished; +} + +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + int i; + paTestData data = {0}; + + printf("PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", + SAMPLE_RATE, FRAMES_PER_BUFFER ); + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + + err = Pa_OpenStream( + &stream, + paNoDevice,/* default input device */ + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + Pa_GetDefaultOutputDeviceID(), /* default output device */ + 1, /* mono output */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + +/* Gradually increase sleep time. */ + for( i=0; i<10000; i+= 1000 ) + { + printf("Sleep for %d milliseconds in audio callback.\n", i ); + data.sleepFor = i; + fflush(stdout); + Pa_Sleep( ((i<1000) ? 1000 : i) ); + } + + printf("Suffer for 10 seconds.\n"); + fflush(stdout); + Pa_Sleep( 10000 ); + + 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 err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_latency.c b/pd/portaudio_v18/pa_tests/patest_latency.c new file mode 100644 index 00000000..39ede0a7 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_latency.c @@ -0,0 +1,176 @@ +/* + * $Id: patest_latency.c,v 1.4 2002/03/21 00:58:45 philburk Exp $ + * Hear the latency caused by big buffers. + * Play a sine wave and change frequency based on letter input. + * + * Author: Phil Burk <philburk@softsynth.com>, and Darren Gibbs + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" + +#define OUTPUT_DEVICE (Pa_GetDefaultOutputDeviceID()) +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (64) + +#if 0 +#define MIN_LATENCY_MSEC (2000) +#define NUM_BUFFERS ((MIN_LATENCY_MSEC * SAMPLE_RATE) / (FRAMES_PER_BUFFER * 1000)) +#else +#define NUM_BUFFERS (0) +#endif + +#define MIN_FREQ (100.0f) +#define CalcPhaseIncrement(freq) ((freq)/SAMPLE_RATE) +#ifndef M_PI +#define M_PI (3.14159265) +#endif +#define TABLE_SIZE (400) +typedef struct +{ + float sine[TABLE_SIZE + 1]; // add one for guard point for interpolation + float phase_increment; + float left_phase; + float right_phase; +} +paTestData; +float LookupSine( paTestData *data, float phase ); +/* Convert phase between and 1.0 to sine value + * using linear interpolation. + */ +float LookupSine( paTestData *data, float phase ) +{ + float fIndex = phase*TABLE_SIZE; + int index = (int) fIndex; + float fract = fIndex - index; + float lo = data->sine[index]; + float hi = data->sine[index+1]; + float val = lo + fract*(hi-lo); + return val; +} +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + int i; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + for( i=0; i<framesPerBuffer; i++ ) + { + *out++ = LookupSine(data, data->left_phase); /* left */ + *out++ = LookupSine(data, data->right_phase); /* right */ + data->left_phase += data->phase_increment; + if( data->left_phase >= 1.0f ) data->left_phase -= 1.0f; + data->right_phase += (data->phase_increment * 1.5f); /* fifth above */ + if( data->right_phase >= 1.0f ) data->right_phase -= 1.0f; + } + return 0; +} +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int i; + int done = 0; + printf("PortAudio Test: enter letter then hit ENTER. numBuffers = %d\n", NUM_BUFFERS ); + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + data.sine[i] = 0.90f * (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. ); + } + data.sine[TABLE_SIZE] = data.sine[0]; // set guard point + data.left_phase = data.right_phase = 0.0; + data.phase_increment = CalcPhaseIncrement(MIN_FREQ); + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + printf("PortAudio Test: output device = %d\n", OUTPUT_DEVICE ); + err = Pa_OpenStream( + &stream, + paNoDevice, + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + OUTPUT_DEVICE, + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, + NUM_BUFFERS, /* number of buffers, if zero then use default minimum */ + paClipOff|paDitherOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + printf("Play ASCII keyboard. Hit 'q' to stop. (Use RETURN key on Mac)\n"); + fflush(stdout); + while ( !done ) + { + float freq; + int index; + char c; + do + { + c = getchar(); + } + while( c < ' '); /* Strip white space and control chars. */ + + if( c == 'q' ) done = 1; + index = c % 26; + freq = MIN_FREQ + (index * 40.0); + data.phase_increment = CalcPhaseIncrement(freq); + } + printf("Call Pa_StopStream()\n"); + err = Pa_StopStream( stream ); + if( err != paNoError ) goto error; + Pa_Terminate(); + printf("Test finished.\n"); + return err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_leftright.c b/pd/portaudio_v18/pa_tests/patest_leftright.c new file mode 100644 index 00000000..6e6172ac --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_leftright.c @@ -0,0 +1,168 @@ +/* + * $Id: patest_leftright.c,v 1.2 2002/02/22 21:46:18 philburk Exp $ + * patest_leftright.c + * Play different tone sine waves that alternate between left and right channel. + * The low tone should be on the left channel. + * + * Authors: + * Ross Bencina <rossb@audiomulch.com> + * Phil Burk <philburk@softsynth.com> + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.audiomulch.com/portaudio/ + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +#define NUM_SECONDS (8) +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (512) +#ifndef M_PI +#define M_PI (3.14159265) +#endif +#define TABLE_SIZE (200) +typedef struct +{ + float sine[TABLE_SIZE]; + int left_phase; + int right_phase; + int toggle; + int countDown; +} +paTestData; +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + unsigned long i; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + for( i=0; i<framesPerBuffer; i++ ) + { + if( data->toggle ) + { + *out++ = data->sine[data->left_phase]; /* left */ + *out++ = 0; /* right */ + } + else + { + *out++ = 0; /* left */ + *out++ = data->sine[data->right_phase]; /* right */ + } + + data->left_phase += 1; + if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE; + data->right_phase += 3; /* higher pitch so we can distinguish left and right. */ + if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE; + } + + if( data->countDown < 0 ) + { + data->countDown = SAMPLE_RATE; + data->toggle = !data->toggle; + } + data->countDown -= framesPerBuffer; + + return finished; +} + +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int i; + int timeout; + + printf("Play different tone sine waves that alternate between left and right channel.\n"); + printf("The low tone should be on the left channel.\n"); + + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. ); + } + data.left_phase = data.right_phase = data.toggle = 0; + data.countDown = SAMPLE_RATE; + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + + err = Pa_OpenStream( + &stream, + paNoDevice,/* default input device */ + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + Pa_GetDefaultOutputDeviceID(), /* default output device */ + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + + printf("Play for several seconds.\n"); + timeout = NUM_SECONDS * 4; + while( timeout > 0 ) + { + Pa_Sleep( 300 ); + timeout -= 1; + } + + 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 err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_longsine.c b/pd/portaudio_v18/pa_tests/patest_longsine.c new file mode 100644 index 00000000..7dc8ae56 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_longsine.c @@ -0,0 +1,137 @@ +/* + * $Id: patest_longsine.c,v 1.2 2002/04/30 21:21:30 philburk Exp $ + * patest_longsine.c + * Play a sine wave using the Portable Audio api until ENTER hit. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" + +#define SAMPLE_RATE (44100) + +#ifndef M_PI +#define M_PI (3.14159265) +#endif + +#define TABLE_SIZE (200) +typedef struct +{ + float sine[TABLE_SIZE]; + int left_phase; + int right_phase; +} +paTestData; + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + unsigned int i; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + for( i=0; i<framesPerBuffer; i++ ) + { + *out++ = data->sine[data->left_phase]; /* left */ + *out++ = data->sine[data->right_phase]; /* right */ + data->left_phase += 1; + if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE; + data->right_phase += 3; /* higher pitch so we can distinguish left and right. */ + if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE; + } + return 0; +} + +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int i; + printf("PortAudio Test: output sine wave.\n"); + + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. ); + } + data.left_phase = data.right_phase = 0; + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + + err = Pa_OpenStream( + &stream, + paNoDevice,/* default input device */ + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + Pa_GetDefaultOutputDeviceID(), /* default output device */ + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + 256, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + + printf("Hit ENTER to stop program.\n"); + getchar(); + + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + Pa_Terminate(); + + printf("Test finished.\n"); + return err; + +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_many.c b/pd/portaudio_v18/pa_tests/patest_many.c new file mode 100644 index 00000000..99f12ec8 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_many.c @@ -0,0 +1,195 @@ +/* + * $Id: patest_many.c,v 1.1.1.1.4.1 2003/02/11 21:41:32 philburk Exp $ + * patest_many.c + * Start and stop the PortAudio Driver multiple times. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include "portaudio.h" +#define NUM_SECONDS (1) +#define SAMPLE_RATE (44100) +#ifndef M_PI +#define M_PI (3.14159265) +#endif +#define TABLE_SIZE (200) +typedef struct +{ + short sine[TABLE_SIZE]; + int left_phase; + int right_phase; + unsigned int sampsToGo; +} +paTestData; +PaError TestOnce( void ); +static int patest1Callback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ); +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patest1Callback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + short *out = (short*)outputBuffer; + unsigned int i; + int finished = 0; + (void) inputBuffer; /* Prevent "unused variable" warnings. */ + (void) outTime; + + if( data->sampsToGo < framesPerBuffer ) + { + /* final buffer... */ + + for( i=0; i<data->sampsToGo; i++ ) + { + *out++ = data->sine[data->left_phase]; /* left */ + *out++ = data->sine[data->right_phase]; /* right */ + data->left_phase += 1; + if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE; + data->right_phase += 3; /* higher pitch so we can distinguish left and right. */ + if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE; + } + /* zero remainder of final buffer */ + for( ; i<framesPerBuffer; i++ ) + { + *out++ = 0; /* left */ + *out++ = 0; /* right */ + } + + finished = 1; + } + else + { + for( i=0; i<framesPerBuffer; i++ ) + { + *out++ = data->sine[data->left_phase]; /* left */ + *out++ = data->sine[data->right_phase]; /* right */ + data->left_phase += 1; + if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE; + data->right_phase += 3; /* higher pitch so we can distinguish left and right. */ + if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE; + } + data->sampsToGo -= framesPerBuffer; + } + return finished; +} +/*******************************************************************/ +#ifdef MACINTOSH +int main(void); +int main(void) +{ + int i; + PaError err; + int numLoops = 10; + printf("Loop %d times.\n", numLoops ); + for( i=0; i<numLoops; i++ ) + { + printf("Loop %d out of %d.\n", i+1, numLoops ); + err = TestOnce(); + if( err < 0 ) return 0; + } +} +#else +int main(int argc, char **argv); +int main(int argc, char **argv) +{ + PaError err; + int i, numLoops = 10; + if( argc > 1 ) + { + numLoops = atoi(argv[1]); + } + for( i=0; i<numLoops; i++ ) + { + printf("Loop %d out of %d.\n", i+1, numLoops ); + err = TestOnce(); + if( err < 0 ) return 1; + } + printf("Test complete.\n"); + return 0; +} +#endif +PaError TestOnce( void ) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int i; + int totalSamps; + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + data.sine[i] = (short) (32767.0 * sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. )); + } + data.left_phase = data.right_phase = 0; + data.sampsToGo = totalSamps = NUM_SECONDS * SAMPLE_RATE; /* Play for a few seconds. */ + err = Pa_Initialize(); + if( err != paNoError ) goto error; + err = Pa_OpenStream( + &stream, + paNoDevice,/* default input device */ + 0, /* no input */ + paInt16, /* sample format */ + NULL, + Pa_GetDefaultOutputDeviceID(), /* default output device */ + 2, /* stereo output */ + paInt16, /* sample format */ + NULL, + SAMPLE_RATE, + 1024, /* frames per buffer */ + 8, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patest1Callback, + &data ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + printf("Waiting for sound to finish.\n"); + fflush(stdout); + Pa_Sleep(1000); + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + Pa_Terminate(); + return paNoError; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_maxsines.c b/pd/portaudio_v18/pa_tests/patest_maxsines.c new file mode 100644 index 00000000..e352715f --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_maxsines.c @@ -0,0 +1,201 @@ +/* + * $Id: patest_maxsines.c,v 1.4.4.1 2003/04/10 23:09:40 philburk Exp $ + * patest_maxsines.c + * How many sine waves can we calculate and play in less than 80% CPU Load. + * + * Authors: + * Ross Bencina <rossb@audiomulch.com> + * Phil Burk <philburk@softsynth.com> + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.audiomulch.com/portaudio/ + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" + +#define MAX_SINES (500) +#define MAX_USAGE (0.8) +#define SAMPLE_RATE (44100) +#define FREQ_TO_PHASE_INC(freq) (freq/(float)SAMPLE_RATE) + +#define MIN_PHASE_INC FREQ_TO_PHASE_INC(200.0f) +#define MAX_PHASE_INC (MIN_PHASE_INC * (1 << 5)) + +#define FRAMES_PER_BUFFER (512) +#ifndef M_PI +#define M_PI (3.14159265) +#endif +#define TWOPI (M_PI * 2.0) + +#define TABLE_SIZE (512) + +typedef struct paTestData +{ + int numSines; + float sine[TABLE_SIZE + 1]; /* add one for guard point for interpolation */ + float phases[MAX_SINES]; +} +paTestData; + +/* Convert phase between and 1.0 to sine value + * using linear interpolation. + */ +float LookupSine( paTestData *data, float phase ); +float LookupSine( paTestData *data, float phase ) +{ + float fIndex = phase*TABLE_SIZE; + int index = (int) fIndex; + float fract = fIndex - index; + float lo = data->sine[index]; + float hi = data->sine[index+1]; + float val = lo + fract*(hi-lo); + return val; +} + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + float outSample; + float scaler; + int numForScale; + unsigned long i; + int j; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + +/* Detemine amplitude scaling factor */ + numForScale = data->numSines; + if( numForScale < 8 ) numForScale = 8; /* prevent pops at beginning */ + scaler = 1.0f / numForScale; + + for( i=0; i<framesPerBuffer; i++ ) + { + float output = 0.0; + float phaseInc = MIN_PHASE_INC; + float phase; + for( j=0; j<data->numSines; j++ ) + { + /* Advance phase of next oscillator. */ + phase = data->phases[j]; + phase += phaseInc; + if( phase >= 1.0 ) phase -= 1.0; + + output += LookupSine(data, phase); + data->phases[j] = phase; + + phaseInc *= 1.02f; + if( phaseInc > MAX_PHASE_INC ) phaseInc = MIN_PHASE_INC; + } + + outSample = (float) (output * scaler); + *out++ = outSample; /* Left */ + *out++ = outSample; /* Right */ + } + return finished; +} + +/*******************************************************************/ +int main(void); +int main(void) +{ + int i; + PortAudioStream *stream; + PaError err; + paTestData data = {0}; + double load; + printf("PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER); + + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. ); + } + data.sine[TABLE_SIZE] = data.sine[0]; /* set guard point */ + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + err = Pa_OpenStream( + &stream, + paNoDevice, + 0, /* no input */ + paFloat32, + NULL, + Pa_GetDefaultOutputDeviceID(), /* default output device */ + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + +/* Play an increasing number of sine waves until we hit MAX_USAGE */ + do + { + data.numSines++; + Pa_Sleep( 200 ); + + load = Pa_GetCPULoad( stream ); + printf("numSines = %d, CPU load = %f\n", data.numSines, load ); + fflush( stdout ); + } + while( (load < MAX_USAGE) && (data.numSines < MAX_SINES) ); + + printf("Press ENTER to stop.\n" ); fflush(stdout); + getchar(); + + printf("CPU load = %f\n", Pa_GetCPULoad( stream ) ); + err = Pa_StopStream( stream ); + if( err != paNoError ) goto error; + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + Pa_Terminate(); + printf("Test finished.\n"); + fflush( stdout ); + return err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_mono.c b/pd/portaudio_v18/pa_tests/patest_mono.c new file mode 100644 index 00000000..18682b5d --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_mono.c @@ -0,0 +1,136 @@ +/* + * $Id: patest_mono.c,v 1.1.2.3 2003/04/10 23:09:40 philburk Exp $ + * patest_sine.c + * Play a monophonic sine wave using the Portable Audio api for several seconds. + * + * Authors: + * Ross Bencina <rossb@audiomulch.com> + * Phil Burk <philburk@softsynth.com> + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.audiomulch.com/portaudio/ + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" + +#define NUM_SECONDS (10) +#define SAMPLE_RATE (44100) +#define AMPLITUDE (0.8) +#define FRAMES_PER_BUFFER (64) +#define OUTPUT_DEVICE Pa_GetDefaultOutputDeviceID() + +#ifndef M_PI +#define M_PI (3.14159265) +#endif + +#define TABLE_SIZE (200) +typedef struct +{ + float sine[TABLE_SIZE]; + int phase; +} +paTestData; + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + unsigned long i; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + for( i=0; i<framesPerBuffer; i++ ) + { + *out++ = data->sine[data->phase]; /* left */ + data->phase += 1; + if( data->phase >= TABLE_SIZE ) data->phase -= TABLE_SIZE; + } + return finished; +} + +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int i; + printf("PortAudio Test: output MONO sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER); + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + data.sine[i] = (float) (AMPLITUDE * sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. )); + } + data.phase = 0; + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + err = Pa_OpenStream( + &stream, + paNoDevice,/* default input device */ + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + OUTPUT_DEVICE, + 1, /* MONO output */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + printf("Play for %d seconds.\n", NUM_SECONDS ); fflush(stdout); + 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 err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_multi_sine.c b/pd/portaudio_v18/pa_tests/patest_multi_sine.c new file mode 100644 index 00000000..d005287a --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_multi_sine.c @@ -0,0 +1,144 @@ +/* + * $Id: patest_multi_sine.c,v 1.1.4.2 2003/02/13 18:05:30 philburk Exp $ + * patest_multi_out.c + * Play a different sine wave on each channels, + * using the Portable Audio api. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" + +#define OUTPUT_DEVICE (Pa_GetDefaultOutputDeviceID()) +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (256) +#define FREQ_INCR (300.0 / SAMPLE_RATE) +#define MAX_CHANNELS (64) + +#ifndef M_PI +#define M_PI (3.14159265) +#endif + +typedef struct +{ + int numChannels; + double phases[MAX_CHANNELS]; +} +paTestData; + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + int frameIndex, channelIndex; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + for( frameIndex=0; frameIndex<(int)framesPerBuffer; frameIndex++ ) + { + for( channelIndex=0; channelIndex<data->numChannels; channelIndex++ ) + { + /* Output sine wave on every channel. */ + *out++ = (float) (0.7 * sin(data->phases[channelIndex])); + + /* Play each channel at a higher frequency. */ + data->phases[channelIndex] += FREQ_INCR * (4 + channelIndex); + if( data->phases[channelIndex] >= (2.0 * M_PI) ) data->phases[channelIndex] -= (2.0 * M_PI); + } + } + + return 0; +} + +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + const PaDeviceInfo *pdi; + paTestData data = {0}; + printf("PortAudio Test: output sine wave on each channel.\n" ); + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + + pdi = Pa_GetDeviceInfo( OUTPUT_DEVICE ); + data.numChannels = pdi->maxOutputChannels; + if( data.numChannels > MAX_CHANNELS ) data.numChannels = MAX_CHANNELS; + printf("Number of Channels = %d\n", data.numChannels ); + + err = Pa_OpenStream( + &stream, + paNoDevice, /* default input device */ + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + OUTPUT_DEVICE, + data.numChannels, + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + + printf("Hit ENTER to stop sound.\n"); + fflush(stdout); + getchar(); + + err = Pa_StopStream( stream ); + if( err != paNoError ) goto error; + + Pa_CloseStream( stream ); + Pa_Terminate(); + printf("Test finished.\n"); + return err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_pink.c b/pd/portaudio_v18/pa_tests/patest_pink.c new file mode 100644 index 00000000..f3bfdadb --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_pink.c @@ -0,0 +1,245 @@ +/* + * $Id: patest_pink.c,v 1.1.1.1 2002/01/22 00:52:36 phil Exp $ + patest_pink.c + Generate Pink Noise using Gardner method. + Optimization suggested by James McCartney uses a tree + to select which random value to replace. + x x x x x x x x x x x x x x x x + x x x x x x x x + x x x x + x x + x + Tree is generated by counting trailing zeros in an increasing index. + When the index is zero, no random number is selected. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +#define PINK_MAX_RANDOM_ROWS (30) +#define PINK_RANDOM_BITS (24) +#define PINK_RANDOM_SHIFT ((sizeof(long)*8)-PINK_RANDOM_BITS) +typedef struct +{ + long pink_Rows[PINK_MAX_RANDOM_ROWS]; + long pink_RunningSum; /* Used to optimize summing of generators. */ + int pink_Index; /* Incremented each sample. */ + int pink_IndexMask; /* Index wrapped by ANDing with this mask. */ + float pink_Scalar; /* Used to scale within range of -1.0 to +1.0 */ +} +PinkNoise; +/* Prototypes */ +static unsigned long GenerateRandomNumber( void ); +void InitializePinkNoise( PinkNoise *pink, int numRows ); +float GeneratePinkNoise( PinkNoise *pink ); +/************************************************************/ +/* Calculate pseudo-random 32 bit number based on linear congruential method. */ +static unsigned long GenerateRandomNumber( void ) +{ + /* Change this seed for different random sequences. */ + static unsigned long randSeed = 22222; + randSeed = (randSeed * 196314165) + 907633515; + return randSeed; +} +/************************************************************/ +/* Setup PinkNoise structure for N rows of generators. */ +void InitializePinkNoise( PinkNoise *pink, int numRows ) +{ + int i; + long pmax; + pink->pink_Index = 0; + pink->pink_IndexMask = (1<<numRows) - 1; + /* Calculate maximum possible signed random value. Extra 1 for white noise always added. */ + pmax = (numRows + 1) * (1<<(PINK_RANDOM_BITS-1)); + pink->pink_Scalar = 1.0f / pmax; + /* Initialize rows. */ + for( i=0; i<numRows; i++ ) pink->pink_Rows[i] = 0; + pink->pink_RunningSum = 0; +} +#define PINK_MEASURE +#ifdef PINK_MEASURE +float pinkMax = -999.0; +float pinkMin = 999.0; +#endif +/* Generate Pink noise values between -1.0 and +1.0 */ +float GeneratePinkNoise( PinkNoise *pink ) +{ + long newRandom; + long sum; + float output; + /* Increment and mask index. */ + pink->pink_Index = (pink->pink_Index + 1) & pink->pink_IndexMask; + /* If index is zero, don't update any random values. */ + if( pink->pink_Index != 0 ) + { + /* Determine how many trailing zeros in PinkIndex. */ + /* This algorithm will hang if n==0 so test first. */ + int numZeros = 0; + int n = pink->pink_Index; + while( (n & 1) == 0 ) + { + n = n >> 1; + numZeros++; + } + /* Replace the indexed ROWS random value. + * Subtract and add back to RunningSum instead of adding all the random + * values together. Only one changes each time. + */ + pink->pink_RunningSum -= pink->pink_Rows[numZeros]; + newRandom = ((long)GenerateRandomNumber()) >> PINK_RANDOM_SHIFT; + pink->pink_RunningSum += newRandom; + pink->pink_Rows[numZeros] = newRandom; + } + + /* Add extra white noise value. */ + newRandom = ((long)GenerateRandomNumber()) >> PINK_RANDOM_SHIFT; + sum = pink->pink_RunningSum + newRandom; + /* Scale to range of -1.0 to 0.9999. */ + output = pink->pink_Scalar * sum; +#ifdef PINK_MEASURE + /* Check Min/Max */ + if( output > pinkMax ) pinkMax = output; + else if( output < pinkMin ) pinkMin = output; +#endif + return output; +} +/*******************************************************************/ +#define PINK_TEST +#ifdef PINK_TEST +/* Context for callback routine. */ +typedef struct +{ + PinkNoise leftPink; + PinkNoise rightPink; + unsigned int sampsToGo; +} +paTestData; +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + int finished; + int i; + int numFrames; + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + (void) inputBuffer; /* Prevent "unused variable" warnings. */ + (void) outTime; + + /* Are we almost at end. */ + if( data->sampsToGo < framesPerBuffer ) + { + numFrames = data->sampsToGo; + finished = 1; + } + else + { + numFrames = framesPerBuffer; + finished = 0; + } + for( i=0; i<numFrames; i++ ) + { + *out++ = GeneratePinkNoise( &data->leftPink ); + *out++ = GeneratePinkNoise( &data->rightPink ); + } + data->sampsToGo -= numFrames; + return finished; +} +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int totalSamps; + /* Initialize two pink noise signals with different numbers of rows. */ + InitializePinkNoise( &data.leftPink, 12 ); + InitializePinkNoise( &data.rightPink, 16 ); + /* Look at a few values. */ + { + int i; + float pink; + for( i=0; i<20; i++ ) + { + pink = GeneratePinkNoise( &data.leftPink ); + printf("Pink = %f\n", pink ); + } + } + data.sampsToGo = totalSamps = 8*44100; /* Play for a few seconds. */ + err = Pa_Initialize(); + if( err != paNoError ) goto error; + /* Open a stereo PortAudio stream so we can hear the result. */ + err = Pa_OpenStream( + &stream, + paNoDevice, + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + Pa_GetDefaultOutputDeviceID(), /* default output device */ + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + NULL, + 44100., + 2048, /* 46 msec buffers */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + printf("Waiting for sound to finish.\n"); + while( Pa_StreamActive( stream ) ) + { + Pa_Sleep(100); /* SPIN! */ + } + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; +#ifdef PINK_MEASURE + printf("Pink min = %f, max = %f\n", pinkMin, pinkMax ); +#endif + 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 ) ); + return 0; +} +#endif /* PINK_TEST */ diff --git a/pd/portaudio_v18/pa_tests/patest_record.c b/pd/portaudio_v18/pa_tests/patest_record.c new file mode 100644 index 00000000..f7f79bd3 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_record.c @@ -0,0 +1,325 @@ +/* + * $Id: patest_record.c,v 1.2.4.4 2003/04/16 19:07:56 philburk Exp $ + * patest_record.c + * Record input into an array. + * Optionally save array to a file. + * Playback recorded data. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <stdlib.h> +#include "portaudio.h" + +/* #define SAMPLE_RATE (17932) // Test failure to open with this value. */ +#define SAMPLE_RATE (44100) +#define NUM_SECONDS (5) +#define NUM_CHANNELS (2) +/* #define DITHER_FLAG (paDitherOff) */ +#define DITHER_FLAG (0) /**/ +#define FRAMES_PER_BUFFER (1024) + +/* Select sample format. */ +#if 1 +#define PA_SAMPLE_TYPE paFloat32 +typedef float SAMPLE; +#define SAMPLE_SILENCE (0.0f) +#elif 0 +#define PA_SAMPLE_TYPE paInt16 +typedef short SAMPLE; +#define SAMPLE_SILENCE (0) +#elif 0 +#define PA_SAMPLE_TYPE paInt8 +typedef char SAMPLE; +#define SAMPLE_SILENCE (0) +#else +#define PA_SAMPLE_TYPE paUInt8 +typedef unsigned char SAMPLE; +#define SAMPLE_SILENCE (128) + +#endif + +typedef struct +{ + int frameIndex; /* Index into sample array. */ + int maxFrameIndex; + SAMPLE *recordedSamples; +} +paTestData; +/* This routine will be called by the PortAudio engine when audio is needed. +** It may be called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int recordCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + SAMPLE *rptr = (SAMPLE*)inputBuffer; + SAMPLE *wptr = &data->recordedSamples[data->frameIndex * NUM_CHANNELS]; + long framesToRecord; + long i; + int finished; + unsigned long framesLeft = data->maxFrameIndex - data->frameIndex; + int samplesToRecord; + + (void) outputBuffer; /* Prevent unused variable warnings. */ + (void) outTime; + + if( framesLeft < framesPerBuffer ) + { + framesToRecord = framesLeft; + finished = 1; + } + else + { + framesToRecord = framesPerBuffer; + finished = 0; + } + + samplesToRecord = framesToRecord * NUM_CHANNELS; + + if( inputBuffer == NULL ) + { + for( i=0; i<samplesToRecord; i++ ) + { + *wptr++ = SAMPLE_SILENCE; + } + } + else + { + for( i=0; i<samplesToRecord; i++ ) + { + *wptr++ = *rptr++; + } + } + data->frameIndex += framesToRecord; + return finished; +} + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may be called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int playCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + SAMPLE *rptr = &data->recordedSamples[data->frameIndex * NUM_CHANNELS]; + SAMPLE *wptr = (SAMPLE*)outputBuffer; + unsigned int i; + int finished; + unsigned int framesLeft = data->maxFrameIndex - data->frameIndex; + (void) inputBuffer; /* Prevent unused variable warnings. */ + (void) outTime; + int framesToPlay, samplesToPlay, samplesPerBuffer; + + if( framesLeft < framesPerBuffer ) + { + framesToPlay = framesLeft; + finished = 1; + } + else + { + framesToPlay = framesPerBuffer; + finished = 0; + } + + samplesToPlay = framesToPlay * NUM_CHANNELS; + samplesPerBuffer = framesPerBuffer * NUM_CHANNELS; + + for( i=0; i<samplesToPlay; i++ ) + { + *wptr++ = *rptr++; + } + for( ; i<framesPerBuffer; i++ ) + { + *wptr++ = 0; /* left */ + if( NUM_CHANNELS == 2 ) *wptr++ = 0; /* right */ + } + data->frameIndex += framesToPlay; + + return finished; +} + +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int i; + int totalFrames; + int numSamples; + int numBytes; + SAMPLE max, average, val; + printf("patest_record.c\n"); fflush(stdout); + + data.maxFrameIndex = totalFrames = NUM_SECONDS * SAMPLE_RATE; /* Record for a few seconds. */ + data.frameIndex = 0; + numSamples = totalFrames * NUM_CHANNELS; + + numBytes = numSamples * sizeof(SAMPLE); + data.recordedSamples = (SAMPLE *) malloc( numBytes ); + if( data.recordedSamples == NULL ) + { + printf("Could not allocate record array.\n"); + exit(1); + } + for( i=0; i<numSamples; i++ ) data.recordedSamples[i] = 0; + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + + /* Record some audio. -------------------------------------------- */ + err = Pa_OpenStream( + &stream, + Pa_GetDefaultInputDeviceID(), + NUM_CHANNELS, + PA_SAMPLE_TYPE, + NULL, + paNoDevice, + 0, + PA_SAMPLE_TYPE, + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + 0, /* paDitherOff, // flags */ + recordCallback, + &data ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + printf("Now recording!!\n"); fflush(stdout); + + while( Pa_StreamActive( stream ) ) + { + Pa_Sleep(1000); + printf("index = %d\n", data.frameIndex ); fflush(stdout); + } + + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + + /* Measure maximum peak amplitude. */ + max = 0; + average = 0; + for( i=0; i<numSamples; i++ ) + { + val = data.recordedSamples[i]; + if( val < 0 ) val = -val; /* ABS */ + if( val > max ) + { + max = val; + } + average += val; + } + + average = average / numSamples; + + if( PA_SAMPLE_TYPE == paFloat32 ) /* This should be done at compile-time with "#if" ?? */ + { /* MIPS-compiler warns at the int-version below. */ + printf("sample max amplitude = %f\n", max ); + printf("sample average = %f\n", average ); + } + else + { + printf("sample max amplitude = %d\n", max ); /* <-- This IS compiled anyhow. */ + printf("sample average = %d\n", average ); + } + + /* Write recorded data to a file. */ +#if 0 + { + FILE *fid; + fid = fopen("recorded.raw", "wb"); + if( fid == NULL ) + { + printf("Could not open file."); + } + else + { + fwrite( data.recordedSamples, NUM_CHANNELS * sizeof(SAMPLE), totalFrames, fid ); + fclose( fid ); + printf("Wrote data to 'recorded.raw'\n"); + } + } +#endif + + /* Playback recorded data. -------------------------------------------- */ + data.frameIndex = 0; + printf("Begin playback.\n"); fflush(stdout); + err = Pa_OpenStream( + &stream, + paNoDevice, + 0, /* NO input */ + PA_SAMPLE_TYPE, + NULL, + Pa_GetDefaultOutputDeviceID(), + NUM_CHANNELS, + PA_SAMPLE_TYPE, + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + playCallback, + &data ); + if( err != paNoError ) goto error; + + if( stream ) + { + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + printf("Waiting for playback to finish.\n"); fflush(stdout); + + while( Pa_StreamActive( stream ) ) Pa_Sleep(100); + + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + printf("Done.\n"); fflush(stdout); + } + free( data.recordedSamples ); + + 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 ) ); + return -1; +} diff --git a/pd/portaudio_v18/pa_tests/patest_ringmix.c b/pd/portaudio_v18/pa_tests/patest_ringmix.c new file mode 100644 index 00000000..9d78ea13 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_ringmix.c @@ -0,0 +1,41 @@ +/* $Id: patest_ringmix.c,v 1.1.1.1 2002/01/22 00:52:37 phil Exp $ */ + +#include "stdio.h" +#include "portaudio.h" +/* This will be called asynchronously by the PortAudio engine. */ +static int myCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, PaTimestamp outTime, void *userData ) +{ + float *out = (float *) outputBuffer; + float *in = (float *) inputBuffer; + float leftInput, rightInput; + unsigned int i; + if( inputBuffer == NULL ) return 0; + /* Read input buffer, process data, and fill output buffer. */ + for( i=0; i<framesPerBuffer; i++ ) + { + leftInput = *in++; /* Get interleaved samples from input buffer. */ + rightInput = *in++; + *out++ = leftInput * rightInput; /* ring modulation */ + *out++ = 0.5f * (leftInput + rightInput); /* mix */ + } + return 0; +} +/* Open a PortAudioStream to input and output audio data. */ +int main(void) +{ + PortAudioStream *stream; + Pa_Initialize(); + Pa_OpenDefaultStream( + &stream, + 2, 2, /* stereo input and output */ + paFloat32, 44100.0, + 64, 0, /* 64 frames per buffer, let PA determine numBuffers */ + myCallback, NULL ); + Pa_StartStream( stream ); + Pa_Sleep( 10000 ); /* Sleep for 10 seconds while processing. */ + Pa_StopStream( stream ); + Pa_CloseStream( stream ); + Pa_Terminate(); + return 0; +} diff --git a/pd/portaudio_v18/pa_tests/patest_saw.c b/pd/portaudio_v18/pa_tests/patest_saw.c new file mode 100644 index 00000000..187db354 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_saw.c @@ -0,0 +1,118 @@ +/* + * $Id: patest_saw.c,v 1.1.1.1 2002/01/22 00:52:38 phil Exp $ + * patest_saw.c + * Play a simple sawtooth wave. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +#define NUM_SECONDS (4) +#define SAMPLE_RATE (44100) +typedef struct +{ + float left_phase; + float right_phase; +} +paTestData; +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + /* Cast data passed through stream to our structure. */ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + unsigned int i; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + for( i=0; i<framesPerBuffer; i++ ) + { + *out++ = data->left_phase; /* left */ + *out++ = data->right_phase; /* right */ + /* Generate simple sawtooth phaser that ranges between -1.0 and 1.0. */ + data->left_phase += 0.01f; + /* When signal reaches top, drop back down. */ + if( data->left_phase >= 1.0f ) data->left_phase -= 2.0f; + /* higher pitch so we can distinguish left and right. */ + data->right_phase += 0.03f; + if( data->right_phase >= 1.0f ) data->right_phase -= 2.0f; + } + return 0; +} +/*******************************************************************/ +static paTestData data; +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + 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 */ + 0, /* number of buffers, if zero then use default minimum */ + 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 err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_sine.c b/pd/portaudio_v18/pa_tests/patest_sine.c new file mode 100644 index 00000000..162fac02 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_sine.c @@ -0,0 +1,141 @@ +/* + * $Id: patest_sine.c,v 1.2.4.1 2003/02/11 21:41:32 philburk Exp $ + * patest_sine.c + * Play a sine wave using the Portable Audio api for several seconds. + * + * Authors: + * Ross Bencina <rossb@audiomulch.com> + * Phil Burk <philburk@softsynth.com> + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.audiomulch.com/portaudio/ + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" + +#define NUM_SECONDS (10) +#define SAMPLE_RATE (44100) +#define AMPLITUDE (0.9) +#define FRAMES_PER_BUFFER (64) +#define OUTPUT_DEVICE Pa_GetDefaultOutputDeviceID() +//#define OUTPUT_DEVICE (2) + +#ifndef M_PI +#define M_PI (3.14159265) +#endif + +#define TABLE_SIZE (200) +typedef struct +{ + float sine[TABLE_SIZE]; + int left_phase; + int right_phase; +} +paTestData; + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + unsigned long i; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + for( i=0; i<framesPerBuffer; i++ ) + { + *out++ = data->sine[data->left_phase]; /* left */ + *out++ = data->sine[data->right_phase]; /* right */ + data->left_phase += 1; + if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE; + data->right_phase += 3; /* higher pitch so we can distinguish left and right. */ + if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE; + } + return finished; +} + +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int i; + printf("PortAudio Test: output sine wave. SR = %d, BufSize = %d, devID = %d\n", + SAMPLE_RATE, FRAMES_PER_BUFFER, OUTPUT_DEVICE); + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + data.sine[i] = (float) (AMPLITUDE * sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. )); + } + data.left_phase = data.right_phase = 0; + err = Pa_Initialize(); + if( err != paNoError ) goto error; + err = Pa_OpenStream( + &stream, + paNoDevice,/* default input device */ + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + OUTPUT_DEVICE, + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + printf("Play for %d seconds.\n", NUM_SECONDS ); fflush(stdout); + 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 err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_sine8.c b/pd/portaudio_v18/pa_tests/patest_sine8.c new file mode 100644 index 00000000..36cf863a --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_sine8.c @@ -0,0 +1,184 @@ +/* + * $Id: patest_sine8.c,v 1.1.1.1 2002/01/22 00:52:38 phil Exp $ + * patest_sine8.c + * Play a sine wave using the Portable Audio api for several seconds. + * Test 8 bit data. + * + * Author: Ross Bencina <rossb@audiomulch.com> + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.audiomulch.com/portaudio/ + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +#define NUM_SECONDS (8) +#define SAMPLE_RATE (44100) +#define TEST_UNSIGNED (1) +#if TEST_UNSIGNED +#define TEST_FORMAT paUInt8 +#else +#define TEST_FORMAT paInt8 +#endif +#ifndef M_PI +#define M_PI (3.14159265) +#endif +#define TABLE_SIZE (200) +typedef struct +{ +#if TEST_UNSIGNED + unsigned char sine[TABLE_SIZE]; +#else + char sine[TABLE_SIZE]; +#endif + int left_phase; + int right_phase; + unsigned int framesToGo; +} +paTestData; +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + char *out = (char*)outputBuffer; + int i; + int framesToCalc; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + if( data->framesToGo < framesPerBuffer ) + { + framesToCalc = data->framesToGo; + data->framesToGo = 0; + finished = 1; + } + else + { + framesToCalc = framesPerBuffer; + data->framesToGo -= framesPerBuffer; + } + + for( i=0; i<framesToCalc; i++ ) + { + *out++ = data->sine[data->left_phase]; /* left */ + *out++ = data->sine[data->right_phase]; /* right */ + data->left_phase += 1; + if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE; + data->right_phase += 3; /* higher pitch so we can distinguish left and right. */ + if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE; + } + /* zero remainder of final buffer */ + for( ; i<(int)framesPerBuffer; i++ ) + { +#if TEST_UNSIGNED + *out++ = (unsigned char) 0x80; /* left */ + *out++ = (unsigned char) 0x80; /* right */ +#else + *out++ = 0; /* left */ + *out++ = 0; /* right */ +#endif + + } + return finished; +} +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int i; + int totalSamps; +#if TEST_UNSIGNED + printf("PortAudio Test: output UNsigned 8 bit sine wave.\n"); +#else + printf("PortAudio Test: output signed 8 bit sine wave.\n"); +#endif + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + data.sine[i] = (char) (127.0 * sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. )); +#if TEST_UNSIGNED + data.sine[i] += (unsigned char) 0x80; +#endif + + } + data.left_phase = data.right_phase = 0; + data.framesToGo = totalSamps = NUM_SECONDS * SAMPLE_RATE; /* Play for a few seconds. */ + err = Pa_Initialize(); + if( err != paNoError ) goto error; + err = Pa_OpenStream( + &stream, + paNoDevice,/* default input device */ + 0, /* no input */ + TEST_FORMAT, + NULL, + Pa_GetDefaultOutputDeviceID(), /* default output device */ + 2, /* stereo output */ + TEST_FORMAT, + NULL, + SAMPLE_RATE, + 256, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + /* Watch until sound is halfway finished. */ + while( Pa_StreamTime( stream ) < (totalSamps/2) ) Pa_Sleep(10); + /* Stop sound until ENTER hit. */ + err = Pa_StopStream( stream ); + if( err != paNoError ) goto error; + printf("Pause for 2 seconds.\n"); + Pa_Sleep( 2000 ); + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + printf("Waiting for sound to finish.\n"); + while( Pa_StreamActive( stream ) ) Pa_Sleep(10); + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + Pa_Terminate(); + printf("Test finished.\n"); + return err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_sine_formats.c b/pd/portaudio_v18/pa_tests/patest_sine_formats.c new file mode 100644 index 00000000..6be0708b --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_sine_formats.c @@ -0,0 +1,203 @@ +/* + * $Id: patest_sine_formats.c,v 1.2.4.2 2003/02/12 01:39:29 philburk Exp $ + * patest_sine_formats.c + * Play a sine wave using the Portable Audio api for several seconds. + * Test various data formats. + * + * Author: Phil Burk + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.audiomulch.com/portaudio/ + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" + +#define NUM_SECONDS (5) +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (512) +#define LEFT_FREQ ((2 * SAMPLE_RATE)/FRAMES_PER_BUFFER) /* So we hit 1.0 */ +#define RIGHT_FREQ (500.0) +#define AMPLITUDE (0.9) + +/* Select ONE format for testing. */ +#define TEST_UINT8 (0) +#define TEST_INT8 (0) +#define TEST_INT16 (0) +#define TEST_INT32 (1) +#define TEST_FLOAT32 (0) + +#if TEST_UINT8 +#define TEST_FORMAT paUInt8 +typedef unsigned char SAMPLE_t; +#define SAMPLE_ZERO (0x80) +#define DOUBLE_TO_SAMPLE(x) (SAMPLE_ZERO + (SAMPLE_t)(127.0 * (x))) +#define FORMAT_NAME "Unsigned 8 Bit" + +#elif TEST_INT8 +#define TEST_FORMAT paInt8 +typedef char SAMPLE_t; +#define SAMPLE_ZERO (0) +#define DOUBLE_TO_SAMPLE(x) (SAMPLE_ZERO + (SAMPLE_t)(127.0 * (x))) +#define FORMAT_NAME "Signed 8 Bit" + +#elif TEST_INT16 +#define TEST_FORMAT paInt16 +typedef short SAMPLE_t; +#define SAMPLE_ZERO (0) +#define DOUBLE_TO_SAMPLE(x) (SAMPLE_ZERO + (SAMPLE_t)(32767 * (x))) +#define FORMAT_NAME "Signed 16 Bit" + +#elif TEST_INT32 +#define TEST_FORMAT paInt32 +typedef long SAMPLE_t; +#define SAMPLE_ZERO (0) +#define DOUBLE_TO_SAMPLE(x) (SAMPLE_ZERO + (SAMPLE_t)(0x7FFFFFFF * (x))) +#define FORMAT_NAME "Signed 32 Bit" + +#elif TEST_FLOAT32 +#define TEST_FORMAT paFloat32 +typedef float SAMPLE_t; +#define SAMPLE_ZERO (0.0) +#define DOUBLE_TO_SAMPLE(x) ((SAMPLE_t)(x)) +#define FORMAT_NAME "Float 32 Bit" +#endif + +#ifndef M_PI +#define M_PI (3.14159265) +#endif + + +typedef struct +{ + double left_phase; + double right_phase; + unsigned int framesToGo; +} +paTestData; +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + SAMPLE_t *out = (SAMPLE_t *)outputBuffer; + int i; + int framesToCalc; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + if( data->framesToGo < framesPerBuffer ) + { + framesToCalc = data->framesToGo; + data->framesToGo = 0; + finished = 1; + } + else + { + framesToCalc = framesPerBuffer; + data->framesToGo -= framesPerBuffer; + } + + for( i=0; i<framesToCalc; i++ ) + { + data->left_phase += (LEFT_FREQ / SAMPLE_RATE); + if( data->left_phase > 1.0) data->left_phase -= 1.0; + *out++ = DOUBLE_TO_SAMPLE( AMPLITUDE * sin( (data->left_phase * M_PI * 2. ))); + + data->right_phase += (RIGHT_FREQ / SAMPLE_RATE); + if( data->right_phase > 1.0) data->right_phase -= 1.0; + *out++ = DOUBLE_TO_SAMPLE( AMPLITUDE * sin( (data->right_phase * M_PI * 2. ))); + } + /* zero remainder of final buffer */ + for( ; i<(int)framesPerBuffer; i++ ) + { + *out++ = SAMPLE_ZERO; /* left */ + *out++ = SAMPLE_ZERO; /* right */ + } + return finished; +} +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int totalSamps; + + printf("PortAudio Test: output " FORMAT_NAME "\n"); + + + data.left_phase = data.right_phase = 0.0; + data.framesToGo = totalSamps = NUM_SECONDS * SAMPLE_RATE; /* Play for a few seconds. */ + err = Pa_Initialize(); + if( err != paNoError ) goto error; + + err = Pa_OpenStream( + &stream, + paNoDevice,/* default input device */ + 0, /* no input */ + TEST_FORMAT, + NULL, + Pa_GetDefaultOutputDeviceID(), /* default output device */ + 2, /* stereo output */ + TEST_FORMAT, + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + + printf("Waiting %d seconds for sound to finish.\n", NUM_SECONDS ); fflush(stdout); + while( Pa_StreamActive( stream ) ) Pa_Sleep(10); + + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + Pa_Terminate(); + + printf("PortAudio Test Finished: " FORMAT_NAME "\n"); + + return err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_sine_time.c b/pd/portaudio_v18/pa_tests/patest_sine_time.c new file mode 100644 index 00000000..e9bc33da --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_sine_time.c @@ -0,0 +1,205 @@ +/* + * $Id: patest_sine_time.c,v 1.2 2002/03/21 00:58:45 philburk Exp $ + * patest_sine_time.c + * Play a sine wave using the Portable Audio api for several seconds. + * Pausing in the middle. + * use the Pa_StreamTime() and Pa_StreamActive() calls. + * + * Authors: + * Ross Bencina <rossb@audiomulch.com> + * Phil Burk <philburk@softsynth.com> + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.audiomulch.com/portaudio/ + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +#define NUM_SECONDS (8) +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (64) +#define NUM_BUFFERS (0) +#ifndef M_PI +#define M_PI (3.14159265) +#endif +#define TABLE_SIZE (200) +typedef struct +{ + float sine[TABLE_SIZE]; + int left_phase; + int right_phase; + int framesToGo; + volatile PaTimestamp outTime; +} +paTestData; +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + int i; + int framesToCalc; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + data->outTime = outTime; + + if( data->framesToGo < framesPerBuffer ) + { + framesToCalc = data->framesToGo; + data->framesToGo = 0; + finished = 1; + } + else + { + framesToCalc = framesPerBuffer; + data->framesToGo -= framesPerBuffer; + } + + for( i=0; i<framesToCalc; i++ ) + { + *out++ = data->sine[data->left_phase]; /* left */ + *out++ = data->sine[data->right_phase]; /* right */ + data->left_phase += 1; + if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE; + data->right_phase += 3; /* higher pitch so we can distinguish left and right. */ + if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE; + } + /* zero remainder of final buffer */ + for( ; i<(int)framesPerBuffer; i++ ) + { + *out++ = 0; /* left */ + *out++ = 0; /* right */ + } + return finished; +} +/*******************************************************************/ +static void ReportStreamTime( PortAudioStream *stream, paTestData *data ); +static void ReportStreamTime( PortAudioStream *stream, paTestData *data ) +{ + PaTimestamp streamTime, latency, outTime; + + streamTime = Pa_StreamTime( stream ); + outTime = data->outTime; + if( outTime < 0.0 ) + { + printf("Stream time = %8.1f\n", streamTime ); + } + else + { + latency = outTime - streamTime; + printf("Stream time = %8.1f, outTime = %8.1f, latency = %8.1f\n", + streamTime, outTime, latency ); + } + fflush(stdout); +} + +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData DATA; + int i; + int totalSamps; + printf("PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER); + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + DATA.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. ); + } + DATA.left_phase = DATA.right_phase = 0; + DATA.framesToGo = totalSamps = NUM_SECONDS * SAMPLE_RATE; /* Play for a few seconds. */ + err = Pa_Initialize(); + if( err != paNoError ) goto error; + err = Pa_OpenStream( + &stream, + paNoDevice,/* default input device */ + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + Pa_GetDefaultOutputDeviceID(), /* default output device */ + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + NUM_BUFFERS, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &DATA ); + if( err != paNoError ) goto error; + + DATA.outTime = -1.0; // mark time for callback as undefined + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + + /* Watch until sound is halfway finished. */ + printf("Play for %d seconds.\n", NUM_SECONDS/2 ); fflush(stdout); + do + { + ReportStreamTime( stream, &DATA ); + Pa_Sleep(100); + } while( Pa_StreamTime( stream ) < (totalSamps/2) ); + + /* Stop sound until ENTER hit. */ + err = Pa_StopStream( stream ); + if( err != paNoError ) goto error; + printf("Pause for 2 seconds.\n"); fflush(stdout); + Pa_Sleep( 2000 ); + + DATA.outTime = -1.0; // mark time for callback as undefined + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + + printf("Play until sound is finished.\n"); fflush(stdout); + do + { + ReportStreamTime( stream, &DATA ); + Pa_Sleep(100); + } while( Pa_StreamActive( stream ) ); + + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + Pa_Terminate(); + printf("Test finished.\n"); + return err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_stop.c b/pd/portaudio_v18/pa_tests/patest_stop.c new file mode 100644 index 00000000..2fd9895c --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_stop.c @@ -0,0 +1,285 @@ +/* + * $Id: patest_stop.c,v 1.1.1.1 2002/01/22 00:52:39 phil Exp $ + * patest_stop.c + * + * Test the three ways of stopping audio: + * calling Pa_StopStream(), + * calling Pa_AbortStream(), + * and returning a 1 from the callback function. + * + * A long latency is set up so that you can hear the difference. + * Then a simple 8 note sequence is repeated twice. + * The program will print what you should hear. + * + * Author: Phil Burk <philburk@softsynth.com> + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +#define OUTPUT_DEVICE (Pa_GetDefaultOutputDeviceID()) +#define SLEEP_DUR (200) +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (256) +#define LATENCY_MSEC (3000) +#define NUM_BUFFERS ((LATENCY_MSEC * SAMPLE_RATE) / (FRAMES_PER_BUFFER * 1000)) +#define FRAMES_PER_NOTE (SAMPLE_RATE/2) +#define MAX_REPEATS (2) +#define FUNDAMENTAL (400.0f / SAMPLE_RATE) +#define NOTE_0 (FUNDAMENTAL * 1.0f / 1.0f) +#define NOTE_1 (FUNDAMENTAL * 5.0f / 4.0f) +#define NOTE_2 (FUNDAMENTAL * 4.0f / 3.0f) +#define NOTE_3 (FUNDAMENTAL * 3.0f / 2.0f) +#define NOTE_4 (FUNDAMENTAL * 2.0f / 1.0f) +#define MODE_FINISH (0) +#define MODE_STOP (1) +#define MODE_ABORT (2) +#ifndef M_PI +#define M_PI (3.14159265) +#endif +#define TABLE_SIZE (400) +typedef struct +{ + float waveform[TABLE_SIZE + 1]; // add one for guard point for interpolation + float phase_increment; + float phase; + float *tune; + int notesPerTune; + int frameCounter; + int noteCounter; + int repeatCounter; + PaTimestamp outTime; + int stopMode; + int done; +} +paTestData; +/************* Prototypes *****************************/ +int TestStopMode( paTestData *data ); +float LookupWaveform( paTestData *data, float phase ); +/****************************************************** + * Convert phase between 0.0 and 1.0 to waveform value + * using linear interpolation. + */ +float LookupWaveform( paTestData *data, float phase ) +{ + float fIndex = phase*TABLE_SIZE; + int index = (int) fIndex; + float fract = fIndex - index; + float lo = data->waveform[index]; + float hi = data->waveform[index+1]; + float val = lo + fract*(hi-lo); + return val; +} +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + float value; + unsigned int i = 0; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + data->outTime = outTime; + if( !data->done ) + { + for( i=0; i<framesPerBuffer; i++ ) + { + /* Are we done with this note? */ + if( data->frameCounter >= FRAMES_PER_NOTE ) + { + data->noteCounter += 1; + data->frameCounter = 0; + /* Are we done with this tune? */ + if( data->noteCounter >= data->notesPerTune ) + { + data->noteCounter = 0; + data->repeatCounter += 1; + /* Are we totally done? */ + if( data->repeatCounter >= MAX_REPEATS ) + { + data->done = 1; + if( data->stopMode == MODE_FINISH ) + { + finished = 1; + break; + } + } + } + data->phase_increment = data->tune[data->noteCounter]; + } + value = LookupWaveform(data, data->phase); + *out++ = value; /* left */ + *out++ = value; /* right */ + data->phase += data->phase_increment; + if( data->phase >= 1.0f ) data->phase -= 1.0f; + + data->frameCounter += 1; + } + } + /* zero remainder of final buffer */ + for( ; i<framesPerBuffer; i++ ) + { + *out++ = 0; /* left */ + *out++ = 0; /* right */ + } + return finished; +} +/*******************************************************************/ +int main(void); +int main(void) +{ + paTestData DATA; + int i; + float simpleTune[] = { NOTE_0, NOTE_1, NOTE_2, NOTE_3, NOTE_4, NOTE_3, NOTE_2, NOTE_1 }; + printf("PortAudio Test: play song and test stopping. ask for %d buffers\n", NUM_BUFFERS ); + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + DATA.waveform[i] = (float) ( + (0.2 * sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. )) + + (0.2 * sin( ((double)(3*i)/(double)TABLE_SIZE) * M_PI * 2. )) + + (0.1 * sin( ((double)(5*i)/(double)TABLE_SIZE) * M_PI * 2. )) + ); + } + DATA.waveform[TABLE_SIZE] = DATA.waveform[0]; // set guard point + DATA.tune = &simpleTune[0]; + DATA.notesPerTune = sizeof(simpleTune) / sizeof(float); + printf("Test MODE_FINISH - callback returns 1.\n"); + printf("Should hear entire %d note tune repeated twice.\n", DATA.notesPerTune); + DATA.stopMode = MODE_FINISH; + if( TestStopMode( &DATA ) != paNoError ) + { + printf("Test of MODE_FINISH failed!\n"); + goto error; + } + printf("Test MODE_STOP - stop when song is done.\n"); + printf("Should hear entire %d note tune repeated twice.\n", DATA.notesPerTune); + DATA.stopMode = MODE_STOP; + if( TestStopMode( &DATA ) != paNoError ) + { + printf("Test of MODE_STOP failed!\n"); + goto error; + } + + printf("Test MODE_ABORT - abort immediately.\n"); + printf("Should hear last repetition cut short by %d msec.\n", LATENCY_MSEC); + DATA.stopMode = MODE_ABORT; + if( TestStopMode( &DATA ) != paNoError ) + { + printf("Test of MODE_ABORT failed!\n"); + goto error; + } + return 0; +error: + return 1; +} + +int TestStopMode( paTestData *data ) +{ + PortAudioStream *stream; + PaError err; + data->done = 0; + data->phase = 0.0; + data->frameCounter = 0; + data->noteCounter = 0; + data->repeatCounter = 0; + data->phase_increment = data->tune[data->noteCounter]; + err = Pa_Initialize(); + if( err != paNoError ) goto error; + err = Pa_OpenStream( + &stream, + paNoDevice,/* default input device */ + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + OUTPUT_DEVICE, + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + NUM_BUFFERS, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + data ); + if( err != paNoError ) goto error; + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + if( data->stopMode == MODE_FINISH ) + { + while( Pa_StreamActive( stream ) ) + { + /*printf("outTime = %g, note# = %d, repeat# = %d\n", data->outTime, + data->noteCounter, data->repeatCounter ); + fflush(stdout); /**/ + Pa_Sleep( SLEEP_DUR ); + } + } + else + { + while( data->repeatCounter < MAX_REPEATS ) + { + /*printf("outTime = %g, note# = %d, repeat# = %d\n", data->outTime, + data->noteCounter, data->repeatCounter ); + fflush(stdout); /**/ + Pa_Sleep( SLEEP_DUR ); + } + } + if( data->stopMode == MODE_ABORT ) + { + printf("Call Pa_AbortStream()\n"); + err = Pa_AbortStream( stream ); + } + else + { + printf("Call Pa_StopStream()\n"); + err = Pa_StopStream( stream ); + } + if( err != paNoError ) goto error; + printf("Call Pa_CloseStream()\n"); fflush(stdout); + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + Pa_Terminate(); + printf("Test finished.\n"); + return err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_sync.c b/pd/portaudio_v18/pa_tests/patest_sync.c new file mode 100644 index 00000000..c70fbb35 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_sync.c @@ -0,0 +1,227 @@ +/* + * $Id: patest_sync.c,v 1.1.1.1 2002/01/22 00:52:40 phil Exp $ + * patest_sync.c + * Test time stamping and synchronization of audio and video. + * A high latency is used so we can hear the difference in time. + * Random durations are used so we know we are hearing the right beep + * and not the one before or after. + * + * Sequence of events: + * Foreground requests a beep. + * Background randomly schedules a beep. + * Foreground waits for the beep to be heard based on Pa_StreamTime(). + * Foreground outputs video (printf) in sync with audio. + * Repeat. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" +#define NUM_BEEPS (6) +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (256) +#define BEEP_DURATION (1000) +#define LATENCY_MSEC (2000) +#define SLEEP_MSEC (10) +#define TIMEOUT_MSEC ((3 * LATENCY_MSEC) / (2 * SLEEP_MSEC)) +#define NUM_BUFFERS ((LATENCY_MSEC * SAMPLE_RATE) / (FRAMES_PER_BUFFER * 1000)) +#define STATE_BKG_IDLE (0) +#define STATE_BKG_PENDING (1) +#define STATE_BKG_BEEPING (2) +typedef struct +{ + float left_phase; + float right_phase; + int state; + int requestBeep; /* Set by foreground, cleared by background. */ + PaTimestamp beepTime; + int beepCount; +} +paTestData; +static unsigned long GenerateRandomNumber( void ); +/************************************************************/ +/* Calculate pseudo-random 32 bit number based on linear congruential method. */ +static unsigned long GenerateRandomNumber( void ) +{ + static unsigned long randSeed = 22222; /* Change this for different random sequences. */ + randSeed = (randSeed * 196314165) + 907633515; + return randSeed; +} +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + /* Cast data passed through stream to our structure. */ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + unsigned int i; + (void) inputBuffer; + + for( i=0; i<framesPerBuffer; i++ ) + { + switch( data->state ) + { + case STATE_BKG_IDLE: + /* Schedule beep at some random time in the future. */ + if( data->requestBeep ) + { + int random = GenerateRandomNumber() >> 14; + data->beepTime = outTime + (i + random + (SAMPLE_RATE/4)); + data->state = STATE_BKG_PENDING; + data->requestBeep = 0; + data->left_phase = data->right_phase = 0.0; + } + *out++ = 0.0; /* left */ + *out++ = 0.0; /* right */ + break; + case STATE_BKG_PENDING: + if( (outTime + i) >= data->beepTime ) + { + data->state = STATE_BKG_BEEPING; + data->beepCount = BEEP_DURATION; + } + *out++ = 0.0; /* left */ + *out++ = 0.0; /* right */ + break; + case STATE_BKG_BEEPING: + if( data->beepCount <= 0 ) + { + data->state = STATE_BKG_IDLE; + *out++ = 0.0; /* left */ + *out++ = 0.0; /* right */ + } + else + { + /* Play sawtooth wave. */ + *out++ = data->left_phase; /* left */ + *out++ = data->right_phase; /* right */ + /* Generate simple sawtooth phaser that ranges between -1.0 and 1.0. */ + data->left_phase += 0.01f; + /* When signal reaches top, drop back down. */ + if( data->left_phase >= 1.0f ) data->left_phase -= 2.0f; + /* higher pitch so we can distinguish left and right. */ + data->right_phase += 0.03f; + if( data->right_phase >= 1.0f ) data->right_phase -= 2.0f; + } + data->beepCount -= 1; + break; + default: + data->state = STATE_BKG_IDLE; + break; + } + } + return 0; +} +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData DATA; + int i, timeout; + PaTimestamp previousTime; + printf("PortAudio Test: you should see BEEP at the same time you hear it.\n"); + printf("Wait for a few seconds random delay between BEEPs.\n"); + printf("BEEP %d times.\n", NUM_BEEPS ); + /* Initialize our DATA for use by callback. */ + DATA.left_phase = DATA.right_phase = 0.0; + DATA.state = STATE_BKG_IDLE; + DATA.requestBeep = 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, + FRAMES_PER_BUFFER, + NUM_BUFFERS, + patestCallback, + &DATA ); + if( err != paNoError ) goto error; + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + previousTime = Pa_StreamTime( stream ); + for( i=0; i<NUM_BEEPS; i++ ) + { + /* Request a beep from background. */ + DATA.requestBeep = 1; + /* Wait for background to acknowledge request. */ + timeout = TIMEOUT_MSEC; + while( (DATA.requestBeep == 1) && (timeout-- > 0 ) ) Pa_Sleep(SLEEP_MSEC); + if( timeout <= 0 ) + { + fprintf( stderr, "Timed out waiting for background to acknowledge request.\n" ); + goto error; + } + /* Wait for scheduled beep time. */ + timeout = TIMEOUT_MSEC + (10000/SLEEP_MSEC); + while( (Pa_StreamTime( stream ) < DATA.beepTime) && (timeout-- > 0 ) ) + { + Pa_Sleep(SLEEP_MSEC); + } + if( timeout <= 0 ) + { + fprintf( stderr, "Timed out waiting for time. Now = %g, Beep for %g.\n", + Pa_StreamTime( stream ), DATA.beepTime ); + goto error; + } + /* Beep should be sounding now so print synchronized BEEP. */ + printf("BEEP"); + fflush(stdout); + printf(" at %d, delta = %d\n", + (long) DATA.beepTime, (long) (DATA.beepTime - previousTime) ); + fflush(stdout); + previousTime = DATA.beepTime; + } + 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 err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_toomanysines.c b/pd/portaudio_v18/pa_tests/patest_toomanysines.c new file mode 100644 index 00000000..53ca8950 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_toomanysines.c @@ -0,0 +1,175 @@ +/* + * $Id: patest_toomanysines.c,v 1.2.4.1 2003/02/11 21:41:32 philburk Exp $ + * Play more sine waves than we can handle in real time as a stress test, + * + * Authors: + * Ross Bencina <rossb@audiomulch.com> + * Phil Burk <philburk@softsynth.com> + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.audiomulch.com/portaudio/ + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" + +#define MAX_SINES (500) +#define MAX_LOAD (1.2) +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (512) +#ifndef M_PI +#define M_PI (3.14159265) +#endif +#define TWOPI (M_PI * 2.0) + +typedef struct paTestData +{ + int numSines; + double phases[MAX_SINES]; +} +paTestData; + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + unsigned long i; + int j; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + for( i=0; i<framesPerBuffer; i++ ) + { + float output = 0.0; + double phaseInc = 0.02; + double phase; + for( j=0; j<data->numSines; j++ ) + { + /* Advance phase of next oscillator. */ + phase = data->phases[j]; + phase += phaseInc; + if( phase > TWOPI ) phase -= TWOPI; + + phaseInc *= 1.02; + if( phaseInc > 0.5 ) phaseInc *= 0.5; + + /* This is not a very efficient way to calc sines. */ + output += (float) sin( phase ); + data->phases[j] = phase; + } + + + *out++ = (float) (output / data->numSines); + } + return finished; +} + +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + int numStress; + paTestData data = {0}; + double load; + printf("PortAudio Test: output sine wave. SR = %d, BufSize = %d. MAX_LOAD = %f\n", + SAMPLE_RATE, FRAMES_PER_BUFFER, MAX_LOAD ); + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + err = Pa_OpenStream( + &stream, + paNoDevice,/* default input device */ + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + Pa_GetDefaultOutputDeviceID(), /* default output device */ + 1, /* mono output */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + + /* Determine number of sines required to get to 50% */ + do + { + data.numSines++; + Pa_Sleep( 100 ); + + load = Pa_GetCPULoad( stream ); + printf("numSines = %d, CPU load = %f\n", data.numSines, load ); + fflush(stdout); + } + while( load < 0.5 ); + + /* Calculate target stress value then ramp up to that level*/ + numStress = (int) (2.0 * data.numSines * MAX_LOAD ); + for( ; data.numSines < numStress; data.numSines++ ) + { + Pa_Sleep( 200 ); + load = Pa_GetCPULoad( stream ); + printf("STRESSING: numSines = %d, CPU load = %f\n", data.numSines, load ); + fflush(stdout); + + } + + printf("Suffer for 5 seconds.\n"); + Pa_Sleep( 5000 ); + + printf("Stop stream.\n"); + 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 err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_two_rates.c b/pd/portaudio_v18/pa_tests/patest_two_rates.c new file mode 100644 index 00000000..350ce043 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_two_rates.c @@ -0,0 +1,168 @@ +/* + * $Id: patest_two_rates.c,v 1.1.2.1 2003/02/11 21:42:24 philburk Exp $ + * patest_two_rates.c + * Play two streams at different rates to make sure they don't interfere. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" + +#define OUTPUT_DEVICE (Pa_GetDefaultOutputDeviceID()) +#define SAMPLE_RATE_1 (44100) +#define SAMPLE_RATE_2 (44100) +#define FRAMES_PER_BUFFER (256) +#define FREQ_INCR (0.1) + +#ifndef M_PI +#define M_PI (3.14159265) +#endif + +typedef struct +{ + double phase; + double numFrames; +} paTestData; + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + int frameIndex, channelIndex; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + + for( frameIndex=0; frameIndex<(int)framesPerBuffer; frameIndex++ ) + { + /* Generate sine wave. */ + float value = (float) 0.3 * sin(data->phase); + /* Stereo - two channels. */ + *out++ = value; + *out++ = value; + + data->phase += FREQ_INCR; + if( data->phase >= (2.0 * M_PI) ) data->phase -= (2.0 * M_PI); + } + + return 0; +} + +/*******************************************************************/ +int main(void); +int main(void) +{ + PaError err; + PortAudioStream *stream1; + PortAudioStream *stream2; + paTestData data1 = {0}; + paTestData data2 = {0}; + printf("PortAudio Test: two rates.\n" ); + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + + /* Start first stream. **********************/ + err = Pa_OpenStream( + &stream1, + paNoDevice, /* default input device */ + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + OUTPUT_DEVICE, + 2, /* Stereo */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE_1, + FRAMES_PER_BUFFER, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data1 ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream1 ); + if( err != paNoError ) goto error; + + Pa_Sleep( 3 * 1000 ); + + /* Start second stream. **********************/ + err = Pa_OpenStream( + &stream2, + paNoDevice, /* default input device */ + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + OUTPUT_DEVICE, + 2, /* Stereo */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE_2, + FRAMES_PER_BUFFER, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data2 ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream2 ); + if( err != paNoError ) goto error; + + Pa_Sleep( 3 * 1000 ); + + err = Pa_StopStream( stream2 ); + if( err != paNoError ) goto error; + + Pa_Sleep( 3 * 1000 ); + + err = Pa_StopStream( stream1 ); + if( err != paNoError ) goto error; + + Pa_CloseStream( stream2 ); + Pa_CloseStream( stream1 ); + + Pa_Terminate(); + printf("Test finished.\n"); + return err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_underflow.c b/pd/portaudio_v18/pa_tests/patest_underflow.c new file mode 100644 index 00000000..1547b2e4 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_underflow.c @@ -0,0 +1,151 @@ +/* + * $Id: patest_underflow.c,v 1.1.1.1 2002/01/22 00:52:40 phil Exp $ + * patest_underflow.c + * Simulate an output buffer underflow condition. + * Tests whether the stream can be stopped when underflowing buffers. + * + * Authors: + * Ross Bencina <rossb@audiomulch.com> + * Phil Burk <philburk@softsynth.com> + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.audiomulch.com/portaudio/ + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" + +#define NUM_SECONDS (20) +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (2048) +#define MSEC_PER_BUFFER ( (FRAMES_PER_BUFFER * 1000) / SAMPLE_RATE ) + +#ifndef M_PI +#define M_PI (3.14159265) +#endif + +#define TABLE_SIZE (200) +typedef struct +{ + float sine[TABLE_SIZE]; + int left_phase; + int right_phase; + int sleepTime; +} +paTestData; + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int patestCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + paTestData *data = (paTestData*)userData; + float *out = (float*)outputBuffer; + unsigned long i; + int finished = 0; + (void) outTime; /* Prevent unused variable warnings. */ + (void) inputBuffer; + for( i=0; i<framesPerBuffer; i++ ) + { + *out++ = data->sine[data->left_phase]; /* left */ + *out++ = data->sine[data->right_phase]; /* right */ + data->left_phase += 1; + if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE; + data->right_phase += 3; /* higher pitch so we can distinguish left and right. */ + if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE; + } + + /* Cause underflow to occur. */ + if( data->sleepTime > 0 ) Pa_Sleep( data->sleepTime ); + data->sleepTime += 1; + + return finished; +} + +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + paTestData data; + int i; + printf("PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER); + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. ); + } + data.left_phase = data.right_phase = data.sleepTime = 0; + err = Pa_Initialize(); + if( err != paNoError ) goto error; + err = Pa_OpenStream( + &stream, + paNoDevice,/* default input device */ + 0, /* no input */ + paFloat32, /* 32 bit floating point input */ + NULL, + Pa_GetDefaultOutputDeviceID(), /* default output device */ + 2, /* stereo output */ + paFloat32, /* 32 bit floating point output */ + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + patestCallback, + &data ); + if( err != paNoError ) goto error; + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + + while( data.sleepTime < (2 * MSEC_PER_BUFFER) ) + { + printf("SleepTime = %d\n", data.sleepTime ); + Pa_Sleep( data.sleepTime ); + } + + printf("Try to stop stream.\n"); + err = Pa_StopStream( stream ); /* */ + err = Pa_AbortStream( stream ); /* */ + if( err != paNoError ) goto error; + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + Pa_Terminate(); + printf("Test finished.\n"); + return err; +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 err; +} diff --git a/pd/portaudio_v18/pa_tests/patest_wire.c b/pd/portaudio_v18/pa_tests/patest_wire.c new file mode 100644 index 00000000..7ea64bb4 --- /dev/null +++ b/pd/portaudio_v18/pa_tests/patest_wire.c @@ -0,0 +1,176 @@ +/* + * $Id: patest_wire.c,v 1.2.4.3 2003/04/10 23:09:40 philburk Exp $ + * patest_wire.c + * + * Pass input directly to output. + * Note that some HW devices, for example many ISA audio cards + * on PCs, do NOT support full duplex! For a PC, you normally need + * a PCI based audio card such as the SBLive. + * + * Author: Phil Burk http://www.softsynth.com + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <math.h> +#include "portaudio.h" + +#define INPUT_DEVICE Pa_GetDefaultInputDeviceID() +#define OUTPUT_DEVICE Pa_GetDefaultOutputDeviceID() + +/* +** Note that many of the older ISA sound cards on PCs do NOT support +** full duplex audio (simultaneous record and playback). +** And some only support full duplex at lower sample rates. +*/ +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (64) + +#if 1 +#define PA_SAMPLE_TYPE paFloat32 +typedef float SAMPLE; +#else +#define PA_SAMPLE_TYPE paInt16 +typedef short SAMPLE; +#endif +static int wireCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ); + +/* This routine will be called by the PortAudio engine when audio is needed. +** It may be called at interrupt level on some machines so don't do anything +** that could mess up the system like calling malloc() or free(). +*/ +static int wireCallback( void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + PaTimestamp outTime, void *userData ) +{ + SAMPLE *out = (SAMPLE*)outputBuffer; + SAMPLE *in = (SAMPLE*)inputBuffer; + unsigned int i; + (void) outTime; + int samplesPerFrame; + int numSamples; + + samplesPerFrame = (int) userData; + numSamples = framesPerBuffer * samplesPerFrame; + + /* This may get called with NULL inputBuffer during initial setup. */ + if( inputBuffer == NULL ) + { + for( i=0; i<numSamples; i++ ) + { + *out++ = 0; + } + } + else + { + for( i=0; i<numSamples; i++ ) + { + *out++ = *in++; + } + } + + return 0; +} + + +/*******************************************************************/ +int main(void); +int main(void) +{ + PortAudioStream *stream; + PaError err; + const PaDeviceInfo *inputInfo; + const PaDeviceInfo *outputInfo; + int numChannels; + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + + printf("PortAudio Test: input device ID = %d\n", INPUT_DEVICE ); + printf("PortAudio Test: output device ID = %d\n", OUTPUT_DEVICE ); + + /* Use as many channels aspossible. */ + inputInfo = Pa_GetDeviceInfo( INPUT_DEVICE ); + outputInfo = Pa_GetDeviceInfo( OUTPUT_DEVICE ); + /* Use smaller count. */ + numChannels = (inputInfo->maxInputChannels < outputInfo->maxOutputChannels) ? + inputInfo->maxInputChannels : outputInfo->maxOutputChannels; + + printf("maxInputChannels channels = %d\n", inputInfo->maxInputChannels ); + printf("maxOutputChannels channels = %d\n", outputInfo->maxOutputChannels ); + if( numChannels > 0 ) + { + printf("Using %d channels.\n", numChannels ); + + err = Pa_OpenStream( + &stream, + INPUT_DEVICE, + numChannels, + PA_SAMPLE_TYPE, + NULL, + OUTPUT_DEVICE, + numChannels, + PA_SAMPLE_TYPE, + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, /* frames per buffer */ + 0, /* number of buffers, if zero then use default minimum */ + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + wireCallback, + (void *) numChannels ); /* pass numChannels to callback */ + if( err != paNoError ) goto error; + + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + + printf("Full duplex sound test in progress.\n"); + printf("Hit ENTER to exit test.\n"); fflush(stdout); + getchar(); + + printf("Closing stream.\n"); + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + } + else + { + printf("Sorry, not enough channels.\n"); + } + Pa_Terminate(); + + printf("Full duplex sound test complete.\n"); fflush(stdout); + 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 ) ); + return -1; +} diff --git a/pd/portaudio_v18/pa_unix_oss/Makefile b/pd/portaudio_v18/pa_unix_oss/Makefile new file mode 100644 index 00000000..3603816a --- /dev/null +++ b/pd/portaudio_v18/pa_unix_oss/Makefile @@ -0,0 +1,32 @@ +# Make PortAudio for Linux +# +# by Phil Burk +# +# To compile a test program, make a target with a .app suffix. +# For example to compile "../pa_tests/pa_devs.c", enter: +# gmake pa_devs.app +# +# To compile and execute a test program, make a target with a .run suffix. +# For example to build and run "../pa_tests/pa_devs.c", enter: +# gmake pa_devs.run + +VPATH = ../pa_common ../pa_tests +CFLAGS = -g -Wall -I../pa_common +CC = gcc + +PAOBJS = pa_lib.o pa_unix_oss.o pa_unix.o +PAINC = portaudio.h pa_unix.h +PALIBS = -lm -lpthread + +all: patest_sine.run + +%.app: %.o $(PAOBJS) $(PAINC) Makefile + gcc $(CFLAGS) $*.o $(PAOBJS) $(PALIBS) -o $@ + +%.run: %.app + ./$*.app + +clean: + -rm *.app + -rm *.o + diff --git a/pd/portaudio_v18/pa_unix_oss/Makefile_freebsd b/pd/portaudio_v18/pa_unix_oss/Makefile_freebsd new file mode 100644 index 00000000..fc8b14db --- /dev/null +++ b/pd/portaudio_v18/pa_unix_oss/Makefile_freebsd @@ -0,0 +1,36 @@ +# Make PortAudio for FreeBSD + +LIBS = -lm -pthread + +CDEFINES = -I../pa_common +CFLAGS = -g +PASRC = ../pa_common/pa_lib.c pa_freebsd.c +PAINC = ../pa_common/portaudio.h + +# Tests that work. +#TESTC = $(PASRC) ../pa_tests/patest_sine.c +TESTC = $(PASRC) ../pa_tests/patest_sine_time.c +#TESTC = $(PASRC) ../pa_tests/patest_stop.c +#TESTC = $(PASRC) ../pa_tests/patest_sync.c +#TESTC = $(PASRC) ../pa_tests/patest_pink.c +#TESTC = $(PASRC) ../pa_tests/patest_leftright.c +#TESTC = $(PASRC) ../pa_tests/patest_clip.c +#TESTC = $(PASRC) ../pa_tests/patest_dither.c +#TESTC = $(PASRC) ../pa_tests/pa_devs.c +#TESTC = $(PASRC) ../pa_tests/patest_many.c +#TESTC = $(PASRC) ../pa_tests/patest_record.c +#TESTC = $(PASRC) ../pa_tests/patest_wire.c +#TESTC = $(PASRC) ../pa_tests/paqa_devs.c + +# Tests that do not yet work. + +TESTH = $(PAINC) + +all: patest + +patest: $(TESTC) $(TESTH) Makefile + gcc $(CFLAGS) $(TESTC) $(CDEFINES) $(LIBS) -o patest + +run: patest + ./patest + diff --git a/pd/portaudio_v18/pa_unix_oss/low_latency_tip.txt b/pd/portaudio_v18/pa_unix_oss/low_latency_tip.txt Binary files differnew file mode 100644 index 00000000..2d982b79 --- /dev/null +++ b/pd/portaudio_v18/pa_unix_oss/low_latency_tip.txt diff --git a/pd/portaudio_v18/pa_unix_oss/pa_unix.c b/pd/portaudio_v18/pa_unix_oss/pa_unix.c new file mode 100644 index 00000000..8d652b73 --- /dev/null +++ b/pd/portaudio_v18/pa_unix_oss/pa_unix.c @@ -0,0 +1,1122 @@ +/* + * PortAudio Portable Real-Time Audio Library + * Latest Version at: http://www.portaudio.com + * Linux OSS Implementation by douglas repetto and Phil Burk + * + * Copyright (c) 1999-2000 Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +/* +Modification History + 1/2001 - Phil Burk - initial hack for Linux + 2/2001 - Douglas Repetto - many improvements, initial query support + 4/2/2001 - Phil - stop/abort thread control, separate in/out native buffers + 5/28/2001 - Phil - use pthread_create() instead of clone(). Thanks Stephen Brandon! + use pthread_join() after thread shutdown. + 5/29/2001 - Phil - query for multiple devices, multiple formats, + input mode and input+output mode working, + Pa_GetCPULoad() implemented. + PLB20010817 - Phil & Janos Haber - don't halt if test of sample rate fails. + SB20010904 - Stephen Brandon - mods needed for GNUSTEP and SndKit + JH20010905 - Janos Haber - FreeBSD mods + 2001-09-22 - Heiko - (i.e. Heiko Purnhagen <purnhage@tnt.uni-hannover.de> ;-) + added 24k and 16k to ratesToTry[] + fixed Pa_GetInternalDevice() + changed DEVICE_NAME_BASE from /dev/audio to /dev/dsp + handled SNDCTL_DSP_SPEED in Pq_QueryDevice() more graceful + fixed Pa_StreamTime() for paqa_errs.c + fixed numCannel=2 oddity and error handling in Pa_SetupDeviceFormat() + grep also for HP20010922 ... + PLB20010924 - Phil - merged Heiko's changes + removed sNumDevices and potential related bugs, + use getenv("PA_MIN_LATENCY_MSEC") to set desired latency, + simplify CPU Load calculation by comparing real-time to framesPerBuffer, + always close device when querying even if error occurs, + PLB20010927 - Phil - Improved negotiation for numChannels. + SG20011005 - Stewart Greenhill - set numChannels back to reasonable value after query. + DH20010115 - David Herring - fixed uninitialized handle. + + DM20020218 - Dominic Mazzoni - Try to open in nonblocking mode first, in case + the device is already open. New implementation of + Pa_StreamTime that uses SNDCTL_DSP_GETOPTR but + uses our own counter to avoid wraparound. + PLB20020222 - Phil Burk - Added WatchDog proc if audio running at high priority. + Check error return from read() and write(). + Check CPU endianness instead of assuming Little Endian. + 20020621 - pa_unix_oss.c split into pa_unix.c, pa_unix.h, pa_unix_oss.c by + Augustus Saunders. Return values from usleep() ignored by Sam Bayer + because not cross-platform compatible (at least until we get configure + going). Pa_SetupDeviceFormat split into input and output sides to + reflect capabilities of Solaris. + + 20030206 - Martin Rohrbach - various mods for Solaris + + 20030410 - Bjorn Dittmer-Roche - fixed numerous problems associated with pthread_t + + 20030630 - Thomas Richter - eliminated unused variable warnings. + +TODO +O- put semaphore lock around shared data? +O- handle native formats better +O- handle stereo-only device better ??? +O- what if input and output of a device capabilities differ (e.g. es1371) ??? +*/ + + +#include "pa_unix.h" + +typedef void *(*pthread_function_t)(void *); + +/************************************************* Shared Data ********/ +/* FIXME - put Mutex around this shared data. */ +static internalPortAudioDevice *sDeviceList = NULL; +static int sDefaultInputDeviceID = paNoDevice; +static int sDefaultOutputDeviceID = paNoDevice; +static int sPaHostError = 0; + +/********************************* BEGIN CPU UTILIZATION MEASUREMENT ****/ +static void Pa_StartUsageCalculation( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return; + /* Query system timer for usage analysis and to prevent overuse of CPU. */ + gettimeofday( &pahsc->pahsc_EntryTime, NULL ); +} + +static long SubtractTime_AminusB( struct timeval *timeA, struct timeval *timeB ) +{ + long secs = timeA->tv_sec - timeB->tv_sec; + long usecs = secs * 1000000; + usecs += (timeA->tv_usec - timeB->tv_usec); + return usecs; +} + +/****************************************************************************** +** Measure fractional CPU load based on real-time it took to calculate +** buffers worth of output. +*/ +static void Pa_EndUsageCalculation( internalPortAudioStream *past ) +{ + struct timeval currentTime; + long usecsElapsed; + double newUsage; + +#define LOWPASS_COEFFICIENT_0 (0.95) +#define LOWPASS_COEFFICIENT_1 (0.99999 - LOWPASS_COEFFICIENT_0) + + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return; + + if( gettimeofday( ¤tTime, NULL ) == 0 ) + { + usecsElapsed = SubtractTime_AminusB( ¤tTime, &pahsc->pahsc_EntryTime ); + /* Use inverse because it is faster than the divide. */ + newUsage = usecsElapsed * pahsc->pahsc_InverseMicrosPerBuffer; + + past->past_Usage = (LOWPASS_COEFFICIENT_0 * past->past_Usage) + + (LOWPASS_COEFFICIENT_1 * newUsage); + + } +} +/****************************************** END CPU UTILIZATION *******/ + +/********************************************************************* + * Determines the number of available devices by trying to open + * each "/dev/dsp#" or "/dsp/audio#" in order until it fails. + * Add each working device to a singly linked list of devices. + */ +PaError Pa_QueryDevices( void ) +{ + internalPortAudioDevice *pad, *lastPad; + int go = 1; + int numDevices = 0; + PaError testResult; + PaError result = paNoError; + char *envdev; + + sDefaultInputDeviceID = paNoDevice; + sDefaultOutputDeviceID = paNoDevice; + + lastPad = NULL; + + while( go ) + { + /* Allocate structure to hold device info. */ + pad = (internalPortAudioDevice *) + PaHost_AllocateFastMemory( sizeof(internalPortAudioDevice) ); + if( pad == NULL ) return paInsufficientMemory; + memset( pad, 0, sizeof(internalPortAudioDevice) ); + + /* Build name for device. */ + if( numDevices == 0 ) + { + sprintf( pad->pad_DeviceName, DEVICE_NAME_BASE); + } + else + { + sprintf( pad->pad_DeviceName, DEVICE_NAME_BASE "%d", numDevices ); + } + + DBUG(("Try device %s\n", pad->pad_DeviceName )); + testResult = Pa_QueryDevice( pad->pad_DeviceName, pad ); + DBUG(("Pa_QueryDevice returned %d\n", testResult )); + if( testResult != paNoError ) + { + if( lastPad == NULL ) + { + result = testResult; /* No good devices! */ + } + go = 0; + PaHost_FreeFastMemory( pad, sizeof(internalPortAudioDevice) ); + } + else + { + numDevices += 1; + /* Add to linked list of devices. */ + if( lastPad ) + { + lastPad->pad_Next = pad; + } + else + { + sDeviceList = pad; /* First element in linked list. */ + } + lastPad = pad; + } + } + + /* I'm sitting at a SunRay1 and I neither have /dev/audio# nor /dev/dsp#. + Instead, the correct audio device is stored in the environment variable + AUDIODEV and/or UTAUDIODEV, so check these devices as well if we haven't + checked them yet above - MR */ + + DBUG(("Checking for AUDIODEV and UTAUDIODEV\n")); + envdev = getenv("AUDIODEV"); + if (envdev != NULL && !strstr(envdev, DEVICE_NAME_BASE)) { + result = paNoError; + + /* Allocate structure to hold device info. */ + pad = (internalPortAudioDevice *) + PaHost_AllocateFastMemory( sizeof(internalPortAudioDevice) ); + if( pad == NULL ) return paInsufficientMemory; + memset( pad, 0, sizeof(internalPortAudioDevice) ); + + /* Build name for device. */ + strcpy(pad->pad_DeviceName, envdev); + + DBUG(("Try device %s\n", pad->pad_DeviceName )); + testResult = Pa_QueryDevice( pad->pad_DeviceName, pad ); + DBUG(("Pa_QueryDevice returned %d\n", testResult )); + if( testResult != paNoError ) + { + if( lastPad == NULL ) + { + result = testResult; /* No good devices! */ + } + PaHost_FreeFastMemory( pad, sizeof(internalPortAudioDevice) ); + } + else + { + numDevices += 1; + /* Add to linked list of devices. */ + if( lastPad ) + { + lastPad->pad_Next = pad; + } + else + { + sDeviceList = pad; /* First element in linked list. */ + } + lastPad = pad; + } + } + + envdev = getenv("UTAUDIODEV"); + if (envdev != NULL && !strstr(envdev, DEVICE_NAME_BASE) && getenv("AUDIODEV") != NULL && strcmp(envdev, getenv("AUDIODEV"))) { + result = paNoError; + + /* Allocate structure to hold device info. */ + pad = (internalPortAudioDevice *) + PaHost_AllocateFastMemory( sizeof(internalPortAudioDevice) ); + if( pad == NULL ) return paInsufficientMemory; + memset( pad, 0, sizeof(internalPortAudioDevice) ); + + /* Build name for device. */ + strcpy(pad->pad_DeviceName, envdev); + + DBUG(("Try device %s\n", pad->pad_DeviceName )); + testResult = Pa_QueryDevice( pad->pad_DeviceName, pad ); + DBUG(("Pa_QueryDevice returned %d\n", testResult )); + if( testResult != paNoError ) + { + if( lastPad == NULL ) + { + result = testResult; /* No good devices! */ + } + PaHost_FreeFastMemory( pad, sizeof(internalPortAudioDevice) ); + } + else + { + numDevices += 1; + /* Add to linked list of devices. */ + if( lastPad ) + { + lastPad->pad_Next = pad; + } + else + { + sDeviceList = pad; /* First element in linked list. */ + } + lastPad = pad; + } + } + + return result; +} + +/*************************************************************************/ +int Pa_CountDevices() +{ + int numDevices = 0; + internalPortAudioDevice *pad; + + if( sDeviceList == NULL ) Pa_Initialize(); + /* Count devices in list. */ + pad = sDeviceList; + while( pad != NULL ) + { + pad = pad->pad_Next; + numDevices++; + } + + return numDevices; +} + +/*************************************************************************/ +internalPortAudioDevice *Pa_GetInternalDevice( PaDeviceID id ) +{ + internalPortAudioDevice *pad; + if( (id < 0) || ( id >= Pa_CountDevices()) ) return NULL; + pad = sDeviceList; + while( id > 0 ) + { + pad = pad->pad_Next; + id--; + } + return pad; +} + +/*************************************************************************/ +const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceID id ) +{ + internalPortAudioDevice *pad; + if( (id < 0) || ( id >= Pa_CountDevices()) ) return NULL; + pad = Pa_GetInternalDevice( id ); + return &pad->pad_Info ; +} + +static PaError Pa_MaybeQueryDevices( void ) +{ + if( sDeviceList == NULL ) + { + return Pa_QueryDevices(); + } + return 0; +} + +PaDeviceID Pa_GetDefaultInputDeviceID( void ) +{ + /* return paNoDevice; */ + return 0; +} + +PaDeviceID Pa_GetDefaultOutputDeviceID( void ) +{ + return 0; +} + +/********************************************************************** +** Make sure that we have queried the device capabilities. +*/ + +PaError PaHost_Init( void ) +{ + return Pa_MaybeQueryDevices(); +} + +/******************************************************************************************* + * The ol' Canary in a Coal Mine trick. + * Just update the time periodically. + * Runs at low priority so if audio thread runs wild, this thread will get starved + * and the watchdog will detect it. + */ + +#define SCHEDULER_POLICY SCHED_RR +#define WATCHDOG_MAX_SECONDS (3) +#define WATCHDOG_INTERVAL_USEC (1000000) + +static int PaHost_CanaryProc( PaHostSoundControl *pahsc ) +{ + int result = 0; + +#ifdef GNUSTEP + GSRegisterCurrentThread(); /* SB20010904 */ +#endif + + while( pahsc->pahsc_CanaryRun) { + usleep( WATCHDOG_INTERVAL_USEC ); + gettimeofday( &pahsc->pahsc_CanaryTime, NULL ); + } + + DBUG(("PaHost_CanaryProc: exiting.\n")); + +#ifdef GNUSTEP + GSUnregisterCurrentThread(); /* SB20010904 */ +#endif + + return result; +} + +/******************************************************************************************* + * Monitor audio thread and lower its it if it hogs the CPU. + * To prevent getting killed, the audio thread must update a + * variable with a timer value. + * If the value is not recent enough, then the + * thread will get killed. + */ + +static PaError PaHost_WatchDogProc( PaHostSoundControl *pahsc ) +{ + struct sched_param schp = { 0 }; + int maxPri; + +#ifdef GNUSTEP + GSRegisterCurrentThread(); /* SB20010904 */ +#endif + +/* Run at a priority level above audio thread so we can still run if it hangs. */ +/* Rise more than 1 because of rumored off-by-one scheduler bugs. */ + schp.sched_priority = pahsc->pahsc_AudioPriority + 4; + maxPri = sched_get_priority_max(SCHEDULER_POLICY); + if( schp.sched_priority > maxPri ) schp.sched_priority = maxPri; + + if (sched_setscheduler(0, SCHEDULER_POLICY, &schp) != 0) + { + ERR_RPT(("PaHost_WatchDogProc: cannot set watch dog priority!\n")); + goto killAudio; + } + + /* Compare watchdog time with audio and canary thread times. */ + /* Sleep for a while or until thread cancelled. */ + while( pahsc->pahsc_WatchDogRun ) + { + + int delta; + struct timeval currentTime; + + usleep( WATCHDOG_INTERVAL_USEC ); + gettimeofday( ¤tTime, NULL ); + + /* If audio thread is not advancing, then it must be hung so kill it. */ + delta = currentTime.tv_sec - pahsc->pahsc_EntryTime.tv_sec; + DBUG(("PaHost_WatchDogProc: audio delta = %d\n", delta )); + if( delta > WATCHDOG_MAX_SECONDS ) + { + goto killAudio; + } + + /* If canary died, then lower audio priority and halt canary. */ + delta = currentTime.tv_sec - pahsc->pahsc_CanaryTime.tv_sec; + if( delta > WATCHDOG_MAX_SECONDS ) + { + ERR_RPT(("PaHost_WatchDogProc: canary died!\n")); + goto lowerAudio; + } + } + + DBUG(("PaHost_WatchDogProc: exiting.\n")); +#ifdef GNUSTEP + GSUnregisterCurrentThread(); /* SB20010904 */ +#endif + return 0; + +lowerAudio: + { + struct sched_param schat = { 0 }; + if( sched_setscheduler(pahsc->pahsc_AudioThreadPID, SCHED_OTHER, &schat) != 0) + { + ERR_RPT(("PaHost_WatchDogProc: failed to lower audio priority. errno = %d\n", errno )); + /* Fall through into killing audio thread. */ + } + else + { + ERR_RPT(("PaHost_WatchDogProc: lowered audio priority to prevent hogging of CPU.\n")); + goto cleanup; + } + } + +killAudio: + ERR_RPT(("PaHost_WatchDogProc: killing hung audio thread!\n")); + pthread_kill( pahsc->pahsc_AudioThread, SIGKILL ); + +cleanup: + pahsc->pahsc_CanaryRun = 0; + DBUG(("PaHost_WatchDogProc: cancel Canary\n")); + pthread_cancel( pahsc->pahsc_CanaryThread ); + DBUG(("PaHost_WatchDogProc: join Canary\n")); + pthread_join( pahsc->pahsc_CanaryThread, NULL ); + DBUG(("PaHost_WatchDogProc: forget Canary\n")); + pahsc->pahsc_IsCanaryThreadValid = 0; + +#ifdef GNUSTEP + GSUnregisterCurrentThread(); /* SB20010904 */ +#endif + return 0; +} + +/*******************************************************************************************/ +static void PaHost_StopWatchDog( PaHostSoundControl *pahsc ) +{ +/* Cancel WatchDog thread if there is one. */ + if( pahsc->pahsc_IsWatchDogThreadValid ) + { + pahsc->pahsc_WatchDogRun = 0; + DBUG(("PaHost_StopWatchDog: cancel WatchDog\n")); + pthread_cancel( pahsc->pahsc_WatchDogThread ); + pthread_join( pahsc->pahsc_WatchDogThread, NULL ); + pahsc->pahsc_IsWatchDogThreadValid = 0; + } +/* Cancel Canary thread if there is one. */ + if( pahsc->pahsc_IsCanaryThreadValid ) + { + pahsc->pahsc_CanaryRun = 0; + DBUG(("PaHost_StopWatchDog: cancel Canary\n")); + pthread_cancel( pahsc->pahsc_CanaryThread ); + DBUG(("PaHost_StopWatchDog: join Canary\n")); + pthread_join( pahsc->pahsc_CanaryThread, NULL ); + pahsc->pahsc_IsCanaryThreadValid = 0; + } +} + +/*******************************************************************************************/ +static PaError PaHost_StartWatchDog( PaHostSoundControl *pahsc ) +{ + int hres; + PaError result = 0; + + /* The watch dog watches for these timer updates */ + gettimeofday( &pahsc->pahsc_EntryTime, NULL ); + gettimeofday( &pahsc->pahsc_CanaryTime, NULL ); + + /* Launch a canary thread to detect priority abuse. */ + pahsc->pahsc_CanaryRun = 1; + hres = pthread_create(&(pahsc->pahsc_CanaryThread), + NULL /*pthread_attr_t * attr*/, + (pthread_function_t)PaHost_CanaryProc, pahsc); + if( hres != 0 ) + { + pahsc->pahsc_IsCanaryThreadValid = 0; + result = paHostError; + sPaHostError = hres; + goto error; + } + pahsc->pahsc_IsCanaryThreadValid = 1; + + /* Launch a watchdog thread to prevent runaway audio thread. */ + pahsc->pahsc_WatchDogRun = 1; + hres = pthread_create(&(pahsc->pahsc_WatchDogThread), + NULL /*pthread_attr_t * attr*/, + (pthread_function_t)PaHost_WatchDogProc, pahsc); + if( hres != 0 ) + { + pahsc->pahsc_IsWatchDogThreadValid = 0; + result = paHostError; + sPaHostError = hres; + goto error; + } + pahsc->pahsc_IsWatchDogThreadValid = 1; + return result; + +error: + PaHost_StopWatchDog( pahsc ); + return result; +} + +/******************************************************************************************* + * Bump priority of audio thread if running with superuser priveledges. + * if priority bumped then launch a watchdog. + */ +static PaError PaHost_BoostPriority( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc; + PaError result = paNoError; + struct sched_param schp = { 0 }; + + pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return paInternalError; + + pahsc->pahsc_AudioThreadPID = getpid(); + DBUG(("PaHost_BoostPriority: audio PID = %d\n", pahsc->pahsc_AudioThreadPID )); + + /* Choose a priority in the middle of the range. */ + pahsc->pahsc_AudioPriority = (sched_get_priority_max(SCHEDULER_POLICY) - + sched_get_priority_min(SCHEDULER_POLICY)) / 2; + schp.sched_priority = pahsc->pahsc_AudioPriority; + + if (sched_setscheduler(0, SCHEDULER_POLICY, &schp) != 0) + { + DBUG(("PortAudio: only superuser can use real-time priority.\n")); + } + else + { + DBUG(("PortAudio: audio callback priority set to level %d!\n", schp.sched_priority)); + /* We are running at high priority so we should have a watchdog in case audio goes wild. */ + result = PaHost_StartWatchDog( pahsc ); + } + + return result; +} + +/*******************************************************************************************/ +static PaError Pa_AudioThreadProc( internalPortAudioStream *past ) +{ + PaError result; + PaHostSoundControl *pahsc; + ssize_t bytes_read, bytes_written; + + pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return paInternalError; + +#ifdef GNUSTEP + GSRegisterCurrentThread(); /* SB20010904 */ +#endif + + result = PaHost_BoostPriority( past ); + if( result < 0 ) goto error; + + past->past_IsActive = 1; + DBUG(("entering thread.\n")); + + while( (past->past_StopNow == 0) && (past->past_StopSoon == 0) ) + { + /* Read data from device */ + if(pahsc->pahsc_NativeInputBuffer) + { + unsigned int totalread = 0; + DBUG(("Pa_AudioThreadProc: attempt to read %d bytes\n", pahsc->pahsc_BytesPerInputBuffer)); + do + { + bytes_read = read(pahsc->pahsc_InputHandle, + (char *)pahsc->pahsc_NativeInputBuffer + totalread, + pahsc->pahsc_BytesPerInputBuffer - totalread); + + if (bytes_read < 0) + { + ERR_RPT(("PortAudio: read interrupted!\n")); + break; + } + + totalread += bytes_read; + } while( totalread < pahsc->pahsc_BytesPerInputBuffer); + } + + /* Convert 16 bit native data to user data and call user routine. */ + DBUG(("converting...\n")); + Pa_StartUsageCalculation( past ); + result = Pa_CallConvertInt16( past, + pahsc->pahsc_NativeInputBuffer, + pahsc->pahsc_NativeOutputBuffer ); + Pa_EndUsageCalculation( past ); + if( result != 0) + { + DBUG(("hmm, Pa_CallConvertInt16() says: %d. i'm bailing.\n", + result)); + break; + } + + /* Write data to device. */ + if( pahsc->pahsc_NativeOutputBuffer ) + { + unsigned int totalwritten = 0; + do + { + bytes_written = write(pahsc->pahsc_OutputHandle, + (void *)pahsc->pahsc_NativeOutputBuffer, + pahsc->pahsc_BytesPerOutputBuffer); + if( bytes_written < 0 ) + { + ERR_RPT(("PortAudio: write interrupted!")); + break; + } + + totalwritten += bytes_written; + } while( totalwritten < pahsc->pahsc_BytesPerOutputBuffer); + } + + Pa_UpdateStreamTime(pahsc); + } + DBUG(("Pa_AudioThreadProc: left audio loop.\n")); + + past->past_IsActive = 0; + PaHost_StopWatchDog( pahsc ); + +error: + DBUG(("leaving audio thread.\n")); +#ifdef GNUSTEP + GSUnregisterCurrentThread(); /* SB20010904 */ +#endif + return result; +} + +/************************************************************************* +** Determine minimum number of buffers required for this host based +** on minimum latency. Latency can be optionally set by user by setting +** an environment variable. For example, to set latency to 200 msec, put: +** +** set PA_MIN_LATENCY_MSEC=200 +** +** in the cshrc file. +*/ +#define PA_LATENCY_ENV_NAME ("PA_MIN_LATENCY_MSEC") + +int Pa_GetMinNumBuffers( int framesPerBuffer, double framesPerSecond ) +{ + int minBuffers; + int minLatencyMsec = MIN_LATENCY_MSEC; + char *minLatencyText = getenv(PA_LATENCY_ENV_NAME); + if( minLatencyText != NULL ) + { + PRINT(("PA_MIN_LATENCY_MSEC = %s\n", minLatencyText )); + minLatencyMsec = atoi( minLatencyText ); + if( minLatencyMsec < 1 ) minLatencyMsec = 1; + else if( minLatencyMsec > 5000 ) minLatencyMsec = 5000; + } + + minBuffers = (int) ((minLatencyMsec * framesPerSecond) / ( 1000.0 * framesPerBuffer )); + if( minBuffers < 2 ) minBuffers = 2; + return minBuffers; +} + +/*******************************************************************/ +PaError PaHost_OpenStream( internalPortAudioStream *past ) +{ + PaError result = paNoError; + PaHostSoundControl *pahsc; + unsigned int minNumBuffers; + internalPortAudioDevice *pad; + DBUG(("PaHost_OpenStream() called.\n" )); + + /* Allocate and initialize host data. */ + pahsc = (PaHostSoundControl *) malloc(sizeof(PaHostSoundControl)); + if( pahsc == NULL ) + { + result = paInsufficientMemory; + goto error; + } + memset( pahsc, 0, sizeof(PaHostSoundControl) ); + past->past_DeviceData = (void *) pahsc; + + pahsc->pahsc_OutputHandle = BAD_DEVICE_ID; /* No device currently opened. */ + pahsc->pahsc_InputHandle = BAD_DEVICE_ID; + pahsc->pahsc_IsAudioThreadValid = 0; + pahsc->pahsc_IsWatchDogThreadValid = 0; + + /* Allocate native buffers. */ + pahsc->pahsc_BytesPerInputBuffer = past->past_FramesPerUserBuffer * + past->past_NumInputChannels * sizeof(short); + if( past->past_NumInputChannels > 0) + { + pahsc->pahsc_NativeInputBuffer = (short *) malloc(pahsc->pahsc_BytesPerInputBuffer); + if( pahsc->pahsc_NativeInputBuffer == NULL ) + { + result = paInsufficientMemory; + goto error; + } + } + pahsc->pahsc_BytesPerOutputBuffer = past->past_FramesPerUserBuffer * + past->past_NumOutputChannels * sizeof(short); + if( past->past_NumOutputChannels > 0) + { + pahsc->pahsc_NativeOutputBuffer = (short *) malloc(pahsc->pahsc_BytesPerOutputBuffer); + if( pahsc->pahsc_NativeOutputBuffer == NULL ) + { + result = paInsufficientMemory; + goto error; + } + } + + /* DBUG(("PaHost_OpenStream: pahsc_MinFramesPerHostBuffer = %d\n", pahsc->pahsc_MinFramesPerHostBuffer )); */ + minNumBuffers = Pa_GetMinNumBuffers( past->past_FramesPerUserBuffer, past->past_SampleRate ); + past->past_NumUserBuffers = ( minNumBuffers > past->past_NumUserBuffers ) ? minNumBuffers : past->past_NumUserBuffers; + + pahsc->pahsc_InverseMicrosPerBuffer = past->past_SampleRate / (1000000.0 * past->past_FramesPerUserBuffer); + DBUG(("past_SampleRate = %g\n", past->past_SampleRate )); + DBUG(("past_FramesPerUserBuffer = %d\n", past->past_FramesPerUserBuffer )); + DBUG(("pahsc_InverseMicrosPerBuffer = %g\n", pahsc->pahsc_InverseMicrosPerBuffer )); + + /* ------------------------- OPEN DEVICE -----------------------*/ + + /* just output */ + if (past->past_OutputDeviceID == past->past_InputDeviceID) + { + + if ((past->past_NumOutputChannels > 0) && (past->past_NumInputChannels > 0) ) + { + pad = Pa_GetInternalDevice( past->past_OutputDeviceID ); + DBUG(("PaHost_OpenStream: attempt to open %s for O_RDWR\n", pad->pad_DeviceName )); + + /* dmazzoni: test it first in nonblocking mode to + make sure the device is not busy */ + pahsc->pahsc_InputHandle = open(pad->pad_DeviceName,O_RDWR|O_NONBLOCK); + if(pahsc->pahsc_InputHandle==-1) + { + ERR_RPT(("PaHost_OpenStream: could not open %s for O_RDWR\n", pad->pad_DeviceName )); + result = paHostError; + goto error; + } + close(pahsc->pahsc_InputHandle); + + pahsc->pahsc_OutputHandle = pahsc->pahsc_InputHandle = + open(pad->pad_DeviceName,O_RDWR); + if(pahsc->pahsc_InputHandle==-1) + { + ERR_RPT(("PaHost_OpenStream: could not open %s for O_RDWR\n", pad->pad_DeviceName )); + result = paHostError; + goto error; + } + Pa_SetLatency( pahsc->pahsc_OutputHandle, + past->past_NumUserBuffers, past->past_FramesPerUserBuffer, + past->past_NumOutputChannels ); + result = Pa_SetupDeviceFormat( pahsc->pahsc_OutputHandle, + past->past_NumOutputChannels, (int)past->past_SampleRate ); + } + } + else + { + if (past->past_NumOutputChannels > 0) + { + pad = Pa_GetInternalDevice( past->past_OutputDeviceID ); + DBUG(("PaHost_OpenStream: attempt to open %s for O_WRONLY\n", pad->pad_DeviceName )); + /* dmazzoni: test it first in nonblocking mode to + make sure the device is not busy */ + pahsc->pahsc_OutputHandle = open(pad->pad_DeviceName,O_WRONLY|O_NONBLOCK); + if(pahsc->pahsc_OutputHandle==-1) + { + ERR_RPT(("PaHost_OpenStream: could not open %s for O_WRONLY\n", pad->pad_DeviceName )); + result = paHostError; + goto error; + } + close(pahsc->pahsc_OutputHandle); + + pahsc->pahsc_OutputHandle = open(pad->pad_DeviceName,O_WRONLY); + if(pahsc->pahsc_OutputHandle==-1) + { + ERR_RPT(("PaHost_OpenStream: could not open %s for O_WRONLY\n", pad->pad_DeviceName )); + result = paHostError; + goto error; + } + Pa_SetLatency( pahsc->pahsc_OutputHandle, + past->past_NumUserBuffers, past->past_FramesPerUserBuffer, + past->past_NumOutputChannels ); + result = Pa_SetupOutputDeviceFormat( pahsc->pahsc_OutputHandle, + past->past_NumOutputChannels, (int)past->past_SampleRate ); + } + + if (past->past_NumInputChannels > 0) + { + pad = Pa_GetInternalDevice( past->past_InputDeviceID ); + DBUG(("PaHost_OpenStream: attempt to open %s for O_RDONLY\n", pad->pad_DeviceName )); + /* dmazzoni: test it first in nonblocking mode to + make sure the device is not busy */ + pahsc->pahsc_InputHandle = open(pad->pad_DeviceName,O_RDONLY|O_NONBLOCK); + if(pahsc->pahsc_InputHandle==-1) + { + ERR_RPT(("PaHost_OpenStream: could not open %s for O_RDONLY\n", pad->pad_DeviceName )); + result = paHostError; + goto error; + } + close(pahsc->pahsc_InputHandle); + + pahsc->pahsc_InputHandle = open(pad->pad_DeviceName,O_RDONLY); + if(pahsc->pahsc_InputHandle==-1) + { + ERR_RPT(("PaHost_OpenStream: could not open %s for O_RDONLY\n", pad->pad_DeviceName )); + result = paHostError; + goto error; + } + Pa_SetLatency( pahsc->pahsc_InputHandle, /* DH20010115 - was OutputHandle! */ + past->past_NumUserBuffers, past->past_FramesPerUserBuffer, + past->past_NumInputChannels ); + result = Pa_SetupInputDeviceFormat( pahsc->pahsc_InputHandle, + past->past_NumInputChannels, (int)past->past_SampleRate ); + } + } + + + DBUG(("PaHost_OpenStream: SUCCESS - result = %d\n", result )); + return result; + +error: + ERR_RPT(("PaHost_OpenStream: ERROR - result = %d\n", result )); + PaHost_CloseStream( past ); + return result; +} + +/*************************************************************************/ +PaError PaHost_StartOutput( internalPortAudioStream *past ) +{ + past = past; /* unused */ + return paNoError; +} + +/*************************************************************************/ +PaError PaHost_StartInput( internalPortAudioStream *past ) +{ + past = past; /* unused */ + return paNoError; +} + +/*************************************************************************/ +PaError PaHost_StartEngine( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc; + PaError result = paNoError; + int hres; + + pahsc = (PaHostSoundControl *) past->past_DeviceData; + + past->past_StopSoon = 0; + past->past_StopNow = 0; + past->past_IsActive = 1; + + /* Use pthread_create() instead of __clone() because: + * - pthread_create also works for other UNIX systems like Solaris, + * - the Java HotSpot VM crashes in pthread_setcanceltype() when using __clone() + */ + hres = pthread_create(&(pahsc->pahsc_AudioThread), + NULL /*pthread_attr_t * attr*/, + (pthread_function_t)Pa_AudioThreadProc, past); + if( hres != 0 ) + { + result = paHostError; + sPaHostError = hres; + pahsc->pahsc_IsAudioThreadValid = 0; + goto error; + } + pahsc->pahsc_IsAudioThreadValid = 1; + +error: + return result; +} + +/*************************************************************************/ +PaError PaHost_StopEngine( internalPortAudioStream *past, int abort ) +{ + int hres; + PaError result = paNoError; + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + + if( pahsc == NULL ) return paNoError; + + /* Tell background thread to stop generating more data and to let current data play out. */ + past->past_StopSoon = 1; + /* If aborting, tell background thread to stop NOW! */ + if( abort ) past->past_StopNow = 1; + + /* Join thread to recover memory resources. */ + if( pahsc->pahsc_IsAudioThreadValid ) + { + /* This check is needed for GNUSTEP - SB20010904 */ + if ( !pthread_equal( pahsc->pahsc_AudioThread, pthread_self() ) ) + { + hres = pthread_join( pahsc->pahsc_AudioThread, NULL ); + } + else + { + DBUG(("Play thread was stopped from itself - can't do pthread_join()\n")); + hres = 0; + } + + if( hres != 0 ) + { + result = paHostError; + sPaHostError = hres; + } + pahsc->pahsc_IsAudioThreadValid = 0; + } + + past->past_IsActive = 0; + + return result; +} + +/*************************************************************************/ +PaError PaHost_StopInput( internalPortAudioStream *past, int abort ) +{ + past = past; /* unused */ + abort = abort; /* unused */ + return paNoError; +} + +/*************************************************************************/ +PaError PaHost_StopOutput( internalPortAudioStream *past, int abort ) +{ + past = past; /* unused */ + abort = abort; /* unused */ + return paNoError; +} + +/*******************************************************************/ +PaError PaHost_CloseStream( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc; + + if( past == NULL ) return paBadStreamPtr; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return paNoError; + + if( pahsc->pahsc_OutputHandle != BAD_DEVICE_ID ) + { + int err = 0; + DBUG(("PaHost_CloseStream: attempt to close output device handle = %d\n", + pahsc->pahsc_OutputHandle )); + + Pa_FlushStream(pahsc->pahsc_OutputHandle); + + err = close(pahsc->pahsc_OutputHandle); + if( err < 0 ) + { + ERR_RPT(("PaHost_CloseStream: warning, closing output device failed.\n")); + } + } + + if( (pahsc->pahsc_InputHandle != BAD_DEVICE_ID) && + (pahsc->pahsc_InputHandle != pahsc->pahsc_OutputHandle) ) + { + int err = 0; + DBUG(("PaHost_CloseStream: attempt to close input device handle = %d\n", + pahsc->pahsc_InputHandle )); + + Pa_FlushStream(pahsc->pahsc_InputHandle); + + err = close(pahsc->pahsc_InputHandle); + if( err < 0 ) + { + ERR_RPT(("PaHost_CloseStream: warning, closing input device failed.\n")); + } + } + pahsc->pahsc_OutputHandle = BAD_DEVICE_ID; + pahsc->pahsc_InputHandle = BAD_DEVICE_ID; + + if( pahsc->pahsc_NativeInputBuffer ) + { + free( pahsc->pahsc_NativeInputBuffer ); + pahsc->pahsc_NativeInputBuffer = NULL; + } + if( pahsc->pahsc_NativeOutputBuffer ) + { + free( pahsc->pahsc_NativeOutputBuffer ); + pahsc->pahsc_NativeOutputBuffer = NULL; + } + + free( pahsc ); + past->past_DeviceData = NULL; + return paNoError; +} + +/*************************************************************************/ +PaError PaHost_Term( void ) +{ + /* Free all of the linked devices. */ + internalPortAudioDevice *pad, *nextPad; + pad = sDeviceList; + while( pad != NULL ) + { + nextPad = pad->pad_Next; + DBUG(("PaHost_Term: freeing %s\n", pad->pad_DeviceName )); + PaHost_FreeFastMemory( pad, sizeof(internalPortAudioDevice) ); + pad = nextPad; + } + sDeviceList = NULL; + return 0; +} + +/************************************************************************* + * Sleep for the requested number of milliseconds. + */ +void Pa_Sleep( long msec ) +{ +#if 0 + struct timeval timeout; + timeout.tv_sec = msec / 1000; + timeout.tv_usec = (msec % 1000) * 1000; + select( 0, NULL, NULL, NULL, &timeout ); +#else + long usecs = msec * 1000; + usleep( usecs ); +#endif +} + +/************************************************************************* + * Allocate memory that can be accessed in real-time. + * This may need to be held in physical memory so that it is not + * paged to virtual memory. + * This call MUST be balanced with a call to PaHost_FreeFastMemory(). + */ +void *PaHost_AllocateFastMemory( long numBytes ) +{ + void *addr = malloc( numBytes ); /* FIXME - do we need physical, wired, non-virtual memory? */ + if( addr != NULL ) memset( addr, 0, numBytes ); + return addr; +} + +/************************************************************************* + * Free memory that could be accessed in real-time. + * This call MUST be balanced with a call to PaHost_AllocateFastMemory(). + */ +void PaHost_FreeFastMemory( void *addr, long numBytes ) +{ + numBytes = numBytes; /* unused */ + if( addr != NULL ) free( addr ); +} + + +/***********************************************************************/ +PaError PaHost_StreamActive( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc; + if( past == NULL ) return paBadStreamPtr; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return paInternalError; + return (PaError) (past->past_IsActive != 0); +} + +/***********************************************************************/ +long Pa_GetHostError( void ) +{ + return (long) sPaHostError; +} diff --git a/pd/portaudio_v18/pa_unix_oss/pa_unix.h b/pd/portaudio_v18/pa_unix_oss/pa_unix.h new file mode 100644 index 00000000..55b16d50 --- /dev/null +++ b/pd/portaudio_v18/pa_unix_oss/pa_unix.h @@ -0,0 +1,141 @@ +/* + * PortAudio Portable Real-Time Audio Library + * Latest Version at: http://www.portaudio.com + * Linux OSS Implementation by douglas repetto and Phil Burk + * + * Copyright (c) 1999-2000 Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +/* Modification history: + 20020621: pa_unix_oss.c split into pa_unix.c, pa_unix.h, pa_unix_oss.c by + Augustus Saunders. See pa_unix.c for previous history. */ + +/* + PROPOSED - should we add this to "portaudio.h". Problem with + Pa_QueryDevice() not having same driver name os Pa_OpenStream(). + + A PaDriverInfo structure can be passed to the underlying device + on the Pa_OpenStream() call. The contents and interpretation of + the structure is determined by the PA implementation. +*/ +typedef struct PaDriverInfo /* PROPOSED */ +{ + /* Size of structure. Allows driver to extend the structure without breaking existing applications. */ + int size; + /* Can be used to request a specific device name. */ + const char *name; + unsigned long data; +} +PaDriverInfo; + +#include <stdio.h> +#include <stdlib.h> +//#include <malloc.h> +#include <memory.h> +#include <math.h> +#include <sys/ioctl.h> +#include <sys/time.h> +#include <fcntl.h> +#include <unistd.h> +#include <signal.h> +#include <sched.h> +#include <pthread.h> +#include <errno.h> + +#include "portaudio.h" +#include "pa_host.h" +#include "pa_trace.h" + +#define PRINT(x) { printf x; fflush(stdout); } +#define ERR_RPT(x) PRINT(x) +#define DBUG(x) /* PRINT(x) */ +#define DBUGX(x) /* PRINT(x) */ + +#define BAD_DEVICE_ID (-1) + +#define MIN_LATENCY_MSEC (100) +#define MIN_TIMEOUT_MSEC (100) +#define MAX_TIMEOUT_MSEC (1000) + +/************************************************* Definitions ********/ +#ifdef __linux__ + #define DEVICE_NAME_BASE "/dev/dsp" +#else + #define DEVICE_NAME_BASE "/dev/audio" +#endif + +#define MAX_CHARS_DEVNAME (32) +#define MAX_SAMPLE_RATES (10) +typedef struct internalPortAudioDevice +{ + struct internalPortAudioDevice *pad_Next; /* Singly linked list. */ + double pad_SampleRates[MAX_SAMPLE_RATES]; /* for pointing to from pad_Info */ + char pad_DeviceName[MAX_CHARS_DEVNAME]; + PaDeviceInfo pad_Info; +} +internalPortAudioDevice; + +/* Define structure to contain all OSS and Linux specific data. */ +typedef struct PaHostSoundControl +{ + int pahsc_OutputHandle; + int pahsc_InputHandle; + int pahsc_AudioPriority; /* priority of background audio thread */ + pthread_t pahsc_AudioThread; /* background audio thread */ + int pahsc_IsAudioThreadValid; /* Is pahsc_AudioThread valid?*/ pid_t pahsc_AudioThreadPID; /* background audio thread */ + pthread_t pahsc_WatchDogThread; /* highest priority thread that protects system */ + int pahsc_IsWatchDogThreadValid; /* Is pahsc_WatchDogThread valid?*/ + int pahsc_WatchDogRun; /* Ask WatchDog to stop. */ + pthread_t pahsc_CanaryThread; /* low priority thread that detects abuse by audio */ + int pahsc_IsCanaryThreadValid; /* Is pahsc_CanaryThread valid?*/ + struct timeval pahsc_CanaryTime; + int pahsc_CanaryRun; /* Ask Canary to stop. */ + short *pahsc_NativeInputBuffer; + short *pahsc_NativeOutputBuffer; + unsigned int pahsc_BytesPerInputBuffer; /* native buffer size in bytes */ + unsigned int pahsc_BytesPerOutputBuffer; /* native buffer size in bytes */ + /* For measuring CPU utilization. */ + struct timeval pahsc_EntryTime; + double pahsc_InverseMicrosPerBuffer; /* 1/Microseconds of real-time audio per user buffer. */ + + /* For calculating stream time */ + int pahsc_LastPosPtr; + double pahsc_LastStreamBytes; +} +PaHostSoundControl; + +/************************************************* Prototypes **********/ + +internalPortAudioDevice *Pa_GetInternalDevice( PaDeviceID id ); +PaError Pa_QueryDevices( void ); +PaError Pa_QueryDevice( const char *deviceName, internalPortAudioDevice *pad ); +PaError Pa_SetupDeviceFormat( int devHandle, int numChannels, int sampleRate ); +PaError Pa_SetupInputDeviceFormat( int devHandle, int numChannels, int sampleRate ); +PaError Pa_SetupOutputDeviceFormat( int devHandle, int numChannels, int sampleRate ); +void Pa_SetLatency( int devHandle, int numBuffers, int framesPerBuffer, int channelsPerFrame ); +void Pa_UpdateStreamTime(PaHostSoundControl *pahsc); +int Pa_FlushStream(int devHandle); diff --git a/pd/portaudio_v18/pa_unix_oss/pa_unix_oss.c b/pd/portaudio_v18/pa_unix_oss/pa_unix_oss.c new file mode 100644 index 00000000..386cd75b --- /dev/null +++ b/pd/portaudio_v18/pa_unix_oss/pa_unix_oss.c @@ -0,0 +1,385 @@ +/* + * PortAudio Portable Real-Time Audio Library + * Latest Version at: http://www.portaudio.com + * Linux OSS Implementation by douglas repetto and Phil Burk + * + * Copyright (c) 1999-2000 Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +/* Modification history: + 20020621: pa_unix_oss.c split into pa_unix.c, pa_unix.h, pa_unix_oss.c by + Augustus Saunders. See pa_unix.c for previous history. Pa_FlushStream + added by Augustus Saunders for Solaris compatibility. + PLB20021018 - Fill device info table with actual sample rates instead of wished for rates. + - Allow stream to open if sample rate within 10% of desired rate. + 20030630 - Thomas Richter - eliminated unused variable warnings. +*/ + +#include "pa_unix.h" + +#ifdef __linux__ +#include <linux/soundcard.h> +#else +#include <machine/soundcard.h> /* JH20010905 */ +#endif + + +#ifndef AFMT_S16_NE +#define AFMT_S16_NE Get_AFMT_S16_NE() +/********************************************************************* + * Some versions of OSS do not define AFMT_S16_NE. So check CPU. + * PowerPC is Big Endian. X86 is Little Endian. + */ +int Get_AFMT_S16_NE( void ) +{ + long testData = 1; + char *ptr = (char *) &testData; + int isLittle = ( *ptr == 1 ); /* Does address point to least significant byte? */ + return isLittle ? AFMT_S16_LE : AFMT_S16_BE; +} +#endif /* AFMT_S16_NE */ + + +/********************************************************************* + * Try to open the named device. + * If it opens, try to set various rates and formats and fill in + * the device info structure. + */ +PaError Pa_QueryDevice( const char *deviceName, internalPortAudioDevice *pad ) +{ + int result = paHostError; + int tempDevHandle; + int numChannels, maxNumChannels; + int format; + int numSampleRates; + int sampleRate; + int numRatesToTry; + int lastRate; + int ratesToTry[9] = {96000, 48000, 44100, 32000, 24000, 22050, 16000, 11025, 8000}; + int i; + + /* douglas: + we have to do this querying in a slightly different order. apparently + some sound cards will give you different info based on their settings. + e.g. a card might give you stereo at 22kHz but only mono at 44kHz. + the correct order for OSS is: format, channels, sample rate + + */ + if ( (tempDevHandle = open(deviceName,O_WRONLY|O_NONBLOCK)) == -1 ) + { + DBUG(("Pa_QueryDevice: could not open %s\n", deviceName )); + return paHostError; + } + + /* Ask OSS what formats are supported by the hardware. */ + pad->pad_Info.nativeSampleFormats = 0; + + if (ioctl(tempDevHandle, SNDCTL_DSP_GETFMTS, &format) == -1) + { + ERR_RPT(("Pa_QueryDevice: could not get format info\n" )); + goto error; + } + if( format & AFMT_U8 ) pad->pad_Info.nativeSampleFormats |= paUInt8; + if( format & AFMT_S16_NE ) pad->pad_Info.nativeSampleFormats |= paInt16; + + /* Negotiate for the maximum number of channels for this device. PLB20010927 + * Consider up to 16 as the upper number of channels. + * Variable numChannels should contain the actual upper limit after the call. + * Thanks to John Lazzaro and Heiko Purnhagen for suggestions. + */ + maxNumChannels = 0; + for( numChannels = 1; numChannels <= 16; numChannels++ ) + { + int temp = numChannels; + DBUG(("Pa_QueryDevice: use SNDCTL_DSP_CHANNELS, numChannels = %d\n", numChannels )) + if(ioctl(tempDevHandle, SNDCTL_DSP_CHANNELS, &temp) < 0 ) + { + /* ioctl() failed so bail out if we already have stereo */ + if( numChannels > 2 ) break; + } + else + { + /* ioctl() worked but bail out if it does not support numChannels. + * We don't want to leave gaps in the numChannels supported. + */ + if( (numChannels > 2) && (temp != numChannels) ) break; + DBUG(("Pa_QueryDevice: temp = %d\n", temp )) + if( temp > maxNumChannels ) maxNumChannels = temp; /* Save maximum. */ + } + } + + /* The above negotiation may fail for an old driver so try this older technique. */ + if( maxNumChannels < 1 ) + { + int stereo = 1; + if(ioctl(tempDevHandle, SNDCTL_DSP_STEREO, &stereo) < 0) + { + maxNumChannels = 1; + } + else + { + maxNumChannels = (stereo) ? 2 : 1; + } + DBUG(("Pa_QueryDevice: use SNDCTL_DSP_STEREO, maxNumChannels = %d\n", maxNumChannels )) + } + + pad->pad_Info.maxOutputChannels = maxNumChannels; + DBUG(("Pa_QueryDevice: maxNumChannels = %d\n", maxNumChannels)) + + /* During channel negotiation, the last ioctl() may have failed. This can + * also cause sample rate negotiation to fail. Hence the following, to return + * to a supported number of channels. SG20011005 */ + { + int temp = maxNumChannels; + if( temp > 2 ) temp = 2; /* use most reasonable default value */ + ioctl(tempDevHandle, SNDCTL_DSP_CHANNELS, &temp); + } + + /* FIXME - for now, assume maxInputChannels = maxOutputChannels. + * Eventually do separate queries for O_WRONLY and O_RDONLY + */ + pad->pad_Info.maxInputChannels = pad->pad_Info.maxOutputChannels; + + DBUG(("Pa_QueryDevice: maxInputChannels = %d\n", + pad->pad_Info.maxInputChannels)) + + + /* Determine available sample rates by trying each one and seeing result. + * OSS often supports funky rates such as 44188 instead of 44100! + */ + numSampleRates = 0; + lastRate = 0; + numRatesToTry = sizeof(ratesToTry)/sizeof(int); + for (i = 0; i < numRatesToTry; i++) + { + sampleRate = ratesToTry[i]; + + if (ioctl(tempDevHandle, SNDCTL_DSP_SPEED, &sampleRate) >= 0 ) /* PLB20010817 */ + { + /* Use whatever rate OSS tells us. PLB20021018 */ + if (sampleRate != lastRate) + { + DBUG(("Pa_QueryDevice: adding sample rate: %d\n", sampleRate)) + pad->pad_SampleRates[numSampleRates] = (float)sampleRate; + numSampleRates++; + lastRate = sampleRate; + } + else + { + DBUG(("Pa_QueryDevice: dang - got sample rate %d again!\n", sampleRate)) + } + } + } + + DBUG(("Pa_QueryDevice: final numSampleRates = %d\n", numSampleRates)) + if (numSampleRates==0) /* HP20010922 */ + { + /* Desparate attempt to keep running even though no good rates found! */ + ERR_RPT(("Pa_QueryDevice: no supported sample rate (or SNDCTL_DSP_SPEED ioctl call failed). Force 44100 Hz\n" )); + pad->pad_SampleRates[numSampleRates++] = 44100; + } + + pad->pad_Info.numSampleRates = numSampleRates; + pad->pad_Info.sampleRates = pad->pad_SampleRates; /* use pointer to embedded array */ + + pad->pad_Info.name = deviceName; + + result = paNoError; + +error: + /* We MUST close the handle here or we won't be able to reopen it later!!! */ + close(tempDevHandle); + + return result; +} + +/*******************************************************************************************/ +PaError Pa_SetupDeviceFormat( int devHandle, int numChannels, int sampleRate ) +{ + PaError result = paNoError; + int tmp; + + /* Set format, channels, and rate in this order to keep OSS happy. */ + /* Set data format. FIXME - handle more native formats. */ + tmp = AFMT_S16_NE; + if( ioctl(devHandle,SNDCTL_DSP_SETFMT,&tmp) == -1) + { + ERR_RPT(("Pa_SetupDeviceFormat: could not SNDCTL_DSP_SETFMT\n" )); + return paHostError; + } + if( tmp != AFMT_S16_NE ) + { + ERR_RPT(("Pa_SetupDeviceFormat: HW does not support AFMT_S16_NE\n" )); + return paHostError; + } + + + /* Set number of channels. */ + tmp = numChannels; + if (ioctl(devHandle, SNDCTL_DSP_CHANNELS, &numChannels) == -1) + { + ERR_RPT(("Pa_SetupDeviceFormat: could not SNDCTL_DSP_CHANNELS\n" )); + return paHostError; + } + if( tmp != numChannels) + { + ERR_RPT(("Pa_SetupDeviceFormat: HW does not support %d channels\n", numChannels )); + return paHostError; + } + + /* Set playing frequency. */ + tmp = sampleRate; + if( ioctl(devHandle,SNDCTL_DSP_SPEED,&tmp) == -1) + { + ERR_RPT(("Pa_SetupDeviceFormat: could not SNDCTL_DSP_SPEED\n" )); + return paHostError; + } + else if( tmp != sampleRate ) + { + int percentError = abs( (100 * (sampleRate - tmp)) / sampleRate ); + PRINT(("Pa_SetupDeviceFormat: warning - requested sample rate = %d Hz - closest = %d\n", + sampleRate, tmp )); + /* Allow sample rate within 10% off of requested rate. PLB20021018 + * Sometimes OSS uses a funky rate like 44188 instead of 44100. + */ + if( percentError > 10 ) + { + ERR_RPT(("Pa_SetupDeviceFormat: HW does not support %d Hz sample rate\n",sampleRate )); + return paHostError; + } + } + + return result; +} + +PaError Pa_SetupOutputDeviceFormat( int devHandle, int numChannels, int sampleRate ) +{ + return Pa_SetupDeviceFormat(devHandle, numChannels, sampleRate); +} + +PaError Pa_SetupInputDeviceFormat( int devHandle, int numChannels, int sampleRate ) +{ + return Pa_SetupDeviceFormat(devHandle, numChannels, sampleRate); +} + + +/******************************************************************************************* +** Set number of fragments and size of fragments to achieve desired latency. +*/ + +static int CalcHigherLogTwo( int n ) +{ + int log2 = 0; + while( (1<<log2) < n ) log2++; + return log2; +} + +void Pa_SetLatency( int devHandle, int numBuffers, int framesPerBuffer, int channelsPerFrame ) +{ + int tmp; + int bufferSize, powerOfTwo; + + /* Increase size of buffers and reduce number of buffers to reduce latency inside driver. */ + while( numBuffers > 8 ) + { + numBuffers = (numBuffers + 1) >> 1; + framesPerBuffer = framesPerBuffer << 1; + } + + /* calculate size of buffers in bytes */ + bufferSize = framesPerBuffer * channelsPerFrame * sizeof(short); /* FIXME - other sizes? */ + + /* Calculate next largest power of two */ + powerOfTwo = CalcHigherLogTwo( bufferSize ); + DBUG(("Pa_SetLatency: numBuffers = %d, framesPerBuffer = %d, powerOfTwo = %d\n", + numBuffers, framesPerBuffer, powerOfTwo )); + + /* Encode info into a single int */ + tmp=(numBuffers<<16) + powerOfTwo; + + if(ioctl(devHandle,SNDCTL_DSP_SETFRAGMENT,&tmp) == -1) + { + ERR_RPT(("Pa_SetLatency: could not SNDCTL_DSP_SETFRAGMENT\n" )); + /* Don't return an error. Best to just continue and hope for the best. */ + ERR_RPT(("Pa_SetLatency: numBuffers = %d, framesPerBuffer = %d, powerOfTwo = %d\n", + numBuffers, framesPerBuffer, powerOfTwo )); + } +} + +/***********************************************************************/ +PaTimestamp Pa_StreamTime( PortAudioStream *stream ) +{ + internalPortAudioStream *past = (internalPortAudioStream *) stream; + PaHostSoundControl *pahsc; + + count_info info; + int delta; + + if( past == NULL ) return paBadStreamPtr; + + pahsc = (PaHostSoundControl *) past->past_DeviceData; + + if( pahsc->pahsc_NativeOutputBuffer ) + { + ioctl(pahsc->pahsc_OutputHandle, SNDCTL_DSP_GETOPTR, &info); + delta = (info.bytes - pahsc->pahsc_LastPosPtr) & 0x000FFFFF; + return (pahsc->pahsc_LastStreamBytes + delta) / (past->past_NumOutputChannels * sizeof(short)); + } + else + { + ioctl(pahsc->pahsc_InputHandle, SNDCTL_DSP_GETIPTR, &info); + delta = (info.bytes - pahsc->pahsc_LastPosPtr) & 0x000FFFFF; + return (pahsc->pahsc_LastStreamBytes + delta) / (past->past_NumInputChannels * sizeof(short)); + } +} + +void Pa_UpdateStreamTime(PaHostSoundControl *pahsc) +{ + count_info info; + int delta; + + /* Update current stream time (using a double so that + we don't wrap around like info.bytes does) */ + if( pahsc->pahsc_NativeOutputBuffer ) + { + ioctl(pahsc->pahsc_OutputHandle, SNDCTL_DSP_GETOPTR, &info); + } + else + { + ioctl(pahsc->pahsc_InputHandle, SNDCTL_DSP_GETIPTR, &info); + } + delta = (info.bytes - pahsc->pahsc_LastPosPtr) & 0x000FFFFF; + pahsc->pahsc_LastStreamBytes += delta; + pahsc->pahsc_LastPosPtr = info.bytes; +} + +PaError Pa_FlushStream(int devHandle) +{ + /* AS: This doesn't do anything under OSS; it was added for Solaris.*/ + devHandle = devHandle; /* unused */ + return paNoError; +} diff --git a/pd/portaudio_v18/pa_unix_oss/pa_unix_solaris.c b/pd/portaudio_v18/pa_unix_oss/pa_unix_solaris.c new file mode 100644 index 00000000..1e1846b3 --- /dev/null +++ b/pd/portaudio_v18/pa_unix_oss/pa_unix_solaris.c @@ -0,0 +1,397 @@ +/* + * PortAudio Portable Real-Time Audio Library + * Latest Version at: http://www.portaudio.com + * Linux OSS Implementation by douglas repetto and Phil Burk + * + * Copyright (c) 1999-2000 Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +/* Modification history: + 20020621: Initial cut at Solaris modifications jointly by Sam Bayer + and Augustus Saunders. + 20030206 - Martin Rohrbach - various mods for Solaris + */ + +#define __solaris_native__ + +#include "pa_unix.h" + +/* SAM 6/2/02: Docs say we should include sys/audio.h, but + that doesn't exist pre Solaris 2.8. These headers work fine. */ + +#include <sys/audioio.h> +#include <sys/stropts.h> + +/********************************************************************* + * Try to open the named device. + * If it opens, try to set various rates and formats and fill in + * the device info structure. + */ +PaError Pa_QueryDevice( const char *deviceName, internalPortAudioDevice *pad ) +{ + int result = paHostError; + int tempDevHandle; + int numChannels, maxNumChannels; + int numSampleRates; + int sampleRate; + int numRatesToTry; + int ratesToTry[9] = {96000, 48000, 44100, 32000, 24000, 22050, 16000, 11025, 8000}; + int i; + audio_info_t solaris_info; + audio_device_t device_info; + + /* douglas: + we have to do this querying in a slightly different order. apparently + some sound cards will give you different info based on their settins. + e.g. a card might give you stereo at 22kHz but only mono at 44kHz. + the correct order for OSS is: format, channels, sample rate + + */ + /* + to check a device for it's capabilities, it's probably better to use the + equivalent "-ctl"-descriptor - MR + */ + char devname[strlen(deviceName) + 4]; + if ( (tempDevHandle = open(strcat(strcpy(devname, deviceName), "ctl"), O_WRONLY|O_NONBLOCK)) == -1 ) + { + DBUG(("Pa_QueryDevice: could not open %s\n", deviceName )); + return paHostError; + } + + /* Ask OSS what formats are supported by the hardware. */ + pad->pad_Info.nativeSampleFormats = 0; + AUDIO_INITINFO(&solaris_info); + + /* SAM 12/31/01: Sparc native does mulaw, alaw and PCM. + I think PCM is signed. */ + + for (i = 8; i <= 32; i += 8) { + solaris_info.play.precision = i; + solaris_info.play.encoding = AUDIO_ENCODING_LINEAR; + /* If there are no errors, add the format. */ + if (ioctl(tempDevHandle, AUDIO_SETINFO, &solaris_info) > -1) { + switch (i) { + case 8: + pad->pad_Info.nativeSampleFormats |= paInt8; + break; + case 16: + pad->pad_Info.nativeSampleFormats |= paInt16; + break; + case 24: + pad->pad_Info.nativeSampleFormats |= paInt24; + break; + case 32: + pad->pad_Info.nativeSampleFormats |= paInt32; + break; + } + } + } + + maxNumChannels = 0; + for( numChannels = 1; numChannels <= 16; numChannels++ ) + { + int temp = numChannels; + DBUG(("Pa_QueryDevice: use SNDCTL_DSP_CHANNELS, numChannels = %d\n", numChannels )) + AUDIO_INITINFO(&solaris_info); + solaris_info.play.channels = temp; + if (ioctl(tempDevHandle, AUDIO_SETINFO, &solaris_info) < 0) + { + /* ioctl() failed so bail out if we already have stereo */ + if( numChannels > 2 ) break; + } + else + { + /* ioctl() worked but bail out if it does not support numChannels. + * We don't want to leave gaps in the numChannels supported. + */ + if( (numChannels > 2) && (temp != numChannels) ) break; + DBUG(("Pa_QueryDevice: temp = %d\n", temp )) + if( temp > maxNumChannels ) maxNumChannels = temp; /* Save maximum. */ + } + } + + pad->pad_Info.maxOutputChannels = maxNumChannels; + DBUG(("Pa_QueryDevice: maxNumChannels = %d\n", maxNumChannels)) + + /* FIXME - for now, assume maxInputChannels = maxOutputChannels. + * Eventually do separate queries for O_WRONLY and O_RDONLY + */ + pad->pad_Info.maxInputChannels = pad->pad_Info.maxOutputChannels; + + DBUG(("Pa_QueryDevice: maxInputChannels = %d\n", + pad->pad_Info.maxInputChannels)) + + + /* Determine available sample rates by trying each one and seeing result. + */ + numSampleRates = 0; + + AUDIO_INITINFO(&solaris_info); + + numRatesToTry = sizeof(ratesToTry)/sizeof(int); + for (i = 0; i < numRatesToTry; i++) + { + sampleRate = ratesToTry[i]; + + solaris_info.play.sample_rate = sampleRate; /* AS: We opened for Write, so set play */ + if (ioctl(tempDevHandle, AUDIO_SETINFO, &solaris_info) >= 0 ) /* PLB20010817 */ + { + if (sampleRate == ratesToTry[i]) + { + DBUG(("Pa_QueryDevice: got sample rate: %d\n", sampleRate)) + pad->pad_SampleRates[numSampleRates] = (float)ratesToTry[i]; + numSampleRates++; + } + } + } + + DBUG(("Pa_QueryDevice: final numSampleRates = %d\n", numSampleRates)) + if (numSampleRates==0) /* HP20010922 */ + { + ERR_RPT(("Pa_QueryDevice: no supported sample rate (or SNDCTL_DSP_SPEED ioctl call failed).\n" )); + goto error; + } + + pad->pad_Info.numSampleRates = numSampleRates; + pad->pad_Info.sampleRates = pad->pad_SampleRates; + + /* query for the device name instead of using the filesystem-device - MR */ + if (ioctl(tempDevHandle, AUDIO_GETDEV, &device_info) == -1) { + pad->pad_Info.name = deviceName; + } else { + char *pt = (char *)PaHost_AllocateFastMemory(strlen(device_info.name)); + strcpy(pt, device_info.name); + pad->pad_Info.name = pt; + } + + result = paNoError; + +error: + /* We MUST close the handle here or we won't be able to reopen it later!!! */ + close(tempDevHandle); + + return result; +} + +/*******************************************************************************************/ + +PaError Pa_SetupInputDeviceFormat( int devHandle, int numChannels, int sampleRate ) +{ + audio_info_t solaris_info; + AUDIO_INITINFO(&solaris_info); + + /* Sam Bayer/Bryan George 1/10/02: Various folks have + reported that on Solaris Ultra II, the not-right thing + happens on read unless you make sure the audio device is + flushed. The folks who wrote the Robust Audio Tool say: + + XXX driver issue - on Ultra II's if you don't drain + * the device before reading commences then the device + * reads in blocks of 500ms irrespective of the + * blocksize set. After a minute or so it flips into the + * correct mode, but obviously this is too late to be + * useful for most apps. grrr. + */ + /* AS: And the Solaris man audio pages say you should flush before changing formats + anyway. So there you go. */ + if (Pa_FlushStream(devHandle) != paNoError) + return paHostError; + + solaris_info.record.encoding = AUDIO_ENCODING_LINEAR; + solaris_info.record.sample_rate = sampleRate; + solaris_info.record.precision = 16; + solaris_info.record.channels = numChannels; + + if (ioctl(devHandle, AUDIO_SETINFO, &solaris_info) == -1) + { + ERR_RPT(("Pa_SetupDeviceFormat: could not set audio info\n" )); + return paHostError; + } + + return paNoError; +} + +PaError Pa_SetupOutputDeviceFormat( int devHandle, int numChannels, int sampleRate ) +{ + audio_info_t solaris_info; + AUDIO_INITINFO(&solaris_info); + + /* Sam Bayer/Bryan George 1/10/02: Various folks have + reported that on Solaris Ultra II, the not-right thing + happens on read unless you make sure the audio device is + flushed. The folks who wrote the Robust Audio Tool say: + + XXX driver issue - on Ultra II's if you don't drain + * the device before reading commences then the device + * reads in blocks of 500ms irrespective of the + * blocksize set. After a minute or so it flips into the + * correct mode, but obviously this is too late to be + * useful for most apps. grrr. + */ + /* AS: And the Solaris man audio pages say you should flush before changing formats + anyway. So there you go. */ + if (Pa_FlushStream(devHandle) != paNoError) + return paHostError; + + solaris_info.play.encoding = AUDIO_ENCODING_LINEAR; + solaris_info.play.sample_rate = sampleRate; + solaris_info.play.precision = 16; + solaris_info.play.channels = numChannels; + + if (ioctl(devHandle, AUDIO_SETINFO, &solaris_info) == -1) + { + ERR_RPT(("Pa_SetupDeviceFormat: could not set audio info\n" )); + return paHostError; + } + + return paNoError; +} + +PaError Pa_SetupDeviceFormat( int devHandle, int numChannels, int sampleRate ) +{ + PaError result = paNoError; + + result = Pa_SetupOutputDeviceFormat(devHandle, numChannels, sampleRate); + if (result != paNoError) + return result; + return Pa_SetupInputDeviceFormat(devHandle, numChannels, sampleRate); +} + +/******************************************************************************************* +** Set number of fragments and size of fragments to achieve desired latency. +*/ + +static PaError Pa_Unpause(int devHandle); +static PaError Pa_PauseAndFlush(int devHandle); + +void Pa_SetLatency( int devHandle, int numBuffers, int framesPerBuffer, int channelsPerFrame ) +{ + int bufferSize; + audio_info_t solaris_info; + + /* Increase size of buffers and reduce number of buffers to reduce latency inside driver. */ + while( numBuffers > 8 ) + { + numBuffers = (numBuffers + 1) >> 1; + framesPerBuffer = framesPerBuffer << 1; + } + + /* calculate size of buffers in bytes */ + bufferSize = framesPerBuffer * channelsPerFrame * sizeof(short); /* FIXME - other sizes? */ + + DBUG(("Pa_SetLatency: numBuffers = %d, framesPerBuffer = %d\n", + numBuffers, framesPerBuffer)); + + /* SAM 6/6/02: Documentation says to pause and flush before + changing buffer size. */ + + if (Pa_PauseAndFlush(devHandle) != paNoError) { + ERR_RPT(("Pa_SetLatency: could not pause audio\n" )); + return; + } + + AUDIO_INITINFO(&solaris_info); + + /* AS: Doesn't look like solaris has multiple buffers, + so I'm being conservative and + making one buffer. Might not be what we want... */ + + solaris_info.play.buffer_size = solaris_info.record.buffer_size = bufferSize; + + if (ioctl(devHandle, AUDIO_SETINFO, &solaris_info) == -1) + { + ERR_RPT(("Pa_SetLatency: could not set audio info\n" )); + } + Pa_Unpause(devHandle); +} + +/***********************************************************************/ +PaTimestamp Pa_StreamTime( PortAudioStream *stream ) +{ + internalPortAudioStream *past = (internalPortAudioStream *) stream; + PaHostSoundControl *pahsc; + audio_info_t solaris_info; + + if( past == NULL ) return paBadStreamPtr; + + pahsc = (PaHostSoundControl *) past->past_DeviceData; + + ioctl(pahsc->pahsc_OutputHandle, AUDIO_GETINFO, &solaris_info); + return solaris_info.play.samples; +} + +void Pa_UpdateStreamTime(PaHostSoundControl *pahsc) +{ + /* AS: Don't need to do anytying for this under Solaris.*/ +} + +static PaError Pa_PauseAndFlush(int devHandle) +{ + audio_info_t solaris_info; + AUDIO_INITINFO(&solaris_info); + + solaris_info.play.pause = solaris_info.record.pause = 1; + + if (ioctl(devHandle, AUDIO_SETINFO, &solaris_info) == -1) + { + ERR_RPT(("Pa_FlushStream failed.\n")); + return paHostError; + } + + if (ioctl(devHandle, I_FLUSH, FLUSHRW) == -1) + { + ERR_RPT(("Pa_FlushStream failed.\n")); + + /* Unpause! */ + AUDIO_INITINFO(&solaris_info); + solaris_info.play.pause = solaris_info.record.pause = 0; + ioctl(devHandle, AUDIO_SETINFO, &solaris_info); + + return paHostError; + } + return paNoError; +} + +static PaError Pa_Unpause(int devHandle) +{ + audio_info_t solaris_info; + AUDIO_INITINFO(&solaris_info); + + solaris_info.play.pause = solaris_info.record.pause = 0; + + if (ioctl(devHandle, AUDIO_SETINFO, &solaris_info) == -1) + { + ERR_RPT(("Pa_FlushStream failed.\n")); + return paHostError; + } + + return paNoError; +} + +PaError Pa_FlushStream(int devHandle) +{ + PaError res = Pa_PauseAndFlush(devHandle); + if (res == paNoError) + return Pa_Unpause(devHandle); + else return res; +} diff --git a/pd/portaudio_v18/pa_unix_oss/recplay.c b/pd/portaudio_v18/pa_unix_oss/recplay.c new file mode 100644 index 00000000..9d4c78cf --- /dev/null +++ b/pd/portaudio_v18/pa_unix_oss/recplay.c @@ -0,0 +1,114 @@ +/* + * recplay.c + * Phil Burk + * Minimal record and playback test. + * + */ +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#ifndef __STDC__ +/* #include <getopt.h> */ +#endif /* __STDC__ */ +#include <fcntl.h> +#ifdef __STDC__ +#include <string.h> +#else /* __STDC__ */ +#include <strings.h> +#endif /* __STDC__ */ +#include <sys/soundcard.h> + +#define NUM_BYTES (64*1024) +#define BLOCK_SIZE (4*1024) + +#define AUDIO "/dev/dsp" + +char buffer[NUM_BYTES]; + +int audioDev = 0; + +main (int argc, char *argv[]) +{ + int numLeft; + char *ptr; + int num; + int samplesize; + + /********** RECORD ********************/ + /* Open audio device. */ + audioDev = open (AUDIO, O_RDONLY, 0); + if (audioDev == -1) + { + perror (AUDIO); + exit (-1); + } + + /* Set to 16 bit samples. */ + samplesize = 16; + ioctl(audioDev, SNDCTL_DSP_SAMPLESIZE, &samplesize); + if (samplesize != 16) + { + perror("Unable to set the sample size."); + exit(-1); + } + + /* Record in blocks */ + printf("Begin recording.\n"); + numLeft = NUM_BYTES; + ptr = buffer; + while( numLeft >= BLOCK_SIZE ) + { + if ( (num = read (audioDev, ptr, BLOCK_SIZE)) < 0 ) + { + perror (AUDIO); + exit (-1); + } + else + { + printf("Read %d bytes\n", num); + ptr += num; + numLeft -= num; + } + } + + close( audioDev ); + + /********** PLAYBACK ********************/ + /* Open audio device for writing. */ + audioDev = open (AUDIO, O_WRONLY, 0); + if (audioDev == -1) + { + perror (AUDIO); + exit (-1); + } + + /* Set to 16 bit samples. */ + samplesize = 16; + ioctl(audioDev, SNDCTL_DSP_SAMPLESIZE, &samplesize); + if (samplesize != 16) + { + perror("Unable to set the sample size."); + exit(-1); + } + + /* Play in blocks */ + printf("Begin playing.\n"); + numLeft = NUM_BYTES; + ptr = buffer; + while( numLeft >= BLOCK_SIZE ) + { + if ( (num = write (audioDev, ptr, BLOCK_SIZE)) < 0 ) + { + perror (AUDIO); + exit (-1); + } + else + { + printf("Wrote %d bytes\n", num); + ptr += num; + numLeft -= num; + } + } + + close( audioDev ); +} diff --git a/pd/portaudio_v18/pa_win_ds/dsound_wrapper.c b/pd/portaudio_v18/pa_win_ds/dsound_wrapper.c new file mode 100644 index 00000000..527f0eb3 --- /dev/null +++ b/pd/portaudio_v18/pa_win_ds/dsound_wrapper.c @@ -0,0 +1,466 @@ +/* + * $Id: dsound_wrapper.c,v 1.1.1.1 2002/01/22 00:52:45 phil Exp $ + * Simplified DirectSound interface. + * + * Author: Phil Burk & Robert Marsanyi + * + * PortAudio Portable Real-Time Audio Library + * For more information see: http://www.softsynth.com/portaudio/ + * DirectSound Implementation + * Copyright (c) 1999-2000 Phil Burk & Robert Marsanyi + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#define INITGUID // Needed to build IID_IDirectSoundNotify. See objbase.h for info. +#include <objbase.h> +#include <unknwn.h> +#include "dsound_wrapper.h" +#include "pa_trace.h" + +/************************************************************************************/ +void DSW_Term( DSoundWrapper *dsw ) +{ + // Cleanup the sound buffers + if (dsw->dsw_OutputBuffer) + { + IDirectSoundBuffer_Stop( dsw->dsw_OutputBuffer ); + IDirectSoundBuffer_Release( dsw->dsw_OutputBuffer ); + dsw->dsw_OutputBuffer = NULL; + } +#if SUPPORT_AUDIO_CAPTURE + if (dsw->dsw_InputBuffer) + { + IDirectSoundCaptureBuffer_Stop( dsw->dsw_InputBuffer ); + IDirectSoundCaptureBuffer_Release( dsw->dsw_InputBuffer ); + dsw->dsw_InputBuffer = NULL; + } + if (dsw->dsw_pDirectSoundCapture) + { + IDirectSoundCapture_Release( dsw->dsw_pDirectSoundCapture ); + dsw->dsw_pDirectSoundCapture = NULL; + } +#endif /* SUPPORT_AUDIO_CAPTURE */ + if (dsw->dsw_pDirectSound) + { + IDirectSound_Release( dsw->dsw_pDirectSound ); + dsw->dsw_pDirectSound = NULL; + } +} +/************************************************************************************/ +HRESULT DSW_Init( DSoundWrapper *dsw ) +{ + memset( dsw, 0, sizeof(DSoundWrapper) ); + return 0; +} +/************************************************************************************/ +HRESULT DSW_InitOutputDevice( DSoundWrapper *dsw, LPGUID lpGUID ) +{ + // Create the DS object + HRESULT hr = DirectSoundCreate( lpGUID, &dsw->dsw_pDirectSound, NULL ); + if( hr != DS_OK ) return hr; + return hr; +} + +/************************************************************************************/ +HRESULT DSW_InitOutputBuffer( DSoundWrapper *dsw, unsigned long nFrameRate, int nChannels, int bytesPerBuffer ) +{ + DWORD dwDataLen; + DWORD playCursor; + HRESULT result; + LPDIRECTSOUNDBUFFER pPrimaryBuffer; + HWND hWnd; + HRESULT hr; + WAVEFORMATEX wfFormat; + DSBUFFERDESC primaryDesc; + DSBUFFERDESC secondaryDesc; + unsigned char* pDSBuffData; + LARGE_INTEGER counterFrequency; + dsw->dsw_OutputSize = bytesPerBuffer; + dsw->dsw_OutputRunning = FALSE; + dsw->dsw_OutputUnderflows = 0; + dsw->dsw_FramesWritten = 0; + dsw->dsw_BytesPerFrame = nChannels * sizeof(short); + // We were using getForegroundWindow() but sometimes the ForegroundWindow may not be the + // applications's window. Also if that window is closed before the Buffer is closed + // then DirectSound can crash. (Thanks for Scott Patterson for reporting this.) + // So we will use GetDesktopWindow() which was suggested by Miller Puckette. + // hWnd = GetForegroundWindow(); + hWnd = GetDesktopWindow(); + // Set cooperative level to DSSCL_EXCLUSIVE so that we can get 16 bit output, 44.1 KHz. + // Exclusize also prevents unexpected sounds from other apps during a performance. + if ((hr = IDirectSound_SetCooperativeLevel( dsw->dsw_pDirectSound, + hWnd, DSSCL_EXCLUSIVE)) != DS_OK) + { + return hr; + } + // ----------------------------------------------------------------------- + // Create primary buffer and set format just so we can specify our custom format. + // Otherwise we would be stuck with the default which might be 8 bit or 22050 Hz. + // Setup the primary buffer description + ZeroMemory(&primaryDesc, sizeof(DSBUFFERDESC)); + primaryDesc.dwSize = sizeof(DSBUFFERDESC); + primaryDesc.dwFlags = DSBCAPS_PRIMARYBUFFER; // all panning, mixing, etc done by synth + primaryDesc.dwBufferBytes = 0; + primaryDesc.lpwfxFormat = NULL; + // Create the buffer + if ((result = IDirectSound_CreateSoundBuffer( dsw->dsw_pDirectSound, + &primaryDesc, &pPrimaryBuffer, NULL)) != DS_OK) return result; + // Define the buffer format + wfFormat.wFormatTag = WAVE_FORMAT_PCM; + wfFormat.nChannels = nChannels; + wfFormat.nSamplesPerSec = nFrameRate; + wfFormat.wBitsPerSample = 8 * sizeof(short); + wfFormat.nBlockAlign = wfFormat.nChannels * wfFormat.wBitsPerSample / 8; + wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign; + wfFormat.cbSize = 0; /* No extended format info. */ + // Set the primary buffer's format + if((result = IDirectSoundBuffer_SetFormat( pPrimaryBuffer, &wfFormat)) != DS_OK) return result; + // ---------------------------------------------------------------------- + // Setup the secondary buffer description + ZeroMemory(&secondaryDesc, sizeof(DSBUFFERDESC)); + secondaryDesc.dwSize = sizeof(DSBUFFERDESC); + secondaryDesc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_GETCURRENTPOSITION2; + secondaryDesc.dwBufferBytes = bytesPerBuffer; + secondaryDesc.lpwfxFormat = &wfFormat; + // Create the secondary buffer + if ((result = IDirectSound_CreateSoundBuffer( dsw->dsw_pDirectSound, + &secondaryDesc, &dsw->dsw_OutputBuffer, NULL)) != DS_OK) return result; + // Lock the DS buffer + if ((result = IDirectSoundBuffer_Lock( dsw->dsw_OutputBuffer, 0, dsw->dsw_OutputSize, (LPVOID*)&pDSBuffData, + &dwDataLen, NULL, 0, 0)) != DS_OK) return result; + // Zero the DS buffer + ZeroMemory(pDSBuffData, dwDataLen); + // Unlock the DS buffer + if ((result = IDirectSoundBuffer_Unlock( dsw->dsw_OutputBuffer, pDSBuffData, dwDataLen, NULL, 0)) != DS_OK) return result; + if( QueryPerformanceFrequency( &counterFrequency ) ) + { + int framesInBuffer = bytesPerBuffer / (nChannels * sizeof(short)); + dsw->dsw_CounterTicksPerBuffer.QuadPart = (counterFrequency.QuadPart * framesInBuffer) / nFrameRate; + AddTraceMessage("dsw_CounterTicksPerBuffer = %d\n", dsw->dsw_CounterTicksPerBuffer.LowPart ); + } + else + { + dsw->dsw_CounterTicksPerBuffer.QuadPart = 0; + } + // Let DSound set the starting write position because if we set it to zero, it looks like the + // buffer is full to begin with. This causes a long pause before sound starts when using large buffers. + hr = IDirectSoundBuffer_GetCurrentPosition( dsw->dsw_OutputBuffer, &playCursor, &dsw->dsw_WriteOffset ); + if( hr != DS_OK ) + { + return hr; + } + dsw->dsw_FramesWritten = dsw->dsw_WriteOffset / dsw->dsw_BytesPerFrame; + /* printf("DSW_InitOutputBuffer: playCursor = %d, writeCursor = %d\n", playCursor, dsw->dsw_WriteOffset ); */ + return DS_OK; +} + +/************************************************************************************/ +HRESULT DSW_StartOutput( DSoundWrapper *dsw ) +{ + HRESULT hr; + QueryPerformanceCounter( &dsw->dsw_LastPlayTime ); + dsw->dsw_LastPlayCursor = 0; + dsw->dsw_FramesPlayed = 0; + hr = IDirectSoundBuffer_SetCurrentPosition( dsw->dsw_OutputBuffer, 0 ); + if( hr != DS_OK ) + { + return hr; + } + // Start the buffer playback in a loop. + if( dsw->dsw_OutputBuffer != NULL ) + { + hr = IDirectSoundBuffer_Play( dsw->dsw_OutputBuffer, 0, 0, DSBPLAY_LOOPING ); + if( hr != DS_OK ) + { + return hr; + } + dsw->dsw_OutputRunning = TRUE; + } + + return 0; +} +/************************************************************************************/ +HRESULT DSW_StopOutput( DSoundWrapper *dsw ) +{ + // Stop the buffer playback + if( dsw->dsw_OutputBuffer != NULL ) + { + dsw->dsw_OutputRunning = FALSE; + return IDirectSoundBuffer_Stop( dsw->dsw_OutputBuffer ); + } + else return 0; +} + +/************************************************************************************/ +HRESULT DSW_QueryOutputSpace( DSoundWrapper *dsw, long *bytesEmpty ) +{ + HRESULT hr; + DWORD playCursor; + DWORD writeCursor; + long numBytesEmpty; + long playWriteGap; + // Query to see how much room is in buffer. + // Note: Even though writeCursor is not used, it must be passed to prevent DirectSound from dieing + // under WinNT. The Microsoft documentation says we can pass NULL but apparently not. + // Thanks to Max Rheiner for the fix. + hr = IDirectSoundBuffer_GetCurrentPosition( dsw->dsw_OutputBuffer, &playCursor, &writeCursor ); + if( hr != DS_OK ) + { + return hr; + } + AddTraceMessage("playCursor", playCursor); + AddTraceMessage("dsw_WriteOffset", dsw->dsw_WriteOffset); + // Determine size of gap between playIndex and WriteIndex that we cannot write into. + playWriteGap = writeCursor - playCursor; + if( playWriteGap < 0 ) playWriteGap += dsw->dsw_OutputSize; // unwrap + /* DirectSound doesn't have a large enough playCursor so we cannot detect wrap-around. */ + /* Attempt to detect playCursor wrap-around and correct it. */ + if( dsw->dsw_OutputRunning && (dsw->dsw_CounterTicksPerBuffer.QuadPart != 0) ) + { + /* How much time has elapsed since last check. */ + LARGE_INTEGER currentTime; + LARGE_INTEGER elapsedTime; + long bytesPlayed; + long bytesExpected; + long buffersWrapped; + QueryPerformanceCounter( ¤tTime ); + elapsedTime.QuadPart = currentTime.QuadPart - dsw->dsw_LastPlayTime.QuadPart; + dsw->dsw_LastPlayTime = currentTime; + /* How many bytes does DirectSound say have been played. */ + bytesPlayed = playCursor - dsw->dsw_LastPlayCursor; + if( bytesPlayed < 0 ) bytesPlayed += dsw->dsw_OutputSize; // unwrap + dsw->dsw_LastPlayCursor = playCursor; + /* Calculate how many bytes we would have expected to been played by now. */ + bytesExpected = (long) ((elapsedTime.QuadPart * dsw->dsw_OutputSize) / dsw->dsw_CounterTicksPerBuffer.QuadPart); + buffersWrapped = (bytesExpected - bytesPlayed) / dsw->dsw_OutputSize; + if( buffersWrapped > 0 ) + { + AddTraceMessage("playCursor wrapped! bytesPlayed", bytesPlayed ); + AddTraceMessage("playCursor wrapped! bytesExpected", bytesExpected ); + playCursor += (buffersWrapped * dsw->dsw_OutputSize); + bytesPlayed += (buffersWrapped * dsw->dsw_OutputSize); + } + /* Maintain frame output cursor. */ + dsw->dsw_FramesPlayed += (bytesPlayed / dsw->dsw_BytesPerFrame); + } + numBytesEmpty = playCursor - dsw->dsw_WriteOffset; + if( numBytesEmpty < 0 ) numBytesEmpty += dsw->dsw_OutputSize; // unwrap offset + /* Have we underflowed? */ + if( numBytesEmpty > (dsw->dsw_OutputSize - playWriteGap) ) + { + if( dsw->dsw_OutputRunning ) + { + dsw->dsw_OutputUnderflows += 1; + AddTraceMessage("underflow detected! numBytesEmpty", numBytesEmpty ); + } + dsw->dsw_WriteOffset = writeCursor; + numBytesEmpty = dsw->dsw_OutputSize - playWriteGap; + } + *bytesEmpty = numBytesEmpty; + return hr; +} + +/************************************************************************************/ +HRESULT DSW_ZeroEmptySpace( DSoundWrapper *dsw ) +{ + HRESULT hr; + LPBYTE lpbuf1 = NULL; + LPBYTE lpbuf2 = NULL; + DWORD dwsize1 = 0; + DWORD dwsize2 = 0; + long bytesEmpty; + hr = DSW_QueryOutputSpace( dsw, &bytesEmpty ); // updates dsw_FramesPlayed + if (hr != DS_OK) return hr; + if( bytesEmpty == 0 ) return DS_OK; + // Lock free space in the DS + hr = IDirectSoundBuffer_Lock( dsw->dsw_OutputBuffer, dsw->dsw_WriteOffset, bytesEmpty, (void **) &lpbuf1, &dwsize1, + (void **) &lpbuf2, &dwsize2, 0); + if (hr == DS_OK) + { + // Copy the buffer into the DS + ZeroMemory(lpbuf1, dwsize1); + if(lpbuf2 != NULL) + { + ZeroMemory(lpbuf2, dwsize2); + } + // Update our buffer offset and unlock sound buffer + dsw->dsw_WriteOffset = (dsw->dsw_WriteOffset + dwsize1 + dwsize2) % dsw->dsw_OutputSize; + IDirectSoundBuffer_Unlock( dsw->dsw_OutputBuffer, lpbuf1, dwsize1, lpbuf2, dwsize2); + dsw->dsw_FramesWritten += bytesEmpty / dsw->dsw_BytesPerFrame; + } + return hr; +} + +/************************************************************************************/ +HRESULT DSW_WriteBlock( DSoundWrapper *dsw, char *buf, long numBytes ) +{ + HRESULT hr; + LPBYTE lpbuf1 = NULL; + LPBYTE lpbuf2 = NULL; + DWORD dwsize1 = 0; + DWORD dwsize2 = 0; + // Lock free space in the DS + hr = IDirectSoundBuffer_Lock( dsw->dsw_OutputBuffer, dsw->dsw_WriteOffset, numBytes, (void **) &lpbuf1, &dwsize1, + (void **) &lpbuf2, &dwsize2, 0); + if (hr == DS_OK) + { + // Copy the buffer into the DS + CopyMemory(lpbuf1, buf, dwsize1); + if(lpbuf2 != NULL) + { + CopyMemory(lpbuf2, buf+dwsize1, dwsize2); + } + // Update our buffer offset and unlock sound buffer + dsw->dsw_WriteOffset = (dsw->dsw_WriteOffset + dwsize1 + dwsize2) % dsw->dsw_OutputSize; + IDirectSoundBuffer_Unlock( dsw->dsw_OutputBuffer, lpbuf1, dwsize1, lpbuf2, dwsize2); + dsw->dsw_FramesWritten += numBytes / dsw->dsw_BytesPerFrame; + } + return hr; +} + +/************************************************************************************/ +DWORD DSW_GetOutputStatus( DSoundWrapper *dsw ) +{ + DWORD status; + if (IDirectSoundBuffer_GetStatus( dsw->dsw_OutputBuffer, &status ) != DS_OK) + return( DSERR_INVALIDPARAM ); + else + return( status ); +} + +#if SUPPORT_AUDIO_CAPTURE +/* These routines are used to support audio input. + * Do NOT compile these calls when using NT4 because it does + * not support the entry points. + */ +/************************************************************************************/ +HRESULT DSW_InitInputDevice( DSoundWrapper *dsw, LPGUID lpGUID ) +{ + HRESULT hr = DirectSoundCaptureCreate( lpGUID, &dsw->dsw_pDirectSoundCapture, NULL ); + if( hr != DS_OK ) return hr; + return hr; +} +/************************************************************************************/ +HRESULT DSW_InitInputBuffer( DSoundWrapper *dsw, unsigned long nFrameRate, int nChannels, int bytesPerBuffer ) +{ + DSCBUFFERDESC captureDesc; + WAVEFORMATEX wfFormat; + HRESULT result; + // Define the buffer format + wfFormat.wFormatTag = WAVE_FORMAT_PCM; + wfFormat.nChannels = nChannels; + wfFormat.nSamplesPerSec = nFrameRate; + wfFormat.wBitsPerSample = 8 * sizeof(short); + wfFormat.nBlockAlign = wfFormat.nChannels * (wfFormat.wBitsPerSample / 8); + wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign; + wfFormat.cbSize = 0; /* No extended format info. */ + dsw->dsw_InputSize = bytesPerBuffer; + // ---------------------------------------------------------------------- + // Setup the secondary buffer description + ZeroMemory(&captureDesc, sizeof(DSCBUFFERDESC)); + captureDesc.dwSize = sizeof(DSCBUFFERDESC); + captureDesc.dwFlags = 0; + captureDesc.dwBufferBytes = bytesPerBuffer; + captureDesc.lpwfxFormat = &wfFormat; + // Create the capture buffer + if ((result = IDirectSoundCapture_CreateCaptureBuffer( dsw->dsw_pDirectSoundCapture, + &captureDesc, &dsw->dsw_InputBuffer, NULL)) != DS_OK) return result; + dsw->dsw_ReadOffset = 0; // reset last read position to start of buffer + return DS_OK; +} + +/************************************************************************************/ +HRESULT DSW_StartInput( DSoundWrapper *dsw ) +{ + // Start the buffer playback + if( dsw->dsw_InputBuffer != NULL ) + { + return IDirectSoundCaptureBuffer_Start( dsw->dsw_InputBuffer, DSCBSTART_LOOPING ); + } + else return 0; +} + +/************************************************************************************/ +HRESULT DSW_StopInput( DSoundWrapper *dsw ) +{ + // Stop the buffer playback + if( dsw->dsw_InputBuffer != NULL ) + { + return IDirectSoundCaptureBuffer_Stop( dsw->dsw_InputBuffer ); + } + else return 0; +} + +/************************************************************************************/ +HRESULT DSW_QueryInputFilled( DSoundWrapper *dsw, long *bytesFilled ) +{ + HRESULT hr; + DWORD capturePos; + DWORD readPos; + long filled; + // Query to see how much data is in buffer. + // We don't need the capture position but sometimes DirectSound doesn't handle NULLS correctly + // so let's pass a pointer just to be safe. + hr = IDirectSoundCaptureBuffer_GetCurrentPosition( dsw->dsw_InputBuffer, &capturePos, &readPos ); + if( hr != DS_OK ) + { + return hr; + } + filled = readPos - dsw->dsw_ReadOffset; + if( filled < 0 ) filled += dsw->dsw_InputSize; // unwrap offset + *bytesFilled = filled; + return hr; +} + +/************************************************************************************/ +HRESULT DSW_ReadBlock( DSoundWrapper *dsw, char *buf, long numBytes ) +{ + HRESULT hr; + LPBYTE lpbuf1 = NULL; + LPBYTE lpbuf2 = NULL; + DWORD dwsize1 = 0; + DWORD dwsize2 = 0; + // Lock free space in the DS + hr = IDirectSoundCaptureBuffer_Lock ( dsw->dsw_InputBuffer, dsw->dsw_ReadOffset, numBytes, (void **) &lpbuf1, &dwsize1, + (void **) &lpbuf2, &dwsize2, 0); + if (hr == DS_OK) + { + // Copy from DS to the buffer + CopyMemory( buf, lpbuf1, dwsize1); + if(lpbuf2 != NULL) + { + CopyMemory( buf+dwsize1, lpbuf2, dwsize2); + } + // Update our buffer offset and unlock sound buffer + dsw->dsw_ReadOffset = (dsw->dsw_ReadOffset + dwsize1 + dwsize2) % dsw->dsw_InputSize; + IDirectSoundCaptureBuffer_Unlock ( dsw->dsw_InputBuffer, lpbuf1, dwsize1, lpbuf2, dwsize2); + } + return hr; +} + +#endif /* SUPPORT_AUDIO_CAPTURE */ diff --git a/pd/portaudio_v18/pa_win_ds/dsound_wrapper.h b/pd/portaudio_v18/pa_win_ds/dsound_wrapper.h new file mode 100644 index 00000000..b04b0020 --- /dev/null +++ b/pd/portaudio_v18/pa_win_ds/dsound_wrapper.h @@ -0,0 +1,106 @@ +#ifndef __DSOUND_WRAPPER_H +#define __DSOUND_WRAPPER_H +/* + * $Id: dsound_wrapper.h,v 1.1.1.1 2002/01/22 00:52:45 phil Exp $ + * Simplified DirectSound interface. + * + * Author: Phil Burk & Robert Marsanyi + * + * For PortAudio Portable Real-Time Audio Library + * For more information see: http://www.softsynth.com/portaudio/ + * DirectSound Implementation + * Copyright (c) 1999-2000 Phil Burk & Robert Marsanyi + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include <DSound.h> +#if !defined(BOOL) +#define BOOL short +#endif +#ifndef SUPPORT_AUDIO_CAPTURE +#define SUPPORT_AUDIO_CAPTURE (1) +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +#define DSW_NUM_POSITIONS (4) +#define DSW_NUM_EVENTS (5) +#define DSW_TERMINATION_EVENT (DSW_NUM_POSITIONS) + +typedef struct +{ + /* Output */ + LPDIRECTSOUND dsw_pDirectSound; + LPDIRECTSOUNDBUFFER dsw_OutputBuffer; + DWORD dsw_WriteOffset; /* last write position */ + INT dsw_OutputSize; + INT dsw_BytesPerFrame; + /* Try to detect play buffer underflows. */ + LARGE_INTEGER dsw_CounterTicksPerBuffer; /* counter ticks it should take to play a full buffer */ + LARGE_INTEGER dsw_LastPlayTime; + UINT dsw_LastPlayCursor; + UINT dsw_OutputUnderflows; + BOOL dsw_OutputRunning; + /* use double which lets us can play for several thousand years with enough precision */ + double dsw_FramesWritten; + double dsw_FramesPlayed; +#if SUPPORT_AUDIO_CAPTURE + /* Input */ + LPDIRECTSOUNDCAPTURE dsw_pDirectSoundCapture; + LPDIRECTSOUNDCAPTUREBUFFER dsw_InputBuffer; + UINT dsw_ReadOffset; /* last read position */ + UINT dsw_InputSize; +#endif /* SUPPORT_AUDIO_CAPTURE */ + +} +DSoundWrapper; +HRESULT DSW_Init( DSoundWrapper *dsw ); +void DSW_Term( DSoundWrapper *dsw ); +HRESULT DSW_InitOutputBuffer( DSoundWrapper *dsw, unsigned long nFrameRate, + int nChannels, int bufSize ); +HRESULT DSW_StartOutput( DSoundWrapper *dsw ); +HRESULT DSW_StopOutput( DSoundWrapper *dsw ); +DWORD DSW_GetOutputStatus( DSoundWrapper *dsw ); +HRESULT DSW_WriteBlock( DSoundWrapper *dsw, char *buf, long numBytes ); +HRESULT DSW_ZeroEmptySpace( DSoundWrapper *dsw ); +HRESULT DSW_QueryOutputSpace( DSoundWrapper *dsw, long *bytesEmpty ); +HRESULT DSW_Enumerate( DSoundWrapper *dsw ); + +#if SUPPORT_AUDIO_CAPTURE +HRESULT DSW_InitInputBuffer( DSoundWrapper *dsw, unsigned long nFrameRate, + int nChannels, int bufSize ); +HRESULT DSW_StartInput( DSoundWrapper *dsw ); +HRESULT DSW_StopInput( DSoundWrapper *dsw ); +HRESULT DSW_ReadBlock( DSoundWrapper *dsw, char *buf, long numBytes ); +HRESULT DSW_QueryInputFilled( DSoundWrapper *dsw, long *bytesFilled ); +#endif /* SUPPORT_AUDIO_CAPTURE */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* __DSOUND_WRAPPER_H */ diff --git a/pd/portaudio_v18/pa_win_ds/pa_dsound.c b/pd/portaudio_v18/pa_win_ds/pa_dsound.c new file mode 100644 index 00000000..52532625 --- /dev/null +++ b/pd/portaudio_v18/pa_win_ds/pa_dsound.c @@ -0,0 +1,1042 @@ +/* + * $Id: pa_dsound.c,v 1.2.4.1 2002/11/19 20:46:06 philburk Exp $ + * PortAudio Portable Real-Time Audio Library + * Latest Version at: http://www.softsynth.com/portaudio/ + * DirectSound Implementation + * + * Copyright (c) 1999-2000 Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +/* Modifications + * 7/19/01 Mike Berry - casts for compiling with __MWERKS__ CodeWarrior + * 9/27/01 Phil Burk - use number of frames instead of real-time for CPULoad calculation. + * 4/19/02 Phil Burk - Check for Win XP for system latency calculation. + */ +/* Compiler flags: + SUPPORT_AUDIO_CAPTURE - define this flag if you want to SUPPORT_AUDIO_CAPTURE + */ + +#include <stdio.h> +#include <stdlib.h> +#ifndef __MWERKS__ +#include <malloc.h> +#include <memory.h> +#endif //__MWERKS__ +#include <math.h> +#include "portaudio.h" +#include "pa_host.h" +#include "pa_trace.h" +#include "dsound_wrapper.h" + +#define PRINT(x) { printf x; fflush(stdout); } +#define ERR_RPT(x) PRINT(x) +#define DBUG(x) /* PRINT(x) */ +#define DBUGX(x) /* PRINT(x) */ + +#define PA_USE_HIGH_LATENCY (0) +#if PA_USE_HIGH_LATENCY +#define PA_WIN_9X_LATENCY (500) +#define PA_WIN_NT_LATENCY (600) +#else +#define PA_WIN_9X_LATENCY (140) +#define PA_WIN_NT_LATENCY (280) +#endif + +#define PA_WIN_WDM_LATENCY (120) + +/* Trigger an underflow for testing purposes. Should normally be (0). */ +#define PA_SIMULATE_UNDERFLOW (0) +#if PA_SIMULATE_UNDERFLOW +static gUnderCallbackCounter = 0; +#define UNDER_START_GAP (10) +#define UNDER_STOP_GAP (UNDER_START_GAP + 4) +#endif + +/************************************************* Definitions ********/ +typedef struct internalPortAudioStream internalPortAudioStream; +typedef struct internalPortAudioDevice +{ + GUID pad_GUID; + GUID *pad_lpGUID; + double pad_SampleRates[10]; /* for pointing to from pad_Info FIXME?!*/ + PaDeviceInfo pad_Info; +} +internalPortAudioDevice; + +/* Define structure to contain all DirectSound and Windows specific data. */ +typedef struct PaHostSoundControl +{ + DSoundWrapper pahsc_DSoundWrapper; + MMRESULT pahsc_TimerID; + BOOL pahsc_IfInsideCallback; /* Test for reentrancy. */ + short *pahsc_NativeBuffer; + unsigned int pahsc_BytesPerBuffer; /* native buffer size in bytes */ + double pahsc_ValidFramesWritten; + int pahsc_FramesPerDSBuffer; + /* For measuring CPU utilization. */ + LARGE_INTEGER pahsc_EntryCount; + double pahsc_InverseTicksPerUserBuffer; +} +PaHostSoundControl; + +/************************************************* Shared Data ********/ +/* FIXME - put Mutex around this shared data. */ +static int sNumDevices = 0; +static int sDeviceIndex = 0; +static internalPortAudioDevice *sDevices = NULL; +static int sDefaultInputDeviceID = paNoDevice; +static int sDefaultOutputDeviceID = paNoDevice; +static int sEnumerationError; +static int sPaHostError = 0; +/************************************************* Prototypes **********/ +static internalPortAudioDevice *Pa_GetInternalDevice( PaDeviceID id ); +static BOOL CALLBACK Pa_EnumProc(LPGUID lpGUID, + LPCTSTR lpszDesc, + LPCTSTR lpszDrvName, + LPVOID lpContext ); +static BOOL CALLBACK Pa_CountDevProc(LPGUID lpGUID, + LPCTSTR lpszDesc, + LPCTSTR lpszDrvName, + LPVOID lpContext ); +static Pa_QueryDevices( void ); +static void CALLBACK Pa_TimerCallback(UINT uID, UINT uMsg, + DWORD dwUser, DWORD dw1, DWORD dw2); + +/********************************* BEGIN CPU UTILIZATION MEASUREMENT ****/ +static void Pa_StartUsageCalculation( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return; + /* Query system timer for usage analysis and to prevent overuse of CPU. */ + QueryPerformanceCounter( &pahsc->pahsc_EntryCount ); +} + +static void Pa_EndUsageCalculation( internalPortAudioStream *past ) +{ + LARGE_INTEGER CurrentCount = { 0, 0 }; + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return; + /* + ** Measure CPU utilization during this callback. Note that this calculation + ** assumes that we had the processor the whole time. + */ +#define LOWPASS_COEFFICIENT_0 (0.9) +#define LOWPASS_COEFFICIENT_1 (0.99999 - LOWPASS_COEFFICIENT_0) + if( QueryPerformanceCounter( &CurrentCount ) ) + { + LONGLONG InsideCount = CurrentCount.QuadPart - pahsc->pahsc_EntryCount.QuadPart; + double newUsage = InsideCount * pahsc->pahsc_InverseTicksPerUserBuffer; + past->past_Usage = (LOWPASS_COEFFICIENT_0 * past->past_Usage) + + (LOWPASS_COEFFICIENT_1 * newUsage); + } +} + +/****************************************** END CPU UTILIZATION *******/ +static PaError Pa_QueryDevices( void ) +{ + int numBytes; + sDefaultInputDeviceID = paNoDevice; + sDefaultOutputDeviceID = paNoDevice; + /* Enumerate once just to count devices. */ + sNumDevices = 0; // for default device + DirectSoundEnumerate( (LPDSENUMCALLBACK)Pa_CountDevProc, NULL ); +#if SUPPORT_AUDIO_CAPTURE + DirectSoundCaptureEnumerate( (LPDSENUMCALLBACK)Pa_CountDevProc, NULL ); +#endif /* SUPPORT_AUDIO_CAPTURE */ + /* Allocate structures to hold device info. */ + numBytes = sNumDevices * sizeof(internalPortAudioDevice); + sDevices = (internalPortAudioDevice *)PaHost_AllocateFastMemory( numBytes ); /* MEM */ + if( sDevices == NULL ) return paInsufficientMemory; + /* Enumerate again to fill in structures. */ + sDeviceIndex = 0; + sEnumerationError = 0; + DirectSoundEnumerate( (LPDSENUMCALLBACK)Pa_EnumProc, (void *)0 ); +#if SUPPORT_AUDIO_CAPTURE + if( sEnumerationError != paNoError ) return sEnumerationError; + sEnumerationError = 0; + DirectSoundCaptureEnumerate( (LPDSENUMCALLBACK)Pa_EnumProc, (void *)1 ); +#endif /* SUPPORT_AUDIO_CAPTURE */ + return sEnumerationError; +} +/************************************************************************************/ +long Pa_GetHostError() +{ + return sPaHostError; +} +/************************************************************************************ +** Just count devices so we know how much memory to allocate. +*/ +static BOOL CALLBACK Pa_CountDevProc(LPGUID lpGUID, + LPCTSTR lpszDesc, + LPCTSTR lpszDrvName, + LPVOID lpContext ) +{ + sNumDevices++; + return TRUE; +} +/************************************************************************************ +** Extract capabilities info from each device. +*/ +static BOOL CALLBACK Pa_EnumProc(LPGUID lpGUID, + LPCTSTR lpszDesc, + LPCTSTR lpszDrvName, + LPVOID lpContext ) +{ + HRESULT hr; + LPDIRECTSOUND lpDirectSound; +#if SUPPORT_AUDIO_CAPTURE + LPDIRECTSOUNDCAPTURE lpDirectSoundCapture; +#endif /* SUPPORT_AUDIO_CAPTURE */ + int isInput = (int) lpContext; /* Passed from Pa_CountDevices() */ + internalPortAudioDevice *pad; + + if( sDeviceIndex >= sNumDevices ) + { + sEnumerationError = paInternalError; + return FALSE; + } + pad = &sDevices[sDeviceIndex]; + /* Copy GUID to static array. Set pointer. */ + if( lpGUID == NULL ) + { + pad->pad_lpGUID = NULL; + } + else + { + memcpy( &pad->pad_GUID, lpGUID, sizeof(GUID) ); + pad->pad_lpGUID = &pad->pad_GUID; + } + pad->pad_Info.sampleRates = pad->pad_SampleRates; /* Point to array. */ + /* Allocate room for descriptive name. */ + if( lpszDesc != NULL ) + { + int len = strlen(lpszDesc); + pad->pad_Info.name = (char *)malloc( len+1 ); + if( pad->pad_Info.name == NULL ) + { + sEnumerationError = paInsufficientMemory; + return FALSE; + } + memcpy( (void *) pad->pad_Info.name, lpszDesc, len+1 ); + } +#if SUPPORT_AUDIO_CAPTURE + if( isInput ) + { + /********** Input ******************************/ + DSCCAPS caps; + if( lpGUID == NULL ) sDefaultInputDeviceID = sDeviceIndex; + hr = DirectSoundCaptureCreate( lpGUID, &lpDirectSoundCapture, NULL ); + if( hr != DS_OK ) + { + pad->pad_Info.maxInputChannels = 0; + DBUG(("Cannot create Capture for %s. Result = 0x%x\n", lpszDesc, hr )); + } + else + { + /* Query device characteristics. */ + caps.dwSize = sizeof(caps); + IDirectSoundCapture_GetCaps( lpDirectSoundCapture, &caps ); + /* printf("caps.dwFormats = 0x%x\n", caps.dwFormats ); */ + pad->pad_Info.maxInputChannels = caps.dwChannels; + /* Determine sample rates from flags. */ + if( caps.dwChannels == 2 ) + { + int index = 0; + if( caps.dwFormats & WAVE_FORMAT_1S16) pad->pad_SampleRates[index++] = 11025.0; + if( caps.dwFormats & WAVE_FORMAT_2S16) pad->pad_SampleRates[index++] = 22050.0; + if( caps.dwFormats & WAVE_FORMAT_4S16) pad->pad_SampleRates[index++] = 44100.0; + pad->pad_Info.numSampleRates = index; + } + else if( caps.dwChannels == 1 ) + { + int index = 0; + if( caps.dwFormats & WAVE_FORMAT_1M16) pad->pad_SampleRates[index++] = 11025.0; + if( caps.dwFormats & WAVE_FORMAT_2M16) pad->pad_SampleRates[index++] = 22050.0; + if( caps.dwFormats & WAVE_FORMAT_4M16) pad->pad_SampleRates[index++] = 44100.0; + pad->pad_Info.numSampleRates = index; + } + else pad->pad_Info.numSampleRates = 0; + IDirectSoundCapture_Release( lpDirectSoundCapture ); + } + } + else +#endif /* SUPPORT_AUDIO_CAPTURE */ + + { + /********** Output ******************************/ + DSCAPS caps; + if( lpGUID == NULL ) sDefaultOutputDeviceID = sDeviceIndex; + /* Create interfaces for each object. */ + hr = DirectSoundCreate( lpGUID, &lpDirectSound, NULL ); + if( hr != DS_OK ) + { + pad->pad_Info.maxOutputChannels = 0; + DBUG(("Cannot create dsound for %s. Result = 0x%x\n", lpszDesc, hr )); + } + else + { + /* Query device characteristics. */ + caps.dwSize = sizeof(caps); + IDirectSound_GetCaps( lpDirectSound, &caps ); + pad->pad_Info.maxOutputChannels = ( caps.dwFlags & DSCAPS_PRIMARYSTEREO ) ? 2 : 1; + /* Get sample rates. */ + pad->pad_SampleRates[0] = (double) caps.dwMinSecondarySampleRate; + pad->pad_SampleRates[1] = (double) caps.dwMaxSecondarySampleRate; + if( caps.dwFlags & DSCAPS_CONTINUOUSRATE ) pad->pad_Info.numSampleRates = -1; + else if( caps.dwMinSecondarySampleRate == caps.dwMaxSecondarySampleRate ) + { + if( caps.dwMinSecondarySampleRate == 0 ) + { + /* + ** On my Thinkpad 380Z, DirectSoundV6 returns min-max=0 !! + ** But it supports continuous sampling. + ** So fake range of rates, and hope it really supports it. + */ + pad->pad_SampleRates[0] = 11025.0f; + pad->pad_SampleRates[1] = 48000.0f; + pad->pad_Info.numSampleRates = -1; /* continuous range */ + + DBUG(("PA - Reported rates both zero. Setting to fake values for device #%d\n", sDeviceIndex )); + } + else + { + pad->pad_Info.numSampleRates = 1; + } + } + else if( (caps.dwMinSecondarySampleRate < 1000.0) && (caps.dwMaxSecondarySampleRate > 50000.0) ) + { + /* The EWS88MT drivers lie, lie, lie. The say they only support two rates, 100 & 100000. + ** But we know that they really support a range of rates! + ** So when we see a ridiculous set of rates, assume it is a range. + */ + pad->pad_Info.numSampleRates = -1; + DBUG(("PA - Sample rate range used instead of two odd values for device #%d\n", sDeviceIndex )); + } + else pad->pad_Info.numSampleRates = 2; + IDirectSound_Release( lpDirectSound ); + } + } + pad->pad_Info.nativeSampleFormats = paInt16; + sDeviceIndex++; + return( TRUE ); +} +/*************************************************************************/ +int Pa_CountDevices() +{ + if( sNumDevices <= 0 ) Pa_Initialize(); + return sNumDevices; +} +static internalPortAudioDevice *Pa_GetInternalDevice( PaDeviceID id ) +{ + if( (id < 0) || ( id >= Pa_CountDevices()) ) return NULL; + return &sDevices[id]; +} +/*************************************************************************/ +const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceID id ) +{ + internalPortAudioDevice *pad; + if( (id < 0) || ( id >= Pa_CountDevices()) ) return NULL; + pad = Pa_GetInternalDevice( id ); + return &pad->pad_Info ; +} +static PaError Pa_MaybeQueryDevices( void ) +{ + if( sNumDevices == 0 ) + { + return Pa_QueryDevices(); + } + return 0; +} +/************************************************************************* +** Returns recommended device ID. +** On the PC, the recommended device can be specified by the user by +** setting an environment variable. For example, to use device #1. +** +** set PA_RECOMMENDED_OUTPUT_DEVICE=1 +** +** The user should first determine the available device ID by using +** the supplied application "pa_devs". +*/ +#define PA_ENV_BUF_SIZE (32) +#define PA_REC_IN_DEV_ENV_NAME ("PA_RECOMMENDED_INPUT_DEVICE") +#define PA_REC_OUT_DEV_ENV_NAME ("PA_RECOMMENDED_OUTPUT_DEVICE") +static PaDeviceID PaHost_GetEnvDefaultDeviceID( char *envName ) +{ + DWORD hresult; + char envbuf[PA_ENV_BUF_SIZE]; + PaDeviceID recommendedID = paNoDevice; + /* Let user determine default device by setting environment variable. */ + hresult = GetEnvironmentVariable( envName, envbuf, PA_ENV_BUF_SIZE ); + if( (hresult > 0) && (hresult < PA_ENV_BUF_SIZE) ) + { + recommendedID = atoi( envbuf ); + } + return recommendedID; +} +PaDeviceID Pa_GetDefaultInputDeviceID( void ) +{ + PaError result; + result = PaHost_GetEnvDefaultDeviceID( PA_REC_IN_DEV_ENV_NAME ); + if( result < 0 ) + { + result = Pa_MaybeQueryDevices(); + if( result < 0 ) return result; + result = sDefaultInputDeviceID; + } + return result; +} +PaDeviceID Pa_GetDefaultOutputDeviceID( void ) +{ + PaError result; + result = PaHost_GetEnvDefaultDeviceID( PA_REC_OUT_DEV_ENV_NAME ); + if( result < 0 ) + { + result = Pa_MaybeQueryDevices(); + if( result < 0 ) return result; + result = sDefaultOutputDeviceID; + } + return result; +} +/********************************************************************** +** Make sure that we have queried the device capabilities. +*/ +PaError PaHost_Init( void ) +{ +#if PA_SIMULATE_UNDERFLOW + PRINT(("WARNING - Underflow Simulation Enabled - Expect a Big Glitch!!!\n")); +#endif + return Pa_MaybeQueryDevices(); +} +static PaError Pa_TimeSlice( internalPortAudioStream *past ) +{ + PaError result = 0; + long bytesEmpty = 0; + long bytesFilled = 0; + long bytesToXfer = 0; + long numChunks; + HRESULT hresult; + PaHostSoundControl *pahsc; + short *nativeBufPtr; + past->past_NumCallbacks += 1; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return paInternalError; + /* How much input data is available? */ +#if SUPPORT_AUDIO_CAPTURE + if( past->past_NumInputChannels > 0 ) + { + DSW_QueryInputFilled( &pahsc->pahsc_DSoundWrapper, &bytesFilled ); + bytesToXfer = bytesFilled; + } +#endif /* SUPPORT_AUDIO_CAPTURE */ + /* How much output room is available? */ + if( past->past_NumOutputChannels > 0 ) + { + DSW_QueryOutputSpace( &pahsc->pahsc_DSoundWrapper, &bytesEmpty ); + bytesToXfer = bytesEmpty; + } + AddTraceMessage( "bytesEmpty ", bytesEmpty ); + /* Choose smallest value if both are active. */ + if( (past->past_NumInputChannels > 0) && (past->past_NumOutputChannels > 0) ) + { + bytesToXfer = ( bytesFilled < bytesEmpty ) ? bytesFilled : bytesEmpty; + } + /* printf("bytesFilled = %d, bytesEmpty = %d, bytesToXfer = %d\n", + bytesFilled, bytesEmpty, bytesToXfer); + */ + /* Quantize to multiples of a buffer. */ + numChunks = bytesToXfer / pahsc->pahsc_BytesPerBuffer; + if( numChunks > (long)(past->past_NumUserBuffers/2) ) + { + numChunks = (long)past->past_NumUserBuffers/2; + } + else if( numChunks < 0 ) + { + numChunks = 0; + } + AddTraceMessage( "numChunks ", numChunks ); + nativeBufPtr = pahsc->pahsc_NativeBuffer; + if( numChunks > 0 ) + { + while( numChunks-- > 0 ) + { + /* Measure usage based on time to process one user buffer. */ + Pa_StartUsageCalculation( past ); +#if SUPPORT_AUDIO_CAPTURE + /* Get native data from DirectSound. */ + if( past->past_NumInputChannels > 0 ) + { + hresult = DSW_ReadBlock( &pahsc->pahsc_DSoundWrapper, (char *) nativeBufPtr, pahsc->pahsc_BytesPerBuffer ); + if( hresult < 0 ) + { + ERR_RPT(("DirectSound ReadBlock failed, hresult = 0x%x\n",hresult)); + sPaHostError = hresult; + break; + } + } +#endif /* SUPPORT_AUDIO_CAPTURE */ + /* Convert 16 bit native data to user data and call user routine. */ + result = Pa_CallConvertInt16( past, nativeBufPtr, nativeBufPtr ); + if( result != 0) break; + /* Pass native data to DirectSound. */ + if( past->past_NumOutputChannels > 0 ) + { + /* static short DEBUGHACK = 0; + DEBUGHACK += 0x0049; + nativeBufPtr[0] = DEBUGHACK; /* Make buzz to see if DirectSound still running. */ + hresult = DSW_WriteBlock( &pahsc->pahsc_DSoundWrapper, (char *) nativeBufPtr, pahsc->pahsc_BytesPerBuffer ); + if( hresult < 0 ) + { + ERR_RPT(("DirectSound WriteBlock failed, result = 0x%x\n",hresult)); + sPaHostError = hresult; + break; + } + } + Pa_EndUsageCalculation( past ); + } + } + return result; +} +/*******************************************************************/ +static void CALLBACK Pa_TimerCallback(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) +{ + internalPortAudioStream *past; + PaHostSoundControl *pahsc; +#if PA_SIMULATE_UNDERFLOW + gUnderCallbackCounter++; + if( (gUnderCallbackCounter >= UNDER_START_GAP) && + (gUnderCallbackCounter <= UNDER_STOP_GAP) ) + { + if( gUnderCallbackCounter == UNDER_START_GAP) + { + AddTraceMessage("Begin stall: gUnderCallbackCounter =======", gUnderCallbackCounter ); + } + if( gUnderCallbackCounter == UNDER_STOP_GAP) + { + AddTraceMessage("End stall: gUnderCallbackCounter =======", gUnderCallbackCounter ); + } + return; + } +#endif + past = (internalPortAudioStream *) dwUser; + if( past == NULL ) return; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return; + if( !pahsc->pahsc_IfInsideCallback && past->past_IsActive ) + { + if( past->past_StopNow ) + { + past->past_IsActive = 0; + } + else if( past->past_StopSoon ) + { + DSoundWrapper *dsw = &pahsc->pahsc_DSoundWrapper; + if( past->past_NumOutputChannels > 0 ) + { + DSW_ZeroEmptySpace( dsw ); + AddTraceMessage("Pa_TimerCallback: waiting - written ", (int) dsw->dsw_FramesWritten ); + AddTraceMessage("Pa_TimerCallback: waiting - played ", (int) dsw->dsw_FramesPlayed ); + /* clear past_IsActive when all sound played */ + if( dsw->dsw_FramesPlayed >= past->past_FrameCount ) + { + past->past_IsActive = 0; + } + } + else + { + past->past_IsActive = 0; + } + } + else + { + pahsc->pahsc_IfInsideCallback = 1; + if( Pa_TimeSlice( past ) != 0) /* Call time slice independant of timing method. */ + { + past->past_StopSoon = 1; + } + pahsc->pahsc_IfInsideCallback = 0; + } + } +} +/*******************************************************************/ +PaError PaHost_OpenStream( internalPortAudioStream *past ) +{ + HRESULT hr; + PaError result = paNoError; + PaHostSoundControl *pahsc; + int numBytes, maxChannels; + unsigned int minNumBuffers; + internalPortAudioDevice *pad; + DSoundWrapper *dsw; + /* Allocate and initialize host data. */ + pahsc = (PaHostSoundControl *) PaHost_AllocateFastMemory(sizeof(PaHostSoundControl)); /* MEM */ + if( pahsc == NULL ) + { + result = paInsufficientMemory; + goto error; + } + memset( pahsc, 0, sizeof(PaHostSoundControl) ); + past->past_DeviceData = (void *) pahsc; + pahsc->pahsc_TimerID = 0; + dsw = &pahsc->pahsc_DSoundWrapper; + DSW_Init( dsw ); + /* Allocate native buffer. */ + maxChannels = ( past->past_NumOutputChannels > past->past_NumInputChannels ) ? + past->past_NumOutputChannels : past->past_NumInputChannels; + pahsc->pahsc_BytesPerBuffer = past->past_FramesPerUserBuffer * maxChannels * sizeof(short); + if( maxChannels > 0 ) + { + pahsc->pahsc_NativeBuffer = (short *) PaHost_AllocateFastMemory(pahsc->pahsc_BytesPerBuffer); /* MEM */ + if( pahsc->pahsc_NativeBuffer == NULL ) + { + result = paInsufficientMemory; + goto error; + } + } + else + { + result = paInvalidChannelCount; + goto error; + } + + DBUG(("PaHost_OpenStream: pahsc_MinFramesPerHostBuffer = %d\n", pahsc->pahsc_MinFramesPerHostBuffer )); + minNumBuffers = Pa_GetMinNumBuffers( past->past_FramesPerUserBuffer, past->past_SampleRate ); + past->past_NumUserBuffers = ( minNumBuffers > past->past_NumUserBuffers ) ? minNumBuffers : past->past_NumUserBuffers; + numBytes = pahsc->pahsc_BytesPerBuffer * past->past_NumUserBuffers; + if( numBytes < DSBSIZE_MIN ) + { + result = paBufferTooSmall; + goto error; + } + if( numBytes > DSBSIZE_MAX ) + { + result = paBufferTooBig; + goto error; + } + pahsc->pahsc_FramesPerDSBuffer = past->past_FramesPerUserBuffer * past->past_NumUserBuffers; + { + int msecLatency = (int) ((pahsc->pahsc_FramesPerDSBuffer * 1000) / past->past_SampleRate); + PRINT(("PortAudio on DirectSound - Latency = %d frames, %d msec\n", pahsc->pahsc_FramesPerDSBuffer, msecLatency )); + } + /* ------------------ OUTPUT */ + if( (past->past_OutputDeviceID >= 0) && (past->past_NumOutputChannels > 0) ) + { + DBUG(("PaHost_OpenStream: deviceID = 0x%x\n", past->past_OutputDeviceID)); + pad = Pa_GetInternalDevice( past->past_OutputDeviceID ); + hr = DirectSoundCreate( pad->pad_lpGUID, &dsw->dsw_pDirectSound, NULL ); + /* If this fails, then try each output device until we find one that works. */ + if( hr != DS_OK ) + { + int i; + ERR_RPT(("Creation of requested Audio Output device '%s' failed.\n", + ((pad->pad_lpGUID == NULL) ? "Default" : pad->pad_Info.name) )); + for( i=0; i<Pa_CountDevices(); i++ ) + { + pad = Pa_GetInternalDevice( i ); + if( pad->pad_Info.maxOutputChannels >= past->past_NumOutputChannels ) + { + DBUG(("Try device '%s' instead.\n", pad->pad_Info.name )); + hr = DirectSoundCreate( pad->pad_lpGUID, &dsw->dsw_pDirectSound, NULL ); + if( hr == DS_OK ) + { + ERR_RPT(("Using device '%s' instead.\n", pad->pad_Info.name )); + break; + } + } + } + } + if( hr != DS_OK ) + { + ERR_RPT(("PortAudio: DirectSoundCreate() failed!\n")); + result = paHostError; + sPaHostError = hr; + goto error; + } + hr = DSW_InitOutputBuffer( dsw, + (unsigned long) (past->past_SampleRate + 0.5), + past->past_NumOutputChannels, numBytes ); + DBUG(("DSW_InitOutputBuffer() returns %x\n", hr)); + if( hr != DS_OK ) + { + result = paHostError; + sPaHostError = hr; + goto error; + } + past->past_FrameCount = pahsc->pahsc_DSoundWrapper.dsw_FramesWritten; + } +#if SUPPORT_AUDIO_CAPTURE + /* ------------------ INPUT */ + if( (past->past_InputDeviceID >= 0) && (past->past_NumInputChannels > 0) ) + { + pad = Pa_GetInternalDevice( past->past_InputDeviceID ); + hr = DirectSoundCaptureCreate( pad->pad_lpGUID, &dsw->dsw_pDirectSoundCapture, NULL ); + /* If this fails, then try each input device until we find one that works. */ + if( hr != DS_OK ) + { + int i; + ERR_RPT(("Creation of requested Audio Capture device '%s' failed.\n", + ((pad->pad_lpGUID == NULL) ? "Default" : pad->pad_Info.name) )); + for( i=0; i<Pa_CountDevices(); i++ ) + { + pad = Pa_GetInternalDevice( i ); + if( pad->pad_Info.maxInputChannels >= past->past_NumInputChannels ) + { + PRINT(("Try device '%s' instead.\n", pad->pad_Info.name )); + hr = DirectSoundCaptureCreate( pad->pad_lpGUID, &dsw->dsw_pDirectSoundCapture, NULL ); + if( hr == DS_OK ) break; + } + } + } + if( hr != DS_OK ) + { + ERR_RPT(("PortAudio: DirectSoundCaptureCreate() failed!\n")); + result = paHostError; + sPaHostError = hr; + goto error; + } + hr = DSW_InitInputBuffer( dsw, + (unsigned long) (past->past_SampleRate + 0.5), + past->past_NumInputChannels, numBytes ); + DBUG(("DSW_InitInputBuffer() returns %x\n", hr)); + if( hr != DS_OK ) + { + ERR_RPT(("PortAudio: DSW_InitInputBuffer() returns %x\n", hr)); + result = paHostError; + sPaHostError = hr; + goto error; + } + } +#endif /* SUPPORT_AUDIO_CAPTURE */ + /* Calculate scalar used in CPULoad calculation. */ + { + LARGE_INTEGER frequency; + if( QueryPerformanceFrequency( &frequency ) == 0 ) + { + pahsc->pahsc_InverseTicksPerUserBuffer = 0.0; + } + else + { + pahsc->pahsc_InverseTicksPerUserBuffer = past->past_SampleRate / + ( (double)frequency.QuadPart * past->past_FramesPerUserBuffer ); + DBUG(("pahsc_InverseTicksPerUserBuffer = %g\n", pahsc->pahsc_InverseTicksPerUserBuffer )); + } + } + return result; +error: + PaHost_CloseStream( past ); + return result; +} +/*************************************************************************/ +PaError PaHost_StartOutput( internalPortAudioStream *past ) +{ + HRESULT hr; + PaHostSoundControl *pahsc; + PaError result = paNoError; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + /* Give user callback a chance to pre-fill buffer. */ + result = Pa_TimeSlice( past ); + if( result != paNoError ) return result; // FIXME - what if finished? + hr = DSW_StartOutput( &pahsc->pahsc_DSoundWrapper ); + DBUG(("PaHost_StartOutput: DSW_StartOutput returned = 0x%X.\n", hr)); + if( hr != DS_OK ) + { + result = paHostError; + sPaHostError = hr; + goto error; + } +error: + return result; +} +/*************************************************************************/ +PaError PaHost_StartInput( internalPortAudioStream *past ) +{ + PaError result = paNoError; +#if SUPPORT_AUDIO_CAPTURE + HRESULT hr; + PaHostSoundControl *pahsc; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + hr = DSW_StartInput( &pahsc->pahsc_DSoundWrapper ); + DBUG(("Pa_StartStream: DSW_StartInput returned = 0x%X.\n", hr)); + if( hr != DS_OK ) + { + result = paHostError; + sPaHostError = hr; + goto error; + } +error: +#endif /* SUPPORT_AUDIO_CAPTURE */ + return result; +} +/*************************************************************************/ +PaError PaHost_StartEngine( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc; + PaError result = paNoError; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + past->past_StopNow = 0; + past->past_StopSoon = 0; + past->past_IsActive = 1; + /* Create timer that will wake us up so we can fill the DSound buffer. */ + { + int msecPerBuffer; + int resolution; + int bufsPerInterrupt; + + DBUG(("PaHost_StartEngine: past_NumUserBuffers = %d\n", past->past_NumUserBuffers)); + /* Decide how often to wake up and fill the buffers. */ + if( past->past_NumUserBuffers == 2 ) + { + /* Generate two timer interrupts per user buffer. */ + msecPerBuffer = (500 * past->past_FramesPerUserBuffer) / (int) past->past_SampleRate; + } + else + { + if ( past->past_NumUserBuffers >= 16 ) bufsPerInterrupt = past->past_NumUserBuffers/8; + else if ( past->past_NumUserBuffers >= 8 ) bufsPerInterrupt = 2; + else bufsPerInterrupt = 1; + + msecPerBuffer = 1000 * (bufsPerInterrupt * past->past_FramesPerUserBuffer) / (int) past->past_SampleRate; + + DBUG(("PaHost_StartEngine: bufsPerInterrupt = %d\n", bufsPerInterrupt)); + } + + DBUG(("PaHost_StartEngine: msecPerBuffer = %d\n", msecPerBuffer)); + + if( msecPerBuffer < 10 ) msecPerBuffer = 10; + else if( msecPerBuffer > 100 ) msecPerBuffer = 100; + DBUG(("PaHost_StartEngine: clipped msecPerBuffer = %d\n", msecPerBuffer)); + + resolution = msecPerBuffer/4; + pahsc->pahsc_TimerID = timeSetEvent( msecPerBuffer, resolution, (LPTIMECALLBACK) Pa_TimerCallback, + (DWORD) past, TIME_PERIODIC ); + } + if( pahsc->pahsc_TimerID == 0 ) + { + past->past_IsActive = 0; + result = paHostError; + sPaHostError = 0; + goto error; + } +error: + return result; +} +/*************************************************************************/ +PaError PaHost_StopEngine( internalPortAudioStream *past, int abort ) +{ + int timeoutMsec; + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return paNoError; + if( abort ) past->past_StopNow = 1; + past->past_StopSoon = 1; + /* Set timeout at 20% beyond maximum time we might wait. */ + timeoutMsec = (int) (1200.0 * pahsc->pahsc_FramesPerDSBuffer / past->past_SampleRate); + while( past->past_IsActive && (timeoutMsec > 0) ) + { + Sleep(10); + timeoutMsec -= 10; + } + if( pahsc->pahsc_TimerID != 0 ) + { + timeKillEvent(pahsc->pahsc_TimerID); /* Stop callback timer. */ + pahsc->pahsc_TimerID = 0; + } + return paNoError; +} +/*************************************************************************/ +PaError PaHost_StopInput( internalPortAudioStream *past, int abort ) +{ +#if SUPPORT_AUDIO_CAPTURE + HRESULT hr; + PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return paNoError; + (void) abort; + hr = DSW_StopInput( &pahsc->pahsc_DSoundWrapper ); + DBUG(("DSW_StopInput() result is %x\n", hr)); +#endif /* SUPPORT_AUDIO_CAPTURE */ + return paNoError; +} +/*************************************************************************/ +PaError PaHost_StopOutput( internalPortAudioStream *past, int abort ) +{ + HRESULT hr; + PaHostSoundControl *pahsc; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return paNoError; + (void) abort; + hr = DSW_StopOutput( &pahsc->pahsc_DSoundWrapper ); + DBUG(("DSW_StopOutput() result is %x\n", hr)); + return paNoError; +} +/*******************************************************************/ +PaError PaHost_CloseStream( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc; + if( past == NULL ) return paBadStreamPtr; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return paNoError; + DSW_Term( &pahsc->pahsc_DSoundWrapper ); + if( pahsc->pahsc_NativeBuffer ) + { + PaHost_FreeFastMemory( pahsc->pahsc_NativeBuffer, pahsc->pahsc_BytesPerBuffer ); /* MEM */ + pahsc->pahsc_NativeBuffer = NULL; + } + PaHost_FreeFastMemory( pahsc, sizeof(PaHostSoundControl) ); /* MEM */ + past->past_DeviceData = NULL; + return paNoError; +} + +/* Set minimal latency based on whether NT or Win95. + * NT has higher latency. + */ +static int PaHost_GetMinSystemLatency( void ) +{ + int minLatencyMsec; + /* Set minimal latency based on whether NT or other OS. + * NT has higher latency. + */ + OSVERSIONINFO osvi; + osvi.dwOSVersionInfoSize = sizeof( osvi ); + GetVersionEx( &osvi ); + DBUG(("PA - PlatformId = 0x%x\n", osvi.dwPlatformId )); + DBUG(("PA - MajorVersion = 0x%x\n", osvi.dwMajorVersion )); + DBUG(("PA - MinorVersion = 0x%x\n", osvi.dwMinorVersion )); + /* Check for NT */ + if( (osvi.dwMajorVersion == 4) && (osvi.dwPlatformId == 2) ) + { + minLatencyMsec = PA_WIN_NT_LATENCY; + } + else if(osvi.dwMajorVersion >= 5) + { + minLatencyMsec = PA_WIN_WDM_LATENCY; + } + else + { + minLatencyMsec = PA_WIN_9X_LATENCY; + } + return minLatencyMsec; +} + +/************************************************************************* +** Determine minimum number of buffers required for this host based +** on minimum latency. Latency can be optionally set by user by setting +** an environment variable. For example, to set latency to 200 msec, put: +** +** set PA_MIN_LATENCY_MSEC=200 +** +** in the AUTOEXEC.BAT file and reboot. +** If the environment variable is not set, then the latency will be determined +** based on the OS. Windows NT has higher latency than Win95. +*/ +#define PA_LATENCY_ENV_NAME ("PA_MIN_LATENCY_MSEC") +int Pa_GetMinNumBuffers( int framesPerBuffer, double sampleRate ) +{ + char envbuf[PA_ENV_BUF_SIZE]; + DWORD hresult; + int minLatencyMsec = 0; + double msecPerBuffer = (1000.0 * framesPerBuffer) / sampleRate; + int minBuffers; + /* Let user determine minimal latency by setting environment variable. */ + hresult = GetEnvironmentVariable( PA_LATENCY_ENV_NAME, envbuf, PA_ENV_BUF_SIZE ); + if( (hresult > 0) && (hresult < PA_ENV_BUF_SIZE) ) + { + minLatencyMsec = atoi( envbuf ); + } + else + { + minLatencyMsec = PaHost_GetMinSystemLatency(); +#if PA_USE_HIGH_LATENCY + PRINT(("PA - Minimum Latency set to %d msec!\n", minLatencyMsec )); +#endif + + } + minBuffers = (int) (1.0 + ((double)minLatencyMsec / msecPerBuffer)); + if( minBuffers < 2 ) minBuffers = 2; + return minBuffers; +} +/*************************************************************************/ +PaError PaHost_Term( void ) +{ + int i; + /* Free names allocated during enumeration. */ + for( i=0; i<sNumDevices; i++ ) + { + if( sDevices[i].pad_Info.name != NULL ) + { + free( (void *) sDevices[i].pad_Info.name ); + sDevices[i].pad_Info.name = NULL; + } + } + if( sDevices != NULL ) + { + PaHost_FreeFastMemory( sDevices, sNumDevices * sizeof(internalPortAudioDevice) ); /* MEM */ + sDevices = NULL; + sNumDevices = 0; + } + return 0; +} +void Pa_Sleep( long msec ) +{ + Sleep( msec ); +} +/************************************************************************* + * Allocate memory that can be accessed in real-time. + * This may need to be held in physical memory so that it is not + * paged to virtual memory. + * This call MUST be balanced with a call to PaHost_FreeFastMemory(). + * Memory will be set to zero. + */ +void *PaHost_AllocateFastMemory( long numBytes ) +{ + void *addr = GlobalAlloc( GPTR, numBytes ); /* FIXME - do we need physical memory? Use VirtualLock() */ /* MEM */ + return addr; +} +/************************************************************************* + * Free memory that could be accessed in real-time. + * This call MUST be balanced with a call to PaHost_AllocateFastMemory(). + */ +void PaHost_FreeFastMemory( void *addr, long numBytes ) +{ + if( addr != NULL ) GlobalFree( addr ); /* MEM */ +} +/***********************************************************************/ +PaError PaHost_StreamActive( internalPortAudioStream *past ) +{ + PaHostSoundControl *pahsc; + if( past == NULL ) return paBadStreamPtr; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + if( pahsc == NULL ) return paInternalError; + return (PaError) (past->past_IsActive); +} +/*************************************************************************/ +PaTimestamp Pa_StreamTime( PortAudioStream *stream ) +{ + DSoundWrapper *dsw; + internalPortAudioStream *past = (internalPortAudioStream *) stream; + PaHostSoundControl *pahsc; + if( past == NULL ) return paBadStreamPtr; + pahsc = (PaHostSoundControl *) past->past_DeviceData; + dsw = &pahsc->pahsc_DSoundWrapper; + return dsw->dsw_FramesPlayed; +} diff --git a/pd/portaudio_v18/pa_win_ds/portaudio.def b/pd/portaudio_v18/pa_win_ds/portaudio.def new file mode 100644 index 00000000..8012b99e --- /dev/null +++ b/pd/portaudio_v18/pa_win_ds/portaudio.def @@ -0,0 +1,28 @@ +LIBRARY PortAudio +DESCRIPTION 'PortAudio Portable interface to audio HW' + +EXPORTS + ; Explicit exports can go here + Pa_Initialize @1 + Pa_Terminate @2 + Pa_GetHostError @3 + Pa_GetErrorText @4 + Pa_CountDevices @5 + Pa_GetDefaultInputDeviceID @6 + Pa_GetDefaultOutputDeviceID @7 + Pa_GetDeviceInfo @8 + Pa_OpenStream @9 + Pa_OpenDefaultStream @10 + Pa_CloseStream @11 + Pa_StartStream @12 + Pa_StopStream @13 + Pa_StreamActive @14 + Pa_StreamTime @15 + Pa_GetCPULoad @16 + Pa_GetMinNumBuffers @17 + Pa_Sleep @18 + + ;123456789012345678901234567890123456 + ;000000000111111111122222222223333333 + + diff --git a/pd/portaudio_v18/pa_win_wmme/Makefile.cygwin b/pd/portaudio_v18/pa_win_wmme/Makefile.cygwin new file mode 100644 index 00000000..5cb4acef --- /dev/null +++ b/pd/portaudio_v18/pa_win_wmme/Makefile.cygwin @@ -0,0 +1,34 @@ + +# Makefile for PortAudio on cygwin +# Contributed by Bill Eldridge on 6/13/2001 + +ARCH= pa_win_wmme + +TESTS:= $(wildcard pa_tests/pa*.c pa_tests/debug*.c) + +.c.o: + -gcc -c -I./pa_common $< -o $*.o + -gcc $*.o -o $*.exe -L/usr/local/lib -L$(ARCH) -lportaudio.dll -lwinmm + +all: sharedlib tests + +sharedlib: ./pa_common/pa_lib.c + gcc -c -I./pa_common pa_common/pa_lib.c -o pa_common/pa_lib.o + gcc -c -I./pa_common pa_win_wmme/pa_win_wmme.c -o pa_win_wmme/pa_win_wmme.o + dlltool --export-all --output-def pa_win_wmme/pa_lib.def pa_common/pa_lib.o pa_win_wmme/pa_win_wmme.o + gcc -shared -Wl,--enable-auto-image-base -o pa_win_wmme/portaudio.dll -Wl,--out-implib=pa_win_wmme/libportaudio.dll.a pa_win_wmme/pa_lib.def pa_common/pa_lib.o pa_win_wmme/pa_win_wmme.o -L/usr/lib/w32api -lwinmm + cp pa_win_wmme/portaudio.dll /usr/local/bin + +tests: $(TESTS:.c=.o) + +sine: + gcc -c -I./pa_common pa_tests/patest_sine.c -o pa_tests/patest_sine.o + gcc pa_tests/patest_sine.o -o pa_tests/patest_sine.exe -L/usr/local/lib -lportaudio.dll -lwinmm + +clean: + -rm ./pa_tests/*.exe + +nothing: + gcc pa_tests/patest_sine.o -L/usr/lib/w32api -L./pa_win_wmme -lportaudio.dll -lwinmm + + diff --git a/pd/portaudio_v18/pa_win_wmme/pa_win_wmme.c b/pd/portaudio_v18/pa_win_wmme/pa_win_wmme.c new file mode 100644 index 00000000..9dc03826 --- /dev/null +++ b/pd/portaudio_v18/pa_win_wmme/pa_win_wmme.c @@ -0,0 +1,1714 @@ +/* + * $Id: pa_win_wmme.c,v 1.6.4.3 2003/04/28 17:43:48 philburk Exp $ + * pa_win_wmme.c + * Implementation of PortAudio for Windows MultiMedia Extensions (WMME) + * + * PortAudio Portable Real-Time Audio Library + * Latest Version at: http://www.portaudio.com + * + * Authors: Ross Bencina and Phil Burk + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * Any person wishing to distribute modifications to the Software is + * requested to send the modifications to the original developer so that + * they can be incorporated into the canonical version. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +/* + All memory allocations and frees are marked with MEM for quick review. +*/ + +/* Modification History: + PLB = Phil Burk + JM = Julien Maillard + RDB = Ross Bencina + PLB20010402 - sDevicePtrs now allocates based on sizeof(pointer) + PLB20010413 - check for excessive numbers of channels + PLB20010422 - apply Mike Berry's changes for CodeWarrior on PC + including condition including of memory.h, + and explicit typecasting on memory allocation + PLB20010802 - use GlobalAlloc for sDevicesPtr instead of PaHost_AllocFastMemory + PLB20010816 - pass process instead of thread to SetPriorityClass() + PLB20010927 - use number of frames instead of real-time for CPULoad calculation. + JM20020118 - prevent hung thread when buffers underflow. + PLB20020321 - detect Win XP versus NT, 9x; fix DBUG typo; removed init of CurrentCount + RDB20020411 - various renaming cleanups, factored streamData alloc and cpu usage init + RDB20020417 - stopped counting WAVE_MAPPER when there were no real devices + refactoring, renaming and fixed a few edge case bugs + PLB20020612 - added 8000.0 Hz to custom sampling rates array +*/ +#pragma warning (disable: 4115) +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <windows.h> +#include <mmsystem.h> +#include <process.h> +/* PLB20010422 - "memory.h" doesn't work on CodeWarrior for PC. Thanks Mike Berry for the mod. */ +#ifndef __MWERKS__ +#include <malloc.h> +#include <memory.h> +#endif /* __MWERKS__ */ +#include "portaudio.h" +#include "pa_host.h" +#include "pa_trace.h" + +/************************************************* Constants ********/ +#define PA_TRACK_MEMORY (0) + +#define PA_USE_TIMER_CALLBACK (0) /* Select between two options for background task. 0=thread, 1=timer */ +/* Switches for debugging. */ +#define PA_SIMULATE_UNDERFLOW (0) /* Set to one to force an underflow of the output buffer. */ + +/* To trace program, enable TRACE_REALTIME_EVENTS in pa_trace.h */ +#define PA_TRACE_RUN (0) +#define PA_TRACE_START_STOP (1) + +#define PA_USE_HIGH_LATENCY (0) /* For debugging glitches. */ + +#if PA_USE_HIGH_LATENCY + #define PA_MIN_MSEC_PER_HOST_BUFFER (100) + #define PA_MAX_MSEC_PER_HOST_BUFFER (300) /* Do not exceed unless user buffer exceeds */ + #define PA_MIN_NUM_HOST_BUFFERS (4) + #define PA_MAX_NUM_HOST_BUFFERS (16) /* OK to exceed if necessary */ + #define PA_WIN_9X_LATENCY (400) +#else + #define PA_MIN_MSEC_PER_HOST_BUFFER (10) + #define PA_MAX_MSEC_PER_HOST_BUFFER (100) /* Do not exceed unless user buffer exceeds */ + #define PA_MIN_NUM_HOST_BUFFERS (3) + #define PA_MAX_NUM_HOST_BUFFERS (16) /* OK to exceed if necessary */ + #define PA_WIN_9X_LATENCY (200) +#endif +#define MIN_TIMEOUT_MSEC (1000) + +/* +** Use higher latency for NT because it is even worse at real-time +** operation than Win9x. +*/ +#define PA_WIN_NT_LATENCY (PA_WIN_9X_LATENCY * 2) +#define PA_WIN_WDM_LATENCY (PA_WIN_9X_LATENCY) + +#if PA_SIMULATE_UNDERFLOW +static gUnderCallbackCounter = 0; +#define UNDER_SLEEP_AT (40) +#define UNDER_SLEEP_FOR (500) +#endif + +#define PRINT(x) { printf x; fflush(stdout); } +#define ERR_RPT(x) PRINT(x) +#define DBUG(x) /* PRINT(x) */ +#define DBUGX(x) /* PRINT(x) */ +/************************************************* Definitions ********/ +/************************************************************** + * Structure for internal host specific stream data. + * This is allocated on a per stream basis. + */ +typedef struct PaWMMEStreamData +{ + /* Input -------------- */ + HWAVEIN hWaveIn; + WAVEHDR *inputBuffers; + int currentInputBuffer; + int bytesPerHostInputBuffer; + int bytesPerUserInputBuffer; /* native buffer size in bytes */ + /* Output -------------- */ + HWAVEOUT hWaveOut; + WAVEHDR *outputBuffers; + int currentOutputBuffer; + int bytesPerHostOutputBuffer; + int bytesPerUserOutputBuffer; /* native buffer size in bytes */ + /* Run Time -------------- */ + PaTimestamp framesPlayed; + long lastPosition; /* used to track frames played. */ + /* For measuring CPU utilization. */ + LARGE_INTEGER entryCount; + double inverseTicksPerHostBuffer; + /* Init Time -------------- */ + int numHostBuffers; + int framesPerHostBuffer; + int userBuffersPerHostBuffer; + CRITICAL_SECTION streamLock; /* Mutext to prevent threads from colliding. */ + INT streamLockInited; +#if PA_USE_TIMER_CALLBACK + BOOL ifInsideCallback; /* Test for reentrancy. */ + MMRESULT timerID; +#else + HANDLE abortEvent; + int abortEventInited; + HANDLE bufferEvent; + int bufferEventInited; + HANDLE engineThread; + DWORD engineThreadID; +#endif +} +PaWMMEStreamData; +/************************************************* Shared Data ********/ +/* FIXME - put Mutex around this shared data. */ +static int sNumInputDevices = 0; +static int sNumOutputDevices = 0; +static int sNumDevices = 0; +static PaDeviceInfo **sDevicePtrs = NULL; +static int sDefaultInputDeviceID = paNoDevice; +static int sDefaultOutputDeviceID = paNoDevice; +static int sPaHostError = 0; +static const char sMapperSuffixInput[] = " - Input"; +static const char sMapperSuffixOutput[] = " - Output"; + +#if PA_TRACK_MEMORY +static int sNumAllocations = 0; +#endif + +/************************************************* Macros ********/ +/* Convert external PA ID to an internal ID that includes WAVE_MAPPER */ +#define PaDeviceIdToWinId(id) (((id) < sNumInputDevices) ? (id - 1) : (id - sNumInputDevices - 1)) +/************************************************* Prototypes **********/ + +void Pa_InitializeNumDevices( void ); +PaError Pa_AllocateDevicePtrs( void ); + +static void CALLBACK Pa_TimerCallback(UINT uID, UINT uMsg, + DWORD dwUser, DWORD dw1, DWORD dw2); +PaError PaHost_GetTotalBufferFrames( internalPortAudioStream *past ); +static PaError PaHost_UpdateStreamTime( PaWMMEStreamData *wmmeStreamData ); +static PaError PaHost_BackgroundManager( internalPortAudioStream *past ); + +static void *PaHost_AllocateTrackedMemory( long numBytes ); +static void PaHost_FreeTrackedMemory( void *addr ); + +/*******************************************************************/ +static PaError PaHost_AllocateWMMEStreamData( internalPortAudioStream *stream ) +{ + PaError result = paNoError; + PaWMMEStreamData *wmmeStreamData; + + wmmeStreamData = (PaWMMEStreamData *) PaHost_AllocateFastMemory(sizeof(PaWMMEStreamData)); /* MEM */ + if( wmmeStreamData == NULL ) + { + result = paInsufficientMemory; + goto error; + } + memset( wmmeStreamData, 0, sizeof(PaWMMEStreamData) ); + stream->past_DeviceData = (void *) wmmeStreamData; + + return result; + +error: + return result; +} + +/*******************************************************************/ +static void PaHost_FreeWMMEStreamData( internalPortAudioStream *internalStream ) +{ + PaWMMEStreamData *wmmeStreamData = (PaWMMEStreamData *) internalStream->past_DeviceData; + + PaHost_FreeFastMemory( wmmeStreamData, sizeof(PaWMMEStreamData) ); /* MEM */ + internalStream->past_DeviceData = NULL; +} +/*************************************************************************/ +static PaWMMEStreamData* PaHost_GetWMMEStreamData( internalPortAudioStream* internalStream ) +{ + PaWMMEStreamData *result = NULL; + + if( internalStream != NULL ) + { + result = (PaWMMEStreamData *) internalStream->past_DeviceData; + } + return result; +} +/********************************* BEGIN CPU UTILIZATION MEASUREMENT ****/ +/* FIXME: the cpu usage code should be factored out into a common module */ +static void Pa_InitializeCpuUsageScalar( internalPortAudioStream *stream ) +{ + PaWMMEStreamData *wmmeStreamData = (PaWMMEStreamData *) stream->past_DeviceData; + + LARGE_INTEGER frequency; + if( QueryPerformanceFrequency( &frequency ) == 0 ) + { + wmmeStreamData->inverseTicksPerHostBuffer = 0.0; + } + else + { + wmmeStreamData->inverseTicksPerHostBuffer = stream->past_SampleRate / + ( (double)frequency.QuadPart * stream->past_FramesPerUserBuffer * wmmeStreamData->userBuffersPerHostBuffer ); + DBUG(("inverseTicksPerHostBuffer = %g\n", wmmeStreamData->inverseTicksPerHostBuffer )); + } +} +static void Pa_StartUsageCalculation( internalPortAudioStream *stream ) +{ + PaWMMEStreamData *wmmeStreamData = (PaWMMEStreamData *) stream->past_DeviceData; + + if( wmmeStreamData == NULL ) return; + /* Query system timer for usage analysis and to prevent overuse of CPU. */ + QueryPerformanceCounter( &wmmeStreamData->entryCount ); +} +static void Pa_EndUsageCalculation( internalPortAudioStream *stream ) +{ + LARGE_INTEGER CurrentCount; + PaWMMEStreamData *wmmeStreamData = (PaWMMEStreamData *) stream->past_DeviceData; + + if( wmmeStreamData == NULL ) return; + /* + * Measure CPU utilization during this callback. Note that this calculation + * assumes that we had the processor the whole time. + */ +#define LOWPASS_COEFFICIENT_0 (0.9) +#define LOWPASS_COEFFICIENT_1 (0.99999 - LOWPASS_COEFFICIENT_0) + if( QueryPerformanceCounter( &CurrentCount ) ) + { + LONGLONG InsideCount = CurrentCount.QuadPart - wmmeStreamData->entryCount.QuadPart; + double newUsage = InsideCount * wmmeStreamData->inverseTicksPerHostBuffer; + stream->past_Usage = (LOWPASS_COEFFICIENT_0 * stream->past_Usage) + + (LOWPASS_COEFFICIENT_1 * newUsage); + } +} +/****************************************** END CPU UTILIZATION *******/ + +static void Pa_InitializeNumDevices( void ) +{ + sNumInputDevices = waveInGetNumDevs(); + if( sNumInputDevices > 0 ) + { + sNumInputDevices += 1; /* add one extra for the WAVE_MAPPER */ + sDefaultInputDeviceID = 0; + } + else + { + sDefaultInputDeviceID = paNoDevice; + } + + sNumOutputDevices = waveOutGetNumDevs(); + if( sNumOutputDevices > 0 ) + { + sNumOutputDevices += 1; /* add one extra for the WAVE_MAPPER */ + sDefaultOutputDeviceID = sNumInputDevices; + } + else + { + sDefaultOutputDeviceID = paNoDevice; + } + + sNumDevices = sNumInputDevices + sNumOutputDevices; +} + +static PaError Pa_AllocateDevicePtrs( void ) +{ + int numBytes; + int i; + + /* Allocate structures to hold device info. */ + /* PLB20010402 - was allocating too much memory. */ + /* numBytes = sNumDevices * sizeof(PaDeviceInfo); // PLB20010402 */ + + if( sNumDevices > 0 ) + { + numBytes = sNumDevices * sizeof(PaDeviceInfo *); /* PLB20010402 */ + sDevicePtrs = (PaDeviceInfo **) PaHost_AllocateTrackedMemory( numBytes ); /* MEM */ + if( sDevicePtrs == NULL ) return paInsufficientMemory; + + for( i = 0; i < sNumDevices; i++ ) + sDevicePtrs[i] = NULL; /* RDB20020417 explicitly set each ptr to NULL */ + } + else + { + sDevicePtrs = NULL; + } + + return paNoError; +} +/*************************************************************************/ +long Pa_GetHostError() +{ + return sPaHostError; +} +/*************************************************************************/ +int Pa_CountDevices() +{ + if( PaHost_IsInitialized() ) + return sNumDevices; + else + return 0; +} +/************************************************************************* + * If a PaDeviceInfo structure has not already been created, + * then allocate one and fill it in for the selected device. + * + * We create one extra input and one extra output device for the WAVE_MAPPER. + * [Does anyone know how to query the default device and get its name?] + */ +const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceID id ) +{ +#define NUM_STANDARDSAMPLINGRATES 3 /* 11025, 22050, 44100 */ + static DWORD customSamplingRates[] = { 8000, 32000, 48000, 64000, 88200, 96000 }; +#define NUM_CUSTOMSAMPLINGRATES (sizeof(customSamplingRates)/sizeof(DWORD)) +#define MAX_NUMSAMPLINGRATES (NUM_STANDARDSAMPLINGRATES+NUM_CUSTOMSAMPLINGRATES) + + PaDeviceInfo *deviceInfo; + double *sampleRates; /* non-const ptr */ + int i; + char *s; + + DBUG(( "Pa_GetDeviceInfo( %d )\n", id )); + if( id < 0 || id >= sNumDevices ) + return NULL; + if( sDevicePtrs[ id ] != NULL ) + { + return sDevicePtrs[ id ]; + } + deviceInfo = (PaDeviceInfo *)PaHost_AllocateTrackedMemory( sizeof(PaDeviceInfo) ); /* MEM */ + if( deviceInfo == NULL ) return NULL; + deviceInfo->structVersion = 1; + deviceInfo->maxInputChannels = 0; + deviceInfo->maxOutputChannels = 0; + deviceInfo->numSampleRates = 0; + sampleRates = (double*)PaHost_AllocateTrackedMemory( MAX_NUMSAMPLINGRATES * sizeof(double) ); /* MEM */ + deviceInfo->sampleRates = sampleRates; + deviceInfo->nativeSampleFormats = paInt16; /* should query for higher bit depths below */ + if( id < sNumInputDevices ) + { + /* input device */ + int inputMmID = PaDeviceIdToWinId(id); + WAVEINCAPS wic; + if( waveInGetDevCaps( inputMmID, &wic, sizeof( WAVEINCAPS ) ) != MMSYSERR_NOERROR ) + goto error; + + /* Append I/O suffix to WAVE_MAPPER device. */ + if( inputMmID == WAVE_MAPPER ) + { + s = (char *) PaHost_AllocateTrackedMemory( strlen( wic.szPname ) + 1 + sizeof(sMapperSuffixInput) ); /* MEM */ + strcpy( s, wic.szPname ); + strcat( s, sMapperSuffixInput ); + } + else + { + s = (char *) PaHost_AllocateTrackedMemory( strlen( wic.szPname ) + 1 ); /* MEM */ + strcpy( s, wic.szPname ); + } + deviceInfo->name = s; + deviceInfo->maxInputChannels = wic.wChannels; + DBUG(( "Pa_GetDeviceInfo: input %s, maxChannels = %d\n", deviceInfo->name, deviceInfo->maxInputChannels )); + /* Sometimes a device can return a rediculously large number of channels. + * This happened with an SBLive card on a Windows ME box. + * If that happens, then force it to 2 channels. PLB20010413 + */ + if( (deviceInfo->maxInputChannels < 1) || (deviceInfo->maxInputChannels > 256) ) + { + ERR_RPT(("Pa_GetDeviceInfo: Num input channels reported as %d! Changed to 2.\n", deviceInfo->maxOutputChannels )); + deviceInfo->maxInputChannels = 2; + } + /* Add a sample rate to the list if we can do stereo 16 bit at that rate + * based on the format flags. */ + if( wic.dwFormats & WAVE_FORMAT_1M16 ||wic.dwFormats & WAVE_FORMAT_1S16 ) + sampleRates[ deviceInfo->numSampleRates++ ] = 11025.; + if( wic.dwFormats & WAVE_FORMAT_2M16 ||wic.dwFormats & WAVE_FORMAT_2S16 ) + sampleRates[ deviceInfo->numSampleRates++ ] = 22050.; + if( wic.dwFormats & WAVE_FORMAT_4M16 ||wic.dwFormats & WAVE_FORMAT_4S16 ) + sampleRates[ deviceInfo->numSampleRates++ ] = 44100.; + /* Add a sample rate to the list if we can do stereo 16 bit at that rate + * based on opening the device successfully. */ + for( i=0; i < NUM_CUSTOMSAMPLINGRATES; i++ ) + { + WAVEFORMATEX wfx; + wfx.wFormatTag = WAVE_FORMAT_PCM; + wfx.nSamplesPerSec = customSamplingRates[i]; + wfx.wBitsPerSample = 16; + wfx.cbSize = 0; /* ignored */ + wfx.nChannels = (WORD)deviceInfo->maxInputChannels; + wfx.nAvgBytesPerSec = wfx.nChannels * wfx.nSamplesPerSec * sizeof(short); + wfx.nBlockAlign = (WORD)(wfx.nChannels * sizeof(short)); + if( waveInOpen( NULL, inputMmID, &wfx, 0, 0, WAVE_FORMAT_QUERY ) == MMSYSERR_NOERROR ) + { + sampleRates[ deviceInfo->numSampleRates++ ] = customSamplingRates[i]; + } + } + + } + else if( id - sNumInputDevices < sNumOutputDevices ) + { + /* output device */ + int outputMmID = PaDeviceIdToWinId(id); + WAVEOUTCAPS woc; + if( waveOutGetDevCaps( outputMmID, &woc, sizeof( WAVEOUTCAPS ) ) != MMSYSERR_NOERROR ) + goto error; + /* Append I/O suffix to WAVE_MAPPER device. */ + if( outputMmID == WAVE_MAPPER ) + { + s = (char *) PaHost_AllocateTrackedMemory( strlen( woc.szPname ) + 1 + sizeof(sMapperSuffixOutput) ); /* MEM */ + strcpy( s, woc.szPname ); + strcat( s, sMapperSuffixOutput ); + } + else + { + s = (char *) PaHost_AllocateTrackedMemory( strlen( woc.szPname ) + 1 ); /* MEM */ + strcpy( s, woc.szPname ); + } + deviceInfo->name = s; + deviceInfo->maxOutputChannels = woc.wChannels; + DBUG(( "Pa_GetDeviceInfo: output %s, maxChannels = %d\n", deviceInfo->name, deviceInfo->maxOutputChannels )); + /* Sometimes a device can return a rediculously large number of channels. + * This happened with an SBLive card on a Windows ME box. + * It also happens on Win XP! + */ + if( (deviceInfo->maxOutputChannels < 1) || (deviceInfo->maxOutputChannels > 256) ) + { +#if 1 + deviceInfo->maxOutputChannels = 2; +#else + /* If channel max is goofy, then query for max channels. PLB20020228 + * This doesn't seem to help. Disable code for now. Remove it later. + */ + ERR_RPT(("Pa_GetDeviceInfo: Num output channels reported as %d!", deviceInfo->maxOutputChannels )); + deviceInfo->maxOutputChannels = 0; + /* Attempt to find the correct maximum by querying the device. */ + for( i=2; i<16; i += 2 ) + { + WAVEFORMATEX wfx; + wfx.wFormatTag = WAVE_FORMAT_PCM; + wfx.nSamplesPerSec = 44100; + wfx.wBitsPerSample = 16; + wfx.cbSize = 0; /* ignored */ + wfx.nChannels = (WORD) i; + wfx.nAvgBytesPerSec = wfx.nChannels * wfx.nSamplesPerSec * sizeof(short); + wfx.nBlockAlign = (WORD)(wfx.nChannels * sizeof(short)); + if( waveOutOpen( NULL, outputMmID, &wfx, 0, 0, WAVE_FORMAT_QUERY ) == MMSYSERR_NOERROR ) + { + deviceInfo->maxOutputChannels = i; + } + else + { + break; + } + } +#endif + ERR_RPT((" Changed to %d.\n", deviceInfo->maxOutputChannels )); + } + + /* Add a sample rate to the list if we can do stereo 16 bit at that rate + * based on the format flags. */ + if( woc.dwFormats & WAVE_FORMAT_1M16 ||woc.dwFormats & WAVE_FORMAT_1S16 ) + sampleRates[ deviceInfo->numSampleRates++ ] = 11025.; + if( woc.dwFormats & WAVE_FORMAT_2M16 ||woc.dwFormats & WAVE_FORMAT_2S16 ) + sampleRates[ deviceInfo->numSampleRates++ ] = 22050.; + if( woc.dwFormats & WAVE_FORMAT_4M16 ||woc.dwFormats & WAVE_FORMAT_4S16 ) + sampleRates[ deviceInfo->numSampleRates++ ] = 44100.; + + /* Add a sample rate to the list if we can do stereo 16 bit at that rate + * based on opening the device successfully. */ + for( i=0; i < NUM_CUSTOMSAMPLINGRATES; i++ ) + { + WAVEFORMATEX wfx; + wfx.wFormatTag = WAVE_FORMAT_PCM; + wfx.nSamplesPerSec = customSamplingRates[i]; + wfx.wBitsPerSample = 16; + wfx.cbSize = 0; /* ignored */ + wfx.nChannels = (WORD)deviceInfo->maxOutputChannels; + wfx.nAvgBytesPerSec = wfx.nChannels * wfx.nSamplesPerSec * sizeof(short); + wfx.nBlockAlign = (WORD)(wfx.nChannels * sizeof(short)); + DBUG(( "Pa_GetDeviceInfo: waveOutOpen( ... WAVE_FORMAT_QUERY at SR = %d\n", customSamplingRates[i] )); + if( waveOutOpen( NULL, outputMmID, &wfx, 0, 0, WAVE_FORMAT_QUERY ) == MMSYSERR_NOERROR ) + { + sampleRates[ deviceInfo->numSampleRates++ ] = customSamplingRates[i]; + } + } + } + DBUG(( "Pa_GetDeviceInfo: done.\n" )); + sDevicePtrs[ id ] = deviceInfo; + return deviceInfo; + +error: + PaHost_FreeTrackedMemory( sampleRates ); /* MEM */ + PaHost_FreeTrackedMemory( deviceInfo ); /* MEM */ + + return NULL; +} +/************************************************************************* + * Returns recommended device ID. + * On the PC, the recommended device can be specified by the user by + * setting an environment variable. For example, to use device #1. + * + * set PA_RECOMMENDED_OUTPUT_DEVICE=1 + * + * The user should first determine the available device ID by using + * the supplied application "pa_devs". + */ +#define PA_ENV_BUF_SIZE (32) +#define PA_REC_IN_DEV_ENV_NAME ("PA_RECOMMENDED_INPUT_DEVICE") +#define PA_REC_OUT_DEV_ENV_NAME ("PA_RECOMMENDED_OUTPUT_DEVICE") +static PaDeviceID PaHost_GetEnvDefaultDeviceID( char *envName ) +{ + DWORD hresult; + char envbuf[PA_ENV_BUF_SIZE]; + PaDeviceID recommendedID = paNoDevice; + + /* Let user determine default device by setting environment variable. */ + hresult = GetEnvironmentVariable( envName, envbuf, PA_ENV_BUF_SIZE ); + if( (hresult > 0) && (hresult < PA_ENV_BUF_SIZE) ) + { + recommendedID = atoi( envbuf ); + } + return recommendedID; +} +/********************************************************************** + * Check for environment variable, else query devices and use result. + */ +PaDeviceID Pa_GetDefaultInputDeviceID( void ) +{ + PaDeviceID result; + + result = PaHost_GetEnvDefaultDeviceID( PA_REC_IN_DEV_ENV_NAME ); + if( result == paNoDevice || result < 0 || result >= sNumInputDevices ) + { + result = sDefaultInputDeviceID; + } + return result; +} +PaDeviceID Pa_GetDefaultOutputDeviceID( void ) +{ + PaDeviceID result; + + result = PaHost_GetEnvDefaultDeviceID( PA_REC_OUT_DEV_ENV_NAME ); + if( result == paNoDevice || result < sNumInputDevices || result >= sNumDevices ) + { + result = sDefaultOutputDeviceID; + } + return result; +} +/********************************************************************** + * Initialize Host dependant part of API. + */ +PaError PaHost_Init( void ) +{ + +#if PA_TRACK_MEMORY + PRINT(("PaHost_Init: sNumAllocations = %d\n", sNumAllocations )); +#endif + +#if PA_SIMULATE_UNDERFLOW + PRINT(("WARNING - Underflow Simulation Enabled - Expect a Big Glitch!!!\n")); +#endif + + + Pa_InitializeNumDevices(); + + return Pa_AllocateDevicePtrs(); +} + +/********************************************************************** + * Check WAVE buffers to see if they are done. + * Fill any available output buffers and use any available + * input buffers by calling user callback. + * + * This routine will loop until: + * user callback returns !=0 OR + * all output buffers are filled OR + * past->past_StopSoon is set OR + * an error occurs when calling WMME. + * + * Returns >0 when user requests a stop, <0 on error. + * + */ +static PaError Pa_TimeSlice( internalPortAudioStream *stream ) +{ + PaError result = paNoError; + MMRESULT mmresult; + char *inBufPtr; + char *outBufPtr; + int gotInput = 0; + int gotOutput = 0; + int i; + int buffersProcessed = 0; + int done = 0; + PaWMMEStreamData *wmmeStreamData = (PaWMMEStreamData *) stream->past_DeviceData; + + if( wmmeStreamData == NULL ) return paInternalError; + + stream->past_NumCallbacks += 1; +#if PA_TRACE_RUN + AddTraceMessage("Pa_TimeSlice: past_NumCallbacks ", stream->past_NumCallbacks ); +#endif + + /* JM20020118 - prevent hung thread when buffers underflow. */ + /* while( !done ) /* BAD */ + while( !done && !stream->past_StopSoon ) /* GOOD */ + { +#if PA_SIMULATE_UNDERFLOW + if(gUnderCallbackCounter++ == UNDER_SLEEP_AT) + { + Sleep(UNDER_SLEEP_FOR); + } +#endif + + /* If we are using output, then we need an empty output buffer. */ + gotOutput = 0; + outBufPtr = NULL; + if( stream->past_NumOutputChannels > 0 ) + { + if((wmmeStreamData->outputBuffers[ wmmeStreamData->currentOutputBuffer ].dwFlags & WHDR_DONE) == 0) + { + break; /* If none empty then bail and try again later. */ + } + else + { + outBufPtr = wmmeStreamData->outputBuffers[ wmmeStreamData->currentOutputBuffer ].lpData; + gotOutput = 1; + } + } + /* Use an input buffer if one is available. */ + gotInput = 0; + inBufPtr = NULL; + if( ( stream->past_NumInputChannels > 0 ) && + (wmmeStreamData->inputBuffers[ wmmeStreamData->currentInputBuffer ].dwFlags & WHDR_DONE) ) + { + inBufPtr = wmmeStreamData->inputBuffers[ wmmeStreamData->currentInputBuffer ].lpData; + gotInput = 1; +#if PA_TRACE_RUN + AddTraceMessage("Pa_TimeSlice: got input buffer at ", (int)inBufPtr ); + AddTraceMessage("Pa_TimeSlice: got input buffer # ", wmmeStreamData->currentInputBuffer ); +#endif + + } + /* If we can't do anything then bail out. */ + if( !gotInput && !gotOutput ) break; + buffersProcessed += 1; + /* Each Wave buffer contains multiple user buffers so do them all now. */ + /* Base Usage on time it took to process one host buffer. */ + Pa_StartUsageCalculation( stream ); + for( i=0; i<wmmeStreamData->userBuffersPerHostBuffer; i++ ) + { + if( done ) + { + if( gotOutput ) + { + /* Clear remainder of wave buffer if we are waiting for stop. */ + AddTraceMessage("Pa_TimeSlice: zero rest of wave buffer ", i ); + memset( outBufPtr, 0, wmmeStreamData->bytesPerUserOutputBuffer ); + } + } + else + { + /* Convert 16 bit native data to user data and call user routine. */ + result = Pa_CallConvertInt16( stream, (short *) inBufPtr, (short *) outBufPtr ); + if( result != 0) done = 1; + } + if( gotInput ) inBufPtr += wmmeStreamData->bytesPerUserInputBuffer; + if( gotOutput) outBufPtr += wmmeStreamData->bytesPerUserOutputBuffer; + } + Pa_EndUsageCalculation( stream ); + /* Send WAVE buffer to Wave Device to be refilled. */ + if( gotInput ) + { + mmresult = waveInAddBuffer( wmmeStreamData->hWaveIn, + &wmmeStreamData->inputBuffers[ wmmeStreamData->currentInputBuffer ], + sizeof(WAVEHDR) ); + if( mmresult != MMSYSERR_NOERROR ) + { + sPaHostError = mmresult; + result = paHostError; + break; + } + wmmeStreamData->currentInputBuffer = (wmmeStreamData->currentInputBuffer+1 >= wmmeStreamData->numHostBuffers) ? + 0 : wmmeStreamData->currentInputBuffer+1; + } + /* Write WAVE buffer to Wave Device. */ + if( gotOutput ) + { +#if PA_TRACE_START_STOP + AddTraceMessage( "Pa_TimeSlice: writing buffer ", wmmeStreamData->currentOutputBuffer ); +#endif + mmresult = waveOutWrite( wmmeStreamData->hWaveOut, + &wmmeStreamData->outputBuffers[ wmmeStreamData->currentOutputBuffer ], + sizeof(WAVEHDR) ); + if( mmresult != MMSYSERR_NOERROR ) + { + sPaHostError = mmresult; + result = paHostError; + break; + } + wmmeStreamData->currentOutputBuffer = (wmmeStreamData->currentOutputBuffer+1 >= wmmeStreamData->numHostBuffers) ? + 0 : wmmeStreamData->currentOutputBuffer+1; + } + + } + +#if PA_TRACE_RUN + AddTraceMessage("Pa_TimeSlice: buffersProcessed ", buffersProcessed ); +#endif + return (result != 0) ? result : done; +} + +/*******************************************************************/ +static PaError PaHost_BackgroundManager( internalPortAudioStream *stream ) +{ + PaError result = paNoError; + int i; + int numQueuedoutputBuffers = 0; + PaWMMEStreamData *wmmeStreamData = (PaWMMEStreamData *) stream->past_DeviceData; + + /* Has someone asked us to abort by calling Pa_AbortStream()? */ + if( stream->past_StopNow ) + { + stream->past_IsActive = 0; /* Will cause thread to return. */ + } + /* Has someone asked us to stop by calling Pa_StopStream() + * OR has a user callback returned '1' to indicate finished. + */ + else if( stream->past_StopSoon ) + { + /* Poll buffer and when all have played then exit thread. */ + /* Count how many output buffers are queued. */ + numQueuedoutputBuffers = 0; + if( stream->past_NumOutputChannels > 0 ) + { + for( i=0; i<wmmeStreamData->numHostBuffers; i++ ) + { + if( !( wmmeStreamData->outputBuffers[ i ].dwFlags & WHDR_DONE) ) + { +#if PA_TRACE_START_STOP + AddTraceMessage( "PaHost_BackgroundManager: waiting for buffer ", i ); +#endif + numQueuedoutputBuffers++; + } + } + } +#if PA_TRACE_START_STOP + AddTraceMessage( "PaHost_BackgroundManager: numQueuedoutputBuffers ", numQueuedoutputBuffers ); +#endif + if( numQueuedoutputBuffers == 0 ) + { + stream->past_IsActive = 0; /* Will cause thread to return. */ + } + } + else + { + /* Process full input buffer and fill up empty output buffers. */ + if( (result = Pa_TimeSlice( stream )) != 0) + { + /* User callback has asked us to stop. */ +#if PA_TRACE_START_STOP + AddTraceMessage( "PaHost_BackgroundManager: TimeSlice() returned ", result ); +#endif + stream->past_StopSoon = 1; /* Request that audio play out then stop. */ + result = paNoError; + } + } + + PaHost_UpdateStreamTime( wmmeStreamData ); + return result; +} + +#if PA_USE_TIMER_CALLBACK +/*******************************************************************/ +static void CALLBACK Pa_TimerCallback(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) +{ + internalPortAudioStream *stream; + PaWMMEStreamData *wmmeStreamData; + PaError result; + + stream = (internalPortAudioStream *) dwUser; + if( stream == NULL ) return; + wmmeStreamData = (PaWMMEStreamData *) stream->past_DeviceData; + if( wmmeStreamData == NULL ) return; + if( wmmeStreamData->ifInsideCallback ) + { + if( wmmeStreamData->timerID != 0 ) + { + timeKillEvent(wmmeStreamData->timerID); /* Stop callback timer. */ + wmmeStreamData->timerID = 0; + } + return; + } + wmmeStreamData->ifInsideCallback = 1; + /* Manage flags and audio processing. */ + result = PaHost_BackgroundManager( stream ); + if( result != paNoError ) + { + stream->past_IsActive = 0; + } + wmmeStreamData->ifInsideCallback = 0; +} +#else /* PA_USE_TIMER_CALLBACK */ +/*******************************************************************/ +static DWORD WINAPI WinMMPa_OutputThreadProc( void *pArg ) +{ + internalPortAudioStream *stream; + PaWMMEStreamData *wmmeStreamData; + HANDLE events[2]; + int numEvents = 0; + DWORD result = 0; + DWORD waitResult; + DWORD numTimeouts = 0; + DWORD timeOut; + stream = (internalPortAudioStream *) pArg; + wmmeStreamData = (PaWMMEStreamData *) stream->past_DeviceData; +#if PA_TRACE_START_STOP + AddTraceMessage( "WinMMPa_OutputThreadProc: timeoutPeriod", timeoutPeriod ); + AddTraceMessage( "WinMMPa_OutputThreadProc: past_NumUserBuffers", stream->past_NumUserBuffers ); +#endif + /* Calculate timeOut as half the time it would take to play all buffers. */ + timeOut = (DWORD) (500.0 * PaHost_GetTotalBufferFrames( stream ) / stream->past_SampleRate); + /* Get event(s) ready for wait. */ + events[numEvents++] = wmmeStreamData->bufferEvent; + if( wmmeStreamData->abortEventInited ) events[numEvents++] = wmmeStreamData->abortEvent; + /* Stay in this thread as long as we are "active". */ + while( stream->past_IsActive ) + { + /*******************************************************************/ + /******** WAIT here for an event from WMME or PA *******************/ + /*******************************************************************/ + waitResult = WaitForMultipleObjects( numEvents, events, FALSE, timeOut ); + /* Error? */ + if( waitResult == WAIT_FAILED ) + { + sPaHostError = GetLastError(); + result = paHostError; + stream->past_IsActive = 0; + } + /* Timeout? Don't stop. Just keep polling for DONE.*/ + else if( waitResult == WAIT_TIMEOUT ) + { +#if PA_TRACE_START_STOP + AddTraceMessage( "WinMMPa_OutputThreadProc: timed out ", numQueuedoutputBuffers ); +#endif + numTimeouts += 1; + } + /* Manage flags and audio processing. */ + result = PaHost_BackgroundManager( stream ); + if( result != paNoError ) + { + stream->past_IsActive = 0; + } + } + return result; +} +#endif + +/*******************************************************************/ +PaError PaHost_OpenInputStream( internalPortAudioStream *stream ) +{ + PaError result = paNoError; + MMRESULT mmresult; + PaWMMEStreamData *wmmeStreamData; + int i; + int inputMmId; + int bytesPerInputFrame; + WAVEFORMATEX wfx; + const PaDeviceInfo *deviceInfo; + + wmmeStreamData = (PaWMMEStreamData *) stream->past_DeviceData; + DBUG(("PaHost_OpenStream: deviceID = 0x%x\n", stream->past_InputDeviceID)); + deviceInfo = Pa_GetDeviceInfo( stream->past_InputDeviceID ); + if( deviceInfo == NULL ) return paInternalError; + + switch( deviceInfo->nativeSampleFormats ) + { + case paInt32: + case paFloat32: + bytesPerInputFrame = sizeof(float) * stream->past_NumInputChannels; + break; + default: + bytesPerInputFrame = sizeof(short) * stream->past_NumInputChannels; + break; + } + wfx.wFormatTag = WAVE_FORMAT_PCM; + wfx.nChannels = (WORD) stream->past_NumInputChannels; + wfx.nSamplesPerSec = (DWORD) stream->past_SampleRate; + wfx.nAvgBytesPerSec = (DWORD)(bytesPerInputFrame * stream->past_SampleRate); + wfx.nBlockAlign = (WORD)bytesPerInputFrame; + wfx.wBitsPerSample = (WORD)((bytesPerInputFrame/stream->past_NumInputChannels) * 8); + wfx.cbSize = 0; + inputMmId = PaDeviceIdToWinId( stream->past_InputDeviceID ); +#if PA_USE_TIMER_CALLBACK + mmresult = waveInOpen( &wmmeStreamData->hWaveIn, inputMmId, &wfx, + 0, 0, CALLBACK_NULL ); +#else + mmresult = waveInOpen( &wmmeStreamData->hWaveIn, inputMmId, &wfx, + (DWORD)wmmeStreamData->bufferEvent, (DWORD) stream, CALLBACK_EVENT ); +#endif + if( mmresult != MMSYSERR_NOERROR ) + { + ERR_RPT(("PortAudio: PaHost_OpenInputStream() failed!\n")); + result = paHostError; + sPaHostError = mmresult; + goto error; + } + /* Allocate an array to hold the buffer pointers. */ + wmmeStreamData->inputBuffers = (WAVEHDR *) PaHost_AllocateTrackedMemory( sizeof(WAVEHDR)*wmmeStreamData->numHostBuffers ); /* MEM */ + if( wmmeStreamData->inputBuffers == NULL ) + { + result = paInsufficientMemory; + goto error; + } + /* Allocate each buffer. */ + for( i=0; i<wmmeStreamData->numHostBuffers; i++ ) + { + wmmeStreamData->inputBuffers[i].lpData = (char *)PaHost_AllocateTrackedMemory( wmmeStreamData->bytesPerHostInputBuffer ); /* MEM */ + if( wmmeStreamData->inputBuffers[i].lpData == NULL ) + { + result = paInsufficientMemory; + goto error; + } + wmmeStreamData->inputBuffers[i].dwBufferLength = wmmeStreamData->bytesPerHostInputBuffer; + wmmeStreamData->inputBuffers[i].dwUser = i; + if( ( mmresult = waveInPrepareHeader( wmmeStreamData->hWaveIn, &wmmeStreamData->inputBuffers[i], sizeof(WAVEHDR) )) != MMSYSERR_NOERROR ) + { + result = paHostError; + sPaHostError = mmresult; + goto error; + } + } + return result; + +error: + return result; +} +/*******************************************************************/ +PaError PaHost_OpenOutputStream( internalPortAudioStream *stream ) +{ + PaError result = paNoError; + MMRESULT mmresult; + PaWMMEStreamData *wmmeStreamData; + int i; + int outputMmID; + int bytesPerOutputFrame; + WAVEFORMATEX wfx; + const PaDeviceInfo *deviceInfo; + + wmmeStreamData = (PaWMMEStreamData *) stream->past_DeviceData; + DBUG(("PaHost_OpenStream: deviceID = 0x%x\n", stream->past_OutputDeviceID)); + + deviceInfo = Pa_GetDeviceInfo( stream->past_OutputDeviceID ); + if( deviceInfo == NULL ) return paInternalError; + + switch( deviceInfo->nativeSampleFormats ) + { + case paInt32: + case paFloat32: + bytesPerOutputFrame = sizeof(float) * stream->past_NumOutputChannels; + break; + default: + bytesPerOutputFrame = sizeof(short) * stream->past_NumOutputChannels; + break; + } + wfx.wFormatTag = WAVE_FORMAT_PCM; + wfx.nChannels = (WORD) stream->past_NumOutputChannels; + wfx.nSamplesPerSec = (DWORD) stream->past_SampleRate; + wfx.nAvgBytesPerSec = (DWORD)(bytesPerOutputFrame * stream->past_SampleRate); + wfx.nBlockAlign = (WORD)bytesPerOutputFrame; + wfx.wBitsPerSample = (WORD)((bytesPerOutputFrame/stream->past_NumOutputChannels) * 8); + wfx.cbSize = 0; + outputMmID = PaDeviceIdToWinId( stream->past_OutputDeviceID ); +#if PA_USE_TIMER_CALLBACK + mmresult = waveOutOpen( &wmmeStreamData->hWaveOut, outputMmID, &wfx, + 0, 0, CALLBACK_NULL ); +#else + + wmmeStreamData->abortEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); + if( wmmeStreamData->abortEvent == NULL ) + { + result = paHostError; + sPaHostError = GetLastError(); + goto error; + } + wmmeStreamData->abortEventInited = 1; + mmresult = waveOutOpen( &wmmeStreamData->hWaveOut, outputMmID, &wfx, + (DWORD)wmmeStreamData->bufferEvent, (DWORD) stream, CALLBACK_EVENT ); +#endif + if( mmresult != MMSYSERR_NOERROR ) + { + ERR_RPT(("PortAudio: PaHost_OpenOutputStream() failed!\n")); + result = paHostError; + sPaHostError = mmresult; + goto error; + } + /* Allocate an array to hold the buffer pointers. */ + wmmeStreamData->outputBuffers = (WAVEHDR *) PaHost_AllocateTrackedMemory( sizeof(WAVEHDR)*wmmeStreamData->numHostBuffers ); /* MEM */ + if( wmmeStreamData->outputBuffers == NULL ) + { + result = paInsufficientMemory; + goto error; + } + /* Allocate each buffer. */ + for( i=0; i<wmmeStreamData->numHostBuffers; i++ ) + { + wmmeStreamData->outputBuffers[i].lpData = (char *) PaHost_AllocateTrackedMemory( wmmeStreamData->bytesPerHostOutputBuffer ); /* MEM */ + if( wmmeStreamData->outputBuffers[i].lpData == NULL ) + { + result = paInsufficientMemory; + goto error; + } + wmmeStreamData->outputBuffers[i].dwBufferLength = wmmeStreamData->bytesPerHostOutputBuffer; + wmmeStreamData->outputBuffers[i].dwUser = i; + if( (mmresult = waveOutPrepareHeader( wmmeStreamData->hWaveOut, &wmmeStreamData->outputBuffers[i], sizeof(WAVEHDR) )) != MMSYSERR_NOERROR ) + { + result = paHostError; + sPaHostError = mmresult; + goto error; + } + } + return result; + +error: + return result; +} +/*******************************************************************/ +PaError PaHost_GetTotalBufferFrames( internalPortAudioStream *stream ) +{ + PaWMMEStreamData *wmmeStreamData = (PaWMMEStreamData *) stream->past_DeviceData; + return wmmeStreamData->numHostBuffers * wmmeStreamData->framesPerHostBuffer; +} +/******************************************************************* + * Determine number of WAVE Buffers + * and how many User Buffers we can put into each WAVE buffer. + */ +static void PaHost_CalcNumHostBuffers( internalPortAudioStream *stream ) +{ + PaWMMEStreamData *wmmeStreamData = (PaWMMEStreamData *) stream->past_DeviceData; + unsigned int minNumBuffers; + int minframesPerHostBuffer; + int maxframesPerHostBuffer; + int minTotalFrames; + int userBuffersPerHostBuffer; + int framesPerHostBuffer; + int numHostBuffers; + + /* Calculate minimum and maximum sizes based on timing and sample rate. */ + minframesPerHostBuffer = (int) (PA_MIN_MSEC_PER_HOST_BUFFER * stream->past_SampleRate * 0.001); + minframesPerHostBuffer = (minframesPerHostBuffer + 7) & ~7; + DBUG(("PaHost_CalcNumHostBuffers: minframesPerHostBuffer = %d\n", minframesPerHostBuffer )); + maxframesPerHostBuffer = (int) (PA_MAX_MSEC_PER_HOST_BUFFER * stream->past_SampleRate * 0.001); + maxframesPerHostBuffer = (maxframesPerHostBuffer + 7) & ~7; + DBUG(("PaHost_CalcNumHostBuffers: maxframesPerHostBuffer = %d\n", maxframesPerHostBuffer )); + /* Determine number of user buffers based on minimum latency. */ + minNumBuffers = Pa_GetMinNumBuffers( stream->past_FramesPerUserBuffer, stream->past_SampleRate ); + stream->past_NumUserBuffers = ( minNumBuffers > stream->past_NumUserBuffers ) ? minNumBuffers : stream->past_NumUserBuffers; + DBUG(("PaHost_CalcNumHostBuffers: min past_NumUserBuffers = %d\n", stream->past_NumUserBuffers )); + minTotalFrames = stream->past_NumUserBuffers * stream->past_FramesPerUserBuffer; + /* We cannot make the WAVE buffers too small because they may not get serviced quickly enough. */ + if( (int) stream->past_FramesPerUserBuffer < minframesPerHostBuffer ) + { + userBuffersPerHostBuffer = + (minframesPerHostBuffer + stream->past_FramesPerUserBuffer - 1) / + stream->past_FramesPerUserBuffer; + } + else + { + userBuffersPerHostBuffer = 1; + } + framesPerHostBuffer = stream->past_FramesPerUserBuffer * userBuffersPerHostBuffer; + /* Calculate number of WAVE buffers needed. Round up to cover minTotalFrames. */ + numHostBuffers = (minTotalFrames + framesPerHostBuffer - 1) / framesPerHostBuffer; + /* Make sure we have anough WAVE buffers. */ + if( numHostBuffers < PA_MIN_NUM_HOST_BUFFERS) + { + numHostBuffers = PA_MIN_NUM_HOST_BUFFERS; + } + else if( (numHostBuffers > PA_MAX_NUM_HOST_BUFFERS) && + ((int) stream->past_FramesPerUserBuffer < (maxframesPerHostBuffer/2) ) ) + { + /* If we have too many WAVE buffers, try to put more user buffers in a wave buffer. */ + while(numHostBuffers > PA_MAX_NUM_HOST_BUFFERS) + { + userBuffersPerHostBuffer += 1; + framesPerHostBuffer = stream->past_FramesPerUserBuffer * userBuffersPerHostBuffer; + numHostBuffers = (minTotalFrames + framesPerHostBuffer - 1) / framesPerHostBuffer; + /* If we have gone too far, back up one. */ + if( (framesPerHostBuffer > maxframesPerHostBuffer) || + (numHostBuffers < PA_MAX_NUM_HOST_BUFFERS) ) + { + userBuffersPerHostBuffer -= 1; + framesPerHostBuffer = stream->past_FramesPerUserBuffer * userBuffersPerHostBuffer; + numHostBuffers = (minTotalFrames + framesPerHostBuffer - 1) / framesPerHostBuffer; + break; + } + } + } + + wmmeStreamData->userBuffersPerHostBuffer = userBuffersPerHostBuffer; + wmmeStreamData->framesPerHostBuffer = framesPerHostBuffer; + wmmeStreamData->numHostBuffers = numHostBuffers; + DBUG(("PaHost_CalcNumHostBuffers: userBuffersPerHostBuffer = %d\n", wmmeStreamData->userBuffersPerHostBuffer )); + DBUG(("PaHost_CalcNumHostBuffers: numHostBuffers = %d\n", wmmeStreamData->numHostBuffers )); + DBUG(("PaHost_CalcNumHostBuffers: framesPerHostBuffer = %d\n", wmmeStreamData->framesPerHostBuffer )); + DBUG(("PaHost_CalcNumHostBuffers: past_NumUserBuffers = %d\n", stream->past_NumUserBuffers )); +} +/*******************************************************************/ +PaError PaHost_OpenStream( internalPortAudioStream *stream ) +{ + PaError result = paNoError; + PaWMMEStreamData *wmmeStreamData; + + result = PaHost_AllocateWMMEStreamData( stream ); + if( result != paNoError ) return result; + + wmmeStreamData = PaHost_GetWMMEStreamData( stream ); + + /* Figure out how user buffers fit into WAVE buffers. */ + PaHost_CalcNumHostBuffers( stream ); + { + int msecLatency = (int) ((PaHost_GetTotalBufferFrames(stream) * 1000) / stream->past_SampleRate); + DBUG(("PortAudio on WMME - Latency = %d frames, %d msec\n", PaHost_GetTotalBufferFrames(stream), msecLatency )); + } + InitializeCriticalSection( &wmmeStreamData->streamLock ); + wmmeStreamData->streamLockInited = 1; + +#if (PA_USE_TIMER_CALLBACK == 0) + wmmeStreamData->bufferEventInited = 0; + wmmeStreamData->bufferEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); + if( wmmeStreamData->bufferEvent == NULL ) + { + result = paHostError; + sPaHostError = GetLastError(); + goto error; + } + wmmeStreamData->bufferEventInited = 1; +#endif /* (PA_USE_TIMER_CALLBACK == 0) */ + /* ------------------ OUTPUT */ + wmmeStreamData->bytesPerUserOutputBuffer = stream->past_FramesPerUserBuffer * stream->past_NumOutputChannels * sizeof(short); + wmmeStreamData->bytesPerHostOutputBuffer = wmmeStreamData->userBuffersPerHostBuffer * wmmeStreamData->bytesPerUserOutputBuffer; + if( (stream->past_OutputDeviceID != paNoDevice) && (stream->past_NumOutputChannels > 0) ) + { + result = PaHost_OpenOutputStream( stream ); + if( result < 0 ) goto error; + } + /* ------------------ INPUT */ + wmmeStreamData->bytesPerUserInputBuffer = stream->past_FramesPerUserBuffer * stream->past_NumInputChannels * sizeof(short); + wmmeStreamData->bytesPerHostInputBuffer = wmmeStreamData->userBuffersPerHostBuffer * wmmeStreamData->bytesPerUserInputBuffer; + if( (stream->past_InputDeviceID != paNoDevice) && (stream->past_NumInputChannels > 0) ) + { + result = PaHost_OpenInputStream( stream ); + if( result < 0 ) goto error; + } + + Pa_InitializeCpuUsageScalar( stream ); + + return result; + +error: + PaHost_CloseStream( stream ); + return result; +} +/*************************************************************************/ +PaError PaHost_StartOutput( internalPortAudioStream *stream ) +{ + PaError result = paNoError; + MMRESULT mmresult; + int i; + PaWMMEStreamData *wmmeStreamData = PaHost_GetWMMEStreamData( stream ); + + if( wmmeStreamData == NULL ) return paInternalError; + + if( stream->past_OutputDeviceID != paNoDevice ) + { + if( (mmresult = waveOutPause( wmmeStreamData->hWaveOut )) != MMSYSERR_NOERROR ) + { + result = paHostError; + sPaHostError = mmresult; + goto error; + } + for( i=0; i<wmmeStreamData->numHostBuffers; i++ ) + { + ZeroMemory( wmmeStreamData->outputBuffers[i].lpData, wmmeStreamData->outputBuffers[i].dwBufferLength ); + mmresult = waveOutWrite( wmmeStreamData->hWaveOut, &wmmeStreamData->outputBuffers[i], sizeof(WAVEHDR) ); + if( mmresult != MMSYSERR_NOERROR ) + { + result = paHostError; + sPaHostError = mmresult; + goto error; + } + stream->past_FrameCount += wmmeStreamData->framesPerHostBuffer; + } + wmmeStreamData->currentOutputBuffer = 0; + if( (mmresult = waveOutRestart( wmmeStreamData->hWaveOut )) != MMSYSERR_NOERROR ) + { + result = paHostError; + sPaHostError = mmresult; + goto error; + } + } + +error: + DBUG(("PaHost_StartOutput: wave returned mmresult = 0x%X.\n", mmresult)); + return result; +} +/*************************************************************************/ +PaError PaHost_StartInput( internalPortAudioStream *internalStream ) +{ + PaError result = paNoError; + MMRESULT mmresult; + int i; + PaWMMEStreamData *wmmeStreamData = PaHost_GetWMMEStreamData( internalStream ); + + if( wmmeStreamData == NULL ) return paInternalError; + + if( internalStream->past_InputDeviceID != paNoDevice ) + { + for( i=0; i<wmmeStreamData->numHostBuffers; i++ ) + { + mmresult = waveInAddBuffer( wmmeStreamData->hWaveIn, &wmmeStreamData->inputBuffers[i], sizeof(WAVEHDR) ); + if( mmresult != MMSYSERR_NOERROR ) + { + result = paHostError; + sPaHostError = mmresult; + goto error; + } + } + wmmeStreamData->currentInputBuffer = 0; + mmresult = waveInStart( wmmeStreamData->hWaveIn ); + DBUG(("Pa_StartStream: waveInStart returned = 0x%X.\n", mmresult)); + if( mmresult != MMSYSERR_NOERROR ) + { + result = paHostError; + sPaHostError = mmresult; + goto error; + } + } + +error: + return result; +} +/*************************************************************************/ +PaError PaHost_StartEngine( internalPortAudioStream *stream ) +{ + PaError result = paNoError; + PaWMMEStreamData *wmmeStreamData = PaHost_GetWMMEStreamData( stream ); +#if PA_USE_TIMER_CALLBACK + int resolution; + int bufsPerTimerCallback; + int msecPerBuffer; +#endif /* PA_USE_TIMER_CALLBACK */ + + if( wmmeStreamData == NULL ) return paInternalError; + + stream->past_StopSoon = 0; + stream->past_StopNow = 0; + stream->past_IsActive = 1; + wmmeStreamData->framesPlayed = 0.0; + wmmeStreamData->lastPosition = 0; +#if PA_TRACE_START_STOP + AddTraceMessage( "PaHost_StartEngine: TimeSlice() returned ", result ); +#endif +#if PA_USE_TIMER_CALLBACK + /* Create timer that will wake us up so we can fill the DSound buffer. */ + bufsPerTimerCallback = wmmeStreamData->numHostBuffers/4; + if( bufsPerTimerCallback < 1 ) bufsPerTimerCallback = 1; + if( bufsPerTimerCallback < 1 ) bufsPerTimerCallback = 1; + msecPerBuffer = (1000 * bufsPerTimerCallback * + wmmeStreamData->userBuffersPerHostBuffer * + internalStream->past_FramesPerUserBuffer ) / (int) internalStream->past_SampleRate; + if( msecPerBuffer < 10 ) msecPerBuffer = 10; + else if( msecPerBuffer > 100 ) msecPerBuffer = 100; + resolution = msecPerBuffer/4; + wmmeStreamData->timerID = timeSetEvent( msecPerBuffer, resolution, + (LPTIMECALLBACK) Pa_TimerCallback, + (DWORD) stream, TIME_PERIODIC ); + if( wmmeStreamData->timerID == 0 ) + { + result = paHostError; + sPaHostError = GetLastError();; + goto error; + } +#else /* PA_USE_TIMER_CALLBACK */ + ResetEvent( wmmeStreamData->abortEvent ); + /* Create thread that waits for audio buffers to be ready for processing. */ + wmmeStreamData->engineThread = CreateThread( 0, 0, WinMMPa_OutputThreadProc, stream, 0, &wmmeStreamData->engineThreadID ); + if( wmmeStreamData->engineThread == NULL ) + { + result = paHostError; + sPaHostError = GetLastError();; + goto error; + } +#if PA_TRACE_START_STOP + AddTraceMessage( "PaHost_StartEngine: thread ", (int) wmmeStreamData->engineThread ); +#endif + /* I used to pass the thread which was failing. I now pass GetCurrentProcess(). + * This fix could improve latency for some applications. It could also result in CPU + * starvation if the callback did too much processing. + * I also added result checks, so we might see more failures at initialization. + * Thanks to Alberto di Bene for spotting this. + */ + if( !SetPriorityClass( GetCurrentProcess(), HIGH_PRIORITY_CLASS ) ) /* PLB20010816 */ + { + result = paHostError; + sPaHostError = GetLastError();; + goto error; + } + if( !SetThreadPriority( wmmeStreamData->engineThread, THREAD_PRIORITY_HIGHEST ) ) + { + result = paHostError; + sPaHostError = GetLastError();; + goto error; + } +#endif + +error: + return result; +} +/*************************************************************************/ +PaError PaHost_StopEngine( internalPortAudioStream *internalStream, int abort ) +{ + int timeOut; + PaWMMEStreamData *wmmeStreamData = PaHost_GetWMMEStreamData( internalStream ); + + if( wmmeStreamData == NULL ) return paNoError; + + /* Tell background thread to stop generating more data and to let current data play out. */ + internalStream->past_StopSoon = 1; + /* If aborting, tell background thread to stop NOW! */ + if( abort ) internalStream->past_StopNow = 1; + + /* Calculate timeOut longer than longest time it could take to play all buffers. */ + timeOut = (DWORD) (1500.0 * PaHost_GetTotalBufferFrames( internalStream ) / internalStream->past_SampleRate); + if( timeOut < MIN_TIMEOUT_MSEC ) timeOut = MIN_TIMEOUT_MSEC; + +#if PA_USE_TIMER_CALLBACK + if( (internalStream->past_OutputDeviceID != paNoDevice) && + internalStream->past_IsActive && + (wmmeStreamData->timerID != 0) ) + { + /* Wait for IsActive to drop. */ + while( (internalStream->past_IsActive) && (timeOut > 0) ) + { + Sleep(10); + timeOut -= 10; + } + timeKillEvent( wmmeStreamData->timerID ); /* Stop callback timer. */ + wmmeStreamData->timerID = 0; + } +#else /* PA_USE_TIMER_CALLBACK */ +#if PA_TRACE_START_STOP + AddTraceMessage( "PaHost_StopEngine: thread ", (int) wmmeStreamData->engineThread ); +#endif + if( (internalStream->past_OutputDeviceID != paNoDevice) && + (internalStream->past_IsActive) && + (wmmeStreamData->engineThread != NULL) ) + { + DWORD got; + /* Tell background thread to stop generating more data and to let current data play out. */ + DBUG(("PaHost_StopEngine: waiting for background thread.\n")); + got = WaitForSingleObject( wmmeStreamData->engineThread, timeOut ); + if( got == WAIT_TIMEOUT ) + { + ERR_RPT(("PaHost_StopEngine: timed out while waiting for background thread to finish.\n")); + return paTimedOut; + } + CloseHandle( wmmeStreamData->engineThread ); + wmmeStreamData->engineThread = NULL; + } +#endif /* PA_USE_TIMER_CALLBACK */ + + internalStream->past_IsActive = 0; + return paNoError; +} +/*************************************************************************/ +PaError PaHost_StopInput( internalPortAudioStream *stream, int abort ) +{ + MMRESULT mmresult; + PaWMMEStreamData *wmmeStreamData = PaHost_GetWMMEStreamData( stream ); + + if( wmmeStreamData == NULL ) return paNoError; /* FIXME: why return paNoError? */ + (void) abort; /* unused parameter */ + + if( wmmeStreamData->hWaveIn != NULL ) + { + mmresult = waveInReset( wmmeStreamData->hWaveIn ); + if( mmresult != MMSYSERR_NOERROR ) + { + sPaHostError = mmresult; + return paHostError; + } + } + return paNoError; +} +/*************************************************************************/ +PaError PaHost_StopOutput( internalPortAudioStream *internalStream, int abort ) +{ + MMRESULT mmresult; + PaWMMEStreamData *wmmeStreamData = PaHost_GetWMMEStreamData( internalStream ); + + if( wmmeStreamData == NULL ) return paNoError; /* FIXME: why return paNoError? */ + (void) abort; /* unused parameter */ + +#if PA_TRACE_START_STOP + AddTraceMessage( "PaHost_StopOutput: hWaveOut ", (int) wmmeStreamData->hWaveOut ); +#endif + if( wmmeStreamData->hWaveOut != NULL ) + { + mmresult = waveOutReset( wmmeStreamData->hWaveOut ); + if( mmresult != MMSYSERR_NOERROR ) + { + sPaHostError = mmresult; + return paHostError; + } + } + return paNoError; +} +/*******************************************************************/ +PaError PaHost_CloseStream( internalPortAudioStream *stream ) +{ + int i; + PaWMMEStreamData *wmmeStreamData = PaHost_GetWMMEStreamData( stream ); + + if( stream == NULL ) return paBadStreamPtr; + if( wmmeStreamData == NULL ) return paNoError; /* FIXME: why return no error? */ + +#if PA_TRACE_START_STOP + AddTraceMessage( "PaHost_CloseStream: hWaveOut ", (int) wmmeStreamData->hWaveOut ); +#endif + /* Free data and device for output. */ + if( wmmeStreamData->hWaveOut ) + { + if( wmmeStreamData->outputBuffers ) + { + for( i=0; i<wmmeStreamData->numHostBuffers; i++ ) + { + waveOutUnprepareHeader( wmmeStreamData->hWaveOut, &wmmeStreamData->outputBuffers[i], sizeof(WAVEHDR) ); + PaHost_FreeTrackedMemory( wmmeStreamData->outputBuffers[i].lpData ); /* MEM */ + } + PaHost_FreeTrackedMemory( wmmeStreamData->outputBuffers ); /* MEM */ + } + waveOutClose( wmmeStreamData->hWaveOut ); + } + /* Free data and device for input. */ + if( wmmeStreamData->hWaveIn ) + { + if( wmmeStreamData->inputBuffers ) + { + for( i=0; i<wmmeStreamData->numHostBuffers; i++ ) + { + waveInUnprepareHeader( wmmeStreamData->hWaveIn, &wmmeStreamData->inputBuffers[i], sizeof(WAVEHDR) ); + PaHost_FreeTrackedMemory( wmmeStreamData->inputBuffers[i].lpData ); /* MEM */ + } + PaHost_FreeTrackedMemory( wmmeStreamData->inputBuffers ); /* MEM */ + } + waveInClose( wmmeStreamData->hWaveIn ); + } +#if (PA_USE_TIMER_CALLBACK == 0) + if( wmmeStreamData->abortEventInited ) CloseHandle( wmmeStreamData->abortEvent ); + if( wmmeStreamData->bufferEventInited ) CloseHandle( wmmeStreamData->bufferEvent ); +#endif + if( wmmeStreamData->streamLockInited ) + DeleteCriticalSection( &wmmeStreamData->streamLock ); + + PaHost_FreeWMMEStreamData( stream ); + + return paNoError; +} +/************************************************************************* + * Determine minimum number of buffers required for this host based + * on minimum latency. Latency can be optionally set by user by setting + * an environment variable. For example, to set latency to 200 msec, put: + * + * set PA_MIN_LATENCY_MSEC=200 + * + * in the AUTOEXEC.BAT file and reboot. + * If the environment variable is not set, then the latency will be determined + * based on the OS. Windows NT has higher latency than Win95. + */ +#define PA_LATENCY_ENV_NAME ("PA_MIN_LATENCY_MSEC") +int Pa_GetMinNumBuffers( int framesPerBuffer, double sampleRate ) +{ + char envbuf[PA_ENV_BUF_SIZE]; + DWORD hresult; + int minLatencyMsec = 0; + double msecPerBuffer = (1000.0 * framesPerBuffer) / sampleRate; + int minBuffers; + + /* Let user determine minimal latency by setting environment variable. */ + hresult = GetEnvironmentVariable( PA_LATENCY_ENV_NAME, envbuf, PA_ENV_BUF_SIZE ); + if( (hresult > 0) && (hresult < PA_ENV_BUF_SIZE) ) + { + minLatencyMsec = atoi( envbuf ); /* REVIEW: will we crash if the environment variable contains some nasty value? */ + } + else + { + /* Set minimal latency based on whether NT or other OS. + * NT has higher latency. + */ + OSVERSIONINFO osvi; + osvi.dwOSVersionInfoSize = sizeof( osvi ); + GetVersionEx( &osvi ); + DBUG(("PA - PlatformId = 0x%x\n", osvi.dwPlatformId )); + DBUG(("PA - MajorVersion = 0x%x\n", osvi.dwMajorVersion )); + DBUG(("PA - MinorVersion = 0x%x\n", osvi.dwMinorVersion )); + /* Check for NT */ + if( (osvi.dwMajorVersion == 4) && (osvi.dwPlatformId == 2) ) + { + minLatencyMsec = PA_WIN_NT_LATENCY; + } + else if(osvi.dwMajorVersion >= 5) + { + minLatencyMsec = PA_WIN_WDM_LATENCY; + } + else + { + minLatencyMsec = PA_WIN_9X_LATENCY; + } +#if PA_USE_HIGH_LATENCY + PRINT(("PA - Minimum Latency set to %d msec!\n", minLatencyMsec )); +#endif + + } + DBUG(("PA - Minimum Latency set to %d msec!\n", minLatencyMsec )); + minBuffers = (int) (1.0 + ((double)minLatencyMsec / msecPerBuffer)); + if( minBuffers < 2 ) minBuffers = 2; + return minBuffers; +} +/************************************************************************* + * Cleanup device info. + */ +PaError PaHost_Term( void ) +{ + int i; + + if( sNumDevices > 0 ) + { + if( sDevicePtrs != NULL ) + { + for( i=0; i<sNumDevices; i++ ) + { + if( sDevicePtrs[i] != NULL ) + { + PaHost_FreeTrackedMemory( (char*)sDevicePtrs[i]->name ); /* MEM */ + PaHost_FreeTrackedMemory( (void*)sDevicePtrs[i]->sampleRates ); /* MEM */ + PaHost_FreeTrackedMemory( sDevicePtrs[i] ); /* MEM */ + } + } + PaHost_FreeTrackedMemory( sDevicePtrs ); /* MEM */ + sDevicePtrs = NULL; + } + sNumDevices = 0; + } + +#if PA_TRACK_MEMORY + PRINT(("PaHost_Term: sNumAllocations = %d\n", sNumAllocations )); +#endif + + return paNoError; +} +/*************************************************************************/ +void Pa_Sleep( long msec ) +{ + Sleep( msec ); +} +/************************************************************************* +FIXME: the following memory allocation routines should not be declared here + * Allocate memory that can be accessed in real-time. + * This may need to be held in physical memory so that it is not + * paged to virtual memory. + * This call MUST be balanced with a call to PaHost_FreeFastMemory(). + * Memory will be set to zero. + */ +void *PaHost_AllocateFastMemory( long numBytes ) +{ + return PaHost_AllocateTrackedMemory( numBytes ); /* FIXME - do we need physical memory? Use VirtualLock() */ /* MEM */ +} +/************************************************************************* + * Free memory that could be accessed in real-time. + * This call MUST be balanced with a call to PaHost_AllocateFastMemory(). + */ +void PaHost_FreeFastMemory( void *addr, long numBytes ) +{ + (void) numBytes; /* unused parameter */ + + PaHost_FreeTrackedMemory( addr ); /* MEM */ +} + +/************************************************************************* + * Track memory allocations to avoid leaks. + */ +static void *PaHost_AllocateTrackedMemory( long numBytes ) +{ + void *result = GlobalAlloc( GPTR, numBytes ); /* MEM */ + +#if PA_TRACK_MEMORY + if( result != NULL ) sNumAllocations += 1; +#endif + return result; +} + +static void PaHost_FreeTrackedMemory( void *addr ) +{ + if( addr != NULL ) + { + GlobalFree( addr ); /* MEM */ +#if PA_TRACK_MEMORY + sNumAllocations -= 1; +#endif + } +} + +/***********************************************************************/ +PaError PaHost_StreamActive( internalPortAudioStream *internalStream ) +{ + if( internalStream == NULL ) return paBadStreamPtr; + + return (PaError) internalStream->past_IsActive; +} +/************************************************************************* + * This must be called periodically because mmtime.u.sample + * is a DWORD and can wrap and lose sync after a few hours. + */ +static PaError PaHost_UpdateStreamTime( PaWMMEStreamData *wmmeStreamData ) +{ + MMRESULT mmresult; + MMTIME mmtime; + mmtime.wType = TIME_SAMPLES; + + if( wmmeStreamData->hWaveOut != NULL ) + { + mmresult = waveOutGetPosition( wmmeStreamData->hWaveOut, &mmtime, sizeof(mmtime) ); + } + else + { + mmresult = waveInGetPosition( wmmeStreamData->hWaveIn, &mmtime, sizeof(mmtime) ); + } + + if( mmresult != MMSYSERR_NOERROR ) + { + sPaHostError = mmresult; + return paHostError; + } + + /* This data has two variables and is shared by foreground and background. + * So we need to make it thread safe. */ + EnterCriticalSection( &wmmeStreamData->streamLock ); + wmmeStreamData->framesPlayed += ((long)mmtime.u.sample) - wmmeStreamData->lastPosition; + wmmeStreamData->lastPosition = (long)mmtime.u.sample; + LeaveCriticalSection( &wmmeStreamData->streamLock ); + + return paNoError; +} +/*************************************************************************/ +PaTimestamp Pa_StreamTime( PortAudioStream *stream ) +{ + internalPortAudioStream *internalStream = PaHost_GetStreamRepresentation( stream ); + PaWMMEStreamData *wmmeStreamData = PaHost_GetWMMEStreamData( internalStream ); + + if( internalStream == NULL ) return paBadStreamPtr; + if( wmmeStreamData == NULL ) return paInternalError; + + PaHost_UpdateStreamTime( wmmeStreamData ); + return wmmeStreamData->framesPlayed; +} +/*************************************************************************/ + + + diff --git a/pd/portaudio_v18/pablio/pablio_pd.c b/pd/portaudio_v18/pablio/pablio_pd.c index 2596b73c..90b0cb34 100644 --- a/pd/portaudio_v18/pablio/pablio_pd.c +++ b/pd/portaudio_v18/pablio/pablio_pd.c @@ -1,5 +1,5 @@ /* - * $Id: pablio_pd.c,v 1.1.1.1 2003-05-09 16:04:00 ggeiger Exp $ + * $Id: pablio_pd.c,v 1.1.1.2 2004-02-02 11:27:58 ggeiger Exp $ * pablio.c * Portable Audio Blocking Input/Output utility. * @@ -34,15 +34,9 @@ * */ -/* History: - * PLB021214 - check for valid stream in CloseAudioStream() to prevent hang. - * add timeOutMSec to CloseAudioStream() to prevent hang. - */ - - /* changes by Miller Puckette (MSP) to support Pd: device selection, + /* changes by Miller Puckette to support Pd: device selection, settable audio buffer size, and settable number of channels. LATER also fix it to poll for input and output fifo fill points. */ - #include <stdio.h> #include <stdlib.h> #include <math.h> @@ -52,6 +46,13 @@ #include <string.h> /* MSP -- FRAMES_PER_BUFFER constant removed */ +static void NPa_Sleep(int n) /* MSP wrapper to check we never stall... */ +{ +#if 0 + fprintf(stderr, "sleep\n"); +#endif + Pa_Sleep(n); +} /************************************************************************/ /******** Prototypes ****************************************************/ @@ -129,7 +130,7 @@ long WriteAudioStream( PABLIO_Stream *aStream, void *data, long numFrames ) bytesWritten = RingBuffer_Write( &aStream->outFIFO, p, numBytes ); numBytes -= bytesWritten; p += bytesWritten; - if( numBytes > 0) Pa_Sleep(10); + if( numBytes > 0) NPa_Sleep(10); /* MSP */ } return numFrames; } @@ -148,7 +149,7 @@ long ReadAudioStream( PABLIO_Stream *aStream, void *data, long numFrames ) bytesRead = RingBuffer_Read( &aStream->inFIFO, p, numBytes ); numBytes -= bytesRead; p += bytesRead; - if( numBytes > 0) Pa_Sleep(10); + if( numBytes > 0) NPa_Sleep(10); /* MSP */ } return numFrames; } @@ -191,8 +192,7 @@ static unsigned long RoundUpToNextPowerOf2( unsigned long n ) * Allocates PABLIO_Stream structure. * * flags parameter can be an ORed combination of: - * PABLIO_READ, PABLIO_WRITE, or PABLIO_READ_WRITE, - * and either PABLIO_MONO or PABLIO_STEREO + * PABLIO_READ, PABLIO_WRITE, or PABLIO_READ_WRITE */ PaError OpenAudioStream( PABLIO_Stream **rwblPtr, double sampleRate, PaSampleFormat format, long flags, int nchannels, @@ -207,6 +207,11 @@ PaError OpenAudioStream( PABLIO_Stream **rwblPtr, double sampleRate, long minNumBuffers; long numFrames; + /* fprintf(stderr, + "open %lf fmt %d flags %d ch: %d fperbuf: %d nbuf: %d devs: %d %d\n", + sampleRate, format, flags, nchannels, + framesperbuf, nbuffers, indeviceno, outdeviceno); */ + if (indeviceno < 0) /* MSP... */ { indeviceno = Pa_GetDefaultInputDeviceID(); @@ -217,9 +222,8 @@ PaError OpenAudioStream( PABLIO_Stream **rwblPtr, double sampleRate, outdeviceno = Pa_GetDefaultOutputDeviceID(); fprintf(stderr, "using default output device number: %d\n", outdeviceno); } - nbuffers = RoundUpToNextPowerOf2(nbuffers); - fprintf(stderr, "nchan %d, flags %d, bufs %d, framesperbuf %d\n", - nchannels, flags, nbuffers, framesperbuf); + /* fprintf(stderr, "nchan %d, flags %d, bufs %d, framesperbuf %d\n", + nchannels, flags, nbuffers, framesperbuf); */ /* ...MSP */ /* Allocate PABLIO_Stream structure for caller. */ @@ -234,7 +238,7 @@ PaError OpenAudioStream( PABLIO_Stream **rwblPtr, double sampleRate, err = (PaError) bytesPerSample; goto error; } - aStream->samplesPerFrame = ((flags&PABLIO_MONO) != 0) ? 1 : 2; + aStream->samplesPerFrame = nchannels; /* MSP */ aStream->bytesPerFrame = bytesPerSample * aStream->samplesPerFrame; /* Initialize PortAudio */ @@ -242,15 +246,14 @@ PaError OpenAudioStream( PABLIO_Stream **rwblPtr, double sampleRate, if( err != paNoError ) goto error; /* Warning: numFrames must be larger than amount of data processed per - interrupt inside PA to prevent glitches. */ /* MSP... */ + interrupt inside PA to prevent glitches. */ /* MSP */ minNumBuffers = Pa_GetMinNumBuffers(framesperbuf, sampleRate); if (minNumBuffers > nbuffers) fprintf(stderr, "warning: number of buffers %d less than recommended minimum %d\n", (int)nbuffers, (int)minNumBuffers); - numFrames = nbuffers * framesperbuf; /* ...MSP */ - - + numFrames = nbuffers * framesperbuf; + /* fprintf(stderr, "numFrames %d\n", numFrames); */ /* Initialize Ring Buffers */ doRead = ((flags & PABLIO_READ) != 0); doWrite = ((flags & PABLIO_WRITE) != 0); @@ -290,18 +293,17 @@ PaError OpenAudioStream( PABLIO_Stream **rwblPtr, double sampleRate, if( err != paNoError ) goto error; err = Pa_StartStream( aStream->stream ); - if( err != paNoError ) /* MSP... */ + if( err != paNoError ) /* MSP */ { fprintf(stderr, "Pa_StartStream failed; closing audio stream...\n"); CloseAudioStream( aStream ); goto error; - } /* ...MSP */ + } *rwblPtr = aStream; return paNoError; error: - CloseAudioStream( aStream ); *rwblPtr = NULL; return err; } @@ -309,31 +311,28 @@ error: /************************************************************/ PaError CloseAudioStream( PABLIO_Stream *aStream ) { - PaError err = paNoError; + PaError err; int bytesEmpty; int byteSize = aStream->outFIFO.bufferSize; - if( aStream->stream != NULL ) /* Make sure stream was opened. PLB021214 */ + /* If we are writing data, make sure we play everything written. */ + if( byteSize > 0 ) { - /* If we are writing data, make sure we play everything written. */ - if( byteSize > 0 ) + bytesEmpty = RingBuffer_GetWriteAvailable( &aStream->outFIFO ); + while( bytesEmpty < byteSize ) { - int timeOutMSec = 2000; + NPa_Sleep( 10 ); /* MSP */ bytesEmpty = RingBuffer_GetWriteAvailable( &aStream->outFIFO ); - while( (bytesEmpty < byteSize) && (timeOutMSec > 0) ) - { - Pa_Sleep( 20 ); - timeOutMSec -= 20; - bytesEmpty = RingBuffer_GetWriteAvailable( &aStream->outFIFO ); - } } - err = Pa_StopStream( aStream->stream ); - if( err != paNoError ) goto error; - err = Pa_CloseStream( aStream->stream ); } -error: + err = Pa_StopStream( aStream->stream ); + if( err != paNoError ) goto error; + err = Pa_CloseStream( aStream->stream ); + if( err != paNoError ) goto error; Pa_Terminate(); + +error: PABLIO_TermFIFO( &aStream->inFIFO ); PABLIO_TermFIFO( &aStream->outFIFO ); free( aStream ); diff --git a/pd/portaudio_v18/pablio/pablio_pd.h b/pd/portaudio_v18/pablio/pablio_pd.h index a99e74b6..0e180705 100644 --- a/pd/portaudio_v18/pablio/pablio_pd.h +++ b/pd/portaudio_v18/pablio/pablio_pd.h @@ -7,7 +7,7 @@ extern "C" #endif /* __cplusplus */ /* - * $Id: pablio_pd.h,v 1.1.1.1 2003-05-09 16:04:00 ggeiger Exp $ + * $Id: pablio_pd.h,v 1.1.1.2 2004-02-02 11:27:58 ggeiger Exp $ * PABLIO.h * Portable Audio Blocking read/write utility. * @@ -53,7 +53,7 @@ typedef struct { RingBuffer inFIFO; RingBuffer outFIFO; - PaStream *stream; /* MSP -- was PortAudioStream; probably an error */ + PortAudioStream *stream; int bytesPerFrame; int samplesPerFrame; } diff --git a/pd/portaudio_v18/pablio/ringbuffer.h b/pd/portaudio_v18/pablio/ringbuffer.h index 4be71d18..02dd40c3 100644 --- a/pd/portaudio_v18/pablio/ringbuffer.h +++ b/pd/portaudio_v18/pablio/ringbuffer.h @@ -6,7 +6,7 @@ extern "C" #endif /* __cplusplus */ /* - * $Id: ringbuffer.h,v 1.1.1.1.4.1 2003/03/13 17:28:14 philburk Exp $ + * $Id: ringbuffer.h,v 1.1.1.1.4.2 2003/04/28 17:45:34 philburk Exp $ * ringbuffer.h * Ring Buffer utility.. * @@ -88,7 +88,7 @@ long RingBuffer_AdvanceWriteIndex( RingBuffer *rbuf, long numBytes ); /* Get address of region(s) from which we can read data. ** If the region is contiguous, size2 will be zero. ** If non-contiguous, size2 will be the size of second region. -** Returns room available to be written or numBytes, whichever is smaller. +** Returns room available to be read or numBytes, whichever is smaller. */ long RingBuffer_GetReadRegions( RingBuffer *rbuf, long numBytes, void **dataPtr1, long *sizePtr1, diff --git a/pd/portaudio_v18/pablio/ringbuffer_pd.c b/pd/portaudio_v18/pablio/ringbuffer_pd.c index 97e060c1..0b2c4da5 100644 --- a/pd/portaudio_v18/pablio/ringbuffer_pd.c +++ b/pd/portaudio_v18/pablio/ringbuffer_pd.c @@ -1,5 +1,5 @@ /* - * $Id: ringbuffer_pd.c,v 1.1.1.1 2003-05-09 16:04:00 ggeiger Exp $ + * $Id: ringbuffer_pd.c,v 1.1.1.2 2004-02-02 11:27:58 ggeiger Exp $ * ringbuffer.c * Ring Buffer utility.. * @@ -58,9 +58,12 @@ long RingBuffer_Init( RingBuffer *rbuf, long numBytes, void *dataPtr ) ** Return number of bytes available for reading. */ long RingBuffer_GetReadAvailable( RingBuffer *rbuf ) { - long ret = (rbuf->writeIndex - rbuf->readIndex) + rbuf->bufferSize; - if (ret >= 2 * rbuf->bufferSize) - ret -= 2 * rbuf->bufferSize; + long ret = rbuf->writeIndex - rbuf->readIndex; + if (ret < 0) + ret += 2 * rbuf->bufferSize; + if (ret < 0 || ret > rbuf->bufferSize) + fprintf(stderr, + "consistency check failed: RingBuffer_GetReadAvailable\n"); return ( ret ); } /*************************************************************************** @@ -119,7 +122,7 @@ long RingBuffer_GetWriteRegions( RingBuffer *rbuf, long numBytes, long RingBuffer_AdvanceWriteIndex( RingBuffer *rbuf, long numBytes ) { long ret = (rbuf->writeIndex + numBytes); - if ( ret > 2 * rbuf->bufferSize) + if ( ret >= 2 * rbuf->bufferSize) ret -= 2 * rbuf->bufferSize; /* check for end of buffer */ return rbuf->writeIndex = ret; } @@ -139,7 +142,7 @@ long RingBuffer_GetReadRegions( RingBuffer *rbuf, long numBytes, if( numBytes > available ) numBytes = available; /* Check to see if read is not contiguous. */ index = rbuf->readIndex; - while (index > rbuf->bufferSize) + while (index >= rbuf->bufferSize) index -= rbuf->bufferSize; if( (index + numBytes) > rbuf->bufferSize ) @@ -165,7 +168,7 @@ long RingBuffer_GetReadRegions( RingBuffer *rbuf, long numBytes, long RingBuffer_AdvanceReadIndex( RingBuffer *rbuf, long numBytes ) { long ret = (rbuf->readIndex + numBytes); - if( ret > 2 * rbuf->bufferSize) + if( ret >= 2 * rbuf->bufferSize) ret -= 2 * rbuf->bufferSize; return rbuf->readIndex = ret; } diff --git a/pd/portaudio_v18/testcvs/changeme.txt b/pd/portaudio_v18/testcvs/changeme.txt new file mode 100644 index 00000000..2866c3b7 --- /dev/null +++ b/pd/portaudio_v18/testcvs/changeme.txt @@ -0,0 +1,8 @@ +This is just a dopy little file used to test the CVS repository. +Feel free to trash this file. +Minor change. +Another tweak. +philburk tweak +stephane test +Phil changed this again on 2/21/02. Yawn... + diff --git a/pd/portmidi_osx/pmdarwin.c b/pd/portmidi_osx/pmdarwin.c index 3ca2c87a..7c1fb712 100644 --- a/pd/portmidi_osx/pmdarwin.c +++ b/pd/portmidi_osx/pmdarwin.c @@ -2,7 +2,15 @@ * PortMidi OS-dependent interface for Darwin (MacOS X) * Jon Parise <jparise@cmu.edu> * - * $Id: pmdarwin.c,v 1.1.1.1 2003-05-09 16:04:00 ggeiger Exp $ + * $Id: pmdarwin.c,v 1.1.1.2 2004-02-02 11:28:02 ggeiger Exp $ + * + * CHANGE LOG: + * 03Jul03 - X. J. Scott (xjs): + * - Pm_GetDefaultInputDeviceID() and Pm_GetDefaultOutputDeviceID() + * now return id of first input and output devices in system, + * rather than returning 0 as before. + * This fix enables valid default port values to be returned. + * 0 is returned if no such device is found. */ /* @@ -17,18 +25,52 @@ #include "portmidi.h" #include "pmmacosx.h" -PmError pm_init() +PmError pm_init(void) // xjs added void { return pm_macosx_init(); } -PmError pm_term() +PmError pm_term(void) // xjs added void { return pm_macosx_term(); } -PmDeviceID Pm_GetDefaultInputDeviceID() { return 0; }; -PmDeviceID Pm_GetDefaultOutputDeviceID() { return 0; }; +/* Pm_GetDefaultInputDeviceID() - return input with lowest id # (xjs) + */ +PmDeviceID Pm_GetDefaultInputDeviceID() +{ + int i; + int device_count; + const PmDeviceInfo *deviceInfo; + + device_count = Pm_CountDevices(); + for (i = 0; i < device_count; i++) { + deviceInfo = Pm_GetDeviceInfo(i); + if (deviceInfo->input) + return i; + } + + return 0; +}; + +/* Pm_GetDefaultOutputDeviceID() - return output with lowest id # (xjs) +*/ +PmDeviceID Pm_GetDefaultOutputDeviceID() +{ + int i; + int device_count; + const PmDeviceInfo *deviceInfo; + + device_count = Pm_CountDevices(); + for (i = 0; i < device_count; i++) { + deviceInfo = Pm_GetDeviceInfo(i); + if (deviceInfo->output) + return i; + } + + return 0; +}; + void *pm_alloc(size_t s) { return malloc(s); } diff --git a/pd/portmidi_osx/pmmacosx.c b/pd/portmidi_osx/pmmacosx.c index 7fe8adc4..9ae0c8ce 100644 --- a/pd/portmidi_osx/pmmacosx.c +++ b/pd/portmidi_osx/pmmacosx.c @@ -3,7 +3,28 @@ * * Jon Parise <jparise@cmu.edu> * - * $Id: pmmacosx.c,v 1.1.1.1 2003-05-09 16:04:00 ggeiger Exp $ + * $Id: pmmacosx.c,v 1.1.1.2 2004-02-02 11:28:02 ggeiger Exp $ + * + * 27Jun02 XJS (X. J. Scott) + * - midi_length(): + * fixed bug that gave bad lengths for system messages + * + * / pm_macosx_init(): + * Now allocates the device names. This fixes bug before where + * it assigned same string buffer on stack to all devices. + * - pm_macosx_term(), deleteDeviceName(): + * devices strings allocated during pm_macosx_init() are deallocated. + * + * + pm_macosx_init(), newDeviceName(): + * registering kMIDIPropertyManufacturer + kMIDIPropertyModel + kMIDIPropertyName + * for name strings instead of just name. + * + * / pm_macosx_init(): unsigned i to quiet compiler griping + * - get_timestamp(): + * no change right here but type of Pt_Time() was altered in porttime.h + * so it matches type PmTimeProcPtr in assignment in this function. + * / midi_write(): + * changed unsigned to signed to stop compiler griping */ #include "portmidi.h" @@ -17,6 +38,8 @@ #include <CoreServices/CoreServices.h> #include <CoreMIDI/MIDIServices.h> +#define PM_DEVICE_NAME_LENGTH 64 + #define PACKET_BUFFER_SIZE 1024 static MIDIClientRef client = NULL; /* Client handle to the MIDI server */ @@ -26,6 +49,9 @@ static MIDIPortRef portOut = NULL; /* Output port handle */ extern pm_fns_node pm_macosx_in_dictionary; extern pm_fns_node pm_macosx_out_dictionary; +static char * newDeviceName(MIDIEndpointRef endpoint); +static void deleteDeviceName(char **szDeviceName_p); + static int midi_length(long msg) { @@ -42,8 +68,8 @@ midi_length(long msg) status = msg & 0xFF; high = status >> 4; low = status & 15; - - return (high != 0xF0) ? high_lengths[high] : low_lengths[low]; +// return (high != 0xF0) ? high_lengths[high] : low_lengths[low]; + return (high != 0x0F) ? high_lengths[high] : low_lengths[low]; // fixed 6/27/03, xjs } static PmTimestamp @@ -171,7 +197,7 @@ midi_write(PmInternal *midi, PmEvent *events, long length) PmTimeProcPtr time_proc; PmEvent event; unsigned int pm_time; - unsigned int eventIndex; + long eventIndex; // xjs: long instead of unsigned int, to match type of 'length' which compares against it unsigned int messageLength; Byte message[3]; @@ -202,7 +228,7 @@ midi_write(PmInternal *midi, PmEvent *events, long length) /* Extract the event data and pack it into the message buffer */ for (eventIndex = 0; eventIndex < length; eventIndex++) { - event = events[eventIndex]; + event = events[eventIndex]; /* Compute the timestamp */ pm_time = (*time_proc)(midi->time_info); @@ -228,6 +254,78 @@ midi_write(PmInternal *midi, PmEvent *events, long length) return pmNoError; } +/* newDeviceName() -- create a string that describes a MIDI endpoint device + * deleteDeviceName() -- dispose of string created. + * + * Concatenates manufacturer, model and name of endpoint and returns + * within freshly allocated space, to be registered in pm_add_device(). + * + * 27Jun03: XJS -- extracted and extended from pm_macosx_init(). + * 11Nov03: XJS -- safely handles cases where any string properties are + * not present, such as is the case with the virtual ports created + * by many programs. + */ + +static char * newDeviceName(MIDIEndpointRef endpoint) +{ + CFStringEncoding defaultEncoding; + CFStringRef deviceCFString; + char manufBuf[PM_DEVICE_NAME_LENGTH]; + char modelBuf[PM_DEVICE_NAME_LENGTH]; + char nameBuf[PM_DEVICE_NAME_LENGTH]; + char manufModelNameBuf[PM_DEVICE_NAME_LENGTH * 3 + 1]; + char *szDeviceName; + size_t length; + OSStatus iErr; + + /* Determine the default system character encording */ + + defaultEncoding = CFStringGetSystemEncoding(); + + /* Get the manufacturer, model and name of this device and combine into one string. */ + + iErr = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyManufacturer, &deviceCFString); + if (noErr == iErr) { + CFStringGetCString(deviceCFString, manufBuf, sizeof(manufBuf), defaultEncoding); + CFRelease(deviceCFString); + } + else + strcpy(manufBuf, "<undef. manuf>"); + + iErr = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyModel, &deviceCFString); + if (noErr == iErr) { + CFStringGetCString(deviceCFString, modelBuf, sizeof(modelBuf), defaultEncoding); + CFRelease(deviceCFString); + } + else + strcpy(modelBuf, "<undef. model>"); + + iErr = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, &deviceCFString); + if (noErr == iErr) { + CFStringGetCString(deviceCFString, nameBuf, sizeof(nameBuf), defaultEncoding); + CFRelease(deviceCFString); + } + else + strcpy(nameBuf, "<undef. name>"); + + sprintf(manufModelNameBuf, "%s %s: %s", manufBuf, modelBuf, nameBuf); + length = strlen(manufModelNameBuf); + + /* Allocate a new string and return. */ + + szDeviceName = (char *)pm_alloc(length + 1); + strcpy(szDeviceName, manufModelNameBuf); + + return szDeviceName; +} + +static void deleteDeviceName(char **szDeviceName_p) +{ + pm_free(*szDeviceName_p); + *szDeviceName_p = NULL; + return; +} + pm_fns_node pm_macosx_in_dictionary = { none_write, midi_in_open, @@ -248,14 +346,12 @@ pm_macosx_init(void) OSStatus status; ItemCount numDevices, numInputs, numOutputs; MIDIEndpointRef endpoint; - CFStringEncoding defaultEncoding; - CFStringRef deviceName; - char nameBuf[256]; - int i; + unsigned int i; // xjs, unsigned + char *szDeviceName; /* Determine the number of MIDI devices on the system */ numDevices = MIDIGetNumberOfDevices(); - numInputs = MIDIGetNumberOfSources(); + numInputs = MIDIGetNumberOfSources(); numOutputs = MIDIGetNumberOfDestinations(); /* Return prematurely if no devices exist on the system */ @@ -263,8 +359,6 @@ pm_macosx_init(void) return pmHostError; } - /* Determine the default system character encording */ - defaultEncoding = CFStringGetSystemEncoding(); /* Iterate over the MIDI input devices */ for (i = 0; i < numInputs; i++) { @@ -273,13 +367,12 @@ pm_macosx_init(void) continue; } - /* Get the name of this device */ - MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, &deviceName); - CFStringGetCString(deviceName, nameBuf, 256, defaultEncoding); - CFRelease(deviceName); + /* Get the manufacturer, model and name of this device and combine into one string. */ + szDeviceName = newDeviceName(endpoint); // xjs /* Register this device with PortMidi */ - pm_add_device("CoreMIDI", nameBuf, TRUE, (void *)endpoint, + // xjs: szDeviceName is allocated memory since each has to be different and is not copied in pm_add_device() + pm_add_device("CoreMIDI", szDeviceName, TRUE, (void *)endpoint, &pm_macosx_in_dictionary); } @@ -290,14 +383,13 @@ pm_macosx_init(void) continue; } - /* Get the name of this device */ - MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, &deviceName); - CFStringGetCString(deviceName, nameBuf, 256, defaultEncoding); - CFRelease(deviceName); + /* Get the manufacturer & model of this device */ + szDeviceName = newDeviceName(endpoint); // xjs /* Register this device with PortMidi */ - pm_add_device("CoreMIDI", nameBuf, FALSE, (void *)endpoint, - &pm_macosx_out_dictionary); + pm_add_device("CoreMIDI", szDeviceName, FALSE, (void *)endpoint, // xjs, szDeviceName (as above) + &pm_macosx_out_dictionary); + } /* Initialize the client handle */ @@ -328,6 +420,17 @@ pm_macosx_init(void) PmError pm_macosx_term(void) { + int i; + int device_count; + const PmDeviceInfo *deviceInfo; + + /* release memory allocated for device names */ + device_count = Pm_CountDevices(); + for (i = 0; i < device_count; i++) { + deviceInfo = Pm_GetDeviceInfo(i); + deleteDeviceName((char **)&deviceInfo->name); + } + if (client != NULL) MIDIClientDispose(client); if (portIn != NULL) MIDIPortDispose(portIn); if (portOut != NULL) MIDIPortDispose(portOut); diff --git a/pd/portmidi_osx/pmtest.c b/pd/portmidi_osx/pmtest.c index 5628d25e..6e590fd5 100644 --- a/pd/portmidi_osx/pmtest.c +++ b/pd/portmidi_osx/pmtest.c @@ -25,11 +25,12 @@ main() int statusprefix; - + Pm_Initialize(); // xjs + /* always start the timer before you start midi */ Pt_Start(1, 0, 0); /* start a timer with millisecond accuracy */ - + printf("%d midi ports found...\n", Pm_CountDevices()); // xjs for (i = 0; i < Pm_CountDevices(); i++) { const PmDeviceInfo *info = Pm_GetDeviceInfo(i); printf("%d: %s, %s", i, info->interf, info->name); @@ -86,6 +87,7 @@ main() gets(line); } + printf("delay %d, tranpose %d\n", delay, transpose); // xjs /* loop, echoing input back transposed with multiple taps */ @@ -111,7 +113,7 @@ main() printf("\nReceived key message = %X %X %X, at time %ld\n", status, data1, data2, buffer[0].timestamp); fflush(stdout); - /* immediately send the echoes to PortMIDI */ + /* immediately send the echoes to PortMIDI (note that only the echoes are to be transposed) */ for (i = 1; i < NUM_ECHOES; i++) { buffer[i].message = Pm_Message(status, data1 + transpose, data2 >> i); buffer[i].timestamp = buffer[0].timestamp + (i * delay); @@ -122,12 +124,16 @@ main() printf("Key C2 pressed. Exiting...\n"); fflush(stdout); + Pt_Stop(); // xjs + /* Give the echoes time to finish before quitting. */ sleep(((NUM_ECHOES * delay) / 1000) + 1); Pm_Close(midi_in); Pm_Close(midi_out); + Pm_Terminate(); // xjs + printf("Done.\n"); return 0; } diff --git a/pd/portmidi_osx/portmidi.c b/pd/portmidi_osx/portmidi.c index c2a32ae7..c8883303 100644 --- a/pd/portmidi_osx/portmidi.c +++ b/pd/portmidi_osx/portmidi.c @@ -12,13 +12,15 @@ descriptor_node descriptors[pm_descriptor_max]; /* pm_add_device -- describe interface/device pair to library * - * This is called at intialization time, once for each + * This is called at initialization time, once for each * interface (e.g. DirectSound) and device (e.g. SoundBlaster 1) * The strings are retained but NOT COPIED, so do not destroy them! * * returns pmInvalidDeviceId if device memory is exceeded * otherwise returns pmNoError + * */ + PmError pm_add_device(char *interf, char *name, int input, void *descriptor, pm_fns_type dictionary) { @@ -279,7 +281,6 @@ PmError Pm_Abort( PortMidiStream* stream ) return (*midi->dictionary->abort)(midi); } - PmError Pm_Close( PortMidiStream *stream ) { PmInternal *midi = (PmInternal *) stream; @@ -354,5 +355,3 @@ int pm_queue_full(PmInternal *midi) return tail == midi->head; } - - diff --git a/pd/portmidi_osx/portmidi.h b/pd/portmidi_osx/portmidi.h index 3e648c90..1264b6f5 100644 --- a/pd/portmidi_osx/portmidi.h +++ b/pd/portmidi_osx/portmidi.h @@ -43,6 +43,9 @@ extern "C" { * prevent opening an input as output and vice versa. * Added comments and documentation. * Implemented Pm_Terminate(). + * + * 27Jun03 X. J. Scott (XJS) + * - Adding void arg to Pm_GetHostError() to stop compiler gripe. */ #ifndef FALSE @@ -88,7 +91,7 @@ PmError Pm_Terminate( void ); number, call Pm_GetHostError(). This can be called after a function returns a PmError equal to pmHostError. */ -int Pm_GetHostError(); +int Pm_GetHostError( void ); /* xjs - void param to stop compiler gripe */ /* Translate the error number into a human readable message. @@ -111,8 +114,8 @@ typedef int PmDeviceID; typedef struct { int structVersion; - const char *interf; - const char *name; + char const *interf; + char const *name; int input; /* true iff input is available */ int output; /* true iff output is available */ } PmDeviceInfo; diff --git a/pd/portmidi_osx/portmidi_osx_change_log.txt b/pd/portmidi_osx/portmidi_osx_change_log.txt new file mode 100644 index 00000000..80640c3b --- /dev/null +++ b/pd/portmidi_osx/portmidi_osx_change_log.txt @@ -0,0 +1,70 @@ +PortMIDI changes of 27 June 2003 by X. J. Scott + +pmdarwin.c +---------- +- added void parameter list to pm_init and pm_term + (to remove a compiler warning) +- Pm_GetDefaultInputDeviceID() and Pm_GetDefaultOutputDeviceID() + now return id of first input and output devices in system, + rather than returning 0 as before. + This fix enables valid default port values to be returned. + 0 is returned if no such device is found. + +ptdarwin.c +---------- +- added void parameter list to Pt_Stop and Pt_Started + (to remove a compiler warning) +- added void *time_info parameter list to Pt_time + -> since Pt_Time is assigned in pmmacosx.c:get_timestamp() to + a variable of type PMTimeProcPtr, which requires this signature. + +porttime.h +---------- +- added void parameter list to Pt_Stop and Pt_Started +- added void *time_info parameter list to Pt_time + +pmmacosx.c +---------- +- midi_length(): + fixed bug that gave bad lengths for system messages + [note that the F5 message may be an issue for someone + to deal with later since the MIDITimePiece interface appopriated + the F5 for a two byte long CableSelectID - this usage + and length differ from the MIDI standard.] + +/ pm_macosx_init(): + Now allocates the device names. This fixes bug before where + it assigned same string buffer on stack to all devices. +- pm_macosx_term(), deleteDeviceName(): + devices strings allocated during pm_macosx_init() are deallocated. + ++ pm_macosx_init(), newDeviceName(): + registering kMIDIPropertyManufacturer + kMIDIPropertyModel + + kMIDIPropertyName for name strings instead of just name. + +/ pm_macosx_init(): + unsigned i to quiet compiler griping +- get_timestamp(): + no change right here but type of Pt_Time() was altered in porttime.h + so it matches type PmTimeProcPtr in assignment in this function. +/ midi_write(): + changed unsigned to signed to stop compiler griping + +portmidi.h +---------- +- Added void arg to Pm_GetHostError() to stop compiler gripe. + +pmtest.c +--------- +- Added Initialize and Terminate calls so that it doesn't + fail the 2nd time the test is run. + +----- + +PortMIDI changes of 11 Nov 2003 by X. J. Scott + +pmmacosx.c +---------- +- Handles ports that don't have the full set of property strings. + This fixes bug where crash would occur if a virtual port was present. + diff --git a/pd/portmidi_osx/porttime.h b/pd/portmidi_osx/porttime.h index 8592106d..fb57fe7d 100644 --- a/pd/portmidi_osx/porttime.h +++ b/pd/portmidi_osx/porttime.h @@ -1,4 +1,7 @@ -/* porttime.h -- portable interface to millisecond timer */ +/* porttime.h -- portable interface to millisecond timer + * + * 27Jun02 XJS - altered type of Pt_Time() (in porttime.h & portmidi.c) so it matches PmTimeProcPtr + */ /* Should there be a way to choose the source of time here? */ @@ -21,9 +24,9 @@ typedef int (PtCallback)( PtTimestamp timestamp, void *userData ); PtError Pt_Start(int resolution, PtCallback *callback, void *userData); -PtError Pt_Stop(); -int Pt_Started(); -PtTimestamp Pt_Time(); +PtError Pt_Stop(void); // xjs, added void +int Pt_Started(void); // xjs, added void +PtTimestamp Pt_Time(void *time_info); /* xjs - added void *time_info so this f() is a PmTimeProcPtr, defined in portmidi.h */ #ifdef __cplusplus } diff --git a/pd/portmidi_osx/ptdarwin.c b/pd/portmidi_osx/ptdarwin.c index 7df41b1c..0e2357dd 100644 --- a/pd/portmidi_osx/ptdarwin.c +++ b/pd/portmidi_osx/ptdarwin.c @@ -3,7 +3,7 @@ * * Jon Parise <jparise@cmu.edu> * - * $Id: ptdarwin.c,v 1.1.1.1 2003-05-09 16:04:00 ggeiger Exp $ + * $Id: ptdarwin.c,v 1.1.1.2 2004-02-02 11:28:02 ggeiger Exp $ */ #include <stdio.h> @@ -28,20 +28,20 @@ PtError Pt_Start(int resolution, PtCallback *callback, void *userData) } -PtError Pt_Stop() +PtError Pt_Stop(void) // xjs added void { time_started_flag = FALSE; return ptNoError; } -int Pt_Started() +int Pt_Started(void) // xjs added void { return time_started_flag; } -PtTimestamp Pt_Time() +PtTimestamp Pt_Time(void *time_info) // xjs added void *time_info { long seconds, milliseconds; struct timeval now; diff --git a/pd/src/CHANGELOG.txt b/pd/src/CHANGELOG.txt new file mode 100644 index 00000000..27441d36 --- /dev/null +++ b/pd/src/CHANGELOG.txt @@ -0,0 +1,80 @@ +This file describes implementation and API changes; stuff more visible to the +user appears in the "release notes" instead. + +0.37.1 + +makefile.in: MANINSTDIR = $(DESTDIR)/$(MANDIR) changed to + $(DESTDIR)/$(INSTALL_PREFIX)/$(MANDIR) (thx. Mathieu Bouchard) + +applied 2 jack patches from Luke Yelavich + +add -fno-strict-aliasing to config script (linux&mac) to improve underflow, +etc., protection + +add underflow protection to vcf~ object; rewrote underflow protection to be +faster in throw~/catch~ and send~/receive~ + +fixed bug in -inchannels/-outchannels arg parsing + +fixed u_main.tk to make "apple" key work to accelerate menus on MACOS + +fooled with MIDI to try to get sysex and other system messages to work. +Needs lots of testing now... + +finally fixed OSS to open audio with NODELAY... also cleared dup-on-exec flag. + +bug fix in scalar_properties + +major editions to the IEM GUIs to fix bugs in how "$" variables are handled. +The code still isn't pretty but hopefully at least works now. + +tried to get alsa noninterleaved access to work (needed for RME). Failed +to get my RME card to load under ALSA and gave up for now. + +fixed scalar drawing to fail gracefully when the template canvas disappears + +bug fix in vd~ for very small delays (d_delay.c) + +set up sys_oldtclversion flag to correct for changed text selection +(u_main.tk, s_main.c, g_rtext.c) + +tried again to add "readn" support to s_audio_alsa.c: coded, but failing so far. + +fixed broken octave divider example + +removed "-Werror" from default makefile; fixed configure script to respect +"CFLAGS" environment variable instead. Suggest developers should use +"setenv CFLAGS -Werror". + +added "-alsaadd" flag so people can specify alsa devnames to add to list. +fixed some problems with Pd crashing when ALSA failed to open. + +took out the 2-pixel padding for MSW in g_canvas.g (HORIZBORDER/VERTBORDER) + +went back to s_midi_mmio (portaudio version got assertion errors and anyway +I could never get sysex working in it as I had wanted.) + +Took bug fixes from s_midi_pm.c, s_audio_jack.c, s_inter.c from "devel" branch; +also added "static" flag to configure.in (but the devel configure.in as a whole +doesn't seem to work for OSX, for me at least.) + +Might have fixed a bug where labels disappear in buttons, etc, when saved +and reloaded. + +brought s_audio_alsa.c up to alsa 1.0.0 compatibility + +fixed "-alsaadd" (never worked before) + +fooled with macintosh audio. Fixed some (not all) of the audio I/O APIs +to deal with open failures better (reducing sys_{in,out}channels accordingly) + +In the Alsa API, the synchronization test was too stringent and was loosened +to 3*DACBLKSIZE/2. + +'make install' fixed to deal with 'extra' correctly. + +one more improvement in jack support (guenter) + +make an "nrt" flag so mac can disable pthread_setschedparam call if yu want. + + diff --git a/pd/src/configure.in.ok b/pd/src/configure.in.ok new file mode 100644 index 00000000..897eafdf --- /dev/null +++ b/pd/src/configure.in.ok @@ -0,0 +1,248 @@ +dnl Process this file with autoconf to produce a configure script. +AC_INIT(d_arithmetic.c) + +AC_SUBST(alsa) +AC_SUBST(jack, no) +AC_SUBST(portaudio) +AC_SUBST(PDLIB) +AC_SUBST(DEFINES) +AC_SUBST(MORECFLAGS) +AC_SUBST(EXT) +AC_SUBST(OPT_CFLAGS) +AC_SUBST(USE_OPT_CFLAGS, YES) +AC_SUBST(SYSSRC) +AC_SUBST(STRIPFLAG) +AC_SUBST(GUINAME) +AC_SUBST(GUIFLAGS) +AC_SUBST(OSNUMBER) +AC_SUBST(EXTERNTARGET) + +dnl other defaults + +dnl check for features + +AC_ARG_ENABLE(alsa, [ --disable-alsa disable ALSA], + alsa="no") +AC_ARG_ENABLE(jack, [ --enable-jack jack audio server], + jack="yes") +AC_ARG_ENABLE(portaudio, [ --enable-portaudio portaudio], + portaudio="yes") +AC_ARG_ENABLE(debug, [ --enable-debug debugging support], + USE_OPT_CFLAGS="no") + +dnl Checks for programs. +AC_PROG_CC +AC_PROG_INSTALL +AC_PROG_MAKE_SET +AC_PROG_CPP + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST +AC_TYPE_PID_T +AC_TYPE_SIZE_T +AC_HEADER_TIME + +dnl Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS(fcntl.h limits.h malloc.h sys/ioctl.h sys/time.h unistd.h bstring.h) + +dnl Checks for library functions. +AC_PROG_GCC_TRADITIONAL +AC_TYPE_SIGNAL +AC_FUNC_VPRINTF +AC_CHECK_FUNCS(gettimeofday select socket strerror) + + +dnl Checks for libraries. +dnl Checking for `dlopen' function in -ldl: +AC_CHECK_LIB(dl, dlopen,PDLIB="$PDLIB -ldl", + echo "dynamic link support required" || exit 1) + +dnl Checking for `sin' function in -lffm: +dnl ffm is the fast math library on the alpha +AC_CHECK_LIB(ffm, sin,PDLIB="$PDLIB -lffm") + +dnl Checking for `sin' function in -lm: +AC_CHECK_LIB(m, sin,PDLIB="$PDLIB -lm", + echo "math library required" || exit 1) + +dnl Checking for `pthread_create' function in -pthread +AC_CHECK_LIB(pthread, pthread_create,PDLIB="$PDLIB -lpthread", + echo "pthreads required" || exit 1) + +dnl This should be fixed so Pd can use ALSA shared libraries where appropriate. +if test "$alsa" != no; then + AC_CHECK_LIB(asound,snd_pcm_info,PDLIB="$PDLIB -lasound" ; alsa="yes",alsa="") +fi + +dnl Find paths to includes and libraries for X11 +AC_PATH_X +dnl Checking for `XCreateWindow' function in -lX11: +AC_CHECK_LIB(X11, XCreateWindow, LIBS="$LIBS -lX11 -L$x_libraries", + echo "no X11 found" || exit 1, -L$x_libraries) + +dnl look for tcl 8.x... do I really have to go through all this!? + +foundit=no +if test $foundit == "no"; +then + AC_CHECK_HEADER(tcl.h,foundit=yes,) +fi +if test $foundit == "no"; +then + AC_CHECK_HEADER(tcl8.7/tcl.h, + GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.7";foundit=yes,) +fi +if test $foundit == "no"; +then + AC_CHECK_HEADER(tcl8.6/tcl.h, + GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.6";foundit=yes,) +fi +if test $foundit == "no"; +then + AC_CHECK_HEADER(tcl8.5/tcl.h, + GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.5";foundit=yes,) +fi +if test $foundit == "no"; +then + AC_CHECK_HEADER(tcl8.4/tcl.h, + GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.4";foundit=yes,) +fi +if test $foundit == "no"; +then + AC_CHECK_HEADER(tcl8.3/tcl.h, + GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.3";foundit=yes,) +fi +if test $foundit == "no"; +then + AC_CHECK_HEADER(tcl8.2/tcl.h, + GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.2";foundit=yes,) +fi +if test $foundit == "no"; +then + echo no tcl header found + exit -1 +fi + +AC_CHECK_LIB(tcl8.7, main,, + AC_CHECK_LIB(tcl8.6, main,, + AC_CHECK_LIB(tcl8.5, main,, + AC_CHECK_LIB(tcl8.4, main,, + AC_CHECK_LIB(tcl8.3, main,, + AC_CHECK_LIB(tcl8.2, main,, + AC_CHECK_LIB(tcl8.0, main,,echo no tcl library found || exit 1))))))) + +AC_CHECK_LIB(tk8.7, main,, + AC_CHECK_LIB(tk8.6, main,, + AC_CHECK_LIB(tk8.5, main,, + AC_CHECK_LIB(tk8.4, main,, + AC_CHECK_LIB(tk8.3, main,, + AC_CHECK_LIB(tk8.2, main,, + AC_CHECK_LIB(tk8.0, main,,echo no tk library found || exit 1))))))) + +dnl Checking for tk.h or tkstep.h - not used at the moment +dnl AC_CHECK_HEADER(tk.h,DEFINES="$DEFINES -DTKINC=\\\"tk.h\\\"") +dnl AC_CHECK_HEADER(tkstep.h,DEFINES="$DEFINES -DTKINC=\\\"tkstep.h\\\"") + +if test `uname -s` = Linux; +then + LDFLAGS="-Wl,-export-dynamic" + EXT=pd_linux + MORECFLAGS="-DDL_OPEN -DUSEAPI_PORTAUDIO -DPA_USE_OSS -DPA_LITTLE_ENDIAN \ + -DUSEAPI_OSS \ + -I../portaudio/pa_common \ + -I../portaudio/pablio -I../portaudio/portmidi-macosx -Werror" + SYSSRC="s_midi_oss.c s_audio_pa.c s_audio_oss.c \ + ../portaudio/pa_common/pa_allocation.c \ + ../portaudio/pa_common/pa_converters.c \ + ../portaudio/pa_common/pa_cpuload.c \ + ../portaudio/pa_common/pa_dither.c \ + ../portaudio/pa_common/pa_front.c \ + ../portaudio/pa_common/pa_process.c \ + ../portaudio/pa_common/pa_skeleton.c \ + ../portaudio/pa_common/pa_stream.c \ + ../portaudio/pa_common/pa_trace.c \ + ../portaudio/pablio/pablio_pd.c \ + ../portaudio/pablio/ringbuffer_pd.c \ + ../portaudio/pa_unix/pa_unix_hostapis.c \ + ../portaudio/pa_unix/pa_unix_util.c \ + ../portaudio/pa_unix_oss/pa_unix_oss.c " + STRIPFLAG=-s + GUINAME="pd-gui" + if test $USE_OPT_CFLAGS == "YES"; + then + OPT_CFLAGS="-O6 -funroll-loops -fomit-frame-pointer" + else + OPT_CFLAGS="-g" + fi + OSNUMBER=0 +fi + +dnl **** note -- SGI/IRIX code is broken here!!! *** + +if test `uname -s` = IRIX64; +then + LDFLAGS="-n32 -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ + -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \ + -shared -rdata_shared" + EXT=pd_irix6 + MORECFLAGS=-DDL_OPEN + SYSSRC=s_sgi.c + STRIPFLAG=-s + GUINAME="pd-gui" + OSNUMBER=0 +fi + +if test `uname -s` = IRIX32; +then + LDFLAGS="-o32 -DUNIX -DIRIX -O2 -shared -rdata_shared" + EXT=pd_irix5 + MORECFLAGS=-DDL_OPEN + SYSSRC=s_sgi.c + STRIPFLAG=-s + GUINAME="pd-gui" + OSNUMBER=0 +fi + +if test `uname -s` = Darwin; +then + LDFLAGS="-Wl -framework Tcl -framework Tk -framework CoreAudio \ + -framework AudioUnit -framework AudioToolbox \ + -framework Carbon -framework CoreMIDI" + EXT=pd_darwin + MORECFLAGS="-DMACOSX -I/usr/X11R6/include \ + -I../portaudio_v18/pa_common \ + -I../portaudio_v18/pablio \ + -I../portmidi_osx \ + -Wno-error \ + -DUSEAPI_PORTAUDIO -DPA_BIG_ENDIAN" + SYSSRC="s_midi_pm.c s_audio_pa.c \ + ../portaudio_v18/pa_common/pa_lib.c \ + ../portaudio_v18/pa_common/pa_trace.c \ + ../portaudio_v18/pa_common/pa_convert.c \ + ../portaudio_v18/pablio/pablio_pd.c \ + ../portaudio_v18/pablio/ringbuffer_pd.c \ + ../portaudio_v18/pa_mac_core/pa_mac_core.c \ + ../portmidi_osx/pmdarwin.c \ + ../portmidi_osx/pmmacosx.c \ + ../portmidi_osx/pmutil.c \ + ../portmidi_osx/portmidi.c \ + ../portmidi_osx/ptdarwin.c " + STRIPFLAG="" + GUINAME="pdtcl" + GUIFLAGS="-framework Tcl -framework Tk \ + -I/Library/Frameworks/Tk.framework/Versions/Current/Headers \ + -I/Library/Frameworks/Tcl.framework/Versions/Current/Headers \ + -I/Library/Frameworks/Tcl.framework/Versions/8.4/PrivateHeaders" + if test $USE_OPT_CFLAGS == "YES"; + then + OPT_CFLAGS="-O2" + else + OPT_CFLAGS="-g" + fi + OSNUMBER=2 + EXTERNTARGET=pd_darwin +fi + +AC_OUTPUT(makefile) + diff --git a/pd/src/configure.in.oops b/pd/src/configure.in.oops new file mode 100644 index 00000000..5a7be36e --- /dev/null +++ b/pd/src/configure.in.oops @@ -0,0 +1,272 @@ +dnl Process this file with autoconf to produce a configure script. +AC_INIT(d_arithmetic.c) + +AC_SUBST(alsa) +AC_SUBST(jack, no) +AC_SUBST(portaudio) +AC_SUBST(PDLIB) +AC_SUBST(DEFINES) +AC_SUBST(MORECFLAGS) +AC_SUBST(EXT) +AC_SUBST(OPT_CFLAGS) +AC_SUBST(USE_OPT_CFLAGS, YES) +AC_SUBST(SYSSRC) +AC_SUBST(STRIPFLAG) +AC_SUBST(GUINAME) +AC_SUBST(GUIFLAGS) +AC_SUBST(OSNUMBER) +AC_SUBST(EXTERNTARGET) + +dnl other defaults + +dnl check for features + +AC_ARG_ENABLE(alsa, [ --disable-alsa disable ALSA], + alsa="no") +AC_ARG_ENABLE(jack, [ --enable-jack jack audio server], + jack="yes") +AC_ARG_ENABLE(portaudio, [ --enable-portaudio portaudio], + portaudio="yes") +AC_ARG_ENABLE(debug, [ --enable-debug debugging support], + USE_OPT_CFLAGS="no") + +dnl Checks for programs. +AC_PROG_CC +AC_PROG_INSTALL +AC_PROG_MAKE_SET +AC_PROG_CPP + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST +AC_TYPE_PID_T +AC_TYPE_SIZE_T +AC_HEADER_TIME + +dnl Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS(fcntl.h limits.h malloc.h sys/ioctl.h sys/time.h unistd.h bstring.h) + +dnl Checks for library functions. +AC_PROG_GCC_TRADITIONAL +AC_TYPE_SIGNAL +AC_FUNC_VPRINTF +AC_CHECK_FUNCS(gettimeofday select socket strerror) + + +dnl Checks for libraries. +dnl Checking for `dlopen' function in -ldl: +AC_CHECK_LIB(dl, dlopen,PDLIB="$PDLIB -ldl", + echo "dynamic link support required" || exit 1) + +dnl Checking for `sin' function in -lffm: +dnl ffm is the fast math library on the alpha +AC_CHECK_LIB(ffm, sin,PDLIB="$PDLIB -lffm") + +dnl Checking for `sin' function in -lm: +AC_CHECK_LIB(m, sin,PDLIB="$PDLIB -lm", + echo "math library required" || exit 1) + +dnl Checking for `pthread_create' function in -pthread +AC_CHECK_LIB(pthread, pthread_create,PDLIB="$PDLIB -lpthread", + echo "pthreads required" || exit 1) + +dnl This should be fixed so Pd can use ALSA shared libraries where appropriate. +if test "$alsa" != no; then + AC_CHECK_LIB(asound,snd_pcm_info,PDLIB="$PDLIB -lasound" ; alsa="yes",alsa="") +fi + +dnl Find paths to includes and libraries for X11 +AC_PATH_X +dnl Checking for `XCreateWindow' function in -lX11: +AC_CHECK_LIB(X11, XCreateWindow, LIBS="$LIBS -lX11 -L$x_libraries", + echo "no X11 found" || exit 1, -L$x_libraries) + +dnl look for tcl 8.x... do I really have to go through all this!? + +foundit=no +if test $foundit == "no"; +then + AC_CHECK_HEADER(tcl.h,foundit=yes,) +fi +if test $foundit == "no"; +then + AC_CHECK_HEADER(tcl8.7/tcl.h, + GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.7";foundit=yes,) +fi +if test $foundit == "no"; +then + AC_CHECK_HEADER(tcl8.6/tcl.h, + GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.6";foundit=yes,) +fi +if test $foundit == "no"; +then + AC_CHECK_HEADER(tcl8.5/tcl.h, + GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.5";foundit=yes,) +fi +if test $foundit == "no"; +then + AC_CHECK_HEADER(tcl8.4/tcl.h, + GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.4";foundit=yes,) +fi +if test $foundit == "no"; +then + AC_CHECK_HEADER(tcl8.3/tcl.h, + GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.3";foundit=yes,) +fi +if test $foundit == "no"; +then + AC_CHECK_HEADER(tcl8.2/tcl.h, + GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.2";foundit=yes,) +fi +if test $foundit == "no"; +then + echo no tcl header found + exit -1 +fi + +AC_CHECK_LIB(tcl8.7, main,, + AC_CHECK_LIB(tcl8.6, main,, + AC_CHECK_LIB(tcl8.5, main,, + AC_CHECK_LIB(tcl8.4, main,, + AC_CHECK_LIB(tcl8.3, main,, + AC_CHECK_LIB(tcl8.2, main,, + AC_CHECK_LIB(tcl8.0, main,,echo no tcl library found || exit 1))))))) + +AC_CHECK_LIB(tk8.7, main,, + AC_CHECK_LIB(tk8.6, main,, + AC_CHECK_LIB(tk8.5, main,, + AC_CHECK_LIB(tk8.4, main,, + AC_CHECK_LIB(tk8.3, main,, + AC_CHECK_LIB(tk8.2, main,, + AC_CHECK_LIB(tk8.0, main,,echo no tk library found || exit 1))))))) + +dnl Checking for tk.h or tkstep.h - not used at the moment +dnl AC_CHECK_HEADER(tk.h,DEFINES="$DEFINES -DTKINC=\\\"tk.h\\\"") +dnl AC_CHECK_HEADER(tkstep.h,DEFINES="$DEFINES -DTKINC=\\\"tkstep.h\\\"") + +if test `uname -s` = Linux; +then + dnl Ckecking for ALSA + + AC_CHECK_LIB(asound,snd_pcm_open,LIBS="$LIBS -lasound";alsa=yes,alsa=no) + + dnl Checking for JACK + + AC_CHECK_LIB(rt,shm_open,LIBS="$LIBS -lrt") + AC_CHECK_LIB(jack,jack_set_xrun_callback,LIBS="$LIBS -ljack";jack=xrun,jack=no) + AC_CHECK_LIB(jack,jack_set_error_function,LIBS="$LIBS -ljack";jack=yes,jack=no) + + LDFLAGS="-Wl,-export-dynamic" + EXT=pd_linux + MORECFLAGS="-DDL_OPEN -DPA_USE_OSS -DPA_LITTLE_ENDIAN \ + -DUSEAPI_OSS \ + -I../portaudio/pa_common \ + -I../portaudio/pablio -I../portaudio/portmidi-macosx -Werror" + SYSSRC="s_midi_oss.c s_audio_oss.c" + if test x$portaudio == "xYES"; + then + MORECFLAGS="-DUSEAPI_PORTAUDIO "$MORECFLAGS + SYSSRC="s_audio_pa.c \ + ../portaudio/pa_common/pa_allocation.c \ + ../portaudio/pa_common/pa_converters.c \ + ../portaudio/pa_common/pa_cpuload.c \ + ../portaudio/pa_common/pa_dither.c \ + ../portaudio/pa_common/pa_front.c \ + ../portaudio/pa_common/pa_process.c \ + ../portaudio/pa_common/pa_skeleton.c \ + ../portaudio/pa_common/pa_stream.c \ + ../portaudio/pa_common/pa_trace.c \ + ../portaudio/pablio/pablio_pd.c \ + ../portaudio/pablio/ringbuffer_pd.c \ + ../portaudio/pa_linux_alsa/callback_thread.c \ + ../portaudio/pa_linux_alsa/pa_linux_alsa.c \ + ../portaudio/pa_linux_alsa/blocking_calls.c \ + ../portaudio/pa_unix/pa_unix_hostapis.c \ + ../portaudio/pa_unix/pa_unix_util.c \ + ../portaudio/pa_unix_oss/pa_unix_oss.c "$SYSSRC + fi + STRIPFLAG=-s + GUINAME="pd-gui" + if test x$USE_OPT_CFLAGS == "xYES"; + then + OPT_CFLAGS="-O6 -funroll-loops -fomit-frame-pointer" + else + OPT_CFLAGS="-g" + fi + OSNUMBER=0 +fi + +dnl **** note -- SGI/IRIX code is broken here!!! *** + +if test `uname -s` = IRIX64; +then + LDFLAGS="-n32 -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ + -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \ + -shared -rdata_shared" + EXT=pd_irix6 + MORECFLAGS=-DDL_OPEN + SYSSRC=s_sgi.c + STRIPFLAG=-s + GUINAME="pd-gui" + OSNUMBER=0 +fi + +if test `uname -s` = IRIX32; +then + LDFLAGS="-o32 -DUNIX -DIRIX -O2 -shared -rdata_shared" + EXT=pd_irix5 + MORECFLAGS=-DDL_OPEN + SYSSRC=s_sgi.c + STRIPFLAG=-s + GUINAME="pd-gui" + OSNUMBER=0 +fi + +if test `uname -s` = Darwin; +then + LDFLAGS="-Wl -framework Tcl -framework Tk -framework CoreAudio \ + -framework AudioUnit -framework AudioToolbox \ + -framework Carbon -framework CoreMIDI" + EXT=pd_darwin + MORECFLAGS="-DMACOSX -I/usr/X11R6/include \ + -I../portaudio_v18/pa_common \ + -I../portaudio_v18/pablio \ + -I../portmidi_osx \ + -Wno-error \ + -DUSEAPI_PORTAUDIO -DPA_BIG_ENDIAN" + SYSSRC="s_midi_pm.c s_audio_pa.c \ + ../portaudio_v18/pa_common/pa_lib.c \ + ../portaudio_v18/pa_common/pa_trace.c \ + ../portaudio_v18/pa_common/pa_convert.c \ + ../portaudio_v18/pablio/pablio_pd.c \ + ../portaudio_v18/pablio/ringbuffer_pd.c \ + ../portaudio_v18/pa_mac_core/pa_mac_core.c \ + ../portmidi_osx/pmdarwin.c \ + ../portmidi_osx/pmmacosx.c \ + ../portmidi_osx/pmutil.c \ + ../portmidi_osx/portmidi.c \ + ../portmidi_osx/ptdarwin.c " + STRIPFLAG="" + GUINAME="pdtcl" + GUIFLAGS="-framework Tcl -framework Tk \ + -I/Library/Frameworks/Tk.framework/Versions/Current/Headers \ + -I/Library/Frameworks/Tcl.framework/Versions/Current/Headers \ + -I/Library/Frameworks/Tcl.framework/Versions/8.4/PrivateHeaders" + if test x$USE_OPT_CFLAGS == "xYES"; + then + OPT_CFLAGS="-O2" + else + OPT_CFLAGS="-g" + fi + OSNUMBER=2 + EXTERNTARGET=pd_darwin + if test "x$jack == "xyes"; + then + LDFLAGS=$LDFLAGS" -framework Jack" + MORECFLAGS=$MORECFLAGS" -DUSEAPI_JACK" + SYSSRC=$SYSSRC" s_audio_jack.c" + endif +fi + +AC_OUTPUT(makefile) + diff --git a/pd/src/configure.in.pa_v19 b/pd/src/configure.in.pa_v19 new file mode 100644 index 00000000..5d82597b --- /dev/null +++ b/pd/src/configure.in.pa_v19 @@ -0,0 +1,231 @@ +dnl Process this file with autoconf to produce a configure script. +AC_INIT(d_arithmetic.c) + +AC_SUBST(alsa) +AC_SUBST(jack) +AC_SUBST(PDLIB) +AC_SUBST(DEFINES) +AC_SUBST(MORECFLAGS) +AC_SUBST(EXT) +AC_SUBST(OPT_CFLAGS) +AC_SUBST(USE_OPT_CFLAGS) +AC_SUBST(SYSSRC) +AC_SUBST(STRIPFLAG) +AC_SUBST(GUINAME) +AC_SUBST(GUIFLAGS) +AC_SUBST(OSNUMBER) +AC_SUBST(EXTERNTARGET) + +dnl other defaults + +dnl check for features + +AC_ARG_ENABLE(alsa, [ --disable-alsa disable ALSA], + alsa="no") +AC_ARG_ENABLE(jack, [ --enable-jack jack audio server], + jack="yes") +AC_ARG_ENABLE(debug, [ --enable-debug debugging support], + USE_OPT_CFLAGS="NO", USE_OPT_CFLAGS="YES") + +dnl Checks for programs. +AC_PROG_CC +AC_PROG_INSTALL +AC_PROG_MAKE_SET +AC_PROG_CPP + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST +AC_TYPE_PID_T +AC_TYPE_SIZE_T +AC_HEADER_TIME + +dnl Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS(fcntl.h limits.h malloc.h sys/ioctl.h sys/time.h unistd.h bstring.h) + +dnl Checks for library functions. +AC_PROG_GCC_TRADITIONAL +AC_TYPE_SIGNAL +AC_FUNC_VPRINTF +AC_CHECK_FUNCS(gettimeofday select socket strerror) + + +dnl Checks for libraries. +dnl Checking for `dlopen' function in -ldl: +AC_CHECK_LIB(dl, dlopen,PDLIB="$PDLIB -ldl", + echo "dynamic link support required" || exit 1) + +dnl Checking for `sin' function in -lffm: +dnl ffm is the fast math library on the alpha +AC_CHECK_LIB(ffm, sin,PDLIB="$PDLIB -lffm") + +dnl Checking for `sin' function in -lm: +AC_CHECK_LIB(m, sin,PDLIB="$PDLIB -lm", + echo "math library required" || exit 1) + +dnl Checking for `pthread_create' function in -pthread +AC_CHECK_LIB(pthread, pthread_create,PDLIB="$PDLIB -lpthread", + echo "pthreads required" || exit 1) + +dnl This should be fixed so Pd can use ALSA shared libraries where appropriate. +if test "$alsa" != no; then + AC_CHECK_LIB(asound,snd_pcm_info,PDLIB="$PDLIB -lasound" ; alsa="yes",alsa="") +fi + +dnl Find paths to includes and libraries for X11 +AC_PATH_X +dnl Checking for `XCreateWindow' function in -lX11: +AC_CHECK_LIB(X11, XCreateWindow, LIBS="$LIBS -lX11 -L$x_libraries", + echo "no X11 found" || exit 1, -L$x_libraries) + +dnl look for tcl 8.x... do I really have to go through all this!? + +AC_CHECK_HEADER(tcl8.7/tcl.h,GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.7", + AC_CHECK_HEADER(tcl8.6/tcl.h,GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.6", + AC_CHECK_HEADER(tcl8.5/tcl.h,GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.5", + AC_CHECK_HEADER(tcl8.4/tcl.h,GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.4", + AC_CHECK_HEADER(tcl8.3/tcl.h,GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.3", + AC_CHECK_HEADER(tcl8.2/tcl.h,GUIFLAGS="$GUIFLAGS -I/usr/include/tcl8.2", + AC_CHECK_HEADER(tcl.h,, echo no tcl/tk headers found))))))) + + +AC_CHECK_LIB(tcl8.7, main,, + AC_CHECK_LIB(tcl8.6, main,, + AC_CHECK_LIB(tcl8.5, main,, + AC_CHECK_LIB(tcl8.4, main,, + AC_CHECK_LIB(tcl8.3, main,, + AC_CHECK_LIB(tcl8.2, main,, + AC_CHECK_LIB(tcl8.0, main))))))) + +AC_CHECK_LIB(tk8.7, main,, + AC_CHECK_LIB(tk8.6, main,, + AC_CHECK_LIB(tk8.5, main,, + AC_CHECK_LIB(tk8.4, main,, + AC_CHECK_LIB(tk8.3, main,, + AC_CHECK_LIB(tk8.2, main,, + AC_CHECK_LIB(tk8.0, main))))))) + +dnl Checking for tk.h or tkstep.h - not used at the moment +dnl AC_CHECK_HEADER(tk.h,DEFINES="$DEFINES -DTKINC=\\\"tk.h\\\"") +dnl AC_CHECK_HEADER(tkstep.h,DEFINES="$DEFINES -DTKINC=\\\"tkstep.h\\\"") + +if test `uname -s` = Linux; +then + dnl Ckecking for ALSA + + AC_CHECK_LIB(asound,snd_pcm_open,LIBS="$LIBS -lasound";alsa=yes,alsa=no) + + dnl Checking for JACK + + AC_CHECK_LIB(rt,shm_open,LIBS="$LIBS -lrt") + AC_CHECK_LIB(jack,jack_set_xrun_callback,LIBS="$LIBS -ljack";jack=xrun,jack=no) + AC_CHECK_LIB(jack,jack_set_error_function,LIBS="$LIBS -ljack";jack=yes,jack=no) + + LDFLAGS="-Wl,-export-dynamic" + EXT=pd_linux + MORECFLAGS="-DDL_OPEN -DUSEAPI_PORTAUDIO -DPA_USE_OSS -DPA_LITTLE_ENDIAN \ + -DUSEAPI_OSS \ + -I../portaudio_v18/pa_common \ + -I../portaudio_v18/pablio \ + -I../portaudio/portmidi-macosx -Werror" + SYSSRC="s_midi_oss.c s_audio_pa.c s_audio_oss.c \ + ../portaudio_v18/pa_common/pa_lib.c \ + ../portaudio_v18/pa_common/pa_trace.c \ + ../portaudio_v18/pa_common/pa_convert.c \ + ../portaudio_v18/pablio/pablio_pd.c \ + ../portaudio_v18/pablio/ringbuffer_pd.c \ + + \ + ../portaudio/pa_common/pa_allocation.c \ + ../portaudio/pa_common/pa_converters.c \ + ../portaudio/pa_common/pa_cpuload.c \ + ../portaudio/pa_common/pa_dither.c \ + ../portaudio/pa_common/pa_front.c \ + ../portaudio/pa_common/pa_process.c \ + ../portaudio/pa_common/pa_skeleton.c \ + ../portaudio/pa_common/pa_stream.c \ + ../portaudio/pa_common/pa_trace.c \ + ../portaudio/pablio/pablio_pd.c \ + ../portaudio/pablio/ringbuffer_pd.c \ + ../portaudio/pa_unix/pa_unix_hostapis.c \ + ../portaudio/pa_unix/pa_unix_util.c \ + ../portaudio/pa_unix_oss/pa_unix_oss.c " + STRIPFLAG=-s + GUINAME="pd-gui" + if test $USE_OPT_CFLAGS == "YES"; + then + OPT_CFLAGS="-O6 -funroll-loops -fomit-frame-pointer" + else + OPT_CFLAGS="-g" + fi + OSNUMBER=0 +fi + +dnl **** note -- SGI/IRIX code is broken here!!! *** + +if test `uname -s` = IRIX64; +then + LDFLAGS="-n32 -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ + -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \ + -shared -rdata_shared" + EXT=pd_irix6 + MORECFLAGS=-DDL_OPEN + SYSSRC=s_sgi.c + STRIPFLAG=-s + GUINAME="pd-gui" + OSNUMBER=0 +fi + +if test `uname -s` = IRIX32; +then + LDFLAGS="-o32 -DUNIX -DIRIX -O2 -shared -rdata_shared" + EXT=pd_irix5 + MORECFLAGS=-DDL_OPEN + SYSSRC=s_sgi.c + STRIPFLAG=-s + GUINAME="pd-gui" + OSNUMBER=0 +fi + +if test `uname -s` = Darwin; +then + LDFLAGS="-Wl -framework Tcl -framework Tk -framework CoreAudio \ + -framework AudioUnit -framework AudioToolbox \ + -framework Carbon -framework CoreMIDI" + EXT=pd_darwin + MORECFLAGS="-DMACOSX -I/usr/X11R6/include \ + -I../portaudio_v18/pa_common \ + -I../portaudio_v18/pablio \ + -I../portmidi_osx \ + -Wno-error \ + -DUSEAPI_PORTAUDIO -DPA_BIG_ENDIAN" + SYSSRC="s_midi_pm.c s_audio_pa.c \ + ../portaudio_v18/pa_common/pa_lib.c \ + ../portaudio_v18/pa_common/pa_trace.c \ + ../portaudio_v18/pa_common/pa_convert.c \ + ../portaudio_v18/pablio/pablio_pd.c \ + ../portaudio_v18/pablio/ringbuffer_pd.c \ + ../portaudio_v18/pa_mac_core/pa_mac_core.c \ + ../portmidi_osx/pmdarwin.c \ + ../portmidi_osx/pmmacosx.c \ + ../portmidi_osx/pmutil.c \ + ../portmidi_osx/portmidi.c \ + ../portmidi_osx/ptdarwin.c " + STRIPFLAG="" + GUINAME="pdtcl" + GUIFLAGS="-framework Tcl -framework Tk \ + -I/Library/Frameworks/Tk.framework/Versions/Current/Headers \ + -I/Library/Frameworks/Tcl.framework/Versions/Current/Headers \ + -I/Library/Frameworks/Tcl.framework/Versions/8.4/PrivateHeaders" + if test $USE_OPT_CFLAGS == "YES"; + then + OPT_CFLAGS="-O2" + else + OPT_CFLAGS="-g" + fi + OSNUMBER=2 + EXTERNTARGET=pd_darwin +fi + +AC_OUTPUT(makefile) + diff --git a/pd/src/d_delay.c b/pd/src/d_delay.c index 1d4defcf..920b28e5 100644 --- a/pd/src/d_delay.c +++ b/pd/src/d_delay.c @@ -247,7 +247,7 @@ static t_int *sigvd_perform(t_int *w) int nsamps = ctl->c_n; float limit = nsamps - n - 1; - float fn = n-4; + float fn = n-1; float *vp = ctl->c_vec, *bp, *wp = vp + ctl->c_phase; float zerodel = x->x_zerodel; while (n--) @@ -261,7 +261,7 @@ static t_int *sigvd_perform(t_int *w) fn = fn - 1.0f; idelsamps = delsamps; frac = delsamps - (float)idelsamps; - bp = wp - (idelsamps + 3); + bp = wp - idelsamps; if (bp < vp + 4) bp += nsamps; d = bp[-3]; c = bp[-2]; diff --git a/pd/src/d_global.c b/pd/src/d_global.c index a84a1ae0..d764ee1b 100644 --- a/pd/src/d_global.c +++ b/pd/src/d_global.c @@ -40,11 +40,9 @@ static t_int *sigsend_perform(t_int *w) int n = (int)(w[3]); while (n--) { - float f = *in++; - if (PD_BADFLOAT(f)) - f = 0; - - *out++ = f; + *out = (PD_BADFLOAT(*in) ? 0 : *in); + out++; + in++; } return (w+4); } @@ -244,10 +242,9 @@ static t_int *sigthrow_perform(t_int *w) { while (n--) { - float f = *in++; - if (PD_BADFLOAT(f)) - f = 0; - *out++ += f; + *out += (PD_BADFLOAT(*in) ? 0 : *in); + out++; + in++; } } return (w+4); diff --git a/pd/src/d_osc.c b/pd/src/d_osc.c index a7990fc6..8fe7f29b 100644 --- a/pd/src/d_osc.c +++ b/pd/src/d_osc.c @@ -448,6 +448,10 @@ static t_int *sigvcf_perform(t_int *w) + coefr * re2 - coefi * im; *out2++ = im = coefi * re2 + coefr * im; } + if (PD_BADFLOAT(re)) + re = 0; + if (PD_BADFLOAT(im)) + im = 0; c->c_re = re; c->c_im = im; return (w+7); diff --git a/pd/src/makefile.nt b/pd/src/makefile.nt index 9105d734..f149f01e 100644 --- a/pd/src/makefile.nt +++ b/pd/src/makefile.nt @@ -13,12 +13,12 @@ LIB = /NODEFAULTLIB:libc /NODEFAULTLIB:oldnames /NODEFAULTLIB:kernel \ $(LDIR)\libc.lib $(LDIR)\oldnames.lib $(LDIR)\kernel32.lib \ $(LDIR)\wsock32.lib $(LDIR)\winmm.lib ..\bin\pthreadVC.lib -GLIB = $(LIB) ..\lib\tcl83.lib ..\lib\tk83.lib +GLIB = $(LIB) ..\bin\tcl83.lib ..\bin\tk83.lib CFLAGS = /nologo /W3 /DMSW /DNT /DPD /DPD_INTERNAL /DWIN32 /DWINDOWS /Ox \ -DPA_LITTLE_ENDIAN -DUSEAPI_MMIO -DUSEAPI_PORTAUDIO LFLAGS = /nologo -SYSSRC = s_audio_pa.c s_audio_mmio.c s_midi_pm.c +SYSSRC = s_audio_pa.c s_audio_mmio.c s_midi_mmio.c SRC = g_canvas.c g_graph.c g_text.c g_rtext.c g_array.c g_template.c g_io.c \ g_scalar.c g_traversal.c g_guiconnect.c g_readwrite.c g_editor.c \ @@ -37,56 +37,19 @@ SRC = g_canvas.c g_graph.c g_text.c g_rtext.c g_array.c g_template.c g_io.c \ PADIR = ..\portaudio INCPA = -I$(PADIR) -I$(PADIR)\pa_common -I$(PADIR)\pablio -I..\lib\asio -SRCPA = \ - $(PADIR)/pa_common/pa_allocation.c \ - $(PADIR)/pa_common/pa_converters.c \ - $(PADIR)/pa_common/pa_cpuload.c \ - $(PADIR)/pa_common/pa_dither.c \ - $(PADIR)/pa_common/pa_front.c \ - $(PADIR)/pa_common/pa_process.c \ - $(PADIR)/pa_common/pa_skeleton.c \ - $(PADIR)/pa_common/pa_stream.c \ - $(PADIR)/pa_common/pa_trace.c \ - $(PADIR)/pablio/pablio_pd.c \ - $(PADIR)/pablio/ringbuffer_pd.c \ - $(PADIR)/pa_win/pa_win_hostapis.c \ - $(PADIR)/pa_win/pa_win_util.c \ - $(PADIR)/pa_win/pa_x86_plain_converters.c \ - $(PADIR)/pa_win_wmme/pa_win_wmme.c - -# $(PADIR)/pa_win_ds/dsound_wrapper.c \ -# $(PADIR)/pa_win_ds/pa_dsound.c \ -# $(PADIR)/pa_win_ds/pa_win_ds.c \ - -PAOBJ = \ - pa_allocation.obj pa_converters.obj pa_cpuload.obj pa_dither.obj pa_front.obj \ - pa_process.obj pa_skeleton.obj pa_stream.obj pa_trace.obj pablio_pd.obj \ - ringbuffer_pd.obj pa_win_hostapis.obj pa_win_util.obj \ - pa_x86_plain_converters.obj \ - pa_win_wmme.obj pa_asio.obj \ - -# dsound_wrapper.obj pa_dsound.obj pa_win_ds.obj - - +SRCPA = $(PADIR)/pa_common/pa_lib.c $(PADIR)/pa_common/pa_trace.c \ + $(PADIR)/pablio/pablio_pd.c $(PADIR)/pablio/ringbuffer_pd.c SRCASIO = $(PADIR)/pa_asio/pa_asio.cpp -ASIOLIB = $(LDIR)\user32.lib $(LDIR)\gdi32.lib $(LDIR)\winspool.lib \ - $(LDIR)\comdlg32.lib \ + +ASIOLIB = $(LDIR)\user32.lib $(LDIR)\gdi32.lib $(LDIR)\winspool.lib $(LDIR)\comdlg32.lib \ $(LDIR)\advapi32.lib $(LDIR)\shell32.lib $(LDIR)\ole32.lib $(LDIR)\oleaut32.lib $(LDIR)\uuid.lib \ $(LDIR)\odbc32.lib $(LDIR)\odbccp32.lib ..\lib\asio\asiolib.lib -PMDIR = ..\portmidi -INCPM = -I$(PMDIR)\pm_common -I$(PMDIR)\pm_win -I$(PMDIR)\porttime -SRCPM = \ - $(PMDIR)/pm_common/portmidi.c \ - $(PMDIR)/pm_common/pmutil.c \ - $(PMDIR)/pm_win/pmwin.c \ - $(PMDIR)/pm_win/pmwinmm.c \ - $(PMDIR)/porttime/porttime.c \ - $(PMDIR)/porttime/ptwinmm.c \ -PMOBJ = portmidi.obj pmutil.obj pmwin.obj pmwinmm.obj porttime.obj ptwinmm.obj +PAOBJ = pa_lib.obj pa_trace.obj pablio_pd.obj ringbuffer_pd.obj pa_asio.obj -OBJC = $(SRC:.c=.obj) $(PAOBJ) $(PMOBJ) + +OBJC = $(SRC:.c=.obj) $(PAOBJ) GSRC = t_main.c t_tkcmd.c @@ -124,60 +87,19 @@ gui: ..\bin\pdtcl.dll link $(LFLAGS) /out:..\bin\pdreceive.exe /INCREMENTAL:NO u_pdreceive.obj \ $(LIB) -# explicit rules to compile portaudio and portmidi sources: -pa_allocation.obj: $(PADIR)\pa_common\pa_allocation.c - cl /c $(ALLCF) $(PADIR)\pa_common\pa_allocation.c -pa_converters.obj: $(PADIR)\pa_common\pa_converters.c - cl /c $(ALLCF) $(PADIR)\pa_common\pa_converters.c -pa_cpuload.obj: $(PADIR)\pa_common\pa_cpuload.c - cl /c $(ALLCF) $(PADIR)\pa_common\pa_cpuload.c -pa_dither.obj: $(PADIR)\pa_common\pa_dither.c - cl /c $(ALLCF) $(PADIR)\pa_common\pa_dither.c -pa_front.obj: $(PADIR)\pa_common\pa_front.c - cl /c $(ALLCF) $(PADIR)\pa_common\pa_front.c -pa_process.obj: $(PADIR)\pa_common\pa_process.c - cl /c $(ALLCF) $(PADIR)\pa_common\pa_process.c -pa_skeleton.obj: $(PADIR)\pa_common\pa_skeleton.c - cl /c $(ALLCF) $(PADIR)\pa_common\pa_skeleton.c -pa_stream.obj: $(PADIR)\pa_common\pa_stream.c - cl /c $(ALLCF) $(PADIR)\pa_common\pa_stream.c +# explicit rules to compile portaudio sources: +pa_lib.obj: $(PADIR)\pa_common\pa_lib.c + cl /c $(ALLCF) $(PADIR)\pa_common\pa_lib.c pa_trace.obj: $(PADIR)\pa_common\pa_trace.c cl /c $(ALLCF) $(PADIR)\pa_common\pa_trace.c pablio_pd.obj: $(PADIR)\pablio\pablio_pd.c cl /c $(ALLCF) $(PADIR)\pablio\pablio_pd.c ringbuffer_pd.obj: $(PADIR)\pablio\ringbuffer_pd.c cl /c $(ALLCF) $(PADIR)\pablio\ringbuffer_pd.c -pa_win_hostapis.obj: $(PADIR)\pa_win\pa_win_hostapis.c - cl /c $(ALLCF) $(PADIR)\pa_win\pa_win_hostapis.c -pa_win_util.obj: $(PADIR)\pa_win\pa_win_util.c - cl /c $(ALLCF) $(PADIR)\pa_win\pa_win_util.c -pa_x86_plain_converters.obj: $(PADIR)\pa_win\pa_x86_plain_converters.c - cl /c $(ALLCF) $(PADIR)\pa_win\pa_x86_plain_converters.c -dsound_wrapper.obj: $(PADIR)\pa_win_ds\dsound_wrapper.c - cl /c $(ALLCF) $(PADIR)\pa_win_ds\dsound_wrapper.c -pa_dsound.obj: $(PADIR)\pa_win_ds\pa_dsound.c - cl /c $(ALLCF) $(PADIR)\pa_win_ds\pa_dsound.c -pa_win_ds.obj: $(PADIR)\pa_win_ds\pa_win_ds.c - cl /c $(ALLCF) $(PADIR)\pa_win_ds\pa_win_ds.c -pa_win_wmme.obj: $(PADIR)\pa_win_wmme\pa_win_wmme.c - cl /c $(ALLCF) $(PADIR)\pa_win_wmme\pa_win_wmme.c pa_asio.obj: $(PADIR)\pa_asio\pa_asio.cpp cl /c $(ALLCF) $(PADIR)\pa_asio\pa_asio.cpp -portmidi.obj: $(PMDIR)\pm_common\portmidi.c - cl /c $(ALLCF) $(PMDIR)\pm_common\portmidi.c -pmutil.obj: $(PMDIR)\pm_common\pmutil.c - cl /c $(ALLCF) $(PMDIR)\pm_common\pmutil.c -pmwin.obj: $(PMDIR)\pm_win\pmwin.c - cl /c $(ALLCF) $(PMDIR)\pm_win\pmwin.c -pmwinmm.obj: $(PMDIR)\pm_win\pmwinmm.c - cl /c $(ALLCF) $(PMDIR)\pm_win\pmwinmm.c -porttime.obj: $(PMDIR)\porttime\porttime.c - cl /c $(ALLCF) $(PMDIR)\porttime\porttime.c -ptwinmm.obj: $(PMDIR)\porttime\ptwinmm.c - cl /c $(ALLCF) $(PMDIR)\porttime\ptwinmm.c - # the following should also clean up "bin" but it doesn't because "bin" holds # precious stuff from elsewhere. clean: diff --git a/pd/src/makefile.nt.pa19 b/pd/src/makefile.nt.pa19 new file mode 100644 index 00000000..9105d734 --- /dev/null +++ b/pd/src/makefile.nt.pa19 @@ -0,0 +1,185 @@ +# Makefile for PD on MSW + +all: pd gui ..\bin\pd.tk ..\bin\pdsend.exe ..\bin\pdreceive.exe + +VC = "C:\Program Files\Microsoft Visual Studio\VC98" +#VC="\Program Files\DevStudio\Vc" +INCLUDE = -I.\ -I..\Tcl\include -I$(VC)\include + +LDIR = $(VC)\lib + +LIB = /NODEFAULTLIB:libc /NODEFAULTLIB:oldnames /NODEFAULTLIB:kernel \ + /NODEFAULTLIB:uuid \ + $(LDIR)\libc.lib $(LDIR)\oldnames.lib $(LDIR)\kernel32.lib \ + $(LDIR)\wsock32.lib $(LDIR)\winmm.lib ..\bin\pthreadVC.lib + +GLIB = $(LIB) ..\lib\tcl83.lib ..\lib\tk83.lib +CFLAGS = /nologo /W3 /DMSW /DNT /DPD /DPD_INTERNAL /DWIN32 /DWINDOWS /Ox \ + -DPA_LITTLE_ENDIAN -DUSEAPI_MMIO -DUSEAPI_PORTAUDIO +LFLAGS = /nologo + +SYSSRC = s_audio_pa.c s_audio_mmio.c s_midi_pm.c + +SRC = g_canvas.c g_graph.c g_text.c g_rtext.c g_array.c g_template.c g_io.c \ + g_scalar.c g_traversal.c g_guiconnect.c g_readwrite.c g_editor.c \ + g_all_guis.c g_bang.c g_hdial.c g_hslider.c g_mycanvas.c g_numbox.c \ + g_toggle.c g_vdial.c g_vslider.c g_vumeter.c \ + m_pd.c m_class.c m_obj.c m_atom.c m_memory.c m_binbuf.c \ + m_conf.c m_glob.c m_sched.c \ + s_main.c s_inter.c s_file.c s_print.c \ + s_loader.c s_path.c s_entry.c s_audio.c s_midi.c \ + d_ugen.c d_ctl.c d_arithmetic.c d_osc.c d_filter.c d_dac.c d_misc.c \ + d_math.c d_fft.c d_mayer_fft.c d_fftroutine.c d_array.c d_global.c \ + d_delay.c d_resample.c \ + x_arithmetic.c x_connective.c x_interface.c x_midi.c x_misc.c \ + x_time.c x_acoustics.c x_net.c x_qlist.c x_gui.c d_soundfile.c \ + $(SYSSRC) + +PADIR = ..\portaudio +INCPA = -I$(PADIR) -I$(PADIR)\pa_common -I$(PADIR)\pablio -I..\lib\asio +SRCPA = \ + $(PADIR)/pa_common/pa_allocation.c \ + $(PADIR)/pa_common/pa_converters.c \ + $(PADIR)/pa_common/pa_cpuload.c \ + $(PADIR)/pa_common/pa_dither.c \ + $(PADIR)/pa_common/pa_front.c \ + $(PADIR)/pa_common/pa_process.c \ + $(PADIR)/pa_common/pa_skeleton.c \ + $(PADIR)/pa_common/pa_stream.c \ + $(PADIR)/pa_common/pa_trace.c \ + $(PADIR)/pablio/pablio_pd.c \ + $(PADIR)/pablio/ringbuffer_pd.c \ + $(PADIR)/pa_win/pa_win_hostapis.c \ + $(PADIR)/pa_win/pa_win_util.c \ + $(PADIR)/pa_win/pa_x86_plain_converters.c \ + $(PADIR)/pa_win_wmme/pa_win_wmme.c + +# $(PADIR)/pa_win_ds/dsound_wrapper.c \ +# $(PADIR)/pa_win_ds/pa_dsound.c \ +# $(PADIR)/pa_win_ds/pa_win_ds.c \ + +PAOBJ = \ + pa_allocation.obj pa_converters.obj pa_cpuload.obj pa_dither.obj pa_front.obj \ + pa_process.obj pa_skeleton.obj pa_stream.obj pa_trace.obj pablio_pd.obj \ + ringbuffer_pd.obj pa_win_hostapis.obj pa_win_util.obj \ + pa_x86_plain_converters.obj \ + pa_win_wmme.obj pa_asio.obj \ + +# dsound_wrapper.obj pa_dsound.obj pa_win_ds.obj + + +SRCASIO = $(PADIR)/pa_asio/pa_asio.cpp +ASIOLIB = $(LDIR)\user32.lib $(LDIR)\gdi32.lib $(LDIR)\winspool.lib \ + $(LDIR)\comdlg32.lib \ +$(LDIR)\advapi32.lib $(LDIR)\shell32.lib $(LDIR)\ole32.lib $(LDIR)\oleaut32.lib $(LDIR)\uuid.lib \ +$(LDIR)\odbc32.lib $(LDIR)\odbccp32.lib ..\lib\asio\asiolib.lib + +PMDIR = ..\portmidi +INCPM = -I$(PMDIR)\pm_common -I$(PMDIR)\pm_win -I$(PMDIR)\porttime +SRCPM = \ + $(PMDIR)/pm_common/portmidi.c \ + $(PMDIR)/pm_common/pmutil.c \ + $(PMDIR)/pm_win/pmwin.c \ + $(PMDIR)/pm_win/pmwinmm.c \ + $(PMDIR)/porttime/porttime.c \ + $(PMDIR)/porttime/ptwinmm.c \ + +PMOBJ = portmidi.obj pmutil.obj pmwin.obj pmwinmm.obj porttime.obj ptwinmm.obj + +OBJC = $(SRC:.c=.obj) $(PAOBJ) $(PMOBJ) + +GSRC = t_main.c t_tkcmd.c + +GOBJ = $(GSRC:.c=.obj) +.PHONY: pd gui + +ALLCF = $(CFLAGS) $(INCLUDE) $(INCASIO) $(INCPA) $(INCPM) /D_WINDOWS /DPA_NO_DS + +.c.obj: + cl /c $(ALLCF) /Tc$*.c + +pd: ..\bin\pd.exe + +gui: ..\bin\pdtcl.dll + +..\bin\pd.exe: s_entry.obj ..\bin\pd.lib + link $(LFLAGS) /out:..\bin\pd.exe /INCREMENTAL:NO s_entry.obj \ + ..\bin\pd.lib $(LIB) $(ASIOLIB) + +..\bin\pd.dll ..\bin\pd.lib: $(OBJC) $(OBJASIO) + link $(LFLAGS) /dll /export:sys_main /out:..\bin\pd.dll $(OBJC) \ + $(OBJASIO) $(LIB) $(ASIOLIB) + +..\bin\pdtcl.dll: t_tkcmd.obj + link $(LFLAGS) /dll /export:Pdtcl_Init /out:..\bin\pdtcl.dll \ + t_tkcmd.obj $(GLIB) + +..\bin\pd.tk: u_main.tk; copy u_main.tk ..\bin\pd.tk + +..\bin\pdsend.exe: u_pdsend.obj + link $(LFLAGS) /out:..\bin\pdsend.exe /INCREMENTAL:NO u_pdsend.obj \ + $(LIB) + +..\bin\pdreceive.exe: u_pdreceive.obj + link $(LFLAGS) /out:..\bin\pdreceive.exe /INCREMENTAL:NO u_pdreceive.obj \ + $(LIB) + +# explicit rules to compile portaudio and portmidi sources: +pa_allocation.obj: $(PADIR)\pa_common\pa_allocation.c + cl /c $(ALLCF) $(PADIR)\pa_common\pa_allocation.c +pa_converters.obj: $(PADIR)\pa_common\pa_converters.c + cl /c $(ALLCF) $(PADIR)\pa_common\pa_converters.c +pa_cpuload.obj: $(PADIR)\pa_common\pa_cpuload.c + cl /c $(ALLCF) $(PADIR)\pa_common\pa_cpuload.c +pa_dither.obj: $(PADIR)\pa_common\pa_dither.c + cl /c $(ALLCF) $(PADIR)\pa_common\pa_dither.c +pa_front.obj: $(PADIR)\pa_common\pa_front.c + cl /c $(ALLCF) $(PADIR)\pa_common\pa_front.c +pa_process.obj: $(PADIR)\pa_common\pa_process.c + cl /c $(ALLCF) $(PADIR)\pa_common\pa_process.c +pa_skeleton.obj: $(PADIR)\pa_common\pa_skeleton.c + cl /c $(ALLCF) $(PADIR)\pa_common\pa_skeleton.c +pa_stream.obj: $(PADIR)\pa_common\pa_stream.c + cl /c $(ALLCF) $(PADIR)\pa_common\pa_stream.c +pa_trace.obj: $(PADIR)\pa_common\pa_trace.c + cl /c $(ALLCF) $(PADIR)\pa_common\pa_trace.c +pablio_pd.obj: $(PADIR)\pablio\pablio_pd.c + cl /c $(ALLCF) $(PADIR)\pablio\pablio_pd.c +ringbuffer_pd.obj: $(PADIR)\pablio\ringbuffer_pd.c + cl /c $(ALLCF) $(PADIR)\pablio\ringbuffer_pd.c +pa_win_hostapis.obj: $(PADIR)\pa_win\pa_win_hostapis.c + cl /c $(ALLCF) $(PADIR)\pa_win\pa_win_hostapis.c +pa_win_util.obj: $(PADIR)\pa_win\pa_win_util.c + cl /c $(ALLCF) $(PADIR)\pa_win\pa_win_util.c +pa_x86_plain_converters.obj: $(PADIR)\pa_win\pa_x86_plain_converters.c + cl /c $(ALLCF) $(PADIR)\pa_win\pa_x86_plain_converters.c +dsound_wrapper.obj: $(PADIR)\pa_win_ds\dsound_wrapper.c + cl /c $(ALLCF) $(PADIR)\pa_win_ds\dsound_wrapper.c +pa_dsound.obj: $(PADIR)\pa_win_ds\pa_dsound.c + cl /c $(ALLCF) $(PADIR)\pa_win_ds\pa_dsound.c +pa_win_ds.obj: $(PADIR)\pa_win_ds\pa_win_ds.c + cl /c $(ALLCF) $(PADIR)\pa_win_ds\pa_win_ds.c +pa_win_wmme.obj: $(PADIR)\pa_win_wmme\pa_win_wmme.c + cl /c $(ALLCF) $(PADIR)\pa_win_wmme\pa_win_wmme.c + +pa_asio.obj: $(PADIR)\pa_asio\pa_asio.cpp + cl /c $(ALLCF) $(PADIR)\pa_asio\pa_asio.cpp + +portmidi.obj: $(PMDIR)\pm_common\portmidi.c + cl /c $(ALLCF) $(PMDIR)\pm_common\portmidi.c +pmutil.obj: $(PMDIR)\pm_common\pmutil.c + cl /c $(ALLCF) $(PMDIR)\pm_common\pmutil.c +pmwin.obj: $(PMDIR)\pm_win\pmwin.c + cl /c $(ALLCF) $(PMDIR)\pm_win\pmwin.c +pmwinmm.obj: $(PMDIR)\pm_win\pmwinmm.c + cl /c $(ALLCF) $(PMDIR)\pm_win\pmwinmm.c +porttime.obj: $(PMDIR)\porttime\porttime.c + cl /c $(ALLCF) $(PMDIR)\porttime\porttime.c +ptwinmm.obj: $(PMDIR)\porttime\ptwinmm.c + cl /c $(ALLCF) $(PMDIR)\porttime\ptwinmm.c + +# the following should also clean up "bin" but it doesn't because "bin" holds +# precious stuff from elsewhere. +clean: + del *.obj + diff --git a/pd/src/s_audio_alsa.c.old b/pd/src/s_audio_alsa.c.old new file mode 100644 index 00000000..99ca3403 --- /dev/null +++ b/pd/src/s_audio_alsa.c.old @@ -0,0 +1,946 @@ +/* Copyright (c) 1997-2003 Guenter Geiger, Miller Puckette, Larry Troxler, +* Winfried Ritsch, Karl MacMillan, and others. +* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ + +/* this file inputs and outputs audio using the ALSA API available on linux. */ + +#include <alsa/asoundlib.h> + +#include "m_pd.h" +#include "s_stuff.h" +#include <errno.h> +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <sys/time.h> +#include <sys/stat.h> +#include <sys/ioctl.h> +#include <fcntl.h> +#include <sched.h> +#include <sys/mman.h> + +typedef int16_t t_alsa_sample16; +typedef int32_t t_alsa_sample32; +#define ALSA_SAMPLEWIDTH_16 sizeof(t_alsa_sample16) +#define ALSA_SAMPLEWIDTH_32 sizeof(t_alsa_sample32) +#define ALSA_XFERSIZE16 (signed int)(sizeof(t_alsa_sample16) * DEFDACBLKSIZE) +#define ALSA_XFERSIZE32 (signed int)(sizeof(t_alsa_sample32) * DEFDACBLKSIZE) +#define ALSA_MAXDEV 1 +#define ALSA_JITTER 1024 +#define ALSA_EXTRABUFFER 2048 +#define ALSA_DEFFRAGSIZE 64 +#define ALSA_DEFNFRAG 12 + +#ifndef INT32_MAX +#define INT32_MAX 0x7fffffff +#endif + +#if (SND_LIB_MAJOR < 1) +#define ALSAAPI9 +#endif + +typedef struct _alsa_dev +{ + snd_pcm_t *inhandle; + snd_pcm_t *outhandle; + int innoninterleave; /* true if we're set for noninterleaved read */ + int outnoninterleave; /* same for write */ +} t_alsa_dev; + +t_alsa_dev alsa_device; +static void *alsa_snd_buf = 0; +static void **alsa_buf_ptrs; +static int alsa_samplewidth; +static snd_pcm_status_t* in_status; +static snd_pcm_status_t* out_status; + +static int alsa_mode; +static int alsa_buf_samps; /* believed actual ALSA bufsize in sample frames */ +static int alsa_inchannels; +static int alsa_outchannels; + +/* Defines */ +#define DEBUG(x) x +#define DEBUG2(x) {x;} + +static void alsa_checkiosync( void); +static void alsa_numbertoname(int devno, char *devname, int nchar); + + /* don't assume we can turn all 31 bits when doing float-to-fix; + otherwise some audio drivers (e.g. Midiman/ALSA) wrap around. */ +#define FMAX 0x7ffff000 +#define CLIP32(x) (((x)>FMAX)?FMAX:((x) < -FMAX)?-FMAX:(x)) + +/* support for ALSA pcmv2 api by Karl MacMillan<karlmac@peabody.jhu.edu> */ + +static void check_error(int err, const char *why) +{ + if (err < 0) + fprintf(stderr, "%s: %s\n", why, snd_strerror(err)); +} + +/* was: alsa_open_audio(int wantinchans, int wantoutchans, int srate) */ + +int alsa_open_audio(int naudioindev, int *audioindev, int nchindev, + int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev, + int *choutdev, int rate) +{ + int err, inchans = 0, outchans = 0, subunitdir; + char devname[512]; + snd_pcm_hw_params_t* hw_params; + snd_pcm_sw_params_t* sw_params; + snd_output_t* out; + int frag_size = (sys_blocksize ? sys_blocksize : ALSA_DEFFRAGSIZE); + int nfrags, i; + short* tmp_buf; + unsigned int tmp_uint; + snd_pcm_uframes_t tmp_snd_pcm_uframes; + int wantinchans, wantoutchans, devno; + + if (naudioindev >= 2 || naudiooutdev >= 2) + post("alsa: only one input and output device allowed (extras ignored"); + if (naudioindev >= 1 && naudiooutdev >= 1 && + audioindev[0] != audiooutdev[0]) + post("alsa: changing output device to agree with input device"); + if (nchindev) + wantinchans = chindev[0]; + else wantinchans = (naudioindev ? 2 : 0); + if (nchoutdev) + wantoutchans = choutdev[0]; + else wantoutchans = (naudiooutdev ? 2 : 0); + devno = (naudioindev > 0 ? audioindev[0] : + (naudiooutdev > 0 ? audiooutdev[0] : 0)); + + alsa_numbertoname(devno, devname, 512); + + if (sys_verbose) + post("device name %s; channels in %d, out %d", devname, wantinchans, + wantoutchans); + + nfrags = sys_schedadvance * (float)rate / (1e6 * frag_size); + /* save our belief as to ALSA's buffer size for later */ + alsa_buf_samps = nfrags * frag_size; + + if (sys_verbose) + post("audio buffer set to %d", (int)(0.001 * sys_schedadvance)); + + alsa_device.innoninterleave = alsa_device.outnoninterleave = 0; + if (wantinchans) + { + err = snd_pcm_open(&alsa_device.inhandle, devname, + SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK); + + check_error(err, "snd_pcm_open (input)"); + if (err < 0) + inchans = 0; + else + { + inchans = wantinchans; + snd_pcm_nonblock(alsa_device.inhandle, 1); + } + } + if (wantoutchans) + { + err = snd_pcm_open(&alsa_device.outhandle, devname, + SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); + + check_error(err, "snd_pcm_open (output)"); + if (err < 0) + outchans = 0; + else + { + outchans = wantoutchans; + snd_pcm_nonblock(alsa_device.outhandle, 1); + } + } + if (inchans) + { + if (sys_verbose) + post("opening sound input..."); + err = snd_pcm_hw_params_malloc(&hw_params); + check_error(err, "snd_pcm_hw_params_malloc (input)"); + + // get the default params + err = snd_pcm_hw_params_any(alsa_device.inhandle, hw_params); + check_error(err, "snd_pcm_hw_params_any (input)"); + + /* try to set interleaved access */ + err = snd_pcm_hw_params_set_access(alsa_device.inhandle, + hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); + if (err < 0) + { + /* OK, so try non-interleaved */ + err = snd_pcm_hw_params_set_access(alsa_device.inhandle, + hw_params, SND_PCM_ACCESS_RW_NONINTERLEAVED); + if (err >= 0) + { + post("using non-interleaved audio input"); + alsa_device.innoninterleave = 1; + } + } + check_error(err, "snd_pcm_hw_params_set_access (input)"); + // Try to set 32 bit format first + err = snd_pcm_hw_params_set_format(alsa_device.inhandle, hw_params, + SND_PCM_FORMAT_S32); + if (err < 0) + { + /* fprintf(stderr, + "PD-ALSA: 32 bit format not available - using 16\n"); */ + err = snd_pcm_hw_params_set_format(alsa_device.inhandle, hw_params, + SND_PCM_FORMAT_S16); + check_error(err, "snd_pcm_hw_params_set_format (input)"); + alsa_samplewidth = 2; + } + else + { + alsa_samplewidth = 4; + } + post("Sample width set to %d bytes", alsa_samplewidth); + // set the subformat + err = snd_pcm_hw_params_set_subformat(alsa_device.inhandle, hw_params, + SND_PCM_SUBFORMAT_STD); + check_error(err, "snd_pcm_hw_params_set_subformat (input)"); + // set the number of channels + tmp_uint = inchans; + err = snd_pcm_hw_params_set_channels_min(alsa_device.inhandle, + hw_params, &tmp_uint); + check_error(err, "snd_pcm_hw_params_set_channels (input)"); + if (tmp_uint != (unsigned)inchans) + post("ALSA: set input channels to %d", tmp_uint); + inchans = tmp_uint; + // set the sampling rate + err = snd_pcm_hw_params_set_rate_min(alsa_device.inhandle, hw_params, + &rate, 0); + check_error(err, "snd_pcm_hw_params_set_rate_min (input)"); +#if 0 + err = snd_pcm_hw_params_get_rate(hw_params, &subunitdir); + post("input sample rate %d", err); +#endif + // set the period - ie frag size + // post("fragsize a %d", frag_size); + + /* LATER try this to get a recommended period size... + right now, it trips an assertion failure in ALSA lib */ +#if 0 + post("input period was %d, min %d, max %d\n", + snd_pcm_hw_params_get_period_size(hw_params, 0), + snd_pcm_hw_params_get_period_size_min(hw_params, 0), + snd_pcm_hw_params_get_period_size_max(hw_params, 0)); +#endif +#ifdef ALSAAPI9 + err = snd_pcm_hw_params_set_period_size_near(alsa_device.inhandle, + hw_params, + (snd_pcm_uframes_t) + frag_size, 0); +#else + tmp_snd_pcm_uframes = frag_size; + err = snd_pcm_hw_params_set_period_size_near(alsa_device.inhandle, + hw_params, &tmp_snd_pcm_uframes, 0); +#endif + check_error(err, "snd_pcm_hw_params_set_period_size_near (input)"); + // post("fragsize b %d", frag_size); + // set the number of periods - ie numfrags + // post("nfrags a %d", nfrags); +#ifdef ALSAAPI9 + err = snd_pcm_hw_params_set_periods_near(alsa_device.inhandle, + hw_params, nfrags, 0); +#else + tmp_uint = nfrags; + err = snd_pcm_hw_params_set_periods_near(alsa_device.inhandle, + hw_params, &tmp_uint, 0); +#endif + check_error(err, "snd_pcm_hw_params_set_periods_near (input)"); + // set the buffer size +#ifdef ALSAAPI9 + err = snd_pcm_hw_params_set_buffer_size_near(alsa_device.inhandle, + hw_params, nfrags * frag_size); +#else + tmp_snd_pcm_uframes = nfrags * frag_size; + err = snd_pcm_hw_params_set_buffer_size_near(alsa_device.inhandle, + hw_params, &tmp_snd_pcm_uframes); +#endif + check_error(err, "snd_pcm_hw_params_set_buffer_size_near (input)"); + + err = snd_pcm_hw_params(alsa_device.inhandle, hw_params); + check_error(err, "snd_pcm_hw_params (input)"); + + snd_pcm_hw_params_free(hw_params); + + err = snd_pcm_sw_params_malloc(&sw_params); + check_error(err, "snd_pcm_sw_params_malloc (input)"); + err = snd_pcm_sw_params_current(alsa_device.inhandle, sw_params); + check_error(err, "snd_pcm_sw_params_current (input)"); + err = snd_pcm_sw_params_set_start_threshold(alsa_device.inhandle, + sw_params, nfrags * frag_size); + check_error(err, "snd_pcm_sw_params_set_start_threshold (input)"); + err = snd_pcm_sw_params_set_stop_threshold(alsa_device.inhandle, + sw_params, 0x7fffffff); + check_error(err, "snd_pcm_sw_params_set_stop_threshold (input)"); + err = snd_pcm_sw_params_set_avail_min(alsa_device.inhandle, sw_params, + frag_size); + check_error(err, "snd_pcm_sw_params_set_avail_min (input)"); + err = snd_pcm_sw_params(alsa_device.inhandle, sw_params); + check_error(err, "snd_pcm_sw_params (input)"); + + snd_pcm_sw_params_free(sw_params); + + snd_output_stdio_attach(&out, stderr, 0); +#if 0 + if (sys_verbose) + { + snd_pcm_dump_hw_setup(alsa_device.inhandle, out); + snd_pcm_dump_sw_setup(alsa_device.inhandle, out); + } +#endif + } + + if (outchans) + { + int foo; + if (sys_verbose) + post("opening sound output..."); + err = snd_pcm_hw_params_malloc(&hw_params); + check_error(err, "snd_pcm_sw_params (output)"); + + // get the default params + err = snd_pcm_hw_params_any(alsa_device.outhandle, hw_params); + check_error(err, "snd_pcm_hw_params_any (output)"); + // set interleaved access - FIXME deal with other access types + err = snd_pcm_hw_params_set_access(alsa_device.outhandle, hw_params, + SND_PCM_ACCESS_RW_INTERLEAVED); + check_error(err, "snd_pcm_hw_params_set_access (output)"); + + /* try to set interleaved access */ + err = snd_pcm_hw_params_set_access(alsa_device.outhandle, + hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); + if (err < 0) + { + /* OK, so try non-interleaved */ + err = snd_pcm_hw_params_set_access(alsa_device.outhandle, + hw_params, SND_PCM_ACCESS_RW_NONINTERLEAVED); + if (err >= 0) + { + post("using non-interleaved audio"); + alsa_device.outnoninterleave = 1; + } + } + check_error(err, "snd_pcm_hw_params_set_access (output)"); + + + // Try to set 32 bit format first + err = snd_pcm_hw_params_set_format(alsa_device.outhandle, hw_params, + SND_PCM_FORMAT_S32); + if (err < 0) + { + err = snd_pcm_hw_params_set_format(alsa_device.outhandle, + hw_params,SND_PCM_FORMAT_S16); + check_error(err, "snd_pcm_hw_params_set_format (output)"); + /* fprintf(stderr, + "PD-ALSA: 32 bit format not available - using 16\n"); */ + alsa_samplewidth = 2; + } + else + { + alsa_samplewidth = 4; + } + // set the subformat + err = snd_pcm_hw_params_set_subformat(alsa_device.outhandle, hw_params, + SND_PCM_SUBFORMAT_STD); + check_error(err, "snd_pcm_hw_params_set_subformat (output)"); + // set the number of channels + tmp_uint = outchans; + err = snd_pcm_hw_params_set_channels_min(alsa_device.outhandle, + hw_params, &tmp_uint); + check_error(err, "snd_pcm_hw_params_set_channels (output)"); + if (tmp_uint != (unsigned)outchans) + post("alsa: set output channels to %d", tmp_uint); + outchans = tmp_uint; + // set the sampling rate + err = snd_pcm_hw_params_set_rate_min(alsa_device.outhandle, hw_params, + &rate, 0); + check_error(err, "snd_pcm_hw_params_set_rate_min (output)"); +#if 0 + err = snd_pcm_hw_params_get_rate(hw_params, &subunitdir); + post("output sample rate %d", err); +#endif + // set the period - ie frag size +#if 0 + post("output period was %d, min %d, max %d\n", + snd_pcm_hw_params_get_period_size(hw_params, 0), + snd_pcm_hw_params_get_period_size_min(hw_params, 0), + snd_pcm_hw_params_get_period_size_max(hw_params, 0)); +#endif + // post("fragsize c %d", frag_size); +#ifdef ALSAAPI9 + err = snd_pcm_hw_params_set_period_size_near(alsa_device.outhandle, + hw_params, + (snd_pcm_uframes_t) + frag_size, 0); +#else + tmp_snd_pcm_uframes = frag_size; + err = snd_pcm_hw_params_set_period_size_near(alsa_device.outhandle, + hw_params, &tmp_snd_pcm_uframes, 0); +#endif + // post("fragsize d %d", frag_size); + check_error(err, "snd_pcm_hw_params_set_period_size_near (output)"); + // set the number of periods - ie numfrags +#ifdef ALSAAPI9 + err = snd_pcm_hw_params_set_periods_near(alsa_device.outhandle, + hw_params, nfrags, 0); +#else + tmp_uint = nfrags; + err = snd_pcm_hw_params_set_periods_near(alsa_device.outhandle, + hw_params, &tmp_uint, 0); +#endif + check_error(err, "snd_pcm_hw_params_set_periods_near (output)"); + // set the buffer size +#ifdef ALSAAPI9 + err = snd_pcm_hw_params_set_buffer_size_near(alsa_device.outhandle, + hw_params, nfrags * frag_size); +#else + tmp_snd_pcm_uframes = nfrags * frag_size; + err = snd_pcm_hw_params_set_buffer_size_near(alsa_device.outhandle, + hw_params, &tmp_snd_pcm_uframes); +#endif + check_error(err, "snd_pcm_hw_params_set_buffer_size_near (output)"); + + err = snd_pcm_hw_params(alsa_device.outhandle, hw_params); + check_error(err, "snd_pcm_hw_params (output)"); + + snd_pcm_hw_params_free(hw_params); + + err = snd_pcm_sw_params_malloc(&sw_params); + check_error(err, "snd_pcm_sw_params_malloc (output)"); + err = snd_pcm_sw_params_current(alsa_device.outhandle, sw_params); + check_error(err, "snd_pcm_sw_params_current (output)"); + err = snd_pcm_sw_params_set_start_threshold(alsa_device.outhandle, + sw_params, nfrags * frag_size); + check_error(err, "snd_pcm_sw_params_set_start_threshold (output)"); + err = snd_pcm_sw_params_set_stop_threshold(alsa_device.outhandle, + sw_params, 0x7fffffff); + check_error(err, "snd_pcm_sw_params_set_stop_threshold (output)"); + err = snd_pcm_sw_params_set_avail_min(alsa_device.outhandle, sw_params, + frag_size); + check_error(err, "snd_pcm_sw_params_set_avail_min (output)"); + err = snd_pcm_sw_params(alsa_device.outhandle, sw_params); + check_error(err, "snd_pcm_sw_params (output)"); + snd_pcm_sw_params_free(sw_params); + + snd_output_stdio_attach(&out, stderr, 0); +#if 0 + if (sys_verbose) + { + snd_pcm_dump_hw_setup(alsa_device.outhandle, out); + snd_pcm_dump_sw_setup(alsa_device.outhandle, out); + } +#endif + } + + if (inchans) + snd_pcm_prepare(alsa_device.inhandle); + if (outchans) + snd_pcm_prepare(alsa_device.outhandle); + + // if duplex we can link the channels so they start together + if (inchans && outchans) + snd_pcm_link(alsa_device.inhandle, alsa_device.outhandle); + + // set up the status variables + err = snd_pcm_status_malloc(&in_status); + check_error(err, "snd_pcm_status_malloc"); + err = snd_pcm_status_malloc(&out_status); + check_error(err, "snd_pcm_status_malloc"); + + // set up the buffer + if (alsa_snd_buf) + free(alsa_snd_buf); + alsa_snd_buf = (void *)malloc( + sizeof(char) * alsa_samplewidth * DEFDACBLKSIZE * + (outchans > inchans ? outchans : inchans)); + memset(alsa_snd_buf, 0, sizeof(char) * alsa_samplewidth * DEFDACBLKSIZE * + (outchans > inchans ? outchans : inchans)); + /* make an array of pointers too in case we need them */ + if (alsa_buf_ptrs) + free(alsa_buf_ptrs); + alsa_buf_ptrs = (void **)malloc( + sizeof(void *) * (outchans > inchans ? outchans : inchans)); + for (i = 0; i < (outchans > inchans ? outchans : inchans); i++) + alsa_buf_ptrs[i] = (t_alsa_sample32 *)alsa_snd_buf + i * DEFDACBLKSIZE; + + // fill the buffer with silence + if (outchans) + { + i = (frag_size * nfrags)/DEFDACBLKSIZE + 1; + while (i--) + { + if (alsa_device.outnoninterleave) + snd_pcm_writen(alsa_device.outhandle, alsa_buf_ptrs, + DEFDACBLKSIZE); + else snd_pcm_writei(alsa_device.outhandle, alsa_snd_buf, + DEFDACBLKSIZE); + } + /* confused about this: */ + /* if ((err = snd_pcm_start(alsa_device.outhandle) < 0)) + check_error(err, "output start failed\n"); */ + } + else if (inchans) + { + if (snd_pcm_start(alsa_device.inhandle) < 0) + check_error(err, "input start failed\n"); + } + alsa_outchannels = outchans; + alsa_inchannels = inchans; + + return (!(inchans || outchans)); +} + +void alsa_close_audio(void) +{ + int err; + if (alsa_inchannels) + { + err = snd_pcm_close(alsa_device.inhandle); + check_error(err, "snd_pcm_close (input)"); + } + if (alsa_outchannels) + { + err = snd_pcm_close(alsa_device.outhandle); + check_error(err, "snd_pcm_close (output)"); + } +} + +// #define DEBUG_ALSA_XFER + +int alsa_send_dacs(void) +{ + static int16_t *sp; + static int xferno = 0; + static int callno = 0; + static double timenow; + double timelast; + t_sample *fp, *fp1, *fp2; + int i, j, k, err, devno = 0; + int inputcount = 0, outputcount = 0, inputlate = 0, outputlate = 0; + int result; + int inchannels = (sys_inchannels > alsa_inchannels ? + alsa_inchannels : sys_inchannels); + int outchannels = (sys_outchannels > alsa_outchannels ? + alsa_outchannels : sys_outchannels); + unsigned int intransfersize = DEFDACBLKSIZE; + unsigned int outtransfersize = DEFDACBLKSIZE; + + // get the status + if (!inchannels && !outchannels) + { + return SENDDACS_NO; + } + + timelast = timenow; + timenow = sys_getrealtime(); + +#ifdef DEBUG_ALSA_XFER + if (timenow - timelast > 0.050) + fprintf(stderr, "(%d)", + (int)(1000 * (timenow - timelast))), fflush(stderr); +#endif + + callno++; + + alsa_checkiosync(); /* check I/O are in sync and data not late */ + + if (alsa_inchannels) + { + snd_pcm_status(alsa_device.inhandle, in_status); + if (snd_pcm_status_get_avail(in_status) < intransfersize) + return SENDDACS_NO; + } + if (alsa_outchannels) + { + snd_pcm_status(alsa_device.outhandle, out_status); + if (snd_pcm_status_get_avail(out_status) < outtransfersize) + return SENDDACS_NO; + } + + /* do output */ + if (alsa_outchannels) + { + fp = sys_soundout; + if (alsa_samplewidth == 4) + { + if (alsa_device.outnoninterleave) + { + int n = outchannels * DEFDACBLKSIZE; + for (i = 0, fp1 = fp; i < n; i++) + { + float s1 = *fp1 * INT32_MAX; + ((t_alsa_sample32 *)alsa_snd_buf)[i] = CLIP32(s1); + } + n = alsa_outchannels * DEFDACBLKSIZE; + for (; i < n; i++) + ((t_alsa_sample32 *)alsa_snd_buf)[i] = 0; + } + else + { + for (i = 0, fp1 = fp; i < outchannels; i++, + fp1 += DEFDACBLKSIZE) + { + for (j = i, k = DEFDACBLKSIZE, fp2 = fp1; k--; + j += alsa_outchannels, fp2++) + { + float s1 = *fp2 * INT32_MAX; + ((t_alsa_sample32 *)alsa_snd_buf)[j] = CLIP32(s1); + } + } + } + } + else + { + for (i = 0, fp1 = fp; i < outchannels; i++, fp1 += DEFDACBLKSIZE) + { + for (j = i, k = DEFDACBLKSIZE, fp2 = fp1; k--; + j += alsa_outchannels, fp2++) + { + int s = *fp2 * 32767.; + if (s > 32767) + s = 32767; + else if (s < -32767) + s = -32767; + ((t_alsa_sample16 *)alsa_snd_buf)[j] = s; + } + } + } + + if (alsa_device.outnoninterleave) + result = snd_pcm_writen(alsa_device.outhandle, alsa_buf_ptrs, + outtransfersize); + else result = snd_pcm_writei(alsa_device.outhandle, alsa_snd_buf, + outtransfersize); + + if (result != (int)outtransfersize) + { + #ifdef DEBUG_ALSA_XFER + if (result >= 0 || errno == EAGAIN) + fprintf(stderr, "ALSA: write returned %d of %d\n", + result, outtransfersize); + else fprintf(stderr, "ALSA: write: %s\n", + snd_strerror(errno)); + fprintf(stderr, + "inputcount %d, outputcount %d, outbufsize %d\n", + inputcount, outputcount, + (ALSA_EXTRABUFFER + sys_advance_samples) + * alsa_samplewidth * outchannels); + #endif + sys_log_error(ERR_DACSLEPT); + return (SENDDACS_NO); + } + + /* zero out the output buffer */ + memset(sys_soundout, 0, DEFDACBLKSIZE * sizeof(*sys_soundout) * + sys_outchannels); + if (sys_getrealtime() - timenow > 0.002) + { + #ifdef DEBUG_ALSA_XFER + fprintf(stderr, "output %d took %d msec\n", + callno, (int)(1000 * (timenow - timelast))), fflush(stderr); + #endif + timenow = sys_getrealtime(); + sys_log_error(ERR_DACSLEPT); + } + } + /* do input */ + if (alsa_inchannels) + { + if (alsa_device.innoninterleave) + result = snd_pcm_readn(alsa_device.inhandle, alsa_buf_ptrs, + intransfersize); + else result = snd_pcm_readi(alsa_device.inhandle, alsa_snd_buf, + intransfersize); + if (result < (int)intransfersize) + { +#ifdef DEBUG_ALSA_XFER + if (result < 0) + fprintf(stderr, + "snd_pcm_read %d %d: %s\n", + callno, xferno, snd_strerror(errno)); + else fprintf(stderr, + "snd_pcm_read %d %d returned only %d\n", + callno, xferno, result); + fprintf(stderr, + "inputcount %d, outputcount %d, inbufsize %d\n", + inputcount, outputcount, + (ALSA_EXTRABUFFER + sys_advance_samples) + * alsa_samplewidth * inchannels); +#endif + sys_log_error(ERR_ADCSLEPT); + return (SENDDACS_NO); + } + fp = sys_soundin; + if (alsa_samplewidth == 4) + { + if (alsa_device.innoninterleave) + { + int n = inchannels * DEFDACBLKSIZE; + for (i = 0, fp1 = fp; i < n; i++) + *fp1 = (float) ((t_alsa_sample32 *)alsa_snd_buf)[i] + * (1./ INT32_MAX); + } + else + { + for (i = 0, fp1 = fp; i < inchannels; + i++, fp1 += DEFDACBLKSIZE) + { + for (j = i, k = DEFDACBLKSIZE, fp2 = fp1; k--; + j += alsa_inchannels, fp2++) + *fp2 = (float) ((t_alsa_sample32 *)alsa_snd_buf)[j] + * (1./ INT32_MAX); + } + } + } + else + { + for (i = 0, fp1 = fp; i < inchannels; i++, fp1 += DEFDACBLKSIZE) + { + for (j = i, k = DEFDACBLKSIZE, fp2 = fp1; k--; + j += alsa_inchannels, fp2++) + *fp2 = (float) ((t_alsa_sample16 *)alsa_snd_buf)[j] + * 3.051850e-05; + } + } + } + xferno++; + if (sys_getrealtime() - timenow > 0.002) + { +#ifdef DEBUG_ALSA_XFER + fprintf(stderr, "routine took %d msec\n", + (int)(1000 * (sys_getrealtime() - timenow))); +#endif + sys_log_error(ERR_ADCSLEPT); + } + return SENDDACS_YES; +} + +void alsa_printstate( void) +{ + int i, result; + snd_pcm_sframes_t indelay, outdelay; + if (sys_audioapi != API_ALSA) + { + error("restart-audio: implemented for ALSA only."); + return; + } + if (sys_inchannels) + { + result = snd_pcm_delay(alsa_device.inhandle, &indelay); + if (result < 0) + post("snd_pcm_delay 1 failed"); + else post("in delay %d", indelay); + } + if (sys_outchannels) + { + result = snd_pcm_delay(alsa_device.outhandle, &outdelay); + if (result < 0) + post("snd_pcm_delay 2 failed"); + else post("out delay %d", outdelay); + } + post("sum %d (%d mod 64)\n", indelay + outdelay, (indelay+outdelay)%64); + + post("buf samples %d", alsa_buf_samps); +} + + +void alsa_resync( void) +{ + int i, result; + if (sys_audioapi != API_ALSA) + { + error("restart-audio: implemented for ALSA only."); + return; + } + memset(alsa_snd_buf, 0, + sizeof(char) * alsa_samplewidth * DEFDACBLKSIZE * sys_outchannels); + for (i = 0; i < 1000000; i++) + { + if (alsa_device.outnoninterleave) + result = snd_pcm_writen(alsa_device.outhandle, alsa_buf_ptrs, + DEFDACBLKSIZE); + else result = snd_pcm_writei(alsa_device.outhandle, alsa_snd_buf, + DEFDACBLKSIZE); + if (result != (int)DEFDACBLKSIZE) + break; + } + post("%d written", i); +} + +void alsa_putzeros(int n) +{ + int i, result; + memset(alsa_snd_buf, 0, + sizeof(char) * alsa_samplewidth * DEFDACBLKSIZE * alsa_outchannels); + for (i = 0; i < n; i++) + { + if (alsa_device.outnoninterleave) + result = snd_pcm_writen(alsa_device.outhandle, alsa_buf_ptrs, + DEFDACBLKSIZE); + else result = snd_pcm_writei(alsa_device.outhandle, alsa_snd_buf, + DEFDACBLKSIZE); +#if 0 + if (result != DEFDACBLKSIZE) + post("result %d", result); +#endif + } +} + +void alsa_getzeros(int n) +{ + int i, result; + for (i = 0; i < n; i++) + { + result = snd_pcm_readi(alsa_device.inhandle, alsa_snd_buf, + DEFDACBLKSIZE); +#if 0 + if (result != DEFDACBLKSIZE) + post("result %d", result); +#endif + } +} + + /* call this only if both input and output are open */ +static void alsa_checkiosync( void) +{ + int i, result, checkit = 1, giveup = 1000, alreadylogged = 0; + snd_pcm_sframes_t indelay, outdelay, defect; + + if (!(alsa_outchannels && alsa_inchannels)) + return; + while (checkit) + { + checkit = 0; + if (giveup-- <= 0) + return; + result = snd_pcm_delay(alsa_device.outhandle, &outdelay); + if (result < 0) + { + post("output snd_pcm_delay failed: %s", snd_strerror(result)); + if (snd_pcm_status(alsa_device.outhandle, out_status) < 0) + post("output snd_pcm_status failed"); + else post("astate %d", + snd_pcm_status_get_state(out_status)); + return; + } + if (outdelay < 0) + sys_log_error(ERR_DATALATE), alreadylogged = 1; + + if (sys_inchannels) + { + result = snd_pcm_delay(alsa_device.inhandle, &indelay); + if (result < 0) + { + post("input snd_pcm_delay failed"); + return; + } + defect = indelay + outdelay - alsa_buf_samps; + if (defect < -DEFDACBLKSIZE) + { + checkit = 1; + alsa_putzeros(1); + if (!alreadylogged) + sys_log_error(ERR_RESYNC), alreadylogged = 1; + } + else if (defect > 0) + { + checkit = 1; + alsa_getzeros(1); + if (!alreadylogged) + sys_log_error(ERR_RESYNC), alreadylogged = 1; + } + } + } +} + +void alsa_listdevs( void) +{ + post("device listing not implemented in ALSA yet\n"); +} + +static int alsa_nnames = 0; +static char **alsa_names = 0; + +void alsa_adddev(char *name) +{ + if (alsa_nnames) + alsa_names = (char **)t_resizebytes(alsa_names, + alsa_nnames * sizeof(char *), + (alsa_nnames+1) * sizeof(char *)); + else alsa_names = (char **)t_getbytes(sizeof(char *)); + alsa_names[alsa_nnames] = gensym(name)->s_name; + alsa_nnames++; +} + +static void alsa_numbertoname(int devno, char *devname, int nchar) +{ + int ndev = 0, cardno = -1; + while (!snd_card_next(&cardno) && cardno >= 0) + ndev++; + if (devno < 2*ndev) + { + if (devno & 1) + snprintf(devname, nchar, "plughw:%d", devno/2); + else snprintf(devname, nchar, "hw:%d", devno/2); + } + else if (devno <2*ndev + alsa_nnames) + snprintf(devname, nchar, "%s", alsa_names[devno - 2*ndev]); + else snprintf(devname, nchar, "???"); +} + + /* For each hardware card found, we list two devices, the "hard" and + "plug" one. The card scan is derived from portaudio code. */ +void alsa_getdevs(char *indevlist, int *nindevs, + char *outdevlist, int *noutdevs, int *canmulti, + int maxndev, int devdescsize) +{ + int ndev = 0, cardno = -1, i, j; + *canmulti = 0; /* only one device; must be the same for input&output */ + while (!snd_card_next(&cardno) && cardno >= 0) + { + snd_ctl_t *ctl; + snd_ctl_card_info_t *info; + char devname[80]; + const char *desc; + if (2 * ndev + 2 > maxndev) + break; + /* apparently, "cardno" is just a counter; but check that here */ + if (ndev != cardno) + fprintf(stderr, "oops: ALSA cards not reported in order?\n"); + sprintf(devname, "hw:%d", cardno ); + /* fprintf(stderr, "\ntry %s...\n", devname); */ + if (snd_ctl_open(&ctl, devname, 0) >= 0) + { + snd_ctl_card_info_malloc(&info); + snd_ctl_card_info(ctl, info); + desc = snd_ctl_card_info_get_name(info); + snd_ctl_card_info_free(info); + } + else + { + fprintf(stderr, "ALSA card scan error\n"); + desc = "???"; + } + /* fprintf(stderr, "name: %s\n", snd_ctl_card_info_get_name(info)); */ + sprintf(indevlist + 2*ndev * devdescsize, "%s (hardware)", desc); + sprintf(indevlist + (2*ndev + 1) * devdescsize, "%s (plug-in)", desc); + sprintf(outdevlist + 2*ndev * devdescsize, "%s (hardware)", desc); + sprintf(outdevlist + (2*ndev + 1) * devdescsize, "%s (plug-in)", desc); + ndev++; + } + for (i = 0, j = 2*ndev; i < alsa_nnames; i++, j++) + { + if (j >= maxndev) + break; + snprintf(indevlist + j * devdescsize, devdescsize, "%s", + alsa_names[i]); + } + *nindevs = *noutdevs = j; +} diff --git a/pd/src/x_midi.c b/pd/src/x_midi.c index 7eac1108..1ff0e4b3 100644 --- a/pd/src/x_midi.c +++ b/pd/src/x_midi.c @@ -85,24 +85,23 @@ static void midiin_setup(void) void inmidi_byte(int portno, int byte) { - static int sysex; t_atom at[2]; - if (byte == 0xf0) - sysex |= (1 << portno); - if (sysexin_sym->s_thing && (sysex & (1 << portno))) + if (midiin_sym->s_thing) { SETFLOAT(at, byte); SETFLOAT(at+1, portno + 1); - pd_list(sysexin_sym->s_thing, 0, 2, at); + pd_list(midiin_sym->s_thing, 0, 2, at); } - if (byte == 0xf7) - sysex &= (~(1 << portno)); +} - if (midiin_sym->s_thing) +void inmidi_sysex(int portno, int byte) +{ + t_atom at[2]; + if (sysexin_sym->s_thing) { SETFLOAT(at, byte); SETFLOAT(at+1, portno + 1); - pd_list(midiin_sym->s_thing, 0, 2, at); + pd_list(sysexin_sym->s_thing, 0, 2, at); } } |