├── .github └── workflows │ ├── linux.yaml │ ├── macos.yaml │ └── windows.yaml ├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── CudaTool.py ├── DistTar.py ├── DistZip.py ├── INSTALL ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.rst ├── SConstruct ├── SiteConfig.py ├── TODO.txt ├── applications └── wavelab │ ├── FilterWidget.py │ ├── OscWidget.py │ ├── Wavelab.py │ ├── layout.glade │ └── layout2.glade ├── docs ├── How_To_Reverse_Engineer_a_Csound_Instrument.odt ├── reference │ └── Doxyfile.in └── user_guide │ ├── Makefile │ ├── my │ ├── __init__.py │ ├── ipython_console_highlighting.py │ ├── mathmpl.py │ └── pyexec_directive.py │ ├── source │ ├── _static │ │ ├── bebot-rt.wav │ │ ├── overrides.css │ │ └── piano-rt.wav │ ├── audio_playback.rst │ ├── basics.rst │ ├── basics │ │ ├── audiostream_creation.rst │ │ ├── basic_manipulations.rst │ │ ├── buffer_creation.rst │ │ ├── data_types.rst │ │ ├── plotting.rst │ │ └── wavefile_io.rst │ ├── conf.py │ ├── fft.rst │ ├── filters.rst │ ├── generators.rst │ ├── images │ │ ├── Speaker_Icon.svg │ │ ├── audioplayback_interface.pdf │ │ ├── audioplayback_interface.png │ │ ├── audioplayback_interface.svg │ │ ├── bebot.png │ │ ├── jack.png │ │ ├── matplotlib_interface.pdf │ │ ├── matplotlib_interface.png │ │ ├── matplotlib_interface.svg │ │ └── matplotlib_plot.pdf │ ├── index.rst │ ├── instruments.rst │ ├── intro │ │ ├── build_and_installing.rst │ │ ├── getting_started.rst │ │ └── what_is_nsound.rst │ ├── introduction.rst │ ├── realtime_audio.rst │ └── stretcher.rst │ └── util.py ├── external ├── cygwin │ └── lib │ │ ├── amd64 │ │ └── portaudio.lib │ │ └── x86 │ │ └── portaudio.lib ├── include │ └── portaudio.h └── win32 │ └── lib │ ├── x64 │ └── portaudio.lib │ └── x86 │ └── portaudio.lib ├── msvs ├── cepstral_pitch_estimate.vcxproj ├── dynamic_filter.vcxproj ├── example1.vcxproj ├── example2.vcxproj ├── example3.vcxproj ├── example4.vcxproj ├── example5.vcxproj ├── example6.vcxproj ├── libnsound.vcxproj ├── mynameis.vcxproj ├── nsound.sln ├── properties.props └── stretcher.vcxproj ├── nsound_config.py ├── nsound_config_cygwin.py ├── nsound_config_linux.py ├── nsound_config_mac.py ├── nsound_config_windows.py ├── setup.py ├── setup_builder.py.in ├── site_scons └── site_tools │ ├── AcGenerateFile.py │ ├── DetectBoost.py │ ├── ImportPythonConfig.py │ ├── PythonSetup.py │ ├── SvnVersion.py │ ├── SwigGen.py │ └── _nsound_utils.py ├── src ├── Nsound │ ├── AudioBackend.cc │ ├── AudioBackend.h │ ├── AudioBackendLibao.cc │ ├── AudioBackendLibao.h │ ├── AudioBackendLibportaudio.cc │ ├── AudioBackendLibportaudio.h │ ├── AudioBackendType.h │ ├── AudioPlayback.cc │ ├── AudioPlayback.h │ ├── AudioPlaybackRt.cc │ ├── AudioPlaybackRt.h │ ├── AudioStream.cc │ ├── AudioStream.h │ ├── AudioStreamSelection.cc │ ├── AudioStreamSelection.h │ ├── Buffer.cc │ ├── Buffer.h │ ├── BufferSelection.cc │ ├── BufferSelection.h │ ├── BufferWindowSearch.cc │ ├── BufferWindowSearch.h │ ├── CircularBuffer.cc │ ├── CircularBuffer.h │ ├── CircularIterators.h │ ├── Clarinet.cc │ ├── Clarinet.h │ ├── Cosine.cc │ ├── Cosine.h │ ├── CudaUtils.cu │ ├── CudaUtils.h │ ├── DelayLine.cc │ ├── DelayLine.h │ ├── DrumBD01.cc │ ├── DrumBD01.h │ ├── DrumKickBass.cc │ ├── DrumKickBass.h │ ├── EnvelopeAdsr.cc │ ├── EnvelopeAdsr.h │ ├── FFTChunk.cc │ ├── FFTChunk.h │ ├── FFTransform.cc │ ├── FFTransform.h │ ├── Filter.cc │ ├── Filter.h │ ├── FilterAllPass.cc │ ├── FilterAllPass.h │ ├── FilterBandPassFIR.cc │ ├── FilterBandPassFIR.h │ ├── FilterBandPassIIR.cc │ ├── FilterBandPassIIR.h │ ├── FilterBandPassVocoder.cc │ ├── FilterBandPassVocoder.h │ ├── FilterBandRejectFIR.cc │ ├── FilterBandRejectFIR.h │ ├── FilterBandRejectIIR.cc │ ├── FilterBandRejectIIR.h │ ├── FilterCombLowPassFeedback.cc │ ├── FilterCombLowPassFeedback.h │ ├── FilterDC.cc │ ├── FilterDC.h │ ├── FilterDelay.cc │ ├── FilterDelay.h │ ├── FilterFlanger.cc │ ├── FilterFlanger.h │ ├── FilterHighPassFIR.cc │ ├── FilterHighPassFIR.h │ ├── FilterHighPassIIR.cc │ ├── FilterHighPassIIR.h │ ├── FilterIIR.cc │ ├── FilterIIR.h │ ├── FilterLeastSquaresFIR.cc │ ├── FilterLeastSquaresFIR.h │ ├── FilterLowPassFIR.cc │ ├── FilterLowPassFIR.h │ ├── FilterLowPassIIR.cc │ ├── FilterLowPassIIR.h │ ├── FilterLowPassMoogVcf.cc │ ├── FilterLowPassMoogVcf.h │ ├── FilterMedian.cpp │ ├── FilterMedian.hpp │ ├── FilterMovingAverage.cc │ ├── FilterMovingAverage.h │ ├── FilterParametricEqualizer.cc │ ├── FilterParametricEqualizer.h │ ├── FilterPhaser.cc │ ├── FilterPhaser.h │ ├── FilterSlinky.cc │ ├── FilterSlinky.h │ ├── FilterStageIIR.cc │ ├── FilterStageIIR.h │ ├── FilterTone.cc │ ├── FilterTone.h │ ├── FluteSlide.cc │ ├── FluteSlide.h │ ├── Generator.cc │ ├── Generator.h │ ├── GeneratorDecay.cc │ ├── GeneratorDecay.h │ ├── Granulator.cc │ ├── Granulator.h │ ├── GuitarBass.cc │ ├── GuitarBass.h │ ├── Hat.cc │ ├── Hat.h │ ├── Instrument.h │ ├── Kernel.cc │ ├── Kernel.h │ ├── Macros.h │ ├── Mesh2D.cc │ ├── Mesh2D.h │ ├── MeshJunction.cc │ ├── MeshJunction.h │ ├── Mixer.cc │ ├── Mixer.h │ ├── MixerNode.cc │ ├── MixerNode.h │ ├── Nsound.h.in │ ├── NsoundAll.h │ ├── OrganPipe.cc │ ├── OrganPipe.h │ ├── Plotter.cc │ ├── Plotter.h │ ├── Pluck.cc │ ├── Pluck.h │ ├── Pulse.cc │ ├── Pulse.h │ ├── RandomNumberGenerator.h │ ├── ReverberationRoom.cc │ ├── ReverberationRoom.h │ ├── RngTausworthe.cc │ ├── RngTausworthe.h │ ├── SConscript │ ├── Sawtooth.cc │ ├── Sawtooth.h │ ├── Sine.cc │ ├── Sine.h │ ├── Spectrogram.cc │ ├── Spectrogram.h │ ├── Square.cc │ ├── Square.h │ ├── StreamOperators.cc │ ├── StreamOperators.h │ ├── Stretcher.cc │ ├── Stretcher.h │ ├── StretcherCuda.cu │ ├── StretcherCuda.h │ ├── TicToc.cc │ ├── TicToc.h │ ├── Triangle.cc │ ├── Triangle.h │ ├── Utils.cc │ ├── Utils.h │ ├── Vocoder.cc │ ├── Vocoder.h │ ├── Wavefile.cc │ ├── Wavefile.h │ └── WindowType.h ├── __init__.py ├── bin │ ├── SConscript │ ├── ns_readwaveheader.cc │ └── ns_vocoder.cc ├── examples │ ├── SConscript │ ├── Temperature_in.wav │ ├── bebot-disp.py │ ├── bebot.cc │ ├── bebot.py │ ├── california.wav │ ├── cepstral_pitch_estimate.cc │ ├── delayline-rt.py │ ├── dynamic_filter.cc │ ├── dynamic_filter.py │ ├── example1.cc │ ├── example1.py │ ├── example2.cc │ ├── example2.py │ ├── example3.cc │ ├── example3.py │ ├── example4.cc │ ├── example4.py │ ├── example5.cc │ ├── example5.py │ ├── example6.cc │ ├── example6.py │ ├── getWavefiles.bash │ ├── interstellar.cc │ ├── make_oscilloscope_video.py │ ├── moogvcf-rt.py │ ├── mynameis.cc │ ├── mynameis.wav │ ├── piano.py │ ├── ringing.py │ ├── stretcher.cc │ ├── stretcher.py │ ├── tapedeck-rt.py │ └── walle.wav ├── plugins │ ├── gimp │ │ ├── NsoundGimpFFT.py │ │ ├── NsoundGimpHighLowPass.py │ │ ├── NsoundGimpUtils.py │ │ └── NsoundGimpWavefile.py │ └── ladspa │ │ ├── Makefile │ │ ├── filter1.cc │ │ └── guitarBass.cc └── test │ ├── BufferResample_UnitTest.cc │ ├── Buffer_UnitTest.cc │ ├── DelayLine_UnitTest.cc │ ├── FFTransform_UnitTest.cc │ ├── FilterCombLowPassFeedback_UnitTest.cc │ ├── FilterDelay_UnitTest.cc │ ├── FilterLeastSquaresFIR_UnitTest.cc │ ├── FilterLowPassIIR_UnitTest.py │ ├── FilterMedian_UnitTest.cc │ ├── FilterParametricEqualizer_UnitTest.cc │ ├── Generator_UnitTest.cc │ ├── Main.cc │ ├── SConscript │ ├── Sine_UnitTest.cc │ ├── Test.h │ ├── Triangle_UnitTest.cc │ ├── UnitTest.h │ ├── Wavefile_UnitTest.cc │ ├── __init__.py │ ├── gold │ ├── BufferResample_out_1_2.wav │ ├── BufferResample_out_2_1.wav │ ├── BufferResample_out_2_3.wav │ ├── BufferResample_out_3_2.wav │ ├── BufferResample_out_3_5.wav │ ├── BufferResample_out_4_7.wav │ ├── BufferResample_out_5_3.wav │ ├── BufferResample_out_7_4.wav │ ├── Buffer_out1.wav │ ├── Buffer_out2.wav │ ├── DelayLine_out1.wav │ ├── FFTransform_out1.wav │ ├── FFTransform_out2.wav │ ├── FFTransform_out3.wav │ ├── FFTransform_out4.wav │ ├── FFTransform_out5.wav │ ├── FFTransform_out6.wav │ ├── FilterBandRejectFIR_out1.wav │ ├── FilterBandRejectFIR_out2.wav │ ├── FilterCombLowPassFeedback_out1.wav │ ├── FilterCombLowPassFeedback_out2.wav │ ├── FilterDelay_out1.wav │ ├── FilterDelay_out2.wav │ ├── FilterDelay_out3.wav │ ├── FilterLeastSquaresFIR_out1.wav │ ├── FilterLeastSquaresFIR_out2.wav │ ├── FilterLeastSquaresFIR_out3.wav │ ├── FilterParametricEqualizer_out_high.wav │ ├── FilterParametricEqualizer_out_low.wav │ ├── FilterParametricEqualizer_out_peaking.wav │ ├── Filter_noise.wav │ ├── Generator_buzz1.wav │ ├── Generator_buzz2.wav │ ├── Generator_buzz3.wav │ ├── Generator_chorus1.wav │ ├── Generator_line1.wav │ ├── Generator_line2.wav │ ├── Generator_sine1.wav │ ├── Generator_sine2.wav │ ├── Generator_sine3.wav │ ├── Generator_sine4.wav │ ├── Generator_sine5.wav │ ├── Generator_sine6.wav │ ├── Sine_1.wav │ ├── Sine_2.wav │ ├── Sine_3.wav │ ├── Sine_4.wav │ ├── Sine_5.wav │ ├── Sine_6.wav │ ├── Sine_7.wav │ ├── Triangle_1.0Hz.wav │ ├── Triangle_1_to_5Hz.wav │ ├── Triangle_2Hz.wav │ ├── Wavefile_out1.wav │ ├── Wavefile_out2.wav │ ├── filter_fir_band_pass.wav │ ├── filter_fir_band_pass_dynamic.wav │ ├── filter_fir_band_reject.wav │ ├── filter_fir_band_reject_dynamic.wav │ ├── filter_fir_high_pass.wav │ ├── filter_fir_high_pass_dynamic.wav │ ├── filter_fir_low_pass.wav │ ├── filter_fir_low_pass_dynamic.wav │ ├── filter_iir_band_pass.wav │ ├── filter_iir_band_pass_dynamic.wav │ ├── filter_iir_band_reject.wav │ ├── filter_iir_band_reject_dynamic.wav │ ├── filter_iir_high_pass.wav │ ├── filter_iir_high_pass_dynamic.wav │ ├── filter_iir_low_pass.wav │ └── filter_iir_low_pass_dynamic.wav │ ├── test_AudioPlaybackRt.py │ ├── test_AudioStream.py │ ├── test_Buffer.py │ ├── test_DelayLine.py │ ├── test_FilterMedian.py │ ├── test_Wavefile.py │ ├── test_audio_stream.cc │ ├── test_convolve.cc │ ├── test_fft.cc │ ├── test_filters.cc │ ├── test_filters.py │ ├── test_generators.cc │ ├── test_granulator.cc │ ├── test_iir_ga.cc │ ├── test_mesh.cc │ ├── test_mixer.cc │ ├── test_moving_average.cc │ ├── test_plotter.cc │ ├── test_pluck.cc │ └── test_rng.cc ├── swig ├── AudioPlaybackRt.i ├── AudioStream.i ├── Buffer.i ├── Nsound.i ├── Plotter.i ├── SConscript ├── ignored.i └── typemaps.i └── windows_env64.bat /.github/workflows/linux.yaml: -------------------------------------------------------------------------------- 1 | name: linux 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - 'release/**' 8 | pull_request: 9 | branches: 10 | - master 11 | - 'release/**' 12 | 13 | jobs: 14 | build: 15 | 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | name: Checkout source 21 | - name: Install dependencies 22 | run: | 23 | sudo apt-get update && sudo apt-get -y install portaudio19-dev libao-dev python3-virtualenv 24 | python3 -m venv venv 25 | . venv/bin/activate 26 | pip install matplotlib scons wheel 27 | - name: Build nsound 28 | run: | 29 | . venv/bin/activate 30 | scons 31 | - name: Run unit tests 32 | run: | 33 | . venv/bin/activate 34 | scons --unit-test 35 | - name: Run python tests 36 | run: | 37 | . venv/bin/activate 38 | scons --pytest --disable-libportaudio --config=force 39 | -------------------------------------------------------------------------------- /.github/workflows/macos.yaml: -------------------------------------------------------------------------------- 1 | name: macos 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - 'release/**' 8 | pull_request: 9 | branches: 10 | - master 11 | - 'release/**' 12 | 13 | jobs: 14 | 15 | macos: 16 | 17 | runs-on: macos-latest 18 | 19 | steps: 20 | - uses: actions/checkout@v2 21 | name: Checkout source 22 | - uses: actions/setup-python@v2 23 | name: Install Python 24 | - name: Install dependencies 25 | run: | 26 | pip3 install matplotlib scons wheel 27 | - name: Build nsound 28 | run: | 29 | scons 30 | - name: Run unit tests 31 | run: | 32 | scons --unit-test 33 | - name: Run python tests 34 | run: | 35 | scons --pytest --disable-libportaudio --config=force 36 | -------------------------------------------------------------------------------- /.github/workflows/windows.yaml: -------------------------------------------------------------------------------- 1 | name: windows 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - 'release/**' 8 | pull_request: 9 | branches: 10 | - master 11 | - 'release/**' 12 | 13 | jobs: 14 | 15 | windows: 16 | 17 | runs-on: windows-latest 18 | 19 | steps: 20 | - uses: actions/checkout@v2 21 | name: Checkout source 22 | - uses: actions/setup-python@v2 23 | name: Install Python 24 | - name: Install dependencies 25 | run: | 26 | pip3 install matplotlib scons wheel 27 | - name: Build nsound 28 | run: | 29 | scons 30 | - name: Run unit tests 31 | run: | 32 | scons --unit-test 33 | - name: Run python tests 34 | run: | 35 | scons --pytest --disable-libportaudio --config=force 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.exe 3 | *.lib 4 | *.o 5 | *.obj 6 | *.os 7 | *.pyc 8 | *.pyo 9 | *.so 10 | *~ 11 | .sconf_temp 12 | .sconsign.dblite 13 | Nsound.egg-info/ 14 | build/ 15 | config.log 16 | core 17 | dist/ 18 | portaudio.log 19 | setup_builder.py 20 | src/Nsound/Nsound.h 21 | src/bin/ns_readwaveheader 22 | src/bin/ns_vocoder 23 | src/examples/bebot 24 | src/examples/cepstral_pitch_estimate 25 | src/examples/dynamic_filter 26 | src/examples/example1 27 | src/examples/example2 28 | src/examples/example3 29 | src/examples/example4 30 | src/examples/example5 31 | src/examples/example6 32 | src/examples/interstellar 33 | src/examples/mynameis 34 | src/examples/stretcher 35 | src/test/Main 36 | src/test/test_wavefile1.wav 37 | src/test/test_wavefile2.wav 38 | swig/Nsound.py 39 | swig/nsound_wrap.cxx 40 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | $Id: AUTHORS 757 2013-09-08 01:04:43Z weegreenblobbie $ 2 | 3 | Authors of Nsound. 4 | 5 | Nick Hilton. Developed first C++ framework for Nsound v0.1 and released it 6 | under the GPL in August 2005. 7 | 8 | Nick can be reached at weegreenblobbie2_gmail_com. 9 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // $Id: INSTALL 757 2013-09-08 01:04:43Z weegreenblobbie $ 4 | // 5 | /////////////////////////////////////////////////////////////////////////////// 6 | 7 | Always check the Nsound User's Guide for the latest information on how to build 8 | and install Nsound: 9 | 10 | http://nsound.sourceforge.net/users_guide/index.html 11 | 12 | Nsound has the following dependencies for build: 13 | 14 | 1) Python (www.python.org) $ apt-get install python 15 | 2) Scons (www.scons.org) $ apt-get install scons 16 | 17 | Optional packages for plotting: 18 | 19 | 3) Python Numpy (for Matplotlib) 20 | 4) Python Matplotlib (Pylab) 21 | 22 | 23 | How to build the Nsound C++ package on Linux or Mac: 24 | 25 | 1) Uncompress the package: 26 | 27 | [~]$ tar xfz nsound-A.B.C.tar.gz 28 | 29 | 2) Execute Scons 30 | 31 | [~]$ cd nsound-A.B.C 32 | [nsound-A.B.C]$ scons 33 | 34 | To compile with debug flags and no optimizations for debugging: 35 | 36 | [nsound-A.B.C]$ CXXFLAGS=-g scons 37 | 38 | To compile with optimizations: 39 | 40 | [nsound-A.B.C]$ CXXFLAGS="-fno-strict-aliasing -fwrapv -O2" scons 41 | 42 | 43 | How to build the Nsound package on windows: 44 | 45 | Please read _WINDOWS_README.txt. 46 | 47 | 48 | How to build the Python Nsound package on Linux or Mac: 49 | 50 | 1) Uncompress the package: 51 | 52 | [~]$ tar xfz nsound-A.B.C.tar.gz 53 | 54 | 2) Execute Scons to generate setup.py 55 | 56 | [~]$ cd nsound-A.B.C 57 | [nsound-A.B.C]$ scons setup.py 58 | 59 | 3) Execute the Python disttools builder 60 | 61 | [nsound-A.B.C]$ sudo python setup.py install 62 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include * 2 | recursive-include src * 3 | recursive-include external * 4 | recursive-include site_scons * 5 | recursive-include swig * 6 | exclude swig/nsound_wrap.cxx 7 | global-exclude *.log 8 | global-exclude *.pyc 9 | global-exclude *.wav 10 | global-exclude .sconsign.dblite 11 | global-exclude Nsound.py -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | # Rules appended by makedepend 3 | 4 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | .. image:: https://github.com/weegreenblobbie/nsound/actions/workflows/linux.yaml/badge.svg?branch=master 2 | :target: https://github.com/weegreenblobbie/nsound/actions/workflows/linux.yaml?query=workflow:linux+branch:master 3 | :alt: Github Actions 4 | 5 | .. image:: https://github.com/weegreenblobbie/nsound/actions/workflows/macos.yaml/badge.svg?branch=master 6 | :target: https://github.com/weegreenblobbie/nsound/actions/workflows/macos.yaml?query=workflow:macos+branch:master 7 | :alt: Github Actions 8 | 9 | .. image:: https://github.com/weegreenblobbie/nsound/actions/workflows/windows.yaml/badge.svg?query=branch:master 10 | :target: https://github.com/weegreenblobbie/nsound/actions/workflows/windows.yaml?query=workflow:windows+branch:master 11 | :alt: Github Actions 12 | 13 | Nsound, a C++ framework for synthesizing sound 14 | ============================================== 15 | 16 | .. hyper link references 17 | 18 | .. _`Nsound Homepage`: https://github.com/weegreenblobbie/nsound 19 | .. _`Nsound User's Guide`: https://weegreenblobbie.com/nsound/user_guide/index.html 20 | .. _`Nsound Doxygen Reference`: https://weegreenblobbie.com/nsound/doxygen/index.html 21 | 22 | .. _`Introduction & Bebot`: https://www.youtube.com/watch?v=j4uLvl68PtI 23 | .. _`bebot.py`: https://github.com/weegreenblobbie/nsound/blob/master/src/examples/bebot.py 24 | 25 | .. _`Oscilloscope`: https://www.youtube.com/watch?v=ORnQVFpdSoA 26 | .. _`make_oscilloscope_video.py`: https://github.com/weegreenblobbie/nsound/blob/master/src/examples/make_oscilloscope_video.py 27 | 28 | .. _`Moog VCF & Delayline`: https://www.youtube.com/watch?v=9m3KA6JBDH8 29 | .. _`moogvcf-rt.py`: https://github.com/weegreenblobbie/nsound/blob/master/src/examples/moogvcf-rt.py 30 | .. _`delayline-rt.py`: https://github.com/weegreenblobbie/nsound/blob/master/src/examples/delayline-rt.py 31 | 32 | .. _`Tape Deck`: https://www.youtube.com/watch?v=Al6aHlwyEuA 33 | .. _`tapedeck-rt.py`: https://github.com/weegreenblobbie/nsound/blob/master/src/examples/tapedeck-rt.py 34 | 35 | 36 | Important Links 37 | --------------- 38 | 39 | - `Nsound Homepage`_ 40 | - `Nsound User's Guide`_ 41 | - `Nsound Doxygen Reference`_ 42 | 43 | YouTube Videos & Source Code 44 | ---------------------------- 45 | 46 | ========================= =================================== 47 | YouTube Video Source Code 48 | ========================= =================================== 49 | `Introduction & Bebot`_ `bebot.py`_ 50 | `Oscilloscope`_ `make_oscilloscope_video.py`_ 51 | `Moog VCF & Delayline`_ `moogvcf-rt.py`_ , `delayline-rt.py`_ 52 | `Tape Deck`_ `tapedeck-rt.py`_ 53 | ========================= =================================== 54 | 55 | Installing Python Module 56 | ------------------------ 57 | 58 | If you're on Windows, OS X, or Linux: 59 | 60 | .. code-block:: bash 61 | 62 | python3 -m pip install Nsound 63 | 64 | -------------------------------------------------------------------------------- /SiteConfig.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # 3 | # $Id: SiteConfig.py 648 2011-03-27 00:09:50Z weegreenblobbie $ 4 | # 5 | # SiteConfig.py 6 | # 7 | # Simply set these values to overide anything during configuration. 8 | # 9 | ############################################################################### 10 | 11 | # EXPERIMENTAL! 12 | # EXPERIMENTAL! 13 | # EXPERIMENTAL! 14 | 15 | # The use of this file hasn't been tested all that much! 16 | 17 | ############################################################################### 18 | # Compiler stuff 19 | 20 | # C compiler 21 | ##CC = "gcc" 22 | CC = "" 23 | 24 | # C++ compiler 25 | ##CPP = "g++" 26 | CPP = "" 27 | 28 | # C compiler flags 29 | ##CFLAGS = "-O2" 30 | CFLAGS = "" 31 | 32 | # C++ compiler flags 33 | ##CXXFLAGS = "-O2" 34 | CXXFLAGS = "" 35 | 36 | # link flags 37 | LDFLAGS = "" 38 | 39 | ############################################################################### 40 | # Python stuff 41 | 42 | #PYTHON_INCLUDE_DIR = "/usr/include/python2.6" 43 | PYTHON_INCLUDE_DIR = "" 44 | 45 | 46 | # Linux overrides 47 | 48 | #PYTHON_LIB_SO = "python2.6" 49 | PYTHON_LIB_SO = "" 50 | #PYTHON_LIB_DIR = "/usr/lib" 51 | PYTHON_LIB_DIR = "" 52 | 53 | 54 | # Windows override 55 | 56 | ##PYTHON_EXE = "C:\Python27\python.exe" 57 | ##PYTHON_EXE = "C:\Python26\python.exe" 58 | ##PYTHON_EXE = "C:\Python25\python.exe" 59 | PYTHON_EXE = "" 60 | 61 | ##PYTHON_DOT_LIB = "C:\Python27\libs\python27.lib" 62 | PYTHON_DOT_LIB = "" 63 | -------------------------------------------------------------------------------- /docs/How_To_Reverse_Engineer_a_Csound_Instrument.odt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/docs/How_To_Reverse_Engineer_a_Csound_Instrument.odt -------------------------------------------------------------------------------- /docs/user_guide/my/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /docs/user_guide/my/pyexec_directive.py: -------------------------------------------------------------------------------- 1 | """ 2 | $Id: pyexec_directive.py 589 2010-12-18 11:13:05Z weegreenblobbie $ 3 | 4 | This Sphinx extentsion allows one to inline python code and have it execute, 5 | the results of the code snippit should be stored in a string with the name 6 | template. 7 | 8 | For example, to embed the current date and time, to the following. 9 | 10 | .. pyexec:: 11 | 12 | from datetime import datetime 13 | template = "%s" % datetime.now() 14 | 15 | Larger strings can be made using Python's tripple quote syntax. 16 | 17 | .. pyexec:: 18 | 19 | frome datetime import datetime 20 | 21 | template = ''' 22 | This text will get inserted into the document at the pyexec directive 23 | above. Inline code can all be used:: 24 | 25 | print("I love Python, the current time is %s"''' % datetime.now()) 26 | 27 | """ 28 | import sys 29 | 30 | from docutils.parsers.rst import Directive 31 | 32 | class PyExec(Directive): 33 | 34 | has_content = True 35 | required_arguments = 0 36 | optional_arguments = 0 37 | 38 | def run(self): 39 | 40 | py_code = "\n".join(self.content) 41 | 42 | globals_ = globals() 43 | locals_ = locals() 44 | 45 | try: 46 | exec(py_code, globals_, locals_) 47 | template = locals_['template'] 48 | 49 | except Exception as e: 50 | message = f""" 51 | 52 | ERROR: An exception occured during the evaluation of the pyexec directive 53 | 54 | The offending code was: 55 | 56 | {py_code} 57 | 58 | """ 59 | sys.stderr.write(message) 60 | sys.stderr.flush() 61 | raise 62 | 63 | lines = ["%s" % row.rstrip() for row in template.split('\n')] 64 | self.state_machine.insert_input( 65 | lines, self.state_machine.input_lines.source(0)) 66 | 67 | return [] 68 | 69 | 70 | def setup(app): 71 | app.add_directive('pyexec', PyExec, True) 72 | 73 | -------------------------------------------------------------------------------- /docs/user_guide/source/_static/bebot-rt.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/docs/user_guide/source/_static/bebot-rt.wav -------------------------------------------------------------------------------- /docs/user_guide/source/_static/overrides.css: -------------------------------------------------------------------------------- 1 | @import url("default.css"); 2 | 3 | tt { 4 | font-size: 130%; 5 | } -------------------------------------------------------------------------------- /docs/user_guide/source/_static/piano-rt.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/docs/user_guide/source/_static/piano-rt.wav -------------------------------------------------------------------------------- /docs/user_guide/source/basics.rst: -------------------------------------------------------------------------------- 1 | Nsound Basics 2 | ============= 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | basics/data_types 8 | basics/buffer_creation 9 | basics/audiostream_creation 10 | basics/wavefile_io 11 | basics/basic_manipulations 12 | basics/plotting 13 | 14 | -------------------------------------------------------------------------------- /docs/user_guide/source/basics/basic_manipulations.rst: -------------------------------------------------------------------------------- 1 | ******************** 2 | Basic Manipulations 3 | ******************** 4 | 5 | AudioStream and Buffer objects have nearly all of their mathematical operators 6 | overloaded. It is easy to manipulate the data they contain. Every operation 7 | that can be done on a Buffer can be done on an AudioStream. In the following 8 | examples, only the Buffer case will be demonstrated, but it can easily be done 9 | to an AudioStream as well. 10 | 11 | Concatenation 12 | ------------- 13 | 14 | After creating an empty Buffer, one can insert samples into it with 15 | concatenation:: 16 | 17 | import Nsound as ns 18 | b = ns.Buffer() 19 | b << 1 << 2 << 3 20 | 21 | b.getLength() 22 | # 3 23 | b.toList() 24 | # [1.0, 2.0, 3.0] 25 | 26 | Buffers can be concatenated together:: 27 | 28 | b2 = ns.Buffer() 29 | b2 << 6 << 7 << 8 30 | 31 | b << b2 32 | 33 | b.getLength() 34 | # 6 35 | b.toList() 36 | # [1.0, 2.0, 3.0, 6.0, 7.0, 8.0] 37 | 38 | Scalar Math 39 | ----------- 40 | 41 | When a scaler is applied to a Buffer or AudioStream, the scalar is applied 42 | element-wise for all the samples contained in the Buffer:: 43 | 44 | import Nsound as ns 45 | b = ns.Buffer() 46 | b << 1 << 2 << 3 << 6 << 7 << 8 47 | 48 | b.toList() 49 | # [1.0, 2.0, 3.0, 6.0, 7.0, 8.0] 50 | 51 | b += 1.0 # b = b + 1.0 would also work 52 | b.toList() 53 | # [2.0, 3.0, 6.0, 7.0, 8.0, 9.0] 54 | 55 | b *= 2.0 56 | b.toList() 57 | # [4.0, 6.0, 12.0, 14.0, 16.0, 18.0] 58 | 59 | b /= 3.0 60 | b.toList() 61 | # [1.3333, 2.0, 2.6666, 4.6666, 5.3333, 6.0] 62 | 63 | Vector Math 64 | ----------- 65 | 66 | Nsound also allows element-wise math between two Buffers. Unlike other 67 | packages such as Numpy or Matlab, the Buffers don't have to be the same length:: 68 | 69 | import Nsound as ns 70 | 71 | b1 = ns.Buffer() 72 | b1 << 1 << 1 << 1 73 | 74 | b2 = ns.Buffer() 75 | b2 << 0 << 1 << 1 << 1 76 | 77 | # Addition 78 | 79 | b3 = b1 + b2 80 | 81 | b3.toList() 82 | # [1.0, 2.0, 2.0] 83 | 84 | b3 = b2 + b1 85 | b3 86 | # [1.0, 2.0, 2.0, 1.0] 87 | 88 | # Subtraction 89 | 90 | b3 = b1 - b2 91 | 92 | b3.toList() 93 | # [1.0, 0.0, 0.0] 94 | 95 | b3 = b2 - b1 96 | 97 | b3.toList() 98 | # [-1.0, 0.0, 0.0, 1.0] 99 | 100 | # Products 101 | 102 | b3 = b1 * b2 103 | 104 | b3.toList() 105 | # [0.0, 1.0, 1.0] 106 | 107 | b3 = b2 * b1 108 | 109 | b3.toList() 110 | # [0.0, 1.0, 1.0, 1.0] 111 | 112 | # Quotients 113 | 114 | b3 = b1 / b2 115 | 116 | b3.toList() 117 | # [1e+20, 1.0, 1.0] 118 | 119 | b3 = b2 / b1 120 | 121 | b3.toList() 122 | # [0.0, 1.0, 1.0, 1.0] 123 | -------------------------------------------------------------------------------- /docs/user_guide/source/basics/buffer_creation.rst: -------------------------------------------------------------------------------- 1 | ***************** 2 | Buffer Creation 3 | ***************** 4 | 5 | A Buffer holds audio samples at discrete sample periods. The Buffer object 6 | knows nothing about time, endianness or bit precision. It is a generic 7 | container of floating point data. 8 | 9 | There are 3 general ways to create an Nsound Buffer: 10 | 11 | 1) Creating an empty Buffer 12 | 2) Call ones(), rand() or zeros() 13 | 3) Reading a wavefile from disk 14 | 15 | Creating An Empty Buffer 16 | ======================== 17 | 18 | Call the constructor:: 19 | 20 | import Nsound as ns 21 | b = ns.Buffer() 22 | 23 | The new Buffer `b` is empty. Calling the getLength() method will return 0. 24 | 25 | The underlying data structure that is held by the Buffer class is a 26 | std::vector. One can preallocate memory when creating a buffer by specify the 27 | number of samples to preallocate:: 28 | 29 | b = ns.Buffer(1024) 30 | 31 | The new Buffer `b` is empty, even though memory was preallocated. Calling the 32 | getLength() method will return 0. 33 | 34 | In general, you don't need to worry about preallocating memory. It is meant 35 | to be useful when implementing new features in Nsound when the size of 36 | Buffers are already known. 37 | 38 | Call Ones, Rand or Zeros 39 | ========================= 40 | 41 | The Buffer class includes some convience functions for creating Buffers that 42 | are filled with oness, random numbers or zeros: 43 | 44 | .. py:function:: Buffer.ones(n_samples) 45 | .. py:function:: Buffer.rand(n_samples) 46 | .. py:function:: Buffer.zeros(n_samples) 47 | 48 | Example usage:: 49 | 50 | import Nsound as ns 51 | b1 = ns.Buffer.ones(10) 52 | b2 = ns.Buffer.rand(10) 53 | b3 = ns.Buffer.zeros(10) 54 | 55 | In the example above, 10 samples were stored in the created Buffers. 56 | 57 | Reading A Wavefile From Disk 58 | ============================ 59 | 60 | A Buffer can be created from a wavefile:: 61 | 62 | b = ns.Buffer("california.wav") 63 | 64 | The new Buffer `b` will contain all the samples in "california.wav". If the 65 | wavefile has more than one channel, `only the first channel` is read and stored 66 | in the new Buffer. 67 | 68 | The wavefile's data will be converted into float64 with a range of 69 | (-1.0, 1.0.). 70 | 71 | Converting Between Numpy Arrays And Buffers 72 | =========================================== 73 | 74 | Suppose you have a numpy array:: 75 | 76 | import numpy as np 77 | 78 | a = np.array([5,4,3,2,1]) 79 | 80 | You can now convert it into a Buffer like so:: 81 | 82 | b = ns.Buffer(a) 83 | 84 | print(b) 85 | 86 | Nsound.Buffer([5, 4, 3, 2, 1, ]) 87 | 88 | You can also convert back using this syntax:: 89 | 90 | a = np.array(b) 91 | 92 | print(a) 93 | 94 | [ 5. 4. 3. 2. 1.] -------------------------------------------------------------------------------- /docs/user_guide/source/basics/data_types.rst: -------------------------------------------------------------------------------- 1 | ***************** 2 | Nsound Data Types 3 | ***************** 4 | 5 | When writing new features for Nsound, C++ typedefs are used to ensure the same 6 | bit width is used on all platforms. To see how these types are defined, look 7 | at the file src/Nsound/Nsound.h after running SCons. 8 | 9 | If you are using the Python module, you won't need to know anything about these 10 | data types. 11 | 12 | +-----------+----------------------------------------------------------------------+ 13 | | Type | Description | 14 | +===========+======================================================================+ 15 | | boolean | The C++ bool type | 16 | +-----------+----------------------------------------------------------------------+ 17 | | int8 | Integer (-128 to 127) | 18 | +-----------+----------------------------------------------------------------------+ 19 | | int16 | Integer (-32768 to 32767) | 20 | +-----------+----------------------------------------------------------------------+ 21 | | int32 | Integer (-2147483648 to 2147483647) | 22 | +-----------+----------------------------------------------------------------------+ 23 | | int64 | Integer (9223372036854775808 to 9223372036854775807) | 24 | +-----------+----------------------------------------------------------------------+ 25 | | float32 | Single precision float: sign bit, 8 bits exponent, 23 bits mantissa | 26 | +-----------+----------------------------------------------------------------------+ 27 | | float64 | Double precision float: sign bit, 11 bits exponent, 52 bits mantissa | 28 | +-----------+----------------------------------------------------------------------+ 29 | | uint8 | Unsigned integer (0 to 255) | 30 | +-----------+----------------------------------------------------------------------+ 31 | | uint16 | Unsigned integer (0 to 65535) | 32 | +-----------+----------------------------------------------------------------------+ 33 | | uint32 | Unsigned integer (0 to 4294967295) | 34 | +-----------+----------------------------------------------------------------------+ 35 | | uint64 | Unsigned integer (0 to 18446744073709551615) | 36 | +-----------+----------------------------------------------------------------------+ 37 | 38 | -------------------------------------------------------------------------------- /docs/user_guide/source/basics/plotting.rst: -------------------------------------------------------------------------------- 1 | ******** 2 | Plotting 3 | ******** 4 | 5 | Nsound uses the wonderful Matplotlib package for making plots. To do this, a 6 | simple C++ class called Plotter wraps some of the Python C-API so that the 7 | C++ libNsound library can make calls into the Matplotlib classes to make plots. 8 | 9 | .. image:: ../images/matplotlib_interface.* 10 | :height: 278px 11 | :alt: Nsound Matplotlib Interface 12 | :align: center 13 | 14 | In the Python module, the Plotter class make calls into the Python Matplotlib 15 | module. 16 | 17 | If you are using the C++ library and the Matplotlib C-API was found, plotting 18 | will be enabled. If you are using the Python module and Matplotlib is 19 | installed, plotting will be enabled. 20 | 21 | .. note:: 22 | 23 | Plots will not pop up by default with the C++ or non-interactive Python 24 | code. For C++, a call to Plotter::show() will render the plots to the 25 | screen. With the Python module, a call to either matplotlib.pylab.show() or 26 | Nsound.Plotter.show() will display the plots. 27 | 28 | .. note:: 29 | 30 | You will not see calls to Plotter.show() in this User's Guide, the plots 31 | are generated with inline Python code and are saved to disk. 32 | 33 | .. note:: 34 | 35 | On MacOSX, if you are using the MacPorts package manager to install Python, 36 | Numpy, and Matplotlib in /opt/local, you will need to set the default 37 | Matplotlib backend. To do so edit the file ~/.matplotlib/matplotlibrc and 38 | add a line that reads "backend : MacOSX". 39 | 40 | Once you start manipulating your Buffers and AudioStreams, it is easy to see 41 | the effect by plotting them: 42 | 43 | .. plot:: 44 | :include-source: 45 | 46 | import Nsound as ns 47 | 48 | b = ns.Buffer() 49 | b << 1 << 2 << 3 << 4 50 | 51 | b.plot("Figure 1") 52 | 53 | a = ns.AudioStream(1, 2) 54 | a[0] = b 55 | a[1] = b.getReverse() 56 | a.plot("Figure 2") 57 | 58 | # Your code needs to call the show() 59 | # method to make the plots show up. 60 | 61 | # ns.Plotter.show() 62 | 63 | -------------------------------------------------------------------------------- /docs/user_guide/source/fft.rst: -------------------------------------------------------------------------------- 1 | ********** 2 | Nsound FFT 3 | ********** 4 | 5 | Nsound currently implements its own fast Fourier transform (FFT) in C++. In 6 | the furture this will change and use the FFTW library if available. 7 | 8 | The FFT is provided by the FFTransform class. It takes an input signal Buffer 9 | and transforms it into the frequency domain. The basic documentation: 10 | 11 | .. py:function:: FFTransform(sample_rate) 12 | 13 | `sample_rate` 14 | The number of samples per second. The sample rate is used for creating 15 | plots with correct axes. 16 | 17 | .. py:function:: FFTransform.fft(x, n_order) 18 | 19 | `x` 20 | The input Buffer. 21 | 22 | `n_order` 23 | The size of the FFT to perform. 24 | 25 | Returns an FFTChunkVector, representing the input signal chopped up into 26 | frames, where each frame is n_order is size. 27 | 28 | .. py:function:: FFTransform.ifft(fft_chunk_vector) 29 | 30 | `fft_chunk_vector` 31 | The input FFTChunkVector returned by fft(). 32 | 33 | Returns an Buffer, where each FFTChunk in the FFTChunkVector is transformed 34 | back into the time-domain. 35 | 36 | The example below creates a square wave with 5 harmonics. 37 | 38 | .. plot:: 39 | :include-source: 40 | 41 | import Nsound as ns 42 | 43 | sample_rate = 500.0 44 | 45 | square = ns.Square(sample_rate, 5) 46 | 47 | b = ns.Buffer() 48 | b << square.generate(0.5, 10.0) 49 | 50 | fft = ns.FFTransform(sample_rate) 51 | 52 | vec = fft.fft(b, 256) 53 | 54 | b.plot("Input signal, 4 Hz Square wave") 55 | 56 | vec[0].plot("Frequency Domain") 57 | 58 | b2 = fft.ifft(vec) 59 | b2.plot("Reconstructed") 60 | 61 | Notice that there are 5 peaks, these correspond to the 5 harmonics in the 62 | square wave. 63 | 64 | Using a Window 65 | -------------- 66 | 67 | Setting a window on the FFT object can get rid of edge effects. This can 68 | improve the results when looking at the frequency domain, but it will affect 69 | the reconstructed signal. 70 | 71 | .. plot:: 72 | :include-source: 73 | 74 | import Nsound as ns 75 | 76 | sample_rate = 500.0 77 | 78 | square = ns.Square(sample_rate, 5) 79 | 80 | b = ns.Buffer() 81 | b << square.generate(0.5, 10.0) 82 | 83 | fft = ns.FFTransform(sample_rate) 84 | 85 | vec1 = fft.fft(b, 256) 86 | b1 = fft.ifft(vec1) 87 | 88 | fft.setWindow(ns.HANNING) 89 | 90 | vec2 = fft.fft(b, 256) 91 | b2 = fft.ifft(vec2) 92 | 93 | vec1[0].plot("Frequency Domain, No Window") 94 | vec2[0].plot("Frequency Domain, With Hanning Window") 95 | 96 | b1.plot("Reconstructed, No Window") 97 | b2.plot("Reconstructed, With Hanning Window") 98 | 99 | As you can see, using a window can clean up the frequency domain plot, but it 100 | should not be used for reconstructing the signal. 101 | 102 | -------------------------------------------------------------------------------- /docs/user_guide/source/images/Speaker_Icon.svg: -------------------------------------------------------------------------------- 1 | 2 | image/svg+xml 23 | 26 | 29 | 30 | -------------------------------------------------------------------------------- /docs/user_guide/source/images/audioplayback_interface.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/docs/user_guide/source/images/audioplayback_interface.pdf -------------------------------------------------------------------------------- /docs/user_guide/source/images/audioplayback_interface.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/docs/user_guide/source/images/audioplayback_interface.png -------------------------------------------------------------------------------- /docs/user_guide/source/images/bebot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/docs/user_guide/source/images/bebot.png -------------------------------------------------------------------------------- /docs/user_guide/source/images/jack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/docs/user_guide/source/images/jack.png -------------------------------------------------------------------------------- /docs/user_guide/source/images/matplotlib_interface.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/docs/user_guide/source/images/matplotlib_interface.pdf -------------------------------------------------------------------------------- /docs/user_guide/source/images/matplotlib_interface.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/docs/user_guide/source/images/matplotlib_interface.png -------------------------------------------------------------------------------- /docs/user_guide/source/images/matplotlib_plot.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/docs/user_guide/source/images/matplotlib_plot.pdf -------------------------------------------------------------------------------- /docs/user_guide/source/index.rst: -------------------------------------------------------------------------------- 1 | .. _user: 2 | 3 | ################### 4 | Nsound User's Guide 5 | ################### 6 | 7 | .. warning:: 8 | 9 | This "User's Guide" is still a work in progress; some of the material 10 | is not organized, and several aspects of Nsound are not yet covered in 11 | sufficient detail. 12 | 13 | This guide is intended as an introductory overview of Nsound and 14 | explains how to install and make use of the most important features of 15 | Nsound. For detailed reference documentation of the functions and 16 | classes contained in the package, see the Doxygen documentation from 17 | `weegreenblobbie.come/nsound `__ 18 | . 19 | 20 | .. Note:: 21 | 22 | Nsound is open source software, the developers continually work on improving 23 | the library and documentation and encourage others interested to contribute. 24 | For information on how to do so, please contact Nick Hilton at 25 | weegreenblobbie2_gmail_com. Thanks! 26 | 27 | .. toctree:: 28 | :maxdepth: 2 29 | 30 | introduction 31 | basics 32 | audio_playback 33 | realtime_audio 34 | instruments 35 | generators 36 | filters 37 | fft 38 | stretcher 39 | -------------------------------------------------------------------------------- /docs/user_guide/source/intro/what_is_nsound.rst: -------------------------------------------------------------------------------- 1 | *************** 2 | What is Nsound? 3 | *************** 4 | 5 | Nsound is a C++ library and Python module for audio synthesis featuring 6 | dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | to disk or plot them. 8 | 9 | In Nsound, all audio data is represented by 64-bit floating point numbers 10 | between -1.0 and 1.0. It is easy to scale the data and adjust the volume by 11 | multiplying the audio data by a percentage, a number between 0.0 and 1.0. The 12 | audio data is is only converted to 8-bit, 16-bit, 24-bit, 32-bit or 64-bit when 13 | it is written to the disk with the Wavefile class. 14 | 15 | The core of Nsound is the Buffer class. Memory is dynamically allocated and 16 | frees the user from worrying about buffer sizes. All the mathematical 17 | operators are overloaded to allow intuitive expressions. 18 | 19 | Generators produce oscillations of the waveform stored in them. Generators 20 | can produce a single frequency of the waveform held in them, or can dynamicly 21 | change frequency, just draw a line that represents frequency and pass it into 22 | the generator. 23 | 24 | A collection of IIR & FIR filters are also included. When creating filters, 25 | the cutoff frequency is specified in Hz. The filters are also real-time, 26 | meaning they keep track of their internal state and for each audio sample 27 | passed in, an audio sample is returned. 28 | 29 | Beautiful plots can be easily created if your platform has the Python 30 | Matplotlib package installed. Most of the Nsound classes have their 31 | own plot methods. 32 | 33 | This User's Guide will specify code snippets written in Python. The C++ 34 | code is nearly identical. For specific C++ reference, view the Doxygen 35 | generated documentation available from 36 | `here `_. 37 | -------------------------------------------------------------------------------- /docs/user_guide/source/introduction.rst: -------------------------------------------------------------------------------- 1 | ############ 2 | Introduction 3 | ############ 4 | 5 | .. toctree:: 6 | 7 | intro/what_is_nsound 8 | intro/build_and_installing 9 | intro/getting_started 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /docs/user_guide/source/stretcher.rst: -------------------------------------------------------------------------------- 1 | **************** 2 | Nsound Stretcher 3 | **************** 4 | 5 | Nsound implements pitch and time shifting using the Stretcher class. The 6 | algorithm is based on the paper "An Overlap-Add Technique Based On Wavefrom 7 | Similarity (WSOLA) For High Quality Time-Scale Modification Of Speech" by 8 | Werner Verhelst and Marc Roelands. 9 | 10 | With the Stretcher class, you can change the time of the singal without 11 | modifying the frequency content. Or, you can also scale the 12 | frequency content without modifying the time. 13 | 14 | Please visit the Nsound 15 | `examples `_ webpage to 16 | listen to a 10 seconds stereo recording that was dynamically time and pitch 17 | shifted. 18 | 19 | Some of the basic documentation: 20 | 21 | .. py:function:: Stretcher(sample_rate) 22 | 23 | .. py:function:: Stretcher.pitchShift(x, factor) 24 | 25 | `x` 26 | The input Buffer or AudioStream. 27 | 28 | `factor` 29 | A percent change factor. 30 | 31 | .. py:function:: Stretcher.timeShift(x, factor) 32 | 33 | `x` 34 | The input Buffer or AudioStream. 35 | 36 | `factor` 37 | A percent change factor. 38 | 39 | The example below creates a signal and shifts it in time, but preserves the 40 | frequency content. The results are put into the frequency domain and plotted. 41 | 42 | .. plot:: 43 | :include-source: 44 | 45 | import Nsound as ns 46 | 47 | sample_rate = 1000.0 48 | 49 | stretch = ns.Stretcher(sample_rate) 50 | stretch.showProgress(True) 51 | 52 | saw = ns.Sawtooth(sample_rate, 4) 53 | 54 | fft = ns.FFTransform(sample_rate) 55 | fft.setWindow(ns.HANNING) 56 | 57 | a = ns.AudioStream(sample_rate, 1) 58 | a << saw.generate(1.0, 100.0) 59 | a.plot("Original Time Domain") 60 | fft.fft(a[0], 1024)[0].plot("Original Frequency Domain") 61 | 62 | # Time shifts 63 | 64 | a2 = stretch.timeShift(a, 0.50) 65 | a2.plot("50% Time Shift") 66 | 67 | a3 = stretch.timeShift(a, 2.0) 68 | a3.plot("200% Time Shift") 69 | 70 | # Frequency Scaling 71 | 72 | a4 = stretch.pitchShift(a, 0.50) 73 | fft.fft(a4[0], 1024)[0].plot("50% Pitch shift") 74 | 75 | a5 = stretch.pitchShift(a, 2.00) 76 | fft.fft(a5[0], 1024)[0].plot("200% Pitch Shift") 77 | 78 | -------------------------------------------------------------------------------- /docs/user_guide/util.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import os 3 | import subprocess 4 | 5 | import Nsound as ns 6 | 7 | def save_ogg(wav, name, remove_wav=True): 8 | wavfile = f"source/_static/{name}.wav" 9 | oggfile = wavfile.replace(".wav", ".ogg") 10 | if not os.path.isfile(oggfile): 11 | wav >> wavfile 12 | subprocess.check_call( 13 | ["oggenc", "-q", "10", wavfile, 14 | "--title", name, 15 | "--artist", "Nsound", 16 | "--album", ns.__version__, 17 | "--date", datetime.datetime.now().strftime("%Y-%m-%d"), 18 | "--comment", "https://github.com/weegreenblobbie/nsound", 19 | ] 20 | ) 21 | if remove_wav: 22 | os.remove(wavfile) 23 | 24 | return f"Sample here: `{name}.ogg <_static/{name}.ogg>`_" 25 | -------------------------------------------------------------------------------- /external/cygwin/lib/amd64/portaudio.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/external/cygwin/lib/amd64/portaudio.lib -------------------------------------------------------------------------------- /external/cygwin/lib/x86/portaudio.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/external/cygwin/lib/x86/portaudio.lib -------------------------------------------------------------------------------- /external/win32/lib/x64/portaudio.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/external/win32/lib/x64/portaudio.lib -------------------------------------------------------------------------------- /external/win32/lib/x86/portaudio.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/external/win32/lib/x86/portaudio.lib -------------------------------------------------------------------------------- /msvs/properties.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | C:\Python27 6 | $(PythonDir)\python.exe 7 | $(PythonDir)\include 8 | $(PythonDir)\libs 9 | $(PythonExe) $(PythonDir)\Scripts\scons.py 10 | $(SolutionDir)..\external 11 | $(PortAudioDir)\include 12 | $(PortAudioDir)\win32\lib\$(Platform) 13 | 14 | 15 | 16 | 17 | $(PythonDir) 18 | true 19 | 20 | 21 | $(PythonExe) 22 | true 23 | 24 | 25 | $(PythonIncludeDir) 26 | true 27 | 28 | 29 | $(PythonLibDir) 30 | true 31 | 32 | 33 | $(SCons) 34 | true 35 | 36 | 37 | $(PortAudioDir) 38 | true 39 | 40 | 41 | $(PortAudioIncludeDir) 42 | true 43 | 44 | 45 | $(PortAudioLibDir) 46 | true 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /nsound_config_cygwin.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # 3 | # $Id: nsound_config_cygwin.py 867 2014-08-23 22:42:55Z weegreenblobbie $ 4 | # 5 | # NsoundConfig.py 6 | # 7 | # A baseclass for configuring Nsound for different computing platforms. 8 | # 9 | ############################################################################## 10 | 11 | import os 12 | 13 | # Scons 14 | from SCons.Script import Dir 15 | 16 | # Nsound imports 17 | from nsound_config import NsoundConfig 18 | 19 | class NsoundConfigCygwin(NsoundConfig): 20 | 21 | def _customize_environment(self): 22 | 23 | self.env['NS_ON_CYGWIN'] = True 24 | self.env['NSOUND_PLATFORM_OS'] = "NSOUND_PLATFORM_OS_CYGWIN" 25 | self.env['NS_BUILD_STATIC'] = True 26 | 27 | CXXFLAGS = [] 28 | 29 | if self.env['NS_DEBUG_BUILD']: 30 | CXXFLAGS.append("-g") 31 | 32 | else: 33 | CXXFLAGS.extend( 34 | ["-fno-strict-aliasing", "-fwrapv", "-O2", ]) 35 | 36 | import platform 37 | cpu = platform.machine().upper() 38 | 39 | if cpu in ['X86_64', 'AMD64']: 40 | cpu = 'amd64' 41 | 42 | CPPDEFINES = [] 43 | CPPPATH = [Dir('external/include')] 44 | LIBPATH = [Dir('external/cygwin/lib/%s' % cpu)] 45 | LIBS = [] 46 | 47 | self.env.AppendUnique( 48 | CPPDEFINES = CPPDEFINES, 49 | CPPPATH = CPPPATH, 50 | LIBPATH = LIBPATH, 51 | LIBS = LIBS) 52 | 53 | def add_custom_compiler_flags(self): 54 | 55 | if not self.env['NS_COMPILER']: return 56 | 57 | CXXFLAGS = [] 58 | 59 | d = self.env['NS_COMPILER'] 60 | 61 | if 'gcc' in d['compiler']: 62 | 63 | longver = d['longver'] 64 | 65 | if longver >= 40600 and longver < 40700: 66 | CXXFLAGS = ["-std=c++0x"] 67 | 68 | elif longver >= 40700: 69 | CXXFLAGS = ["-std=c++11"] 70 | 71 | self.env.AppendUnique(CXXFLAGS = CXXFLAGS) 72 | 73 | def on_cygwin(self): 74 | return True 75 | -------------------------------------------------------------------------------- /nsound_config_linux.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | $Id: nsound_config_linux.py 875 2014-09-27 22:25:13Z weegreenblobbie $ 4 | 5 | """ 6 | 7 | import os 8 | 9 | # Nsound imports 10 | from nsound_config import NsoundConfig 11 | 12 | class NsoundConfigLinux(NsoundConfig): 13 | 14 | def _customize_environment(self): 15 | 16 | self.env['NS_ON_LINUX'] = True 17 | self.env['NSOUND_PLATFORM_OS'] = "NSOUND_PLATFORM_OS_LINUX" 18 | 19 | if self.env['NS_DEBUG_BUILD']: 20 | self.env.AppendUnique(CXXFLAGS = ["-g"]) 21 | 22 | else: 23 | self.env.AppendUnique( 24 | CXXFLAGS = ["-fno-strict-aliasing", "-fwrapv", "-O2", '-Wall']) 25 | 26 | def add_custom_compiler_flags(self): 27 | 28 | if not self.env['NS_COMPILER']: return 29 | 30 | CXXFLAGS = [] 31 | 32 | d = self.env['NS_COMPILER'] 33 | 34 | if 'gcc' in d['compiler']: 35 | 36 | longver = d['longver'] 37 | 38 | if longver >= 40600 and longver < 40700: 39 | CXXFLAGS = ["-std=c++0x"] 40 | 41 | elif longver >= 40700: 42 | CXXFLAGS = ["-std=c++11"] 43 | 44 | elif 'clang' in d['compiler']: 45 | 46 | longver = d['longver'] 47 | 48 | if longver >= 40200: 49 | CXXFLAGS = ["-std=c++11"] 50 | 51 | self.env.AppendUnique(CXXFLAGS = CXXFLAGS) 52 | 53 | def on_linux(self): 54 | return True 55 | -------------------------------------------------------------------------------- /nsound_config_mac.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # 3 | # $Id: nsound_config_mac.py 854 2014-06-30 00:29:02Z weegreenblobbie $ 4 | # 5 | # NsoundConfig_Mac.py 6 | # 7 | # A baseclass for configuring Nsound for different computing platforms. 8 | # 9 | ############################################################################## 10 | 11 | # Python imports 12 | import os 13 | import sys 14 | 15 | # Nsound imports 16 | from nsound_config import NsoundConfig 17 | 18 | class NsoundConfigMac(NsoundConfig): 19 | 20 | def _customize_environment(self): 21 | 22 | self.env['NS_ON_MAC'] = True 23 | self.env['NSUOND_PLATFORM_OS'] = "NSOUND_PLATFORM_OS_MAC" 24 | 25 | if self.env['NS_DEBUG_BUILD']: 26 | self.env.AppenduUnique(CXXFLAGS = ["-g"]) 27 | 28 | else: 29 | self.env.AppendUnique(CXXFLAGS = ["-O2"]) 30 | 31 | # Enbale c++11. 32 | self.env.AppendUnique(CXXFLAGS = ['-std=c++11']) 33 | 34 | #--------------------------------------------------------- 35 | # rpath Hack, g++ on OSX doesn't use -Wl,-rpath=somepath 36 | # 37 | # The trick here is to specify an abspath when linking libNsound.dylib 38 | 39 | self.env.AppendUnique( 40 | SHLINKFLAGS = 41 | [ 42 | '-install_name', 43 | '%s/${TARGET.filebase}${TARGET.suffix}' % self.env['NS_LIBDIR'] 44 | ]) 45 | 46 | #---------------------------------------------------------- 47 | # look for portaudio.h 48 | 49 | PATH_LIST = ["/usr", "/usr/local", "/opt", "/opt/local"] 50 | 51 | for path in PATH_LIST: 52 | 53 | portaudio_h = os.path.join(path, "include", "portaudio.h") 54 | 55 | if os.path.isfile(portaudio_h): 56 | cpppath = os.path.join(path, "include") 57 | libpath = os.path.join(path, "lib") 58 | 59 | self.env.AppendUnique( 60 | CPPPATH = [cpppath], 61 | LIBPATH = [libpath]) 62 | 63 | def add_to_rpath(self, path): 64 | """ 65 | -Wl,-rpath not available on Mac. 66 | """ 67 | #self.env.Append( 68 | # LINKFLAGS = ['-Xlinker', '-rpath', '-Xlinker', path]) 69 | 70 | def on_mac(self): 71 | return True 72 | 73 | -------------------------------------------------------------------------------- /nsound_config_windows.py: -------------------------------------------------------------------------------- 1 | """ 2 | $Id: nsound_config_windows.py 896 2015-06-07 03:46:27Z weegreenblobbie $ 3 | 4 | Nsound is a C++ library and Python module for audio synthesis featuring 5 | dynamic digital filters. Nsound lets you easily shape waveforms and write 6 | to disk or plot them. Nsound aims to be as powerful as Csound but easy to 7 | use. 8 | 9 | Copyright (c) 2009-Present Nick Hilton 10 | """ 11 | 12 | # Python modules 13 | import os 14 | import sys 15 | 16 | # Scons 17 | from SCons.SConf import CheckContext 18 | from SCons.Script import Dir 19 | 20 | # Custom python scripts 21 | from nsound_config import NsoundConfig 22 | 23 | CONFIG_DIR = "msvs" 24 | 25 | 26 | class NsoundConfigWindows(NsoundConfig): 27 | 28 | def _customize_environment(self): 29 | 30 | self.env['NS_ON_WINDOWS'] = True 31 | self.env['NSOUND_PLATFORM_OS'] = "NSOUND_PLATFORM_OS_WINDOWS" 32 | self.env['NS_BUILD_STATIC'] = True 33 | 34 | import platform 35 | cpu = platform.machine().upper() 36 | 37 | if cpu in ['X86_64', 'AMD64']: 38 | cpu = 'x64' 39 | 40 | # Defaults 41 | CPPDEFINES = ["_CRT_SECURE_NO_WARNINGS"] 42 | CPPPATH = [Dir('external/include')] 43 | CXXFLAGS = "/nologo /O2 /W3 /EHsc /MD /Gd /TP /Zm256 /std:c++14".split() 44 | LIBPATH = [Dir('external/win32/lib/%s' % cpu)] 45 | LIBS = [] 46 | LINKFLAGS = ["/nologo"] 47 | 48 | self.env.AppendUnique( 49 | CPPDEFINES = CPPDEFINES, 50 | CPPPATH = CPPPATH, 51 | CXXFLAGS = CXXFLAGS, 52 | LIBPATH = LIBPATH, 53 | LIBS = LIBS, 54 | LINKFLAGS = LINKFLAGS) 55 | 56 | def on_windows(self): 57 | return True 58 | -------------------------------------------------------------------------------- /site_scons/site_tools/PythonSetup.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Tool for running python setup.py install --user 4 | 5 | Reference: http://scons.org/wiki/ToolsForFools 6 | 7 | $Id: PythonSetup.py 763 2013-09-18 00:43:44Z weegreenblobbie $ 8 | """ 9 | 10 | """ 11 | Nsound is a C++ library and Python module for audio synthesis featuring 12 | dynamic digital filters. Nsound lets you easily shape waveforms and write 13 | to disk or plot them. Nsound aims to be as powerful as Csound but easy to 14 | use. 15 | 16 | Copyright (c) 2004 to Present Nick Hilton 17 | 18 | weegreenblobbie_at_yahoo_com 19 | 20 | This program is free software; you can redistribute it and/or modify 21 | it under the terms of the GNU General Public License as published by 22 | the Free Software Foundation; either version 2 of the License, or 23 | (at your option) any later version. 24 | 25 | This program is distributed in the hope that it will be useful, 26 | but WITHOUT ANY WARRANTY; without even the implied warranty of 27 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28 | GNU Library General Public License for more details. 29 | 30 | You should have received a copy of the GNU General Public License 31 | along with this program; if not, write to the Free Software 32 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 33 | """ 34 | 35 | 36 | import datetime 37 | import shlex 38 | import sys 39 | import subprocess 40 | 41 | from SCons.Action import Action 42 | from SCons.Script import Delete 43 | from SCons.Script import EnsureSConsVersion 44 | from SCons.Script import File 45 | from SCons.Script import Touch 46 | 47 | EnsureSConsVersion(0,96,92) 48 | 49 | def emitter(target, source, env): 50 | 51 | env.Depends(target, source) 52 | 53 | return target, source 54 | 55 | 56 | def generate(env): 57 | """ 58 | Add builders and construction variables for the SvnVersion builder. 59 | """ 60 | 61 | python = File(sys.executable).get_abspath() 62 | python = python.replace("\\", "\\\\") # windows fix 63 | 64 | env['PYTHON'] = python 65 | cmd = "$PYTHON $SOURCE install --user" 66 | env['PYTHONSETUPCOM'] = cmd 67 | 68 | action = Action('$PYTHONSETUPCOM', '$PYTHONSETUPCOMSTR') 69 | 70 | bld = env.Builder( 71 | action = [Delete("build"), action, Touch("$TARGETS")], 72 | emitter = emitter, 73 | target_factor = env.fs.Entry, 74 | src_suffic = ".py", 75 | ) 76 | 77 | env['BUILDERS']['PythonSetup'] = bld 78 | 79 | 80 | def exists(env): 81 | return True 82 | 83 | -------------------------------------------------------------------------------- /site_scons/site_tools/SvnVersion.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Substitues svn version information into target. 4 | 5 | $Id: SvnVersion.py 763 2013-09-18 00:43:44Z weegreenblobbie $ 6 | """ 7 | 8 | """ 9 | Nsound is a C++ library and Python module for audio synthesis featuring 10 | dynamic digital filters. Nsound lets you easily shape waveforms and write 11 | to disk or plot them. Nsound aims to be as powerful as Csound but easy to 12 | use. 13 | 14 | Copyright (c) 2004 to Present Nick Hilton 15 | 16 | weegreenblobbie_at_yahoo_com 17 | 18 | This program is free software; you can redistribute it and/or modify 19 | it under the terms of the GNU General Public License as published by 20 | the Free Software Foundation; either version 2 of the License, or 21 | (at your option) any later version. 22 | 23 | This program is distributed in the hope that it will be useful, 24 | but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | GNU Library General Public License for more details. 27 | 28 | You should have received a copy of the GNU General Public License 29 | along with this program; if not, write to the Free Software 30 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | """ 32 | 33 | 34 | import os 35 | import shlex 36 | import subprocess 37 | 38 | import SCons.Action 39 | import SCons.Builder 40 | import SCons.Util 41 | import SCons.Script 42 | 43 | SCons.Script.EnsureSConsVersion(0,96,92) 44 | 45 | SvnVersionAction = SCons.Action.Action('$SVNVERSIONCOM', '$SVNVERSIONCOMSTR') 46 | 47 | 48 | def svnversion_builder(*args): 49 | 50 | env, _, path = args 51 | 52 | dir_ = os.path.abspath(str(path[0])) 53 | 54 | if not os.path.isdir(dir_): 55 | raise ValueError( 56 | "target not found or not a directory path: %s" % repr(dir_)) 57 | 58 | cmd = ['svnversion', dir_] 59 | 60 | p = subprocess.Popen(cmd, stdout = subprocess.PIPE) 61 | output = p.communicate()[0].strip() 62 | 63 | if len(output) == 0: 64 | output = "error" 65 | 66 | # Take the second half of any version reported as XXXX:YYYY. 67 | 68 | if ':' in output: 69 | output = output.split(":")[-1] 70 | 71 | return output 72 | 73 | 74 | def generate(env): 75 | """ 76 | Add builders and construction variables for the SvnVersion builder. 77 | """ 78 | env.Append(BUILDERS = dict(svnversion = env.Builder( 79 | action = svnversion_builder))) 80 | 81 | try: 82 | bld = env['BUILDERS']['SvnVersion'] 83 | except KeyError: 84 | bld = svnversion_builder 85 | env['BUILDERS']['SvnVersion'] = bld 86 | 87 | env['SVNVERSIONCOM'] = 'svnversion $TARGET' 88 | 89 | 90 | def exists(env): 91 | return env.Detect('svnversion') 92 | -------------------------------------------------------------------------------- /site_scons/site_tools/_nsound_utils.py: -------------------------------------------------------------------------------- 1 | """ 2 | $Id: _nsound_utils.py 760 2013-09-17 03:17:53Z weegreenblobbie $ 3 | 4 | Nsound is a C++ library and Python module for audio synthesis featuring 5 | dynamic digital filters. Nsound lets you easily shape waveforms and write 6 | to disk or plot them. Nsound aims to be as powerful as Csound but easy to 7 | use. 8 | 9 | Copyright (c) 2004 to Present Nick Hilton 10 | 11 | weegreenblobbie_at_yahoo_com 12 | 13 | This program is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2 of the License, or 16 | (at your option) any later version. 17 | 18 | This program is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU Library General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this program; if not, write to the Free Software 25 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | """ 27 | 28 | import os 29 | import shlex 30 | import subprocess 31 | 32 | def dbg_print(env, filename, message, basename = True): 33 | """ 34 | Prints debug messages if enabled. 35 | """ 36 | 37 | if not env['NS_CONFIG_DEBUG']: return 38 | 39 | if basename: 40 | filename = os.path.basename(filename) 41 | 42 | print("%s: %s" % (filename, message)) 43 | 44 | 45 | def run_command(command, env): 46 | """ 47 | Runs the command in a subprocess and returns stdout, stderr, exit_code. 48 | """ 49 | 50 | cmd = shlex.split(command) 51 | 52 | p = subprocess.Popen( 53 | cmd, 54 | env = env, 55 | stdout = subprocess.PIPE, 56 | stderr = subprocess.PIPE) 57 | 58 | stdout, stderr = p.communicate() 59 | 60 | return stdout.strip(), stderr.strip(), p.returncode 61 | 62 | -------------------------------------------------------------------------------- /src/Nsound/AudioBackend.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: AudioBackend.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2005-2006 Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | #include 30 | 31 | using namespace Nsound; 32 | 33 | std::string state_strings[3] = 34 | { 35 | "Backend Not Initialized", 36 | "Backend Ready", 37 | "Backend Error" 38 | }; 39 | 40 | //----------------------------------------------------------------------------- 41 | std::string 42 | AudioBackend:: 43 | getStateString() 44 | { 45 | return state_strings[state_]; 46 | } 47 | 48 | //----------------------------------------------------------------------------- 49 | std::string 50 | AudioBackend:: 51 | getStateString(const State & state) 52 | { 53 | if( state >= BACKEND_NOT_INITIALIZED && 54 | state <= BACKEND_ERROR) 55 | { 56 | return state_strings[state]; 57 | } 58 | 59 | return "Unknown Backend State"; 60 | } 61 | 62 | 63 | // :mode=c++: 64 | -------------------------------------------------------------------------------- /src/Nsound/AudioBackendType.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: AudioBackendType.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2011-Present Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | #ifndef _NSOUND_AUDIO_BACKEND_TYPE_H_ 34 | #define _NSOUND_AUDIO_BACKEND_TYPE_H_ 35 | 36 | namespace Nsound 37 | { 38 | enum AudioBackendType 39 | { 40 | BACKEND_TYPE_NONE, 41 | BACKEND_TYPE_LIBAO, 42 | BACKEND_TYPE_LIBPORTAUDIO, 43 | }; 44 | }; 45 | 46 | #endif 47 | 48 | // :mode=c++: jEdit modeline 49 | -------------------------------------------------------------------------------- /src/Nsound/AudioStreamSelection.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: AudioStreamSelection.h 912 2015-07-26 00:50:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2009-Present Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | #ifndef _NSOUND_AUDIO_STREAM_SELECTION_H_ 34 | #define _NSOUND_AUDIO_STREAM_SELECTION_H_ 35 | 36 | #include 37 | 38 | #include 39 | 40 | namespace Nsound 41 | { 42 | 43 | // Forward 44 | class AudioStream; 45 | 46 | typedef std::vector< std::vector< boolean > > BooleanVectorVector; 47 | 48 | //----------------------------------------------------------------------------- 49 | //! A helper class for advance operators. 50 | class AudioStreamSelection 51 | { 52 | 53 | public: 54 | 55 | AudioStreamSelection(AudioStream & as, const BooleanVectorVector & bv); 56 | AudioStreamSelection(const AudioStreamSelection & copy); 57 | AudioStreamSelection & operator=(const AudioStreamSelection & rhs); 58 | ~AudioStreamSelection(){} 59 | 60 | AudioStreamSelection & operator+=(const float64 & rhs); 61 | AudioStreamSelection & operator-=(const float64 & rhs); 62 | AudioStreamSelection & operator*=(const float64 & rhs); 63 | AudioStreamSelection & operator/=(const float64 & rhs); 64 | AudioStreamSelection & operator^=(const float64 & rhs); 65 | 66 | AudioStreamSelection & operator=(const float64 & rhs); 67 | 68 | // For SWIG 69 | void 70 | set(const float64 & rhs){this->operator=(rhs);}; 71 | 72 | private: 73 | 74 | AudioStream * target_as_; 75 | BooleanVectorVector bv_; 76 | }; 77 | 78 | }; 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /src/Nsound/BufferWindowSearch.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: BufferWindowSearch.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2009-Present Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | #ifndef _NSOUND_BUFFER_WINDOW_SEARCH_H_ 34 | #define _NSOUND_BUFFER_WINDOW_SEARCH_H_ 35 | 36 | #include 37 | 38 | namespace Nsound 39 | { 40 | 41 | // Forward 42 | class Buffer; 43 | 44 | //----------------------------------------------------------------------------- 45 | //! Searches the target Buffer for zero crossings at or after the window_size position. 46 | class BufferWindowSearch 47 | { 48 | public: 49 | 50 | BufferWindowSearch(const Buffer & buffer, uint32 window_size = 2048); 51 | 52 | BufferWindowSearch(const BufferWindowSearch & copy); 53 | 54 | ~BufferWindowSearch(){}; 55 | 56 | BufferWindowSearch & 57 | operator=(const BufferWindowSearch & rhs); 58 | 59 | //! Searches the target Buffer for a zero crossing at or after the window_size position. 60 | Buffer 61 | getNextWindow(); 62 | 63 | //! Returns how many samples are left in the target Buffer. 64 | uint32 65 | getSamplesLeft() const; 66 | 67 | //! Resets the search. 68 | void 69 | reset() 70 | {position_ = 0;}; 71 | 72 | //! Search a different Buffer. 73 | void 74 | setBuffer(const Buffer & buffer) 75 | { 76 | target_buffer_ = &buffer; 77 | reset(); 78 | } 79 | 80 | protected: 81 | 82 | const Buffer * target_buffer_; 83 | uint32 window_size_; 84 | uint32 position_; 85 | }; 86 | 87 | }; 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /src/Nsound/CircularBuffer.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: CircularBuffer.cc 878 2014-11-23 04:51:23Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2008 Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace Nsound; 34 | 35 | using std::cerr; 36 | using std::endl; 37 | 38 | CircularBuffer:: 39 | CircularBuffer(uint32 n_samples) 40 | : 41 | buffer_(std::make_shared(Buffer::zeros(n_samples))), 42 | itor_(std::make_shared(buffer_->cbegin())) 43 | { 44 | } 45 | 46 | 47 | Buffer 48 | CircularBuffer:: 49 | read() const 50 | { 51 | const uint32 N = buffer_->getLength(); 52 | 53 | Buffer::circular_iterator ci(*itor_); 54 | 55 | Buffer b(N); 56 | 57 | for(uint32 i = 0; i < N; ++i) 58 | { 59 | b << *ci; 60 | ++ci; 61 | } 62 | 63 | return b; 64 | } 65 | 66 | 67 | void 68 | CircularBuffer:: 69 | write(const AudioStream & as) 70 | { 71 | write(as.getMono()[0]); 72 | } 73 | 74 | 75 | void 76 | CircularBuffer:: 77 | write(const Buffer & src) 78 | { 79 | for(auto x : src) 80 | { 81 | write(x); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Nsound/CircularBuffer.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: CircularBuffer.h 878 2014-11-23 04:51:23Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2008-Present Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | #ifndef _NSOUND_CIRCULAR_BUFFER_H_ 34 | #define _NSOUND_CIRCULAR_BUFFER_H_ 35 | 36 | #include 37 | 38 | #include 39 | 40 | namespace Nsound 41 | { 42 | 43 | class Buffer; 44 | 45 | class CircularBuffer 46 | { 47 | 48 | public: 49 | 50 | CircularBuffer(uint32 n_samples); 51 | 52 | Buffer read() const; 53 | float64 read_head() const { return *(*itor_); } 54 | 55 | void write(float64 d) { *(*itor_) = d; ++(*itor_); } 56 | 57 | void write(const AudioStream & as); 58 | void write(const Buffer & b); 59 | 60 | protected: 61 | 62 | CircularBuffer(const CircularBuffer & copy); 63 | CircularBuffer & operator=(const CircularBuffer & rhs); 64 | 65 | std::shared_ptr buffer_; 66 | std::shared_ptr itor_; 67 | }; 68 | 69 | } // namespace 70 | 71 | // :mode=c++: jEdit modeline 72 | #endif 73 | -------------------------------------------------------------------------------- /src/Nsound/Cosine.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: Cosine.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2009-Present Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | using namespace Nsound; 35 | 36 | //----------------------------------------------------------------------------- 37 | Cosine:: 38 | Cosine(const float64 & sample_rate) 39 | : Generator(sample_rate) 40 | { 41 | Buffer waveform = drawSine2(1.0, 1.0, 0.5); 42 | ctor(sample_rate, waveform); 43 | } 44 | -------------------------------------------------------------------------------- /src/Nsound/Cosine.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: Cosine.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2009-Present Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | 34 | #ifndef _NSOUND_COSINE_H_ 35 | #define _NSOUND_COSINE_H_ 36 | 37 | #include 38 | 39 | namespace Nsound 40 | { 41 | 42 | //----------------------------------------------------------------------------- 43 | //! DOXME 44 | class Cosine : public Generator 45 | { 46 | public: 47 | 48 | //! DOXME 49 | Cosine(const float64 & sample_rate); 50 | 51 | };// class Sine 52 | 53 | };// namespace Nsound 54 | 55 | // :mode=c++: jEdit modeline 56 | #endif 57 | -------------------------------------------------------------------------------- /src/Nsound/CudaUtils.cu: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // $Id: CudaUtils.cu 699 2011-10-03 20:56:04Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2008 to Present Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | /////////////////////////////////////////////////////////////////////////////// 15 | 16 | /////////////////////////////////////////////////////////////////////////////// 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | /////////////////////////////////////////////////////////////////////////////// 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | // The nvcc compiler doesn't handle namespaces the same way GCC does, as of 40 | // version: Cuda compilation tools, release 3.2, V0.2.1221 41 | 42 | Nsound::Context::State 43 | Nsound::Context::state_ = Nsound::Context::BOOTING_; 44 | 45 | /////////////////////////////////////////////////////////////////////////////// 46 | void 47 | Nsound:: 48 | Context:: 49 | init(int flags) 50 | { 51 | if(state_ == BOOTING_) 52 | { 53 | if(CUDA_SUCCESS == cuInit(flags)) 54 | { 55 | state_ = INITALIZED_; 56 | } 57 | else 58 | { 59 | checkForCudaError(); 60 | state_ = ERROR_; 61 | } 62 | } 63 | } 64 | 65 | // :mode=c++: jEdit modeline 66 | -------------------------------------------------------------------------------- /src/Nsound/CudaUtils.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: CudaUtils.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2008 to Present Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | #ifndef _NSOUND_CUDA_UTILS_H_ 34 | #define _NSOUND_CUDA_UTILS_H_ 35 | 36 | namespace Nsound 37 | { 38 | 39 | //----------------------------------------------------------------------------- 40 | // Magic macro to check for cuda errors. 41 | #define checkForCudaError() \ 42 | { \ 43 | cudaError_t ecode = cudaGetLastError(); \ 44 | if(ecode) \ 45 | { \ 46 | printf("%s:%3d: Error: %s\n", \ 47 | __FILE__, \ 48 | __LINE__, \ 49 | cudaGetErrorString(ecode)); \ 50 | } \ 51 | } 52 | 53 | struct Context 54 | { 55 | enum State 56 | { 57 | BOOTING_ = 1, 58 | INITALIZED_ = 10, 59 | UNLOADED_ = 20, 60 | ERROR_ = 30, 61 | }; 62 | 63 | static State state_; 64 | 65 | //! Initialize the card once. 66 | void 67 | init(int flags = 0); 68 | }; 69 | 70 | } // namespace 71 | 72 | #endif 73 | // :mode=c++: jEdit modeline 74 | -------------------------------------------------------------------------------- /src/Nsound/DelayLine.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: DelayLine.h 908 2015-07-08 02:04:41Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2007 Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | #ifndef _NSOUND_DELAY_LINE_H_ 34 | #define _NSOUND_DELAY_LINE_H_ 35 | 36 | #include 37 | 38 | #include 39 | 40 | namespace Nsound 41 | { 42 | 43 | 44 | class AudioStream; 45 | class Buffer; 46 | 47 | 48 | class DelayLine 49 | { 50 | 51 | public: 52 | 53 | DelayLine(float64 sample_rate, float64 max_delay_in_seconds); 54 | 55 | void setRealtime(bool flag) {is_realtime_ = flag;} 56 | 57 | Buffer delay(const Buffer & x, const Buffer & delay_time); 58 | 59 | float64 delay(float64 x, float64 delay_time); 60 | 61 | float64 read(); 62 | float64 read(float64 delay); 63 | 64 | void write(float64 x); 65 | 66 | void reset(); // flushes internal state 67 | 68 | protected: 69 | 70 | float64 sample_rate_; 71 | float64 max_delay_time_; 72 | float64 delay_time_; 73 | 74 | std::vector buffer_; 75 | 76 | uint32 wr_idx_; 77 | 78 | bool is_realtime_; 79 | 80 | private: 81 | 82 | DelayLine(const DelayLine & copy); 83 | DelayLine & operator=(const DelayLine & rhs); 84 | }; 85 | 86 | 87 | } // namespace 88 | 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /src/Nsound/DrumBD01.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: DrumBD01.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2009-Present Nick Hilton 11 | // 12 | // Simulates a bass drum. Based on a Csound drum. 13 | // 14 | // source: http://www.csounds.com/istvan/html/drums.html 15 | // 16 | //----------------------------------------------------------------------------- 17 | 18 | //----------------------------------------------------------------------------- 19 | // 20 | // This program is free software; you can redistribute it and/or modify 21 | // it under the terms of the GNU General Public License as published by 22 | // the Free Software Foundation; either version 2 of the License, or 23 | // (at your option) any later version. 24 | // 25 | // This program is distributed in the hope that it will be useful, 26 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 27 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28 | // GNU Library General Public License for more details. 29 | // 30 | // You should have received a copy of the GNU General Public License 31 | // along with this program; if not, write to the Free Software 32 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 33 | // 34 | //----------------------------------------------------------------------------- 35 | 36 | #ifndef _NSOUND_DRUM_BD01_H_ 37 | #define _NSOUND_DRUM_BD01_H_ 38 | 39 | #include 40 | 41 | namespace Nsound 42 | { 43 | 44 | // Forward Declarations 45 | class AudioStream; 46 | class Buffer; 47 | 48 | //----------------------------------------------------------------------------- 49 | //! Class DrumBD01 50 | class DrumBD01 : public Instrument 51 | { 52 | public: 53 | 54 | //! Creates a Drum 55 | DrumBD01(const float64 & sample_rate); 56 | 57 | //! Destructor 58 | ~DrumBD01(); 59 | 60 | //! Plays a demo for this instrument. 61 | AudioStream play(); 62 | 63 | //! Plays a static note for this instrument. 64 | AudioStream play(const float64 & duration, const float64 & frequency); 65 | 66 | //! Static play method. 67 | AudioStream play( 68 | const float64 & duration, 69 | const float64 & frequency, 70 | const float64 & velocity); 71 | 72 | //! Nsound::DrumBD01 information. 73 | std::string getInfo() 74 | { 75 | return 76 | "Nsound::DrumBD01 by Nick Hilton on 2009-05-02\n" 77 | "Simulates a bass drum. Based on a Csound drum.\n" 78 | "source: http://www.csounds.com/istvan/html/drums.html\n"; 79 | }; 80 | 81 | }; 82 | 83 | }; 84 | 85 | // :mode=c++: jEdit modeline 86 | #endif 87 | -------------------------------------------------------------------------------- /src/Nsound/FilterDC.cc: -------------------------------------------------------------------------------- 1 | //-----------------------------------------------------------------------------//// 2 | // 3 | // $Id: FilterDC.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2007 Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //-----------------------------------------------------------------------------//// 10 | 11 | //-----------------------------------------------------------------------------//// 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //-----------------------------------------------------------------------------//// 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace Nsound; 34 | 35 | //----------------------------------------------------------------------------- 36 | FilterDC:: 37 | FilterDC(const float64 & feedback_gain) 38 | : 39 | feedback_gain_(feedback_gain), 40 | last_input_(0.0), 41 | last_output_(0.0) 42 | { 43 | } 44 | 45 | AudioStream 46 | FilterDC:: 47 | filter(const AudioStream & x) 48 | { 49 | uint32 n_channels = x.getNChannels(); 50 | 51 | AudioStream y(x.getSampleRate(), n_channels); 52 | 53 | for(uint32 channel = 0; channel < n_channels; ++channel) 54 | { 55 | y[channel] = filter(x[channel]); 56 | } 57 | 58 | return y; 59 | } 60 | 61 | 62 | Buffer 63 | FilterDC:: 64 | filter(const Buffer & x) 65 | { 66 | uint32 n_samples = x.getLength(); 67 | 68 | Buffer y; 69 | 70 | for(uint32 n = 0; n < n_samples; ++n) 71 | { 72 | y << filter(x[n]); 73 | } 74 | 75 | return y; 76 | } 77 | 78 | float64 79 | FilterDC:: 80 | filter(const float64 & x) 81 | { 82 | float64 out = x - last_input_ + feedback_gain_ * last_output_; 83 | 84 | last_input_ = x; 85 | last_output_ = out; 86 | 87 | return out; 88 | } 89 | 90 | -------------------------------------------------------------------------------- /src/Nsound/FilterDC.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: FilterDC.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2007 Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | #ifndef _NSOUND_FILTER_DC_H_ 34 | #define _NSOUND_FILTER_DC_H_ 35 | 36 | #include 37 | 38 | namespace Nsound 39 | { 40 | 41 | class AudioStream; 42 | class Buffer; 43 | 44 | /////////////////////////////////////////////////////////////////////////// 45 | class FilterDC 46 | { 47 | /////////////////////////////////////////////////////////////////////// 48 | public: 49 | 50 | FilterDC(const float64 & feedback_gain); 51 | 52 | /////////////////////////////////////////////////////////////////////// 53 | AudioStream 54 | filter(const AudioStream & x); 55 | 56 | /////////////////////////////////////////////////////////////////////// 57 | Buffer 58 | filter(const Buffer & x); 59 | 60 | /////////////////////////////////////////////////////////////////////// 61 | float64 62 | filter(const float64 & x); 63 | 64 | /////////////////////////////////////////////////////////////////////// 65 | protected: 66 | 67 | float64 feedback_gain_; 68 | float64 last_input_; 69 | float64 last_output_; 70 | }; 71 | 72 | }; // Nsound 73 | 74 | // :mode=c++: jEdit modeline 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/Nsound/FilterHighPassIIR.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: FilterHighPassIIR.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2007 Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | #ifndef _NSOUND_FILTER_HIGH_PASS_IIR_H_ 29 | #define _NSOUND_FILTER_HIGH_PASS_IIR_H_ 30 | 31 | #include 32 | 33 | namespace Nsound 34 | { 35 | 36 | // Forward class declarations 37 | class AudioStream; 38 | class Buffer; 39 | 40 | //----------------------------------------------------------------------------- 41 | //! A class for filtering audio in the frequecy domain. 42 | class FilterHighPassIIR : public FilterStageIIR 43 | { 44 | public: 45 | 46 | FilterHighPassIIR( 47 | const float64 & sample_rate, 48 | uint32 n_poles, 49 | const float64 & frequency, 50 | const float64 & percent_ripple = 0.0); 51 | 52 | AudioStream 53 | filter(const AudioStream & x); 54 | 55 | AudioStream 56 | filter(const AudioStream & x, const float64 & f); 57 | 58 | AudioStream 59 | filter(const AudioStream & x, const Buffer & frequencies); 60 | 61 | Buffer 62 | filter(const Buffer & x); 63 | 64 | Buffer 65 | filter(const Buffer & x, const float64 & f); 66 | 67 | Buffer 68 | filter(const Buffer & x, const Buffer & frequencies); 69 | 70 | float64 71 | filter(const float64 & x); 72 | 73 | float64 74 | filter(const float64 & x, const float64 & frequency); 75 | 76 | float64 77 | getFrequency() const {return frequency_;}; 78 | 79 | void 80 | makeKernel(const float64 & frequency); 81 | 82 | void 83 | plot(boolean show_fc = true, boolean show_phase = false); 84 | 85 | void 86 | reset(); 87 | 88 | }; 89 | 90 | }; 91 | 92 | // :mode=c++: jEdit modeline 93 | #endif 94 | -------------------------------------------------------------------------------- /src/Nsound/FilterMedian.hpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // $Id: FilterMedian.h 825 2014-02-22 03:39:23Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2016 Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | ////////////////////////////////////////////////////////////////////////////// 15 | 16 | ////////////////////////////////////////////////////////////////////////////// 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | ////////////////////////////////////////////////////////////////////////////// 33 | #ifndef _NSOUND_FILTER_MEDIAN_HPP_ 34 | #define _NSOUND_FILTER_MEDIAN_HPP_ 35 | 36 | #include 37 | 38 | namespace Nsound 39 | { 40 | 41 | 42 | class AudioStream; 43 | class Buffer; 44 | 45 | 46 | class FilterMedian 47 | { 48 | public: 49 | 50 | FilterMedian(uint32 n_samples_in_pool); 51 | 52 | AudioStream filter(const AudioStream & x); 53 | 54 | Buffer filter(const Buffer & b); 55 | 56 | float64 filter(const float64 & x); 57 | 58 | void fill(float64 x); 59 | 60 | protected: 61 | 62 | uint32 _h_ptr; 63 | uint32 _median; 64 | 65 | std::vector _history; 66 | std::vector _pool; 67 | }; 68 | 69 | 70 | } // namespace 71 | 72 | // :mode=c++: jEdit modeline 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /src/Nsound/Instrument.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: Instrument.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2004, 2005 Nick Hilton 11 | // 12 | // weegreenblobbie_at_yahoo_com 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | 34 | #ifndef _NSOUND_INSTRUMENT_H_ 35 | #define _NSOUND_INSTRUMENT_H_ 36 | 37 | #include 38 | 39 | #include 40 | 41 | namespace Nsound 42 | { 43 | 44 | // Forward declarations 45 | 46 | class AudioStream; 47 | 48 | //----------------------------------------------------------------------------- 49 | //! The Nsound Instrument baseclass. All Nsound instruments extend this class. 50 | class Instrument 51 | { 52 | public: 53 | 54 | Instrument(const float64 & sample_rate):sample_rate_(sample_rate){}; 55 | 56 | virtual 57 | ~Instrument(){}; 58 | 59 | //! Plays a demo for this instrument. 60 | virtual 61 | AudioStream 62 | play() = 0; 63 | 64 | //! Plays a static note for this instrument. 65 | virtual 66 | AudioStream 67 | play(const float64 & duration, const float64 & frequency) = 0; 68 | 69 | //! Returns information about who wrote this instrument and how to use it. 70 | virtual 71 | std::string 72 | getInfo() = 0; 73 | 74 | protected: 75 | 76 | float64 sample_rate_; 77 | }; 78 | 79 | }; 80 | 81 | // :mode=c++: jEdit modeline 82 | #endif 83 | -------------------------------------------------------------------------------- /src/Nsound/Pluck.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: Pluck.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2004-2007 Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | using namespace Nsound; 39 | 40 | //----------------------------------------------------------------------------- 41 | Nsound:: 42 | Pluck:: 43 | Pluck(const float64 & sample_rate, uint32 n_smooth_samples) 44 | : 45 | Generator(sample_rate), 46 | n_smooth_samples_(n_smooth_samples) 47 | { 48 | } 49 | 50 | //----------------------------------------------------------------------------- 51 | Nsound:: 52 | Pluck:: 53 | ~Pluck() 54 | { 55 | } 56 | 57 | Buffer 58 | Pluck:: 59 | generate(const float64 & duration, const float64 & frequency) 60 | { 61 | DelayLine delay(sample_rate_, 1.0 / frequency); 62 | FilterDC dc_filter(0.99); 63 | FilterTone tone(sample_rate_, 14 * frequency * duration); 64 | 65 | Buffer noise_env = drawLine(1.0 / frequency, 1.0, 1.0) 66 | << drawLine(duration - (1.0 / frequency), 0.0, 0.0) 67 | << 0.0; 68 | 69 | Buffer x = whiteNoise(duration) * noise_env * 2.0; 70 | 71 | x.smooth(1, n_smooth_samples_); 72 | x.normalize(); 73 | 74 | uint32 n_samples = static_cast(duration * sample_rate_); 75 | 76 | Buffer y; 77 | 78 | delay.write(x[0]); 79 | for(uint32 n = 0; n < n_samples; ++n) 80 | { 81 | 82 | y << dc_filter.filter(tone.filter(delay.read())); 83 | 84 | delay.write(x[n] + y[n]); 85 | } 86 | y.normalize(); 87 | 88 | return y; 89 | } 90 | 91 | -------------------------------------------------------------------------------- /src/Nsound/Pluck.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: Pluck.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2004-2007 Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | #ifndef _NSOUND_PLUCK_H_ 30 | #define _NSOUND_PLUCK_H_ 31 | 32 | #include 33 | 34 | namespace Nsound 35 | { 36 | 37 | class Buffer; 38 | 39 | //----------------------------------------------------------------------------- 40 | //! Implements a simple Karplus-Strong String Synthesis algorithim. 41 | // 42 | class Pluck : public Generator 43 | { 44 | public: 45 | 46 | Pluck(const float64 & sample_rate, uint32 n_smooth_samples); 47 | 48 | virtual ~Pluck(); 49 | 50 | //! Implements simple Karplus-Strong plucked string. 51 | Buffer 52 | generate(const float64 & duration, const float64 & frequency); 53 | 54 | // These don't do anything yet. 55 | float64 generate(const float64 & f){return 0.0;} 56 | float64 generate2(const float64 & f, const float64 & p){return 0.0;} 57 | 58 | Buffer generate2( 59 | const float64 & d, 60 | const float64 & f, 61 | const float64 & p){return Buffer();} 62 | 63 | Buffer generate( 64 | const float64 & d, 65 | const Buffer & f){return Buffer();} 66 | 67 | Buffer generate2( 68 | const float64 & d, 69 | const float64 & f, 70 | const Buffer & p){return Buffer();} 71 | 72 | Buffer generate2( 73 | const float64 & d, 74 | const Buffer & f, 75 | const float64 & p){return Buffer();} 76 | 77 | Buffer generate2( 78 | const float64 & d, 79 | const Buffer & f, 80 | const Buffer & p){return Buffer();} 81 | 82 | protected: 83 | 84 | uint32 n_smooth_samples_; 85 | 86 | }; 87 | 88 | }; 89 | 90 | // :mode=c++: jEdit modeline 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /src/Nsound/RandomNumberGenerator.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: RandomNumberGenerator.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2009 to Present Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | #ifndef _NSOUND_RANDOM_NUMBER_GENERATOR_H_ 34 | #define _NSOUND_RANDOM_NUMBER_GENERATOR_H_ 35 | 36 | #include 37 | 38 | namespace Nsound 39 | { 40 | 41 | //----------------------------------------------------------------------------- 42 | //! Base class for random number generators. 43 | class RandomNumberGenerator 44 | { 45 | public: 46 | 47 | virtual 48 | ~RandomNumberGenerator(){}; 49 | 50 | //! Get a random number. 51 | virtual 52 | uint32 53 | get() = 0; 54 | 55 | //! Get a random float64 between min & max. 56 | virtual 57 | float64 58 | get(const float64 & min, const float64 & max) = 0; 59 | 60 | //! Set the seed to use. 61 | virtual 62 | void 63 | setSeed(uint32 seed) = 0; 64 | 65 | }; // class Filter 66 | 67 | } // namespace 68 | 69 | // :mode=c++: jEdit modeline 70 | #endif 71 | -------------------------------------------------------------------------------- /src/Nsound/RngTausworthe.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: RngTausworthe.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2009 to Present Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | #ifndef _NSOUND_RNG_TAUSWORTHE_H_ 34 | #define _NSOUND_RNG_TAUSWORTHE_H_ 35 | 36 | #include 37 | #include 38 | 39 | namespace Nsound 40 | { 41 | 42 | //----------------------------------------------------------------------------- 43 | //! An implementation of the Tausworthe random number algorithm found in the 44 | //! GNU Scientific Library. 45 | class RngTausworthe : public RandomNumberGenerator 46 | { 47 | public: 48 | 49 | //! Default seed used is the number of seconds from unix epoch. 50 | RngTausworthe(); 51 | 52 | //! Get a random number. 53 | uint32 54 | get(); 55 | 56 | //! Get a random float64 between min & max. 57 | int32 58 | get(const Nsound::int32 min, const Nsound::int32 max); 59 | 60 | //! Get a random float64 between min & max. 61 | float64 62 | get(const Nsound::float64 & min, const Nsound::float64 & max); 63 | 64 | //! assignment operator 65 | RngTausworthe & 66 | operator=(const RngTausworthe & rhs); 67 | 68 | //! Set the seed to use. 69 | void 70 | setSeed(Nsound::uint32 seed); 71 | 72 | private: 73 | 74 | Nsound::uint32 s1_; 75 | Nsound::uint32 s2_; 76 | Nsound::uint32 s3_; 77 | }; 78 | 79 | } // namespace 80 | 81 | #endif 82 | 83 | // :mode=c++: jEdit modeline 84 | -------------------------------------------------------------------------------- /src/Nsound/Sawtooth.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: Sawtooth.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2004-2006 Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | using namespace Nsound; 38 | 39 | //----------------------------------------------------------------------------- 40 | Sawtooth:: 41 | Sawtooth(const float64 & sample_rate, const int32 n_harmonics) 42 | : Generator(sample_rate) 43 | { 44 | 45 | // From wikipedia's definition of a sawtooth wave. 46 | 47 | float64 Nf = static_cast(std::abs(n_harmonics)); 48 | 49 | if(Nf < 1.0) Nf = 1.0; 50 | 51 | Buffer waveform = Buffer::zeros(static_cast(sample_rate_)); 52 | 53 | for(float64 k = 1.0; k <= Nf; k += 1.0) 54 | { 55 | waveform += drawSine(1.0, k) / k; 56 | } 57 | 58 | waveform *= 2.0 / M_PI; 59 | 60 | ctor(sample_rate, waveform); 61 | } 62 | -------------------------------------------------------------------------------- /src/Nsound/Sawtooth.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: Sawtooth.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2010-Present Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | #ifndef _NSOUND_SAWTOOTH_H_ 34 | #define _NSOUND_SAWTOOTH_H_ 35 | 36 | #include 37 | 38 | namespace Nsound 39 | { 40 | 41 | //----------------------------------------------------------------------------- 42 | //! DOXME 43 | class Sawtooth : public Generator 44 | { 45 | public: 46 | 47 | //! DOXME 48 | Sawtooth(const float64 & sample_rate, const int32 n_harmonics = 100); 49 | 50 | }; 51 | 52 | }; 53 | 54 | #endif 55 | 56 | // :mode=c++: jEdit modeline 57 | -------------------------------------------------------------------------------- /src/Nsound/Sine.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: Sine.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2004-2006 Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | using namespace Nsound; 35 | 36 | //----------------------------------------------------------------------------- 37 | Sine:: 38 | Sine(const float64 & sample_rate) 39 | : Generator(sample_rate) 40 | { 41 | //~ float64 two_pi = 2.0 * M_PI; 42 | 43 | //~ float64 w = two_pi / sample_rate_; 44 | 45 | //~ uint64 n_samples = static_cast(sample_rate_); 46 | 47 | //~ for(uint64 i = 0; i < n_samples; ++i) 48 | //~ { 49 | //~ waveform_[i] = std::sin(i * w); 50 | //~ } 51 | 52 | Buffer waveform = drawSine(1.0, 1.0); 53 | ctor(sample_rate, waveform); 54 | } 55 | -------------------------------------------------------------------------------- /src/Nsound/Sine.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: Sine.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2004-2006 Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | #ifndef _NSOUND_SINE_H_ 34 | #define _NSOUND_SINE_H_ 35 | 36 | #include 37 | 38 | namespace Nsound 39 | { 40 | 41 | //----------------------------------------------------------------------------- 42 | //! DOXME 43 | class Sine : public Generator 44 | { 45 | public: 46 | 47 | //! DOXME 48 | Sine(const float64 & sample_rate); 49 | 50 | };// class Sine 51 | 52 | };// namespace Nsound 53 | 54 | // :mode=c++: jEdit modeline 55 | #endif 56 | -------------------------------------------------------------------------------- /src/Nsound/Square.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: Square.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2006 Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | #ifndef _NSOUND_SQUARE_H_ 29 | #define _NSOUND_SQUARE_H_ 30 | 31 | #include 32 | #include 33 | 34 | namespace Nsound 35 | { 36 | 37 | //! Square generator. 38 | // 39 | //! 1----2 40 | //! | | 41 | //! | | 42 | //! | | 43 | //! --1 2--3 4-- 44 | //! | | 45 | //! | | 46 | //! | | 47 | //! 3----4 48 | //! 49 | //! |-----lambda------| 50 | class Square : public Generator 51 | { 52 | public: 53 | 54 | Square( 55 | const float64 & sample_rate); 56 | 57 | Square( 58 | const float64 & sample_rate, 59 | const int32 n_harmonics); 60 | 61 | Square( 62 | const float64 & sample_rate, 63 | const float64 & percent_lambda_1, 64 | const float64 & amplitude_1, 65 | const float64 & percent_lambda_2, 66 | const float64 & percent_lambda_3, 67 | const float64 & amplitude_3, 68 | const float64 & percent_lambda_4); 69 | }; 70 | 71 | }; 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src/Nsound/StreamOperators.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: StreamOperators.cc 879 2014-11-29 20:48:10Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2009 to Present Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | #include 30 | 31 | namespace Nsound 32 | { 33 | 34 | template 35 | std::ostream & 36 | _write(std::ostream & out, T value) 37 | { 38 | out.write(reinterpret_cast(&value), sizeof(T)); 39 | return out; 40 | } 41 | 42 | std::ostream & 43 | operator&(std::ostream & out, char value) { return _write(out, value); } 44 | 45 | std::ostream & 46 | operator&(std::ostream & out, uint32 value) { return _write(out, value); } 47 | 48 | std::ostream & 49 | operator&(std::ostream & out, uint64 value) { return _write(out, value); } 50 | 51 | std::ostream & 52 | operator&(std::ostream & out, float32 value) { return _write(out, value); } 53 | 54 | std::ostream & 55 | operator&(std::ostream & out, float64 value) { return _write(out, value); } 56 | 57 | template 58 | std::istream & 59 | _read(std::istream & in, T & value) 60 | { 61 | in.read(reinterpret_cast(&value), sizeof(T)); 62 | return in; 63 | } 64 | 65 | std::istream & 66 | operator&(std::istream & in, char & value) { return _read(in, value); } 67 | 68 | std::istream & 69 | operator&(std::istream & in, uint32 & value) { return _read(in, value); } 70 | 71 | std::istream & 72 | operator&(std::istream & in, uint64 & value) { return _read(in, value); } 73 | 74 | std::istream & 75 | operator&(std::istream & in, float32 & value) { return _read(in, value); } 76 | 77 | std::istream & 78 | operator&(std::istream & in, float64 & value) { return _read(in, value); } 79 | 80 | } // namespace -------------------------------------------------------------------------------- /src/Nsound/StreamOperators.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: StreamOperators.h 879 2014-11-29 20:48:10Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2007 Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | 34 | #ifndef _NSOUND_STREAM_OPERATORS_H_ 35 | #define _NSOUND_STREAM_OPERATORS_H_ 36 | 37 | #include 38 | 39 | #include 40 | 41 | namespace Nsound 42 | { 43 | 44 | // Read/write binary to/from streams. 45 | 46 | std::ostream & operator&(std::ostream & out, char value); 47 | std::ostream & operator&(std::ostream & out, uint32 value); 48 | std::ostream & operator&(std::ostream & out, uint64 value); 49 | std::ostream & operator&(std::ostream & out, float32 value); 50 | std::ostream & operator&(std::ostream & out, float64 value); 51 | 52 | std::istream & operator&(std::istream & out, char & value); 53 | std::istream & operator&(std::istream & out, uint32 & value); 54 | std::istream & operator&(std::istream & out, uint64 & value); 55 | std::istream & operator&(std::istream & out, float32 & value); 56 | std::istream & operator&(std::istream & out, float64 & value); 57 | 58 | template 59 | T peek(std::istream & in) 60 | { 61 | T tmp = 0; 62 | 63 | std::streampos pos = in.tellg(); 64 | 65 | in.read(static_cast(&tmp), sizeof(T)); 66 | 67 | in.seekg(pos); 68 | 69 | return tmp; 70 | } 71 | 72 | } // namespace 73 | 74 | // :mode=c++: jEdit modeline 75 | #endif 76 | -------------------------------------------------------------------------------- /src/Nsound/StretcherCuda.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: StretcherCuda.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2008 to Present Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | #ifndef _NSOUND_STRETCHER_CUDA_H_ 34 | #define _NSOUND_STRETCHER_CUDA_H_ 35 | 36 | namespace Nsound 37 | { 38 | 39 | void 40 | searchForBestMatch_f64( 41 | double * rss, 42 | const double * source, 43 | const unsigned int source_index, 44 | const unsigned int search_index, 45 | const unsigned int window_length, 46 | const unsigned int max_delta); 47 | 48 | void 49 | searchForBestMatch_f32( 50 | float * rss, 51 | const float * source, 52 | const unsigned int source_index, 53 | const unsigned int search_index, 54 | const unsigned int window_length, 55 | const unsigned int max_delta); 56 | 57 | } // namespace 58 | 59 | #endif 60 | // :mode=c++: jEdit modeline 61 | -------------------------------------------------------------------------------- /src/Nsound/TicToc.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: TicToc.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2004-2006 Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | #include 30 | 31 | #include 32 | 33 | namespace Nsound 34 | { 35 | static double start_time = 0.0; 36 | 37 | void Tic() 38 | { 39 | start_time = clock(); 40 | } 41 | 42 | Nsound::float64 Toc() 43 | { 44 | return ((clock() - start_time) / static_cast(CLOCKS_PER_SEC)); 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /src/Nsound/TicToc.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: TicToc.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2004-2006 Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | #ifndef _NSOUND_TICTOC_H_ 34 | #define _NSOUND_TICTOC_H_ 35 | 36 | #include 37 | 38 | namespace Nsound 39 | { 40 | void Tic(); 41 | Nsound::float64 Toc(); 42 | }; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/Nsound/Utils.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: Utils.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2005-Present Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | #include 34 | 35 | #include // for pow 36 | 37 | using namespace Nsound; 38 | 39 | namespace Nsound 40 | { 41 | 42 | //----------------------------------------------------------------------------- 43 | // ! Calculates a new frequency that is a number of octaves and cents away. 44 | float64 45 | getFrequencyOffset( 46 | const float64 & f1, 47 | const float64 & octaves, 48 | const float64 & cents) 49 | { 50 | return f1 * pow(2.0, octaves + cents / 1200.0); 51 | } 52 | 53 | }; // Nsound 54 | 55 | // :mode=c++: jEdit modeline 56 | -------------------------------------------------------------------------------- /src/Nsound/Utils.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: Utils.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2004-2006 Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | #ifndef _NSOUND_UTILS_H_ 34 | #define _NSOUND_UTILS_H_ 35 | 36 | #include 37 | 38 | namespace Nsound 39 | { 40 | 41 | //~static const float32 zero = 0.0; 42 | 43 | //----------------------------------------------------------------------------- 44 | // ! Calculates a new frequency that is a number of octaves and cents away. 45 | float64 46 | getFrequencyOffset( 47 | const float64 & f1, 48 | const float64 & octaves = 0.0, 49 | const float64 & cents = 0.0); 50 | 51 | }; 52 | 53 | #endif 54 | 55 | // :mode=c++: jEdit modeline 56 | -------------------------------------------------------------------------------- /src/Nsound/WindowType.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: WindowType.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2004-2006 Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | #ifndef _NSOUND_WINDOW_TYPE_H_ 34 | #define _NSOUND_WINDOW_TYPE_H_ 35 | 36 | namespace Nsound 37 | { 38 | 39 | enum WindowType 40 | { 41 | BARTLETT, 42 | BLACKMAN, 43 | BLACKMAN_HARRIS, 44 | GAUSSIAN, 45 | GAUSSIAN_05, 46 | GAUSSIAN_10, 47 | GAUSSIAN_15, 48 | GAUSSIAN_20, 49 | GAUSSIAN_25, 50 | GAUSSIAN_30, 51 | GAUSSIAN_33, 52 | GAUSSIAN_35, 53 | GAUSSIAN_40, 54 | GAUSSIAN_45, 55 | GAUSSIAN_50, 56 | GAUSSIAN_55, 57 | GAUSSIAN_60, 58 | GAUSSIAN_65, 59 | GAUSSIAN_66, 60 | GAUSSIAN_70, 61 | GAUSSIAN_75, 62 | GAUSSIAN_80, 63 | GAUSSIAN_85, 64 | GAUSSIAN_90, 65 | GAUSSIAN_95, 66 | GAUSSIAN_99, 67 | HAMMING, 68 | HANNING, 69 | KAISER, 70 | NUTTALL, 71 | PARZEN, 72 | RECTANGULAR, 73 | }; 74 | 75 | }; 76 | 77 | #endif 78 | 79 | // :mode=c++: jEdit modeline 80 | -------------------------------------------------------------------------------- /src/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/__init__.py -------------------------------------------------------------------------------- /src/bin/SConscript: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # 3 | # $Id: SConscript 807 2013-12-26 22:49:36Z weegreenblobbie $ 4 | # 5 | ############################################################################### 6 | 7 | Import("nsound_config") 8 | Import("nsound_h") 9 | 10 | env = nsound_config.env 11 | 12 | linkflags = "$_RPATH" 13 | 14 | if env['NS_BUILD_STATIC']: 15 | linkflags = "" 16 | 17 | exe_env = env.Clone() 18 | 19 | exe_env.AppendUnique( 20 | CPPPATH = [".."], 21 | LIBPATH = [env['NS_LIBDIR']], 22 | LINKFLAGS = [linkflags]) 23 | 24 | exe_env.AppendUnique(LIBS = ["Nsound"]) 25 | 26 | exe_list = Split( 27 | """ 28 | ns_readwaveheader 29 | ns_vocoder 30 | """) 31 | 32 | for f in exe_list: 33 | exe = exe_env.Program(target = f, source = f + ".cc") 34 | nsound_config.env.Default(exe) 35 | nsound_config.env.Depends(exe, nsound_h) 36 | nsound_config.env.Install(dir = env['NS_BINDIR'], source = exe) 37 | 38 | # :mode=python: 39 | -------------------------------------------------------------------------------- /src/bin/ns_readwaveheader.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: ns_readwaveheader.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2005-2006 Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | #include 30 | 31 | #include 32 | 33 | using namespace Nsound; 34 | 35 | using std::cout; 36 | using std::cerr; 37 | using std::endl; 38 | 39 | int main(int argc, char ** argv) 40 | { 41 | 42 | if(argc < 2) 43 | { 44 | cerr << endl 45 | << "usage: readHeader [wave]" 46 | << endl 47 | << endl; 48 | return 1; 49 | } 50 | 51 | std::string filename(argv[1]); 52 | std::string info; 53 | 54 | if( Nsound::Wavefile::readHeader(filename, info) ) 55 | { 56 | cout << info << "SUCCESS" << endl; 57 | } 58 | else 59 | { 60 | cout << info << "FAILURE" << endl; 61 | } 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /src/examples/SConscript: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # 3 | # $Id: SConscript 823 2014-02-18 03:44:15Z weegreenblobbie $ 4 | # 5 | ############################################################################### 6 | 7 | Import("nsound_config") 8 | Import("nsound_h") 9 | 10 | env = nsound_config.env 11 | 12 | linkflags = "$_RPATH" 13 | 14 | if env['NS_BUILD_STATIC']: 15 | linkflags = "" 16 | 17 | exe_env = env.Clone() 18 | 19 | exe_env.PrependUnique( 20 | CPPPATH = [".."], 21 | LIBPATH = [env['NS_LIBDIR']], 22 | LINKFLAGS = [linkflags]) 23 | 24 | exe_env.PrependUnique(LIBS = ["Nsound"]) 25 | 26 | exe_list = Split( 27 | """ 28 | bebot 29 | cepstral_pitch_estimate 30 | dynamic_filter 31 | example1 32 | example2 33 | example3 34 | example4 35 | example5 36 | example6 37 | interstellar 38 | mynameis 39 | stretcher 40 | """) 41 | 42 | for f in exe_list: 43 | exe = exe_env.Program(target = f, source = f + ".cc") 44 | nsound_config.env.Depends(exe, nsound_h) 45 | nsound_config.env.Default(exe) 46 | 47 | # :mode=python: 48 | -------------------------------------------------------------------------------- /src/examples/Temperature_in.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/examples/Temperature_in.wav -------------------------------------------------------------------------------- /src/examples/california.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/examples/california.wav -------------------------------------------------------------------------------- /src/examples/dynamic_filter.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: dynamic_filter.cc 913 2015-08-08 16:41:22Z weegreenblobbie $ 4 | // 5 | //----------------------------------------------------------------------------- 6 | 7 | // Nsound headers 8 | #include 9 | 10 | using namespace Nsound; 11 | 12 | int 13 | main(void) 14 | { 15 | // Read in the wavefile. 16 | AudioStream input("Temperature_in.wav"); 17 | 18 | // Grab the duration in seconds. 19 | float64 duration = input.getDuration(); 20 | 21 | // Create a low pass filter with a kernel of 256 terms. 22 | FilterLowPassFIR lpf(input.getSampleRate(), 256, 100); 23 | 24 | // Create a buffer that will hold cut off frequencies. 25 | Buffer frequencies; 26 | 27 | // Fill it with two lines 28 | Sine sin(input.getSampleRate()); 29 | 30 | frequencies << sin.drawLine(0.5 * duration, 8000, 50) 31 | << sin.drawLine(0.5 * duration, 50, 8000); 32 | 33 | // Filter it. 34 | AudioStream output = lpf.filter(input, frequencies); 35 | 36 | // Write to disk. 37 | output >> "Temperature_out.wav"; 38 | 39 | AudioPlaybackRt pb(input.getSampleRate(), 2); 40 | 41 | output * 0.666 >> pb; 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /src/examples/dynamic_filter.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # 3 | # $Id: dynamic_filter.py 361 2009-09-10 00:37:56Z weegreenblobbie $ 4 | # 5 | ############################################################################### 6 | 7 | from Nsound import * 8 | 9 | # Read in the wavefile. 10 | input = AudioStream("Temperature_in.wav") 11 | 12 | # Grab the duration in seconds. 13 | duration = input.getDuration() 14 | 15 | # Create a low pass filter with a kernel of 256 terms. 16 | lpf = FilterLowPassFIR(input.getSampleRate(), 256, 100) 17 | 18 | # Create a buffer that will hold cut off frequencies. 19 | frequencies = Buffer() 20 | 21 | # Fill it with two lines 22 | sin = Sine(input.getSampleRate()) 23 | 24 | frequencies << sin.drawLine(0.5 * duration, 8000, 50) \ 25 | << sin.drawLine(0.5 * duration, 50, 8000) 26 | 27 | # Filter it. 28 | output = lpf.filter(input, frequencies) 29 | 30 | # Write to disk. 31 | output >> "Temperature_out.wav" 32 | 33 | -------------------------------------------------------------------------------- /src/examples/example1.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: example1.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | //----------------------------------------------------------------------------- 6 | 7 | #include 8 | 9 | #include 10 | 11 | using std::cout; 12 | using std::cerr; 13 | using std::endl; 14 | 15 | using namespace Nsound; 16 | 17 | int 18 | main(void) 19 | { 20 | float64 sr = 44100.0; 21 | 22 | // Creating the Pac Man background tone. 23 | 24 | Sine sine(sr); 25 | 26 | float64 time = 0.40; 27 | float64 h_time = time / 2.0; 28 | 29 | // The first tone. 30 | Buffer f1 = sine.drawLine(h_time, 345, 923) 31 | << sine.drawLine(h_time, 923, 345); 32 | 33 | Buffer pac_man = sine.generate(7*time, f1); 34 | 35 | // Here we create an envelop to smoothly finish the waveform, removing 36 | // any clicking that might have occured. 37 | Buffer envelope = sine.drawLine(7*time-0.005, 1.0, 1.0) 38 | << sine.drawLine(0.005, 1.0, 0.0); 39 | 40 | pac_man *= envelope; 41 | 42 | pac_man.normalize(); 43 | pac_man *= 0.25; 44 | 45 | pac_man >> "example1.wav"; 46 | 47 | // Play to audio device. 48 | 49 | try 50 | { 51 | AudioPlayback pb(sr, 1, 16); 52 | pac_man >> pb; 53 | } 54 | catch(Exception & e) 55 | { 56 | cerr << "Could not play audio: " << e.what() << endl; 57 | } 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /src/examples/example1.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # 3 | # $Id: example1.py 718 2012-04-15 23:59:35Z weegreenblobbie $ 4 | # 5 | ############################################################################### 6 | 7 | # Import the Nsound module 8 | import Nsound as ns 9 | 10 | sr = 44100.0 11 | 12 | # Creating the Pac Man background tone. 13 | 14 | sine = ns.Sine(sr) 15 | 16 | time = 0.40 17 | h_time = time / 2.0 18 | 19 | # The first tone. 20 | f1 = ns.Buffer() 21 | f1 << sine.drawLine(h_time, 345, 923) \ 22 | << sine.drawLine(h_time, 923, 345) 23 | 24 | pac_man = ns.AudioStream(sr, 1) 25 | pac_man << sine.generate(7.0 * time, f1) 26 | 27 | # Here we create an envelop to smoothly finish the waveform, removing 28 | # any clicking that might have occured. 29 | envelope = ns.AudioStream(sr, 1) 30 | envelope << sine.drawLine(7*time-0.005, 1.0, 1.0) \ 31 | << sine.drawLine(0.005, 1.0, 0.0) 32 | 33 | pac_man *= envelope 34 | 35 | pac_man.normalize() 36 | pac_man *= 0.25 37 | 38 | pac_man >> "example1.wav" 39 | 40 | # Play to audio device. 41 | 42 | pac_man >> ns.AudioPlayback(sr, 1, 16) 43 | 44 | -------------------------------------------------------------------------------- /src/examples/example2.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: example2.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | //----------------------------------------------------------------------------- 6 | 7 | // Include the Nsound headers 8 | #include 9 | 10 | using namespace Nsound; 11 | 12 | using std::cerr; 13 | using std::endl; 14 | 15 | int 16 | main(void) 17 | { 18 | float64 sr = 44100.0; 19 | 20 | // Create a new instance of the Sine Generator 21 | Sine sine(sr); 22 | 23 | Buffer pan; 24 | 25 | pan << sine.generate(4.9, 3.0); 26 | 27 | // Create a stereo AudioStream. 28 | AudioStream as(sr, 2); 29 | 30 | // Fill it with a 220 Hz sine wave. 31 | as << 0.5 * sine.generate(4.9, 220); 32 | 33 | // Execute the pan method. 34 | as.pan(pan); 35 | 36 | // Write the AudioStream to a wave file 37 | as >> "example2.wav"; 38 | 39 | // Play it through the sound card 40 | 41 | try 42 | { 43 | AudioPlayback pb(sr, 2, 16); 44 | as >> pb; 45 | } 46 | catch(Exception & e) 47 | { 48 | cerr << "Could not play audio: " << e.what() << endl; 49 | } 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /src/examples/example2.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # 3 | # $Id: example2.py 718 2012-04-15 23:59:35Z weegreenblobbie $ 4 | # 5 | ############################################################################### 6 | 7 | import Nsound as ns 8 | 9 | sr = 44100.0 10 | 11 | # Create a new instance of the Sine Generator 12 | sine = ns.Sine(sr) 13 | 14 | pan = ns.Buffer() 15 | 16 | pan << sine.generate(4.9, 3.0) 17 | 18 | # Create a stereo AudioStream. 19 | a = ns.AudioStream(sr, 2) 20 | 21 | # Fill it with a 220 Hz sine wave. 22 | a << 0.5 * sine.generate(4.9, 220) 23 | 24 | # Execute the pan method. 25 | a.pan(pan) 26 | 27 | # Write the AudioStream to a wave file 28 | a >> "example2.wav"; 29 | 30 | a >> ns.AudioPlayback(sr, 2, 16); 31 | 32 | -------------------------------------------------------------------------------- /src/examples/example3.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # 3 | # $Id: example3.py 718 2012-04-15 23:59:35Z weegreenblobbie $ 4 | # 5 | # Simulates a drum. Based on the Csound drum by Hans Mikelson. 6 | # 7 | # source: http://www.csounds.com/ezine/winter2001/synthesis/ 8 | # 9 | ############################################################################### 10 | 11 | from Nsound import * 12 | 13 | sr = 44100.0 14 | BITS_PER_SAMPLE = 16 15 | 16 | ############################################################################### 17 | def drum( 18 | duration, 19 | attack_time, 20 | high_frequency, 21 | low_frequency, 22 | tension, 23 | resident_frequency): 24 | "Simple drum" 25 | 26 | sin = Sine(sr) 27 | 28 | frequency_sweep = sin.drawLine(attack_time, high_frequency, low_frequency) 29 | 30 | frequency_sweep << sin.drawLine( 31 | (duration - attack_time), low_frequency, low_frequency) 32 | 33 | hz_20 = sin.generate(duration, resident_frequency) 34 | 35 | rezzy = hz_20 * frequency_sweep 36 | 37 | parabola = sin.drawParabola(duration, 1.0, duration / 2, 0.25, 0.0) 38 | 39 | rezzy *= parabola 40 | 41 | temp1 = rezzy * tension 42 | 43 | frequency_sweep -= temp1 44 | 45 | audio = sin.generate(duration, frequency_sweep) 46 | 47 | audio *= sin.drawParabola(duration,1.0, 0.5 * duration, 0.3,0.0); 48 | 49 | return audio 50 | 51 | ############################################################################### 52 | 53 | sine = Sine(sr) 54 | 55 | bd01 = DrumBD01(sr) 56 | dkb = DrumKickBass(sr, 266, 0.0) 57 | 58 | out = AudioStream(sr, 1); 59 | 60 | out << bd01.play() \ 61 | << sine.silence(0.25) \ 62 | << dkb.play() \ 63 | << sine.silence(0.25) 64 | 65 | # duration, attack, high f, low f, tension, ressonance 66 | out << drum(0.5, 0.012, 160, 51, 0.9, 54) \ 67 | << drum(0.5, 0.012, 160, 51, 0.9, 54) \ 68 | << drum(0.5, 0.012, 160, 51, 0.9, 54) \ 69 | << drum(0.5, 0.012, 160, 51, 0.9, 54) \ 70 | << sine.silence(0.25) 71 | 72 | out *= 0.5 73 | 74 | hat = Hat(sr) 75 | 76 | out << 0.666 * hat.play() << sine.silence(0.25) 77 | 78 | out >> "example3.wav" 79 | 80 | # ReverberationRoom(sample_rate, room_feedback, wet_percent, dry_percent, low_pass_freq) 81 | room = ReverberationRoom(sr, 0.60, 0.5, 1.0, 100.0) 82 | 83 | out2 = 0.5 * room.filter(out) 84 | 85 | out2 >> "example3_reverb.wav" 86 | 87 | pb = AudioPlayback(sr, 2, 16); 88 | 89 | out2 >> pb 90 | -------------------------------------------------------------------------------- /src/examples/example4.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: example4.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | //----------------------------------------------------------------------------- 6 | 7 | // Nsound headers 8 | #include 9 | 10 | using namespace Nsound; 11 | 12 | #include 13 | 14 | using std::cerr; 15 | using std::endl; 16 | 17 | //----------------------------------------------------------------------------- 18 | int 19 | main(void) 20 | { 21 | float64 sr = 44100.0; 22 | 23 | Sine sine(sr); 24 | 25 | GuitarBass bass(sr); 26 | FluteSlide slide(sr); 27 | Clarinet clarinet(sr); 28 | 29 | AudioStream out(sr, 1); 30 | 31 | out << bass.play() << sine.silence(1.0) 32 | << slide.play() << sine.silence(1.0) 33 | << clarinet.play() << sine.silence(1.0); 34 | 35 | out *= 0.5; 36 | 37 | // Set the default Wavefile sample size and rate. 38 | Wavefile::setDefaults(sr, 16); 39 | 40 | out >> "example4.wav"; 41 | 42 | ReverberationRoom room(sr, 0.9); // 0.9 = room feed back (0.0 to 1.0) 43 | 44 | AudioStream out2 = room.filter(0.5 * (bass.play() << sine.silence(1.5))); 45 | 46 | out2 >> "example4_reverb.wav"; 47 | 48 | // Try to play the audio 49 | 50 | try 51 | { 52 | AudioPlayback pb(sr, 2, 16); 53 | out >> pb; 54 | out2 >> pb; 55 | } 56 | catch(Exception & e) 57 | { 58 | cerr << "Could not play audio: " << e.what() << endl; 59 | } 60 | 61 | return 0; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /src/examples/example4.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # 3 | # $Id: example4.py 718 2012-04-15 23:59:35Z weegreenblobbie $ 4 | # 5 | ############################################################################### 6 | 7 | import Nsound as ns 8 | 9 | sr = 44100.0 10 | 11 | sine = ns.Sine(sr) 12 | 13 | bass = ns.GuitarBass(sr) 14 | slide = ns.FluteSlide(sr) 15 | clarinet = ns.Clarinet(sr) 16 | 17 | out = ns.AudioStream(sr, 1) 18 | 19 | out << bass.play() << sine.silence(1.0) \ 20 | << slide.play() << sine.silence(1.0) \ 21 | << clarinet.play() << sine.silence(1.0) 22 | 23 | out *= 0.5 24 | 25 | # Set the default Wavefile sample size and rate. 26 | ns.Wavefile.setDefaults(sr, 16) 27 | 28 | out >> "example4.wav" 29 | 30 | room = ns.ReverberationRoom(sr, 0.9); # 0.9 = room feed back (0.0 to 1.0) 31 | 32 | out2 = ns.AudioStream(sr, 1) 33 | out2 << bass.play() << sine.silence(1.5) 34 | 35 | out2 = room.filter(0.5 * out2) 36 | 37 | out2 >> "example4_reverb.wav" 38 | 39 | # Play to audio device. 40 | 41 | pb = ns.AudioPlayback(sr, 2, 16) 42 | 43 | out >> pb 44 | out2 >> pb 45 | -------------------------------------------------------------------------------- /src/examples/example5.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # 3 | # $Id: example5.py 811 2013-12-27 00:15:15Z weegreenblobbie $ 4 | # 5 | ############################################################################### 6 | 7 | from Nsound import * 8 | 9 | voice = AudioStream("california.wav") 10 | 11 | sr = voice.getSampleRate() 12 | 13 | # Get rid of some low frequency noise from the recording. 14 | hp = FilterHighPassIIR(sr, 6, 45.0, 0.01) 15 | 16 | voice = hp.filter(voice) 17 | 18 | voice_dur = voice.getDuration() 19 | 20 | gen = Granulator(sr, Granulator.DECAY) 21 | 22 | carrier = gen.generate(voice_dur, 1500.0, 6, 40.0) 23 | 24 | vocod = Vocoder(sr, 0.020, 16, 8000) 25 | 26 | output = vocod.filter(voice[0], carrier) 27 | 28 | output.normalize() 29 | 30 | output *= 0.666 31 | 32 | # Play to sound card 33 | pb = AudioPlayback(sr, 2, 16) 34 | 35 | output >> "example5.wav" 36 | output >> pb 37 | 38 | ############################################################################### 39 | # Create some spectrogram plots. 40 | 41 | window = 0.080 # seconds 42 | step = 0.020 # seconds 43 | 44 | pylab = Plotter() 45 | 46 | pylab.figure() 47 | ax1 = pylab.subplot(2, 1, 1) 48 | 49 | spec1 = Spectrogram(voice[0], sr, window, step, HANNING); 50 | 51 | pylab.imagesc( 52 | spec1.getTimeAxis(), 53 | spec1.getFrequencyAxis(), 54 | spec1.getMagnitude().getTranspose()) 55 | 56 | fmax = 2000.0 57 | 58 | pylab.ylim(0.0, fmax) 59 | pylab.xlim(0.0, voice_dur) 60 | 61 | pylab.title("Voice input") 62 | 63 | pylab.subplot(2, 1, 2, "", ax1, ax1) 64 | 65 | spec2 = Spectrogram (output, sr, window, step, HANNING) 66 | 67 | pylab.imagesc( 68 | spec2.getTimeAxis(), 69 | spec2.getFrequencyAxis(), 70 | spec2.getMagnitude().getTranspose()) 71 | 72 | pylab.ylim(0.0, fmax) 73 | pylab.xlim(0.0, voice_dur) 74 | 75 | pylab.title("Voice output") 76 | 77 | pylab.show() 78 | -------------------------------------------------------------------------------- /src/examples/getWavefiles.bash: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | 3 | ############################################################################### 4 | # 5 | # $Id: getWavefiles.bash 595 2010-12-31 16:24:32Z weegreenblobbie $ 6 | # 7 | # Tries to get the example wavefiles from the Nsound Subversion repository. 8 | # 9 | ############################################################################### 10 | 11 | SVN_PREFIX="https://nsound.svn.sourceforge.net/svnroot/nsound/tags/nsound-0.7.4/src/examples" 12 | 13 | echo "Attempting to get wave files from Nsound SVN ..." 14 | 15 | FILES=(\ 16 | "mynameis.wav" 17 | "california.wav" 18 | "walle.wav" 19 | "Temperature_in.wav") 20 | 21 | for f in ${FILES[@]}; do 22 | 23 | echo "wget $SVN_PREFIX/$f" 24 | 25 | wget "$SVN_PREFIX/$f" 26 | 27 | done 28 | 29 | ls -l *.wav 30 | 31 | echo "All done!" 32 | -------------------------------------------------------------------------------- /src/examples/mynameis.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: mynameis.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | //----------------------------------------------------------------------------- 6 | 7 | // Nsound headers 8 | #include 9 | 10 | using namespace Nsound; 11 | 12 | int 13 | main(void) 14 | { 15 | AudioStream as0("mynameis.wav"); 16 | 17 | float64 sr = as0.getSampleRate(); 18 | 19 | // Get rid of some low frequency noise from the recording. 20 | FilterHighPassIIR hp(sr, 6, 200.0, 0.01); 21 | 22 | as0 = hp.filter(as0); 23 | 24 | Buffer raw = as0[0]; 25 | 26 | raw.normalize(); 27 | raw *= 0.5; 28 | 29 | AudioStream as1(sr, 2); 30 | 31 | as1 << raw; 32 | 33 | float64 raw_duration = as1.getDuration(); 34 | 35 | // dynamic pan 36 | Sine sine(sr); 37 | 38 | AudioStream temp = as1.getPan(sine.generate(1.0,8.0)); 39 | 40 | temp >> "mynameis-pan.wav"; 41 | 42 | // Create a Stretcher instance 43 | Stretcher stretch(sr, 0.08, 0.25); 44 | 45 | stretch.showProgress(true); 46 | 47 | // Pitch UP 48 | temp = stretch.pitchShift(as1, 1.3); 49 | 50 | temp >> "mynameis-high-pitch.wav"; 51 | 52 | // Pitch DOWN 53 | temp = stretch.pitchShift(as1, 0.7); 54 | 55 | temp >> "mynameis-low-pitch.wav"; 56 | 57 | // Speed UP 58 | temp = stretch.timeShift(as1, 0.7); 59 | 60 | temp >> "mynameis-faster.wav"; 61 | 62 | // Speed DOWN 63 | temp = stretch.timeShift(as1, 1.3); 64 | 65 | temp >> "mynameis-slower.wav"; 66 | 67 | // wobble 68 | Buffer wobble = 1.0 + 0.25 * sine.generate(1.0,5.0); 69 | 70 | temp = stretch.pitchShift(as1, wobble); 71 | 72 | temp >> "mynameis-wobble.wav"; 73 | 74 | // ramp 75 | Buffer ramp = sine.drawLine(as1.getDuration(), 0.7, 1.3); 76 | 77 | temp = stretch.pitchShift(as1, ramp); 78 | 79 | temp >> "mynameis-ramp.wav"; 80 | 81 | // dynamic filter 82 | Buffer low_freqs = sine.drawLine(1.0, 1000, 1000) 83 | << sine.drawLine(raw_duration - 1.0, 1000, 20); 84 | 85 | Buffer high_freqs = sine.drawLine(1.0, 2000, 2000) 86 | << sine.drawLine(raw_duration - 1.0, 2000, 16000); 87 | 88 | FilterBandPassIIR bpf(sr, 4, 1000, 2000, 0.01); 89 | 90 | AudioStream filtered(sr, 1); 91 | 92 | filtered << raw << sine.silence(0.25); 93 | 94 | filtered = bpf.filter(filtered, low_freqs, high_freqs); 95 | 96 | // There is a large click at the end of this result from the IIR high pass 97 | // portion, IIR filter are not stable at every frequency. 98 | 99 | // Cut off the click. 100 | filtered = filtered.substream(0.0f, 3.7f); 101 | 102 | filtered.normalize(); 103 | filtered *= 0.5; 104 | 105 | filtered >> "mynameis-filtered.wav"; 106 | 107 | return 0; 108 | } 109 | -------------------------------------------------------------------------------- /src/examples/mynameis.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/examples/mynameis.wav -------------------------------------------------------------------------------- /src/examples/stretcher.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: stretcher.cc 913 2015-08-08 16:41:22Z weegreenblobbie $ 4 | // 5 | //----------------------------------------------------------------------------- 6 | 7 | // Nsound headers 8 | #include 9 | 10 | // C++ header 11 | #include 12 | 13 | using namespace Nsound; 14 | 15 | using std::cout; 16 | using std::endl; 17 | 18 | //----------------------------------------------------------------------------- 19 | int 20 | main(void) 21 | { 22 | AudioStream a("Temperature_in.wav"); 23 | 24 | // Grab sample rate. 25 | float64 sr = a.getSampleRate(); 26 | 27 | // Create a audio playback object 28 | 29 | AudioPlaybackRt pb(sr, a.getNChannels()); 30 | 31 | // Grab the duration in seconds. 32 | float64 duration = a.getDuration(); 33 | 34 | // Create a Gaussian curve for pitch/time shifting. 35 | Sine sin(sr); 36 | 37 | Buffer bend = sin.drawFatGaussian(duration, 0.15) + 1.0; 38 | 39 | // Create a Stretcher instance 40 | Stretcher stretch(sr, 0.08, 0.25); 41 | 42 | // Print progress to command line. 43 | stretch.showProgress(true); 44 | 45 | cout << "Pitch Shifting Up" << endl; 46 | 47 | // Create new output AudioStream, pitch shift input AudioStream. 48 | AudioStream out(sr, 2); 49 | 50 | out << stretch.pitchShift(a, bend); 51 | out >> "Temperature_Pitch_Shifted_Up.wav"; 52 | out * 0.666 >> pb; 53 | 54 | cout << "Time Shifting Faster" << endl; 55 | 56 | // Time shift input AudioStream. 57 | out = AudioStream(sr, 2); 58 | 59 | out << stretch.timeShift(a, 1.0 / bend); 60 | out >> "Temperature_Time_Shifted_Faster.wav"; 61 | out * 0.666 >> pb; 62 | 63 | bend = 1.0 - 0.25 * sin.drawFatGaussian(duration, 0.15); 64 | 65 | cout << "Pitch Shifting Down" << endl; 66 | 67 | out = AudioStream(sr, 2); 68 | out << stretch.pitchShift(a, bend); 69 | out >> "Temperature_Pitch_Shifted_Down.wav"; 70 | out * 0.666 >> pb; 71 | 72 | cout << "Time Shifting Slower" << endl; 73 | 74 | bend = 1.0 + 0.75 * sin.drawFatGaussian(duration, 0.15); 75 | 76 | out = AudioStream(sr,2); 77 | out << stretch.timeShift(a, bend); 78 | out >> "Temperature_Time_Shifted_Slower.wav"; 79 | out * 0.666 >> pb; 80 | 81 | return 0; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /src/examples/stretcher.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # 3 | # $Id: stretcher.py 585 2010-12-15 05:21:28Z weegreenblobbie $ 4 | # 5 | ############################################################################### 6 | 7 | from Nsound import * 8 | 9 | # Read in the wavefile. 10 | a1 = AudioStream("Temperature_in.wav") 11 | 12 | # Grab sample rate. 13 | sr = a1.getSampleRate() 14 | 15 | # Grab the duration in seconds. 16 | duration = a1.getDuration() 17 | 18 | # Create a Gaussian curve for pitch/time shifting. 19 | sin = Sine(sr) 20 | 21 | bend = Buffer() 22 | bend << sin.drawFatGaussian(duration, 0.15) + 1.0 23 | 24 | # Create a Stretcher instance 25 | stretch = Stretcher(sr, 0.08, 0.25) 26 | 27 | # Print progress to command line. 28 | stretch.showProgress(True) 29 | 30 | print("Pitch Shifting Up") 31 | 32 | # Create new output AudioStream. 33 | out = AudioStream(sr, 2) 34 | 35 | # Pitch shift the input AudioStream. 36 | out << stretch.pitchShift(a1, bend) 37 | out >> "Temperature_Pitch_Shifted_Up.wav" 38 | 39 | print("Time Shifting Faster") 40 | 41 | # Time shift input AudioStream 42 | out = AudioStream(sr,2) 43 | out << stretch.timeShift(a1, 1.0 / bend) 44 | out >> "Temperature_Time_Shifted_Faster.wav" 45 | 46 | bend = Buffer() 47 | bend << 1.0 - 0.25 * sin.drawFatGaussian(duration, 0.15) 48 | 49 | print("Pitch Shifting Down") 50 | 51 | out = AudioStream(sr, 2) 52 | out << stretch.pitchShift(a1, bend) 53 | out >> "Temperature_Pitch_Shifted_Down.wav" 54 | 55 | print("Time Shifting Slower") 56 | 57 | bend = Buffer() 58 | bend << 1.0 + 0.75 * sin.drawFatGaussian(duration, 0.15) 59 | 60 | out = AudioStream(sr, 2) 61 | out << stretch.timeShift(a1, bend) 62 | out >> "Temperature_Time_Shifted_Slower.wav" 63 | 64 | -------------------------------------------------------------------------------- /src/examples/walle.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/examples/walle.wav -------------------------------------------------------------------------------- /src/plugins/ladspa/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile 2 | 3 | # :mode=Makefile: 4 | 5 | LIBDIR := /home/nhilton/development/nsound-0.6.1/lib 6 | INCLUDE := /home/nhilton/development/nsound-0.6.1/src 7 | 8 | all: filter1.so guitarBass.so 9 | 10 | %.o: %.cc 11 | g++ $(CXXFLAGS) -c $< -fPIC -o $@ -I$(INCLUDE) 12 | 13 | %.so: %.o 14 | g++ -shared $< -o $@ -Wl,-rpath=$(LIBDIR) -L$(LIBDIR) -lNsound 15 | 16 | .PHONY: clean 17 | 18 | clean: 19 | rm -f *.so *.o 20 | 21 | install: filter1.so guitarBass.so 22 | cp -f *.so ~/.ladspa 23 | -------------------------------------------------------------------------------- /src/test/Main.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: Main.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2005-2006 Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | #include 30 | 31 | #include "UnitTest.h" 32 | 33 | #include 34 | 35 | using std::cerr; 36 | using std::cout; 37 | using std::endl; 38 | using std::flush; 39 | 40 | int main(int argc, char ** argv) 41 | { 42 | cout << "////////////////////////////////////////////////////////////" 43 | << endl 44 | << "// Testing the Nsound release ..." 45 | << endl 46 | << flush; 47 | 48 | Wavefile_UnitTest(); 49 | 50 | Buffer_UnitTest(); 51 | BufferResample_UnitTest(); 52 | 53 | DelayLine_UnitTest(); 54 | 55 | FilterDelay_UnitTest(); 56 | 57 | FilterCombLowPassFeedback_UnitTest(); 58 | 59 | FilterLeastSquaresFIR_UnitTest(); 60 | 61 | FilterMedian_UnitTest(); 62 | 63 | FilterParametricEqualizer_UnitTest(); 64 | 65 | Generator_UnitTest(); 66 | Sine_UnitTest(); 67 | Triangle_UnitTest(); 68 | 69 | FFTransform_UnitTest(); 70 | 71 | Nsound::Plotter::show(); 72 | 73 | cout << endl 74 | << "All Unit Tests Passed!" 75 | << endl; 76 | 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /src/test/SConscript: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # SConstruct - scons file (www.scons.org) 3 | ############################################################################### 4 | 5 | Import("nsound_config") 6 | Import("nsound_h") 7 | 8 | env = nsound_config.env 9 | 10 | linkflags = "$_RPATH" 11 | 12 | if env['NS_BUILD_STATIC']: 13 | linkflags = "" 14 | 15 | exe_env = env.Clone() 16 | 17 | exe_env.AppendUnique( 18 | CPPPATH = [".."], 19 | LIBPATH = [env['NS_LIBDIR']], 20 | LINKFLAGS = [linkflags]) 21 | 22 | exe_env.AppendUnique(LIBS = ["Nsound"]) 23 | 24 | unit_tests = [] 25 | 26 | source_list = Split( 27 | """ 28 | BufferResample_UnitTest.cc 29 | Buffer_UnitTest.cc 30 | DelayLine_UnitTest.cc 31 | FFTransform_UnitTest.cc 32 | FilterCombLowPassFeedback_UnitTest.cc 33 | FilterDelay_UnitTest.cc 34 | FilterLeastSquaresFIR_UnitTest.cc 35 | FilterMedian_UnitTest.cc 36 | FilterParametricEqualizer_UnitTest.cc 37 | Generator_UnitTest.cc 38 | Main.cc 39 | Sine_UnitTest.cc 40 | Triangle_UnitTest.cc 41 | Wavefile_UnitTest.cc 42 | """) 43 | 44 | prog = exe_env.Program(target = "Main", source = source_list) 45 | nsound_config.env.Depends(prog, nsound_h) 46 | unit_tests.append(prog) 47 | 48 | other_tests = Split( 49 | """ 50 | test_audio_stream 51 | test_convolve 52 | test_generators 53 | test_granulator 54 | test_fft 55 | test_filters 56 | test_iir_ga 57 | test_rng 58 | test_mesh 59 | test_mixer 60 | test_moving_average 61 | test_pluck 62 | test_plotter 63 | """) 64 | 65 | for t in other_tests: 66 | prog = exe_env.Program(target = t, source = t + ".cc") 67 | nsound_config.env.Depends(prog, nsound_h) 68 | unit_tests.append(prog) 69 | 70 | Export("unit_tests") 71 | 72 | # :mode=python: 73 | -------------------------------------------------------------------------------- /src/test/Test.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: Test.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Nsound is a C++ library and Python module for audio synthesis featuring 6 | // dynamic digital filters. Nsound lets you easily shape waveforms and write 7 | // to disk or plot them. Nsound aims to be as powerful as Csound but easy to 8 | // use. 9 | // 10 | // Copyright (c) 2006 Nick Hilton 11 | // 12 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 13 | // 14 | //----------------------------------------------------------------------------- 15 | 16 | //----------------------------------------------------------------------------- 17 | // 18 | // This program is free software; you can redistribute it and/or modify 19 | // it under the terms of the GNU General Public License as published by 20 | // the Free Software Foundation; either version 2 of the License, or 21 | // (at your option) any later version. 22 | // 23 | // This program is distributed in the hope that it will be useful, 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | // GNU Library General Public License for more details. 27 | // 28 | // You should have received a copy of the GNU General Public License 29 | // along with this program; if not, write to the Free Software 30 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 31 | // 32 | //----------------------------------------------------------------------------- 33 | 34 | #ifndef _NSOUND_TEST_H_ 35 | #define _NSOUND_TEST_H_ 36 | 37 | #define TEST_HEADER2(line) \ 38 | THIS_FILE << ":"; cout.width(4); cout << line \ 39 | << ": "; cout.width(0); cout 40 | 41 | #define TEST_ERROR_HEADER2(line) \ 42 | endl << THIS_FILE << ":"; cerr.width(4); cerr << line \ 43 | << ": ***Error! "; cerr.width(0); cout 44 | 45 | #define TEST_HEADER \ 46 | THIS_FILE << ":"; cout.width(4); cout << __LINE__ \ 47 | << ": "; cout.width(0); cout 48 | 49 | #define TEST_ERROR_HEADER \ 50 | endl << THIS_FILE << ":"; cerr.width(4); cerr << __LINE__ \ 51 | << ": ***Error! "; cerr.width(0); cout 52 | 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/test/UnitTest.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: UnitTest.h 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2008 Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | #ifndef _NSOUND_UNIT_TEST_H_ 30 | #define _NSOUND_UNIT_TEST_H_ 31 | 32 | // Some macros for messages. 33 | 34 | #define TEST_HEADER \ 35 | endl << THIS_FILE << ":"; cout.width(4); cout << __LINE__ \ 36 | << ": "; cout.width(0); cout 37 | 38 | #define TEST_ERROR_HEADER \ 39 | " FAILURE!" << endl << THIS_FILE << ":"; cerr.width(4); cerr << __LINE__ \ 40 | << ": ***Error! "; cerr.width(0); cerr 41 | 42 | #define SUCCESS \ 43 | " SUCCESS!" 44 | 45 | // The unit tests. 46 | 47 | void Buffer_UnitTest(); 48 | void BufferResample_UnitTest(); 49 | void DelayLine_UnitTest(); 50 | void FFTransform_UnitTest(); 51 | void FilterBandPassFIR_UnitTest(); 52 | void FilterBandPassIIR_UnitTest(); 53 | void FilterBandRejectFIR_UnitTest(); 54 | void FilterBandRejectIIR_UnitTest(); 55 | void FilterCombLowPassFeedback_UnitTest(); 56 | void FilterDelay_UnitTest(); 57 | void FilterHighPassFIR_UnitTest(); 58 | void FilterHighPassIIR_UnitTest(); 59 | void FilterLeastSquaresFIR_UnitTest(); 60 | void FilterLowPassFIR_UnitTest(); 61 | void FilterLowPassIIR_UnitTest(); 62 | void FilterMedian_UnitTest(); 63 | void FilterParametricEqualizer_UnitTest(); 64 | void Generator_UnitTest(); 65 | void Sine_UnitTest(); 66 | void Triangle_UnitTest(); 67 | void Wavefile_UnitTest(); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /src/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/__init__.py -------------------------------------------------------------------------------- /src/test/gold/BufferResample_out_1_2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/BufferResample_out_1_2.wav -------------------------------------------------------------------------------- /src/test/gold/BufferResample_out_2_1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/BufferResample_out_2_1.wav -------------------------------------------------------------------------------- /src/test/gold/BufferResample_out_2_3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/BufferResample_out_2_3.wav -------------------------------------------------------------------------------- /src/test/gold/BufferResample_out_3_2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/BufferResample_out_3_2.wav -------------------------------------------------------------------------------- /src/test/gold/BufferResample_out_3_5.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/BufferResample_out_3_5.wav -------------------------------------------------------------------------------- /src/test/gold/BufferResample_out_4_7.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/BufferResample_out_4_7.wav -------------------------------------------------------------------------------- /src/test/gold/BufferResample_out_5_3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/BufferResample_out_5_3.wav -------------------------------------------------------------------------------- /src/test/gold/BufferResample_out_7_4.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/BufferResample_out_7_4.wav -------------------------------------------------------------------------------- /src/test/gold/Buffer_out1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Buffer_out1.wav -------------------------------------------------------------------------------- /src/test/gold/Buffer_out2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Buffer_out2.wav -------------------------------------------------------------------------------- /src/test/gold/DelayLine_out1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/DelayLine_out1.wav -------------------------------------------------------------------------------- /src/test/gold/FFTransform_out1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FFTransform_out1.wav -------------------------------------------------------------------------------- /src/test/gold/FFTransform_out2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FFTransform_out2.wav -------------------------------------------------------------------------------- /src/test/gold/FFTransform_out3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FFTransform_out3.wav -------------------------------------------------------------------------------- /src/test/gold/FFTransform_out4.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FFTransform_out4.wav -------------------------------------------------------------------------------- /src/test/gold/FFTransform_out5.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FFTransform_out5.wav -------------------------------------------------------------------------------- /src/test/gold/FFTransform_out6.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FFTransform_out6.wav -------------------------------------------------------------------------------- /src/test/gold/FilterBandRejectFIR_out1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FilterBandRejectFIR_out1.wav -------------------------------------------------------------------------------- /src/test/gold/FilterBandRejectFIR_out2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FilterBandRejectFIR_out2.wav -------------------------------------------------------------------------------- /src/test/gold/FilterCombLowPassFeedback_out1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FilterCombLowPassFeedback_out1.wav -------------------------------------------------------------------------------- /src/test/gold/FilterCombLowPassFeedback_out2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FilterCombLowPassFeedback_out2.wav -------------------------------------------------------------------------------- /src/test/gold/FilterDelay_out1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FilterDelay_out1.wav -------------------------------------------------------------------------------- /src/test/gold/FilterDelay_out2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FilterDelay_out2.wav -------------------------------------------------------------------------------- /src/test/gold/FilterDelay_out3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FilterDelay_out3.wav -------------------------------------------------------------------------------- /src/test/gold/FilterLeastSquaresFIR_out1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FilterLeastSquaresFIR_out1.wav -------------------------------------------------------------------------------- /src/test/gold/FilterLeastSquaresFIR_out2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FilterLeastSquaresFIR_out2.wav -------------------------------------------------------------------------------- /src/test/gold/FilterLeastSquaresFIR_out3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FilterLeastSquaresFIR_out3.wav -------------------------------------------------------------------------------- /src/test/gold/FilterParametricEqualizer_out_high.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FilterParametricEqualizer_out_high.wav -------------------------------------------------------------------------------- /src/test/gold/FilterParametricEqualizer_out_low.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FilterParametricEqualizer_out_low.wav -------------------------------------------------------------------------------- /src/test/gold/FilterParametricEqualizer_out_peaking.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/FilterParametricEqualizer_out_peaking.wav -------------------------------------------------------------------------------- /src/test/gold/Filter_noise.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Filter_noise.wav -------------------------------------------------------------------------------- /src/test/gold/Generator_buzz1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Generator_buzz1.wav -------------------------------------------------------------------------------- /src/test/gold/Generator_buzz2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Generator_buzz2.wav -------------------------------------------------------------------------------- /src/test/gold/Generator_buzz3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Generator_buzz3.wav -------------------------------------------------------------------------------- /src/test/gold/Generator_chorus1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Generator_chorus1.wav -------------------------------------------------------------------------------- /src/test/gold/Generator_line1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Generator_line1.wav -------------------------------------------------------------------------------- /src/test/gold/Generator_line2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Generator_line2.wav -------------------------------------------------------------------------------- /src/test/gold/Generator_sine1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Generator_sine1.wav -------------------------------------------------------------------------------- /src/test/gold/Generator_sine2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Generator_sine2.wav -------------------------------------------------------------------------------- /src/test/gold/Generator_sine3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Generator_sine3.wav -------------------------------------------------------------------------------- /src/test/gold/Generator_sine4.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Generator_sine4.wav -------------------------------------------------------------------------------- /src/test/gold/Generator_sine5.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Generator_sine5.wav -------------------------------------------------------------------------------- /src/test/gold/Generator_sine6.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Generator_sine6.wav -------------------------------------------------------------------------------- /src/test/gold/Sine_1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Sine_1.wav -------------------------------------------------------------------------------- /src/test/gold/Sine_2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Sine_2.wav -------------------------------------------------------------------------------- /src/test/gold/Sine_3.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Sine_3.wav -------------------------------------------------------------------------------- /src/test/gold/Sine_4.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Sine_4.wav -------------------------------------------------------------------------------- /src/test/gold/Sine_5.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Sine_5.wav -------------------------------------------------------------------------------- /src/test/gold/Sine_6.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Sine_6.wav -------------------------------------------------------------------------------- /src/test/gold/Sine_7.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Sine_7.wav -------------------------------------------------------------------------------- /src/test/gold/Triangle_1.0Hz.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Triangle_1.0Hz.wav -------------------------------------------------------------------------------- /src/test/gold/Triangle_1_to_5Hz.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Triangle_1_to_5Hz.wav -------------------------------------------------------------------------------- /src/test/gold/Triangle_2Hz.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Triangle_2Hz.wav -------------------------------------------------------------------------------- /src/test/gold/Wavefile_out1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Wavefile_out1.wav -------------------------------------------------------------------------------- /src/test/gold/Wavefile_out2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/Wavefile_out2.wav -------------------------------------------------------------------------------- /src/test/gold/filter_fir_band_pass.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/filter_fir_band_pass.wav -------------------------------------------------------------------------------- /src/test/gold/filter_fir_band_pass_dynamic.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/filter_fir_band_pass_dynamic.wav -------------------------------------------------------------------------------- /src/test/gold/filter_fir_band_reject.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/filter_fir_band_reject.wav -------------------------------------------------------------------------------- /src/test/gold/filter_fir_band_reject_dynamic.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/filter_fir_band_reject_dynamic.wav -------------------------------------------------------------------------------- /src/test/gold/filter_fir_high_pass.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/filter_fir_high_pass.wav -------------------------------------------------------------------------------- /src/test/gold/filter_fir_high_pass_dynamic.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/filter_fir_high_pass_dynamic.wav -------------------------------------------------------------------------------- /src/test/gold/filter_fir_low_pass.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/filter_fir_low_pass.wav -------------------------------------------------------------------------------- /src/test/gold/filter_fir_low_pass_dynamic.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/filter_fir_low_pass_dynamic.wav -------------------------------------------------------------------------------- /src/test/gold/filter_iir_band_pass.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/filter_iir_band_pass.wav -------------------------------------------------------------------------------- /src/test/gold/filter_iir_band_pass_dynamic.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/filter_iir_band_pass_dynamic.wav -------------------------------------------------------------------------------- /src/test/gold/filter_iir_band_reject.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/filter_iir_band_reject.wav -------------------------------------------------------------------------------- /src/test/gold/filter_iir_band_reject_dynamic.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/filter_iir_band_reject_dynamic.wav -------------------------------------------------------------------------------- /src/test/gold/filter_iir_high_pass.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/filter_iir_high_pass.wav -------------------------------------------------------------------------------- /src/test/gold/filter_iir_high_pass_dynamic.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/filter_iir_high_pass_dynamic.wav -------------------------------------------------------------------------------- /src/test/gold/filter_iir_low_pass.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/filter_iir_low_pass.wav -------------------------------------------------------------------------------- /src/test/gold/filter_iir_low_pass_dynamic.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weegreenblobbie/nsound/fde90e44f7c25d0f1ff15042410474d476567c5b/src/test/gold/filter_iir_low_pass_dynamic.wav -------------------------------------------------------------------------------- /src/test/test_DelayLine.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | $Id: test_DelayLine.py 904 2015-06-15 03:26:19Z weegreenblobbie $ 4 | 5 | Copyright (c) 2009 to Present Nick Hilton 6 | 7 | weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Library General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 | 23 | """ 24 | 25 | import unittest 26 | 27 | import Nsound as ns 28 | fn = ns.rel_to_abs 29 | 30 | class Test(unittest.TestCase): 31 | 32 | def test_01(self): 33 | "DelayLine stuff" 34 | 35 | dl = ns.DelayLine(1, 5) 36 | 37 | gold = [0.0] * 5 38 | gold.extend([0.0, 1.0, 2.0, 3.0, 4.0]) 39 | gold = [int(x) for x in gold] 40 | 41 | data = [] 42 | 43 | for i in range(10): 44 | 45 | x = dl.read() 46 | 47 | data.append(int(x)) 48 | 49 | dl.write(i) 50 | 51 | self.assertEqual(gold, data) 52 | -------------------------------------------------------------------------------- /src/test/test_FilterMedian.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Copyright (c) 2016 to Present Nick Hilton 4 | 5 | weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | 21 | """ 22 | 23 | import unittest 24 | 25 | import Nsound as ns 26 | 27 | class Test(unittest.TestCase): 28 | 29 | def test_01(self): 30 | "FilterMedian stuff" 31 | 32 | fm = ns.FilterMedian(3) 33 | 34 | b1 = ns.Buffer([1, 2, 3, 4, 5, 6, 7]) 35 | 36 | data = fm.filter(b1) 37 | 38 | gold = [1, 1, 2, 3, 4, 5, 6] 39 | 40 | # convert to int for comparison conviences 41 | data = [int(x) for x in data] 42 | 43 | self.assertEqual(gold, data) 44 | 45 | 46 | def test_02(self): 47 | "FilterMedian stuff" 48 | 49 | fm = ns.FilterMedian(3) 50 | 51 | b1 = ns.Buffer([6, 4, 2, 1, 7, 3, 5]) 52 | 53 | data = fm.filter(b1) 54 | 55 | gold = [6, 6, 4, 2, 2, 3, 5] 56 | 57 | # convert to int for comparison conviences 58 | data = [int(x) for x in data] 59 | 60 | self.assertEqual(gold, data) 61 | 62 | 63 | def test_03(self): 64 | "FilterMedian stuff" 65 | 66 | fm = ns.FilterMedian(4) 67 | 68 | b1 = ns.Buffer([6, 4, 2, 1, 7, 3, 5, 9, 4, 6, 2]) 69 | 70 | data = fm.filter(b1) 71 | 72 | gold = [6, 6, 6, 4, 4, 3, 3, 5, 5, 5, 5] 73 | 74 | # convert to int for comparison conviences 75 | data = [int(x) for x in data] 76 | 77 | self.assertEqual(gold, data) 78 | 79 | 80 | -------------------------------------------------------------------------------- /src/test/test_convolve.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: test_convolve.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2008-Present Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | #include 30 | 31 | #include "Test.h" 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | using namespace Nsound; 38 | 39 | using std::cerr; 40 | using std::cout; 41 | using std::endl; 42 | using std::flush; 43 | 44 | static const char * THIS_FILE = "test_convolve.cc"; 45 | 46 | int main(int argc, char ** argv) 47 | { 48 | AudioStream x("../examples/california.wav"); 49 | AudioStream h("../examples/walle.wav"); 50 | 51 | x.resample2(8000); 52 | h.resample2(8000); 53 | 54 | cout << TEST_HEADER 55 | << "AudioStream::getConvolve(x) ... " << flush; 56 | 57 | Tic(); 58 | 59 | AudioStream y = h.getConvolve(x[0]); 60 | 61 | float64 delta_t = Toc(); 62 | 63 | y.normalize(); 64 | y *= 0.6; 65 | 66 | cout << endl << "writing convolved2.wav ..." << flush; 67 | 68 | y >> "convolved2.wav"; 69 | 70 | cout << " done " << delta_t << " seconds" << endl; 71 | 72 | return 0; 73 | } 74 | 75 | 76 | -------------------------------------------------------------------------------- /src/test/test_granulator.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: test_granulator.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2002-2007 Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | 39 | using namespace Nsound; 40 | 41 | using std::cerr; 42 | using std::cout; 43 | using std::endl; 44 | using std::flush; 45 | 46 | int 47 | main(int argc, char ** argv) 48 | { 49 | Wavefile::setDefaultSampleRate(44100); 50 | Wavefile::setDefaultSampleSize(16); 51 | 52 | Granulator grains(44100, Granulator::GAUSSIAN_30); 53 | Sine sin(44100); 54 | 55 | Buffer grain_freqs; 56 | grain_freqs << 180; 57 | 58 | Buffer waves_per_grain; 59 | waves_per_grain << 2.0; 60 | 61 | Buffer grains_per_second = 1200 * sin.drawDecay(5.0); 62 | 63 | Tic(); 64 | cout << "gran.generate() ... " << flush; 65 | 66 | Buffer output(4096); 67 | 68 | output << 0.6 * grains.generate(5, grain_freqs, waves_per_grain, grains_per_second); 69 | 70 | cout << Toc() << " seconds" << endl << flush; 71 | 72 | output >> "grains.wav"; 73 | 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /src/test/test_mesh.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: test_mesh.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2008-Present Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | #include 30 | 31 | #include "Test.h" 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | using namespace Nsound; 38 | 39 | using std::cerr; 40 | using std::cout; 41 | using std::endl; 42 | using std::flush; 43 | 44 | static const char * THIS_FILE = "test_mesh.cc"; 45 | 46 | int main(int argc, char ** argv) 47 | { 48 | //~ for(int x = 3; x <= 19; x += 4) 49 | //~ { 50 | //~ for(float64 leak = 0.87; leak <= 0.99; leak += 0.06) 51 | //~ { 52 | //~ for(float64 tau = 0.005; tau <= 0.16; tau *= 2.0) 53 | //~ { 54 | //~ char buffer[1024]; 55 | //~ 56 | //~ sprintf(buffer, "mesh_x%02d_y19_leak%4.2f_tau%5.3f.wav", 57 | //~ x, 58 | //~ leak, 59 | //~ tau); 60 | //~ 61 | //~ cout << "writing " << buffer; 62 | //~ 63 | //~ Mesh2D mesh(44100.0, x, 19, leak, tau); 64 | //~ 65 | //~ Buffer hit = mesh.strike(0.25, 0.25, 1.0); 66 | //~ 67 | //~ Buffer output; 68 | //~ 69 | //~ output << hit << hit << hit; 70 | //~ output.normalize(); 71 | //~ 72 | //~ output *= 0.8; 73 | //~ 74 | //~ output >> buffer; 75 | //~ 76 | //~ cout << endl; 77 | //~ 78 | //~ } 79 | //~ } 80 | //~ } 81 | 82 | // sr x y leak tau 83 | Mesh2D mesh(44100.0, 11, 19, 0.88, 0.010); 84 | 85 | Buffer output; 86 | 87 | output << mesh.strike(0.333, 0.333, 3.0); 88 | 89 | output.normalize(); 90 | 91 | output >> "mesh.wav"; 92 | 93 | return 0; 94 | } 95 | 96 | 97 | -------------------------------------------------------------------------------- /src/test/test_moving_average.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: test_moving_average.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | //----------------------------------------------------------------------------- 6 | 7 | // Nsound headers 8 | #include 9 | 10 | using namespace Nsound; 11 | 12 | //----------------------------------------------------------------------------- 13 | int 14 | main(void) 15 | { 16 | float64 sr = 48000.0; 17 | 18 | Sine sine(sr); 19 | 20 | // Draw a pulse. 21 | Buffer input = sine.silence(0.25) 22 | << sine.drawLine(0.25, 1.0, 1.0) 23 | << sine.silence(0.25); 24 | 25 | input += sine.whiteNoise(0.75) * 0.25; 26 | 27 | input.plot("noisy input"); 28 | 29 | FilterMovingAverage fma(101); 30 | 31 | Buffer output = fma.filter(input); 32 | 33 | output.plot("filtered output"); 34 | 35 | Plotter::show(); 36 | 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /src/test/test_rng.cc: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: test_rng.cc 874 2014-09-08 02:21:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2009 to Present Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | #include 30 | #include "Test.h" 31 | 32 | #include 33 | #include 34 | 35 | using namespace Nsound; 36 | 37 | using std::cerr; 38 | using std::cout; 39 | using std::endl; 40 | using std::flush; 41 | 42 | //~static const char * THIS_FILE = "test_rng.cc"; 43 | 44 | int main(int argc, char ** argv) 45 | { 46 | RngTausworthe rng; 47 | 48 | for(uint32 i = 0; i < 100; ++i) 49 | { 50 | cout << rng.get(0, 10) << endl; 51 | } 52 | 53 | return 0; 54 | } 55 | 56 | 57 | -------------------------------------------------------------------------------- /swig/AudioPlaybackRt.i: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: AudioPlaybackRt.i 912 2015-07-26 00:50:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2009 to Present Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | 30 | %feature("shadow") Nsound::AudioPlaybackRt::_swig_shadow() 31 | %{ 32 | 33 | #------------------------------------------------------------------------------ 34 | # from swig/AudioPlaybackRt.i 35 | # 36 | def __lshift__(self, rhs): 37 | self.play(rhs) 38 | 39 | def __rshift__(self, rhs): 40 | self.play(rhs) 41 | 42 | def __str__(self): 43 | return "Nsound.AudioPlaybackRt(): %s\n%s" % (self.getInfo(), self.debug_print()) 44 | 45 | __repr__ = __str__ 46 | 47 | # 48 | #------------------------------------------------------------------------------ 49 | 50 | %} 51 | 52 | // :mode=python: 53 | -------------------------------------------------------------------------------- /swig/Plotter.i: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // $Id: Plotter.i 912 2015-07-26 00:50:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2009 to Present Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | //----------------------------------------------------------------------------- 10 | 11 | //----------------------------------------------------------------------------- 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | //----------------------------------------------------------------------------- 28 | 29 | 30 | %feature("shadow") Nsound::Plotter::_swig_shadow() 31 | %{ 32 | 33 | #------------------------------------------------------------------------------ 34 | # from swig/Plotter.i 35 | # 36 | def show(): 37 | try: 38 | matplotlib.pylab.show() 39 | except: 40 | pass 41 | 42 | show = staticmethod(show) 43 | # 44 | #------------------------------------------------------------------------------ 45 | 46 | %} 47 | 48 | // :mode=python: 49 | -------------------------------------------------------------------------------- /swig/ignored.i: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // $Id: ignored.i 912 2015-07-26 00:50:29Z weegreenblobbie $ 4 | // 5 | // Copyright (c) 2009 to Present Nick Hilton 6 | // 7 | // weegreenblobbie2_gmail_com (replace '_' with '@' and '.') 8 | // 9 | /////////////////////////////////////////////////////////////////////////////// 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | // 13 | // This program is free software; you can redistribute it and/or modify 14 | // it under the terms of the GNU General Public License as published by 15 | // the Free Software Foundation; either version 2 of the License, or 16 | // (at your option) any later version. 17 | // 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU Library General Public License for more details. 22 | // 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program; if not, write to the Free Software 25 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 | // 27 | /////////////////////////////////////////////////////////////////////////////// 28 | 29 | %ignore Nsound::AudioStream::operator=; 30 | %ignore Nsound::AudioStream::operator[]; 31 | %ignore Nsound::AudioStreamSelection::operator=; 32 | %ignore Nsound::Axes::operator=; 33 | %ignore Nsound::Buffer::begin; 34 | %ignore Nsound::Buffer::end; 35 | %ignore Nsound::Buffer::operator=; 36 | %ignore Nsound::Buffer::operator[]; 37 | %ignore Nsound::BufferSelection::operator=; 38 | %ignore Nsound::BufferWindowSearch::operator=; 39 | %ignore Nsound::circular_iterator::operator=; 40 | %ignore Nsound::circular_iterator::operator++; 41 | %ignore Nsound::circular_iterator::operator--; 42 | %ignore Nsound::const_circular_iterator::operator=; 43 | %ignore Nsound::const_circular_iterator::operator++; 44 | %ignore Nsound::const_circular_iterator::operator--; 45 | %ignore Nsound::CircularBuffer::operator=; 46 | %ignore Nsound::EnvelopeAdsr::operator=; 47 | %ignore Nsound::FFTChunk::operator=; 48 | %ignore Nsound::FilterAllPass::operator=; 49 | %ignore Nsound::FilterCombLowPassFeedback::operator=; 50 | %ignore Nsound::FilterDelay::operator=; 51 | %ignore Nsound::FilterFlanger::operator=; 52 | %ignore Nsound::FilterIIR::operator=; 53 | %ignore Nsound::FilterLeastSquaresFIR::operator=; 54 | %ignore Nsound::FilterMovingAverage::operator=; 55 | %ignore Nsound::FilterPhaser::operator=; 56 | %ignore Nsound::FilterStageIIR::operator=; 57 | %ignore Nsound::Generator::operator=; 58 | %ignore Nsound::Granulator::operator=; 59 | %ignore Nsound::Hat::operator=; 60 | %ignore Nsound::Mesh2D::operator=; 61 | %ignore Nsound::Plotter::show; 62 | %ignore Nsound::ReverberationRoom::operator=; 63 | %ignore Nsound::RngTausworthe::operator=; 64 | %ignore Nsound::Spectrogram::operator=; 65 | %ignore Nsound::Stretcher::operator=; 66 | 67 | // :mode=c++: 68 | -------------------------------------------------------------------------------- /swig/typemaps.i: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // 3 | // This program is free software; you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation; either version 2 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU Library General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with this program; if not, write to the Free Software 15 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 | // 17 | //----------------------------------------------------------------------------- 18 | 19 | // Return a bytearry from binary string. 20 | %typemap(out) Nsound::bytearray 21 | { 22 | // %typemap(out) Nsound::bytearray (C++ to Python) 23 | 24 | $result = PyByteArray_FromStringAndSize($1.c_str(), $1.size()); 25 | } 26 | 27 | 28 | // Return a binary string from bytearray. 29 | %typemap(in) (const void * data, std::size_t size) 30 | { 31 | // %typemap(in) (const void * data, std::size_t size) (Python to C++) 32 | $1 = PyByteArray_AsString($input); 33 | $2 = PyByteArray_Size($input); 34 | } 35 | 36 | // :mode=python: 37 | --------------------------------------------------------------------------------