Message Boards Message Boards

Play any sound, i.e: piano type sound, at any desired frequency?

GROUPS:

Hi all, Please kindly let me explain further on this: All the software I have seen in the web for playing sounds seems to be always restricted to the musical ratios (musical notes) defined by any of the existing musical scales. However, I need to make a chord with any number of string-type sounds, so that I could assign any arbitrary frequency to each of them, frequencies choosen at will (not related to any existing musical scale).

Could someone tell me if there are any mathematica commands I could use, or any other way to do so.

enter image description here

Many thanks in advance for your help, indeed Best regards,

POSTED BY: Domingo Gomez Morin
Answer
9 months ago
Play[Sin[256*2 \[Pi] t] + Sin[1.25*256*2 \[Pi] t] + 
  Sin[1.5*256*2 \[Pi] t] + Sin[2*256*2 \[Pi] t], {t, 0, 1}]
POSTED BY: Frank Kampas
Answer
9 months ago

Hi Frank, It seems I didn´t explain my point as I should. I didn´t ask for sine-type waves.
I am looking for arbitrary chords using string-type sounds (piano, violin, guitar) at any frequency. That is, chords that do not follow the ratios of the musical notes of any existing musical scale. The frequencies of the sounds must be choosen at will directly using Herzt units (not musical notes).

So to do so, I would need either the wave equation for simulating the string-type sound along with the Play Command, or any existing mathematica program code (or commands). Got it? Many thanks in advanced for any help on this matter. I have been struggling on this for some time and I am frankly frustrated, I am not quite sure if mathematica has any synthesizer code that could help, or if there is any other synthesizers out there that could do the job.

The mathematica command SoundNote does not do the job, it only works with the frequencies of musical notes, not with any frequencies chosen at will

POSTED BY: Domingo Gomez Morin
Answer
9 months ago

Often these complex instrument sounds consist of the fundamental and a set of harmonics at amplitudes related to that of the fundamental. So one approach to simulating such sounds is to determine these additional components, either through available writings or by Fourier analysis of examples. Then you could write a function which accepts a fundamental frequency and outputs a sum of notes representing the full set of components. The fundamental could then be any frequency, not just those of standard notes.

POSTED BY: David Keith
Answer
9 months ago

The Mathematica Command SoundNote uses internal functions to develope those complex sounds, however, to my disgrace mathematica does not show those special functions and the command only uses the frequencies of known musical notes. Besides, the point is that I am not making a research on how to construct those string-type sounds but on analysing chords of string-sounds at any chosen frequency, so I guess somewhere I could finally find those functions instead of trying to contruct them by myself which no doubt would be a so hard task.

POSTED BY: Domingo Gomez Morin
Answer
9 months ago

I suspect that you'll have to add the harmonics yourself to reproduce a given sound, if you want it at any frequency.

POSTED BY: Frank Kampas
Answer
9 months ago

SoundNote[] uses standard MIDI. By default, the pitches are Equal temperament, A = 440 hz. The MIDI standard allows you to alter the pitch, but I have found no (easy) way to do this.

