Exporting sounds as WAV files - wolfram-mathematica

I never worked too much with sounds in Mma.
I have
t = Sound[List["Violin",SoundNote[-6]]]
How could I Export t as a .WAV file?
When I try the obvious
Export["c:\\test.wav",t]
I get
In this old thread Szabolcs said that it can't be done. Perhaps things have improved since 2007!

I think that it still can't be done. Mathematica supports creating and modifying MIDI objects, but leaves the sound generation from the midi to the underlying operating system. For now, you'll have to export to midi then use the midi interface on your system or an online service to convert to a sampled sound format.
For example (from the documentation)
t = Sound[SoundNote[DeleteCases[3 Range[31] Reverse[#], 0] - 48, .1] & /#
Transpose[CellularAutomaton[90, {{1}, 0}, 30]]]
Export["test.mid", t]
Uploaded to http://free-midi-converter.com/Midi/Create gives the link.
It can also be converted with TiMidity which is available on all major operating systems with the command (assuming you've run the above)
Run["timidity test.mid -Ow -o test.wav"]
which can be imported back into Mathematica using Import["test.wav"].
This conversion can be automated if need be...
Apparently VLC can also convert midi to wav, which might be an easier option for some propriety operating systems! See also the options given here.

Related

overlay one pdf with another from the command line: pdftk alternative?

I use a bash script to auto-generate a pdf calendar each month.I use the wonderful remind program as the basis for this routine. Great as are the calendars I get using that program, I need a more detailed header for the calendar (than just the name of the month and the year). I couldn't puzzle out a way to get the remind program to enhance the header, but I was able to get the enhanced results I wanted by creating a second pdf containing the header enhancements I need, then overlaying that pdf onto the calendar I produce with remind, via the pdftk utility (pdftk calendar.pdf stamp calendar_overlay.pdf output MONTH-YEAR-cal.pdf). Unfortunately, I recently lost the ability to use pdftk since keeping it on my system would necessitate me ceasing to do other system updates. In short, I had to remove it in order to continue updating my system.
So now I'm looking for some alternative that I can incorporate into my bash script. I am not finding any utility that will allow me to overlay one pdf with another, like pdftk allows. It seems I may be able to do something like what I'm after using imagemagick (-convert), though I would likely need to overlay the pdf with an image file like a .jpg rather than with a pdf. Another possible solution may be to use TeX/LaTeX to insert text into the pdf as described at https://rsmith.home.xs4all.nl/howto/adding-text-or-graphics-to-a-pdf-file.html.
I wanted to ask here, before investing a lot of time and effort into pursuing one or other of the two potential options I've identified, whether there is some other way, using command line options that can be incorporated into a bash script, of overlaying one pdf with another in the manner described? Input will be appreciated.
LATER EDIT: another link with indications how to do such things using LaTeX https://askubuntu.com/questions/712691/batch-add-header-footer-to-pdf-files
Assuming for simplicity that both of your files are of size 500pt x 200pt,
you can use pdfjam with nup and delta options to trick it into overlaying your source pdf files.
pdfjam bottom.pdf top.pdf --outfile merged.pdf \
--nup "1x2" \
--noautoscale true \
--delta "0 -200pt" \
--papersize "{500pt, 200pt}"
Unfortunately, I've found in my tests that I needed to increase the y delta by one point to get perfect alignment.
pdftk-java is a Java-based port of pdftk which looks to be actively in development. Given that its only real requirement appears to be Java 7+, it should work even in environments such as your own that no longer support the requirements of pdftk, so long as they have a Java runtime installed.

jFugue Saving MIDI Files While Still Including Loaded Instruments

I am using an external soundfont to play MusicStrings and everything is working find. When I use player.saveMidi(etc, etc) the files are saved with the original MIDI soundfont.
Soundbank soundbank = MidiSystem.getSoundbank(new File("SGM-V2.01.sf2"));
Synthesizer synth = MidiSystem.getSynthesizer();
synth.open();
synth.loadAllInstruments(soundbank);
Player player = new Player(synth);
Pattern pattern = new Pattern("C5majw C5majw C5majw");
player.play(pattern); // works fine with external soundbank
player.saveMidi(pattern, filename); //Doesn't save with external soundbank instruments
Is there any workaround or built in feature that supports this functionality?
Thanks!
Keep in mind that MIDI is a set of musical instructions. Regardless of whether you load a soundbank into the Java program, when you save as MIDI, you're only saving musical instructions. (By "musical instructions", I mean things like "NOTE ON" or "INSTRUMENT CHANGE" but not actual musical sound data)
It sounds like what you want to do is render your music into a WAV file using the sounds from the soundbank that you have loaded. To do this, you'll want to use the Midi2WavRenderer available here: http://www.jfugue.org/code/Midi2WavRenderer.java

How to convert .epsf to .eps?

I'm looking for a method of converting .epsf to .eps for a publication I'm submitting. The submission site requires .eps (even though my understanding is that modern renderers should be able to read .epsf as well - the site is archaic, I have to upload all 100 images individually.) My co-author sent me the zipped files to upload (and now to convert) - I didn't make them myself. Further, the programs that made these images may exist on my co-authors computer but where is uncertain.
I've tried this in Mathematica 8 to reasonable but not full success - as in colored files become black and white, files with duplicate entries (as in Fig11a.eps and Fig11a.epsf both exist though they are different, it seems that the .eps is the background and the .epsf is the foreground layer) convert incorrectly. My attempt was to import the .epsf files to Mathematica and export them as .eps.
Also, I've using a middle man format - e.g. gif/tiff/png/jpg - with similar results. I haven't been able to find a program that's free (I assume photoshop could pull this off) that I could use - also I'd like to do it as a batch. A method that uses requires python/Mathematica or XP/Linux OS's would be fine. Thanks.
You do not need to convert anything. Encapsulated PostScript files can have both extensions (both EPS and EPSF). If you publisher refuses to accept files with an EPSF extension just rename them to EPS.
Any processing/conversion you do on the files (using GhostScript, Mathematica, etc.) carries the risk of corrupting the graphics in some way. But there's no need to do it. Send them as they are or rename them if you prefer.
(If you have any doubt, you can check the EPS Format Specification from 1992 which says that on the Macintish the recommended file extension is .epsf while on DOS it's .EPS)

Control AudioUnits from the command line?

Is there any software for the make which offers command line (or other scripting) utility to modify AudioUnit parameters?
The use case is this:
Default (Built-In) input
Attach better Gain Control
AudioUnit (the default OS-X gain
control is inadequate)
Attach L-R balance control (or
"pan")
Pass-through (link) to Default
Output a.k.a. LineIn.app
Script control of AudioUnit 2).
For a 0-100% volume control of the
input audio. In 1/16 increments
(6.5%) just like the main volume in
OS-X.
Script control of AudioUnit 3)
for L-R balance (pan) control.
The problem here for me is at steps 5 and 6.
Steps 1) through to 4) can be adequately achieved graphically in AudioHijackPro. The pass-through, and audio units can be created in there. It also comes with a really good gain control dial / knob. However all those effects are set exclusively through the GUI interface.
Desperately searching for a command-line tool (or "audiounit host") which can set the parameters values and send them to these audio units with the set parameter C api function(s).
Do any existing tools on the Mac offer this kind of functionality?
It sounds like you want Triumph. It can't be controlled from the command line but it is Applescript-able.
Spotify's Pedalbord is a Python library that can apply AU plugins:
https://github.com/spotify/pedalboard
With Fire, it's trivial to turn any Python script into a CLI tool:
https://github.com/google/python-fire

(fluxus) learning curve

I'm trying to have some fun with fluxus, but its manual and online docs all seem to assume that the reader is already an expert network programmer who's never heard of Scheme before. Consequently, you get passages that try to explain the very basics of prefix notation, but assume that you know how to pipe sound-card data into the program, or setup and connect to an OSC process.
Is there any tutorial out there that goes the opposite way? IE, assumes that you already have a handle on the Lisp/Scheme thing, but need some pointers before you can properly set up sound sources or an OSC server?
Barring that, does anyone know how to get (for example) the system microphone to connect to (fluxus), or how to get it to play a sound file from disk?
To get the system microphone to connect to fluxus you need a software to comunicate and take the data in your audio card, like jackpilot http://www.jackosx.com/about.html
Once you have installed in your computer (mac in this case):
go to system preferencies/audio... in audio IN, you need to select your microphone
strart jackpilot
in jackpilot preferences configure audio IN to microphone too
put in buffer size 1024, and sample rate 44100
save (jackpilot) and click run
open fluxus
try this little code
(clear)
(start-audio "" 1024 44100)
(define (something)
(rotate (vector (gh 0) (gh 5) (gh 15)))
(draw-cube)
)
(every-frame (something))
If you need the same info in linux, tell me.
If you need to do the same on windows... windows do not have audio support.
I hope this info works for you.

Resources