home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 3.ddi / DEMOS.DI$ / SOUNDDEM.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  2.9 KB  |  94 lines

  1. %SOUNDDEMO Demonstrate MATLAB V4's sound capability.
  2.  
  3. %       Copyright (c) 1984-93 by The MathWorks, Inc.
  4.  
  5. echo on
  6. clc
  7. %       MATLAB has sound capability on SPARC, HP 9000/700, SGI, and
  8. %       Macintosh computers.  On PCs, sound is available if you
  9. %       have an MS-Windows supported sound card installed.
  10. %
  11. %       Continue with this demo only if you have sound available.
  12.  
  13. echo off
  14. s = input('Do you wish to continue? ([y]/n) ','s');
  15. if isempty(s), s = 'y'; end
  16. if strcmp(lower(s(1)),'n')
  17.         return
  18. end
  19. clf 
  20. saxis('auto')
  21. echo on
  22. clc
  23. %       MATLAB is useful for exploring audio data. Sounds can be thought
  24. %       of as one-dimensional arrays, or vectors.  There are a number of
  25. %       sample files with sound data in the sounds directory.  Let's see
  26. %       what's there.
  27.  
  28. pause      % Press any key to continue.
  29. clc
  30. what sounds
  31. %       The MAT-files in this directory contain data appropriate for using
  32. %       with the sound command. For example, splat.mat contains
  33. %       audio data of a dropping egg.  Let's load the data in.
  34.  
  35. load splat
  36.  
  37. pause      % Press any key to continue.
  38. clc
  39.  
  40. %       Now in the workspace is vector y, with audio data, and scalar Fs
  41. %       containing the sample rate.  Let's generate the corresponding
  42. %       time vector and plot the time sequence.
  43.  
  44. t = (1:length(y))/Fs;
  45. plot(t,y)
  46.  
  47. pause      % Press any key to continue.
  48.  
  49. %       Use MATLAB's SOUND command to play the sound through the audio
  50. %       port.
  51.  
  52. sound(y,Fs)
  53.  
  54. pause      % Press any key to continue.
  55. clc
  56.  
  57. %       The SAXIS command controls the volume at which the next sound
  58. %       is played in much the same way that AXIS controls plot scaling.
  59. %       First find out the range of the data.
  60.  
  61. range  = [min(y) max(y)]
  62. %       Now replay the egg-drop sound at a lower volume.
  63.  
  64. saxis(2*range)
  65. sound(y,Fs)
  66.  
  67. pause      % Press any key to continue.
  68. clc
  69.  
  70. %       Finally, let's build a separate window in which buttons, made from
  71. %       UICONTROLS, are set up.  These display choices of sounds to play,
  72. %       a volume control, and, alternate ways to view the data graphically,
  73. %       if the Signal Processing Toolbox is present.
  74.  
  75. %       You may view the audio graphically in three ways.
  76. %       The default option, as a time sequence, is a straight-forward
  77. %       two-dimensional plot of the data as a function of time.
  78.  
  79. %       Another way to see the information in the data is to view the
  80. %       "spectrum", an average of the signal's frequency content for
  81. %       the duration of the sound. The spectrum shows the signal's
  82. %       power as a function of frequency.
  83.  
  84. %       The third choice is to look at the "spectrogram" of the data.
  85. %       This is a view of the frequency content of the signal as a
  86. %       function of time.  Time increases from left to right;
  87. %       frequency increases from bottom to top.
  88.  
  89. echo off
  90. soundext
  91. if exist('freqz')~=2
  92.     clc
  93. end
  94.