Hot answers tagged sound
18
A lot depends on your specific data. But if the noise is far from voice in frequency domain there is a simple brute-force trick of cutting off/out "bad" frequencies using wavelets. Let's import some sample recording:
voice = ExampleData[{"Sound", "Apollo11ReturnSafely"}]
WaveletScalogram is great for visualizing voice versus noise features:
cwt = ...
18
Edit: this answer is now structured in two sections. The first deals about creating a candidate RNG from audio data. The second demonstrates some testing I performed on this RNG.
Creating the RNG
Okay, I'll got at it another way then. I recorded 10 seconds of ambient noise on my MacBook Pro internal speakers. I was possibly in the worst conditions for ...
16
Here's a possible starting point for a solution. It splits the sample list into chunks and measures the Norm of the sample Differences in each chunk, and then does the FFT on that data.
bpmplot[snd_, bpmmax_: 300] :=
Module[{samples, minfreq, signal, fft},
samples = snd[[1, 1, 1]];
minfreq = snd[[1, 2]]/Length[samples];
signal = (Norm[Differences[#]]) ...
16
Running Trace[Speak["Hello"]] and Names["*Speak*"] revealed the following possibility:
MathLink`CallFrontEnd[CurrentlySpeakingPacket]
Using this with a text that is split into a list of shorter strings allows you to interrupt the audio at well-defined points, phrase breaks, say. Here is one way to do it:
Clear[interruptibleSpeak];
...
12
In Mathematica it is easy to turn any time series data into sound. Here are the Boston temperatures for a few decades:
data = WeatherData["Boston", "MeanTemperature", {{1970}, {2012}, "Day"}];
DateListLogPlot[data, PlotStyle -> PointSize[0], AspectRatio -> 1/5]
To turn it into sound and play it in a Mathematica notebook:
ListPlay[data[[All, 2]], ...
12
Due to security restrictions some functions such as Import, Uncompress, or OS access functions cannot be used as a part of Demonstrations code, including the Initialization. So a generally great idea by @acl comment about compression will not work on Demonstrations site (but it's really ncie to use otherwise). This is what you get if you try to use ...
12
vid[time_, frame_] := Module[{tag},
Reap[Do[Sow[CurrentImage[], tag];
Pause[frame], {Round[time/frame]}]][[2, 1]]]
So, vid[1., 0.001] would return a list of snapshots taken every 0.001 seconds over a second.
This opens a dialog that allows you to record sound and returns it as a Sound object
SystemDialogInput["RecordSound"];
12
Here is my quick and dirty attempt based on: Cryptographic Key From Webcam Image. I've used an example image as I don't have a webcam on my desktop but you could simply use CurrentImage to grab the webcam image live if you have one.
Update using a webcam image from my laptop
image = CurrentImage[];
grayscale = ColorConvert[image, "Grayscale"];
imagedata = ...
11
You want this:
data = Import["test.wav", "Data"]
This imports the raw data of sample values. For example, on a test file of approximately 10 seconds, stereo at 48000 Hz, data is an array of size 2 × 520192 (from which I can deduce that my recording was actually 10.84 seconds).
See the documentation for WAF format import/export, as well as this answer on ...
10
What you need is BandpassFilter, which is new in version 9. Assuming your audio is sampled at 22400 Hz, you can do:
BandpassFilter[data, {60 π, 180 π}, SampleRate -> 22400]
to filter it to between 60-180 Hz.
10
You can use CurrentImage and set up a ScheduledTask to capture frames at the desired fps. Something like:
frames = {};
fps = 30;
task = CreateScheduledTask[frames = {CurrentImage[], frames};, 1/fps];
Then start and stop recording with
StartScheduledTask[task];
StopScheduledTask[task];
Note that stopping the task won't turn off the camera on a Mac ...
9
I feel there may be a few issues here. First, you're using FourierDST, the discrete sine transform. I'm not too familiar with this one, but it looks like you shouldn't confuse it with Fourier.
Application of FourierDST as follows:
ListLinePlot[
FourierDST[Table[Sin[100 t], {t, 0, 10, 0.02}]][[250 ;; 350]],
PlotRange -> All]
yields:
whereas, with ...
6
This example in Documentation exactly answers your question. You just need to specify overlapping time intervals. Lets expand your specific case. Below after every second a new instrument will come in and they will all end at the same time.
Sound[{SoundNote["C", {0, 4}, "Oboe"],
SoundNote["G", {1, 4}, "SynthVoice"],
SoundNote["C5", {2, 4}, ...
6
You can simply put the results in a list and apply Sound to the list. An example taken from the docs:
Sound[{Play[Sin[1000 t (1 + t^2)], {t, 0, .2}], Play[Sin[500 t (1 + t^3)], {t, 0, .5}]}]
You can then export this Sound object.
6
This function is still present in version 8, but it is part of the Audio` package. For example,
<<Audio`
ListWaveform[{{1, 1}, {2, 0.5}}, 440, 1]
You can find this information by typing ListWaveform into the documentation browser.
6
Here is another possibility based on mouse movements, updated with live histogram, further updated by hashing a combination of the mouse position and AbsoluteTime:
DynamicModule[{},
positionlist = {};
list = {};
EventHandler[{Dynamic[
Framed@Graphics[{Red, Line@positionlist, Point@positionlist},
PlotRange -> 2]],
...
6
Read in the wave file (use Import). Then use the Fourier[]function. This breaks it into a sum of complex exponentials. You can turn this into a trigonometric series using Euler's formula. Here's a bit more detail.
Reading in the .wav file is easy:
q = Import[fullFileName];
Now q has two parts: the data in q[[All,1]] and the sampling rate in q[[1,2]] ...
6
It shouldn't be too hard to do some simple sound processing. Take an example file:
data = ExampleData[{"Sound" , "Apollo13Problem"}]
Get a short sequence of sample values from near the end of the file:
soundsamples = data[[1, 1]][[All, 110000 ;; -2000]];
It looks OK:
ListLinePlot[{soundsamples[[1]]}]
Play it without modifications:
...
5
Here is a letter I got regarding this question from premier service technical support:
Thank you for taking the time to send this in. Unfortunately, I do not
believe this functionality currently exists in Mathematica and I have
forwarded the suggestion that it be included in a future release of
Mathematica to the developers in charge of this area.
...
5
Let's take an example of WAV sound data:
data=Import[ "ExampleData/rule30.wav"]
You can see sampling rate 44100 Hz and duration 1.8 s of your sample. This function extracts data for a specific time duration:
TakeSound[d_, s_, e_] := {d[[1, 1, 1, Round[44100 s] ;; Round[44100 e]]]}
And this app allows you to cut and play sub-samples of your data:
...
5
This is one way to control the sound emission. Import a short .WAV file:
sound = Import[ "ExampleData/rule30.wav" ]
Now make sound only when your animation control reaches some value - k=0 or k=1 in this case:
Animate[If[k == 0 || k == 1, EmitSound[sound]];
Plot[k*x^2, {x, -2, 2}, PlotRange -> {{-2, 2}, {-10, 10}}],
{k, -2, 2, 0.1, AnimationRate ...
5
This answer addresses some of your question, which is actually fairly broad and I think touches as much on the underlying concepts as on how to use Mathematica to achieve the stated goal.
This will answer:
How to import a wav file as samples
How to get the discrete Fourier transform normalized to give expected magnitudes
How to get a range of frequencies
...
5
The answer was already given by Xerxes. It is a limitation of MIDI, which only supports 16 channels. That Mathematica really uses MIDI is described in the docs. For instance in the tutorial The Representation of Sound:
At the lowest level, all sounds in Mathematica are represented as a sequence of amplitude samples, or as a sequence of MIDI events.
4
Here's mine:
-first create a scale by dividing an octave to some intervals (12 gives you the usual good temperament):
microscale[divisions_Integer, baseFreq_: 260.741] :=
Module[{interval},
interval = 2 π /divisions;
Play[#, {t, 0, .4}] & /@ Table[Sin[(2 π + i) baseFreq t], {i, 0, 2 π, interval}]
];
which you can use like so: ...
4
The key to getting separate sounds to join smoothly is to make the waveform continuous. For example this sound contains an integer number of cycles, and we can emit a sequence of these with no audible gaps:
testsound=Sound[SampledSoundFunction[Sin[0.4Pi #]&,1000,8000]];
Do[EmitSound[testsound],{5}]
Contrast with this next one, where I have adjusted ...
4
You can produce an identical signal by using UnitBox instead of HeavisidePi:
aNote[x_] := Sin[440*2*Pi*x];
unv[x_] := UnitBox[x - 1] + UnitBox[x - 2.5];
Play[unv[x] aNote[x], {x, 0, 3.5}]
Use UnitStep and Piecewise for more sophisticated functions.
Not sure, but maybe the reason for your trouble is that HeavisidePi does not evaluate at 1/2:
...
3
Sonic Visualiser is a point and click interface for all sorts of audio tasks, from analysis, filtering, beat detection, etc. You should play around with it (does take some getting used to) and download the freeware plugins too.
Once you get the hang of it, you might want to try Sonic Annotator, which is, I believe, just a text based interface to Sonic ...
3
The basic idea is to install a virtual MIDI device software on your Mac and change the system default MIDI output to that virtual device. Mathematica will play into it, and the device can at the same time function as a MIDI input for Logic/GarageBand.
http://www.johanlooijenga.com/tools/5-apps/12-virtual-ports.html
It would be easier if you could change ...
3
Try Export["~/Desktop/test.txt", Compress@sound] and in = Uncompress@Import["~/Desktop/test.txt"]. The way you did it, it gets imported as a string. There's other ways, but the one I present is what I always use to export/import arbitrary data structures: it's cross-platform and robust (as far as I can tell).
Regarding the second example and the comments:
...
3
The 4th line needs correction:
in = Import["test.txt", "Data"] // Flatten
Now it will work - you need to read up on import/export of data on Documentation. This is fixes your specific code. But there are many ways to do this. For example to use "test.dat" format is better (no "Data" specification needed in Import). Or exporting sound itself (not the data) ...
Only top voted, non community-wiki answers of a minimum length are eligible



