home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / SoundMusicDSP / Resound-2.5-MIHS / APIExamples / Zero / ZeroModule.m < prev   
Encoding:
Text File  |  1997-12-05  |  2.8 KB  |  121 lines

  1. /*
  2. ZeroModule
  3. For Resound 2.2
  4. Sean Luke
  5. Jan 10 1995
  6.  
  7. A simple example module which zeroes out the selected sound, to get you
  8. started using Resound modules.  This code is discussed in Resound's Help
  9. facility, under the section "Building a Resound Module: A Walk-Though".
  10. For a more sophisticated module, see the API/Math directory.
  11.  
  12. INTEL READY
  13.  
  14.  
  15. Copyright (c) 1995 by Sean Luke
  16.  
  17. Permission to use, copy, modify, and distribute this material 
  18. for any purpose and without fee is hereby granted.  SEAN LUKE 
  19. MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
  20. OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
  21. WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  22. */
  23.  
  24.  
  25.     #import "ZeroModule.h"
  26.     #import <soundkit/soundkit.h>
  27.     #import <appkit/appkit.h>
  28.     
  29.     @implementation ZeroModule
  30.  
  31.     -init
  32.         {
  33.         id returnVal=[super init];
  34.         
  35.         ModuleMenuNode* zeroNode=[[ModuleMenuNode alloc] init];
  36.         
  37.         [TheModuleMenuNode setLength:1];
  38.         [TheModuleMenuNode setSubmenu: 0 : zeroNode];
  39.         
  40.         [zeroNode setName: "Zero"];
  41.         [zeroNode setReceiver: self];
  42.         [zeroNode setMessage:@selector(zeroSound:)];
  43.         [zeroNode setLength:0];
  44.                 
  45.         return returnVal;
  46.         }
  47.         
  48.     - zeroSound:sender
  49.         {
  50.         Sound* current=            [TheModuleController currentSound];
  51.         SoundView* cview=    [TheModuleController currentSoundView];
  52.         
  53.         int dataFormat=            [current dataFormat];
  54.         int channelCount=            [current channelCount];
  55.         int sampleCount=            [current sampleCount];
  56.         char* data;
  57.         int x;
  58.     
  59.         int firstSample,sampleLength;
  60.         
  61.         [cview getSelection: &firstSample size: &sampleLength];
  62.         
  63.         if (current==NULL||!sampleLength)        // no sound
  64.             {
  65.             NXRunAlertPanel("No Sound", 
  66.                 "There is no sound with which to perform this operation." , 
  67.                 "Okay",NULL,NULL);
  68.             return NULL;
  69.             }
  70.             
  71.         [TheModuleController stop];
  72.         [current compactSamples];
  73.  
  74.         data=(char*) [current data];
  75.  
  76.         SNDSwapSoundToHost
  77.             ((void*)data, (void*)data, sampleCount, channelCount, dataFormat);
  78.             
  79.         switch(dataFormat)
  80.             {
  81.             case SND_FORMAT_MULAW_8: 
  82.             case SND_FORMAT_LINEAR_8:
  83.                 {
  84.                 char* d=(char*) data;
  85.                 for (x=firstSample;x<firstSample+sampleLength;x++) d[x]=0;
  86.                 break;
  87.                 }
  88.             case SND_FORMAT_LINEAR_16:
  89.                 {
  90.                 signed short* d=(signed short*)data;
  91.                 for (x=firstSample;x<firstSample+sampleLength;x++) d[x]=0;
  92.                 break;
  93.                 }
  94.             case SND_FORMAT_FLOAT:             
  95.                 {
  96.                 float* d=(float*)data;
  97.                 for (x=firstSample;x<firstSample+sampleLength;x++) d[x]=0;
  98.                 break;
  99.                 }
  100.             case SND_FORMAT_DOUBLE:             
  101.                 {
  102.                 double* d=(double*)data;
  103.                 for (x=firstSample;x<firstSample+sampleLength;x++) d[x]=0;
  104.                 break;
  105.                 }
  106.             default:
  107.                 NXRunAlertPanel("Invalid Format", 
  108.                     "This operation cannot be performed with "
  109.                     "this particular sound format." , 
  110.                     "Okay",NULL,NULL);
  111.                 break;
  112.             }
  113.         SNDSwapHostToSound
  114.             ((void*)data, (void*)data, sampleCount, channelCount, dataFormat);
  115.         [TheModuleController soundTouched];
  116.         return self;
  117.         }    
  118.  
  119.     @end
  120.  
  121.