MIDI should be an obsolete standard, mostly because it defaults to Western, equal tempered scales, which is really appropriate for Western (Eutorpean) music since 1760 or so. (Bach's Well-Tempered Clavier was written to exhibit the utility of a well-tempered scale, not equal temperament.) Indian, Chinese, and older Western Music (e.g. Baroque and Renaissance and before) use different scales.

Looking at the new audio functionality is on my list of things to do. I haven't checked this out, but you might be able to create an audio entity using SoundNote[], specifying the instrument, and then manipulate the pitch using AudioPitchShift[]. If that works, then you could wrote a function that would wrap up the code and have as an input one of the various MIDI instruments.

POSTED BY: George Woodrow III
Answer
9 months ago

Many thanks George, interesting, I'll try this one. I am desperately looking to achieve this, because it also deals with a math research I am working on. It seems to be a choice, let's see...

p.d. By the way, pretty nice your wolfram demonstration on linear equations system

POSTED BY: Domingo Gomez Morin
Answer
9 months ago

Thinking about this some more. For a continuous note, such as made by a violin or trumpet, it may be sufficient to know the harmonics and their amplitudes relative to the fundamental. That would not include non-continuous components, for example the sound of the trumpet note being initiated. However, for struck or plucked instruments, such as guitar or piano, we would want in addition to know a decay rate for the fundamental and each harmonic. Then a sampled sound list could be constructed from the fundamental.

I tried to do this for the midi sound for a guitar as produced by Mathematica by first analyzing the sound for the harmonics. But I found that many of the tools would not work. I saw no way to just get a simple list of sample amplitudes. I tried to use Periodogram, but it was not clear that the partition option could be used to get the spectral component values at a set of time-delayed windows, for fitting to exponential decays. Of course this is just about getting the characteristic -- I could record a guitar and analyze the result.

So I tried George's suggestion. I could indeed shift the frequencies of a 5 sec guitar note (E2). But when I compare the result of shifting E2 by 2x (1 octave) and E3, they are not the same pitch. I insert an image, since I am sure the boxes would be a mess as code:

enter image description here

POSTED BY: David Keith
Answer
9 months ago

this is getting quite interesting...

POSTED BY: Domingo Gomez Morin
Answer
9 months ago

It seems, you need to previously convert the sound into an audio file, that's the meaning of the command AudioPitchShift

POSTED BY: Domingo Gomez Morin
Answer
9 months ago

at this point, another important question emerges:

The shift factor used in the audiopitchshift is an arbitrarily chosen numerical factor, or is it a restrictive musical ratio (semitone units)?.

If the later then this shifting is definitely not an option to follow. The chords need to be totally free from any pre-established ratios.

POSTED BY: Domingo Gomez Morin
Answer
9 months ago

According to the documentation, you can use any ratio. There are ways of adjusting the pitch by multiples of semitones, but you don't need to do this.

This 'technique' is a bit of a hack. What we really want to do is to use AudioGenerator with a suitable envelope (model). The documentation lists several models that are built-in. One promising one is to use a Time Series. You could create a function that would duplicate the harmonics and decays of any arbitrary sound. This is non-trivial, of course.

As I said, this is on my list of things to do.

POSTED BY: George Woodrow III
Answer
9 months ago

Well, many thanks to all of you for your comments. I'll try to find function by myself, it is a hard task, but it seems there is no other way.

Best Regards

POSTED BY: Domingo Gomez Morin
Answer
9 months ago

I suggest that you send Wolfram a suggestion that AudioGenerator should accept instrument names ("Piano") as well as standard waveforms ("Sawtooth"). I'm pretty sure that this is possible -- hard for us, but perhaps not so much for the developers.

If they can do this, then Wolfram Language would have a shot at replacing General MIDI as a more flexible and general music generator.

The more people who suggest this, the more likely it will happen.

POSTED BY: George Woodrow III
Answer
9 months ago

Excelent suggestion. Many thanks for your help,

POSTED BY: Domingo Gomez Morin
Answer
9 months ago

Now, I think I finally did it, and I am enjoying it a lot ¡¡¡ <strong>

The name of this application is: FREE MUSIC, FREE SOUNDS ¡¡¡ As all we know, almost all synthetizers are restricted to the use of just the well-known musical notes, as a consecuence, if I want to make some research on consonance, then I have to restrict my investigation to the musical tones imposed by musicians and their sacred musical scales, no pun intended, indeed, because musical scales became kind of sacred religion.

The main objective of this mathematica app is TO FREE MUSIC AND SOUNDS from the chains of such an ancient musical theological-dictatorship. :-) :-)

Using dynamic input variables, piecewise funtions and Manipulate rutine, this app allows to play chords of up to 6 notes, assigning any frequency value to each note, at will, without any musical scale restrictions at all. **Besides, you can assign up to 12 harmonics amplitude values to each note in order to get any desired pitch. The harmonics can be edited at any time for each sound, and saved for further playing or chord inclusion.**

At the botton of the console there are four buttons with pre-assigned harmonic values to simulate guitar, piano, flute and violin pitchs. By this time, only the guitar pitch is fully functional (it took me a lot of work to make the guitar harmonics-table using an Spectrum Analyzer, as well as the interpolating functions to embrace all the proper harmonics at any frequency level) However, I hope to do the same task for the other pitchs: piano, flute and violin, very soon.

Each sound can be saved and played at any time ( 'Play Sound' button at right), besides any sound can be added to the chord at will. The attached image shows the chord of just two sounds: 110 and 220 hertz assigned to the chord which can be played using the 'Play Chord' Button at right.
A plot of all the waves added to the chord is included at the right bottom of the console, by adjusting che Chord Duration you will be able to see the resulting wave form. In this way, the sound play time and the chord play time can be adjusted at will.

Attack Decay Sustain and Release for each sound can be also adjusted. All the harmonics have the same attack-dcay-sustain-realease values (In the future I hope to have the time to improve this). The harmonics scale can be also adjusted. Apart from the 12 harmonics, the app includes various waveforms: square, triangle, bessel, fractional, riemann.

I am enjoying so much this app, however, I only regret two issues: 1.- Considering that it took me a lot of work and even when I would like to publish this app in the web to be freely used, I am not willing to send this app to wolfran to be considered for publication as a demonstration app, specially because there are no guarantees and it could finally get not published at all. I understand there is no way to make an independent executable file.

2.- The Play function is too slow when using my piecewise functions, mainly when the sound and chord duration are >1. Thus, even using a low-samplerate value (4000), each time you change any value the Play function took about 3 or 4 seconds to update. I understand this is well-known problem with mathematica play button and piecewise functions.

Well, that's it, I only wanted to share all this, of course, if someone wished to share some thoughts, ideas or even construct and play some special chords, I will be happy to do them for you. I would also appreciatte any feedback on the guitar pitch I got using an spectrum analyzer. I am a civil engineer with some background on dynamical and numerical analysis, so all this wave-stuff is of so much interest to me. You can find me in the web and youtube with my full-name Best regards, Domingo Gomez Morin

POSTED BY: Domingo Gomez Morin
Answer
6 months ago

Could you please share the code?

POSTED BY: Vitaliy Kaurov
Answer
6 months ago

Ok, I'll try to send it to wolfram demonstrations project.

POSTED BY: Domingo Gomez Morin
Answer
6 months ago

In the mean time, if you are willing to check the code and make some suggestions to improve this project, please kindly let me know your email address and I will send to you the whole code.

enter image description here

My webpage is: https://domingogomezmorin.wordpress.com

POSTED BY: Domingo Gomez Morin
Answer
6 months ago

As promised, I am attaching an image of the console (Manipulate output) and the source code (.txt file) of the new project: 'FREE MUSIC, FREE SOUNDS' SYNTHESIZER

Just copy an paste the code of the .txt file into mathematica, and run.

Please also kindly read the text included at the top of the code and share any ideas, harmonics database, and comments on this project. Remember, this is a new open project.!

Best regards, https://domingogomezmorin.wordpress.com

enter image description here

Attachments:
POSTED BY: Domingo Gomez Morin
Answer
6 months ago

This is great! Is there a reason you did not attach the notebook itself but a .TXT file?

POSTED BY: Sam Carrettie
Answer
6 months ago

No, it is just that I was trying to paste the code directly into the screen (I didn't notice there is a button for uploading files but just for images), so I previously converted it to a .txt file. Later I realized the button was there.

By the way, the number of sound buttons of this app could be increased and they could be arranged as piano keys icons, or guitar string icons. I hope to see people contributing to this open project, mainly on improving the time response of the PLAY command.

POSTED BY: Domingo Gomez Morin
Answer
6 months ago

It would be great if mathematica could improve the time response for the PLAY command when using functions.

I know that by previously using the table command the time response is reduced, however I didn't find the way to use that in this dynamic case, I just have to directly use large piecewise functions within the play command.

I am attaching again the SYNTHESIZER code with some minor changes, just copy the contents, paste and run.

Attachments:
POSTED BY: Domingo Gomez Morin
Answer
6 months ago

In this synthesizer the harmonics for simulating musical-instrument timbre are calculated using interpolating functions and the avalilabe harmonics-data of current musical notes. The manipulate routine could be improved using AudioGenerator

We do agree, calculating the harmonics this way for the guitar timbre is a crude approximation, however, if you have in mind experimenting with some particular frequencies, then you should find the real harmonics by using a real musical instrument and a spectrum analyzer.

I made the database of up to 21 harmonics for all the equal-temperament notes, however, I thought it was far enough to use 12 harmonics in this synthesizer.

I think, at this point, I must made the following remark: Even considering those delays in the Mathematica Play command, no other software allows you to do things like this, I think all this a great.

Mathematica is a truly powerful tool of liberation.

POSTED BY: Domingo Gomez Morin
Answer
6 months ago

Note: Never use blank spaces for your filenames. Never¡

POSTED BY: Domingo Gomez Morin
Answer
5 months ago

Group Abstract Group Abstract