Plugins-soundmanager
From Bcontrol
Revision as of 21:40, 11 August 2007 by CarlosBrody (talk | contribs)
Follow this link for some simple example code using the soundmanager plugin.
And from the Matlab help file ("help @soundmanager/SoundManagerSection"):
% [] = SoundManagerSection(obj, action, [arg1], [arg2], [arg3]) % % This plugin helps to manage sounds sent to the SoundServer. % (@RTLSoundMachine; or, in a virtual rig, @softsound). The plugin stores % soundwaves (identifying them by name, so they are easy to id), sends them % to the SoundServer, and keeps track of which sounds have been sent and % which haven't, so they aren't sent again if that is unnecessary. % % The plugin acts as a clean wrapper to the SoundServer; it is easier to % use than the native SoundServer commands, and if you use it, you need % never know about the native commands. % % This plugin has no GUI elements. This plugin requires Dispatcher. % % % % PARAMETERS: % ----------- % % obj Default object argument. % % action One of: % % 'init' Initializes the plugin. Sets up internal variables % and initalizes the RT Linux SoundServer. % % 'initialize_machine' Delete all existing sounds from the RT Linux SoundServer % and from the plugin; reinitialize the RT Linux SoundServer. % % 'get_sample_rate' Returns the sample rate used by the RT Linux % SoundServer. This information is crucial when you are going % to synthesize the sound waveforms that will be sent to the % RTL SoundServer. % % 'declare_new_sound' name [waveform] [loop_fg=0] % This action defines a new name that can be used to identify % sounds. This action requires at least one further argument, % name, which should be a string. The next argument is % optional; this argument, waveform, if provided, should be a % numeric matrix that defines the sound waveform associated % with the name. waveform can be a vector, in which case the % sound will be mono (sound will be played on both speakers). % If waveform has either two columns or two rows, then it is % interpreted as two vectors, one for the Left speaker, and % one for the Right speaker. The first row (or column) is for % the Left speaker; the other for the Right. If the waveform % is not provided, then action='set_sound' (see below) must be % called before the newly declared sound can be used. The last % argument is also optional; if loop_fg is non-zero, then the % sound will loop until explicitly turned off. If loop_fg is % zero (the default) then the sound stops after being played % once. NOTE: LOOP_FG NON-ZERO IS ACCEPTED, BUT % NON-FUNCTIONAL, IN THE @SOFTSMMARKII EMULATOR % % 'set_sound' name waveform [loop_fg=0] % Set the waveform of a previously declared sound. This action % requires two additional arguments: name, the string that is % used to identify the sound; and waveform, which should be a % numeric matrix that defines the sound waveform associated % with that name. waveform can be a vector, in which case the % sound will be mono (sound will be played on both speakers). % If waveform has either two columns or two rows, then it is % interpreted as two vectors, one for the Left speaker, and % one for the Right speaker. The first row (or column) is for % the Left speaker; the other for the Right. The last % argument is optional; if loop_fg is non-zero, then the % sound will loop until explicitly turned off. If loop_fg is % zero (the default) then the sound stops after being played % once. NOTE: LOOP_FG NON-ZERO IS ACCEPTED, BUT % NON-FUNCTIONAL, IN THE @SOFTSMMARKII EMULATOR % % 'send_not_yet_uploaded_sounds' Any sound that has been newly % declared, or for which the waveform has been set using % 'set_sound' since the last call to % 'send_not_yet_uploaded_sounds', will be uploaded to the RTL % SoundServer. Sounds that were already uploaded and didn't % have their waveform set since they were uploaded will not be % uploaded again, to save time. % % 'get_sound_id' name % The RTLSM triggers sounds in the SoundServer using integer % ids, not sound names. This action returns the sound id % associated with a particular name. (You will need this % information, for example, when using the % @StateMachineAssembler to define a state that triggers a % sound). If no sound with this name has been declared, an % error will occur. % % 'get_sound_duration' name % Returns, in seconds, the duration of the indicated sound. % name should be a string. If no sound with this name has been % declared, an error will occur. % % 'get_sound' name % Returns the sound wave of the specified sound. % added by jerlich, July 2007 % % 'sound_exists' name % Returns either 1 or 0: a 1 if a sound with the indicated % name has been declared (see 'declare_new_sound' above), 0 if % it hasn't. % % 'play_sound' name % If the sound with this name hasn't been uploaded yet, upload % it to the SoundServer; after that, tell the SoundServer to % play it asap. No real-time guarantees here. % % 'get_sound_machine' Returns the sound machine object, which will % either be an @RTLSoundMachine or an @softsound, depending on % whether you are on a physical rig (first case) or a virtual % rig (latter case). This action is provided for completeness, % but if you are using this plugin, there is nor eason you % should ever need direct access to the SoundServer. % % 'reinit' Delete all of this plugin's data, and reinit from scratch. %