Adding a sliding sound to a website
I would like to add an unusual feature to a website that would allow the user to play a sound...a single sampled note. When the user moves a slider control the sound would go up or down in tone (seamlessly). So, as the user slides the button to the right the sound would rise in pitch, when moved to the left it would go down in pitch (from soprano to bass). Does anyone know how this could be achieved? What sort of sound file would you use and how would you get it to play continuously (when a button was pressed) and change pitch (when the slider was moved)? This isnt really language specific - it could be php or flex. Thanks in advance. Simon...
=============================================== Further information
It appears that the best solution might involve something like C or C# or C++. Unfortunately, I have very little experienc开发者_StackOverflow中文版e of these languages. Would anyone be able to tell me whether it is possible to achieve this in C? Thanks.
There are these guys "Sonoflash" who are doing very interesting things with generated audio in pure ActionScript3 - in other words, no external sound file necessary.
Here's a link to an interview that Adobe Platform Evangelist Ryan Stewart did with them. I suspect that you'll be able to get what you need using this AS3 library.
http://blog.digitalbackcountry.com/2009/09/sonoflash-easily-add-sound-to-your-flash-apps/
You will need a client-side plugin to make this work in a browser, Silverlight, Flex, or Flash will most likely be your best/only option.
On a website, with limited access to hardware, what you want to do will be hard, if not impossible. Your best bet is to have many audio files (for each note/pitch you want) and have the slide control play a different file.
You may want to use a queue and an array of different audio files.
If the next item from the queue is different than the first, play it, if the queue is empty, keep playing the last file. Then in the "slider" event you'll queue the next file.
If you were running a native application, you would have more control over the sound hardware, and could likely create this effect without having an mp3 for each note/pitch you want to play.
To achieve what you want you need specific audio manipulation tools, that most web-apps do not have access to. I suggest you take a look at Flex and Alchemy. Alchemy allows you to call c or c++ which can allow you to use different c filters for transforming the sound.
I know it is not impossible... just not so easy to do :) Good luck.
Adrian
There is definately not a PHP solution, other than echoing HTML to call the client-side routine.
Sure you could use Flash, or Flex.. but have you tried JavaScript mouse events?
for example:
<img src="buttonImageFilename"
onMouseDown="handlePress();return true;"
onMouseUp="handleRelease();return true;"
onMouseOut="handleRelease();return true;"
onClick="return false;"
>
Honestly, it bugs me whenever Flash gets thrown around as first solution since an environment object wrapper is normally needed to render it. (have you seen the issues with Flash10 and CPU hogging??)
Many times for simple things JavaScript works just fine.
精彩评论