Message Boards Message Boards

GROUPS:

Emit sounds over one another?

Posted 11 months ago
1279 Views
|
6 Replies
|
2 Total Likes
|

I'm trying and failing to use "EmitSound" to play notes OVER one another. It seems that if one sound is emitted after another sound, the second sound stops the first before playing. I know that I can take a list of notes (which have lengths associated with them) and create a sound object and then play that, but the thing is, I'm trying to generate notes continuously so I need it to play on the fly, I can't "compile" the notes beforehand.

See, if I play

EmitSound[Sound[SoundNote[1, 10, "Trumpet"]]]; Pause[1]; EmitSound[Sound[SoundNote[1, 1, "Piano"]]]

the piano cuts off the trumpet before it plays for the full 10 seconds. If I try to do something LIKE this:

While[True, EmitSound[Sound[SoundNote[RandomInteger[8], {0, RandomInteger[7]}, "Trumpet"]]]; Pause[1]]

It doesn't work. What I had in mind for that code was to every second play a randomly selected note between 1-8 for between 1-7 seconds, but what happens is that it just plays each note for one second as they all cut each other off.

The code I'm writing in the end isn't exactly that (just random gibberish notes) but the next step is that I need to get something like this to work, thanks.

6 Replies

EmitSound[] is an older function. If you have Version 11 or later, there is a lot of new stuff in Audio. See the documentation and some of the fine tutorials and videos on the website.

Also, you should check the syntax for Emit sound. To play sounds sequentially, you put them in a list, surrounded by {}. The documentation can give you help with rests.

Look at Sound[]. It may give you some clues.

To accomplish your ultimate goal, you will need to use a lot of the functionality in the new Audio Processing.

Posted 11 months ago

I guess I should have elaborated on the fact that I'm trying to generate notes continuously. I know how to play songs over one another as long as the notes are specified IN ADVANCE. But my whole problem is that I'm trying to generate an endless stream of notes here. I may be playing for one minute, I may be playing for days, I don't know ahead of time, so I can't, as you say, "put them in a list" because I don't even know how long the list will be.

Believe me I've looked up and down the Sound function, and unless I'm missing something here, I do not see a way to play notes over one another unless, as you say, I put them in a list ahead of time.

I am currently using Mathematica 11.0.0.0

At the recent WTC, there was a talk that touched on this. This functionality is apparently coming 'soon', for a suitable definition of 'soon'. You might want to check the video from last year's WTC and this years when they are available.

Is this what you need, meaning specifying not duration but the start and end of time interval of a note?

Sound[{SoundNote["C", {0, 2}, "Trumpet"], SoundNote["G", {1, 3}, "Piano"]}]

That was an example from the docs: SoundNote >> Scope >> Timing

http://reference.wolfram.com/language/ref/SoundNote.html

Experimenting with random specs, here are a few ideas:

inst={"Trumpet","Piano","Organ","Violin","Voice"};
Sound[
    Table[
       SoundNote[3RandomInteger[{-5,5}],
       Sort[RandomInteger[{0,9},2]],
       RandomChoice[inst]],
    15]
    ~Join~
    Table[
       SoundNote[3RandomInteger[{-5,5}],
       {#,#+.5}&@RandomReal[{0,9}],
       RandomChoice[inst]],
    15]
]
Posted 11 months ago

Gadzooks, Vitaliy Kaurov, I know I can start and end notes if I know AHEAD OF TIME when then will start and end and put them in a list. Look think of it this way, what if I were simply trying to play one note, and then when the user hits a key, it plays a note over the first note. How do I do that? I don't think I can, because when the second note plays it stops the first, and I didn't know AHEAD OF TIME that the user would push the button, so I can't just put it all in a list from a table.

Similarly and closer to what I'm doing let's say I'm trying to use the digits of pi to specify start and times. I don't know long the song will go on for so I don't know how many digits I will need ahead of time so I want to play the notes AS the digits are computed, not afterward. Look at my second code example, it uses While, so it goes on forever/indefinitely picking random notes.

In your code, you knew ahead of time what notes would be played. I do not. I'm playing an infinite stream of notes. Does that make sense or not?

P.S. George Woodrow, thanks, I look forward to the eventual new functionality.

I looked into similar applications after the new Audio functionality was introduced last year. I looked into making a virtual Theremin. I could see no way to do this in Wolfram Language, while there was a clear path to doing this in iOS/macOS with Xcode.

I have since moved on, but it was clear that in making software, it is sometimes better to go with the strengths of a language, rather than trying to shoehorn functionality into a language. Best case I could come up with was to write the code in Swift and call it as an external function in Wolfram language.

Life is short.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract